pdfjs-dist 2.1.266 → 2.5.207

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