pdfjs-dist 2.2.228 → 2.6.347

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.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2019 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -26,45 +26,27 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.PDFNetworkStream = void 0;
28
28
 
29
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _util = require("../shared/util");
32
-
33
- var _network_utils = require("./network_utils");
34
-
35
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
-
37
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
38
-
39
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
40
-
41
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
42
-
43
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
44
-
45
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31
+ var _network_utils = require("./network_utils.js");
46
32
 
47
33
  ;
48
- var OK_RESPONSE = 200;
49
- var PARTIAL_CONTENT_RESPONSE = 206;
34
+ const OK_RESPONSE = 200;
35
+ const PARTIAL_CONTENT_RESPONSE = 206;
50
36
 
51
37
  function getArrayBuffer(xhr) {
52
- var data = xhr.response;
38
+ const data = xhr.response;
53
39
 
54
- if (typeof data !== 'string') {
40
+ if (typeof data !== "string") {
55
41
  return data;
56
42
  }
57
43
 
58
- var array = (0, _util.stringToBytes)(data);
44
+ const array = (0, _util.stringToBytes)(data);
59
45
  return array.buffer;
60
46
  }
61
47
 
62
- var NetworkManager =
63
- /*#__PURE__*/
64
- function () {
65
- function NetworkManager(url, args) {
66
- _classCallCheck(this, NetworkManager);
67
-
48
+ class NetworkManager {
49
+ constructor(url, args) {
68
50
  this.url = url;
69
51
  args = args || {};
70
52
  this.isHttp = /^https?:/i.test(url);
@@ -79,190 +61,159 @@ function () {
79
61
  this.pendingRequests = Object.create(null);
80
62
  }
81
63
 
82
- _createClass(NetworkManager, [{
83
- key: "requestRange",
84
- value: function requestRange(begin, end, listeners) {
85
- var args = {
86
- begin: begin,
87
- end: end
88
- };
89
-
90
- for (var prop in listeners) {
91
- args[prop] = listeners[prop];
92
- }
64
+ requestRange(begin, end, listeners) {
65
+ const args = {
66
+ begin,
67
+ end
68
+ };
93
69
 
94
- return this.request(args);
70
+ for (const prop in listeners) {
71
+ args[prop] = listeners[prop];
95
72
  }
96
- }, {
97
- key: "requestFull",
98
- value: function requestFull(listeners) {
99
- return this.request(listeners);
100
- }
101
- }, {
102
- key: "request",
103
- value: function request(args) {
104
- var xhr = this.getXhr();
105
- var xhrId = this.currXhrId++;
106
- var pendingRequest = this.pendingRequests[xhrId] = {
107
- xhr: xhr
108
- };
109
- xhr.open('GET', this.url);
110
- xhr.withCredentials = this.withCredentials;
111
-
112
- for (var property in this.httpHeaders) {
113
- var value = this.httpHeaders[property];
114
73
 
115
- if (typeof value === 'undefined') {
116
- continue;
117
- }
74
+ return this.request(args);
75
+ }
118
76
 
119
- xhr.setRequestHeader(property, value);
120
- }
77
+ requestFull(listeners) {
78
+ return this.request(listeners);
79
+ }
121
80
 
122
- if (this.isHttp && 'begin' in args && 'end' in args) {
123
- xhr.setRequestHeader('Range', "bytes=".concat(args.begin, "-").concat(args.end - 1));
124
- pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
125
- } else {
126
- pendingRequest.expectedStatus = OK_RESPONSE;
127
- }
81
+ request(args) {
82
+ const xhr = this.getXhr();
83
+ const xhrId = this.currXhrId++;
84
+ const pendingRequest = this.pendingRequests[xhrId] = {
85
+ xhr
86
+ };
87
+ xhr.open("GET", this.url);
88
+ xhr.withCredentials = this.withCredentials;
128
89
 
129
- xhr.responseType = 'arraybuffer';
90
+ for (const property in this.httpHeaders) {
91
+ const value = this.httpHeaders[property];
130
92
 
131
- if (args.onError) {
132
- xhr.onerror = function (evt) {
133
- args.onError(xhr.status);
134
- };
93
+ if (typeof value === "undefined") {
94
+ continue;
135
95
  }
136
96
 
137
- xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
138
- xhr.onprogress = this.onProgress.bind(this, xhrId);
139
- pendingRequest.onHeadersReceived = args.onHeadersReceived;
140
- pendingRequest.onDone = args.onDone;
141
- pendingRequest.onError = args.onError;
142
- pendingRequest.onProgress = args.onProgress;
143
- xhr.send(null);
144
- return xhrId;
97
+ xhr.setRequestHeader(property, value);
145
98
  }
146
- }, {
147
- key: "onProgress",
148
- value: function onProgress(xhrId, evt) {
149
- var pendingRequest = this.pendingRequests[xhrId];
150
99
 
151
- if (!pendingRequest) {
152
- return;
153
- }
154
-
155
- if (pendingRequest.onProgress) {
156
- pendingRequest.onProgress(evt);
157
- }
100
+ if (this.isHttp && "begin" in args && "end" in args) {
101
+ xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
102
+ pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
103
+ } else {
104
+ pendingRequest.expectedStatus = OK_RESPONSE;
158
105
  }
159
- }, {
160
- key: "onStateChange",
161
- value: function onStateChange(xhrId, evt) {
162
- var pendingRequest = this.pendingRequests[xhrId];
163
106
 
164
- if (!pendingRequest) {
165
- return;
166
- }
107
+ xhr.responseType = "arraybuffer";
167
108
 
168
- var xhr = pendingRequest.xhr;
109
+ if (args.onError) {
110
+ xhr.onerror = function (evt) {
111
+ args.onError(xhr.status);
112
+ };
113
+ }
169
114
 
170
- if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
171
- pendingRequest.onHeadersReceived();
172
- delete pendingRequest.onHeadersReceived;
173
- }
115
+ xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
116
+ xhr.onprogress = this.onProgress.bind(this, xhrId);
117
+ pendingRequest.onHeadersReceived = args.onHeadersReceived;
118
+ pendingRequest.onDone = args.onDone;
119
+ pendingRequest.onError = args.onError;
120
+ pendingRequest.onProgress = args.onProgress;
121
+ xhr.send(null);
122
+ return xhrId;
123
+ }
174
124
 
175
- if (xhr.readyState !== 4) {
176
- return;
177
- }
125
+ onProgress(xhrId, evt) {
126
+ const pendingRequest = this.pendingRequests[xhrId];
178
127
 
179
- if (!(xhrId in this.pendingRequests)) {
180
- return;
181
- }
128
+ if (!pendingRequest) {
129
+ return;
130
+ }
182
131
 
183
- delete this.pendingRequests[xhrId];
132
+ if (pendingRequest.onProgress) {
133
+ pendingRequest.onProgress(evt);
134
+ }
135
+ }
184
136
 
185
- if (xhr.status === 0 && this.isHttp) {
186
- if (pendingRequest.onError) {
187
- pendingRequest.onError(xhr.status);
188
- }
137
+ onStateChange(xhrId, evt) {
138
+ const pendingRequest = this.pendingRequests[xhrId];
189
139
 
190
- return;
191
- }
140
+ if (!pendingRequest) {
141
+ return;
142
+ }
192
143
 
193
- var xhrStatus = xhr.status || OK_RESPONSE;
194
- var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
144
+ const xhr = pendingRequest.xhr;
195
145
 
196
- if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
197
- if (pendingRequest.onError) {
198
- pendingRequest.onError(xhr.status);
199
- }
146
+ if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
147
+ pendingRequest.onHeadersReceived();
148
+ delete pendingRequest.onHeadersReceived;
149
+ }
200
150
 
201
- return;
202
- }
151
+ if (xhr.readyState !== 4) {
152
+ return;
153
+ }
203
154
 
204
- var chunk = getArrayBuffer(xhr);
155
+ if (!(xhrId in this.pendingRequests)) {
156
+ return;
157
+ }
205
158
 
206
- if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
207
- var rangeHeader = xhr.getResponseHeader('Content-Range');
208
- var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
209
- pendingRequest.onDone({
210
- begin: parseInt(matches[1], 10),
211
- chunk: chunk
212
- });
213
- } else if (chunk) {
214
- pendingRequest.onDone({
215
- begin: 0,
216
- chunk: chunk
217
- });
218
- } else if (pendingRequest.onError) {
159
+ delete this.pendingRequests[xhrId];
160
+
161
+ if (xhr.status === 0 && this.isHttp) {
162
+ if (pendingRequest.onError) {
219
163
  pendingRequest.onError(xhr.status);
220
164
  }
221
- }
222
- }, {
223
- key: "hasPendingRequests",
224
- value: function hasPendingRequests() {
225
- for (var xhrId in this.pendingRequests) {
226
- return true;
227
- }
228
165
 
229
- return false;
230
- }
231
- }, {
232
- key: "getRequestXhr",
233
- value: function getRequestXhr(xhrId) {
234
- return this.pendingRequests[xhrId].xhr;
235
- }
236
- }, {
237
- key: "isPendingRequest",
238
- value: function isPendingRequest(xhrId) {
239
- return xhrId in this.pendingRequests;
166
+ return;
240
167
  }
241
- }, {
242
- key: "abortAllRequests",
243
- value: function abortAllRequests() {
244
- for (var xhrId in this.pendingRequests) {
245
- this.abortRequest(xhrId | 0);
168
+
169
+ const xhrStatus = xhr.status || OK_RESPONSE;
170
+ const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
171
+
172
+ if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
173
+ if (pendingRequest.onError) {
174
+ pendingRequest.onError(xhr.status);
246
175
  }
176
+
177
+ return;
247
178
  }
248
- }, {
249
- key: "abortRequest",
250
- value: function abortRequest(xhrId) {
251
- var xhr = this.pendingRequests[xhrId].xhr;
252
- delete this.pendingRequests[xhrId];
253
- xhr.abort();
179
+
180
+ const chunk = getArrayBuffer(xhr);
181
+
182
+ if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
183
+ const rangeHeader = xhr.getResponseHeader("Content-Range");
184
+ const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
185
+ pendingRequest.onDone({
186
+ begin: parseInt(matches[1], 10),
187
+ chunk
188
+ });
189
+ } else if (chunk) {
190
+ pendingRequest.onDone({
191
+ begin: 0,
192
+ chunk
193
+ });
194
+ } else if (pendingRequest.onError) {
195
+ pendingRequest.onError(xhr.status);
254
196
  }
255
- }]);
197
+ }
256
198
 
257
- return NetworkManager;
258
- }();
199
+ getRequestXhr(xhrId) {
200
+ return this.pendingRequests[xhrId].xhr;
201
+ }
259
202
 
260
- var PDFNetworkStream =
261
- /*#__PURE__*/
262
- function () {
263
- function PDFNetworkStream(source) {
264
- _classCallCheck(this, PDFNetworkStream);
203
+ isPendingRequest(xhrId) {
204
+ return xhrId in this.pendingRequests;
205
+ }
265
206
 
207
+ abortRequest(xhrId) {
208
+ const xhr = this.pendingRequests[xhrId].xhr;
209
+ delete this.pendingRequests[xhrId];
210
+ xhr.abort();
211
+ }
212
+
213
+ }
214
+
215
+ class PDFNetworkStream {
216
+ constructor(source) {
266
217
  this._source = source;
267
218
  this._manager = new NetworkManager(source.url, {
268
219
  httpHeaders: source.httpHeaders,
@@ -273,60 +224,49 @@ function () {
273
224
  this._rangeRequestReaders = [];
274
225
  }
275
226
 
276
- _createClass(PDFNetworkStream, [{
277
- key: "_onRangeRequestReaderClosed",
278
- value: function _onRangeRequestReaderClosed(reader) {
279
- var i = this._rangeRequestReaders.indexOf(reader);
227
+ _onRangeRequestReaderClosed(reader) {
228
+ const i = this._rangeRequestReaders.indexOf(reader);
280
229
 
281
- if (i >= 0) {
282
- this._rangeRequestReaders.splice(i, 1);
283
- }
284
- }
285
- }, {
286
- key: "getFullReader",
287
- value: function getFullReader() {
288
- (0, _util.assert)(!this._fullRequestReader);
289
- this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
290
- return this._fullRequestReader;
230
+ if (i >= 0) {
231
+ this._rangeRequestReaders.splice(i, 1);
291
232
  }
292
- }, {
293
- key: "getRangeReader",
294
- value: function getRangeReader(begin, end) {
295
- var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
296
- reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
233
+ }
297
234
 
298
- this._rangeRequestReaders.push(reader);
235
+ getFullReader() {
236
+ (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
237
+ this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
238
+ return this._fullRequestReader;
239
+ }
299
240
 
300
- return reader;
301
- }
302
- }, {
303
- key: "cancelAllRequests",
304
- value: function cancelAllRequests(reason) {
305
- if (this._fullRequestReader) {
306
- this._fullRequestReader.cancel(reason);
307
- }
241
+ getRangeReader(begin, end) {
242
+ const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
243
+ reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
308
244
 
309
- var readers = this._rangeRequestReaders.slice(0);
245
+ this._rangeRequestReaders.push(reader);
310
246
 
311
- readers.forEach(function (reader) {
312
- reader.cancel(reason);
313
- });
247
+ return reader;
248
+ }
249
+
250
+ cancelAllRequests(reason) {
251
+ if (this._fullRequestReader) {
252
+ this._fullRequestReader.cancel(reason);
314
253
  }
315
- }]);
316
254
 
317
- return PDFNetworkStream;
318
- }();
255
+ const readers = this._rangeRequestReaders.slice(0);
319
256
 
320
- exports.PDFNetworkStream = PDFNetworkStream;
257
+ readers.forEach(function (reader) {
258
+ reader.cancel(reason);
259
+ });
260
+ }
261
+
262
+ }
321
263
 
322
- var PDFNetworkStreamFullRequestReader =
323
- /*#__PURE__*/
324
- function () {
325
- function PDFNetworkStreamFullRequestReader(manager, source) {
326
- _classCallCheck(this, PDFNetworkStreamFullRequestReader);
264
+ exports.PDFNetworkStream = PDFNetworkStream;
327
265
 
266
+ class PDFNetworkStreamFullRequestReader {
267
+ constructor(manager, source) {
328
268
  this._manager = manager;
329
- var args = {
269
+ const args = {
330
270
  onHeadersReceived: this._onHeadersReceived.bind(this),
331
271
  onDone: this._onDone.bind(this),
332
272
  onError: this._onError.bind(this),
@@ -353,218 +293,168 @@ function () {
353
293
  this.onProgress = null;
354
294
  }
355
295
 
356
- _createClass(PDFNetworkStreamFullRequestReader, [{
357
- key: "_onHeadersReceived",
358
- value: function _onHeadersReceived() {
359
- var fullRequestXhrId = this._fullRequestId;
296
+ _onHeadersReceived() {
297
+ const fullRequestXhrId = this._fullRequestId;
360
298
 
361
- var fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
299
+ const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
362
300
 
363
- var getResponseHeader = function getResponseHeader(name) {
364
- return fullRequestXhr.getResponseHeader(name);
365
- };
301
+ const getResponseHeader = name => {
302
+ return fullRequestXhr.getResponseHeader(name);
303
+ };
366
304
 
367
- var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({
368
- getResponseHeader: getResponseHeader,
369
- isHttp: this._manager.isHttp,
370
- rangeChunkSize: this._rangeChunkSize,
371
- disableRange: this._disableRange
372
- }),
373
- allowRangeRequests = _validateRangeRequest.allowRangeRequests,
374
- suggestedLength = _validateRangeRequest.suggestedLength;
375
-
376
- if (allowRangeRequests) {
377
- this._isRangeSupported = true;
378
- }
305
+ const {
306
+ allowRangeRequests,
307
+ suggestedLength
308
+ } = (0, _network_utils.validateRangeRequestCapabilities)({
309
+ getResponseHeader,
310
+ isHttp: this._manager.isHttp,
311
+ rangeChunkSize: this._rangeChunkSize,
312
+ disableRange: this._disableRange
313
+ });
379
314
 
380
- this._contentLength = suggestedLength || this._contentLength;
381
- this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
315
+ if (allowRangeRequests) {
316
+ this._isRangeSupported = true;
317
+ }
382
318
 
383
- if (this._isRangeSupported) {
384
- this._manager.abortRequest(fullRequestXhrId);
385
- }
319
+ this._contentLength = suggestedLength || this._contentLength;
320
+ this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
386
321
 
387
- this._headersReceivedCapability.resolve();
322
+ if (this._isRangeSupported) {
323
+ this._manager.abortRequest(fullRequestXhrId);
388
324
  }
389
- }, {
390
- key: "_onDone",
391
- value: function _onDone(args) {
392
- if (args) {
393
- if (this._requests.length > 0) {
394
- var requestCapability = this._requests.shift();
395
-
396
- requestCapability.resolve({
397
- value: args.chunk,
398
- done: false
399
- });
400
- } else {
401
- this._cachedChunks.push(args.chunk);
402
- }
403
- }
404
325
 
405
- this._done = true;
326
+ this._headersReceivedCapability.resolve();
327
+ }
406
328
 
407
- if (this._cachedChunks.length > 0) {
408
- return;
409
- }
329
+ _onDone(args) {
330
+ if (args) {
331
+ if (this._requests.length > 0) {
332
+ const requestCapability = this._requests.shift();
410
333
 
411
- this._requests.forEach(function (requestCapability) {
412
334
  requestCapability.resolve({
413
- value: undefined,
414
- done: true
335
+ value: args.chunk,
336
+ done: false
415
337
  });
416
- });
417
-
418
- this._requests = [];
338
+ } else {
339
+ this._cachedChunks.push(args.chunk);
340
+ }
419
341
  }
420
- }, {
421
- key: "_onError",
422
- value: function _onError(status) {
423
- var url = this._url;
424
- var exception = (0, _network_utils.createResponseStatusError)(status, url);
425
- this._storedError = exception;
426
342
 
427
- this._headersReceivedCapability.reject(exception);
343
+ this._done = true;
428
344
 
429
- this._requests.forEach(function (requestCapability) {
430
- requestCapability.reject(exception);
345
+ if (this._cachedChunks.length > 0) {
346
+ return;
347
+ }
348
+
349
+ this._requests.forEach(function (requestCapability) {
350
+ requestCapability.resolve({
351
+ value: undefined,
352
+ done: true
431
353
  });
354
+ });
432
355
 
433
- this._requests = [];
434
- this._cachedChunks = [];
435
- }
436
- }, {
437
- key: "_onProgress",
438
- value: function _onProgress(data) {
439
- if (this.onProgress) {
440
- this.onProgress({
441
- loaded: data.loaded,
442
- total: data.lengthComputable ? data.total : this._contentLength
443
- });
444
- }
445
- }
446
- }, {
447
- key: "read",
448
- value: function () {
449
- var _read = _asyncToGenerator(
450
- /*#__PURE__*/
451
- _regenerator["default"].mark(function _callee() {
452
- var chunk, requestCapability;
453
- return _regenerator["default"].wrap(function _callee$(_context) {
454
- while (1) {
455
- switch (_context.prev = _context.next) {
456
- case 0:
457
- if (!this._storedError) {
458
- _context.next = 2;
459
- break;
460
- }
461
-
462
- throw this._storedError;
463
-
464
- case 2:
465
- if (!(this._cachedChunks.length > 0)) {
466
- _context.next = 5;
467
- break;
468
- }
469
-
470
- chunk = this._cachedChunks.shift();
471
- return _context.abrupt("return", {
472
- value: chunk,
473
- done: false
474
- });
475
-
476
- case 5:
477
- if (!this._done) {
478
- _context.next = 7;
479
- break;
480
- }
481
-
482
- return _context.abrupt("return", {
483
- value: undefined,
484
- done: true
485
- });
486
-
487
- case 7:
488
- requestCapability = (0, _util.createPromiseCapability)();
489
-
490
- this._requests.push(requestCapability);
491
-
492
- return _context.abrupt("return", requestCapability.promise);
493
-
494
- case 10:
495
- case "end":
496
- return _context.stop();
497
- }
498
- }
499
- }, _callee, this);
500
- }));
501
-
502
- function read() {
503
- return _read.apply(this, arguments);
504
- }
356
+ this._requests = [];
357
+ }
505
358
 
506
- return read;
507
- }()
508
- }, {
509
- key: "cancel",
510
- value: function cancel(reason) {
511
- this._done = true;
359
+ _onError(status) {
360
+ const url = this._url;
361
+ const exception = (0, _network_utils.createResponseStatusError)(status, url);
362
+ this._storedError = exception;
512
363
 
513
- this._headersReceivedCapability.reject(reason);
364
+ this._headersReceivedCapability.reject(exception);
514
365
 
515
- this._requests.forEach(function (requestCapability) {
516
- requestCapability.resolve({
517
- value: undefined,
518
- done: true
519
- });
366
+ this._requests.forEach(function (requestCapability) {
367
+ requestCapability.reject(exception);
368
+ });
369
+
370
+ this._requests = [];
371
+ this._cachedChunks = [];
372
+ }
373
+
374
+ _onProgress(data) {
375
+ if (this.onProgress) {
376
+ this.onProgress({
377
+ loaded: data.loaded,
378
+ total: data.lengthComputable ? data.total : this._contentLength
520
379
  });
380
+ }
381
+ }
521
382
 
522
- this._requests = [];
383
+ get filename() {
384
+ return this._filename;
385
+ }
523
386
 
524
- if (this._manager.isPendingRequest(this._fullRequestId)) {
525
- this._manager.abortRequest(this._fullRequestId);
526
- }
387
+ get isRangeSupported() {
388
+ return this._isRangeSupported;
389
+ }
527
390
 
528
- this._fullRequestReader = null;
529
- }
530
- }, {
531
- key: "filename",
532
- get: function get() {
533
- return this._filename;
534
- }
535
- }, {
536
- key: "isRangeSupported",
537
- get: function get() {
538
- return this._isRangeSupported;
391
+ get isStreamingSupported() {
392
+ return this._isStreamingSupported;
393
+ }
394
+
395
+ get contentLength() {
396
+ return this._contentLength;
397
+ }
398
+
399
+ get headersReady() {
400
+ return this._headersReceivedCapability.promise;
401
+ }
402
+
403
+ async read() {
404
+ if (this._storedError) {
405
+ throw this._storedError;
539
406
  }
540
- }, {
541
- key: "isStreamingSupported",
542
- get: function get() {
543
- return this._isStreamingSupported;
407
+
408
+ if (this._cachedChunks.length > 0) {
409
+ const chunk = this._cachedChunks.shift();
410
+
411
+ return {
412
+ value: chunk,
413
+ done: false
414
+ };
544
415
  }
545
- }, {
546
- key: "contentLength",
547
- get: function get() {
548
- return this._contentLength;
416
+
417
+ if (this._done) {
418
+ return {
419
+ value: undefined,
420
+ done: true
421
+ };
549
422
  }
550
- }, {
551
- key: "headersReady",
552
- get: function get() {
553
- return this._headersReceivedCapability.promise;
423
+
424
+ const requestCapability = (0, _util.createPromiseCapability)();
425
+
426
+ this._requests.push(requestCapability);
427
+
428
+ return requestCapability.promise;
429
+ }
430
+
431
+ cancel(reason) {
432
+ this._done = true;
433
+
434
+ this._headersReceivedCapability.reject(reason);
435
+
436
+ this._requests.forEach(function (requestCapability) {
437
+ requestCapability.resolve({
438
+ value: undefined,
439
+ done: true
440
+ });
441
+ });
442
+
443
+ this._requests = [];
444
+
445
+ if (this._manager.isPendingRequest(this._fullRequestId)) {
446
+ this._manager.abortRequest(this._fullRequestId);
554
447
  }
555
- }]);
556
448
 
557
- return PDFNetworkStreamFullRequestReader;
558
- }();
449
+ this._fullRequestReader = null;
450
+ }
559
451
 
560
- var PDFNetworkStreamRangeRequestReader =
561
- /*#__PURE__*/
562
- function () {
563
- function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
564
- _classCallCheck(this, PDFNetworkStreamRangeRequestReader);
452
+ }
565
453
 
454
+ class PDFNetworkStreamRangeRequestReader {
455
+ constructor(manager, begin, end) {
566
456
  this._manager = manager;
567
- var args = {
457
+ const args = {
568
458
  onDone: this._onDone.bind(this),
569
459
  onProgress: this._onProgress.bind(this)
570
460
  };
@@ -576,132 +466,93 @@ function () {
576
466
  this.onClosed = null;
577
467
  }
578
468
 
579
- _createClass(PDFNetworkStreamRangeRequestReader, [{
580
- key: "_close",
581
- value: function _close() {
582
- if (this.onClosed) {
583
- this.onClosed(this);
584
- }
469
+ _close() {
470
+ if (this.onClosed) {
471
+ this.onClosed(this);
585
472
  }
586
- }, {
587
- key: "_onDone",
588
- value: function _onDone(data) {
589
- var chunk = data.chunk;
473
+ }
590
474
 
591
- if (this._requests.length > 0) {
592
- var requestCapability = this._requests.shift();
475
+ _onDone(data) {
476
+ const chunk = data.chunk;
593
477
 
594
- requestCapability.resolve({
595
- value: chunk,
596
- done: false
597
- });
598
- } else {
599
- this._queuedChunk = chunk;
600
- }
478
+ if (this._requests.length > 0) {
479
+ const requestCapability = this._requests.shift();
601
480
 
602
- this._done = true;
481
+ requestCapability.resolve({
482
+ value: chunk,
483
+ done: false
484
+ });
485
+ } else {
486
+ this._queuedChunk = chunk;
487
+ }
603
488
 
604
- this._requests.forEach(function (requestCapability) {
605
- requestCapability.resolve({
606
- value: undefined,
607
- done: true
608
- });
489
+ this._done = true;
490
+
491
+ this._requests.forEach(function (requestCapability) {
492
+ requestCapability.resolve({
493
+ value: undefined,
494
+ done: true
609
495
  });
496
+ });
610
497
 
611
- this._requests = [];
498
+ this._requests = [];
499
+
500
+ this._close();
501
+ }
612
502
 
613
- this._close();
503
+ _onProgress(evt) {
504
+ if (!this.isStreamingSupported && this.onProgress) {
505
+ this.onProgress({
506
+ loaded: evt.loaded
507
+ });
614
508
  }
615
- }, {
616
- key: "_onProgress",
617
- value: function _onProgress(evt) {
618
- if (!this.isStreamingSupported && this.onProgress) {
619
- this.onProgress({
620
- loaded: evt.loaded
621
- });
622
- }
509
+ }
510
+
511
+ get isStreamingSupported() {
512
+ return false;
513
+ }
514
+
515
+ async read() {
516
+ if (this._queuedChunk !== null) {
517
+ const chunk = this._queuedChunk;
518
+ this._queuedChunk = null;
519
+ return {
520
+ value: chunk,
521
+ done: false
522
+ };
623
523
  }
624
- }, {
625
- key: "read",
626
- value: function () {
627
- var _read2 = _asyncToGenerator(
628
- /*#__PURE__*/
629
- _regenerator["default"].mark(function _callee2() {
630
- var chunk, requestCapability;
631
- return _regenerator["default"].wrap(function _callee2$(_context2) {
632
- while (1) {
633
- switch (_context2.prev = _context2.next) {
634
- case 0:
635
- if (!(this._queuedChunk !== null)) {
636
- _context2.next = 4;
637
- break;
638
- }
639
-
640
- chunk = this._queuedChunk;
641
- this._queuedChunk = null;
642
- return _context2.abrupt("return", {
643
- value: chunk,
644
- done: false
645
- });
646
-
647
- case 4:
648
- if (!this._done) {
649
- _context2.next = 6;
650
- break;
651
- }
652
-
653
- return _context2.abrupt("return", {
654
- value: undefined,
655
- done: true
656
- });
657
-
658
- case 6:
659
- requestCapability = (0, _util.createPromiseCapability)();
660
-
661
- this._requests.push(requestCapability);
662
-
663
- return _context2.abrupt("return", requestCapability.promise);
664
-
665
- case 9:
666
- case "end":
667
- return _context2.stop();
668
- }
669
- }
670
- }, _callee2, this);
671
- }));
672
-
673
- function read() {
674
- return _read2.apply(this, arguments);
675
- }
676
524
 
677
- return read;
678
- }()
679
- }, {
680
- key: "cancel",
681
- value: function cancel(reason) {
682
- this._done = true;
525
+ if (this._done) {
526
+ return {
527
+ value: undefined,
528
+ done: true
529
+ };
530
+ }
683
531
 
684
- this._requests.forEach(function (requestCapability) {
685
- requestCapability.resolve({
686
- value: undefined,
687
- done: true
688
- });
689
- });
532
+ const requestCapability = (0, _util.createPromiseCapability)();
690
533
 
691
- this._requests = [];
534
+ this._requests.push(requestCapability);
692
535
 
693
- if (this._manager.isPendingRequest(this._requestId)) {
694
- this._manager.abortRequest(this._requestId);
695
- }
536
+ return requestCapability.promise;
537
+ }
696
538
 
697
- this._close();
698
- }
699
- }, {
700
- key: "isStreamingSupported",
701
- get: function get() {
702
- return false;
539
+ cancel(reason) {
540
+ this._done = true;
541
+
542
+ this._requests.forEach(function (requestCapability) {
543
+ requestCapability.resolve({
544
+ value: undefined,
545
+ done: true
546
+ });
547
+ });
548
+
549
+ this._requests = [];
550
+
551
+ if (this._manager.isPendingRequest(this._requestId)) {
552
+ this._manager.abortRequest(this._requestId);
703
553
  }
704
- }]);
705
554
 
706
- return PDFNetworkStreamRangeRequestReader;
707
- }();
555
+ this._close();
556
+ }
557
+
558
+ }