pdfjs-dist 2.0.943 → 2.4.456

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 (192) 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 +8286 -14230
  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 +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -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 +57878 -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 +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  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 +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  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 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -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.
@@ -19,25 +19,13 @@
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
-
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
-
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
-
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
-
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
-
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
-
38
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
39
-
40
- var XMLParserErrorCode = {
27
+ exports.SimpleXMLParser = void 0;
28
+ const XMLParserErrorCode = {
41
29
  NoError: 0,
42
30
  EndOfDocument: -1,
43
31
  UnterminatedCdat: -2,
@@ -50,388 +38,421 @@ var XMLParserErrorCode = {
50
38
  UnterminatedElement: -9,
51
39
  ElementNeverBegun: -10
52
40
  };
41
+
53
42
  function isWhitespace(s, index) {
54
- var ch = s[index];
55
- return ch === ' ' || ch === '\n' || ch === '\r' || ch === '\t';
43
+ const ch = s[index];
44
+ return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
56
45
  }
46
+
57
47
  function isWhitespaceString(s) {
58
- for (var i = 0, ii = s.length; i < ii; i++) {
48
+ for (let i = 0, ii = s.length; i < ii; i++) {
59
49
  if (!isWhitespace(s, i)) {
60
50
  return false;
61
51
  }
62
52
  }
53
+
63
54
  return true;
64
55
  }
65
56
 
66
- var XMLParserBase = function () {
67
- function XMLParserBase() {
68
- _classCallCheck(this, XMLParserBase);
69
- }
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
+ }
70
65
 
71
- _createClass(XMLParserBase, [{
72
- key: '_resolveEntities',
73
- value: function _resolveEntities(s) {
74
- return s.replace(/&([^;]+);/g, function (all, entity) {
75
- if (entity.substring(0, 2) === '#x') {
76
- return String.fromCharCode(parseInt(entity.substring(2), 16));
77
- } else if (entity.substring(0, 1) === '#') {
78
- return String.fromCharCode(parseInt(entity.substring(1), 10));
79
- }
80
- switch (entity) {
81
- case 'lt':
82
- return '<';
83
- case 'gt':
84
- return '>';
85
- case 'amp':
86
- return '&';
87
- case 'quot':
88
- return '\"';
89
- }
90
- return this.onResolveEntity(entity);
91
- });
92
- }
93
- }, {
94
- key: '_parseContent',
95
- value: function _parseContent(s, start) {
96
- var pos = start,
97
- name = void 0,
98
- attributes = [];
99
- function skipWs() {
100
- while (pos < s.length && isWhitespace(s, pos)) {
101
- ++pos;
102
- }
66
+ switch (entity) {
67
+ case "lt":
68
+ return "<";
69
+
70
+ case "gt":
71
+ return ">";
72
+
73
+ case "amp":
74
+ return "&";
75
+
76
+ case "quot":
77
+ return '"';
103
78
  }
104
- while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '>' && s[pos] !== '/') {
79
+
80
+ return this.onResolveEntity(entity);
81
+ });
82
+ }
83
+
84
+ _parseContent(s, start) {
85
+ const attributes = [];
86
+ let pos = start;
87
+
88
+ function skipWs() {
89
+ while (pos < s.length && isWhitespace(s, pos)) {
105
90
  ++pos;
106
91
  }
107
- name = s.substring(start, pos);
92
+ }
93
+
94
+ while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
95
+ ++pos;
96
+ }
97
+
98
+ const name = s.substring(start, pos);
99
+ skipWs();
100
+
101
+ while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
108
102
  skipWs();
109
- while (pos < s.length && s[pos] !== '>' && s[pos] !== '/' && s[pos] !== '?') {
110
- skipWs();
111
- var attrName = '',
112
- attrValue = '';
113
- while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '=') {
114
- attrName += s[pos];
115
- ++pos;
116
- }
117
- skipWs();
118
- if (s[pos] !== '=') {
119
- return null;
120
- }
103
+ let attrName = "",
104
+ attrValue = "";
105
+
106
+ while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
107
+ attrName += s[pos];
121
108
  ++pos;
122
- skipWs();
123
- var attrEndChar = s[pos];
124
- if (attrEndChar !== '\"' && attrEndChar !== '\'') {
125
- return null;
126
- }
127
- var attrEndIndex = s.indexOf(attrEndChar, ++pos);
128
- if (attrEndIndex < 0) {
129
- return null;
130
- }
131
- attrValue = s.substring(pos, attrEndIndex);
132
- attributes.push({
133
- name: attrName,
134
- value: this._resolveEntities(attrValue)
135
- });
136
- pos = attrEndIndex + 1;
137
- skipWs();
138
109
  }
139
- return {
140
- name: name,
141
- attributes: attributes,
142
- parsed: pos - start
143
- };
144
- }
145
- }, {
146
- key: '_parseProcessingInstruction',
147
- value: function _parseProcessingInstruction(s, start) {
148
- var pos = start,
149
- name = void 0,
150
- value = void 0;
151
- function skipWs() {
152
- while (pos < s.length && isWhitespace(s, pos)) {
153
- ++pos;
154
- }
110
+
111
+ skipWs();
112
+
113
+ if (s[pos] !== "=") {
114
+ return null;
155
115
  }
156
- while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '>' && s[pos] !== '/') {
157
- ++pos;
116
+
117
+ ++pos;
118
+ skipWs();
119
+ const attrEndChar = s[pos];
120
+
121
+ if (attrEndChar !== '"' && attrEndChar !== "'") {
122
+ return null;
123
+ }
124
+
125
+ const attrEndIndex = s.indexOf(attrEndChar, ++pos);
126
+
127
+ if (attrEndIndex < 0) {
128
+ return null;
158
129
  }
159
- name = s.substring(start, pos);
130
+
131
+ attrValue = s.substring(pos, attrEndIndex);
132
+ attributes.push({
133
+ name: attrName,
134
+ value: this._resolveEntities(attrValue)
135
+ });
136
+ pos = attrEndIndex + 1;
160
137
  skipWs();
161
- var attrStart = pos;
162
- while (pos < s.length && (s[pos] !== '?' || s[pos + 1] !== '>')) {
138
+ }
139
+
140
+ return {
141
+ name,
142
+ attributes,
143
+ parsed: pos - start
144
+ };
145
+ }
146
+
147
+ _parseProcessingInstruction(s, start) {
148
+ let pos = start;
149
+
150
+ function skipWs() {
151
+ while (pos < s.length && isWhitespace(s, pos)) {
163
152
  ++pos;
164
153
  }
165
- value = s.substring(attrStart, pos);
166
- return {
167
- name: name,
168
- value: value,
169
- parsed: pos - start
170
- };
171
154
  }
172
- }, {
173
- key: 'parseXml',
174
- value: function parseXml(s) {
175
- var i = 0;
176
- while (i < s.length) {
177
- var ch = s[i];
178
- var j = i;
179
- if (ch === '<') {
180
- ++j;
181
- var ch2 = s[j];
182
- var q = void 0;
183
- switch (ch2) {
184
- case '/':
185
- ++j;
186
- q = s.indexOf('>', j);
155
+
156
+ while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
157
+ ++pos;
158
+ }
159
+
160
+ const name = s.substring(start, pos);
161
+ skipWs();
162
+ const attrStart = pos;
163
+
164
+ while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
165
+ ++pos;
166
+ }
167
+
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);
219
+
187
220
  if (q < 0) {
188
- this.onError(XMLParserErrorCode.UnterminatedElement);
221
+ this.onError(XMLParserErrorCode.UnterminatedComment);
189
222
  return;
190
223
  }
191
- this.onEndElement(s.substring(j, q));
192
- j = q + 1;
193
- break;
194
- case '?':
195
- ++j;
196
- var pi = this._parseProcessingInstruction(s, j);
197
- if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== '?>') {
198
- this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
224
+
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);
229
+
230
+ if (q < 0) {
231
+ this.onError(XMLParserErrorCode.UnterminatedCdat);
199
232
  return;
200
233
  }
201
- this.onPi(pi.name, pi.value);
202
- j += pi.parsed + 2;
203
- break;
204
- case '!':
205
- if (s.substring(j + 1, j + 3) === '--') {
206
- q = s.indexOf('-->', j + 3);
207
- if (q < 0) {
208
- this.onError(XMLParserErrorCode.UnterminatedComment);
209
- return;
210
- }
211
- this.onComment(s.substring(j + 3, q));
212
- j = q + 3;
213
- } else if (s.substring(j + 1, j + 8) === '[CDATA[') {
214
- q = s.indexOf(']]>', j + 8);
215
- if (q < 0) {
216
- this.onError(XMLParserErrorCode.UnterminatedCdat);
217
- return;
218
- }
219
- this.onCdata(s.substring(j + 8, q));
220
- j = q + 3;
221
- } else if (s.substring(j + 1, j + 8) === 'DOCTYPE') {
222
- var q2 = s.indexOf('[', j + 8);
223
- var complexDoctype = false;
224
- q = s.indexOf('>', j + 8);
234
+
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);
241
+
242
+ if (q < 0) {
243
+ this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
244
+ return;
245
+ }
246
+
247
+ if (q2 > 0 && q > q2) {
248
+ q = s.indexOf("]>", j + 8);
249
+
225
250
  if (q < 0) {
226
251
  this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
227
252
  return;
228
253
  }
229
- if (q2 > 0 && q > q2) {
230
- q = s.indexOf(']>', j + 8);
231
- if (q < 0) {
232
- this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
233
- return;
234
- }
235
- complexDoctype = true;
236
- }
237
- var doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
238
- this.onDoctype(doctypeContent);
239
- j = q + (complexDoctype ? 2 : 1);
240
- } else {
241
- this.onError(XMLParserErrorCode.MalformedElement);
242
- return;
243
- }
244
- break;
245
- default:
246
- var content = this._parseContent(s, j);
247
- if (content === null) {
248
- this.onError(XMLParserErrorCode.MalformedElement);
249
- return;
250
- }
251
- var isClosed = false;
252
- if (s.substring(j + content.parsed, j + content.parsed + 2) === '/>') {
253
- isClosed = true;
254
- } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== '>') {
255
- this.onError(XMLParserErrorCode.UnterminatedElement);
256
- return;
254
+
255
+ complexDoctype = true;
257
256
  }
258
- this.onBeginElement(content.name, content.attributes, isClosed);
259
- j += content.parsed + (isClosed ? 2 : 1);
260
- break;
261
- }
262
- } else {
263
- while (j < s.length && s[j] !== '<') {
264
- j++;
265
- }
266
- var text = s.substring(i, j);
267
- this.onText(this._resolveEntities(text));
257
+
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
+ }
265
+
266
+ break;
267
+
268
+ default:
269
+ const content = this._parseContent(s, j);
270
+
271
+ if (content === null) {
272
+ this.onError(XMLParserErrorCode.MalformedElement);
273
+ return;
274
+ }
275
+
276
+ let isClosed = false;
277
+
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
+ }
284
+
285
+ this.onBeginElement(content.name, content.attributes, isClosed);
286
+ j += content.parsed + (isClosed ? 2 : 1);
287
+ break;
268
288
  }
269
- i = j;
289
+ } else {
290
+ while (j < s.length && s[j] !== "<") {
291
+ j++;
292
+ }
293
+
294
+ const text = s.substring(i, j);
295
+ this.onText(this._resolveEntities(text));
270
296
  }
297
+
298
+ i = j;
271
299
  }
272
- }, {
273
- key: 'onResolveEntity',
274
- value: function onResolveEntity(name) {
275
- return '&' + name + ';';
276
- }
277
- }, {
278
- key: 'onPi',
279
- value: function onPi(name, value) {}
280
- }, {
281
- key: 'onComment',
282
- value: function onComment(text) {}
283
- }, {
284
- key: 'onCdata',
285
- value: function onCdata(text) {}
286
- }, {
287
- key: 'onDoctype',
288
- value: function onDoctype(doctypeContent) {}
289
- }, {
290
- key: 'onText',
291
- value: function onText(text) {}
292
- }, {
293
- key: 'onBeginElement',
294
- value: function onBeginElement(name, attributes, isEmpty) {}
295
- }, {
296
- key: 'onEndElement',
297
- value: function onEndElement(name) {}
298
- }, {
299
- key: 'onError',
300
- value: function onError(code) {}
301
- }]);
302
-
303
- return XMLParserBase;
304
- }();
305
-
306
- var SimpleDOMNode = function () {
307
- function SimpleDOMNode(nodeName, nodeValue) {
308
- _classCallCheck(this, SimpleDOMNode);
300
+ }
301
+
302
+ onResolveEntity(name) {
303
+ return `&${name};`;
304
+ }
305
+
306
+ onPi(name, value) {}
307
+
308
+ onComment(text) {}
309
+
310
+ onCdata(text) {}
311
+
312
+ onDoctype(doctypeContent) {}
313
+
314
+ onText(text) {}
315
+
316
+ onBeginElement(name, attributes, isEmpty) {}
309
317
 
318
+ onEndElement(name) {}
319
+
320
+ onError(code) {}
321
+
322
+ }
323
+
324
+ class SimpleDOMNode {
325
+ constructor(nodeName, nodeValue) {
310
326
  this.nodeName = nodeName;
311
327
  this.nodeValue = nodeValue;
312
- Object.defineProperty(this, 'parentNode', {
328
+ Object.defineProperty(this, "parentNode", {
313
329
  value: null,
314
330
  writable: true
315
331
  });
316
332
  }
317
333
 
318
- _createClass(SimpleDOMNode, [{
319
- key: 'hasChildNodes',
320
- value: function hasChildNodes() {
321
- return this.childNodes && this.childNodes.length > 0;
322
- }
323
- }, {
324
- key: 'firstChild',
325
- get: function get() {
326
- return this.childNodes[0];
327
- }
328
- }, {
329
- key: 'nextSibling',
330
- get: function get() {
331
- var index = this.parentNode.childNodes.indexOf(this);
332
- return this.parentNode.childNodes[index + 1];
333
- }
334
- }, {
335
- key: 'textContent',
336
- get: function get() {
337
- if (!this.childNodes) {
338
- return this.nodeValue || '';
339
- }
340
- return this.childNodes.map(function (child) {
341
- return child.textContent;
342
- }).join('');
334
+ get firstChild() {
335
+ return this.childNodes && this.childNodes[0];
336
+ }
337
+
338
+ get nextSibling() {
339
+ const childNodes = this.parentNode.childNodes;
340
+
341
+ if (!childNodes) {
342
+ return undefined;
343
343
  }
344
- }]);
345
344
 
346
- return SimpleDOMNode;
347
- }();
345
+ const index = childNodes.indexOf(this);
348
346
 
349
- var SimpleXMLParser = function (_XMLParserBase) {
350
- _inherits(SimpleXMLParser, _XMLParserBase);
347
+ if (index === -1) {
348
+ return undefined;
349
+ }
351
350
 
352
- function SimpleXMLParser() {
353
- _classCallCheck(this, SimpleXMLParser);
351
+ return childNodes[index + 1];
352
+ }
354
353
 
355
- var _this = _possibleConstructorReturn(this, (SimpleXMLParser.__proto__ || Object.getPrototypeOf(SimpleXMLParser)).call(this));
354
+ get textContent() {
355
+ if (!this.childNodes) {
356
+ return this.nodeValue || "";
357
+ }
356
358
 
357
- _this._currentFragment = null;
358
- _this._stack = null;
359
- _this._errorCode = XMLParserErrorCode.NoError;
360
- return _this;
359
+ return this.childNodes.map(function (child) {
360
+ return child.textContent;
361
+ }).join("");
361
362
  }
362
363
 
363
- _createClass(SimpleXMLParser, [{
364
- key: 'parseFromString',
365
- value: function parseFromString(data) {
366
- this._currentFragment = [];
367
- this._stack = [];
368
- this._errorCode = XMLParserErrorCode.NoError;
369
- this.parseXml(data);
370
- if (this._errorCode !== XMLParserErrorCode.NoError) {
371
- return undefined;
372
- }
364
+ hasChildNodes() {
365
+ return this.childNodes && this.childNodes.length > 0;
366
+ }
373
367
 
374
- var _currentFragment = _slicedToArray(this._currentFragment, 1),
375
- documentElement = _currentFragment[0];
368
+ }
376
369
 
377
- if (!documentElement) {
378
- return undefined;
379
- }
380
- return { documentElement: documentElement };
370
+ class SimpleXMLParser extends XMLParserBase {
371
+ constructor() {
372
+ super();
373
+ this._currentFragment = null;
374
+ this._stack = null;
375
+ this._errorCode = XMLParserErrorCode.NoError;
376
+ }
377
+
378
+ parseFromString(data) {
379
+ this._currentFragment = [];
380
+ this._stack = [];
381
+ this._errorCode = XMLParserErrorCode.NoError;
382
+ this.parseXml(data);
383
+
384
+ if (this._errorCode !== XMLParserErrorCode.NoError) {
385
+ return undefined;
381
386
  }
382
- }, {
383
- key: 'onResolveEntity',
384
- value: function onResolveEntity(name) {
385
- switch (name) {
386
- case 'apos':
387
- return '\'';
388
- }
389
- return _get(SimpleXMLParser.prototype.__proto__ || Object.getPrototypeOf(SimpleXMLParser.prototype), 'onResolveEntity', this).call(this, name);
387
+
388
+ const [documentElement] = this._currentFragment;
389
+
390
+ if (!documentElement) {
391
+ return undefined;
390
392
  }
391
- }, {
392
- key: 'onText',
393
- value: function onText(text) {
394
- if (isWhitespaceString(text)) {
395
- return;
396
- }
397
- var node = new SimpleDOMNode('#text', text);
398
- this._currentFragment.push(node);
393
+
394
+ return {
395
+ documentElement
396
+ };
397
+ }
398
+
399
+ onResolveEntity(name) {
400
+ switch (name) {
401
+ case "apos":
402
+ return "'";
399
403
  }
400
- }, {
401
- key: 'onCdata',
402
- value: function onCdata(text) {
403
- var node = new SimpleDOMNode('#text', text);
404
- this._currentFragment.push(node);
404
+
405
+ return super.onResolveEntity(name);
406
+ }
407
+
408
+ onText(text) {
409
+ if (isWhitespaceString(text)) {
410
+ return;
405
411
  }
406
- }, {
407
- key: 'onBeginElement',
408
- value: function onBeginElement(name, attributes, isEmpty) {
409
- var node = new SimpleDOMNode(name);
410
- node.childNodes = [];
411
- this._currentFragment.push(node);
412
- if (isEmpty) {
413
- return;
414
- }
415
- this._stack.push(this._currentFragment);
416
- this._currentFragment = node.childNodes;
412
+
413
+ const node = new SimpleDOMNode("#text", text);
414
+
415
+ this._currentFragment.push(node);
416
+ }
417
+
418
+ onCdata(text) {
419
+ const node = new SimpleDOMNode("#text", text);
420
+
421
+ this._currentFragment.push(node);
422
+ }
423
+
424
+ onBeginElement(name, attributes, isEmpty) {
425
+ const node = new SimpleDOMNode(name);
426
+ node.childNodes = [];
427
+
428
+ this._currentFragment.push(node);
429
+
430
+ if (isEmpty) {
431
+ return;
417
432
  }
418
- }, {
419
- key: 'onEndElement',
420
- value: function onEndElement(name) {
421
- this._currentFragment = this._stack.pop();
422
- var lastElement = this._currentFragment[this._currentFragment.length - 1];
423
- for (var i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
424
- lastElement.childNodes[i].parentNode = lastElement;
425
- }
433
+
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;
426
445
  }
427
- }, {
428
- key: 'onError',
429
- value: function onError(code) {
430
- this._errorCode = code;
446
+
447
+ for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
448
+ lastElement.childNodes[i].parentNode = lastElement;
431
449
  }
432
- }]);
450
+ }
433
451
 
434
- return SimpleXMLParser;
435
- }(XMLParserBase);
452
+ onError(code) {
453
+ this._errorCode = code;
454
+ }
455
+
456
+ }
436
457
 
437
458
  exports.SimpleXMLParser = SimpleXMLParser;