@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4
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.
- package/README.md +1 -1
- package/package.json +33 -18
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/get.js +1857 -0
- package/pdfjs/dist/index.js +767 -0
- package/pdfjs/dist/l10n_utils.js +140 -0
- package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
- package/{src/display → pdfjs/dist}/network.js +149 -87
- package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
- package/{src/display → pdfjs/dist}/node_stream.js +133 -98
- package/pdfjs/dist/pdf.js +12778 -0
- package/pdfjs/dist/pdf_link_service.js +638 -0
- package/pdfjs/dist/pdf_rendering_queue.js +199 -0
- package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
- package/pdfjs/dist/pdf_viewer.js +3598 -0
- package/pdfjs/dist/typeof.js +100 -0
- package/pdfjs/dist/ui_utils.js +1033 -0
- package/{src/shared → pdfjs/dist}/util.js +301 -287
- package/pdfjs/dist/worker.js +62813 -0
- package/src/vcf-pdf-viewer.js +77 -27
- package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
- package/theme/material/vcf-pdf-viewer.js +2 -2
- package/src/core/.eslintrc +0 -13
- package/src/core/annotation.js +0 -2948
- package/src/core/arithmetic_decoder.js +0 -182
- package/src/core/ascii_85_stream.js +0 -98
- package/src/core/ascii_hex_stream.js +0 -79
- package/src/core/base_stream.js +0 -110
- package/src/core/bidi.js +0 -438
- package/src/core/calibri_factors.js +0 -308
- package/src/core/catalog.js +0 -1459
- package/src/core/ccitt.js +0 -1062
- package/src/core/ccitt_stream.js +0 -60
- package/src/core/cff_font.js +0 -116
- package/src/core/cff_parser.js +0 -1949
- package/src/core/charsets.js +0 -119
- package/src/core/chunked_stream.js +0 -557
- package/src/core/cmap.js +0 -1039
- package/src/core/colorspace.js +0 -1533
- package/src/core/core_utils.js +0 -464
- package/src/core/crypto.js +0 -1900
- package/src/core/decode_stream.js +0 -170
- package/src/core/decrypt_stream.js +0 -59
- package/src/core/default_appearance.js +0 -99
- package/src/core/document.js +0 -1456
- package/src/core/encodings.js +0 -301
- package/src/core/evaluator.js +0 -4601
- package/src/core/file_spec.js +0 -108
- package/src/core/flate_stream.js +0 -402
- package/src/core/font_renderer.js +0 -882
- package/src/core/fonts.js +0 -3260
- package/src/core/fonts_utils.js +0 -221
- package/src/core/function.js +0 -1257
- package/src/core/glyf.js +0 -706
- package/src/core/glyphlist.js +0 -4558
- package/src/core/helvetica_factors.js +0 -353
- package/src/core/image.js +0 -802
- package/src/core/image_utils.js +0 -291
- package/src/core/jbig2.js +0 -2572
- package/src/core/jbig2_stream.js +0 -73
- package/src/core/jpeg_stream.js +0 -105
- package/src/core/jpg.js +0 -1416
- package/src/core/jpx.js +0 -2343
- package/src/core/jpx_stream.js +0 -87
- package/src/core/liberationsans_widths.js +0 -221
- package/src/core/lzw_stream.js +0 -150
- package/src/core/metadata_parser.js +0 -146
- package/src/core/metrics.js +0 -2970
- package/src/core/murmurhash3.js +0 -139
- package/src/core/myriadpro_factors.js +0 -290
- package/src/core/name_number_tree.js +0 -153
- package/src/core/object_loader.js +0 -149
- package/src/core/opentype_file_builder.js +0 -154
- package/src/core/operator_list.js +0 -734
- package/src/core/parser.js +0 -1416
- package/src/core/pattern.js +0 -985
- package/src/core/pdf_manager.js +0 -217
- package/src/core/predictor_stream.js +0 -238
- package/src/core/primitives.js +0 -402
- package/src/core/ps_parser.js +0 -272
- package/src/core/run_length_stream.js +0 -61
- package/src/core/segoeui_factors.js +0 -308
- package/src/core/standard_fonts.js +0 -817
- package/src/core/stream.js +0 -103
- package/src/core/struct_tree.js +0 -335
- package/src/core/to_unicode_map.js +0 -103
- package/src/core/type1_font.js +0 -421
- package/src/core/type1_parser.js +0 -776
- package/src/core/unicode.js +0 -1649
- package/src/core/worker.js +0 -848
- package/src/core/worker_stream.js +0 -135
- package/src/core/writer.js +0 -278
- package/src/core/xfa/bind.js +0 -652
- package/src/core/xfa/builder.js +0 -207
- package/src/core/xfa/config.js +0 -1926
- package/src/core/xfa/connection_set.js +0 -202
- package/src/core/xfa/data.js +0 -82
- package/src/core/xfa/datasets.js +0 -76
- package/src/core/xfa/factory.js +0 -111
- package/src/core/xfa/fonts.js +0 -181
- package/src/core/xfa/formcalc_lexer.js +0 -385
- package/src/core/xfa/formcalc_parser.js +0 -1340
- package/src/core/xfa/html_utils.js +0 -639
- package/src/core/xfa/layout.js +0 -383
- package/src/core/xfa/locale_set.js +0 -345
- package/src/core/xfa/namespaces.js +0 -81
- package/src/core/xfa/parser.js +0 -184
- package/src/core/xfa/setup.js +0 -38
- package/src/core/xfa/signature.js +0 -40
- package/src/core/xfa/som.js +0 -338
- package/src/core/xfa/stylesheet.js +0 -40
- package/src/core/xfa/template.js +0 -6260
- package/src/core/xfa/text.js +0 -290
- package/src/core/xfa/unknown.js +0 -29
- package/src/core/xfa/utils.js +0 -217
- package/src/core/xfa/xdp.js +0 -59
- package/src/core/xfa/xfa_object.js +0 -1130
- package/src/core/xfa/xhtml.js +0 -543
- package/src/core/xfa_fonts.js +0 -208
- package/src/core/xml_parser.js +0 -507
- package/src/core/xref.js +0 -899
- package/src/display/annotation_layer.js +0 -2107
- package/src/display/annotation_storage.js +0 -113
- package/src/display/api.js +0 -3292
- package/src/display/base_factory.js +0 -180
- package/src/display/canvas.js +0 -2828
- package/src/display/font_loader.js +0 -484
- package/src/display/metadata.js +0 -41
- package/src/display/network_utils.js +0 -100
- package/src/display/node_utils.js +0 -83
- package/src/display/optional_content_config.js +0 -189
- package/src/display/pattern_helper.js +0 -659
- package/src/display/svg.js +0 -1709
- package/src/display/text_layer.js +0 -847
- package/src/display/transport_stream.js +0 -303
- package/src/display/worker_options.js +0 -40
- package/src/display/xfa_layer.js +0 -204
- package/src/doc_helper.js +0 -25
- package/src/images/logo.svg +0 -41
- package/src/interfaces.js +0 -169
- package/src/license_header.js +0 -14
- package/src/license_header_libre.js +0 -21
- package/src/pdf.image_decoders.js +0 -46
- package/src/pdf.js +0 -146
- package/src/pdf.sandbox.external.js +0 -181
- package/src/pdf.sandbox.js +0 -151
- package/src/pdf.scripting.js +0 -25
- package/src/pdf.worker.entry.js +0 -19
- package/src/pdf.worker.js +0 -23
- package/src/scripting_api/aform.js +0 -608
- package/src/scripting_api/app.js +0 -621
- package/src/scripting_api/color.js +0 -129
- package/src/scripting_api/common.js +0 -58
- package/src/scripting_api/console.js +0 -38
- package/src/scripting_api/constants.js +0 -208
- package/src/scripting_api/doc.js +0 -1195
- package/src/scripting_api/error.js +0 -23
- package/src/scripting_api/event.js +0 -232
- package/src/scripting_api/field.js +0 -620
- package/src/scripting_api/fullscreen.js +0 -145
- package/src/scripting_api/initialization.js +0 -223
- package/src/scripting_api/pdf_object.js +0 -24
- package/src/scripting_api/print_params.js +0 -146
- package/src/scripting_api/proxy.js +0 -139
- package/src/scripting_api/thermometer.js +0 -69
- package/src/scripting_api/util.js +0 -581
- package/src/shared/.eslintrc +0 -13
- package/src/shared/cffStandardStrings.js +0 -311
- package/src/shared/compatibility.js +0 -114
- package/src/shared/fonts_utils.js +0 -429
- package/src/shared/is_node.js +0 -27
- package/src/shared/scripting_utils.js +0 -85
- package/src/worker_loader.js +0 -32
package/src/core/xfa_fonts.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021 Mozilla Foundation
|
|
2
|
-
*
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
CalibriBoldFactors,
|
|
18
|
-
CalibriBoldItalicFactors,
|
|
19
|
-
CalibriBoldItalicLineHeight,
|
|
20
|
-
CalibriBoldLineHeight,
|
|
21
|
-
CalibriItalicFactors,
|
|
22
|
-
CalibriItalicLineHeight,
|
|
23
|
-
CalibriRegularFactors,
|
|
24
|
-
CalibriRegularLineHeight,
|
|
25
|
-
} from "./calibri_factors.js";
|
|
26
|
-
import {
|
|
27
|
-
HelveticaBoldFactors,
|
|
28
|
-
HelveticaBoldItalicFactors,
|
|
29
|
-
HelveticaBoldItalicLineHeight,
|
|
30
|
-
HelveticaBoldLineHeight,
|
|
31
|
-
HelveticaItalicFactors,
|
|
32
|
-
HelveticaItalicLineHeight,
|
|
33
|
-
HelveticaRegularFactors,
|
|
34
|
-
HelveticaRegularLineHeight,
|
|
35
|
-
} from "./helvetica_factors.js";
|
|
36
|
-
import {
|
|
37
|
-
LiberationSansBoldItalicWidths,
|
|
38
|
-
LiberationSansBoldWidths,
|
|
39
|
-
LiberationSansItalicWidths,
|
|
40
|
-
LiberationSansRegularWidths,
|
|
41
|
-
} from "./liberationsans_widths.js";
|
|
42
|
-
import {
|
|
43
|
-
MyriadProBoldFactors,
|
|
44
|
-
MyriadProBoldItalicFactors,
|
|
45
|
-
MyriadProBoldItalicLineHeight,
|
|
46
|
-
MyriadProBoldLineHeight,
|
|
47
|
-
MyriadProItalicFactors,
|
|
48
|
-
MyriadProItalicLineHeight,
|
|
49
|
-
MyriadProRegularFactors,
|
|
50
|
-
MyriadProRegularLineHeight,
|
|
51
|
-
} from "./myriadpro_factors.js";
|
|
52
|
-
import {
|
|
53
|
-
SegoeuiBoldFactors,
|
|
54
|
-
SegoeuiBoldItalicFactors,
|
|
55
|
-
SegoeuiBoldItalicLineHeight,
|
|
56
|
-
SegoeuiBoldLineHeight,
|
|
57
|
-
SegoeuiItalicFactors,
|
|
58
|
-
SegoeuiItalicLineHeight,
|
|
59
|
-
SegoeuiRegularFactors,
|
|
60
|
-
SegoeuiRegularLineHeight,
|
|
61
|
-
} from "./segoeui_factors.js";
|
|
62
|
-
import { getLookupTableFactory } from "./core_utils.js";
|
|
63
|
-
import { normalizeFontName } from "./fonts_utils.js";
|
|
64
|
-
|
|
65
|
-
const getXFAFontMap = getLookupTableFactory(function (t) {
|
|
66
|
-
t["MyriadPro-Regular"] = t["PdfJS-Fallback-Regular"] = {
|
|
67
|
-
name: "LiberationSans-Regular",
|
|
68
|
-
factors: MyriadProRegularFactors,
|
|
69
|
-
baseWidths: LiberationSansRegularWidths,
|
|
70
|
-
lineHeight: MyriadProRegularLineHeight,
|
|
71
|
-
};
|
|
72
|
-
t["MyriadPro-Bold"] = t["PdfJS-Fallback-Bold"] = {
|
|
73
|
-
name: "LiberationSans-Bold",
|
|
74
|
-
factors: MyriadProBoldFactors,
|
|
75
|
-
baseWidths: LiberationSansBoldWidths,
|
|
76
|
-
lineHeight: MyriadProBoldLineHeight,
|
|
77
|
-
};
|
|
78
|
-
t["MyriadPro-It"] =
|
|
79
|
-
t["MyriadPro-Italic"] =
|
|
80
|
-
t["PdfJS-Fallback-Italic"] =
|
|
81
|
-
{
|
|
82
|
-
name: "LiberationSans-Italic",
|
|
83
|
-
factors: MyriadProItalicFactors,
|
|
84
|
-
baseWidths: LiberationSansItalicWidths,
|
|
85
|
-
lineHeight: MyriadProItalicLineHeight,
|
|
86
|
-
};
|
|
87
|
-
t["MyriadPro-BoldIt"] =
|
|
88
|
-
t["MyriadPro-BoldItalic"] =
|
|
89
|
-
t["PdfJS-Fallback-BoldItalic"] =
|
|
90
|
-
{
|
|
91
|
-
name: "LiberationSans-BoldItalic",
|
|
92
|
-
factors: MyriadProBoldItalicFactors,
|
|
93
|
-
baseWidths: LiberationSansBoldItalicWidths,
|
|
94
|
-
lineHeight: MyriadProBoldItalicLineHeight,
|
|
95
|
-
};
|
|
96
|
-
t.ArialMT =
|
|
97
|
-
t.Arial =
|
|
98
|
-
t["Arial-Regular"] =
|
|
99
|
-
{
|
|
100
|
-
name: "LiberationSans-Regular",
|
|
101
|
-
baseWidths: LiberationSansRegularWidths,
|
|
102
|
-
};
|
|
103
|
-
t["Arial-BoldMT"] = t["Arial-Bold"] = {
|
|
104
|
-
name: "LiberationSans-Bold",
|
|
105
|
-
baseWidths: LiberationSansBoldWidths,
|
|
106
|
-
};
|
|
107
|
-
t["Arial-ItalicMT"] = t["Arial-Italic"] = {
|
|
108
|
-
name: "LiberationSans-Italic",
|
|
109
|
-
baseWidths: LiberationSansItalicWidths,
|
|
110
|
-
};
|
|
111
|
-
t["Arial-BoldItalicMT"] = t["Arial-BoldItalic"] = {
|
|
112
|
-
name: "LiberationSans-BoldItalic",
|
|
113
|
-
baseWidths: LiberationSansBoldItalicWidths,
|
|
114
|
-
};
|
|
115
|
-
t["Calibri-Regular"] = {
|
|
116
|
-
name: "LiberationSans-Regular",
|
|
117
|
-
factors: CalibriRegularFactors,
|
|
118
|
-
baseWidths: LiberationSansRegularWidths,
|
|
119
|
-
lineHeight: CalibriRegularLineHeight,
|
|
120
|
-
};
|
|
121
|
-
t["Calibri-Bold"] = {
|
|
122
|
-
name: "LiberationSans-Bold",
|
|
123
|
-
factors: CalibriBoldFactors,
|
|
124
|
-
baseWidths: LiberationSansBoldWidths,
|
|
125
|
-
lineHeight: CalibriBoldLineHeight,
|
|
126
|
-
};
|
|
127
|
-
t["Calibri-Italic"] = {
|
|
128
|
-
name: "LiberationSans-Italic",
|
|
129
|
-
factors: CalibriItalicFactors,
|
|
130
|
-
baseWidths: LiberationSansItalicWidths,
|
|
131
|
-
lineHeight: CalibriItalicLineHeight,
|
|
132
|
-
};
|
|
133
|
-
t["Calibri-BoldItalic"] = {
|
|
134
|
-
name: "LiberationSans-BoldItalic",
|
|
135
|
-
factors: CalibriBoldItalicFactors,
|
|
136
|
-
baseWidths: LiberationSansBoldItalicWidths,
|
|
137
|
-
lineHeight: CalibriBoldItalicLineHeight,
|
|
138
|
-
};
|
|
139
|
-
t["Segoeui-Regular"] = {
|
|
140
|
-
name: "LiberationSans-Regular",
|
|
141
|
-
factors: SegoeuiRegularFactors,
|
|
142
|
-
baseWidths: LiberationSansRegularWidths,
|
|
143
|
-
lineHeight: SegoeuiRegularLineHeight,
|
|
144
|
-
};
|
|
145
|
-
t["Segoeui-Bold"] = {
|
|
146
|
-
name: "LiberationSans-Bold",
|
|
147
|
-
factors: SegoeuiBoldFactors,
|
|
148
|
-
baseWidths: LiberationSansBoldWidths,
|
|
149
|
-
lineHeight: SegoeuiBoldLineHeight,
|
|
150
|
-
};
|
|
151
|
-
t["Segoeui-Italic"] = {
|
|
152
|
-
name: "LiberationSans-Italic",
|
|
153
|
-
factors: SegoeuiItalicFactors,
|
|
154
|
-
baseWidths: LiberationSansItalicWidths,
|
|
155
|
-
lineHeight: SegoeuiItalicLineHeight,
|
|
156
|
-
};
|
|
157
|
-
t["Segoeui-BoldItalic"] = {
|
|
158
|
-
name: "LiberationSans-BoldItalic",
|
|
159
|
-
factors: SegoeuiBoldItalicFactors,
|
|
160
|
-
baseWidths: LiberationSansBoldItalicWidths,
|
|
161
|
-
lineHeight: SegoeuiBoldItalicLineHeight,
|
|
162
|
-
};
|
|
163
|
-
t["Helvetica-Regular"] = t.Helvetica = {
|
|
164
|
-
name: "LiberationSans-Regular",
|
|
165
|
-
factors: HelveticaRegularFactors,
|
|
166
|
-
baseWidths: LiberationSansRegularWidths,
|
|
167
|
-
lineHeight: HelveticaRegularLineHeight,
|
|
168
|
-
};
|
|
169
|
-
t["Helvetica-Bold"] = {
|
|
170
|
-
name: "LiberationSans-Bold",
|
|
171
|
-
factors: HelveticaBoldFactors,
|
|
172
|
-
baseWidths: LiberationSansBoldWidths,
|
|
173
|
-
lineHeight: HelveticaBoldLineHeight,
|
|
174
|
-
};
|
|
175
|
-
t["Helvetica-Italic"] = {
|
|
176
|
-
name: "LiberationSans-Italic",
|
|
177
|
-
factors: HelveticaItalicFactors,
|
|
178
|
-
baseWidths: LiberationSansItalicWidths,
|
|
179
|
-
lineHeight: HelveticaItalicLineHeight,
|
|
180
|
-
};
|
|
181
|
-
t["Helvetica-BoldItalic"] = {
|
|
182
|
-
name: "LiberationSans-BoldItalic",
|
|
183
|
-
factors: HelveticaBoldItalicFactors,
|
|
184
|
-
baseWidths: LiberationSansBoldItalicWidths,
|
|
185
|
-
lineHeight: HelveticaBoldItalicLineHeight,
|
|
186
|
-
};
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
function getXfaFontName(name) {
|
|
190
|
-
const fontName = normalizeFontName(name);
|
|
191
|
-
const fontMap = getXFAFontMap();
|
|
192
|
-
return fontMap[fontName];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function getXfaFontWidths(name) {
|
|
196
|
-
const info = getXfaFontName(name);
|
|
197
|
-
if (!info) {
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const { baseWidths, factors } = info;
|
|
202
|
-
if (!factors) {
|
|
203
|
-
return baseWidths;
|
|
204
|
-
}
|
|
205
|
-
return baseWidths.map((w, i) => w * factors[i]);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export { getXfaFontName, getXfaFontWidths };
|
package/src/core/xml_parser.js
DELETED
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
/* Copyright 2018 Mozilla Foundation
|
|
2
|
-
*
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// The code for XMLParserBase copied from
|
|
17
|
-
// https://github.com/mozilla/shumway/blob/16451d8836fa85f4b16eeda8b4bda2fa9e2b22b0/src/avm2/natives/xml.ts
|
|
18
|
-
|
|
19
|
-
import { encodeToXmlString } from "./core_utils.js";
|
|
20
|
-
|
|
21
|
-
const XMLParserErrorCode = {
|
|
22
|
-
NoError: 0,
|
|
23
|
-
EndOfDocument: -1,
|
|
24
|
-
UnterminatedCdat: -2,
|
|
25
|
-
UnterminatedXmlDeclaration: -3,
|
|
26
|
-
UnterminatedDoctypeDeclaration: -4,
|
|
27
|
-
UnterminatedComment: -5,
|
|
28
|
-
MalformedElement: -6,
|
|
29
|
-
OutOfMemory: -7,
|
|
30
|
-
UnterminatedAttributeValue: -8,
|
|
31
|
-
UnterminatedElement: -9,
|
|
32
|
-
ElementNeverBegun: -10,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function isWhitespace(s, index) {
|
|
36
|
-
const ch = s[index];
|
|
37
|
-
return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function isWhitespaceString(s) {
|
|
41
|
-
for (let i = 0, ii = s.length; i < ii; i++) {
|
|
42
|
-
if (!isWhitespace(s, i)) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class XMLParserBase {
|
|
50
|
-
_resolveEntities(s) {
|
|
51
|
-
return s.replace(/&([^;]+);/g, (all, entity) => {
|
|
52
|
-
if (entity.substring(0, 2) === "#x") {
|
|
53
|
-
return String.fromCodePoint(parseInt(entity.substring(2), 16));
|
|
54
|
-
} else if (entity.substring(0, 1) === "#") {
|
|
55
|
-
return String.fromCodePoint(parseInt(entity.substring(1), 10));
|
|
56
|
-
}
|
|
57
|
-
switch (entity) {
|
|
58
|
-
case "lt":
|
|
59
|
-
return "<";
|
|
60
|
-
case "gt":
|
|
61
|
-
return ">";
|
|
62
|
-
case "amp":
|
|
63
|
-
return "&";
|
|
64
|
-
case "quot":
|
|
65
|
-
return '"';
|
|
66
|
-
case "apos":
|
|
67
|
-
return "'";
|
|
68
|
-
}
|
|
69
|
-
return this.onResolveEntity(entity);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
_parseContent(s, start) {
|
|
74
|
-
const attributes = [];
|
|
75
|
-
let pos = start;
|
|
76
|
-
|
|
77
|
-
function skipWs() {
|
|
78
|
-
while (pos < s.length && isWhitespace(s, pos)) {
|
|
79
|
-
++pos;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
while (
|
|
84
|
-
pos < s.length &&
|
|
85
|
-
!isWhitespace(s, pos) &&
|
|
86
|
-
s[pos] !== ">" &&
|
|
87
|
-
s[pos] !== "/"
|
|
88
|
-
) {
|
|
89
|
-
++pos;
|
|
90
|
-
}
|
|
91
|
-
const name = s.substring(start, pos);
|
|
92
|
-
skipWs();
|
|
93
|
-
while (
|
|
94
|
-
pos < s.length &&
|
|
95
|
-
s[pos] !== ">" &&
|
|
96
|
-
s[pos] !== "/" &&
|
|
97
|
-
s[pos] !== "?"
|
|
98
|
-
) {
|
|
99
|
-
skipWs();
|
|
100
|
-
let attrName = "",
|
|
101
|
-
attrValue = "";
|
|
102
|
-
while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
|
|
103
|
-
attrName += s[pos];
|
|
104
|
-
++pos;
|
|
105
|
-
}
|
|
106
|
-
skipWs();
|
|
107
|
-
if (s[pos] !== "=") {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
++pos;
|
|
111
|
-
skipWs();
|
|
112
|
-
const attrEndChar = s[pos];
|
|
113
|
-
if (attrEndChar !== '"' && attrEndChar !== "'") {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
const attrEndIndex = s.indexOf(attrEndChar, ++pos);
|
|
117
|
-
if (attrEndIndex < 0) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
attrValue = s.substring(pos, attrEndIndex);
|
|
121
|
-
attributes.push({
|
|
122
|
-
name: attrName,
|
|
123
|
-
value: this._resolveEntities(attrValue),
|
|
124
|
-
});
|
|
125
|
-
pos = attrEndIndex + 1;
|
|
126
|
-
skipWs();
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
name,
|
|
130
|
-
attributes,
|
|
131
|
-
parsed: pos - start,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_parseProcessingInstruction(s, start) {
|
|
136
|
-
let pos = start;
|
|
137
|
-
|
|
138
|
-
function skipWs() {
|
|
139
|
-
while (pos < s.length && isWhitespace(s, pos)) {
|
|
140
|
-
++pos;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
while (
|
|
145
|
-
pos < s.length &&
|
|
146
|
-
!isWhitespace(s, pos) &&
|
|
147
|
-
s[pos] !== ">" &&
|
|
148
|
-
s[pos] !== "?" &&
|
|
149
|
-
s[pos] !== "/"
|
|
150
|
-
) {
|
|
151
|
-
++pos;
|
|
152
|
-
}
|
|
153
|
-
const name = s.substring(start, pos);
|
|
154
|
-
skipWs();
|
|
155
|
-
const attrStart = pos;
|
|
156
|
-
while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
|
|
157
|
-
++pos;
|
|
158
|
-
}
|
|
159
|
-
const value = s.substring(attrStart, pos);
|
|
160
|
-
return {
|
|
161
|
-
name,
|
|
162
|
-
value,
|
|
163
|
-
parsed: pos - start,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
parseXml(s) {
|
|
168
|
-
let i = 0;
|
|
169
|
-
while (i < s.length) {
|
|
170
|
-
const ch = s[i];
|
|
171
|
-
let j = i;
|
|
172
|
-
if (ch === "<") {
|
|
173
|
-
++j;
|
|
174
|
-
const ch2 = s[j];
|
|
175
|
-
let q;
|
|
176
|
-
switch (ch2) {
|
|
177
|
-
case "/":
|
|
178
|
-
++j;
|
|
179
|
-
q = s.indexOf(">", j);
|
|
180
|
-
if (q < 0) {
|
|
181
|
-
this.onError(XMLParserErrorCode.UnterminatedElement);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
this.onEndElement(s.substring(j, q));
|
|
185
|
-
j = q + 1;
|
|
186
|
-
break;
|
|
187
|
-
case "?":
|
|
188
|
-
++j;
|
|
189
|
-
const pi = this._parseProcessingInstruction(s, j);
|
|
190
|
-
if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
|
|
191
|
-
this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
this.onPi(pi.name, pi.value);
|
|
195
|
-
j += pi.parsed + 2;
|
|
196
|
-
break;
|
|
197
|
-
case "!":
|
|
198
|
-
if (s.substring(j + 1, j + 3) === "--") {
|
|
199
|
-
q = s.indexOf("-->", j + 3);
|
|
200
|
-
if (q < 0) {
|
|
201
|
-
this.onError(XMLParserErrorCode.UnterminatedComment);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
this.onComment(s.substring(j + 3, q));
|
|
205
|
-
j = q + 3;
|
|
206
|
-
} else if (s.substring(j + 1, j + 8) === "[CDATA[") {
|
|
207
|
-
q = s.indexOf("]]>", j + 8);
|
|
208
|
-
if (q < 0) {
|
|
209
|
-
this.onError(XMLParserErrorCode.UnterminatedCdat);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
this.onCdata(s.substring(j + 8, q));
|
|
213
|
-
j = q + 3;
|
|
214
|
-
} else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
|
|
215
|
-
const q2 = s.indexOf("[", j + 8);
|
|
216
|
-
let complexDoctype = false;
|
|
217
|
-
q = s.indexOf(">", j + 8);
|
|
218
|
-
if (q < 0) {
|
|
219
|
-
this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
if (q2 > 0 && q > q2) {
|
|
223
|
-
q = s.indexOf("]>", j + 8);
|
|
224
|
-
if (q < 0) {
|
|
225
|
-
this.onError(
|
|
226
|
-
XMLParserErrorCode.UnterminatedDoctypeDeclaration
|
|
227
|
-
);
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
complexDoctype = true;
|
|
231
|
-
}
|
|
232
|
-
const doctypeContent = s.substring(
|
|
233
|
-
j + 8,
|
|
234
|
-
q + (complexDoctype ? 1 : 0)
|
|
235
|
-
);
|
|
236
|
-
this.onDoctype(doctypeContent);
|
|
237
|
-
j = q + (complexDoctype ? 2 : 1);
|
|
238
|
-
} else {
|
|
239
|
-
this.onError(XMLParserErrorCode.MalformedElement);
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
break;
|
|
243
|
-
default:
|
|
244
|
-
const content = this._parseContent(s, j);
|
|
245
|
-
if (content === null) {
|
|
246
|
-
this.onError(XMLParserErrorCode.MalformedElement);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
let isClosed = false;
|
|
250
|
-
if (
|
|
251
|
-
s.substring(j + content.parsed, j + content.parsed + 2) === "/>"
|
|
252
|
-
) {
|
|
253
|
-
isClosed = true;
|
|
254
|
-
} else if (
|
|
255
|
-
s.substring(j + content.parsed, j + content.parsed + 1) !== ">"
|
|
256
|
-
) {
|
|
257
|
-
this.onError(XMLParserErrorCode.UnterminatedElement);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
this.onBeginElement(content.name, content.attributes, isClosed);
|
|
261
|
-
j += content.parsed + (isClosed ? 2 : 1);
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
} else {
|
|
265
|
-
while (j < s.length && s[j] !== "<") {
|
|
266
|
-
j++;
|
|
267
|
-
}
|
|
268
|
-
const text = s.substring(i, j);
|
|
269
|
-
this.onText(this._resolveEntities(text));
|
|
270
|
-
}
|
|
271
|
-
i = j;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
onResolveEntity(name) {
|
|
276
|
-
return `&${name};`;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
onPi(name, value) {}
|
|
280
|
-
|
|
281
|
-
onComment(text) {}
|
|
282
|
-
|
|
283
|
-
onCdata(text) {}
|
|
284
|
-
|
|
285
|
-
onDoctype(doctypeContent) {}
|
|
286
|
-
|
|
287
|
-
onText(text) {}
|
|
288
|
-
|
|
289
|
-
onBeginElement(name, attributes, isEmpty) {}
|
|
290
|
-
|
|
291
|
-
onEndElement(name) {}
|
|
292
|
-
|
|
293
|
-
onError(code) {}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
class SimpleDOMNode {
|
|
297
|
-
constructor(nodeName, nodeValue) {
|
|
298
|
-
this.nodeName = nodeName;
|
|
299
|
-
this.nodeValue = nodeValue;
|
|
300
|
-
|
|
301
|
-
Object.defineProperty(this, "parentNode", { value: null, writable: true });
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
get firstChild() {
|
|
305
|
-
return this.childNodes && this.childNodes[0];
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
get nextSibling() {
|
|
309
|
-
const childNodes = this.parentNode.childNodes;
|
|
310
|
-
if (!childNodes) {
|
|
311
|
-
return undefined;
|
|
312
|
-
}
|
|
313
|
-
const index = childNodes.indexOf(this);
|
|
314
|
-
if (index === -1) {
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
return childNodes[index + 1];
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
get textContent() {
|
|
321
|
-
if (!this.childNodes) {
|
|
322
|
-
return this.nodeValue || "";
|
|
323
|
-
}
|
|
324
|
-
return this.childNodes
|
|
325
|
-
.map(function (child) {
|
|
326
|
-
return child.textContent;
|
|
327
|
-
})
|
|
328
|
-
.join("");
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
hasChildNodes() {
|
|
332
|
-
return this.childNodes && this.childNodes.length > 0;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Search a node in the tree with the given path
|
|
337
|
-
* foo.bar[nnn], i.e. find the nnn-th node named
|
|
338
|
-
* bar under a node named foo.
|
|
339
|
-
*
|
|
340
|
-
* @param {Array} paths - an array of objects as
|
|
341
|
-
* returned by {parseXFAPath}.
|
|
342
|
-
* @param {number} pos - the current position in
|
|
343
|
-
* the paths array.
|
|
344
|
-
* @returns {SimpleDOMNode} The node corresponding
|
|
345
|
-
* to the path or null if not found.
|
|
346
|
-
*/
|
|
347
|
-
searchNode(paths, pos) {
|
|
348
|
-
if (pos >= paths.length) {
|
|
349
|
-
return this;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const component = paths[pos];
|
|
353
|
-
const stack = [];
|
|
354
|
-
let node = this;
|
|
355
|
-
|
|
356
|
-
while (true) {
|
|
357
|
-
if (component.name === node.nodeName) {
|
|
358
|
-
if (component.pos === 0) {
|
|
359
|
-
const res = node.searchNode(paths, pos + 1);
|
|
360
|
-
if (res !== null) {
|
|
361
|
-
return res;
|
|
362
|
-
}
|
|
363
|
-
} else if (stack.length === 0) {
|
|
364
|
-
return null;
|
|
365
|
-
} else {
|
|
366
|
-
const [parent] = stack.pop();
|
|
367
|
-
let siblingPos = 0;
|
|
368
|
-
for (const child of parent.childNodes) {
|
|
369
|
-
if (component.name === child.nodeName) {
|
|
370
|
-
if (siblingPos === component.pos) {
|
|
371
|
-
return child.searchNode(paths, pos + 1);
|
|
372
|
-
}
|
|
373
|
-
siblingPos++;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
// We didn't find the correct sibling
|
|
377
|
-
// so just return the first found node
|
|
378
|
-
return node.searchNode(paths, pos + 1);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (node.childNodes && node.childNodes.length !== 0) {
|
|
383
|
-
stack.push([node, 0]);
|
|
384
|
-
node = node.childNodes[0];
|
|
385
|
-
} else if (stack.length === 0) {
|
|
386
|
-
return null;
|
|
387
|
-
} else {
|
|
388
|
-
while (stack.length !== 0) {
|
|
389
|
-
const [parent, currentPos] = stack.pop();
|
|
390
|
-
const newPos = currentPos + 1;
|
|
391
|
-
if (newPos < parent.childNodes.length) {
|
|
392
|
-
stack.push([parent, newPos]);
|
|
393
|
-
node = parent.childNodes[newPos];
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
if (stack.length === 0) {
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
dump(buffer) {
|
|
405
|
-
if (this.nodeName === "#text") {
|
|
406
|
-
buffer.push(encodeToXmlString(this.nodeValue));
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
buffer.push(`<${this.nodeName}`);
|
|
411
|
-
if (this.attributes) {
|
|
412
|
-
for (const attribute of this.attributes) {
|
|
413
|
-
buffer.push(
|
|
414
|
-
` ${attribute.name}="${encodeToXmlString(attribute.value)}"`
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
if (this.hasChildNodes()) {
|
|
419
|
-
buffer.push(">");
|
|
420
|
-
for (const child of this.childNodes) {
|
|
421
|
-
child.dump(buffer);
|
|
422
|
-
}
|
|
423
|
-
buffer.push(`</${this.nodeName}>`);
|
|
424
|
-
} else if (this.nodeValue) {
|
|
425
|
-
buffer.push(`>${encodeToXmlString(this.nodeValue)}</${this.nodeName}>`);
|
|
426
|
-
} else {
|
|
427
|
-
buffer.push("/>");
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
class SimpleXMLParser extends XMLParserBase {
|
|
433
|
-
constructor({ hasAttributes = false, lowerCaseName = false }) {
|
|
434
|
-
super();
|
|
435
|
-
this._currentFragment = null;
|
|
436
|
-
this._stack = null;
|
|
437
|
-
this._errorCode = XMLParserErrorCode.NoError;
|
|
438
|
-
this._hasAttributes = hasAttributes;
|
|
439
|
-
this._lowerCaseName = lowerCaseName;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
parseFromString(data) {
|
|
443
|
-
this._currentFragment = [];
|
|
444
|
-
this._stack = [];
|
|
445
|
-
this._errorCode = XMLParserErrorCode.NoError;
|
|
446
|
-
|
|
447
|
-
this.parseXml(data);
|
|
448
|
-
|
|
449
|
-
if (this._errorCode !== XMLParserErrorCode.NoError) {
|
|
450
|
-
return undefined; // return undefined on error
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// We should only have one root.
|
|
454
|
-
const [documentElement] = this._currentFragment;
|
|
455
|
-
if (!documentElement) {
|
|
456
|
-
return undefined; // Return undefined if no root was found.
|
|
457
|
-
}
|
|
458
|
-
return { documentElement };
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
onText(text) {
|
|
462
|
-
if (isWhitespaceString(text)) {
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
const node = new SimpleDOMNode("#text", text);
|
|
466
|
-
this._currentFragment.push(node);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
onCdata(text) {
|
|
470
|
-
const node = new SimpleDOMNode("#text", text);
|
|
471
|
-
this._currentFragment.push(node);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
onBeginElement(name, attributes, isEmpty) {
|
|
475
|
-
if (this._lowerCaseName) {
|
|
476
|
-
name = name.toLowerCase();
|
|
477
|
-
}
|
|
478
|
-
const node = new SimpleDOMNode(name);
|
|
479
|
-
node.childNodes = [];
|
|
480
|
-
if (this._hasAttributes) {
|
|
481
|
-
node.attributes = attributes;
|
|
482
|
-
}
|
|
483
|
-
this._currentFragment.push(node);
|
|
484
|
-
if (isEmpty) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
this._stack.push(this._currentFragment);
|
|
488
|
-
this._currentFragment = node.childNodes;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
onEndElement(name) {
|
|
492
|
-
this._currentFragment = this._stack.pop() || [];
|
|
493
|
-
const lastElement = this._currentFragment[this._currentFragment.length - 1];
|
|
494
|
-
if (!lastElement) {
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
|
|
498
|
-
lastElement.childNodes[i].parentNode = lastElement;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
onError(code) {
|
|
503
|
-
this._errorCode = code;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export { SimpleDOMNode, SimpleXMLParser, XMLParserBase, XMLParserErrorCode };
|