pdfjs-dist 2.0.943 → 2.1.266

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 (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. package/lib/web/dom_events.js +0 -140
package/lib/core/obj.js CHANGED
@@ -19,76 +19,100 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.FileSpec = exports.XRef = exports.ObjectLoader = exports.Catalog = undefined;
27
+ exports.FileSpec = exports.XRef = exports.ObjectLoader = exports.Catalog = void 0;
28
28
 
29
- var _regenerator = require('babel-runtime/regenerator');
29
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
30
 
31
- var _regenerator2 = _interopRequireDefault(_regenerator);
31
+ var _util = require("../shared/util");
32
32
 
33
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
33
+ var _primitives = require("./primitives");
34
34
 
35
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
35
+ var _parser = require("./parser");
36
36
 
37
- var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
37
+ var _chunked_stream = require("./chunked_stream");
38
38
 
39
- var _util = require('../shared/util');
39
+ var _crypto = require("./crypto");
40
40
 
41
- var _primitives = require('./primitives');
41
+ var _colorspace = require("./colorspace");
42
42
 
43
- var _parser = require('./parser');
43
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
44
 
45
- var _chunked_stream = require('./chunked_stream');
45
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
46
46
 
47
- var _crypto = require('./crypto');
47
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
48
48
 
49
- var _colorspace = require('./colorspace');
49
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
50
50
 
51
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
52
+
53
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
54
+
55
+ 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); } }
56
+
57
+ 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); }); }; }
58
+
59
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
60
+
61
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
52
62
 
53
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
63
+ function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
54
64
 
55
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
65
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
56
66
 
57
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
67
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
58
68
 
59
69
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
60
70
 
71
+ 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); } }
72
+
73
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
74
+
61
75
  function fetchDestination(dest) {
62
76
  return (0, _primitives.isDict)(dest) ? dest.get('D') : dest;
63
77
  }
64
78
 
65
- var Catalog = function () {
79
+ var Catalog =
80
+ /*#__PURE__*/
81
+ function () {
66
82
  function Catalog(pdfManager, xref) {
67
83
  _classCallCheck(this, Catalog);
68
84
 
69
85
  this.pdfManager = pdfManager;
70
86
  this.xref = xref;
71
87
  this.catDict = xref.getCatalogObj();
88
+
72
89
  if (!(0, _primitives.isDict)(this.catDict)) {
73
90
  throw new _util.FormatError('Catalog object is not a dictionary.');
74
91
  }
92
+
75
93
  this.fontCache = new _primitives.RefSetCache();
76
94
  this.builtInCMapCache = new Map();
77
95
  this.pageKidsCountCache = new _primitives.RefSetCache();
78
96
  }
79
97
 
80
98
  _createClass(Catalog, [{
81
- key: '_readDocumentOutline',
99
+ key: "_readDocumentOutline",
82
100
  value: function _readDocumentOutline() {
83
101
  var obj = this.catDict.get('Outlines');
102
+
84
103
  if (!(0, _primitives.isDict)(obj)) {
85
104
  return null;
86
105
  }
106
+
87
107
  obj = obj.getRaw('First');
108
+
88
109
  if (!(0, _primitives.isRef)(obj)) {
89
110
  return null;
90
111
  }
91
- var root = { items: [] };
112
+
113
+ var root = {
114
+ items: []
115
+ };
92
116
  var queue = [{
93
117
  obj: obj,
94
118
  parent: root
@@ -97,15 +121,19 @@ var Catalog = function () {
97
121
  processed.put(obj);
98
122
  var xref = this.xref,
99
123
  blackColor = new Uint8ClampedArray(3);
124
+
100
125
  while (queue.length > 0) {
101
126
  var i = queue.shift();
102
127
  var outlineDict = xref.fetchIfRef(i.obj);
128
+
103
129
  if (outlineDict === null) {
104
130
  continue;
105
131
  }
132
+
106
133
  if (!outlineDict.has('Title')) {
107
134
  throw new _util.FormatError('Invalid outline item encountered.');
108
135
  }
136
+
109
137
  var data = {
110
138
  url: null,
111
139
  dest: null
@@ -119,9 +147,11 @@ var Catalog = function () {
119
147
  var flags = outlineDict.get('F') || 0;
120
148
  var color = outlineDict.getArray('C');
121
149
  var rgbColor = blackColor;
150
+
122
151
  if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
123
152
  rgbColor = _colorspace.ColorSpace.singletons.rgb.getRgb(color, 0);
124
153
  }
154
+
125
155
  var outlineItem = {
126
156
  dest: data.dest,
127
157
  url: data.url,
@@ -136,6 +166,7 @@ var Catalog = function () {
136
166
  };
137
167
  i.parent.items.push(outlineItem);
138
168
  obj = outlineDict.getRaw('First');
169
+
139
170
  if ((0, _primitives.isRef)(obj) && !processed.has(obj)) {
140
171
  queue.push({
141
172
  obj: obj,
@@ -143,7 +174,9 @@ var Catalog = function () {
143
174
  });
144
175
  processed.put(obj);
145
176
  }
177
+
146
178
  obj = outlineDict.getRaw('Next');
179
+
147
180
  if ((0, _primitives.isRef)(obj) && !processed.has(obj)) {
148
181
  queue.push({
149
182
  obj: obj,
@@ -152,42 +185,53 @@ var Catalog = function () {
152
185
  processed.put(obj);
153
186
  }
154
187
  }
188
+
155
189
  return root.items.length > 0 ? root.items : null;
156
190
  }
157
191
  }, {
158
- key: '_readPermissions',
192
+ key: "_readPermissions",
159
193
  value: function _readPermissions() {
160
194
  var encrypt = this.xref.trailer.get('Encrypt');
195
+
161
196
  if (!(0, _primitives.isDict)(encrypt)) {
162
197
  return null;
163
198
  }
199
+
164
200
  var flags = encrypt.get('P');
201
+
165
202
  if (!(0, _util.isNum)(flags)) {
166
203
  return null;
167
204
  }
205
+
168
206
  flags += Math.pow(2, 32);
169
207
  var permissions = [];
208
+
170
209
  for (var key in _util.PermissionFlag) {
171
210
  var value = _util.PermissionFlag[key];
211
+
172
212
  if (flags & value) {
173
213
  permissions.push(value);
174
214
  }
175
215
  }
216
+
176
217
  return permissions;
177
218
  }
178
219
  }, {
179
- key: 'getDestination',
220
+ key: "getDestination",
180
221
  value: function getDestination(destinationId) {
181
222
  var obj = this._readDests();
223
+
182
224
  if (obj instanceof NameTree || obj instanceof _primitives.Dict) {
183
225
  return fetchDestination(obj.get(destinationId) || null);
184
226
  }
227
+
185
228
  return null;
186
229
  }
187
230
  }, {
188
- key: '_readDests',
231
+ key: "_readDests",
189
232
  value: function _readDests() {
190
233
  var obj = this.catDict.get('Names');
234
+
191
235
  if (obj && obj.has('Dests')) {
192
236
  return new NameTree(obj.getRaw('Dests'), this.xref);
193
237
  } else if (this.catDict.has('Dests')) {
@@ -195,12 +239,14 @@ var Catalog = function () {
195
239
  }
196
240
  }
197
241
  }, {
198
- key: '_readPageLabels',
242
+ key: "_readPageLabels",
199
243
  value: function _readPageLabels() {
200
244
  var obj = this.catDict.getRaw('PageLabels');
245
+
201
246
  if (!obj) {
202
247
  return null;
203
248
  }
249
+
204
250
  var pageLabels = new Array(this.numPages);
205
251
  var style = null,
206
252
  prefix = '';
@@ -208,51 +254,66 @@ var Catalog = function () {
208
254
  var nums = numberTree.getAll();
209
255
  var currentLabel = '',
210
256
  currentIndex = 1;
257
+
211
258
  for (var i = 0, ii = this.numPages; i < ii; i++) {
212
259
  if (i in nums) {
213
260
  var labelDict = nums[i];
261
+
214
262
  if (!(0, _primitives.isDict)(labelDict)) {
215
263
  throw new _util.FormatError('PageLabel is not a dictionary.');
216
264
  }
265
+
217
266
  if (labelDict.has('Type') && !(0, _primitives.isName)(labelDict.get('Type'), 'PageLabel')) {
218
267
  throw new _util.FormatError('Invalid type in PageLabel dictionary.');
219
268
  }
269
+
220
270
  if (labelDict.has('S')) {
221
271
  var s = labelDict.get('S');
272
+
222
273
  if (!(0, _primitives.isName)(s)) {
223
274
  throw new _util.FormatError('Invalid style in PageLabel dictionary.');
224
275
  }
276
+
225
277
  style = s.name;
226
278
  } else {
227
279
  style = null;
228
280
  }
281
+
229
282
  if (labelDict.has('P')) {
230
283
  var p = labelDict.get('P');
284
+
231
285
  if (!(0, _util.isString)(p)) {
232
286
  throw new _util.FormatError('Invalid prefix in PageLabel dictionary.');
233
287
  }
288
+
234
289
  prefix = (0, _util.stringToPDFString)(p);
235
290
  } else {
236
291
  prefix = '';
237
292
  }
293
+
238
294
  if (labelDict.has('St')) {
239
295
  var st = labelDict.get('St');
296
+
240
297
  if (!(Number.isInteger(st) && st >= 1)) {
241
298
  throw new _util.FormatError('Invalid start in PageLabel dictionary.');
242
299
  }
300
+
243
301
  currentIndex = st;
244
302
  } else {
245
303
  currentIndex = 1;
246
304
  }
247
305
  }
306
+
248
307
  switch (style) {
249
308
  case 'D':
250
309
  currentLabel = currentIndex;
251
310
  break;
311
+
252
312
  case 'R':
253
313
  case 'r':
254
314
  currentLabel = (0, _util.toRomanNumerals)(currentIndex, style === 'r');
255
315
  break;
316
+
256
317
  case 'A':
257
318
  case 'a':
258
319
  var LIMIT = 26;
@@ -262,24 +323,67 @@ var Catalog = function () {
262
323
  var letterIndex = currentIndex - 1;
263
324
  var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
264
325
  var charBuf = [];
326
+
265
327
  for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
266
328
  charBuf.push(character);
267
329
  }
330
+
268
331
  currentLabel = charBuf.join('');
269
332
  break;
333
+
270
334
  default:
271
335
  if (style) {
272
- throw new _util.FormatError('Invalid style "' + style + '" in PageLabel dictionary.');
336
+ throw new _util.FormatError("Invalid style \"".concat(style, "\" in PageLabel dictionary."));
273
337
  }
338
+
274
339
  currentLabel = '';
275
340
  }
341
+
276
342
  pageLabels[i] = prefix + currentLabel;
277
343
  currentIndex++;
278
344
  }
345
+
279
346
  return pageLabels;
280
347
  }
281
348
  }, {
282
- key: 'cleanup',
349
+ key: "fontFallback",
350
+ value: function fontFallback(id, handler) {
351
+ var promises = [];
352
+ this.fontCache.forEach(function (promise) {
353
+ promises.push(promise);
354
+ });
355
+ return Promise.all(promises).then(function (translatedFonts) {
356
+ var _iteratorNormalCompletion = true;
357
+ var _didIteratorError = false;
358
+ var _iteratorError = undefined;
359
+
360
+ try {
361
+ for (var _iterator = translatedFonts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
362
+ var translatedFont = _step.value;
363
+
364
+ if (translatedFont.loadedName === id) {
365
+ translatedFont.fallback(handler);
366
+ return;
367
+ }
368
+ }
369
+ } catch (err) {
370
+ _didIteratorError = true;
371
+ _iteratorError = err;
372
+ } finally {
373
+ try {
374
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
375
+ _iterator.return();
376
+ }
377
+ } finally {
378
+ if (_didIteratorError) {
379
+ throw _iteratorError;
380
+ }
381
+ }
382
+ }
383
+ });
384
+ }
385
+ }, {
386
+ key: "cleanup",
283
387
  value: function cleanup() {
284
388
  var _this = this;
285
389
 
@@ -293,41 +397,50 @@ var Catalog = function () {
293
397
  var font = translatedFonts[i].dict;
294
398
  delete font.translated;
295
399
  }
400
+
296
401
  _this.fontCache.clear();
402
+
297
403
  _this.builtInCMapCache.clear();
298
404
  });
299
405
  }
300
406
  }, {
301
- key: 'getPageDict',
407
+ key: "getPageDict",
302
408
  value: function getPageDict(pageIndex) {
303
409
  var capability = (0, _util.createPromiseCapability)();
304
410
  var nodesToVisit = [this.catDict.getRaw('Pages')];
305
411
  var xref = this.xref,
306
412
  pageKidsCountCache = this.pageKidsCountCache;
307
- var count = void 0,
413
+ var count,
308
414
  currentPageIndex = 0;
415
+
309
416
  function next() {
310
417
  var _loop = function _loop() {
311
418
  var currentNode = nodesToVisit.pop();
419
+
312
420
  if ((0, _primitives.isRef)(currentNode)) {
313
421
  count = pageKidsCountCache.get(currentNode);
422
+
314
423
  if (count > 0 && currentPageIndex + count < pageIndex) {
315
424
  currentPageIndex += count;
316
- return 'continue';
425
+ return "continue";
317
426
  }
427
+
318
428
  xref.fetchAsync(currentNode).then(function (obj) {
319
429
  if ((0, _primitives.isDict)(obj, 'Page') || (0, _primitives.isDict)(obj) && !obj.has('Kids')) {
320
430
  if (pageIndex === currentPageIndex) {
321
431
  if (currentNode && !pageKidsCountCache.has(currentNode)) {
322
432
  pageKidsCountCache.put(currentNode, 1);
323
433
  }
434
+
324
435
  capability.resolve([obj, currentNode]);
325
436
  } else {
326
437
  currentPageIndex++;
327
438
  next();
328
439
  }
440
+
329
441
  return;
330
442
  }
443
+
331
444
  nodesToVisit.push(obj);
332
445
  next();
333
446
  }, capability.reject);
@@ -335,24 +448,31 @@ var Catalog = function () {
335
448
  v: void 0
336
449
  };
337
450
  }
451
+
338
452
  if (!(0, _primitives.isDict)(currentNode)) {
339
453
  capability.reject(new _util.FormatError('Page dictionary kid reference points to wrong type of object.'));
340
454
  return {
341
455
  v: void 0
342
456
  };
343
457
  }
458
+
344
459
  count = currentNode.get('Count');
460
+
345
461
  if (Number.isInteger(count) && count >= 0) {
346
462
  var objId = currentNode.objId;
463
+
347
464
  if (objId && !pageKidsCountCache.has(objId)) {
348
465
  pageKidsCountCache.put(objId, count);
349
466
  }
467
+
350
468
  if (currentPageIndex + count <= pageIndex) {
351
469
  currentPageIndex += count;
352
- return 'continue';
470
+ return "continue";
353
471
  }
354
472
  }
473
+
355
474
  var kids = currentNode.get('Kids');
475
+
356
476
  if (!Array.isArray(kids)) {
357
477
  if ((0, _primitives.isName)(currentNode.get('Type'), 'Page') || !currentNode.has('Type') && currentNode.has('Contents')) {
358
478
  if (currentPageIndex === pageIndex) {
@@ -361,14 +481,17 @@ var Catalog = function () {
361
481
  v: void 0
362
482
  };
363
483
  }
484
+
364
485
  currentPageIndex++;
365
- return 'continue';
486
+ return "continue";
366
487
  }
488
+
367
489
  capability.reject(new _util.FormatError('Page dictionary kids object is not an array.'));
368
490
  return {
369
491
  v: void 0
370
492
  };
371
493
  }
494
+
372
495
  for (var last = kids.length - 1; last >= 0; last--) {
373
496
  nodesToVisit.push(kids[last]);
374
497
  }
@@ -378,64 +501,78 @@ var Catalog = function () {
378
501
  var _ret = _loop();
379
502
 
380
503
  switch (_ret) {
381
- case 'continue':
504
+ case "continue":
382
505
  continue;
383
506
 
384
507
  default:
385
- if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
508
+ if (_typeof(_ret) === "object") return _ret.v;
386
509
  }
387
510
  }
388
- capability.reject(new Error('Page index ' + pageIndex + ' not found.'));
511
+
512
+ capability.reject(new Error("Page index ".concat(pageIndex, " not found.")));
389
513
  }
514
+
390
515
  next();
391
516
  return capability.promise;
392
517
  }
393
518
  }, {
394
- key: 'getPageIndex',
519
+ key: "getPageIndex",
395
520
  value: function getPageIndex(pageRef) {
396
521
  var xref = this.xref;
522
+
397
523
  function pagesBeforeRef(kidRef) {
398
524
  var total = 0,
399
- parentRef = void 0;
525
+ parentRef;
400
526
  return xref.fetchAsync(kidRef).then(function (node) {
401
527
  if ((0, _primitives.isRefsEqual)(kidRef, pageRef) && !(0, _primitives.isDict)(node, 'Page') && !((0, _primitives.isDict)(node) && !node.has('Type') && node.has('Contents'))) {
402
528
  throw new _util.FormatError('The reference does not point to a /Page dictionary.');
403
529
  }
530
+
404
531
  if (!node) {
405
532
  return null;
406
533
  }
534
+
407
535
  if (!(0, _primitives.isDict)(node)) {
408
536
  throw new _util.FormatError('Node must be a dictionary.');
409
537
  }
538
+
410
539
  parentRef = node.getRaw('Parent');
411
540
  return node.getAsync('Parent');
412
541
  }).then(function (parent) {
413
542
  if (!parent) {
414
543
  return null;
415
544
  }
545
+
416
546
  if (!(0, _primitives.isDict)(parent)) {
417
547
  throw new _util.FormatError('Parent must be a dictionary.');
418
548
  }
549
+
419
550
  return parent.getAsync('Kids');
420
551
  }).then(function (kids) {
421
552
  if (!kids) {
422
553
  return null;
423
554
  }
555
+
424
556
  var kidPromises = [];
425
557
  var found = false;
558
+
426
559
  for (var i = 0, ii = kids.length; i < ii; i++) {
427
560
  var kid = kids[i];
561
+
428
562
  if (!(0, _primitives.isRef)(kid)) {
429
563
  throw new _util.FormatError('Kid must be a reference.');
430
564
  }
565
+
431
566
  if ((0, _primitives.isRefsEqual)(kid, kidRef)) {
432
567
  found = true;
433
568
  break;
434
569
  }
570
+
435
571
  kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
436
572
  if (!(0, _primitives.isDict)(kid)) {
437
573
  throw new _util.FormatError('Kid node must be a dictionary.');
438
574
  }
575
+
439
576
  if (kid.has('Count')) {
440
577
  total += kid.get('Count');
441
578
  } else {
@@ -443,15 +580,19 @@ var Catalog = function () {
443
580
  }
444
581
  }));
445
582
  }
583
+
446
584
  if (!found) {
447
585
  throw new _util.FormatError('Kid reference not found in parent\'s kids.');
448
586
  }
587
+
449
588
  return Promise.all(kidPromises).then(function () {
450
589
  return [total, parentRef];
451
590
  });
452
591
  });
453
592
  }
593
+
454
594
  var total = 0;
595
+
455
596
  function next(ref) {
456
597
  return pagesBeforeRef(ref).then(function (args) {
457
598
  if (!args) {
@@ -466,21 +607,26 @@ var Catalog = function () {
466
607
  return next(parentRef);
467
608
  });
468
609
  }
610
+
469
611
  return next(pageRef);
470
612
  }
471
613
  }, {
472
- key: 'metadata',
614
+ key: "metadata",
473
615
  get: function get() {
474
616
  var streamRef = this.catDict.getRaw('Metadata');
617
+
475
618
  if (!(0, _primitives.isRef)(streamRef)) {
476
619
  return (0, _util.shadow)(this, 'metadata', null);
477
620
  }
621
+
478
622
  var suppressEncryption = !(this.xref.encrypt && this.xref.encrypt.encryptMetadata);
479
623
  var stream = this.xref.fetch(streamRef, suppressEncryption);
480
- var metadata = void 0;
624
+ var metadata;
625
+
481
626
  if (stream && (0, _primitives.isDict)(stream.dict)) {
482
627
  var type = stream.dict.get('Type');
483
628
  var subtype = stream.dict.get('Subtype');
629
+
484
630
  if ((0, _primitives.isName)(type, 'Metadata') && (0, _primitives.isName)(subtype, 'XML')) {
485
631
  try {
486
632
  metadata = (0, _util.stringToUTF8String)((0, _util.bytesToString)(stream.getBytes()));
@@ -488,65 +634,79 @@ var Catalog = function () {
488
634
  if (e instanceof _util.MissingDataException) {
489
635
  throw e;
490
636
  }
637
+
491
638
  (0, _util.info)('Skipping invalid metadata.');
492
639
  }
493
640
  }
494
641
  }
642
+
495
643
  return (0, _util.shadow)(this, 'metadata', metadata);
496
644
  }
497
645
  }, {
498
- key: 'toplevelPagesDict',
646
+ key: "toplevelPagesDict",
499
647
  get: function get() {
500
648
  var pagesObj = this.catDict.get('Pages');
649
+
501
650
  if (!(0, _primitives.isDict)(pagesObj)) {
502
651
  throw new _util.FormatError('Invalid top-level pages dictionary.');
503
652
  }
653
+
504
654
  return (0, _util.shadow)(this, 'toplevelPagesDict', pagesObj);
505
655
  }
506
656
  }, {
507
- key: 'documentOutline',
657
+ key: "documentOutline",
508
658
  get: function get() {
509
659
  var obj = null;
660
+
510
661
  try {
511
662
  obj = this._readDocumentOutline();
512
663
  } catch (ex) {
513
664
  if (ex instanceof _util.MissingDataException) {
514
665
  throw ex;
515
666
  }
667
+
516
668
  (0, _util.warn)('Unable to read document outline.');
517
669
  }
670
+
518
671
  return (0, _util.shadow)(this, 'documentOutline', obj);
519
672
  }
520
673
  }, {
521
- key: 'permissions',
674
+ key: "permissions",
522
675
  get: function get() {
523
676
  var permissions = null;
677
+
524
678
  try {
525
679
  permissions = this._readPermissions();
526
680
  } catch (ex) {
527
681
  if (ex instanceof _util.MissingDataException) {
528
682
  throw ex;
529
683
  }
684
+
530
685
  (0, _util.warn)('Unable to read permissions.');
531
686
  }
687
+
532
688
  return (0, _util.shadow)(this, 'permissions', permissions);
533
689
  }
534
690
  }, {
535
- key: 'numPages',
691
+ key: "numPages",
536
692
  get: function get() {
537
693
  var obj = this.toplevelPagesDict.get('Count');
694
+
538
695
  if (!Number.isInteger(obj)) {
539
696
  throw new _util.FormatError('Page count in top-level pages dictionary is not an integer.');
540
697
  }
698
+
541
699
  return (0, _util.shadow)(this, 'numPages', obj);
542
700
  }
543
701
  }, {
544
- key: 'destinations',
702
+ key: "destinations",
545
703
  get: function get() {
546
704
  var obj = this._readDests(),
547
705
  dests = Object.create(null);
706
+
548
707
  if (obj instanceof NameTree) {
549
708
  var names = obj.getAll();
709
+
550
710
  for (var name in names) {
551
711
  dests[name] = fetchDestination(names[name]);
552
712
  }
@@ -557,27 +717,32 @@ var Catalog = function () {
557
717
  }
558
718
  });
559
719
  }
720
+
560
721
  return (0, _util.shadow)(this, 'destinations', dests);
561
722
  }
562
723
  }, {
563
- key: 'pageLabels',
724
+ key: "pageLabels",
564
725
  get: function get() {
565
726
  var obj = null;
727
+
566
728
  try {
567
729
  obj = this._readPageLabels();
568
730
  } catch (ex) {
569
731
  if (ex instanceof _util.MissingDataException) {
570
732
  throw ex;
571
733
  }
734
+
572
735
  (0, _util.warn)('Unable to read page labels.');
573
736
  }
737
+
574
738
  return (0, _util.shadow)(this, 'pageLabels', obj);
575
739
  }
576
740
  }, {
577
- key: 'pageMode',
741
+ key: "pageMode",
578
742
  get: function get() {
579
743
  var obj = this.catDict.get('PageMode');
580
744
  var pageMode = 'UseNone';
745
+
581
746
  if ((0, _primitives.isName)(obj)) {
582
747
  switch (obj.name) {
583
748
  case 'UseNone':
@@ -589,83 +754,129 @@ var Catalog = function () {
589
754
  pageMode = obj.name;
590
755
  }
591
756
  }
757
+
592
758
  return (0, _util.shadow)(this, 'pageMode', pageMode);
593
759
  }
594
760
  }, {
595
- key: 'attachments',
761
+ key: "openActionDestination",
762
+ get: function get() {
763
+ var obj = this.catDict.get('OpenAction');
764
+ var openActionDest = null;
765
+
766
+ if ((0, _primitives.isDict)(obj)) {
767
+ var destDict = new _primitives.Dict(this.xref);
768
+ destDict.set('A', obj);
769
+ var resultObj = {
770
+ url: null,
771
+ dest: null
772
+ };
773
+ Catalog.parseDestDictionary({
774
+ destDict: destDict,
775
+ resultObj: resultObj
776
+ });
777
+
778
+ if (Array.isArray(resultObj.dest)) {
779
+ openActionDest = resultObj.dest;
780
+ }
781
+ } else if (Array.isArray(obj)) {
782
+ openActionDest = obj;
783
+ }
784
+
785
+ return (0, _util.shadow)(this, 'openActionDestination', openActionDest);
786
+ }
787
+ }, {
788
+ key: "attachments",
596
789
  get: function get() {
597
790
  var obj = this.catDict.get('Names');
598
791
  var attachments = null;
792
+
599
793
  if (obj && obj.has('EmbeddedFiles')) {
600
794
  var nameTree = new NameTree(obj.getRaw('EmbeddedFiles'), this.xref);
601
795
  var names = nameTree.getAll();
796
+
602
797
  for (var name in names) {
603
798
  var fs = new FileSpec(names[name], this.xref);
799
+
604
800
  if (!attachments) {
605
801
  attachments = Object.create(null);
606
802
  }
803
+
607
804
  attachments[(0, _util.stringToPDFString)(name)] = fs.serializable;
608
805
  }
609
806
  }
807
+
610
808
  return (0, _util.shadow)(this, 'attachments', attachments);
611
809
  }
612
810
  }, {
613
- key: 'javaScript',
811
+ key: "javaScript",
614
812
  get: function get() {
615
813
  var obj = this.catDict.get('Names');
616
814
  var javaScript = null;
815
+
617
816
  function appendIfJavaScriptDict(jsDict) {
618
817
  var type = jsDict.get('S');
818
+
619
819
  if (!(0, _primitives.isName)(type, 'JavaScript')) {
620
820
  return;
621
821
  }
822
+
622
823
  var js = jsDict.get('JS');
824
+
623
825
  if ((0, _primitives.isStream)(js)) {
624
826
  js = (0, _util.bytesToString)(js.getBytes());
625
827
  } else if (!(0, _util.isString)(js)) {
626
828
  return;
627
829
  }
830
+
628
831
  if (!javaScript) {
629
832
  javaScript = [];
630
833
  }
834
+
631
835
  javaScript.push((0, _util.stringToPDFString)(js));
632
836
  }
837
+
633
838
  if (obj && obj.has('JavaScript')) {
634
839
  var nameTree = new NameTree(obj.getRaw('JavaScript'), this.xref);
635
840
  var names = nameTree.getAll();
841
+
636
842
  for (var name in names) {
637
843
  var jsDict = names[name];
844
+
638
845
  if ((0, _primitives.isDict)(jsDict)) {
639
846
  appendIfJavaScriptDict(jsDict);
640
847
  }
641
848
  }
642
849
  }
850
+
643
851
  var openActionDict = this.catDict.get('OpenAction');
852
+
644
853
  if ((0, _primitives.isDict)(openActionDict, 'Action')) {
645
854
  var actionType = openActionDict.get('S');
855
+
646
856
  if ((0, _primitives.isName)(actionType, 'Named')) {
647
857
  var action = openActionDict.get('N');
858
+
648
859
  if ((0, _primitives.isName)(action, 'Print')) {
649
860
  if (!javaScript) {
650
861
  javaScript = [];
651
862
  }
863
+
652
864
  javaScript.push('print({});');
653
865
  }
654
866
  } else {
655
867
  appendIfJavaScriptDict(openActionDict);
656
868
  }
657
869
  }
870
+
658
871
  return (0, _util.shadow)(this, 'javaScript', javaScript);
659
872
  }
660
873
  }], [{
661
- key: 'parseDestDictionary',
874
+ key: "parseDestDictionary",
662
875
  value: function parseDestDictionary(params) {
663
876
  function addDefaultProtocolToUrl(url) {
664
- if (url.indexOf('www.') === 0) {
665
- return 'http://' + url;
666
- }
667
- return url;
877
+ return url.startsWith('www.') ? "http://".concat(url) : url;
668
878
  }
879
+
669
880
  function tryConvertUrlEncoding(url) {
670
881
  try {
671
882
  return (0, _util.stringToUTF8String)(url);
@@ -673,57 +884,76 @@ var Catalog = function () {
673
884
  return url;
674
885
  }
675
886
  }
887
+
676
888
  var destDict = params.destDict;
889
+
677
890
  if (!(0, _primitives.isDict)(destDict)) {
678
891
  (0, _util.warn)('parseDestDictionary: `destDict` must be a dictionary.');
679
892
  return;
680
893
  }
894
+
681
895
  var resultObj = params.resultObj;
682
- if ((typeof resultObj === 'undefined' ? 'undefined' : _typeof(resultObj)) !== 'object') {
896
+
897
+ if (_typeof(resultObj) !== 'object') {
683
898
  (0, _util.warn)('parseDestDictionary: `resultObj` must be an object.');
684
899
  return;
685
900
  }
901
+
686
902
  var docBaseUrl = params.docBaseUrl || null;
687
903
  var action = destDict.get('A'),
688
- url = void 0,
689
- dest = void 0;
904
+ url,
905
+ dest;
906
+
690
907
  if (!(0, _primitives.isDict)(action) && destDict.has('Dest')) {
691
908
  action = destDict.get('Dest');
692
909
  }
910
+
693
911
  if ((0, _primitives.isDict)(action)) {
694
912
  var actionType = action.get('S');
913
+
695
914
  if (!(0, _primitives.isName)(actionType)) {
696
915
  (0, _util.warn)('parseDestDictionary: Invalid type in Action dictionary.');
697
916
  return;
698
917
  }
918
+
699
919
  var actionName = actionType.name;
920
+
700
921
  switch (actionName) {
701
922
  case 'URI':
702
923
  url = action.get('URI');
924
+
703
925
  if ((0, _primitives.isName)(url)) {
704
926
  url = '/' + url.name;
705
927
  } else if ((0, _util.isString)(url)) {
706
928
  url = addDefaultProtocolToUrl(url);
707
929
  }
930
+
708
931
  break;
932
+
709
933
  case 'GoTo':
710
934
  dest = action.get('D');
711
935
  break;
936
+
712
937
  case 'Launch':
713
938
  case 'GoToR':
714
939
  var urlDict = action.get('F');
940
+
715
941
  if ((0, _primitives.isDict)(urlDict)) {
716
942
  url = urlDict.get('F') || null;
717
943
  } else if ((0, _util.isString)(urlDict)) {
718
944
  url = urlDict;
719
945
  }
946
+
720
947
  var remoteDest = action.get('D');
948
+
721
949
  if (remoteDest) {
722
950
  if ((0, _primitives.isName)(remoteDest)) {
723
951
  remoteDest = remoteDest.name;
724
952
  }
953
+
725
954
  if ((0, _util.isString)(url)) {
726
955
  var baseUrl = url.split('#')[0];
956
+
727
957
  if ((0, _util.isString)(remoteDest)) {
728
958
  url = baseUrl + '#' + remoteDest;
729
959
  } else if (Array.isArray(remoteDest)) {
@@ -731,56 +961,74 @@ var Catalog = function () {
731
961
  }
732
962
  }
733
963
  }
964
+
734
965
  var newWindow = action.get('NewWindow');
966
+
735
967
  if ((0, _util.isBool)(newWindow)) {
736
968
  resultObj.newWindow = newWindow;
737
969
  }
970
+
738
971
  break;
972
+
739
973
  case 'Named':
740
974
  var namedAction = action.get('N');
975
+
741
976
  if ((0, _primitives.isName)(namedAction)) {
742
977
  resultObj.action = namedAction.name;
743
978
  }
979
+
744
980
  break;
981
+
745
982
  case 'JavaScript':
746
983
  var jsAction = action.get('JS');
747
- var js = void 0;
984
+ var js;
985
+
748
986
  if ((0, _primitives.isStream)(jsAction)) {
749
987
  js = (0, _util.bytesToString)(jsAction.getBytes());
750
988
  } else if ((0, _util.isString)(jsAction)) {
751
989
  js = jsAction;
752
990
  }
991
+
753
992
  if (js) {
754
993
  var URL_OPEN_METHODS = ['app.launchURL', 'window.open'];
755
994
  var regex = new RegExp('^\\s*(' + URL_OPEN_METHODS.join('|').split('.').join('\\.') + ')\\((?:\'|\")([^\'\"]*)(?:\'|\")(?:,\\s*(\\w+)\\)|\\))', 'i');
756
995
  var jsUrl = regex.exec((0, _util.stringToPDFString)(js));
996
+
757
997
  if (jsUrl && jsUrl[2]) {
758
998
  url = jsUrl[2];
999
+
759
1000
  if (jsUrl[3] === 'true' && jsUrl[1] === 'app.launchURL') {
760
1001
  resultObj.newWindow = true;
761
1002
  }
1003
+
762
1004
  break;
763
1005
  }
764
1006
  }
1007
+
765
1008
  default:
766
- (0, _util.warn)('parseDestDictionary: unsupported action type "' + actionName + '".');
1009
+ (0, _util.warn)("parseDestDictionary: unsupported action type \"".concat(actionName, "\"."));
767
1010
  break;
768
1011
  }
769
1012
  } else if (destDict.has('Dest')) {
770
1013
  dest = destDict.get('Dest');
771
1014
  }
1015
+
772
1016
  if ((0, _util.isString)(url)) {
773
1017
  url = tryConvertUrlEncoding(url);
774
1018
  var absoluteUrl = (0, _util.createValidAbsoluteUrl)(url, docBaseUrl);
1019
+
775
1020
  if (absoluteUrl) {
776
1021
  resultObj.url = absoluteUrl.href;
777
1022
  }
1023
+
778
1024
  resultObj.unsafeUrl = url;
779
1025
  }
1026
+
780
1027
  if (dest) {
781
1028
  if ((0, _primitives.isName)(dest)) {
782
1029
  dest = dest.name;
783
1030
  }
1031
+
784
1032
  if ((0, _util.isString)(dest) || Array.isArray(dest)) {
785
1033
  resultObj.dest = dest;
786
1034
  }
@@ -791,6 +1039,8 @@ var Catalog = function () {
791
1039
  return Catalog;
792
1040
  }();
793
1041
 
1042
+ exports.Catalog = Catalog;
1043
+
794
1044
  var XRef = function XRefClosure() {
795
1045
  function XRef(stream, pdfManager) {
796
1046
  this.stream = stream;
@@ -803,50 +1053,61 @@ var XRef = function XRefClosure() {
803
1053
  fontTypes: []
804
1054
  };
805
1055
  }
1056
+
806
1057
  XRef.prototype = {
807
1058
  setStartXRef: function XRef_setStartXRef(startXRef) {
808
1059
  this.startXRefQueue = [startXRef];
809
1060
  },
810
1061
  parse: function XRef_parse(recoveryMode) {
811
1062
  var trailerDict;
1063
+
812
1064
  if (!recoveryMode) {
813
1065
  trailerDict = this.readXRef();
814
1066
  } else {
815
1067
  (0, _util.warn)('Indexing all PDF objects');
816
1068
  trailerDict = this.indexObjects();
817
1069
  }
1070
+
818
1071
  trailerDict.assignXref(this);
819
1072
  this.trailer = trailerDict;
820
- var encrypt = void 0;
1073
+ var encrypt;
1074
+
821
1075
  try {
822
1076
  encrypt = trailerDict.get('Encrypt');
823
1077
  } catch (ex) {
824
1078
  if (ex instanceof _util.MissingDataException) {
825
1079
  throw ex;
826
1080
  }
827
- (0, _util.warn)('XRef.parse - Invalid "Encrypt" reference: "' + ex + '".');
1081
+
1082
+ (0, _util.warn)("XRef.parse - Invalid \"Encrypt\" reference: \"".concat(ex, "\"."));
828
1083
  }
1084
+
829
1085
  if ((0, _primitives.isDict)(encrypt)) {
830
1086
  var ids = trailerDict.get('ID');
831
1087
  var fileId = ids && ids.length ? ids[0] : '';
832
1088
  encrypt.suppressEncryption = true;
833
1089
  this.encrypt = new _crypto.CipherTransformFactory(encrypt, fileId, this.pdfManager.password);
834
1090
  }
835
- var root = void 0;
1091
+
1092
+ var root;
1093
+
836
1094
  try {
837
1095
  root = trailerDict.get('Root');
838
1096
  } catch (ex) {
839
1097
  if (ex instanceof _util.MissingDataException) {
840
1098
  throw ex;
841
1099
  }
842
- (0, _util.warn)('XRef.parse - Invalid "Root" reference: "' + ex + '".');
1100
+
1101
+ (0, _util.warn)("XRef.parse - Invalid \"Root\" reference: \"".concat(ex, "\"."));
843
1102
  }
1103
+
844
1104
  if ((0, _primitives.isDict)(root) && root.has('Pages')) {
845
1105
  this.root = root;
846
1106
  } else {
847
1107
  if (!recoveryMode) {
848
1108
  throw new _util.XRefParseException();
849
1109
  }
1110
+
850
1111
  throw new _util.FormatError('Invalid root reference');
851
1112
  }
852
1113
  },
@@ -859,17 +1120,23 @@ var XRef = function XRefClosure() {
859
1120
  parserBuf2: parser.buf2
860
1121
  };
861
1122
  }
1123
+
862
1124
  var obj = this.readXRefTable(parser);
1125
+
863
1126
  if (!(0, _primitives.isCmd)(obj, 'trailer')) {
864
1127
  throw new _util.FormatError('Invalid XRef table: could not find trailer dictionary');
865
1128
  }
1129
+
866
1130
  var dict = parser.getObj();
1131
+
867
1132
  if (!(0, _primitives.isDict)(dict) && dict.dict) {
868
1133
  dict = dict.dict;
869
1134
  }
1135
+
870
1136
  if (!(0, _primitives.isDict)(dict)) {
871
1137
  throw new _util.FormatError('Invalid XRef table: could not parse trailer dictionary');
872
1138
  }
1139
+
873
1140
  delete this.tableState;
874
1141
  return dict;
875
1142
  },
@@ -880,19 +1147,24 @@ var XRef = function XRefClosure() {
880
1147
  parser.buf1 = tableState.parserBuf1;
881
1148
  parser.buf2 = tableState.parserBuf2;
882
1149
  var obj;
1150
+
883
1151
  while (true) {
884
1152
  if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
885
1153
  if ((0, _primitives.isCmd)(obj = parser.getObj(), 'trailer')) {
886
1154
  break;
887
1155
  }
1156
+
888
1157
  tableState.firstEntryNum = obj;
889
1158
  tableState.entryCount = parser.getObj();
890
1159
  }
1160
+
891
1161
  var first = tableState.firstEntryNum;
892
1162
  var count = tableState.entryCount;
1163
+
893
1164
  if (!Number.isInteger(first) || !Number.isInteger(count)) {
894
1165
  throw new _util.FormatError('Invalid XRef table: wrong types in subsection header');
895
1166
  }
1167
+
896
1168
  for (var i = tableState.entryNum; i < count; i++) {
897
1169
  tableState.streamPos = stream.pos;
898
1170
  tableState.entryNum = i;
@@ -902,21 +1174,26 @@ var XRef = function XRefClosure() {
902
1174
  entry.offset = parser.getObj();
903
1175
  entry.gen = parser.getObj();
904
1176
  var type = parser.getObj();
1177
+
905
1178
  if ((0, _primitives.isCmd)(type, 'f')) {
906
1179
  entry.free = true;
907
1180
  } else if ((0, _primitives.isCmd)(type, 'n')) {
908
1181
  entry.uncompressed = true;
909
1182
  }
1183
+
910
1184
  if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {
911
- throw new _util.FormatError('Invalid entry in XRef subsection: ' + first + ', ' + count);
1185
+ throw new _util.FormatError("Invalid entry in XRef subsection: ".concat(first, ", ").concat(count));
912
1186
  }
1187
+
913
1188
  if (i === 0 && entry.free && first === 1) {
914
1189
  first = 0;
915
1190
  }
1191
+
916
1192
  if (!this.entries[i + first]) {
917
1193
  this.entries[i + first] = entry;
918
1194
  }
919
1195
  }
1196
+
920
1197
  tableState.entryNum = 0;
921
1198
  tableState.streamPos = stream.pos;
922
1199
  tableState.parserBuf1 = parser.buf1;
@@ -924,9 +1201,11 @@ var XRef = function XRefClosure() {
924
1201
  delete tableState.firstEntryNum;
925
1202
  delete tableState.entryCount;
926
1203
  }
1204
+
927
1205
  if (this.entries[0] && !this.entries[0].free) {
928
1206
  throw new _util.FormatError('Invalid XRef table: unexpected first object');
929
1207
  }
1208
+
930
1209
  return obj;
931
1210
  },
932
1211
  processXRefStream: function XRef_processXRefStream(stream) {
@@ -934,9 +1213,11 @@ var XRef = function XRefClosure() {
934
1213
  var streamParameters = stream.dict;
935
1214
  var byteWidths = streamParameters.get('W');
936
1215
  var range = streamParameters.get('Index');
1216
+
937
1217
  if (!range) {
938
1218
  range = [0, streamParameters.get('Size')];
939
1219
  }
1220
+
940
1221
  this.streamState = {
941
1222
  entryRanges: range,
942
1223
  byteWidths: byteWidths,
@@ -944,6 +1225,7 @@ var XRef = function XRefClosure() {
944
1225
  streamPos: stream.pos
945
1226
  };
946
1227
  }
1228
+
947
1229
  this.readXRefStream(stream);
948
1230
  delete this.streamState;
949
1231
  return stream.dict;
@@ -957,52 +1239,67 @@ var XRef = function XRefClosure() {
957
1239
  var offsetFieldWidth = byteWidths[1];
958
1240
  var generationFieldWidth = byteWidths[2];
959
1241
  var entryRanges = streamState.entryRanges;
1242
+
960
1243
  while (entryRanges.length > 0) {
961
1244
  var first = entryRanges[0];
962
1245
  var n = entryRanges[1];
1246
+
963
1247
  if (!Number.isInteger(first) || !Number.isInteger(n)) {
964
- throw new _util.FormatError('Invalid XRef range fields: ' + first + ', ' + n);
1248
+ throw new _util.FormatError("Invalid XRef range fields: ".concat(first, ", ").concat(n));
965
1249
  }
1250
+
966
1251
  if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) {
967
- throw new _util.FormatError('Invalid XRef entry fields length: ' + first + ', ' + n);
1252
+ throw new _util.FormatError("Invalid XRef entry fields length: ".concat(first, ", ").concat(n));
968
1253
  }
1254
+
969
1255
  for (i = streamState.entryNum; i < n; ++i) {
970
1256
  streamState.entryNum = i;
971
1257
  streamState.streamPos = stream.pos;
972
1258
  var type = 0,
973
1259
  offset = 0,
974
1260
  generation = 0;
1261
+
975
1262
  for (j = 0; j < typeFieldWidth; ++j) {
976
1263
  type = type << 8 | stream.getByte();
977
1264
  }
1265
+
978
1266
  if (typeFieldWidth === 0) {
979
1267
  type = 1;
980
1268
  }
1269
+
981
1270
  for (j = 0; j < offsetFieldWidth; ++j) {
982
1271
  offset = offset << 8 | stream.getByte();
983
1272
  }
1273
+
984
1274
  for (j = 0; j < generationFieldWidth; ++j) {
985
1275
  generation = generation << 8 | stream.getByte();
986
1276
  }
1277
+
987
1278
  var entry = {};
988
1279
  entry.offset = offset;
989
1280
  entry.gen = generation;
1281
+
990
1282
  switch (type) {
991
1283
  case 0:
992
1284
  entry.free = true;
993
1285
  break;
1286
+
994
1287
  case 1:
995
1288
  entry.uncompressed = true;
996
1289
  break;
1290
+
997
1291
  case 2:
998
1292
  break;
1293
+
999
1294
  default:
1000
- throw new _util.FormatError('Invalid XRef entry type: ' + type);
1295
+ throw new _util.FormatError("Invalid XRef entry type: ".concat(type));
1001
1296
  }
1297
+
1002
1298
  if (!this.entries[first + i]) {
1003
1299
  this.entries[first + i] = entry;
1004
1300
  }
1005
1301
  }
1302
+
1006
1303
  streamState.entryNum = 0;
1007
1304
  streamState.streamPos = stream.pos;
1008
1305
  entryRanges.splice(0, 2);
@@ -1015,38 +1312,49 @@ var XRef = function XRefClosure() {
1015
1312
  SPACE = 0x20;
1016
1313
  var PERCENT = 0x25,
1017
1314
  LT = 0x3C;
1315
+
1018
1316
  function readToken(data, offset) {
1019
1317
  var token = '',
1020
1318
  ch = data[offset];
1319
+
1021
1320
  while (ch !== LF && ch !== CR && ch !== LT) {
1022
1321
  if (++offset >= data.length) {
1023
1322
  break;
1024
1323
  }
1324
+
1025
1325
  token += String.fromCharCode(ch);
1026
1326
  ch = data[offset];
1027
1327
  }
1328
+
1028
1329
  return token;
1029
1330
  }
1331
+
1030
1332
  function skipUntil(data, offset, what) {
1031
1333
  var length = what.length,
1032
1334
  dataLength = data.length;
1033
1335
  var skipped = 0;
1336
+
1034
1337
  while (offset < dataLength) {
1035
1338
  var i = 0;
1339
+
1036
1340
  while (i < length && data[offset + i] === what[i]) {
1037
1341
  ++i;
1038
1342
  }
1343
+
1039
1344
  if (i >= length) {
1040
1345
  break;
1041
1346
  }
1347
+
1042
1348
  offset++;
1043
1349
  skipped++;
1044
1350
  }
1351
+
1045
1352
  return skipped;
1046
1353
  }
1354
+
1047
1355
  var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
1048
1356
  var endobjRegExp = /\bendobj[\b\s]$/;
1049
- var nestedObjRegExp = /\s+(\d+\s+\d+\s+obj[\b\s])$/;
1357
+ var nestedObjRegExp = /\s+(\d+\s+\d+\s+obj[\b\s<])$/;
1050
1358
  var CHECK_CONTENT_LENGTH = 25;
1051
1359
  var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
1052
1360
  var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]);
@@ -1060,132 +1368,174 @@ var XRef = function XRefClosure() {
1060
1368
  length = buffer.length;
1061
1369
  var trailers = [],
1062
1370
  xrefStms = [];
1371
+
1063
1372
  while (position < length) {
1064
1373
  var ch = buffer[position];
1374
+
1065
1375
  if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
1066
1376
  ++position;
1067
1377
  continue;
1068
1378
  }
1379
+
1069
1380
  if (ch === PERCENT) {
1070
1381
  do {
1071
1382
  ++position;
1383
+
1072
1384
  if (position >= length) {
1073
1385
  break;
1074
1386
  }
1387
+
1075
1388
  ch = buffer[position];
1076
1389
  } while (ch !== LF && ch !== CR);
1390
+
1077
1391
  continue;
1078
1392
  }
1393
+
1079
1394
  var token = readToken(buffer, position);
1080
1395
  var m;
1081
- if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
1396
+
1397
+ if (token.startsWith('xref') && (token.length === 4 || /\s/.test(token[4]))) {
1082
1398
  position += skipUntil(buffer, position, trailerBytes);
1083
1399
  trailers.push(position);
1084
1400
  position += skipUntil(buffer, position, startxrefBytes);
1085
1401
  } else if (m = objRegExp.exec(token)) {
1086
- if (typeof this.entries[m[1]] === 'undefined') {
1087
- this.entries[m[1]] = {
1402
+ var num = m[1] | 0,
1403
+ gen = m[2] | 0;
1404
+
1405
+ if (typeof this.entries[num] === 'undefined') {
1406
+ this.entries[num] = {
1088
1407
  offset: position - stream.start,
1089
- gen: m[2] | 0,
1408
+ gen: gen,
1090
1409
  uncompressed: true
1091
1410
  };
1092
1411
  }
1412
+
1093
1413
  var contentLength = void 0,
1094
1414
  startPos = position + token.length;
1415
+
1095
1416
  while (startPos < buffer.length) {
1096
1417
  var endPos = startPos + skipUntil(buffer, startPos, objBytes) + 4;
1097
1418
  contentLength = endPos - position;
1098
1419
  var checkPos = Math.max(endPos - CHECK_CONTENT_LENGTH, startPos);
1099
1420
  var tokenStr = (0, _util.bytesToString)(buffer.subarray(checkPos, endPos));
1421
+
1100
1422
  if (endobjRegExp.test(tokenStr)) {
1101
1423
  break;
1102
1424
  } else {
1103
1425
  var objToken = nestedObjRegExp.exec(tokenStr);
1426
+
1104
1427
  if (objToken && objToken[1]) {
1105
1428
  (0, _util.warn)('indexObjects: Found new "obj" inside of another "obj", ' + 'caused by missing "endobj" -- trying to recover.');
1106
1429
  contentLength -= objToken[1].length;
1107
1430
  break;
1108
1431
  }
1109
1432
  }
1433
+
1110
1434
  startPos = endPos;
1111
1435
  }
1436
+
1112
1437
  var content = buffer.subarray(position, position + contentLength);
1113
1438
  var xrefTagOffset = skipUntil(content, 0, xrefBytes);
1439
+
1114
1440
  if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
1115
1441
  xrefStms.push(position - stream.start);
1116
1442
  this.xrefstms[position - stream.start] = 1;
1117
1443
  }
1444
+
1118
1445
  position += contentLength;
1119
- } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
1446
+ } else if (token.startsWith('trailer') && (token.length === 7 || /\s/.test(token[7]))) {
1120
1447
  trailers.push(position);
1121
1448
  position += skipUntil(buffer, position, startxrefBytes);
1122
1449
  } else {
1123
1450
  position += token.length + 1;
1124
1451
  }
1125
1452
  }
1453
+
1126
1454
  var i, ii;
1455
+
1127
1456
  for (i = 0, ii = xrefStms.length; i < ii; ++i) {
1128
1457
  this.startXRefQueue.push(xrefStms[i]);
1129
1458
  this.readXRef(true);
1130
1459
  }
1131
- var trailerDict = void 0;
1460
+
1461
+ var trailerDict;
1462
+
1132
1463
  for (i = 0, ii = trailers.length; i < ii; ++i) {
1133
1464
  stream.pos = trailers[i];
1134
1465
  var parser = new _parser.Parser(new _parser.Lexer(stream), true, this, true);
1135
1466
  var obj = parser.getObj();
1467
+
1136
1468
  if (!(0, _primitives.isCmd)(obj, 'trailer')) {
1137
1469
  continue;
1138
1470
  }
1471
+
1139
1472
  var dict = parser.getObj();
1473
+
1140
1474
  if (!(0, _primitives.isDict)(dict)) {
1141
1475
  continue;
1142
1476
  }
1477
+
1143
1478
  var rootDict = void 0;
1479
+
1144
1480
  try {
1145
1481
  rootDict = dict.get('Root');
1146
1482
  } catch (ex) {
1147
1483
  if (ex instanceof _util.MissingDataException) {
1148
1484
  throw ex;
1149
1485
  }
1486
+
1150
1487
  continue;
1151
1488
  }
1489
+
1152
1490
  if (!(0, _primitives.isDict)(rootDict) || !rootDict.has('Pages')) {
1153
1491
  continue;
1154
1492
  }
1493
+
1155
1494
  if (dict.has('ID')) {
1156
1495
  return dict;
1157
1496
  }
1497
+
1158
1498
  trailerDict = dict;
1159
1499
  }
1500
+
1160
1501
  if (trailerDict) {
1161
1502
  return trailerDict;
1162
1503
  }
1504
+
1163
1505
  throw new _util.InvalidPDFException('Invalid PDF structure');
1164
1506
  },
1165
1507
  readXRef: function XRef_readXRef(recoveryMode) {
1166
1508
  var stream = this.stream;
1167
1509
  var startXRefParsedCache = Object.create(null);
1510
+
1168
1511
  try {
1169
1512
  while (this.startXRefQueue.length) {
1170
1513
  var startXRef = this.startXRefQueue[0];
1514
+
1171
1515
  if (startXRefParsedCache[startXRef]) {
1172
1516
  (0, _util.warn)('readXRef - skipping XRef table since it was already parsed.');
1173
1517
  this.startXRefQueue.shift();
1174
1518
  continue;
1175
1519
  }
1520
+
1176
1521
  startXRefParsedCache[startXRef] = true;
1177
1522
  stream.pos = startXRef + stream.start;
1178
1523
  var parser = new _parser.Parser(new _parser.Lexer(stream), true, this);
1179
1524
  var obj = parser.getObj();
1180
1525
  var dict;
1526
+
1181
1527
  if ((0, _primitives.isCmd)(obj, 'xref')) {
1182
1528
  dict = this.processXRefTable(parser);
1529
+
1183
1530
  if (!this.topDict) {
1184
1531
  this.topDict = dict;
1185
1532
  }
1533
+
1186
1534
  obj = dict.get('XRefStm');
1535
+
1187
1536
  if (Number.isInteger(obj)) {
1188
1537
  var pos = obj;
1538
+
1189
1539
  if (!(pos in this.xrefstms)) {
1190
1540
  this.xrefstms[pos] = 1;
1191
1541
  this.startXRefQueue.push(pos);
@@ -1195,164 +1545,216 @@ var XRef = function XRefClosure() {
1195
1545
  if (!Number.isInteger(parser.getObj()) || !(0, _primitives.isCmd)(parser.getObj(), 'obj') || !(0, _primitives.isStream)(obj = parser.getObj())) {
1196
1546
  throw new _util.FormatError('Invalid XRef stream');
1197
1547
  }
1548
+
1198
1549
  dict = this.processXRefStream(obj);
1550
+
1199
1551
  if (!this.topDict) {
1200
1552
  this.topDict = dict;
1201
1553
  }
1554
+
1202
1555
  if (!dict) {
1203
1556
  throw new _util.FormatError('Failed to read XRef stream');
1204
1557
  }
1205
1558
  } else {
1206
1559
  throw new _util.FormatError('Invalid XRef stream header');
1207
1560
  }
1561
+
1208
1562
  obj = dict.get('Prev');
1563
+
1209
1564
  if (Number.isInteger(obj)) {
1210
1565
  this.startXRefQueue.push(obj);
1211
1566
  } else if ((0, _primitives.isRef)(obj)) {
1212
1567
  this.startXRefQueue.push(obj.num);
1213
1568
  }
1569
+
1214
1570
  this.startXRefQueue.shift();
1215
1571
  }
1572
+
1216
1573
  return this.topDict;
1217
1574
  } catch (e) {
1218
1575
  if (e instanceof _util.MissingDataException) {
1219
1576
  throw e;
1220
1577
  }
1578
+
1221
1579
  (0, _util.info)('(while reading XRef): ' + e);
1222
1580
  }
1581
+
1223
1582
  if (recoveryMode) {
1224
1583
  return;
1225
1584
  }
1585
+
1226
1586
  throw new _util.XRefParseException();
1227
1587
  },
1228
1588
  getEntry: function XRef_getEntry(i) {
1229
1589
  var xrefEntry = this.entries[i];
1590
+
1230
1591
  if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
1231
1592
  return xrefEntry;
1232
1593
  }
1594
+
1233
1595
  return null;
1234
1596
  },
1235
1597
  fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
1236
1598
  if (!(0, _primitives.isRef)(obj)) {
1237
1599
  return obj;
1238
1600
  }
1601
+
1239
1602
  return this.fetch(obj, suppressEncryption);
1240
1603
  },
1241
1604
  fetch: function XRef_fetch(ref, suppressEncryption) {
1242
1605
  if (!(0, _primitives.isRef)(ref)) {
1243
1606
  throw new Error('ref object is not a reference');
1244
1607
  }
1608
+
1245
1609
  var num = ref.num;
1610
+
1246
1611
  if (num in this.cache) {
1247
1612
  var cacheEntry = this.cache[num];
1613
+
1248
1614
  if (cacheEntry instanceof _primitives.Dict && !cacheEntry.objId) {
1249
1615
  cacheEntry.objId = ref.toString();
1250
1616
  }
1617
+
1251
1618
  return cacheEntry;
1252
1619
  }
1620
+
1253
1621
  var xrefEntry = this.getEntry(num);
1622
+
1254
1623
  if (xrefEntry === null) {
1255
1624
  return this.cache[num] = null;
1256
1625
  }
1626
+
1257
1627
  if (xrefEntry.uncompressed) {
1258
1628
  xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
1259
1629
  } else {
1260
- xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
1630
+ xrefEntry = this.fetchCompressed(ref, xrefEntry, suppressEncryption);
1261
1631
  }
1632
+
1262
1633
  if ((0, _primitives.isDict)(xrefEntry)) {
1263
1634
  xrefEntry.objId = ref.toString();
1264
1635
  } else if ((0, _primitives.isStream)(xrefEntry)) {
1265
1636
  xrefEntry.dict.objId = ref.toString();
1266
1637
  }
1638
+
1267
1639
  return xrefEntry;
1268
1640
  },
1269
- fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
1641
+ fetchUncompressed: function fetchUncompressed(ref, xrefEntry) {
1642
+ var suppressEncryption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1270
1643
  var gen = ref.gen;
1271
1644
  var num = ref.num;
1645
+
1272
1646
  if (xrefEntry.gen !== gen) {
1273
- throw new _util.FormatError('inconsistent generation in XRef');
1647
+ throw new _util.XRefEntryException("Inconsistent generation in XRef: ".concat(ref));
1274
1648
  }
1649
+
1275
1650
  var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
1276
1651
  var parser = new _parser.Parser(new _parser.Lexer(stream), true, this);
1277
1652
  var obj1 = parser.getObj();
1278
1653
  var obj2 = parser.getObj();
1279
1654
  var obj3 = parser.getObj();
1655
+
1280
1656
  if (!Number.isInteger(obj1)) {
1281
1657
  obj1 = parseInt(obj1, 10);
1282
1658
  }
1659
+
1283
1660
  if (!Number.isInteger(obj2)) {
1284
1661
  obj2 = parseInt(obj2, 10);
1285
1662
  }
1663
+
1286
1664
  if (obj1 !== num || obj2 !== gen || !(0, _primitives.isCmd)(obj3)) {
1287
- throw new _util.FormatError('bad XRef entry');
1665
+ throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
1288
1666
  }
1667
+
1289
1668
  if (obj3.cmd !== 'obj') {
1290
- if (obj3.cmd.indexOf('obj') === 0) {
1669
+ if (obj3.cmd.startsWith('obj')) {
1291
1670
  num = parseInt(obj3.cmd.substring(3), 10);
1671
+
1292
1672
  if (!Number.isNaN(num)) {
1293
1673
  return num;
1294
1674
  }
1295
1675
  }
1296
- throw new _util.FormatError('bad XRef entry');
1676
+
1677
+ throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
1297
1678
  }
1679
+
1298
1680
  if (this.encrypt && !suppressEncryption) {
1299
1681
  xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
1300
1682
  } else {
1301
1683
  xrefEntry = parser.getObj();
1302
1684
  }
1685
+
1303
1686
  if (!(0, _primitives.isStream)(xrefEntry)) {
1304
1687
  this.cache[num] = xrefEntry;
1305
1688
  }
1689
+
1306
1690
  return xrefEntry;
1307
1691
  },
1308
- fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
1692
+ fetchCompressed: function fetchCompressed(ref, xrefEntry) {
1693
+ var suppressEncryption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1309
1694
  var tableOffset = xrefEntry.offset;
1310
1695
  var stream = this.fetch(new _primitives.Ref(tableOffset, 0));
1696
+
1311
1697
  if (!(0, _primitives.isStream)(stream)) {
1312
1698
  throw new _util.FormatError('bad ObjStm stream');
1313
1699
  }
1700
+
1314
1701
  var first = stream.dict.get('First');
1315
1702
  var n = stream.dict.get('N');
1703
+
1316
1704
  if (!Number.isInteger(first) || !Number.isInteger(n)) {
1317
1705
  throw new _util.FormatError('invalid first and n parameters for ObjStm stream');
1318
1706
  }
1707
+
1319
1708
  var parser = new _parser.Parser(new _parser.Lexer(stream), false, this);
1320
1709
  parser.allowStreams = true;
1321
1710
  var i,
1322
1711
  entries = [],
1323
1712
  num,
1324
1713
  nums = [];
1714
+
1325
1715
  for (i = 0; i < n; ++i) {
1326
1716
  num = parser.getObj();
1717
+
1327
1718
  if (!Number.isInteger(num)) {
1328
- throw new _util.FormatError('invalid object number in the ObjStm stream: ' + num);
1719
+ throw new _util.FormatError("invalid object number in the ObjStm stream: ".concat(num));
1329
1720
  }
1721
+
1330
1722
  nums.push(num);
1331
1723
  var offset = parser.getObj();
1724
+
1332
1725
  if (!Number.isInteger(offset)) {
1333
- throw new _util.FormatError('invalid object offset in the ObjStm stream: ' + offset);
1726
+ throw new _util.FormatError("invalid object offset in the ObjStm stream: ".concat(offset));
1334
1727
  }
1335
1728
  }
1729
+
1336
1730
  for (i = 0; i < n; ++i) {
1337
1731
  entries.push(parser.getObj());
1732
+
1338
1733
  if ((0, _primitives.isCmd)(parser.buf1, 'endobj')) {
1339
1734
  parser.shift();
1340
1735
  }
1736
+
1341
1737
  num = nums[i];
1342
1738
  var entry = this.entries[num];
1739
+
1343
1740
  if (entry && entry.offset === tableOffset && entry.gen === i) {
1344
1741
  this.cache[num] = entries[i];
1345
1742
  }
1346
1743
  }
1744
+
1347
1745
  xrefEntry = entries[xrefEntry.gen];
1746
+
1348
1747
  if (xrefEntry === undefined) {
1349
- throw new _util.FormatError('bad XRef entry for compressed object');
1748
+ throw new _util.XRefEntryException("Bad (compressed) XRef entry: ".concat(ref));
1350
1749
  }
1750
+
1351
1751
  return xrefEntry;
1352
1752
  },
1353
1753
  fetchIfRefAsync: function () {
1354
- var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(obj, suppressEncryption) {
1355
- return _regenerator2.default.wrap(function _callee$(_context) {
1754
+ var _fetchIfRefAsync = _asyncToGenerator(
1755
+ /*#__PURE__*/
1756
+ _regenerator.default.mark(function _callee(obj, suppressEncryption) {
1757
+ return _regenerator.default.wrap(function _callee$(_context) {
1356
1758
  while (1) {
1357
1759
  switch (_context.prev = _context.next) {
1358
1760
  case 0:
@@ -1361,13 +1763,13 @@ var XRef = function XRefClosure() {
1361
1763
  break;
1362
1764
  }
1363
1765
 
1364
- return _context.abrupt('return', obj);
1766
+ return _context.abrupt("return", obj);
1365
1767
 
1366
1768
  case 2:
1367
- return _context.abrupt('return', this.fetchAsync(obj, suppressEncryption));
1769
+ return _context.abrupt("return", this.fetchAsync(obj, suppressEncryption));
1368
1770
 
1369
1771
  case 3:
1370
- case 'end':
1772
+ case "end":
1371
1773
  return _context.stop();
1372
1774
  }
1373
1775
  }
@@ -1375,23 +1777,25 @@ var XRef = function XRefClosure() {
1375
1777
  }));
1376
1778
 
1377
1779
  function fetchIfRefAsync(_x, _x2) {
1378
- return _ref.apply(this, arguments);
1780
+ return _fetchIfRefAsync.apply(this, arguments);
1379
1781
  }
1380
1782
 
1381
1783
  return fetchIfRefAsync;
1382
1784
  }(),
1383
1785
  fetchAsync: function () {
1384
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2(ref, suppressEncryption) {
1385
- return _regenerator2.default.wrap(function _callee2$(_context2) {
1786
+ var _fetchAsync = _asyncToGenerator(
1787
+ /*#__PURE__*/
1788
+ _regenerator.default.mark(function _callee2(ref, suppressEncryption) {
1789
+ return _regenerator.default.wrap(function _callee2$(_context2) {
1386
1790
  while (1) {
1387
1791
  switch (_context2.prev = _context2.next) {
1388
1792
  case 0:
1389
1793
  _context2.prev = 0;
1390
- return _context2.abrupt('return', this.fetch(ref, suppressEncryption));
1794
+ return _context2.abrupt("return", this.fetch(ref, suppressEncryption));
1391
1795
 
1392
1796
  case 4:
1393
1797
  _context2.prev = 4;
1394
- _context2.t0 = _context2['catch'](0);
1798
+ _context2.t0 = _context2["catch"](0);
1395
1799
 
1396
1800
  if (_context2.t0 instanceof _util.MissingDataException) {
1397
1801
  _context2.next = 8;
@@ -1405,10 +1809,10 @@ var XRef = function XRefClosure() {
1405
1809
  return this.pdfManager.requestRange(_context2.t0.begin, _context2.t0.end);
1406
1810
 
1407
1811
  case 10:
1408
- return _context2.abrupt('return', this.fetchAsync(ref, suppressEncryption));
1812
+ return _context2.abrupt("return", this.fetchAsync(ref, suppressEncryption));
1409
1813
 
1410
1814
  case 11:
1411
- case 'end':
1815
+ case "end":
1412
1816
  return _context2.stop();
1413
1817
  }
1414
1818
  }
@@ -1416,12 +1820,11 @@ var XRef = function XRefClosure() {
1416
1820
  }));
1417
1821
 
1418
1822
  function fetchAsync(_x3, _x4) {
1419
- return _ref2.apply(this, arguments);
1823
+ return _fetchAsync.apply(this, arguments);
1420
1824
  }
1421
1825
 
1422
1826
  return fetchAsync;
1423
1827
  }(),
1424
-
1425
1828
  getCatalogObj: function XRef_getCatalogObj() {
1426
1829
  return this.root;
1427
1830
  }
@@ -1429,100 +1832,131 @@ var XRef = function XRefClosure() {
1429
1832
  return XRef;
1430
1833
  }();
1431
1834
 
1432
- var NameOrNumberTree = function () {
1835
+ exports.XRef = XRef;
1836
+
1837
+ var NameOrNumberTree =
1838
+ /*#__PURE__*/
1839
+ function () {
1433
1840
  function NameOrNumberTree(root, xref, type) {
1434
1841
  _classCallCheck(this, NameOrNumberTree);
1435
1842
 
1436
1843
  if (this.constructor === NameOrNumberTree) {
1437
1844
  (0, _util.unreachable)('Cannot initialize NameOrNumberTree.');
1438
1845
  }
1846
+
1439
1847
  this.root = root;
1440
1848
  this.xref = xref;
1441
1849
  this._type = type;
1442
1850
  }
1443
1851
 
1444
1852
  _createClass(NameOrNumberTree, [{
1445
- key: 'getAll',
1853
+ key: "getAll",
1446
1854
  value: function getAll() {
1447
1855
  var dict = Object.create(null);
1856
+
1448
1857
  if (!this.root) {
1449
1858
  return dict;
1450
1859
  }
1860
+
1451
1861
  var xref = this.xref;
1452
1862
  var processed = new _primitives.RefSet();
1453
1863
  processed.put(this.root);
1454
1864
  var queue = [this.root];
1865
+
1455
1866
  while (queue.length > 0) {
1456
1867
  var obj = xref.fetchIfRef(queue.shift());
1868
+
1457
1869
  if (!(0, _primitives.isDict)(obj)) {
1458
1870
  continue;
1459
1871
  }
1872
+
1460
1873
  if (obj.has('Kids')) {
1461
- var _kids = obj.get('Kids');
1462
- for (var i = 0, ii = _kids.length; i < ii; i++) {
1463
- var kid = _kids[i];
1874
+ var kids = obj.get('Kids');
1875
+
1876
+ for (var i = 0, ii = kids.length; i < ii; i++) {
1877
+ var kid = kids[i];
1878
+
1464
1879
  if (processed.has(kid)) {
1465
- throw new _util.FormatError('Duplicate entry in "' + this._type + '" tree.');
1880
+ throw new _util.FormatError("Duplicate entry in \"".concat(this._type, "\" tree."));
1466
1881
  }
1882
+
1467
1883
  queue.push(kid);
1468
1884
  processed.put(kid);
1469
1885
  }
1886
+
1470
1887
  continue;
1471
1888
  }
1889
+
1472
1890
  var entries = obj.get(this._type);
1891
+
1473
1892
  if (Array.isArray(entries)) {
1474
1893
  for (var _i2 = 0, _ii = entries.length; _i2 < _ii; _i2 += 2) {
1475
1894
  dict[xref.fetchIfRef(entries[_i2])] = xref.fetchIfRef(entries[_i2 + 1]);
1476
1895
  }
1477
1896
  }
1478
1897
  }
1898
+
1479
1899
  return dict;
1480
1900
  }
1481
1901
  }, {
1482
- key: 'get',
1902
+ key: "get",
1483
1903
  value: function get(key) {
1484
1904
  if (!this.root) {
1485
1905
  return null;
1486
1906
  }
1907
+
1487
1908
  var xref = this.xref;
1488
1909
  var kidsOrEntries = xref.fetchIfRef(this.root);
1489
1910
  var loopCount = 0;
1490
1911
  var MAX_LEVELS = 10;
1912
+
1491
1913
  while (kidsOrEntries.has('Kids')) {
1492
1914
  if (++loopCount > MAX_LEVELS) {
1493
- (0, _util.warn)('Search depth limit reached for "' + this._type + '" tree.');
1915
+ (0, _util.warn)("Search depth limit reached for \"".concat(this._type, "\" tree."));
1494
1916
  return null;
1495
1917
  }
1496
- var _kids2 = kidsOrEntries.get('Kids');
1497
- if (!Array.isArray(_kids2)) {
1918
+
1919
+ var kids = kidsOrEntries.get('Kids');
1920
+
1921
+ if (!Array.isArray(kids)) {
1498
1922
  return null;
1499
1923
  }
1924
+
1500
1925
  var l = 0,
1501
- r = _kids2.length - 1;
1926
+ r = kids.length - 1;
1927
+
1502
1928
  while (l <= r) {
1503
1929
  var m = l + r >> 1;
1504
- var kid = xref.fetchIfRef(_kids2[m]);
1930
+ var kid = xref.fetchIfRef(kids[m]);
1505
1931
  var limits = kid.get('Limits');
1932
+
1506
1933
  if (key < xref.fetchIfRef(limits[0])) {
1507
1934
  r = m - 1;
1508
1935
  } else if (key > xref.fetchIfRef(limits[1])) {
1509
1936
  l = m + 1;
1510
1937
  } else {
1511
- kidsOrEntries = xref.fetchIfRef(_kids2[m]);
1938
+ kidsOrEntries = xref.fetchIfRef(kids[m]);
1512
1939
  break;
1513
1940
  }
1514
1941
  }
1942
+
1515
1943
  if (l > r) {
1516
1944
  return null;
1517
1945
  }
1518
1946
  }
1947
+
1519
1948
  var entries = kidsOrEntries.get(this._type);
1949
+
1520
1950
  if (Array.isArray(entries)) {
1521
1951
  var _l = 0,
1522
1952
  _r = entries.length - 2;
1953
+
1523
1954
  while (_l <= _r) {
1524
- var _m = _l + _r & ~1;
1955
+ var tmp = _l + _r >> 1,
1956
+ _m = tmp + (tmp & 1);
1957
+
1525
1958
  var currentKey = xref.fetchIfRef(entries[_m]);
1959
+
1526
1960
  if (key < currentKey) {
1527
1961
  _r = _m - 2;
1528
1962
  } else if (key > currentKey) {
@@ -1531,7 +1965,19 @@ var NameOrNumberTree = function () {
1531
1965
  return xref.fetchIfRef(entries[_m + 1]);
1532
1966
  }
1533
1967
  }
1968
+
1969
+ (0, _util.info)("Falling back to an exhaustive search, for key \"".concat(key, "\", ") + "in \"".concat(this._type, "\" tree."));
1970
+
1971
+ for (var _m2 = 0, mm = entries.length; _m2 < mm; _m2 += 2) {
1972
+ var _currentKey = xref.fetchIfRef(entries[_m2]);
1973
+
1974
+ if (_currentKey === key) {
1975
+ (0, _util.warn)("The \"".concat(key, "\" key was found at an incorrect, ") + "i.e. out-of-order, position in \"".concat(this._type, "\" tree."));
1976
+ return xref.fetchIfRef(entries[_m2 + 1]);
1977
+ }
1978
+ }
1534
1979
  }
1980
+
1535
1981
  return null;
1536
1982
  }
1537
1983
  }]);
@@ -1539,25 +1985,29 @@ var NameOrNumberTree = function () {
1539
1985
  return NameOrNumberTree;
1540
1986
  }();
1541
1987
 
1542
- var NameTree = function (_NameOrNumberTree) {
1988
+ var NameTree =
1989
+ /*#__PURE__*/
1990
+ function (_NameOrNumberTree) {
1543
1991
  _inherits(NameTree, _NameOrNumberTree);
1544
1992
 
1545
1993
  function NameTree(root, xref) {
1546
1994
  _classCallCheck(this, NameTree);
1547
1995
 
1548
- return _possibleConstructorReturn(this, (NameTree.__proto__ || Object.getPrototypeOf(NameTree)).call(this, root, xref, 'Names'));
1996
+ return _possibleConstructorReturn(this, _getPrototypeOf(NameTree).call(this, root, xref, 'Names'));
1549
1997
  }
1550
1998
 
1551
1999
  return NameTree;
1552
2000
  }(NameOrNumberTree);
1553
2001
 
1554
- var NumberTree = function (_NameOrNumberTree2) {
2002
+ var NumberTree =
2003
+ /*#__PURE__*/
2004
+ function (_NameOrNumberTree2) {
1555
2005
  _inherits(NumberTree, _NameOrNumberTree2);
1556
2006
 
1557
2007
  function NumberTree(root, xref) {
1558
2008
  _classCallCheck(this, NumberTree);
1559
2009
 
1560
- return _possibleConstructorReturn(this, (NumberTree.__proto__ || Object.getPrototypeOf(NumberTree)).call(this, root, xref, 'Nums'));
2010
+ return _possibleConstructorReturn(this, _getPrototypeOf(NumberTree).call(this, root, xref, 'Nums'));
1561
2011
  }
1562
2012
 
1563
2013
  return NumberTree;
@@ -1568,21 +2018,28 @@ var FileSpec = function FileSpecClosure() {
1568
2018
  if (!root || !(0, _primitives.isDict)(root)) {
1569
2019
  return;
1570
2020
  }
2021
+
1571
2022
  this.xref = xref;
1572
2023
  this.root = root;
2024
+
1573
2025
  if (root.has('FS')) {
1574
2026
  this.fs = root.get('FS');
1575
2027
  }
2028
+
1576
2029
  this.description = root.has('Desc') ? (0, _util.stringToPDFString)(root.get('Desc')) : '';
2030
+
1577
2031
  if (root.has('RF')) {
1578
2032
  (0, _util.warn)('Related file specifications are not supported');
1579
2033
  }
2034
+
1580
2035
  this.contentAvailable = true;
2036
+
1581
2037
  if (!root.has('EF')) {
1582
2038
  this.contentAvailable = false;
1583
2039
  (0, _util.warn)('Non-embedded file specifications are not supported');
1584
2040
  }
1585
2041
  }
2042
+
1586
2043
  function pickPlatformItem(dict) {
1587
2044
  if (dict.has('UF')) {
1588
2045
  return dict.get('UF');
@@ -1595,27 +2052,35 @@ var FileSpec = function FileSpecClosure() {
1595
2052
  } else if (dict.has('DOS')) {
1596
2053
  return dict.get('DOS');
1597
2054
  }
2055
+
1598
2056
  return null;
1599
2057
  }
2058
+
1600
2059
  FileSpec.prototype = {
1601
2060
  get filename() {
1602
2061
  if (!this._filename && this.root) {
1603
2062
  var filename = pickPlatformItem(this.root) || 'unnamed';
1604
2063
  this._filename = (0, _util.stringToPDFString)(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
1605
2064
  }
2065
+
1606
2066
  return this._filename;
1607
2067
  },
2068
+
1608
2069
  get content() {
1609
2070
  if (!this.contentAvailable) {
1610
2071
  return null;
1611
2072
  }
2073
+
1612
2074
  if (!this.contentRef && this.root) {
1613
2075
  this.contentRef = pickPlatformItem(this.root.get('EF'));
1614
2076
  }
2077
+
1615
2078
  var content = null;
2079
+
1616
2080
  if (this.contentRef) {
1617
2081
  var xref = this.xref;
1618
2082
  var fileObj = xref.fetchIfRef(this.contentRef);
2083
+
1619
2084
  if (fileObj && (0, _primitives.isStream)(fileObj)) {
1620
2085
  content = fileObj.getBytes();
1621
2086
  } else {
@@ -1624,27 +2089,36 @@ var FileSpec = function FileSpecClosure() {
1624
2089
  } else {
1625
2090
  (0, _util.warn)('Embedded file specification does not have a content');
1626
2091
  }
2092
+
1627
2093
  return content;
1628
2094
  },
2095
+
1629
2096
  get serializable() {
1630
2097
  return {
1631
2098
  filename: this.filename,
1632
2099
  content: this.content
1633
2100
  };
1634
2101
  }
2102
+
1635
2103
  };
1636
2104
  return FileSpec;
1637
2105
  }();
2106
+
2107
+ exports.FileSpec = FileSpec;
2108
+
1638
2109
  var ObjectLoader = function () {
1639
2110
  function mayHaveChildren(value) {
1640
2111
  return (0, _primitives.isRef)(value) || (0, _primitives.isDict)(value) || Array.isArray(value) || (0, _primitives.isStream)(value);
1641
2112
  }
2113
+
1642
2114
  function addChildren(node, nodesToVisit) {
1643
2115
  if ((0, _primitives.isDict)(node) || (0, _primitives.isStream)(node)) {
1644
2116
  var dict = (0, _primitives.isDict)(node) ? node : node.dict;
1645
2117
  var dictKeys = dict.getKeys();
2118
+
1646
2119
  for (var i = 0, ii = dictKeys.length; i < ii; i++) {
1647
2120
  var rawValue = dict.getRaw(dictKeys[i]);
2121
+
1648
2122
  if (mayHaveChildren(rawValue)) {
1649
2123
  nodesToVisit.push(rawValue);
1650
2124
  }
@@ -1652,12 +2126,14 @@ var ObjectLoader = function () {
1652
2126
  } else if (Array.isArray(node)) {
1653
2127
  for (var _i3 = 0, _ii2 = node.length; _i3 < _ii2; _i3++) {
1654
2128
  var value = node[_i3];
2129
+
1655
2130
  if (mayHaveChildren(value)) {
1656
2131
  nodesToVisit.push(value);
1657
2132
  }
1658
2133
  }
1659
2134
  }
1660
2135
  }
2136
+
1661
2137
  function ObjectLoader(dict, keys, xref) {
1662
2138
  this.dict = dict;
1663
2139
  this.keys = keys;
@@ -1665,57 +2141,70 @@ var ObjectLoader = function () {
1665
2141
  this.refSet = null;
1666
2142
  this.capability = null;
1667
2143
  }
2144
+
1668
2145
  ObjectLoader.prototype = {
1669
2146
  load: function load() {
1670
2147
  this.capability = (0, _util.createPromiseCapability)();
2148
+
1671
2149
  if (!(this.xref.stream instanceof _chunked_stream.ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
1672
2150
  this.capability.resolve();
1673
2151
  return this.capability.promise;
1674
2152
  }
2153
+
1675
2154
  var keys = this.keys,
1676
2155
  dict = this.dict;
1677
-
1678
2156
  this.refSet = new _primitives.RefSet();
1679
2157
  var nodesToVisit = [];
2158
+
1680
2159
  for (var i = 0, ii = keys.length; i < ii; i++) {
1681
2160
  var rawValue = dict.getRaw(keys[i]);
2161
+
1682
2162
  if (rawValue !== undefined) {
1683
2163
  nodesToVisit.push(rawValue);
1684
2164
  }
1685
2165
  }
2166
+
1686
2167
  this._walk(nodesToVisit);
2168
+
1687
2169
  return this.capability.promise;
1688
2170
  },
1689
2171
  _walk: function _walk(nodesToVisit) {
1690
- var _this4 = this;
2172
+ var _this2 = this;
1691
2173
 
1692
2174
  var nodesToRevisit = [];
1693
2175
  var pendingRequests = [];
2176
+
1694
2177
  while (nodesToVisit.length) {
1695
- var _currentNode = nodesToVisit.pop();
1696
- if ((0, _primitives.isRef)(_currentNode)) {
1697
- if (this.refSet.has(_currentNode)) {
2178
+ var currentNode = nodesToVisit.pop();
2179
+
2180
+ if ((0, _primitives.isRef)(currentNode)) {
2181
+ if (this.refSet.has(currentNode)) {
1698
2182
  continue;
1699
2183
  }
2184
+
1700
2185
  try {
1701
- this.refSet.put(_currentNode);
1702
- _currentNode = this.xref.fetch(_currentNode);
2186
+ this.refSet.put(currentNode);
2187
+ currentNode = this.xref.fetch(currentNode);
1703
2188
  } catch (ex) {
1704
2189
  if (!(ex instanceof _util.MissingDataException)) {
1705
2190
  throw ex;
1706
2191
  }
1707
- nodesToRevisit.push(_currentNode);
2192
+
2193
+ nodesToRevisit.push(currentNode);
1708
2194
  pendingRequests.push({
1709
2195
  begin: ex.begin,
1710
2196
  end: ex.end
1711
2197
  });
1712
2198
  }
1713
2199
  }
1714
- if (_currentNode && _currentNode.getBaseStreams) {
1715
- var baseStreams = _currentNode.getBaseStreams();
2200
+
2201
+ if (currentNode && currentNode.getBaseStreams) {
2202
+ var baseStreams = currentNode.getBaseStreams();
1716
2203
  var foundMissingData = false;
2204
+
1717
2205
  for (var i = 0, ii = baseStreams.length; i < ii; i++) {
1718
2206
  var stream = baseStreams[i];
2207
+
1719
2208
  if (stream.getMissingChunks && stream.getMissingChunks().length) {
1720
2209
  foundMissingData = true;
1721
2210
  pendingRequests.push({
@@ -1724,31 +2213,35 @@ var ObjectLoader = function () {
1724
2213
  });
1725
2214
  }
1726
2215
  }
2216
+
1727
2217
  if (foundMissingData) {
1728
- nodesToRevisit.push(_currentNode);
2218
+ nodesToRevisit.push(currentNode);
1729
2219
  }
1730
2220
  }
1731
- addChildren(_currentNode, nodesToVisit);
2221
+
2222
+ addChildren(currentNode, nodesToVisit);
1732
2223
  }
2224
+
1733
2225
  if (pendingRequests.length) {
1734
2226
  this.xref.stream.manager.requestRanges(pendingRequests).then(function () {
1735
2227
  for (var _i4 = 0, _ii3 = nodesToRevisit.length; _i4 < _ii3; _i4++) {
1736
2228
  var node = nodesToRevisit[_i4];
2229
+
1737
2230
  if ((0, _primitives.isRef)(node)) {
1738
- _this4.refSet.remove(node);
2231
+ _this2.refSet.remove(node);
1739
2232
  }
1740
2233
  }
1741
- _this4._walk(nodesToRevisit);
2234
+
2235
+ _this2._walk(nodesToRevisit);
1742
2236
  }, this.capability.reject);
1743
2237
  return;
1744
2238
  }
2239
+
1745
2240
  this.refSet = null;
1746
2241
  this.capability.resolve();
1747
2242
  }
1748
2243
  };
1749
2244
  return ObjectLoader;
1750
2245
  }();
1751
- exports.Catalog = Catalog;
1752
- exports.ObjectLoader = ObjectLoader;
1753
- exports.XRef = XRef;
1754
- exports.FileSpec = FileSpec;
2246
+
2247
+ exports.ObjectLoader = ObjectLoader;