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
@@ -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,86 +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
471
  if (!documentElement) {
378
472
  return undefined;
379
473
  }
380
- return { documentElement: documentElement };
474
+
475
+ return {
476
+ documentElement: documentElement
477
+ };
381
478
  }
382
479
  }, {
383
- key: 'onResolveEntity',
480
+ key: "onResolveEntity",
384
481
  value: function onResolveEntity(name) {
385
482
  switch (name) {
386
483
  case 'apos':
387
484
  return '\'';
388
485
  }
389
- 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);
390
488
  }
391
489
  }, {
392
- key: 'onText',
490
+ key: "onText",
393
491
  value: function onText(text) {
394
492
  if (isWhitespaceString(text)) {
395
493
  return;
396
494
  }
495
+
397
496
  var node = new SimpleDOMNode('#text', text);
497
+
398
498
  this._currentFragment.push(node);
399
499
  }
400
500
  }, {
401
- key: 'onCdata',
501
+ key: "onCdata",
402
502
  value: function onCdata(text) {
403
503
  var node = new SimpleDOMNode('#text', text);
504
+
404
505
  this._currentFragment.push(node);
405
506
  }
406
507
  }, {
407
- key: 'onBeginElement',
508
+ key: "onBeginElement",
408
509
  value: function onBeginElement(name, attributes, isEmpty) {
409
510
  var node = new SimpleDOMNode(name);
410
511
  node.childNodes = [];
512
+
411
513
  this._currentFragment.push(node);
514
+
412
515
  if (isEmpty) {
413
516
  return;
414
517
  }
518
+
415
519
  this._stack.push(this._currentFragment);
520
+
416
521
  this._currentFragment = node.childNodes;
417
522
  }
418
523
  }, {
419
- key: 'onEndElement',
524
+ key: "onEndElement",
420
525
  value: function onEndElement(name) {
421
- this._currentFragment = this._stack.pop();
526
+ this._currentFragment = this._stack.pop() || [];
422
527
  var lastElement = this._currentFragment[this._currentFragment.length - 1];
528
+
529
+ if (!lastElement) {
530
+ return;
531
+ }
532
+
423
533
  for (var i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
424
534
  lastElement.childNodes[i].parentNode = lastElement;
425
535
  }
426
536
  }
427
537
  }, {
428
- key: 'onError',
538
+ key: "onError",
429
539
  value: function onError(code) {
430
540
  this._errorCode = code;
431
541
  }