pdfjs-dist 2.2.228 → 2.6.347

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 (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
@@ -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 2019 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;