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.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +1144 -927
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- 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
|
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
|
-
|
75
|
-
return ch ===
|
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 (
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
101
|
-
|
102
|
-
return
|
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
|
-
|
108
|
-
|
109
|
-
return '<';
|
70
|
+
case "gt":
|
71
|
+
return ">";
|
110
72
|
|
111
|
-
|
112
|
-
|
73
|
+
case "amp":
|
74
|
+
return "&";
|
113
75
|
|
114
|
-
|
115
|
-
|
76
|
+
case "quot":
|
77
|
+
return '"';
|
78
|
+
}
|
116
79
|
|
117
|
-
|
118
|
-
|
119
|
-
|
80
|
+
return this.onResolveEntity(entity);
|
81
|
+
});
|
82
|
+
}
|
120
83
|
|
121
|
-
|
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
|
-
|
88
|
+
function skipWs() {
|
89
|
+
while (pos < s.length && isWhitespace(s, pos)) {
|
138
90
|
++pos;
|
139
91
|
}
|
92
|
+
}
|
140
93
|
|
141
|
-
|
142
|
-
|
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
|
-
|
98
|
+
const name = s.substring(start, pos);
|
99
|
+
skipWs();
|
155
100
|
|
156
|
-
|
157
|
-
|
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
|
-
|
162
|
-
var attrEndChar = s[pos];
|
109
|
+
}
|
163
110
|
|
164
|
-
|
165
|
-
return null;
|
166
|
-
}
|
111
|
+
skipWs();
|
167
112
|
|
168
|
-
|
113
|
+
if (s[pos] !== "=") {
|
114
|
+
return null;
|
115
|
+
}
|
169
116
|
|
170
|
-
|
171
|
-
|
172
|
-
|
117
|
+
++pos;
|
118
|
+
skipWs();
|
119
|
+
const attrEndChar = s[pos];
|
173
120
|
|
174
|
-
|
175
|
-
|
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
|
-
|
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
|
-
|
203
|
-
|
127
|
+
if (attrEndIndex < 0) {
|
128
|
+
return null;
|
204
129
|
}
|
205
130
|
|
206
|
-
|
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
|
-
|
138
|
+
}
|
139
|
+
|
140
|
+
return {
|
141
|
+
name,
|
142
|
+
attributes,
|
143
|
+
parsed: pos - start
|
144
|
+
};
|
145
|
+
}
|
209
146
|
|
210
|
-
|
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
|
-
|
215
|
-
|
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
|
-
|
227
|
-
|
228
|
-
|
160
|
+
const name = s.substring(start, pos);
|
161
|
+
skipWs();
|
162
|
+
const attrStart = pos;
|
229
163
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
var q = void 0;
|
164
|
+
while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
|
165
|
+
++pos;
|
166
|
+
}
|
234
167
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
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.
|
221
|
+
this.onError(XMLParserErrorCode.UnterminatedComment);
|
242
222
|
return;
|
243
223
|
}
|
244
224
|
|
245
|
-
this.
|
246
|
-
j = q +
|
247
|
-
|
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
|
-
|
250
|
-
|
230
|
+
if (q < 0) {
|
231
|
+
this.onError(XMLParserErrorCode.UnterminatedCdat);
|
232
|
+
return;
|
233
|
+
}
|
251
234
|
|
252
|
-
|
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 (
|
255
|
-
this.onError(XMLParserErrorCode.
|
242
|
+
if (q < 0) {
|
243
|
+
this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
|
256
244
|
return;
|
257
245
|
}
|
258
246
|
|
259
|
-
|
260
|
-
|
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.
|
251
|
+
this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
|
269
252
|
return;
|
270
253
|
}
|
271
254
|
|
272
|
-
|
273
|
-
|
274
|
-
} else if (s.substring(j + 1, j + 8) === '[CDATA[') {
|
275
|
-
q = s.indexOf(']]>', j + 8);
|
255
|
+
complexDoctype = true;
|
256
|
+
}
|
276
257
|
|
277
|
-
|
278
|
-
|
279
|
-
|
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
|
-
|
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
|
-
|
290
|
-
|
291
|
-
return;
|
292
|
-
}
|
268
|
+
default:
|
269
|
+
const content = this._parseContent(s, j);
|
293
270
|
|
294
|
-
|
295
|
-
|
271
|
+
if (content === null) {
|
272
|
+
this.onError(XMLParserErrorCode.MalformedElement);
|
273
|
+
return;
|
274
|
+
}
|
296
275
|
|
297
|
-
|
298
|
-
this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
|
299
|
-
return;
|
300
|
-
}
|
276
|
+
let isClosed = false;
|
301
277
|
|
302
|
-
|
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
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
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
|
-
|
294
|
+
const text = s.substring(i, j);
|
295
|
+
this.onText(this._resolveEntities(text));
|
296
|
+
}
|
314
297
|
|
315
|
-
|
316
|
-
|
298
|
+
i = j;
|
299
|
+
}
|
300
|
+
}
|
317
301
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
}
|
302
|
+
onResolveEntity(name) {
|
303
|
+
return `&${name};`;
|
304
|
+
}
|
322
305
|
|
323
|
-
|
306
|
+
onPi(name, value) {}
|
324
307
|
|
325
|
-
|
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
|
-
|
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
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
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,
|
328
|
+
Object.defineProperty(this, "parentNode", {
|
391
329
|
value: null,
|
392
330
|
writable: true
|
393
331
|
});
|
394
332
|
}
|
395
333
|
|
396
|
-
|
397
|
-
|
398
|
-
|
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
|
-
|
412
|
-
|
413
|
-
}
|
338
|
+
get nextSibling() {
|
339
|
+
const childNodes = this.parentNode.childNodes;
|
414
340
|
|
415
|
-
|
341
|
+
if (!childNodes) {
|
342
|
+
return undefined;
|
343
|
+
}
|
416
344
|
|
417
|
-
|
418
|
-
return undefined;
|
419
|
-
}
|
345
|
+
const index = childNodes.indexOf(this);
|
420
346
|
|
421
|
-
|
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
|
-
|
431
|
-
|
432
|
-
}).join('');
|
433
|
-
}
|
434
|
-
}]);
|
351
|
+
return childNodes[index + 1];
|
352
|
+
}
|
435
353
|
|
436
|
-
|
437
|
-
|
354
|
+
get textContent() {
|
355
|
+
if (!this.childNodes) {
|
356
|
+
return this.nodeValue || "";
|
357
|
+
}
|
438
358
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
359
|
+
return this.childNodes.map(function (child) {
|
360
|
+
return child.textContent;
|
361
|
+
}).join("");
|
362
|
+
}
|
443
363
|
|
444
|
-
|
445
|
-
|
364
|
+
hasChildNodes() {
|
365
|
+
return this.childNodes && this.childNodes.length > 0;
|
366
|
+
}
|
446
367
|
|
447
|
-
|
368
|
+
}
|
448
369
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
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
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
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
|
-
|
465
|
-
|
466
|
-
|
384
|
+
if (this._errorCode !== XMLParserErrorCode.NoError) {
|
385
|
+
return undefined;
|
386
|
+
}
|
467
387
|
|
468
|
-
|
469
|
-
documentElement = _this$_currentFragmen[0];
|
388
|
+
const [documentElement] = this._currentFragment;
|
470
389
|
|
471
|
-
|
472
|
-
|
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
|
-
|
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
|
-
|
405
|
+
return super.onResolveEntity(name);
|
406
|
+
}
|
497
407
|
|
498
|
-
|
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
|
-
|
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
|
-
|
415
|
+
this._currentFragment.push(node);
|
416
|
+
}
|
514
417
|
|
515
|
-
|
516
|
-
|
517
|
-
|
418
|
+
onCdata(text) {
|
419
|
+
const node = new SimpleDOMNode("#text", text);
|
420
|
+
|
421
|
+
this._currentFragment.push(node);
|
422
|
+
}
|
518
423
|
|
519
|
-
|
424
|
+
onBeginElement(name, attributes, isEmpty) {
|
425
|
+
const node = new SimpleDOMNode(name);
|
426
|
+
node.childNodes = [];
|
520
427
|
|
521
|
-
|
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
|
-
|
534
|
-
|
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
|
-
|
539
|
-
|
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
|
-
|
545
|
-
}(XMLParserBase);
|
456
|
+
}
|
546
457
|
|
547
458
|
exports.SimpleXMLParser = SimpleXMLParser;
|