@loaders.gl/wms 3.3.0-alpha.10
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/LICENSE +41 -0
- package/README.md +7 -0
- package/dist/dist.min.js +2277 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +34 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/data-sources/image-data-source.js +4 -0
- package/dist/es5/lib/data-sources/image-data-source.js.map +1 -0
- package/dist/es5/lib/data-sources/wms-data-source.js +223 -0
- package/dist/es5/lib/data-sources/wms-data-source.js.map +1 -0
- package/dist/es5/lib/parse-wms.js +102 -0
- package/dist/es5/lib/parse-wms.js.map +1 -0
- package/dist/es5/wms-capabilities-loader.js +54 -0
- package/dist/es5/wms-capabilities-loader.js.map +1 -0
- package/dist/es5/wms-feature-info-loader.js +44 -0
- package/dist/es5/wms-feature-info-loader.js.map +1 -0
- package/dist/es5/wms-layer-description-loader.js +44 -0
- package/dist/es5/wms-layer-description-loader.js.map +1 -0
- package/dist/es5/wms-types.js +2 -0
- package/dist/es5/wms-types.js.map +1 -0
- package/dist/esm/bundle.js +6 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/data-sources/image-data-source.js +2 -0
- package/dist/esm/lib/data-sources/image-data-source.js.map +1 -0
- package/dist/esm/lib/data-sources/wms-data-source.js +70 -0
- package/dist/esm/lib/data-sources/wms-data-source.js.map +1 -0
- package/dist/esm/lib/parse-wms.js +70 -0
- package/dist/esm/lib/parse-wms.js.map +1 -0
- package/dist/esm/wms-capabilities-loader.js +25 -0
- package/dist/esm/wms-capabilities-loader.js.map +1 -0
- package/dist/esm/wms-feature-info-loader.js +14 -0
- package/dist/esm/wms-feature-info-loader.js.map +1 -0
- package/dist/esm/wms-layer-description-loader.js +14 -0
- package/dist/esm/wms-layer-description-loader.js.map +1 -0
- package/dist/esm/wms-types.js +2 -0
- package/dist/esm/wms-types.js.map +1 -0
- package/package.json +43 -0
- package/src/bundle.ts +6 -0
- package/src/index.ts +13 -0
- package/src/lib/data-sources/image-data-source.ts +84 -0
- package/src/lib/data-sources/wms-data-source.ts +99 -0
- package/src/lib/parse-wms.ts +92 -0
- package/src/wms-capabilities-loader.ts +40 -0
- package/src/wms-feature-info-loader.ts +21 -0
- package/src/wms-layer-description-loader.ts +21 -0
- package/src/wms-types.ts +2051 -0
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,2277 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
__markAsModule(target);
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, module, desc) => {
|
|
21
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(module))
|
|
23
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
24
|
+
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
var __toModule = (module) => {
|
|
29
|
+
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ../xml/node_modules/fast-xml-parser/src/util.js
|
|
33
|
+
var require_util = __commonJS({
|
|
34
|
+
"../xml/node_modules/fast-xml-parser/src/util.js"(exports) {
|
|
35
|
+
"use strict";
|
|
36
|
+
var nameStartChar = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
|
37
|
+
var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
|
38
|
+
var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
|
|
39
|
+
var regexName = new RegExp("^" + nameRegexp + "$");
|
|
40
|
+
var getAllMatches = function(string, regex) {
|
|
41
|
+
const matches2 = [];
|
|
42
|
+
let match = regex.exec(string);
|
|
43
|
+
while (match) {
|
|
44
|
+
const allmatches = [];
|
|
45
|
+
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
46
|
+
const len = match.length;
|
|
47
|
+
for (let index = 0; index < len; index++) {
|
|
48
|
+
allmatches.push(match[index]);
|
|
49
|
+
}
|
|
50
|
+
matches2.push(allmatches);
|
|
51
|
+
match = regex.exec(string);
|
|
52
|
+
}
|
|
53
|
+
return matches2;
|
|
54
|
+
};
|
|
55
|
+
var isName = function(string) {
|
|
56
|
+
const match = regexName.exec(string);
|
|
57
|
+
return !(match === null || typeof match === "undefined");
|
|
58
|
+
};
|
|
59
|
+
exports.isExist = function(v) {
|
|
60
|
+
return typeof v !== "undefined";
|
|
61
|
+
};
|
|
62
|
+
exports.isEmptyObject = function(obj) {
|
|
63
|
+
return Object.keys(obj).length === 0;
|
|
64
|
+
};
|
|
65
|
+
exports.merge = function(target, a, arrayMode) {
|
|
66
|
+
if (a) {
|
|
67
|
+
const keys = Object.keys(a);
|
|
68
|
+
const len = keys.length;
|
|
69
|
+
for (let i = 0; i < len; i++) {
|
|
70
|
+
if (arrayMode === "strict") {
|
|
71
|
+
target[keys[i]] = [a[keys[i]]];
|
|
72
|
+
} else {
|
|
73
|
+
target[keys[i]] = a[keys[i]];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.getValue = function(v) {
|
|
79
|
+
if (exports.isExist(v)) {
|
|
80
|
+
return v;
|
|
81
|
+
} else {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.isName = isName;
|
|
86
|
+
exports.getAllMatches = getAllMatches;
|
|
87
|
+
exports.nameRegexp = nameRegexp;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// ../xml/node_modules/fast-xml-parser/src/validator.js
|
|
92
|
+
var require_validator = __commonJS({
|
|
93
|
+
"../xml/node_modules/fast-xml-parser/src/validator.js"(exports) {
|
|
94
|
+
"use strict";
|
|
95
|
+
var util = require_util();
|
|
96
|
+
var defaultOptions = {
|
|
97
|
+
allowBooleanAttributes: false,
|
|
98
|
+
unpairedTags: []
|
|
99
|
+
};
|
|
100
|
+
exports.validate = function(xmlData, options) {
|
|
101
|
+
options = Object.assign({}, defaultOptions, options);
|
|
102
|
+
const tags = [];
|
|
103
|
+
let tagFound = false;
|
|
104
|
+
let reachedRoot = false;
|
|
105
|
+
if (xmlData[0] === "\uFEFF") {
|
|
106
|
+
xmlData = xmlData.substr(1);
|
|
107
|
+
}
|
|
108
|
+
for (let i = 0; i < xmlData.length; i++) {
|
|
109
|
+
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
110
|
+
i += 2;
|
|
111
|
+
i = readPI(xmlData, i);
|
|
112
|
+
if (i.err)
|
|
113
|
+
return i;
|
|
114
|
+
} else if (xmlData[i] === "<") {
|
|
115
|
+
let tagStartPos = i;
|
|
116
|
+
i++;
|
|
117
|
+
if (xmlData[i] === "!") {
|
|
118
|
+
i = readCommentAndCDATA(xmlData, i);
|
|
119
|
+
continue;
|
|
120
|
+
} else {
|
|
121
|
+
let closingTag = false;
|
|
122
|
+
if (xmlData[i] === "/") {
|
|
123
|
+
closingTag = true;
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
let tagName = "";
|
|
127
|
+
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
|
|
128
|
+
tagName += xmlData[i];
|
|
129
|
+
}
|
|
130
|
+
tagName = tagName.trim();
|
|
131
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
132
|
+
tagName = tagName.substring(0, tagName.length - 1);
|
|
133
|
+
i--;
|
|
134
|
+
}
|
|
135
|
+
if (!validateTagName(tagName)) {
|
|
136
|
+
let msg;
|
|
137
|
+
if (tagName.trim().length === 0) {
|
|
138
|
+
msg = "Invalid space after '<'.";
|
|
139
|
+
} else {
|
|
140
|
+
msg = "Tag '" + tagName + "' is an invalid name.";
|
|
141
|
+
}
|
|
142
|
+
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
143
|
+
}
|
|
144
|
+
const result = readAttributeStr(xmlData, i);
|
|
145
|
+
if (result === false) {
|
|
146
|
+
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
147
|
+
}
|
|
148
|
+
let attrStr = result.value;
|
|
149
|
+
i = result.index;
|
|
150
|
+
if (attrStr[attrStr.length - 1] === "/") {
|
|
151
|
+
const attrStrStart = i - attrStr.length;
|
|
152
|
+
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
153
|
+
const isValid = validateAttributeString(attrStr, options);
|
|
154
|
+
if (isValid === true) {
|
|
155
|
+
tagFound = true;
|
|
156
|
+
} else {
|
|
157
|
+
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
158
|
+
}
|
|
159
|
+
} else if (closingTag) {
|
|
160
|
+
if (!result.tagClosed) {
|
|
161
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
162
|
+
} else if (attrStr.trim().length > 0) {
|
|
163
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
164
|
+
} else {
|
|
165
|
+
const otg = tags.pop();
|
|
166
|
+
if (tagName !== otg.tagName) {
|
|
167
|
+
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
168
|
+
return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
169
|
+
}
|
|
170
|
+
if (tags.length == 0) {
|
|
171
|
+
reachedRoot = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
const isValid = validateAttributeString(attrStr, options);
|
|
176
|
+
if (isValid !== true) {
|
|
177
|
+
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
178
|
+
}
|
|
179
|
+
if (reachedRoot === true) {
|
|
180
|
+
return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
|
|
181
|
+
} else if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
182
|
+
} else {
|
|
183
|
+
tags.push({ tagName, tagStartPos });
|
|
184
|
+
}
|
|
185
|
+
tagFound = true;
|
|
186
|
+
}
|
|
187
|
+
for (i++; i < xmlData.length; i++) {
|
|
188
|
+
if (xmlData[i] === "<") {
|
|
189
|
+
if (xmlData[i + 1] === "!") {
|
|
190
|
+
i++;
|
|
191
|
+
i = readCommentAndCDATA(xmlData, i);
|
|
192
|
+
continue;
|
|
193
|
+
} else if (xmlData[i + 1] === "?") {
|
|
194
|
+
i = readPI(xmlData, ++i);
|
|
195
|
+
if (i.err)
|
|
196
|
+
return i;
|
|
197
|
+
} else {
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
} else if (xmlData[i] === "&") {
|
|
201
|
+
const afterAmp = validateAmpersand(xmlData, i);
|
|
202
|
+
if (afterAmp == -1)
|
|
203
|
+
return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
204
|
+
i = afterAmp;
|
|
205
|
+
} else {
|
|
206
|
+
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
207
|
+
return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (xmlData[i] === "<") {
|
|
212
|
+
i--;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
if (isWhiteSpace(xmlData[i])) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!tagFound) {
|
|
223
|
+
return getErrorObject("InvalidXml", "Start tag expected.", 1);
|
|
224
|
+
} else if (tags.length == 1) {
|
|
225
|
+
return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
226
|
+
} else if (tags.length > 0) {
|
|
227
|
+
return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
};
|
|
231
|
+
function isWhiteSpace(char) {
|
|
232
|
+
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
233
|
+
}
|
|
234
|
+
function readPI(xmlData, i) {
|
|
235
|
+
const start = i;
|
|
236
|
+
for (; i < xmlData.length; i++) {
|
|
237
|
+
if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
238
|
+
const tagname = xmlData.substr(start, i - start);
|
|
239
|
+
if (i > 5 && tagname === "xml") {
|
|
240
|
+
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
241
|
+
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
242
|
+
i++;
|
|
243
|
+
break;
|
|
244
|
+
} else {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return i;
|
|
250
|
+
}
|
|
251
|
+
function readCommentAndCDATA(xmlData, i) {
|
|
252
|
+
if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
|
|
253
|
+
for (i += 3; i < xmlData.length; i++) {
|
|
254
|
+
if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
|
|
255
|
+
i += 2;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
} else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
|
|
260
|
+
let angleBracketsCount = 1;
|
|
261
|
+
for (i += 8; i < xmlData.length; i++) {
|
|
262
|
+
if (xmlData[i] === "<") {
|
|
263
|
+
angleBracketsCount++;
|
|
264
|
+
} else if (xmlData[i] === ">") {
|
|
265
|
+
angleBracketsCount--;
|
|
266
|
+
if (angleBracketsCount === 0) {
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
|
|
272
|
+
for (i += 8; i < xmlData.length; i++) {
|
|
273
|
+
if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
|
|
274
|
+
i += 2;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return i;
|
|
280
|
+
}
|
|
281
|
+
var doubleQuote = '"';
|
|
282
|
+
var singleQuote = "'";
|
|
283
|
+
function readAttributeStr(xmlData, i) {
|
|
284
|
+
let attrStr = "";
|
|
285
|
+
let startChar = "";
|
|
286
|
+
let tagClosed = false;
|
|
287
|
+
for (; i < xmlData.length; i++) {
|
|
288
|
+
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
|
289
|
+
if (startChar === "") {
|
|
290
|
+
startChar = xmlData[i];
|
|
291
|
+
} else if (startChar !== xmlData[i]) {
|
|
292
|
+
} else {
|
|
293
|
+
startChar = "";
|
|
294
|
+
}
|
|
295
|
+
} else if (xmlData[i] === ">") {
|
|
296
|
+
if (startChar === "") {
|
|
297
|
+
tagClosed = true;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
attrStr += xmlData[i];
|
|
302
|
+
}
|
|
303
|
+
if (startChar !== "") {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
value: attrStr,
|
|
308
|
+
index: i,
|
|
309
|
+
tagClosed
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
|
|
313
|
+
function validateAttributeString(attrStr, options) {
|
|
314
|
+
const matches2 = util.getAllMatches(attrStr, validAttrStrRegxp);
|
|
315
|
+
const attrNames = {};
|
|
316
|
+
for (let i = 0; i < matches2.length; i++) {
|
|
317
|
+
if (matches2[i][1].length === 0) {
|
|
318
|
+
return getErrorObject("InvalidAttr", "Attribute '" + matches2[i][2] + "' has no space in starting.", getPositionFromMatch(matches2[i]));
|
|
319
|
+
} else if (matches2[i][3] !== void 0 && matches2[i][4] === void 0) {
|
|
320
|
+
return getErrorObject("InvalidAttr", "Attribute '" + matches2[i][2] + "' is without value.", getPositionFromMatch(matches2[i]));
|
|
321
|
+
} else if (matches2[i][3] === void 0 && !options.allowBooleanAttributes) {
|
|
322
|
+
return getErrorObject("InvalidAttr", "boolean attribute '" + matches2[i][2] + "' is not allowed.", getPositionFromMatch(matches2[i]));
|
|
323
|
+
}
|
|
324
|
+
const attrName = matches2[i][2];
|
|
325
|
+
if (!validateAttrName(attrName)) {
|
|
326
|
+
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches2[i]));
|
|
327
|
+
}
|
|
328
|
+
if (!attrNames.hasOwnProperty(attrName)) {
|
|
329
|
+
attrNames[attrName] = 1;
|
|
330
|
+
} else {
|
|
331
|
+
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches2[i]));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
function validateNumberAmpersand(xmlData, i) {
|
|
337
|
+
let re = /\d/;
|
|
338
|
+
if (xmlData[i] === "x") {
|
|
339
|
+
i++;
|
|
340
|
+
re = /[\da-fA-F]/;
|
|
341
|
+
}
|
|
342
|
+
for (; i < xmlData.length; i++) {
|
|
343
|
+
if (xmlData[i] === ";")
|
|
344
|
+
return i;
|
|
345
|
+
if (!xmlData[i].match(re))
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
return -1;
|
|
349
|
+
}
|
|
350
|
+
function validateAmpersand(xmlData, i) {
|
|
351
|
+
i++;
|
|
352
|
+
if (xmlData[i] === ";")
|
|
353
|
+
return -1;
|
|
354
|
+
if (xmlData[i] === "#") {
|
|
355
|
+
i++;
|
|
356
|
+
return validateNumberAmpersand(xmlData, i);
|
|
357
|
+
}
|
|
358
|
+
let count = 0;
|
|
359
|
+
for (; i < xmlData.length; i++, count++) {
|
|
360
|
+
if (xmlData[i].match(/\w/) && count < 20)
|
|
361
|
+
continue;
|
|
362
|
+
if (xmlData[i] === ";")
|
|
363
|
+
break;
|
|
364
|
+
return -1;
|
|
365
|
+
}
|
|
366
|
+
return i;
|
|
367
|
+
}
|
|
368
|
+
function getErrorObject(code, message, lineNumber) {
|
|
369
|
+
return {
|
|
370
|
+
err: {
|
|
371
|
+
code,
|
|
372
|
+
msg: message,
|
|
373
|
+
line: lineNumber.line || lineNumber,
|
|
374
|
+
col: lineNumber.col
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function validateAttrName(attrName) {
|
|
379
|
+
return util.isName(attrName);
|
|
380
|
+
}
|
|
381
|
+
function validateTagName(tagname) {
|
|
382
|
+
return util.isName(tagname);
|
|
383
|
+
}
|
|
384
|
+
function getLineNumberForPosition(xmlData, index) {
|
|
385
|
+
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
386
|
+
return {
|
|
387
|
+
line: lines.length,
|
|
388
|
+
col: lines[lines.length - 1].length + 1
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function getPositionFromMatch(match) {
|
|
392
|
+
return match.startIndex + match[1].length;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
|
|
398
|
+
var require_OptionsBuilder = __commonJS({
|
|
399
|
+
"../xml/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports) {
|
|
400
|
+
var defaultOptions = {
|
|
401
|
+
preserveOrder: false,
|
|
402
|
+
attributeNamePrefix: "@_",
|
|
403
|
+
attributesGroupName: false,
|
|
404
|
+
textNodeName: "#text",
|
|
405
|
+
ignoreAttributes: true,
|
|
406
|
+
removeNSPrefix: false,
|
|
407
|
+
allowBooleanAttributes: false,
|
|
408
|
+
parseTagValue: true,
|
|
409
|
+
parseAttributeValue: false,
|
|
410
|
+
trimValues: true,
|
|
411
|
+
cdataPropName: false,
|
|
412
|
+
numberParseOptions: {
|
|
413
|
+
hex: true,
|
|
414
|
+
leadingZeros: true
|
|
415
|
+
},
|
|
416
|
+
tagValueProcessor: function(tagName, val) {
|
|
417
|
+
return val;
|
|
418
|
+
},
|
|
419
|
+
attributeValueProcessor: function(attrName, val) {
|
|
420
|
+
return val;
|
|
421
|
+
},
|
|
422
|
+
stopNodes: [],
|
|
423
|
+
alwaysCreateTextNode: false,
|
|
424
|
+
isArray: () => false,
|
|
425
|
+
commentPropName: false,
|
|
426
|
+
unpairedTags: [],
|
|
427
|
+
processEntities: true,
|
|
428
|
+
htmlEntities: false,
|
|
429
|
+
ignoreDeclaration: false,
|
|
430
|
+
ignorePiTags: false,
|
|
431
|
+
transformTagName: false
|
|
432
|
+
};
|
|
433
|
+
var buildOptions = function(options) {
|
|
434
|
+
return Object.assign({}, defaultOptions, options);
|
|
435
|
+
};
|
|
436
|
+
exports.buildOptions = buildOptions;
|
|
437
|
+
exports.defaultOptions = defaultOptions;
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
|
|
442
|
+
var require_xmlNode = __commonJS({
|
|
443
|
+
"../xml/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports, module) {
|
|
444
|
+
"use strict";
|
|
445
|
+
var XmlNode = class {
|
|
446
|
+
constructor(tagname) {
|
|
447
|
+
this.tagname = tagname;
|
|
448
|
+
this.child = [];
|
|
449
|
+
this[":@"] = {};
|
|
450
|
+
}
|
|
451
|
+
add(key, val) {
|
|
452
|
+
this.child.push({ [key]: val });
|
|
453
|
+
}
|
|
454
|
+
addChild(node) {
|
|
455
|
+
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
456
|
+
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
457
|
+
} else {
|
|
458
|
+
this.child.push({ [node.tagname]: node.child });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
module.exports = XmlNode;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
|
|
467
|
+
var require_DocTypeReader = __commonJS({
|
|
468
|
+
"../xml/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports, module) {
|
|
469
|
+
function readDocType(xmlData, i) {
|
|
470
|
+
const entities = {};
|
|
471
|
+
if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
|
|
472
|
+
i = i + 9;
|
|
473
|
+
let angleBracketsCount = 1;
|
|
474
|
+
let hasBody = false, entity = false, comment = false;
|
|
475
|
+
let exp = "";
|
|
476
|
+
for (; i < xmlData.length; i++) {
|
|
477
|
+
if (xmlData[i] === "<") {
|
|
478
|
+
if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y") {
|
|
479
|
+
i += 7;
|
|
480
|
+
entity = true;
|
|
481
|
+
} else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T") {
|
|
482
|
+
i += 8;
|
|
483
|
+
} else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T") {
|
|
484
|
+
i += 8;
|
|
485
|
+
} else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N") {
|
|
486
|
+
i += 9;
|
|
487
|
+
} else if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-") {
|
|
488
|
+
comment = true;
|
|
489
|
+
} else {
|
|
490
|
+
throw new Error("Invalid DOCTYPE");
|
|
491
|
+
}
|
|
492
|
+
angleBracketsCount++;
|
|
493
|
+
exp = "";
|
|
494
|
+
} else if (xmlData[i] === ">") {
|
|
495
|
+
if (comment) {
|
|
496
|
+
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
|
|
497
|
+
comment = false;
|
|
498
|
+
} else {
|
|
499
|
+
throw new Error(`Invalid XML comment in DOCTYPE`);
|
|
500
|
+
}
|
|
501
|
+
} else if (entity) {
|
|
502
|
+
parseEntityExp(exp, entities);
|
|
503
|
+
entity = false;
|
|
504
|
+
}
|
|
505
|
+
angleBracketsCount--;
|
|
506
|
+
if (angleBracketsCount === 0) {
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
} else if (xmlData[i] === "[") {
|
|
510
|
+
hasBody = true;
|
|
511
|
+
} else {
|
|
512
|
+
exp += xmlData[i];
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (angleBracketsCount !== 0) {
|
|
516
|
+
throw new Error(`Unclosed DOCTYPE`);
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
520
|
+
}
|
|
521
|
+
return { entities, i };
|
|
522
|
+
}
|
|
523
|
+
var entityRegex = RegExp(`^\\s([a-zA-z0-0]+)[ ](['"])([^&]+)\\2`);
|
|
524
|
+
function parseEntityExp(exp, entities) {
|
|
525
|
+
const match = entityRegex.exec(exp);
|
|
526
|
+
if (match) {
|
|
527
|
+
entities[match[1]] = {
|
|
528
|
+
regx: RegExp(`&${match[1]};`, "g"),
|
|
529
|
+
val: match[3]
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
module.exports = readDocType;
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// ../../node_modules/strnum/strnum.js
|
|
538
|
+
var require_strnum = __commonJS({
|
|
539
|
+
"../../node_modules/strnum/strnum.js"(exports, module) {
|
|
540
|
+
var hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
541
|
+
var numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
|
|
542
|
+
if (!Number.parseInt && window.parseInt) {
|
|
543
|
+
Number.parseInt = window.parseInt;
|
|
544
|
+
}
|
|
545
|
+
if (!Number.parseFloat && window.parseFloat) {
|
|
546
|
+
Number.parseFloat = window.parseFloat;
|
|
547
|
+
}
|
|
548
|
+
var consider = {
|
|
549
|
+
hex: true,
|
|
550
|
+
leadingZeros: true,
|
|
551
|
+
decimalPoint: ".",
|
|
552
|
+
eNotation: true
|
|
553
|
+
};
|
|
554
|
+
function toNumber(str, options = {}) {
|
|
555
|
+
options = Object.assign({}, consider, options);
|
|
556
|
+
if (!str || typeof str !== "string")
|
|
557
|
+
return str;
|
|
558
|
+
let trimmedStr = str.trim();
|
|
559
|
+
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr))
|
|
560
|
+
return str;
|
|
561
|
+
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
562
|
+
return Number.parseInt(trimmedStr, 16);
|
|
563
|
+
} else {
|
|
564
|
+
const match = numRegex.exec(trimmedStr);
|
|
565
|
+
if (match) {
|
|
566
|
+
const sign = match[1];
|
|
567
|
+
const leadingZeros = match[2];
|
|
568
|
+
let numTrimmedByZeros = trimZeros(match[3]);
|
|
569
|
+
const eNotation = match[4] || match[6];
|
|
570
|
+
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".")
|
|
571
|
+
return str;
|
|
572
|
+
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".")
|
|
573
|
+
return str;
|
|
574
|
+
else {
|
|
575
|
+
const num = Number(trimmedStr);
|
|
576
|
+
const numStr = "" + num;
|
|
577
|
+
if (numStr.search(/[eE]/) !== -1) {
|
|
578
|
+
if (options.eNotation)
|
|
579
|
+
return num;
|
|
580
|
+
else
|
|
581
|
+
return str;
|
|
582
|
+
} else if (eNotation) {
|
|
583
|
+
if (options.eNotation)
|
|
584
|
+
return num;
|
|
585
|
+
else
|
|
586
|
+
return str;
|
|
587
|
+
} else if (trimmedStr.indexOf(".") !== -1) {
|
|
588
|
+
if (numStr === "0" && numTrimmedByZeros === "")
|
|
589
|
+
return num;
|
|
590
|
+
else if (numStr === numTrimmedByZeros)
|
|
591
|
+
return num;
|
|
592
|
+
else if (sign && numStr === "-" + numTrimmedByZeros)
|
|
593
|
+
return num;
|
|
594
|
+
else
|
|
595
|
+
return str;
|
|
596
|
+
}
|
|
597
|
+
if (leadingZeros) {
|
|
598
|
+
if (numTrimmedByZeros === numStr)
|
|
599
|
+
return num;
|
|
600
|
+
else if (sign + numTrimmedByZeros === numStr)
|
|
601
|
+
return num;
|
|
602
|
+
else
|
|
603
|
+
return str;
|
|
604
|
+
}
|
|
605
|
+
if (trimmedStr === numStr)
|
|
606
|
+
return num;
|
|
607
|
+
else if (trimmedStr === sign + numStr)
|
|
608
|
+
return num;
|
|
609
|
+
return str;
|
|
610
|
+
}
|
|
611
|
+
} else {
|
|
612
|
+
return str;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function trimZeros(numStr) {
|
|
617
|
+
if (numStr && numStr.indexOf(".") !== -1) {
|
|
618
|
+
numStr = numStr.replace(/0+$/, "");
|
|
619
|
+
if (numStr === ".")
|
|
620
|
+
numStr = "0";
|
|
621
|
+
else if (numStr[0] === ".")
|
|
622
|
+
numStr = "0" + numStr;
|
|
623
|
+
else if (numStr[numStr.length - 1] === ".")
|
|
624
|
+
numStr = numStr.substr(0, numStr.length - 1);
|
|
625
|
+
return numStr;
|
|
626
|
+
}
|
|
627
|
+
return numStr;
|
|
628
|
+
}
|
|
629
|
+
module.exports = toNumber;
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
|
|
634
|
+
var require_OrderedObjParser = __commonJS({
|
|
635
|
+
"../xml/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js"(exports, module) {
|
|
636
|
+
"use strict";
|
|
637
|
+
var util = require_util();
|
|
638
|
+
var xmlNode = require_xmlNode();
|
|
639
|
+
var readDocType = require_DocTypeReader();
|
|
640
|
+
var toNumber = require_strnum();
|
|
641
|
+
var regx = "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util.nameRegexp);
|
|
642
|
+
var OrderedObjParser = class {
|
|
643
|
+
constructor(options) {
|
|
644
|
+
this.options = options;
|
|
645
|
+
this.currentNode = null;
|
|
646
|
+
this.tagsNodeStack = [];
|
|
647
|
+
this.docTypeEntities = {};
|
|
648
|
+
this.lastEntities = {
|
|
649
|
+
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
650
|
+
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
651
|
+
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
652
|
+
"quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
|
|
653
|
+
};
|
|
654
|
+
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
|
|
655
|
+
this.htmlEntities = {
|
|
656
|
+
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
657
|
+
"cent": { regex: /&(cent|#162);/g, val: "\xA2" },
|
|
658
|
+
"pound": { regex: /&(pound|#163);/g, val: "\xA3" },
|
|
659
|
+
"yen": { regex: /&(yen|#165);/g, val: "\xA5" },
|
|
660
|
+
"euro": { regex: /&(euro|#8364);/g, val: "\u20AC" },
|
|
661
|
+
"copyright": { regex: /&(copy|#169);/g, val: "\xA9" },
|
|
662
|
+
"reg": { regex: /&(reg|#174);/g, val: "\xAE" },
|
|
663
|
+
"inr": { regex: /&(inr|#8377);/g, val: "\u20B9" }
|
|
664
|
+
};
|
|
665
|
+
this.addExternalEntities = addExternalEntities;
|
|
666
|
+
this.parseXml = parseXml;
|
|
667
|
+
this.parseTextData = parseTextData;
|
|
668
|
+
this.resolveNameSpace = resolveNameSpace;
|
|
669
|
+
this.buildAttributesMap = buildAttributesMap;
|
|
670
|
+
this.isItStopNode = isItStopNode;
|
|
671
|
+
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
672
|
+
this.readStopNodeData = readStopNodeData;
|
|
673
|
+
this.saveTextToParentTag = saveTextToParentTag;
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
function addExternalEntities(externalEntities) {
|
|
677
|
+
const entKeys = Object.keys(externalEntities);
|
|
678
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
679
|
+
const ent = entKeys[i];
|
|
680
|
+
this.lastEntities[ent] = {
|
|
681
|
+
regex: new RegExp("&" + ent + ";", "g"),
|
|
682
|
+
val: externalEntities[ent]
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
687
|
+
if (val !== void 0) {
|
|
688
|
+
if (this.options.trimValues && !dontTrim) {
|
|
689
|
+
val = val.trim();
|
|
690
|
+
}
|
|
691
|
+
if (val.length > 0) {
|
|
692
|
+
if (!escapeEntities)
|
|
693
|
+
val = this.replaceEntitiesValue(val);
|
|
694
|
+
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
|
|
695
|
+
if (newval === null || newval === void 0) {
|
|
696
|
+
return val;
|
|
697
|
+
} else if (typeof newval !== typeof val || newval !== val) {
|
|
698
|
+
return newval;
|
|
699
|
+
} else if (this.options.trimValues) {
|
|
700
|
+
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
701
|
+
} else {
|
|
702
|
+
const trimmedVal = val.trim();
|
|
703
|
+
if (trimmedVal === val) {
|
|
704
|
+
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
705
|
+
} else {
|
|
706
|
+
return val;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
function resolveNameSpace(tagname) {
|
|
713
|
+
if (this.options.removeNSPrefix) {
|
|
714
|
+
const tags = tagname.split(":");
|
|
715
|
+
const prefix = tagname.charAt(0) === "/" ? "/" : "";
|
|
716
|
+
if (tags[0] === "xmlns") {
|
|
717
|
+
return "";
|
|
718
|
+
}
|
|
719
|
+
if (tags.length === 2) {
|
|
720
|
+
tagname = prefix + tags[1];
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return tagname;
|
|
724
|
+
}
|
|
725
|
+
var attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
|
|
726
|
+
function buildAttributesMap(attrStr, jPath) {
|
|
727
|
+
if (!this.options.ignoreAttributes && typeof attrStr === "string") {
|
|
728
|
+
const matches2 = util.getAllMatches(attrStr, attrsRegx);
|
|
729
|
+
const len = matches2.length;
|
|
730
|
+
const attrs = {};
|
|
731
|
+
for (let i = 0; i < len; i++) {
|
|
732
|
+
const attrName = this.resolveNameSpace(matches2[i][1]);
|
|
733
|
+
let oldVal = matches2[i][4];
|
|
734
|
+
const aName = this.options.attributeNamePrefix + attrName;
|
|
735
|
+
if (attrName.length) {
|
|
736
|
+
if (oldVal !== void 0) {
|
|
737
|
+
if (this.options.trimValues) {
|
|
738
|
+
oldVal = oldVal.trim();
|
|
739
|
+
}
|
|
740
|
+
oldVal = this.replaceEntitiesValue(oldVal);
|
|
741
|
+
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
|
|
742
|
+
if (newVal === null || newVal === void 0) {
|
|
743
|
+
attrs[aName] = oldVal;
|
|
744
|
+
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
|
|
745
|
+
attrs[aName] = newVal;
|
|
746
|
+
} else {
|
|
747
|
+
attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
|
|
748
|
+
}
|
|
749
|
+
} else if (this.options.allowBooleanAttributes) {
|
|
750
|
+
attrs[aName] = true;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
if (!Object.keys(attrs).length) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (this.options.attributesGroupName) {
|
|
758
|
+
const attrCollection = {};
|
|
759
|
+
attrCollection[this.options.attributesGroupName] = attrs;
|
|
760
|
+
return attrCollection;
|
|
761
|
+
}
|
|
762
|
+
return attrs;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
var parseXml = function(xmlData) {
|
|
766
|
+
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
767
|
+
const xmlObj = new xmlNode("!xml");
|
|
768
|
+
let currentNode = xmlObj;
|
|
769
|
+
let textData = "";
|
|
770
|
+
let jPath = "";
|
|
771
|
+
for (let i = 0; i < xmlData.length; i++) {
|
|
772
|
+
const ch = xmlData[i];
|
|
773
|
+
if (ch === "<") {
|
|
774
|
+
if (xmlData[i + 1] === "/") {
|
|
775
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
776
|
+
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
777
|
+
if (this.options.removeNSPrefix) {
|
|
778
|
+
const colonIndex = tagName.indexOf(":");
|
|
779
|
+
if (colonIndex !== -1) {
|
|
780
|
+
tagName = tagName.substr(colonIndex + 1);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (this.options.transformTagName) {
|
|
784
|
+
tagName = this.options.transformTagName(tagName);
|
|
785
|
+
}
|
|
786
|
+
if (currentNode) {
|
|
787
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
788
|
+
}
|
|
789
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
790
|
+
currentNode = this.tagsNodeStack.pop();
|
|
791
|
+
textData = "";
|
|
792
|
+
i = closeIndex;
|
|
793
|
+
} else if (xmlData[i + 1] === "?") {
|
|
794
|
+
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
795
|
+
if (!tagData)
|
|
796
|
+
throw new Error("Pi Tag is not closed.");
|
|
797
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
798
|
+
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) {
|
|
799
|
+
} else {
|
|
800
|
+
const childNode = new xmlNode(tagData.tagName);
|
|
801
|
+
childNode.add(this.options.textNodeName, "");
|
|
802
|
+
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
|
|
803
|
+
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath);
|
|
804
|
+
}
|
|
805
|
+
currentNode.addChild(childNode);
|
|
806
|
+
}
|
|
807
|
+
i = tagData.closeIndex + 1;
|
|
808
|
+
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
809
|
+
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
810
|
+
if (this.options.commentPropName) {
|
|
811
|
+
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
812
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
813
|
+
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
|
|
814
|
+
}
|
|
815
|
+
i = endIndex;
|
|
816
|
+
} else if (xmlData.substr(i + 1, 2) === "!D") {
|
|
817
|
+
const result = readDocType(xmlData, i);
|
|
818
|
+
this.docTypeEntities = result.entities;
|
|
819
|
+
i = result.i;
|
|
820
|
+
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
821
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
822
|
+
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
823
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
824
|
+
if (this.options.cdataPropName) {
|
|
825
|
+
currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
|
|
826
|
+
} else {
|
|
827
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
|
|
828
|
+
if (val == void 0)
|
|
829
|
+
val = "";
|
|
830
|
+
currentNode.add(this.options.textNodeName, val);
|
|
831
|
+
}
|
|
832
|
+
i = closeIndex + 2;
|
|
833
|
+
} else {
|
|
834
|
+
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
835
|
+
let tagName = result.tagName;
|
|
836
|
+
let tagExp = result.tagExp;
|
|
837
|
+
let attrExpPresent = result.attrExpPresent;
|
|
838
|
+
let closeIndex = result.closeIndex;
|
|
839
|
+
if (this.options.transformTagName) {
|
|
840
|
+
tagName = this.options.transformTagName(tagName);
|
|
841
|
+
}
|
|
842
|
+
if (currentNode && textData) {
|
|
843
|
+
if (currentNode.tagname !== "!xml") {
|
|
844
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (tagName !== xmlObj.tagname) {
|
|
848
|
+
jPath += jPath ? "." + tagName : tagName;
|
|
849
|
+
}
|
|
850
|
+
const lastTag = currentNode;
|
|
851
|
+
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
|
|
852
|
+
currentNode = this.tagsNodeStack.pop();
|
|
853
|
+
}
|
|
854
|
+
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
855
|
+
let tagContent = "";
|
|
856
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
857
|
+
i = result.closeIndex;
|
|
858
|
+
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
859
|
+
i = result.closeIndex;
|
|
860
|
+
} else {
|
|
861
|
+
const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
|
|
862
|
+
if (!result2)
|
|
863
|
+
throw new Error(`Unexpected end of ${tagName}`);
|
|
864
|
+
i = result2.i;
|
|
865
|
+
tagContent = result2.tagContent;
|
|
866
|
+
}
|
|
867
|
+
const childNode = new xmlNode(tagName);
|
|
868
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
869
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
870
|
+
}
|
|
871
|
+
if (tagContent) {
|
|
872
|
+
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
873
|
+
}
|
|
874
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
875
|
+
childNode.add(this.options.textNodeName, tagContent);
|
|
876
|
+
currentNode.addChild(childNode);
|
|
877
|
+
} else {
|
|
878
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
879
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
880
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
881
|
+
tagExp = tagName;
|
|
882
|
+
} else {
|
|
883
|
+
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
884
|
+
}
|
|
885
|
+
if (this.options.transformTagName) {
|
|
886
|
+
tagName = this.options.transformTagName(tagName);
|
|
887
|
+
}
|
|
888
|
+
const childNode = new xmlNode(tagName);
|
|
889
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
890
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
891
|
+
}
|
|
892
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
893
|
+
currentNode.addChild(childNode);
|
|
894
|
+
} else {
|
|
895
|
+
const childNode = new xmlNode(tagName);
|
|
896
|
+
this.tagsNodeStack.push(currentNode);
|
|
897
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
898
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
899
|
+
}
|
|
900
|
+
currentNode.addChild(childNode);
|
|
901
|
+
currentNode = childNode;
|
|
902
|
+
}
|
|
903
|
+
textData = "";
|
|
904
|
+
i = closeIndex;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
} else {
|
|
908
|
+
textData += xmlData[i];
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return xmlObj.child;
|
|
912
|
+
};
|
|
913
|
+
var replaceEntitiesValue = function(val) {
|
|
914
|
+
if (this.options.processEntities) {
|
|
915
|
+
for (let entityName in this.docTypeEntities) {
|
|
916
|
+
const entity = this.docTypeEntities[entityName];
|
|
917
|
+
val = val.replace(entity.regx, entity.val);
|
|
918
|
+
}
|
|
919
|
+
for (let entityName in this.lastEntities) {
|
|
920
|
+
const entity = this.lastEntities[entityName];
|
|
921
|
+
val = val.replace(entity.regex, entity.val);
|
|
922
|
+
}
|
|
923
|
+
if (this.options.htmlEntities) {
|
|
924
|
+
for (let entityName in this.htmlEntities) {
|
|
925
|
+
const entity = this.htmlEntities[entityName];
|
|
926
|
+
val = val.replace(entity.regex, entity.val);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
930
|
+
}
|
|
931
|
+
return val;
|
|
932
|
+
};
|
|
933
|
+
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
934
|
+
if (textData) {
|
|
935
|
+
if (isLeafNode === void 0)
|
|
936
|
+
isLeafNode = Object.keys(currentNode.child).length === 0;
|
|
937
|
+
textData = this.parseTextData(textData, currentNode.tagname, jPath, false, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false, isLeafNode);
|
|
938
|
+
if (textData !== void 0 && textData !== "")
|
|
939
|
+
currentNode.add(this.options.textNodeName, textData);
|
|
940
|
+
textData = "";
|
|
941
|
+
}
|
|
942
|
+
return textData;
|
|
943
|
+
}
|
|
944
|
+
function isItStopNode(stopNodes, jPath, currentTagName) {
|
|
945
|
+
const allNodesExp = "*." + currentTagName;
|
|
946
|
+
for (const stopNodePath in stopNodes) {
|
|
947
|
+
const stopNodeExp = stopNodes[stopNodePath];
|
|
948
|
+
if (allNodesExp === stopNodeExp || jPath === stopNodeExp)
|
|
949
|
+
return true;
|
|
950
|
+
}
|
|
951
|
+
return false;
|
|
952
|
+
}
|
|
953
|
+
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
954
|
+
let attrBoundary;
|
|
955
|
+
let tagExp = "";
|
|
956
|
+
for (let index = i; index < xmlData.length; index++) {
|
|
957
|
+
let ch = xmlData[index];
|
|
958
|
+
if (attrBoundary) {
|
|
959
|
+
if (ch === attrBoundary)
|
|
960
|
+
attrBoundary = "";
|
|
961
|
+
} else if (ch === '"' || ch === "'") {
|
|
962
|
+
attrBoundary = ch;
|
|
963
|
+
} else if (ch === closingChar[0]) {
|
|
964
|
+
if (closingChar[1]) {
|
|
965
|
+
if (xmlData[index + 1] === closingChar[1]) {
|
|
966
|
+
return {
|
|
967
|
+
data: tagExp,
|
|
968
|
+
index
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
} else {
|
|
972
|
+
return {
|
|
973
|
+
data: tagExp,
|
|
974
|
+
index
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
} else if (ch === " ") {
|
|
978
|
+
ch = " ";
|
|
979
|
+
}
|
|
980
|
+
tagExp += ch;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
function findClosingIndex(xmlData, str, i, errMsg) {
|
|
984
|
+
const closingIndex = xmlData.indexOf(str, i);
|
|
985
|
+
if (closingIndex === -1) {
|
|
986
|
+
throw new Error(errMsg);
|
|
987
|
+
} else {
|
|
988
|
+
return closingIndex + str.length - 1;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
|
|
992
|
+
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
|
|
993
|
+
if (!result)
|
|
994
|
+
return;
|
|
995
|
+
let tagExp = result.data;
|
|
996
|
+
const closeIndex = result.index;
|
|
997
|
+
const separatorIndex = tagExp.search(/\s/);
|
|
998
|
+
let tagName = tagExp;
|
|
999
|
+
let attrExpPresent = true;
|
|
1000
|
+
if (separatorIndex !== -1) {
|
|
1001
|
+
tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
|
|
1002
|
+
tagExp = tagExp.substr(separatorIndex + 1);
|
|
1003
|
+
}
|
|
1004
|
+
if (removeNSPrefix) {
|
|
1005
|
+
const colonIndex = tagName.indexOf(":");
|
|
1006
|
+
if (colonIndex !== -1) {
|
|
1007
|
+
tagName = tagName.substr(colonIndex + 1);
|
|
1008
|
+
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return {
|
|
1012
|
+
tagName,
|
|
1013
|
+
tagExp,
|
|
1014
|
+
closeIndex,
|
|
1015
|
+
attrExpPresent
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
function readStopNodeData(xmlData, tagName, i) {
|
|
1019
|
+
const startIndex = i;
|
|
1020
|
+
let openTagCount = 1;
|
|
1021
|
+
for (; i < xmlData.length; i++) {
|
|
1022
|
+
if (xmlData[i] === "<") {
|
|
1023
|
+
if (xmlData[i + 1] === "/") {
|
|
1024
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
1025
|
+
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1026
|
+
if (closeTagName === tagName) {
|
|
1027
|
+
openTagCount--;
|
|
1028
|
+
if (openTagCount === 0) {
|
|
1029
|
+
return {
|
|
1030
|
+
tagContent: xmlData.substring(startIndex, i),
|
|
1031
|
+
i: closeIndex
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
i = closeIndex;
|
|
1036
|
+
} else if (xmlData[i + 1] === "?") {
|
|
1037
|
+
const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
|
|
1038
|
+
i = closeIndex;
|
|
1039
|
+
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1040
|
+
const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
|
|
1041
|
+
i = closeIndex;
|
|
1042
|
+
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1043
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
1044
|
+
i = closeIndex;
|
|
1045
|
+
} else {
|
|
1046
|
+
const tagData = readTagExp(xmlData, i, ">");
|
|
1047
|
+
if (tagData) {
|
|
1048
|
+
const openTagName = tagData && tagData.tagName;
|
|
1049
|
+
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
|
|
1050
|
+
openTagCount++;
|
|
1051
|
+
}
|
|
1052
|
+
i = tagData.closeIndex;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
function parseValue(val, shouldParse, options) {
|
|
1059
|
+
if (shouldParse && typeof val === "string") {
|
|
1060
|
+
const newval = val.trim();
|
|
1061
|
+
if (newval === "true")
|
|
1062
|
+
return true;
|
|
1063
|
+
else if (newval === "false")
|
|
1064
|
+
return false;
|
|
1065
|
+
else
|
|
1066
|
+
return toNumber(val, options);
|
|
1067
|
+
} else {
|
|
1068
|
+
if (util.isExist(val)) {
|
|
1069
|
+
return val;
|
|
1070
|
+
} else {
|
|
1071
|
+
return "";
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
module.exports = OrderedObjParser;
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlparser/node2json.js
|
|
1080
|
+
var require_node2json = __commonJS({
|
|
1081
|
+
"../xml/node_modules/fast-xml-parser/src/xmlparser/node2json.js"(exports) {
|
|
1082
|
+
"use strict";
|
|
1083
|
+
function prettify(node, options) {
|
|
1084
|
+
return compress(node, options);
|
|
1085
|
+
}
|
|
1086
|
+
function compress(arr, options, jPath) {
|
|
1087
|
+
let text;
|
|
1088
|
+
const compressedObj = {};
|
|
1089
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1090
|
+
const tagObj = arr[i];
|
|
1091
|
+
const property = propName(tagObj);
|
|
1092
|
+
let newJpath = "";
|
|
1093
|
+
if (jPath === void 0)
|
|
1094
|
+
newJpath = property;
|
|
1095
|
+
else
|
|
1096
|
+
newJpath = jPath + "." + property;
|
|
1097
|
+
if (property === options.textNodeName) {
|
|
1098
|
+
if (text === void 0)
|
|
1099
|
+
text = tagObj[property];
|
|
1100
|
+
else
|
|
1101
|
+
text += "" + tagObj[property];
|
|
1102
|
+
} else if (property === void 0) {
|
|
1103
|
+
continue;
|
|
1104
|
+
} else if (tagObj[property]) {
|
|
1105
|
+
let val = compress(tagObj[property], options, newJpath);
|
|
1106
|
+
const isLeaf = isLeafTag(val, options);
|
|
1107
|
+
if (tagObj[":@"]) {
|
|
1108
|
+
assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
1109
|
+
} else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
|
|
1110
|
+
val = val[options.textNodeName];
|
|
1111
|
+
} else if (Object.keys(val).length === 0) {
|
|
1112
|
+
if (options.alwaysCreateTextNode)
|
|
1113
|
+
val[options.textNodeName] = "";
|
|
1114
|
+
else
|
|
1115
|
+
val = "";
|
|
1116
|
+
}
|
|
1117
|
+
if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
|
|
1118
|
+
if (!Array.isArray(compressedObj[property])) {
|
|
1119
|
+
compressedObj[property] = [compressedObj[property]];
|
|
1120
|
+
}
|
|
1121
|
+
compressedObj[property].push(val);
|
|
1122
|
+
} else {
|
|
1123
|
+
if (options.isArray(property, newJpath, isLeaf)) {
|
|
1124
|
+
compressedObj[property] = [val];
|
|
1125
|
+
} else {
|
|
1126
|
+
compressedObj[property] = val;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
if (typeof text === "string") {
|
|
1132
|
+
if (text.length > 0)
|
|
1133
|
+
compressedObj[options.textNodeName] = text;
|
|
1134
|
+
} else if (text !== void 0)
|
|
1135
|
+
compressedObj[options.textNodeName] = text;
|
|
1136
|
+
return compressedObj;
|
|
1137
|
+
}
|
|
1138
|
+
function propName(obj) {
|
|
1139
|
+
const keys = Object.keys(obj);
|
|
1140
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1141
|
+
const key = keys[i];
|
|
1142
|
+
if (key !== ":@")
|
|
1143
|
+
return key;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function assignAttributes(obj, attrMap, jpath, options) {
|
|
1147
|
+
if (attrMap) {
|
|
1148
|
+
const keys = Object.keys(attrMap);
|
|
1149
|
+
const len = keys.length;
|
|
1150
|
+
for (let i = 0; i < len; i++) {
|
|
1151
|
+
const atrrName = keys[i];
|
|
1152
|
+
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
1153
|
+
obj[atrrName] = [attrMap[atrrName]];
|
|
1154
|
+
} else {
|
|
1155
|
+
obj[atrrName] = attrMap[atrrName];
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
function isLeafTag(obj, options) {
|
|
1161
|
+
const propCount = Object.keys(obj).length;
|
|
1162
|
+
if (propCount === 0 || propCount === 1 && obj[options.textNodeName])
|
|
1163
|
+
return true;
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
exports.prettify = prettify;
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
|
|
1171
|
+
var require_XMLParser = __commonJS({
|
|
1172
|
+
"../xml/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports, module) {
|
|
1173
|
+
var { buildOptions } = require_OptionsBuilder();
|
|
1174
|
+
var OrderedObjParser = require_OrderedObjParser();
|
|
1175
|
+
var { prettify } = require_node2json();
|
|
1176
|
+
var validator = require_validator();
|
|
1177
|
+
var XMLParser = class {
|
|
1178
|
+
constructor(options) {
|
|
1179
|
+
this.externalEntities = {};
|
|
1180
|
+
this.options = buildOptions(options);
|
|
1181
|
+
}
|
|
1182
|
+
parse(xmlData, validationOption) {
|
|
1183
|
+
if (typeof xmlData === "string") {
|
|
1184
|
+
} else if (xmlData.toString) {
|
|
1185
|
+
xmlData = xmlData.toString();
|
|
1186
|
+
} else {
|
|
1187
|
+
throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
1188
|
+
}
|
|
1189
|
+
if (validationOption) {
|
|
1190
|
+
if (validationOption === true)
|
|
1191
|
+
validationOption = {};
|
|
1192
|
+
const result = validator.validate(xmlData, validationOption);
|
|
1193
|
+
if (result !== true) {
|
|
1194
|
+
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
const orderedObjParser = new OrderedObjParser(this.options);
|
|
1198
|
+
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
1199
|
+
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
1200
|
+
if (this.options.preserveOrder || orderedResult === void 0)
|
|
1201
|
+
return orderedResult;
|
|
1202
|
+
else
|
|
1203
|
+
return prettify(orderedResult, this.options);
|
|
1204
|
+
}
|
|
1205
|
+
addEntity(key, value) {
|
|
1206
|
+
if (value.indexOf("&") !== -1) {
|
|
1207
|
+
throw new Error("Entity value can't have '&'");
|
|
1208
|
+
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
1209
|
+
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
1210
|
+
} else if (value === "&") {
|
|
1211
|
+
throw new Error("An entity with value '&' is not permitted");
|
|
1212
|
+
} else {
|
|
1213
|
+
this.externalEntities[key] = value;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
module.exports = XMLParser;
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js
|
|
1222
|
+
var require_orderedJs2Xml = __commonJS({
|
|
1223
|
+
"../xml/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports, module) {
|
|
1224
|
+
var EOL = "\n";
|
|
1225
|
+
function toXml(jArray, options) {
|
|
1226
|
+
return arrToStr(jArray, options, "", 0);
|
|
1227
|
+
}
|
|
1228
|
+
function arrToStr(arr, options, jPath, level) {
|
|
1229
|
+
let xmlStr = "";
|
|
1230
|
+
let indentation = "";
|
|
1231
|
+
if (options.format && options.indentBy.length > 0) {
|
|
1232
|
+
indentation = EOL + "" + options.indentBy.repeat(level);
|
|
1233
|
+
}
|
|
1234
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1235
|
+
const tagObj = arr[i];
|
|
1236
|
+
const tagName = propName(tagObj);
|
|
1237
|
+
let newJPath = "";
|
|
1238
|
+
if (jPath.length === 0)
|
|
1239
|
+
newJPath = tagName;
|
|
1240
|
+
else
|
|
1241
|
+
newJPath = `${jPath}.${tagName}`;
|
|
1242
|
+
if (tagName === options.textNodeName) {
|
|
1243
|
+
let tagText = tagObj[tagName];
|
|
1244
|
+
if (!isStopNode(newJPath, options)) {
|
|
1245
|
+
tagText = options.tagValueProcessor(tagName, tagText);
|
|
1246
|
+
tagText = replaceEntitiesValue(tagText, options);
|
|
1247
|
+
}
|
|
1248
|
+
xmlStr += indentation + tagText;
|
|
1249
|
+
continue;
|
|
1250
|
+
} else if (tagName === options.cdataPropName) {
|
|
1251
|
+
xmlStr += indentation + `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
1252
|
+
continue;
|
|
1253
|
+
} else if (tagName === options.commentPropName) {
|
|
1254
|
+
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
1255
|
+
continue;
|
|
1256
|
+
} else if (tagName[0] === "?") {
|
|
1257
|
+
const attStr2 = attr_to_str(tagObj[":@"], options);
|
|
1258
|
+
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
1259
|
+
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
1260
|
+
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
|
|
1261
|
+
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
const attStr = attr_to_str(tagObj[":@"], options);
|
|
1265
|
+
let tagStart = indentation + `<${tagName}${attStr}`;
|
|
1266
|
+
let tagValue = arrToStr(tagObj[tagName], options, newJPath, level + 1);
|
|
1267
|
+
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1268
|
+
if (options.suppressUnpairedNode)
|
|
1269
|
+
xmlStr += tagStart + ">";
|
|
1270
|
+
else
|
|
1271
|
+
xmlStr += tagStart + "/>";
|
|
1272
|
+
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
1273
|
+
xmlStr += tagStart + "/>";
|
|
1274
|
+
} else {
|
|
1275
|
+
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return xmlStr;
|
|
1279
|
+
}
|
|
1280
|
+
function propName(obj) {
|
|
1281
|
+
const keys = Object.keys(obj);
|
|
1282
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1283
|
+
const key = keys[i];
|
|
1284
|
+
if (key !== ":@")
|
|
1285
|
+
return key;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
function attr_to_str(attrMap, options) {
|
|
1289
|
+
let attrStr = "";
|
|
1290
|
+
if (attrMap && !options.ignoreAttributes) {
|
|
1291
|
+
for (let attr in attrMap) {
|
|
1292
|
+
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
1293
|
+
attrVal = replaceEntitiesValue(attrVal, options);
|
|
1294
|
+
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
1295
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
1296
|
+
} else {
|
|
1297
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return attrStr;
|
|
1302
|
+
}
|
|
1303
|
+
function isStopNode(jPath, options) {
|
|
1304
|
+
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
1305
|
+
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
1306
|
+
for (let index in options.stopNodes) {
|
|
1307
|
+
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName)
|
|
1308
|
+
return true;
|
|
1309
|
+
}
|
|
1310
|
+
return false;
|
|
1311
|
+
}
|
|
1312
|
+
function replaceEntitiesValue(textValue, options) {
|
|
1313
|
+
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
1314
|
+
for (let i = 0; i < options.entities.length; i++) {
|
|
1315
|
+
const entity = options.entities[i];
|
|
1316
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
return textValue;
|
|
1320
|
+
}
|
|
1321
|
+
module.exports = toXml;
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
// ../xml/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js
|
|
1326
|
+
var require_json2xml = __commonJS({
|
|
1327
|
+
"../xml/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js"(exports, module) {
|
|
1328
|
+
"use strict";
|
|
1329
|
+
var buildFromOrderedJs = require_orderedJs2Xml();
|
|
1330
|
+
var defaultOptions = {
|
|
1331
|
+
attributeNamePrefix: "@_",
|
|
1332
|
+
attributesGroupName: false,
|
|
1333
|
+
textNodeName: "#text",
|
|
1334
|
+
ignoreAttributes: true,
|
|
1335
|
+
cdataPropName: false,
|
|
1336
|
+
format: false,
|
|
1337
|
+
indentBy: " ",
|
|
1338
|
+
suppressEmptyNode: false,
|
|
1339
|
+
suppressUnpairedNode: true,
|
|
1340
|
+
suppressBooleanAttributes: true,
|
|
1341
|
+
tagValueProcessor: function(key, a) {
|
|
1342
|
+
return a;
|
|
1343
|
+
},
|
|
1344
|
+
attributeValueProcessor: function(attrName, a) {
|
|
1345
|
+
return a;
|
|
1346
|
+
},
|
|
1347
|
+
preserveOrder: false,
|
|
1348
|
+
commentPropName: false,
|
|
1349
|
+
unpairedTags: [],
|
|
1350
|
+
entities: [
|
|
1351
|
+
{ regex: new RegExp("&", "g"), val: "&" },
|
|
1352
|
+
{ regex: new RegExp(">", "g"), val: ">" },
|
|
1353
|
+
{ regex: new RegExp("<", "g"), val: "<" },
|
|
1354
|
+
{ regex: new RegExp("'", "g"), val: "'" },
|
|
1355
|
+
{ regex: new RegExp('"', "g"), val: """ }
|
|
1356
|
+
],
|
|
1357
|
+
processEntities: true,
|
|
1358
|
+
stopNodes: [],
|
|
1359
|
+
transformTagName: false
|
|
1360
|
+
};
|
|
1361
|
+
function Builder(options) {
|
|
1362
|
+
this.options = Object.assign({}, defaultOptions, options);
|
|
1363
|
+
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
|
|
1364
|
+
this.isAttribute = function() {
|
|
1365
|
+
return false;
|
|
1366
|
+
};
|
|
1367
|
+
} else {
|
|
1368
|
+
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
1369
|
+
this.isAttribute = isAttribute;
|
|
1370
|
+
}
|
|
1371
|
+
this.processTextOrObjNode = processTextOrObjNode;
|
|
1372
|
+
if (this.options.format) {
|
|
1373
|
+
this.indentate = indentate;
|
|
1374
|
+
this.tagEndChar = ">\n";
|
|
1375
|
+
this.newLine = "\n";
|
|
1376
|
+
} else {
|
|
1377
|
+
this.indentate = function() {
|
|
1378
|
+
return "";
|
|
1379
|
+
};
|
|
1380
|
+
this.tagEndChar = ">";
|
|
1381
|
+
this.newLine = "";
|
|
1382
|
+
}
|
|
1383
|
+
if (this.options.suppressEmptyNode) {
|
|
1384
|
+
this.buildTextNode = buildEmptyTextNode;
|
|
1385
|
+
this.buildObjNode = buildEmptyObjNode;
|
|
1386
|
+
} else {
|
|
1387
|
+
this.buildTextNode = buildTextValNode;
|
|
1388
|
+
this.buildObjNode = buildObjectNode;
|
|
1389
|
+
}
|
|
1390
|
+
this.buildTextValNode = buildTextValNode;
|
|
1391
|
+
this.buildObjectNode = buildObjectNode;
|
|
1392
|
+
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
1393
|
+
this.buildAttrPairStr = buildAttrPairStr;
|
|
1394
|
+
}
|
|
1395
|
+
Builder.prototype.build = function(jObj) {
|
|
1396
|
+
if (this.options.preserveOrder) {
|
|
1397
|
+
return buildFromOrderedJs(jObj, this.options);
|
|
1398
|
+
} else {
|
|
1399
|
+
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
|
|
1400
|
+
jObj = {
|
|
1401
|
+
[this.options.arrayNodeName]: jObj
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
return this.j2x(jObj, 0).val;
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
Builder.prototype.j2x = function(jObj, level) {
|
|
1408
|
+
let attrStr = "";
|
|
1409
|
+
let val = "";
|
|
1410
|
+
for (let key in jObj) {
|
|
1411
|
+
if (typeof jObj[key] === "undefined") {
|
|
1412
|
+
} else if (jObj[key] === null) {
|
|
1413
|
+
if (key[0] === "?")
|
|
1414
|
+
val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
1415
|
+
else
|
|
1416
|
+
val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1417
|
+
} else if (jObj[key] instanceof Date) {
|
|
1418
|
+
val += this.buildTextNode(jObj[key], key, "", level);
|
|
1419
|
+
} else if (typeof jObj[key] !== "object") {
|
|
1420
|
+
const attr = this.isAttribute(key);
|
|
1421
|
+
if (attr) {
|
|
1422
|
+
attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
|
|
1423
|
+
} else {
|
|
1424
|
+
if (key === this.options.textNodeName) {
|
|
1425
|
+
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
|
|
1426
|
+
val += this.replaceEntitiesValue(newval);
|
|
1427
|
+
} else {
|
|
1428
|
+
val += this.buildTextNode(jObj[key], key, "", level);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
} else if (Array.isArray(jObj[key])) {
|
|
1432
|
+
const arrLen = jObj[key].length;
|
|
1433
|
+
for (let j = 0; j < arrLen; j++) {
|
|
1434
|
+
const item = jObj[key][j];
|
|
1435
|
+
if (typeof item === "undefined") {
|
|
1436
|
+
} else if (item === null) {
|
|
1437
|
+
if (key[0] === "?")
|
|
1438
|
+
val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
1439
|
+
else
|
|
1440
|
+
val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1441
|
+
} else if (typeof item === "object") {
|
|
1442
|
+
val += this.processTextOrObjNode(item, key, level);
|
|
1443
|
+
} else {
|
|
1444
|
+
val += this.buildTextNode(item, key, "", level);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
} else {
|
|
1448
|
+
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
1449
|
+
const Ks = Object.keys(jObj[key]);
|
|
1450
|
+
const L = Ks.length;
|
|
1451
|
+
for (let j = 0; j < L; j++) {
|
|
1452
|
+
attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
|
|
1453
|
+
}
|
|
1454
|
+
} else {
|
|
1455
|
+
val += this.processTextOrObjNode(jObj[key], key, level);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return { attrStr, val };
|
|
1460
|
+
};
|
|
1461
|
+
function buildAttrPairStr(attrName, val) {
|
|
1462
|
+
val = this.options.attributeValueProcessor(attrName, "" + val);
|
|
1463
|
+
val = this.replaceEntitiesValue(val);
|
|
1464
|
+
if (this.options.suppressBooleanAttributes && val === "true") {
|
|
1465
|
+
return " " + attrName;
|
|
1466
|
+
} else
|
|
1467
|
+
return " " + attrName + '="' + val + '"';
|
|
1468
|
+
}
|
|
1469
|
+
function processTextOrObjNode(object, key, level) {
|
|
1470
|
+
const result = this.j2x(object, level + 1);
|
|
1471
|
+
if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
|
|
1472
|
+
return this.buildTextNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
1473
|
+
} else {
|
|
1474
|
+
return this.buildObjNode(result.val, key, result.attrStr, level);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function buildObjectNode(val, key, attrStr, level) {
|
|
1478
|
+
let tagEndExp = "</" + key + this.tagEndChar;
|
|
1479
|
+
let piClosingChar = "";
|
|
1480
|
+
if (key[0] === "?") {
|
|
1481
|
+
piClosingChar = "?";
|
|
1482
|
+
tagEndExp = "";
|
|
1483
|
+
}
|
|
1484
|
+
if (attrStr && val.indexOf("<") === -1) {
|
|
1485
|
+
return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val + tagEndExp;
|
|
1486
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
1487
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
1488
|
+
} else {
|
|
1489
|
+
return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val + this.indentate(level) + tagEndExp;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function buildEmptyObjNode(val, key, attrStr, level) {
|
|
1493
|
+
if (val !== "") {
|
|
1494
|
+
return this.buildObjectNode(val, key, attrStr, level);
|
|
1495
|
+
} else {
|
|
1496
|
+
if (key[0] === "?")
|
|
1497
|
+
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
1498
|
+
else
|
|
1499
|
+
return this.indentate(level) + "<" + key + attrStr + "/" + this.tagEndChar;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
function buildTextValNode(val, key, attrStr, level) {
|
|
1503
|
+
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
1504
|
+
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
1505
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
1506
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
1507
|
+
} else {
|
|
1508
|
+
let textValue = this.options.tagValueProcessor(key, val);
|
|
1509
|
+
textValue = this.replaceEntitiesValue(textValue);
|
|
1510
|
+
if (textValue === "" && this.options.unpairedTags.indexOf(key) !== -1) {
|
|
1511
|
+
if (this.options.suppressUnpairedNode) {
|
|
1512
|
+
return this.indentate(level) + "<" + key + this.tagEndChar;
|
|
1513
|
+
} else {
|
|
1514
|
+
return this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1515
|
+
}
|
|
1516
|
+
} else {
|
|
1517
|
+
return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
function replaceEntitiesValue(textValue) {
|
|
1522
|
+
if (textValue && textValue.length > 0 && this.options.processEntities) {
|
|
1523
|
+
for (let i = 0; i < this.options.entities.length; i++) {
|
|
1524
|
+
const entity = this.options.entities[i];
|
|
1525
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return textValue;
|
|
1529
|
+
}
|
|
1530
|
+
function buildEmptyTextNode(val, key, attrStr, level) {
|
|
1531
|
+
if (val === "" && this.options.unpairedTags.indexOf(key) !== -1) {
|
|
1532
|
+
if (this.options.suppressUnpairedNode) {
|
|
1533
|
+
return this.indentate(level) + "<" + key + this.tagEndChar;
|
|
1534
|
+
} else {
|
|
1535
|
+
return this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1536
|
+
}
|
|
1537
|
+
} else if (val !== "") {
|
|
1538
|
+
return this.buildTextValNode(val, key, attrStr, level);
|
|
1539
|
+
} else {
|
|
1540
|
+
if (key[0] === "?")
|
|
1541
|
+
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
1542
|
+
else
|
|
1543
|
+
return this.indentate(level) + "<" + key + attrStr + "/" + this.tagEndChar;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
function indentate(level) {
|
|
1547
|
+
return this.options.indentBy.repeat(level);
|
|
1548
|
+
}
|
|
1549
|
+
function isAttribute(name) {
|
|
1550
|
+
if (name.startsWith(this.options.attributeNamePrefix)) {
|
|
1551
|
+
return name.substr(this.attrPrefixLen);
|
|
1552
|
+
} else {
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
module.exports = Builder;
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
|
|
1560
|
+
// ../xml/node_modules/fast-xml-parser/src/fxp.js
|
|
1561
|
+
var require_fxp = __commonJS({
|
|
1562
|
+
"../xml/node_modules/fast-xml-parser/src/fxp.js"(exports, module) {
|
|
1563
|
+
"use strict";
|
|
1564
|
+
var validator = require_validator();
|
|
1565
|
+
var XMLParser = require_XMLParser();
|
|
1566
|
+
var XMLBuilder = require_json2xml();
|
|
1567
|
+
module.exports = {
|
|
1568
|
+
XMLParser,
|
|
1569
|
+
XMLValidator: validator,
|
|
1570
|
+
XMLBuilder
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
|
|
1575
|
+
// ../xml/src/lib/parse-xml.ts
|
|
1576
|
+
function parseXML(text, options) {
|
|
1577
|
+
const parser = new import_fast_xml_parser.XMLParser({
|
|
1578
|
+
ignoreAttributes: false,
|
|
1579
|
+
attributeNamePrefix: "",
|
|
1580
|
+
...options
|
|
1581
|
+
});
|
|
1582
|
+
const parsedXML = parser.parse(text);
|
|
1583
|
+
return parsedXML;
|
|
1584
|
+
}
|
|
1585
|
+
var import_fast_xml_parser;
|
|
1586
|
+
var init_parse_xml = __esm({
|
|
1587
|
+
"../xml/src/lib/parse-xml.ts"() {
|
|
1588
|
+
import_fast_xml_parser = __toModule(require_fxp());
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
// ../xml/src/xml-loader.ts
|
|
1593
|
+
function testXMLFile(text) {
|
|
1594
|
+
return text.startsWith("<?xml");
|
|
1595
|
+
}
|
|
1596
|
+
var VERSION, XMLLoader;
|
|
1597
|
+
var init_xml_loader = __esm({
|
|
1598
|
+
"../xml/src/xml-loader.ts"() {
|
|
1599
|
+
init_parse_xml();
|
|
1600
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1601
|
+
XMLLoader = {
|
|
1602
|
+
name: "XML",
|
|
1603
|
+
id: "xml",
|
|
1604
|
+
module: "xml",
|
|
1605
|
+
version: VERSION,
|
|
1606
|
+
worker: false,
|
|
1607
|
+
extensions: ["xml"],
|
|
1608
|
+
mimeTypes: ["application/xml", "text/xml"],
|
|
1609
|
+
testText: testXMLFile,
|
|
1610
|
+
options: {
|
|
1611
|
+
xml: {}
|
|
1612
|
+
},
|
|
1613
|
+
parse: async (arrayBuffer, options) => parseXML(new TextDecoder().decode(arrayBuffer), options),
|
|
1614
|
+
parseTextSync: (text, options) => parseXML(text, options)
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
|
|
1619
|
+
// ../xml/src/index.ts
|
|
1620
|
+
var init_src = __esm({
|
|
1621
|
+
"../xml/src/index.ts"() {
|
|
1622
|
+
init_xml_loader();
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
|
|
1626
|
+
// src/lib/parse-wms.ts
|
|
1627
|
+
function parseWMSCapabilities(text, options) {
|
|
1628
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
1629
|
+
const xmlCapabilities = parsedXML.WMT_MS_Capabilities || parsedXML.WMS_Capabilities || parsedXML;
|
|
1630
|
+
return extractCapabilities(xmlCapabilities);
|
|
1631
|
+
}
|
|
1632
|
+
function extractCapabilities(xml) {
|
|
1633
|
+
const capabilities = {
|
|
1634
|
+
name: xml.Service?.Name || "unnamed",
|
|
1635
|
+
title: xml.Service?.Title,
|
|
1636
|
+
keywords: [],
|
|
1637
|
+
requests: {},
|
|
1638
|
+
layer: extractLayer(xml.Capability?.Layer),
|
|
1639
|
+
raw: xml
|
|
1640
|
+
};
|
|
1641
|
+
for (const keyword of xml.Service?.KeywordList?.Keyword || []) {
|
|
1642
|
+
capabilities.keywords.push(keyword);
|
|
1643
|
+
}
|
|
1644
|
+
for (const [name, xmlRequest] of Object.entries(xml.Capability?.Request || {})) {
|
|
1645
|
+
capabilities.requests[name] = extractRequest(name, xmlRequest);
|
|
1646
|
+
}
|
|
1647
|
+
return capabilities;
|
|
1648
|
+
}
|
|
1649
|
+
function extractRequest(name, xmlRequest) {
|
|
1650
|
+
const format = xmlRequest?.Format;
|
|
1651
|
+
const mimeTypes = Array.isArray(format) ? format : [format];
|
|
1652
|
+
return { name, mimeTypes };
|
|
1653
|
+
}
|
|
1654
|
+
function extractLayer(xmlLayer) {
|
|
1655
|
+
const layer = {
|
|
1656
|
+
name: xmlLayer?.Name,
|
|
1657
|
+
title: xmlLayer?.Title,
|
|
1658
|
+
srs: xmlLayer?.SRS || [],
|
|
1659
|
+
layers: []
|
|
1660
|
+
};
|
|
1661
|
+
for (const xmlSubLayer of xmlLayer?.Layer || []) {
|
|
1662
|
+
layer.layers?.push(extractLayer(xmlSubLayer));
|
|
1663
|
+
}
|
|
1664
|
+
return layer;
|
|
1665
|
+
}
|
|
1666
|
+
function parseWMSFeatureInfo(text, options) {
|
|
1667
|
+
const parsedXML = XMLLoader.parseTextSync(text, options);
|
|
1668
|
+
const xmlFeatureInfo = parsedXML.FeatureInfoResponse?.FIELDS || [];
|
|
1669
|
+
const xmlFeatures = Array.isArray(xmlFeatureInfo) ? xmlFeatureInfo : [xmlFeatureInfo];
|
|
1670
|
+
return {
|
|
1671
|
+
features: xmlFeatures.map((xmlFeature) => extractFeature(xmlFeature))
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
function extractFeature(xmlFeature) {
|
|
1675
|
+
const xmlFields = xmlFeature || {};
|
|
1676
|
+
return { attributes: xmlFields };
|
|
1677
|
+
}
|
|
1678
|
+
var init_parse_wms = __esm({
|
|
1679
|
+
"src/lib/parse-wms.ts"() {
|
|
1680
|
+
init_src();
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
// src/wms-capabilities-loader.ts
|
|
1685
|
+
function testXMLFile2(text) {
|
|
1686
|
+
return text.startsWith("<?xml");
|
|
1687
|
+
}
|
|
1688
|
+
var VERSION2, WMSCapabilitiesLoader;
|
|
1689
|
+
var init_wms_capabilities_loader = __esm({
|
|
1690
|
+
"src/wms-capabilities-loader.ts"() {
|
|
1691
|
+
init_parse_wms();
|
|
1692
|
+
VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1693
|
+
WMSCapabilitiesLoader = {
|
|
1694
|
+
name: "WMS Capabilities",
|
|
1695
|
+
id: "wms-capabilities",
|
|
1696
|
+
module: "wms",
|
|
1697
|
+
version: VERSION2,
|
|
1698
|
+
worker: false,
|
|
1699
|
+
extensions: ["xml"],
|
|
1700
|
+
mimeTypes: ["application/vnd.ogc.wms_xml", "application/xml", "text/xml"],
|
|
1701
|
+
testText: testXMLFile2,
|
|
1702
|
+
options: {
|
|
1703
|
+
wms: {}
|
|
1704
|
+
},
|
|
1705
|
+
parse: async (arrayBuffer, options) => parseWMSCapabilities(new TextDecoder().decode(arrayBuffer), options),
|
|
1706
|
+
parseTextSync: (text, options) => parseWMSCapabilities(text, options)
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
// src/wms-feature-info-loader.ts
|
|
1712
|
+
var WMSFeatureInfoLoader;
|
|
1713
|
+
var init_wms_feature_info_loader = __esm({
|
|
1714
|
+
"src/wms-feature-info-loader.ts"() {
|
|
1715
|
+
init_wms_capabilities_loader();
|
|
1716
|
+
init_parse_wms();
|
|
1717
|
+
WMSFeatureInfoLoader = {
|
|
1718
|
+
...WMSCapabilitiesLoader,
|
|
1719
|
+
name: "WMS FeatureInfo",
|
|
1720
|
+
id: "wms-feature-info",
|
|
1721
|
+
parse: async (arrayBuffer, options) => parseWMSFeatureInfo(new TextDecoder().decode(arrayBuffer), options),
|
|
1722
|
+
parseTextSync: (text, options) => parseWMSFeatureInfo(text, options)
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
// src/wms-layer-description-loader.ts
|
|
1728
|
+
var WMSLayerDescriptionLoader;
|
|
1729
|
+
var init_wms_layer_description_loader = __esm({
|
|
1730
|
+
"src/wms-layer-description-loader.ts"() {
|
|
1731
|
+
init_wms_capabilities_loader();
|
|
1732
|
+
init_parse_wms();
|
|
1733
|
+
WMSLayerDescriptionLoader = {
|
|
1734
|
+
...WMSCapabilitiesLoader,
|
|
1735
|
+
name: "WMS DescribeLayer",
|
|
1736
|
+
id: "wms-layer-description",
|
|
1737
|
+
parse: async (arrayBuffer, options) => parseWMSFeatureInfo(new TextDecoder().decode(arrayBuffer), options),
|
|
1738
|
+
parseTextSync: (text, options) => parseWMSFeatureInfo(text, options)
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
|
|
1743
|
+
// ../images/src/lib/utils/version.ts
|
|
1744
|
+
var VERSION3;
|
|
1745
|
+
var init_version = __esm({
|
|
1746
|
+
"../images/src/lib/utils/version.ts"() {
|
|
1747
|
+
VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1751
|
+
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
1752
|
+
function assert(condition, message) {
|
|
1753
|
+
if (!condition) {
|
|
1754
|
+
throw new Error(message || "loader assertion failed.");
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
var init_assert = __esm({
|
|
1758
|
+
"../loader-utils/src/lib/env-utils/assert.ts"() {
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1761
|
+
|
|
1762
|
+
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
1763
|
+
var globals, self_, window_, global_, document_, isBrowser, matches, nodeVersion;
|
|
1764
|
+
var init_globals = __esm({
|
|
1765
|
+
"../loader-utils/src/lib/env-utils/globals.ts"() {
|
|
1766
|
+
globals = {
|
|
1767
|
+
self: typeof self !== "undefined" && self,
|
|
1768
|
+
window: typeof window !== "undefined" && window,
|
|
1769
|
+
global: typeof global !== "undefined" && global,
|
|
1770
|
+
document: typeof document !== "undefined" && document
|
|
1771
|
+
};
|
|
1772
|
+
self_ = globals.self || globals.window || globals.global || {};
|
|
1773
|
+
window_ = globals.window || globals.self || globals.global || {};
|
|
1774
|
+
global_ = globals.global || globals.self || globals.window || {};
|
|
1775
|
+
document_ = globals.document || {};
|
|
1776
|
+
isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
|
|
1777
|
+
matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
1778
|
+
nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
|
|
1782
|
+
// ../loader-utils/src/index.ts
|
|
1783
|
+
var init_src2 = __esm({
|
|
1784
|
+
"../loader-utils/src/index.ts"() {
|
|
1785
|
+
init_assert();
|
|
1786
|
+
init_globals();
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
|
|
1790
|
+
// ../images/src/lib/category-api/image-type.ts
|
|
1791
|
+
function isImageTypeSupported(type) {
|
|
1792
|
+
switch (type) {
|
|
1793
|
+
case "auto":
|
|
1794
|
+
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
1795
|
+
case "imagebitmap":
|
|
1796
|
+
return IMAGE_BITMAP_SUPPORTED;
|
|
1797
|
+
case "image":
|
|
1798
|
+
return IMAGE_SUPPORTED;
|
|
1799
|
+
case "data":
|
|
1800
|
+
return DATA_SUPPORTED;
|
|
1801
|
+
default:
|
|
1802
|
+
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
function getDefaultImageType() {
|
|
1806
|
+
if (IMAGE_BITMAP_SUPPORTED) {
|
|
1807
|
+
return "imagebitmap";
|
|
1808
|
+
}
|
|
1809
|
+
if (IMAGE_SUPPORTED) {
|
|
1810
|
+
return "image";
|
|
1811
|
+
}
|
|
1812
|
+
if (DATA_SUPPORTED) {
|
|
1813
|
+
return "data";
|
|
1814
|
+
}
|
|
1815
|
+
throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
|
|
1816
|
+
}
|
|
1817
|
+
var _parseImageNode, IMAGE_SUPPORTED, IMAGE_BITMAP_SUPPORTED, NODE_IMAGE_SUPPORTED, DATA_SUPPORTED;
|
|
1818
|
+
var init_image_type = __esm({
|
|
1819
|
+
"../images/src/lib/category-api/image-type.ts"() {
|
|
1820
|
+
init_src2();
|
|
1821
|
+
({ _parseImageNode } = globalThis);
|
|
1822
|
+
IMAGE_SUPPORTED = typeof Image !== "undefined";
|
|
1823
|
+
IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
|
|
1824
|
+
NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
1825
|
+
DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1828
|
+
|
|
1829
|
+
// ../images/src/lib/category-api/parsed-image-api.ts
|
|
1830
|
+
function getImageType(image) {
|
|
1831
|
+
const format = getImageTypeOrNull(image);
|
|
1832
|
+
if (!format) {
|
|
1833
|
+
throw new Error("Not an image");
|
|
1834
|
+
}
|
|
1835
|
+
return format;
|
|
1836
|
+
}
|
|
1837
|
+
function getImageData(image) {
|
|
1838
|
+
switch (getImageType(image)) {
|
|
1839
|
+
case "data":
|
|
1840
|
+
return image;
|
|
1841
|
+
case "image":
|
|
1842
|
+
case "imagebitmap":
|
|
1843
|
+
const canvas = document.createElement("canvas");
|
|
1844
|
+
const context = canvas.getContext("2d");
|
|
1845
|
+
if (!context) {
|
|
1846
|
+
throw new Error("getImageData");
|
|
1847
|
+
}
|
|
1848
|
+
canvas.width = image.width;
|
|
1849
|
+
canvas.height = image.height;
|
|
1850
|
+
context.drawImage(image, 0, 0);
|
|
1851
|
+
return context.getImageData(0, 0, image.width, image.height);
|
|
1852
|
+
default:
|
|
1853
|
+
throw new Error("getImageData");
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
function getImageTypeOrNull(image) {
|
|
1857
|
+
if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
1858
|
+
return "imagebitmap";
|
|
1859
|
+
}
|
|
1860
|
+
if (typeof Image !== "undefined" && image instanceof Image) {
|
|
1861
|
+
return "image";
|
|
1862
|
+
}
|
|
1863
|
+
if (image && typeof image === "object" && image.data && image.width && image.height) {
|
|
1864
|
+
return "data";
|
|
1865
|
+
}
|
|
1866
|
+
return null;
|
|
1867
|
+
}
|
|
1868
|
+
var init_parsed_image_api = __esm({
|
|
1869
|
+
"../images/src/lib/category-api/parsed-image-api.ts"() {
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
|
|
1873
|
+
// ../images/src/lib/parsers/svg-utils.ts
|
|
1874
|
+
function isSVG(url) {
|
|
1875
|
+
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
1876
|
+
}
|
|
1877
|
+
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
1878
|
+
if (isSVG(url)) {
|
|
1879
|
+
const textDecoder = new TextDecoder();
|
|
1880
|
+
let xmlText = textDecoder.decode(arrayBuffer);
|
|
1881
|
+
try {
|
|
1882
|
+
if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
|
|
1883
|
+
xmlText = unescape(encodeURIComponent(xmlText));
|
|
1884
|
+
}
|
|
1885
|
+
} catch (error) {
|
|
1886
|
+
throw new Error(error.message);
|
|
1887
|
+
}
|
|
1888
|
+
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
1889
|
+
return src;
|
|
1890
|
+
}
|
|
1891
|
+
return getBlob(arrayBuffer, url);
|
|
1892
|
+
}
|
|
1893
|
+
function getBlob(arrayBuffer, url) {
|
|
1894
|
+
if (isSVG(url)) {
|
|
1895
|
+
throw new Error("SVG cannot be parsed directly to imagebitmap");
|
|
1896
|
+
}
|
|
1897
|
+
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
1898
|
+
}
|
|
1899
|
+
var SVG_DATA_URL_PATTERN, SVG_URL_PATTERN;
|
|
1900
|
+
var init_svg_utils = __esm({
|
|
1901
|
+
"../images/src/lib/parsers/svg-utils.ts"() {
|
|
1902
|
+
SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
1903
|
+
SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
|
|
1907
|
+
// ../images/src/lib/parsers/parse-to-image.ts
|
|
1908
|
+
async function parseToImage(arrayBuffer, options, url) {
|
|
1909
|
+
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
1910
|
+
const URL = self.URL || self.webkitURL;
|
|
1911
|
+
const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
|
|
1912
|
+
try {
|
|
1913
|
+
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
1914
|
+
} finally {
|
|
1915
|
+
if (objectUrl) {
|
|
1916
|
+
URL.revokeObjectURL(objectUrl);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
async function loadToImage(url, options) {
|
|
1921
|
+
const image = new Image();
|
|
1922
|
+
image.src = url;
|
|
1923
|
+
if (options.image && options.image.decode && image.decode) {
|
|
1924
|
+
await image.decode();
|
|
1925
|
+
return image;
|
|
1926
|
+
}
|
|
1927
|
+
return await new Promise((resolve, reject) => {
|
|
1928
|
+
try {
|
|
1929
|
+
image.onload = () => resolve(image);
|
|
1930
|
+
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
1931
|
+
} catch (error) {
|
|
1932
|
+
reject(error);
|
|
1933
|
+
}
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
var init_parse_to_image = __esm({
|
|
1937
|
+
"../images/src/lib/parsers/parse-to-image.ts"() {
|
|
1938
|
+
init_svg_utils();
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
|
|
1942
|
+
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
1943
|
+
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
1944
|
+
let blob;
|
|
1945
|
+
if (isSVG(url)) {
|
|
1946
|
+
const image = await parseToImage(arrayBuffer, options, url);
|
|
1947
|
+
blob = image;
|
|
1948
|
+
} else {
|
|
1949
|
+
blob = getBlob(arrayBuffer, url);
|
|
1950
|
+
}
|
|
1951
|
+
const imagebitmapOptions = options && options.imagebitmap;
|
|
1952
|
+
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
1953
|
+
}
|
|
1954
|
+
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
1955
|
+
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
1956
|
+
imagebitmapOptions = null;
|
|
1957
|
+
}
|
|
1958
|
+
if (imagebitmapOptions) {
|
|
1959
|
+
try {
|
|
1960
|
+
return await createImageBitmap(blob, imagebitmapOptions);
|
|
1961
|
+
} catch (error) {
|
|
1962
|
+
console.warn(error);
|
|
1963
|
+
imagebitmapOptionsSupported = false;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return await createImageBitmap(blob);
|
|
1967
|
+
}
|
|
1968
|
+
function isEmptyObject(object) {
|
|
1969
|
+
for (const key in object || EMPTY_OBJECT) {
|
|
1970
|
+
return false;
|
|
1971
|
+
}
|
|
1972
|
+
return true;
|
|
1973
|
+
}
|
|
1974
|
+
var EMPTY_OBJECT, imagebitmapOptionsSupported;
|
|
1975
|
+
var init_parse_to_image_bitmap = __esm({
|
|
1976
|
+
"../images/src/lib/parsers/parse-to-image-bitmap.ts"() {
|
|
1977
|
+
init_svg_utils();
|
|
1978
|
+
init_parse_to_image();
|
|
1979
|
+
EMPTY_OBJECT = {};
|
|
1980
|
+
imagebitmapOptionsSupported = true;
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
|
|
1984
|
+
// ../images/src/lib/category-api/binary-image-api.ts
|
|
1985
|
+
function getBinaryImageMetadata(binaryData) {
|
|
1986
|
+
const dataView = toDataView(binaryData);
|
|
1987
|
+
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView);
|
|
1988
|
+
}
|
|
1989
|
+
function getPngMetadata(binaryData) {
|
|
1990
|
+
const dataView = toDataView(binaryData);
|
|
1991
|
+
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
|
|
1992
|
+
if (!isPng) {
|
|
1993
|
+
return null;
|
|
1994
|
+
}
|
|
1995
|
+
return {
|
|
1996
|
+
mimeType: "image/png",
|
|
1997
|
+
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
1998
|
+
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
function getGifMetadata(binaryData) {
|
|
2002
|
+
const dataView = toDataView(binaryData);
|
|
2003
|
+
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
|
|
2004
|
+
if (!isGif) {
|
|
2005
|
+
return null;
|
|
2006
|
+
}
|
|
2007
|
+
return {
|
|
2008
|
+
mimeType: "image/gif",
|
|
2009
|
+
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
2010
|
+
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
function getBmpMetadata(binaryData) {
|
|
2014
|
+
const dataView = toDataView(binaryData);
|
|
2015
|
+
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
2016
|
+
if (!isBmp) {
|
|
2017
|
+
return null;
|
|
2018
|
+
}
|
|
2019
|
+
return {
|
|
2020
|
+
mimeType: "image/bmp",
|
|
2021
|
+
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
2022
|
+
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
2023
|
+
};
|
|
2024
|
+
}
|
|
2025
|
+
function getJpegMetadata(binaryData) {
|
|
2026
|
+
const dataView = toDataView(binaryData);
|
|
2027
|
+
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
|
|
2028
|
+
if (!isJpeg) {
|
|
2029
|
+
return null;
|
|
2030
|
+
}
|
|
2031
|
+
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
2032
|
+
let i = 2;
|
|
2033
|
+
while (i + 9 < dataView.byteLength) {
|
|
2034
|
+
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
2035
|
+
if (sofMarkers.has(marker)) {
|
|
2036
|
+
return {
|
|
2037
|
+
mimeType: "image/jpeg",
|
|
2038
|
+
height: dataView.getUint16(i + 5, BIG_ENDIAN),
|
|
2039
|
+
width: dataView.getUint16(i + 7, BIG_ENDIAN)
|
|
2040
|
+
};
|
|
2041
|
+
}
|
|
2042
|
+
if (!tableMarkers.has(marker)) {
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
2045
|
+
i += 2;
|
|
2046
|
+
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
2047
|
+
}
|
|
2048
|
+
return null;
|
|
2049
|
+
}
|
|
2050
|
+
function getJpegMarkers() {
|
|
2051
|
+
const tableMarkers = new Set([65499, 65476, 65484, 65501, 65534]);
|
|
2052
|
+
for (let i = 65504; i < 65520; ++i) {
|
|
2053
|
+
tableMarkers.add(i);
|
|
2054
|
+
}
|
|
2055
|
+
const sofMarkers = new Set([
|
|
2056
|
+
65472,
|
|
2057
|
+
65473,
|
|
2058
|
+
65474,
|
|
2059
|
+
65475,
|
|
2060
|
+
65477,
|
|
2061
|
+
65478,
|
|
2062
|
+
65479,
|
|
2063
|
+
65481,
|
|
2064
|
+
65482,
|
|
2065
|
+
65483,
|
|
2066
|
+
65485,
|
|
2067
|
+
65486,
|
|
2068
|
+
65487,
|
|
2069
|
+
65502
|
|
2070
|
+
]);
|
|
2071
|
+
return { tableMarkers, sofMarkers };
|
|
2072
|
+
}
|
|
2073
|
+
function toDataView(data) {
|
|
2074
|
+
if (data instanceof DataView) {
|
|
2075
|
+
return data;
|
|
2076
|
+
}
|
|
2077
|
+
if (ArrayBuffer.isView(data)) {
|
|
2078
|
+
return new DataView(data.buffer);
|
|
2079
|
+
}
|
|
2080
|
+
if (data instanceof ArrayBuffer) {
|
|
2081
|
+
return new DataView(data);
|
|
2082
|
+
}
|
|
2083
|
+
throw new Error("toDataView");
|
|
2084
|
+
}
|
|
2085
|
+
var BIG_ENDIAN, LITTLE_ENDIAN;
|
|
2086
|
+
var init_binary_image_api = __esm({
|
|
2087
|
+
"../images/src/lib/category-api/binary-image-api.ts"() {
|
|
2088
|
+
BIG_ENDIAN = false;
|
|
2089
|
+
LITTLE_ENDIAN = true;
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
|
|
2093
|
+
// ../images/src/lib/parsers/parse-to-node-image.ts
|
|
2094
|
+
async function parseToNodeImage(arrayBuffer, options) {
|
|
2095
|
+
const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {};
|
|
2096
|
+
const _parseImageNode2 = globalThis._parseImageNode;
|
|
2097
|
+
assert(_parseImageNode2);
|
|
2098
|
+
return await _parseImageNode2(arrayBuffer, mimeType);
|
|
2099
|
+
}
|
|
2100
|
+
var init_parse_to_node_image = __esm({
|
|
2101
|
+
"../images/src/lib/parsers/parse-to-node-image.ts"() {
|
|
2102
|
+
init_src2();
|
|
2103
|
+
init_binary_image_api();
|
|
2104
|
+
}
|
|
2105
|
+
});
|
|
2106
|
+
|
|
2107
|
+
// ../images/src/lib/parsers/parse-image.ts
|
|
2108
|
+
async function parseImage(arrayBuffer, options, context) {
|
|
2109
|
+
options = options || {};
|
|
2110
|
+
const imageOptions = options.image || {};
|
|
2111
|
+
const imageType = imageOptions.type || "auto";
|
|
2112
|
+
const { url } = context || {};
|
|
2113
|
+
const loadType = getLoadableImageType(imageType);
|
|
2114
|
+
let image;
|
|
2115
|
+
switch (loadType) {
|
|
2116
|
+
case "imagebitmap":
|
|
2117
|
+
image = await parseToImageBitmap(arrayBuffer, options, url);
|
|
2118
|
+
break;
|
|
2119
|
+
case "image":
|
|
2120
|
+
image = await parseToImage(arrayBuffer, options, url);
|
|
2121
|
+
break;
|
|
2122
|
+
case "data":
|
|
2123
|
+
image = await parseToNodeImage(arrayBuffer, options);
|
|
2124
|
+
break;
|
|
2125
|
+
default:
|
|
2126
|
+
assert(false);
|
|
2127
|
+
}
|
|
2128
|
+
if (imageType === "data") {
|
|
2129
|
+
image = getImageData(image);
|
|
2130
|
+
}
|
|
2131
|
+
return image;
|
|
2132
|
+
}
|
|
2133
|
+
function getLoadableImageType(type) {
|
|
2134
|
+
switch (type) {
|
|
2135
|
+
case "auto":
|
|
2136
|
+
case "data":
|
|
2137
|
+
return getDefaultImageType();
|
|
2138
|
+
default:
|
|
2139
|
+
isImageTypeSupported(type);
|
|
2140
|
+
return type;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
var init_parse_image = __esm({
|
|
2144
|
+
"../images/src/lib/parsers/parse-image.ts"() {
|
|
2145
|
+
init_src2();
|
|
2146
|
+
init_image_type();
|
|
2147
|
+
init_parsed_image_api();
|
|
2148
|
+
init_parse_to_image();
|
|
2149
|
+
init_parse_to_image_bitmap();
|
|
2150
|
+
init_parse_to_node_image();
|
|
2151
|
+
}
|
|
2152
|
+
});
|
|
2153
|
+
|
|
2154
|
+
// ../images/src/image-loader.ts
|
|
2155
|
+
var EXTENSIONS, MIME_TYPES, DEFAULT_IMAGE_LOADER_OPTIONS, ImageLoader;
|
|
2156
|
+
var init_image_loader = __esm({
|
|
2157
|
+
"../images/src/image-loader.ts"() {
|
|
2158
|
+
init_version();
|
|
2159
|
+
init_parse_image();
|
|
2160
|
+
init_binary_image_api();
|
|
2161
|
+
EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg"];
|
|
2162
|
+
MIME_TYPES = [
|
|
2163
|
+
"image/png",
|
|
2164
|
+
"image/jpeg",
|
|
2165
|
+
"image/gif",
|
|
2166
|
+
"image/webp",
|
|
2167
|
+
"image/bmp",
|
|
2168
|
+
"image/vnd.microsoft.icon",
|
|
2169
|
+
"image/svg+xml"
|
|
2170
|
+
];
|
|
2171
|
+
DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
2172
|
+
image: {
|
|
2173
|
+
type: "auto",
|
|
2174
|
+
decode: true
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
ImageLoader = {
|
|
2178
|
+
id: "image",
|
|
2179
|
+
module: "images",
|
|
2180
|
+
name: "Images",
|
|
2181
|
+
version: VERSION3,
|
|
2182
|
+
mimeTypes: MIME_TYPES,
|
|
2183
|
+
extensions: EXTENSIONS,
|
|
2184
|
+
parse: parseImage,
|
|
2185
|
+
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
2186
|
+
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
});
|
|
2190
|
+
|
|
2191
|
+
// ../images/src/index.ts
|
|
2192
|
+
var init_src3 = __esm({
|
|
2193
|
+
"../images/src/index.ts"() {
|
|
2194
|
+
init_image_loader();
|
|
2195
|
+
}
|
|
2196
|
+
});
|
|
2197
|
+
|
|
2198
|
+
// src/lib/data-sources/wms-data-source.ts
|
|
2199
|
+
var WMSDataSource;
|
|
2200
|
+
var init_wms_data_source = __esm({
|
|
2201
|
+
"src/lib/data-sources/wms-data-source.ts"() {
|
|
2202
|
+
init_src4();
|
|
2203
|
+
init_src3();
|
|
2204
|
+
WMSDataSource = class {
|
|
2205
|
+
constructor(props) {
|
|
2206
|
+
this.url = props.url;
|
|
2207
|
+
this.loadOptions = props.loadOptions || {};
|
|
2208
|
+
this.fetch = props.fetch || fetch;
|
|
2209
|
+
}
|
|
2210
|
+
async getCapabilities(options) {
|
|
2211
|
+
const url = this.getUrl({ request: "GetCapabilities", ...options });
|
|
2212
|
+
const response = await this.fetch(url, this.loadOptions);
|
|
2213
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2214
|
+
return await WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions);
|
|
2215
|
+
}
|
|
2216
|
+
async getImage(options) {
|
|
2217
|
+
const url = this.getUrl({ request: "GetMap", ...options });
|
|
2218
|
+
const response = await this.fetch(url, this.loadOptions);
|
|
2219
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2220
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
2221
|
+
}
|
|
2222
|
+
async getFeatureInfo(options) {
|
|
2223
|
+
const url = this.getUrl({ request: "GetFeatureInfo", ...options });
|
|
2224
|
+
const response = await this.fetch(url, this.loadOptions);
|
|
2225
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2226
|
+
return await WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions);
|
|
2227
|
+
}
|
|
2228
|
+
async getLayerInfo(options) {
|
|
2229
|
+
const url = this.getUrl({ request: "GetLayerInfo", ...options });
|
|
2230
|
+
const response = await this.fetch(url, this.loadOptions);
|
|
2231
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2232
|
+
return await WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions);
|
|
2233
|
+
}
|
|
2234
|
+
async getLegendImage(options) {
|
|
2235
|
+
const url = this.getUrl({ request: "GetLegendImage", ...options });
|
|
2236
|
+
const response = await this.fetch(url, this.loadOptions);
|
|
2237
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2238
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
2239
|
+
}
|
|
2240
|
+
getUrl(options) {
|
|
2241
|
+
let url = `${this.url}?REQUEST=${options.request}`;
|
|
2242
|
+
if (options.layers?.length) {
|
|
2243
|
+
url += `&LAYERS=[${options.layers.join(",")}]`;
|
|
2244
|
+
}
|
|
2245
|
+
return url;
|
|
2246
|
+
}
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
|
|
2251
|
+
// src/index.ts
|
|
2252
|
+
var src_exports = {};
|
|
2253
|
+
__export(src_exports, {
|
|
2254
|
+
WMSCapabilitiesLoader: () => WMSCapabilitiesLoader,
|
|
2255
|
+
WMSFeatureInfoLoader: () => WMSFeatureInfoLoader,
|
|
2256
|
+
WMSLayerDescriptionLoader: () => WMSLayerDescriptionLoader,
|
|
2257
|
+
_WMSDataSource: () => WMSDataSource
|
|
2258
|
+
});
|
|
2259
|
+
var init_src4 = __esm({
|
|
2260
|
+
"src/index.ts"() {
|
|
2261
|
+
init_wms_capabilities_loader();
|
|
2262
|
+
init_wms_feature_info_loader();
|
|
2263
|
+
init_wms_layer_description_loader();
|
|
2264
|
+
init_wms_data_source();
|
|
2265
|
+
}
|
|
2266
|
+
});
|
|
2267
|
+
|
|
2268
|
+
// src/bundle.ts
|
|
2269
|
+
var require_bundle = __commonJS({
|
|
2270
|
+
"src/bundle.ts"(exports, module) {
|
|
2271
|
+
var moduleExports = (init_src4(), src_exports);
|
|
2272
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
2273
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
2274
|
+
}
|
|
2275
|
+
});
|
|
2276
|
+
require_bundle();
|
|
2277
|
+
})();
|