pdfjs-dist 2.0.489 → 2.2.228

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 (169) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +18515 -11402
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +48266 -37137
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/external/url/url-lib.js +627 -0
  10. package/image_decoders/pdf.image_decoders.js +11350 -0
  11. package/image_decoders/pdf.image_decoders.js.map +1 -0
  12. package/image_decoders/pdf.image_decoders.min.js +1 -0
  13. package/lib/core/annotation.js +587 -242
  14. package/lib/core/arithmetic_decoder.js +275 -245
  15. package/lib/core/bidi.js +65 -6
  16. package/lib/core/ccitt.js +173 -18
  17. package/lib/core/ccitt_stream.js +15 -6
  18. package/lib/core/cff_parser.js +433 -61
  19. package/lib/core/charsets.js +5 -4
  20. package/lib/core/chunked_stream.js +400 -152
  21. package/lib/core/cmap.js +326 -87
  22. package/lib/core/colorspace.js +874 -594
  23. package/lib/core/core_utils.js +147 -0
  24. package/lib/core/crypto.js +290 -45
  25. package/lib/core/document.js +560 -268
  26. package/lib/core/encodings.js +19 -10
  27. package/lib/core/evaluator.js +1005 -360
  28. package/lib/core/font_renderer.js +331 -97
  29. package/lib/core/fonts.js +812 -195
  30. package/lib/core/function.js +284 -71
  31. package/lib/core/glyphlist.js +4 -3
  32. package/lib/core/image.js +169 -62
  33. package/lib/core/image_utils.js +111 -0
  34. package/lib/core/jbig2.js +479 -66
  35. package/lib/core/jbig2_stream.js +19 -8
  36. package/lib/core/jpeg_stream.js +38 -13
  37. package/lib/core/jpg.js +253 -29
  38. package/lib/core/jpx.js +396 -6
  39. package/lib/core/jpx_stream.js +18 -6
  40. package/lib/core/metrics.js +15 -15
  41. package/lib/core/murmurhash3.js +56 -34
  42. package/lib/core/obj.js +1354 -488
  43. package/lib/core/operator_list.js +144 -31
  44. package/lib/core/parser.js +539 -191
  45. package/lib/core/pattern.js +148 -14
  46. package/lib/core/pdf_manager.js +323 -133
  47. package/lib/core/primitives.js +111 -24
  48. package/lib/core/ps_parser.js +134 -45
  49. package/lib/core/standard_fonts.js +17 -17
  50. package/lib/core/stream.js +313 -34
  51. package/lib/core/type1_parser.js +143 -13
  52. package/lib/core/unicode.js +32 -5
  53. package/lib/core/worker.js +217 -190
  54. package/lib/core/worker_stream.js +277 -0
  55. package/lib/display/annotation_layer.js +450 -133
  56. package/lib/display/api.js +1597 -784
  57. package/lib/display/api_compatibility.js +11 -13
  58. package/lib/display/canvas.js +360 -44
  59. package/lib/display/content_disposition.js +83 -32
  60. package/lib/display/display_utils.js +747 -0
  61. package/lib/display/fetch_stream.js +221 -90
  62. package/lib/display/font_loader.js +468 -236
  63. package/lib/display/metadata.js +38 -16
  64. package/lib/display/network.js +635 -428
  65. package/lib/display/network_utils.js +32 -19
  66. package/lib/display/node_stream.js +367 -175
  67. package/lib/display/pattern_helper.js +81 -31
  68. package/lib/display/svg.js +1235 -519
  69. package/lib/display/text_layer.js +153 -29
  70. package/lib/display/transport_stream.js +345 -94
  71. package/lib/display/webgl.js +64 -18
  72. package/lib/display/worker_options.js +5 -4
  73. package/lib/display/xml_parser.js +166 -53
  74. package/lib/examples/node/domstubs.js +60 -4
  75. package/lib/pdf.js +36 -14
  76. package/lib/pdf.worker.js +5 -3
  77. package/lib/shared/compatibility.js +158 -564
  78. package/lib/shared/global_scope.js +2 -2
  79. package/lib/shared/is_node.js +4 -4
  80. package/lib/shared/message_handler.js +521 -0
  81. package/lib/shared/streams_polyfill.js +21 -17
  82. package/lib/shared/url_polyfill.js +56 -0
  83. package/lib/shared/util.js +243 -710
  84. package/lib/test/unit/annotation_spec.js +870 -401
  85. package/lib/test/unit/api_spec.js +657 -345
  86. package/lib/test/unit/bidi_spec.js +7 -7
  87. package/lib/test/unit/cff_parser_spec.js +54 -11
  88. package/lib/test/unit/clitests_helper.js +10 -8
  89. package/lib/test/unit/cmap_spec.js +95 -41
  90. package/lib/test/unit/colorspace_spec.js +115 -63
  91. package/lib/test/unit/core_utils_spec.js +191 -0
  92. package/lib/test/unit/crypto_spec.js +17 -5
  93. package/lib/test/unit/custom_spec.js +43 -55
  94. package/lib/test/unit/display_svg_spec.js +34 -18
  95. package/lib/test/unit/display_utils_spec.js +273 -0
  96. package/lib/test/unit/document_spec.js +8 -13
  97. package/lib/test/unit/encodings_spec.js +25 -45
  98. package/lib/test/unit/evaluator_spec.js +38 -15
  99. package/lib/test/unit/fetch_stream_spec.js +109 -0
  100. package/lib/test/unit/function_spec.js +17 -5
  101. package/lib/test/unit/jasmine-boot.js +33 -20
  102. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  103. package/lib/test/unit/metadata_spec.js +71 -11
  104. package/lib/test/unit/murmurhash3_spec.js +3 -3
  105. package/lib/test/unit/network_spec.js +19 -54
  106. package/lib/test/unit/network_utils_spec.js +91 -14
  107. package/lib/test/unit/node_stream_spec.js +56 -32
  108. package/lib/test/unit/parser_spec.js +162 -71
  109. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  110. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  111. package/lib/test/unit/pdf_history_spec.js +21 -9
  112. package/lib/test/unit/primitives_spec.js +53 -20
  113. package/lib/test/unit/stream_spec.js +12 -4
  114. package/lib/test/unit/test_utils.js +273 -56
  115. package/lib/test/unit/testreporter.js +21 -3
  116. package/lib/test/unit/type1_parser_spec.js +8 -6
  117. package/lib/test/unit/ui_utils_spec.js +454 -16
  118. package/lib/test/unit/unicode_spec.js +18 -15
  119. package/lib/test/unit/util_spec.js +87 -128
  120. package/lib/web/annotation_layer_builder.js +39 -22
  121. package/lib/web/app.js +1290 -588
  122. package/lib/web/app_options.js +100 -62
  123. package/lib/web/base_viewer.js +511 -182
  124. package/lib/web/chromecom.js +261 -117
  125. package/lib/web/debugger.js +166 -22
  126. package/lib/web/download_manager.js +32 -13
  127. package/lib/web/firefox_print_service.js +20 -10
  128. package/lib/web/firefoxcom.js +315 -80
  129. package/lib/web/genericcom.js +89 -30
  130. package/lib/web/genericl10n.js +142 -30
  131. package/lib/web/grab_to_pan.js +28 -4
  132. package/lib/web/interfaces.js +170 -47
  133. package/lib/web/overlay_manager.js +235 -85
  134. package/lib/web/password_prompt.js +22 -14
  135. package/lib/web/pdf_attachment_viewer.js +38 -18
  136. package/lib/web/pdf_cursor_tools.js +39 -16
  137. package/lib/web/pdf_document_properties.js +255 -136
  138. package/lib/web/pdf_find_bar.js +84 -40
  139. package/lib/web/pdf_find_controller.js +495 -184
  140. package/lib/web/pdf_find_utils.js +111 -0
  141. package/lib/web/pdf_history.js +190 -53
  142. package/lib/web/pdf_link_service.js +138 -77
  143. package/lib/web/pdf_outline_viewer.js +122 -46
  144. package/lib/web/pdf_page_view.js +191 -67
  145. package/lib/web/pdf_presentation_mode.js +99 -34
  146. package/lib/web/pdf_print_service.js +61 -13
  147. package/lib/web/pdf_rendering_queue.js +28 -9
  148. package/lib/web/pdf_sidebar.js +141 -81
  149. package/lib/web/pdf_sidebar_resizer.js +42 -16
  150. package/lib/web/pdf_single_page_viewer.js +74 -66
  151. package/lib/web/pdf_thumbnail_view.js +104 -33
  152. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  153. package/lib/web/pdf_viewer.component.js +112 -32
  154. package/lib/web/pdf_viewer.js +91 -52
  155. package/lib/web/preferences.js +284 -89
  156. package/lib/web/secondary_toolbar.js +165 -40
  157. package/lib/web/text_layer_builder.js +134 -59
  158. package/lib/web/toolbar.js +78 -43
  159. package/lib/web/ui_utils.js +462 -136
  160. package/lib/web/view_history.js +215 -67
  161. package/lib/web/viewer_compatibility.js +4 -13
  162. package/package.json +5 -4
  163. package/web/pdf_viewer.css +79 -11
  164. package/web/pdf_viewer.js +6107 -3748
  165. package/web/pdf_viewer.js.map +1 -1
  166. package/lib/display/dom_utils.js +0 -309
  167. package/lib/test/unit/dom_utils_spec.js +0 -89
  168. package/lib/test/unit/fonts_spec.js +0 -81
  169. package/lib/web/dom_events.js +0 -137
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 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.
@@ -19,24 +19,43 @@
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.SimpleXMLParser = void 0;
27
28
 
28
- 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"); } }; }();
29
+ 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); }
29
30
 
30
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
31
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
31
32
 
32
- 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; }; }();
33
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
33
34
 
34
- 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; }
35
+ 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; }
35
36
 
36
- 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; }
37
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
38
+
39
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
40
+
41
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
42
+
43
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
44
+
45
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
46
+
47
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
48
+
49
+ 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); }
50
+
51
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
52
 
38
53
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
39
54
 
55
+ 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); } }
56
+
57
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
58
+
40
59
  var XMLParserErrorCode = {
41
60
  NoError: 0,
42
61
  EndOfDocument: -1,
@@ -50,84 +69,108 @@ var XMLParserErrorCode = {
50
69
  UnterminatedElement: -9,
51
70
  ElementNeverBegun: -10
52
71
  };
72
+
53
73
  function isWhitespace(s, index) {
54
74
  var ch = s[index];
55
75
  return ch === ' ' || ch === '\n' || ch === '\r' || ch === '\t';
56
76
  }
77
+
57
78
  function isWhitespaceString(s) {
58
79
  for (var i = 0, ii = s.length; i < ii; i++) {
59
80
  if (!isWhitespace(s, i)) {
60
81
  return false;
61
82
  }
62
83
  }
84
+
63
85
  return true;
64
86
  }
65
87
 
66
- var XMLParserBase = function () {
88
+ var XMLParserBase =
89
+ /*#__PURE__*/
90
+ function () {
67
91
  function XMLParserBase() {
68
92
  _classCallCheck(this, XMLParserBase);
69
93
  }
70
94
 
71
95
  _createClass(XMLParserBase, [{
72
- key: '_resolveEntities',
96
+ key: "_resolveEntities",
73
97
  value: function _resolveEntities(s) {
98
+ var _this = this;
99
+
74
100
  return s.replace(/&([^;]+);/g, function (all, entity) {
75
101
  if (entity.substring(0, 2) === '#x') {
76
102
  return String.fromCharCode(parseInt(entity.substring(2), 16));
77
103
  } else if (entity.substring(0, 1) === '#') {
78
104
  return String.fromCharCode(parseInt(entity.substring(1), 10));
79
105
  }
106
+
80
107
  switch (entity) {
81
108
  case 'lt':
82
109
  return '<';
110
+
83
111
  case 'gt':
84
112
  return '>';
113
+
85
114
  case 'amp':
86
115
  return '&';
116
+
87
117
  case 'quot':
88
118
  return '\"';
89
119
  }
90
- return this.onResolveEntity(entity);
120
+
121
+ return _this.onResolveEntity(entity);
91
122
  });
92
123
  }
93
124
  }, {
94
- key: '_parseContent',
125
+ key: "_parseContent",
95
126
  value: function _parseContent(s, start) {
96
127
  var pos = start,
97
- name = void 0,
128
+ name,
98
129
  attributes = [];
130
+
99
131
  function skipWs() {
100
132
  while (pos < s.length && isWhitespace(s, pos)) {
101
133
  ++pos;
102
134
  }
103
135
  }
136
+
104
137
  while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '>' && s[pos] !== '/') {
105
138
  ++pos;
106
139
  }
140
+
107
141
  name = s.substring(start, pos);
108
142
  skipWs();
143
+
109
144
  while (pos < s.length && s[pos] !== '>' && s[pos] !== '/' && s[pos] !== '?') {
110
145
  skipWs();
111
146
  var attrName = '',
112
147
  attrValue = '';
148
+
113
149
  while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '=') {
114
150
  attrName += s[pos];
115
151
  ++pos;
116
152
  }
153
+
117
154
  skipWs();
155
+
118
156
  if (s[pos] !== '=') {
119
157
  return null;
120
158
  }
159
+
121
160
  ++pos;
122
161
  skipWs();
123
162
  var attrEndChar = s[pos];
163
+
124
164
  if (attrEndChar !== '\"' && attrEndChar !== '\'') {
125
165
  return null;
126
166
  }
167
+
127
168
  var attrEndIndex = s.indexOf(attrEndChar, ++pos);
169
+
128
170
  if (attrEndIndex < 0) {
129
171
  return null;
130
172
  }
173
+
131
174
  attrValue = s.substring(pos, attrEndIndex);
132
175
  attributes.push({
133
176
  name: attrName,
@@ -136,6 +179,7 @@ var XMLParserBase = function () {
136
179
  pos = attrEndIndex + 1;
137
180
  skipWs();
138
181
  }
182
+
139
183
  return {
140
184
  name: name,
141
185
  attributes: attributes,
@@ -143,25 +187,30 @@ var XMLParserBase = function () {
143
187
  };
144
188
  }
145
189
  }, {
146
- key: '_parseProcessingInstruction',
190
+ key: "_parseProcessingInstruction",
147
191
  value: function _parseProcessingInstruction(s, start) {
148
192
  var pos = start,
149
- name = void 0,
150
- value = void 0;
193
+ name,
194
+ value;
195
+
151
196
  function skipWs() {
152
197
  while (pos < s.length && isWhitespace(s, pos)) {
153
198
  ++pos;
154
199
  }
155
200
  }
201
+
156
202
  while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '>' && s[pos] !== '/') {
157
203
  ++pos;
158
204
  }
205
+
159
206
  name = s.substring(start, pos);
160
207
  skipWs();
161
208
  var attrStart = pos;
209
+
162
210
  while (pos < s.length && (s[pos] !== '?' || s[pos + 1] !== '>')) {
163
211
  ++pos;
164
212
  }
213
+
165
214
  value = s.substring(attrStart, pos);
166
215
  return {
167
216
  name: name,
@@ -170,70 +219,89 @@ var XMLParserBase = function () {
170
219
  };
171
220
  }
172
221
  }, {
173
- key: 'parseXml',
222
+ key: "parseXml",
174
223
  value: function parseXml(s) {
175
224
  var i = 0;
225
+
176
226
  while (i < s.length) {
177
227
  var ch = s[i];
178
228
  var j = i;
229
+
179
230
  if (ch === '<') {
180
231
  ++j;
181
232
  var ch2 = s[j];
182
233
  var q = void 0;
234
+
183
235
  switch (ch2) {
184
236
  case '/':
185
237
  ++j;
186
238
  q = s.indexOf('>', j);
239
+
187
240
  if (q < 0) {
188
241
  this.onError(XMLParserErrorCode.UnterminatedElement);
189
242
  return;
190
243
  }
244
+
191
245
  this.onEndElement(s.substring(j, q));
192
246
  j = q + 1;
193
247
  break;
248
+
194
249
  case '?':
195
250
  ++j;
251
+
196
252
  var pi = this._parseProcessingInstruction(s, j);
253
+
197
254
  if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== '?>') {
198
255
  this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
199
256
  return;
200
257
  }
258
+
201
259
  this.onPi(pi.name, pi.value);
202
260
  j += pi.parsed + 2;
203
261
  break;
262
+
204
263
  case '!':
205
264
  if (s.substring(j + 1, j + 3) === '--') {
206
265
  q = s.indexOf('-->', j + 3);
266
+
207
267
  if (q < 0) {
208
268
  this.onError(XMLParserErrorCode.UnterminatedComment);
209
269
  return;
210
270
  }
271
+
211
272
  this.onComment(s.substring(j + 3, q));
212
273
  j = q + 3;
213
274
  } else if (s.substring(j + 1, j + 8) === '[CDATA[') {
214
275
  q = s.indexOf(']]>', j + 8);
276
+
215
277
  if (q < 0) {
216
278
  this.onError(XMLParserErrorCode.UnterminatedCdat);
217
279
  return;
218
280
  }
281
+
219
282
  this.onCdata(s.substring(j + 8, q));
220
283
  j = q + 3;
221
284
  } else if (s.substring(j + 1, j + 8) === 'DOCTYPE') {
222
285
  var q2 = s.indexOf('[', j + 8);
223
286
  var complexDoctype = false;
224
287
  q = s.indexOf('>', j + 8);
288
+
225
289
  if (q < 0) {
226
290
  this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
227
291
  return;
228
292
  }
293
+
229
294
  if (q2 > 0 && q > q2) {
230
295
  q = s.indexOf(']>', j + 8);
296
+
231
297
  if (q < 0) {
232
298
  this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
233
299
  return;
234
300
  }
301
+
235
302
  complexDoctype = true;
236
303
  }
304
+
237
305
  var doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
238
306
  this.onDoctype(doctypeContent);
239
307
  j = q + (complexDoctype ? 2 : 1);
@@ -241,20 +309,26 @@ var XMLParserBase = function () {
241
309
  this.onError(XMLParserErrorCode.MalformedElement);
242
310
  return;
243
311
  }
312
+
244
313
  break;
314
+
245
315
  default:
246
316
  var content = this._parseContent(s, j);
317
+
247
318
  if (content === null) {
248
319
  this.onError(XMLParserErrorCode.MalformedElement);
249
320
  return;
250
321
  }
322
+
251
323
  var isClosed = false;
324
+
252
325
  if (s.substring(j + content.parsed, j + content.parsed + 2) === '/>') {
253
326
  isClosed = true;
254
327
  } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== '>') {
255
328
  this.onError(XMLParserErrorCode.UnterminatedElement);
256
329
  return;
257
330
  }
331
+
258
332
  this.onBeginElement(content.name, content.attributes, isClosed);
259
333
  j += content.parsed + (isClosed ? 2 : 1);
260
334
  break;
@@ -263,47 +337,51 @@ var XMLParserBase = function () {
263
337
  while (j < s.length && s[j] !== '<') {
264
338
  j++;
265
339
  }
340
+
266
341
  var text = s.substring(i, j);
267
342
  this.onText(this._resolveEntities(text));
268
343
  }
344
+
269
345
  i = j;
270
346
  }
271
347
  }
272
348
  }, {
273
- key: 'onResolveEntity',
349
+ key: "onResolveEntity",
274
350
  value: function onResolveEntity(name) {
275
- return '&' + name + ';';
351
+ return "&".concat(name, ";");
276
352
  }
277
353
  }, {
278
- key: 'onPi',
354
+ key: "onPi",
279
355
  value: function onPi(name, value) {}
280
356
  }, {
281
- key: 'onComment',
357
+ key: "onComment",
282
358
  value: function onComment(text) {}
283
359
  }, {
284
- key: 'onCdata',
360
+ key: "onCdata",
285
361
  value: function onCdata(text) {}
286
362
  }, {
287
- key: 'onDoctype',
363
+ key: "onDoctype",
288
364
  value: function onDoctype(doctypeContent) {}
289
365
  }, {
290
- key: 'onText',
366
+ key: "onText",
291
367
  value: function onText(text) {}
292
368
  }, {
293
- key: 'onBeginElement',
369
+ key: "onBeginElement",
294
370
  value: function onBeginElement(name, attributes, isEmpty) {}
295
371
  }, {
296
- key: 'onEndElement',
372
+ key: "onEndElement",
297
373
  value: function onEndElement(name) {}
298
374
  }, {
299
- key: 'onError',
375
+ key: "onError",
300
376
  value: function onError(code) {}
301
377
  }]);
302
378
 
303
379
  return XMLParserBase;
304
380
  }();
305
381
 
306
- var SimpleDOMNode = function () {
382
+ var SimpleDOMNode =
383
+ /*#__PURE__*/
384
+ function () {
307
385
  function SimpleDOMNode(nodeName, nodeValue) {
308
386
  _classCallCheck(this, SimpleDOMNode);
309
387
 
@@ -316,27 +394,39 @@ var SimpleDOMNode = function () {
316
394
  }
317
395
 
318
396
  _createClass(SimpleDOMNode, [{
319
- key: 'hasChildNodes',
397
+ key: "hasChildNodes",
320
398
  value: function hasChildNodes() {
321
399
  return this.childNodes && this.childNodes.length > 0;
322
400
  }
323
401
  }, {
324
- key: 'firstChild',
402
+ key: "firstChild",
325
403
  get: function get() {
326
- return this.childNodes[0];
404
+ return this.childNodes && this.childNodes[0];
327
405
  }
328
406
  }, {
329
- key: 'nextSibling',
407
+ key: "nextSibling",
330
408
  get: function get() {
331
- var index = this.parentNode.childNodes.indexOf(this);
332
- return this.parentNode.childNodes[index + 1];
409
+ var childNodes = this.parentNode.childNodes;
410
+
411
+ if (!childNodes) {
412
+ return undefined;
413
+ }
414
+
415
+ var index = childNodes.indexOf(this);
416
+
417
+ if (index === -1) {
418
+ return undefined;
419
+ }
420
+
421
+ return childNodes[index + 1];
333
422
  }
334
423
  }, {
335
- key: 'textContent',
424
+ key: "textContent",
336
425
  get: function get() {
337
426
  if (!this.childNodes) {
338
427
  return this.nodeValue || '';
339
428
  }
429
+
340
430
  return this.childNodes.map(function (child) {
341
431
  return child.textContent;
342
432
  }).join('');
@@ -346,83 +436,106 @@ var SimpleDOMNode = function () {
346
436
  return SimpleDOMNode;
347
437
  }();
348
438
 
349
- var SimpleXMLParser = function (_XMLParserBase) {
439
+ var SimpleXMLParser =
440
+ /*#__PURE__*/
441
+ function (_XMLParserBase) {
350
442
  _inherits(SimpleXMLParser, _XMLParserBase);
351
443
 
352
444
  function SimpleXMLParser() {
353
- _classCallCheck(this, SimpleXMLParser);
445
+ var _this2;
354
446
 
355
- var _this = _possibleConstructorReturn(this, (SimpleXMLParser.__proto__ || Object.getPrototypeOf(SimpleXMLParser)).call(this));
447
+ _classCallCheck(this, SimpleXMLParser);
356
448
 
357
- _this._currentFragment = null;
358
- _this._stack = null;
359
- _this._errorCode = XMLParserErrorCode.NoError;
360
- return _this;
449
+ _this2 = _possibleConstructorReturn(this, _getPrototypeOf(SimpleXMLParser).call(this));
450
+ _this2._currentFragment = null;
451
+ _this2._stack = null;
452
+ _this2._errorCode = XMLParserErrorCode.NoError;
453
+ return _this2;
361
454
  }
362
455
 
363
456
  _createClass(SimpleXMLParser, [{
364
- key: 'parseFromString',
457
+ key: "parseFromString",
365
458
  value: function parseFromString(data) {
366
459
  this._currentFragment = [];
367
460
  this._stack = [];
368
461
  this._errorCode = XMLParserErrorCode.NoError;
369
462
  this.parseXml(data);
463
+
370
464
  if (this._errorCode !== XMLParserErrorCode.NoError) {
371
465
  return undefined;
372
466
  }
373
467
 
374
- var _currentFragment = _slicedToArray(this._currentFragment, 1),
375
- documentElement = _currentFragment[0];
468
+ var _this$_currentFragmen = _slicedToArray(this._currentFragment, 1),
469
+ documentElement = _this$_currentFragmen[0];
376
470
 
377
- return { documentElement: documentElement };
471
+ if (!documentElement) {
472
+ return undefined;
473
+ }
474
+
475
+ return {
476
+ documentElement: documentElement
477
+ };
378
478
  }
379
479
  }, {
380
- key: 'onResolveEntity',
480
+ key: "onResolveEntity",
381
481
  value: function onResolveEntity(name) {
382
482
  switch (name) {
383
483
  case 'apos':
384
484
  return '\'';
385
485
  }
386
- return _get(SimpleXMLParser.prototype.__proto__ || Object.getPrototypeOf(SimpleXMLParser.prototype), 'onResolveEntity', this).call(this, name);
486
+
487
+ return _get(_getPrototypeOf(SimpleXMLParser.prototype), "onResolveEntity", this).call(this, name);
387
488
  }
388
489
  }, {
389
- key: 'onText',
490
+ key: "onText",
390
491
  value: function onText(text) {
391
492
  if (isWhitespaceString(text)) {
392
493
  return;
393
494
  }
495
+
394
496
  var node = new SimpleDOMNode('#text', text);
497
+
395
498
  this._currentFragment.push(node);
396
499
  }
397
500
  }, {
398
- key: 'onCdata',
501
+ key: "onCdata",
399
502
  value: function onCdata(text) {
400
503
  var node = new SimpleDOMNode('#text', text);
504
+
401
505
  this._currentFragment.push(node);
402
506
  }
403
507
  }, {
404
- key: 'onBeginElement',
508
+ key: "onBeginElement",
405
509
  value: function onBeginElement(name, attributes, isEmpty) {
406
510
  var node = new SimpleDOMNode(name);
407
511
  node.childNodes = [];
512
+
408
513
  this._currentFragment.push(node);
514
+
409
515
  if (isEmpty) {
410
516
  return;
411
517
  }
518
+
412
519
  this._stack.push(this._currentFragment);
520
+
413
521
  this._currentFragment = node.childNodes;
414
522
  }
415
523
  }, {
416
- key: 'onEndElement',
524
+ key: "onEndElement",
417
525
  value: function onEndElement(name) {
418
- this._currentFragment = this._stack.pop();
526
+ this._currentFragment = this._stack.pop() || [];
419
527
  var lastElement = this._currentFragment[this._currentFragment.length - 1];
528
+
529
+ if (!lastElement) {
530
+ return;
531
+ }
532
+
420
533
  for (var i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
421
534
  lastElement.childNodes[i].parentNode = lastElement;
422
535
  }
423
536
  }
424
537
  }, {
425
- key: 'onError',
538
+ key: "onError",
426
539
  value: function onError(code) {
427
540
  this._errorCode = code;
428
541
  }