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.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- 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 +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -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/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- 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 +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- 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
|
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
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
|
28
|
-
|
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
|
-
|
55
|
-
return ch ===
|
43
|
+
const ch = s[index];
|
44
|
+
return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
|
56
45
|
}
|
46
|
+
|
57
47
|
function isWhitespaceString(s) {
|
58
|
-
for (
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
return
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
|
157
|
-
|
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
|
-
|
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
|
-
|
162
|
-
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
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.
|
221
|
+
this.onError(XMLParserErrorCode.UnterminatedComment);
|
189
222
|
return;
|
190
223
|
}
|
191
|
-
|
192
|
-
j
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if (
|
198
|
-
this.onError(XMLParserErrorCode.
|
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
|
-
|
202
|
-
j
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
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
|
-
|
230
|
-
|
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
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
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
|
-
|
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
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
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,
|
328
|
+
Object.defineProperty(this, "parentNode", {
|
313
329
|
value: null,
|
314
330
|
writable: true
|
315
331
|
});
|
316
332
|
}
|
317
333
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
return
|
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
|
-
|
347
|
-
}();
|
345
|
+
const index = childNodes.indexOf(this);
|
348
346
|
|
349
|
-
|
350
|
-
|
347
|
+
if (index === -1) {
|
348
|
+
return undefined;
|
349
|
+
}
|
351
350
|
|
352
|
-
|
353
|
-
|
351
|
+
return childNodes[index + 1];
|
352
|
+
}
|
354
353
|
|
355
|
-
|
354
|
+
get textContent() {
|
355
|
+
if (!this.childNodes) {
|
356
|
+
return this.nodeValue || "";
|
357
|
+
}
|
356
358
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
return _this;
|
359
|
+
return this.childNodes.map(function (child) {
|
360
|
+
return child.textContent;
|
361
|
+
}).join("");
|
361
362
|
}
|
362
363
|
|
363
|
-
|
364
|
-
|
365
|
-
|
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
|
-
|
375
|
-
documentElement = _currentFragment[0];
|
368
|
+
}
|
376
369
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
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
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
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
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
393
|
+
|
394
|
+
return {
|
395
|
+
documentElement
|
396
|
+
};
|
397
|
+
}
|
398
|
+
|
399
|
+
onResolveEntity(name) {
|
400
|
+
switch (name) {
|
401
|
+
case "apos":
|
402
|
+
return "'";
|
399
403
|
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
404
|
+
|
405
|
+
return super.onResolveEntity(name);
|
406
|
+
}
|
407
|
+
|
408
|
+
onText(text) {
|
409
|
+
if (isWhitespaceString(text)) {
|
410
|
+
return;
|
405
411
|
}
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
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
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
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
|
-
|
429
|
-
|
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
|
-
|
435
|
-
|
452
|
+
onError(code) {
|
453
|
+
this._errorCode = code;
|
454
|
+
}
|
455
|
+
|
456
|
+
}
|
436
457
|
|
437
458
|
exports.SimpleXMLParser = SimpleXMLParser;
|