@loaders.gl/wms 4.0.0-beta.5 → 4.0.0-beta.7
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/dist/index.cjs +5 -5
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/parsers/wms/parse-wms-capabilities.d.ts +3 -5
- package/dist/lib/parsers/wms/parse-wms-capabilities.d.ts.map +1 -1
- package/dist/lib/parsers/wms/parse-wms-capabilities.js +2 -2
- package/dist/lib/parsers/wms/parse-wms-capabilities.js.map +1 -1
- package/dist/wms-capabilities-loader.d.ts +1 -3
- package/dist/wms-capabilities-loader.d.ts.map +1 -1
- package/dist/wms-capabilities-loader.js.map +1 -1
- package/package.json +12 -9
- package/src/index.ts +3 -11
- package/src/lib/parsers/wms/parse-wms-capabilities.ts +5 -8
- package/src/wms-capabilities-loader.ts +1 -3
- package/dist/dist.dev.js +0 -4194
- package/dist/lerc-loader.d.ts +0 -17
- package/dist/lerc-loader.d.ts.map +0 -1
- package/dist/lerc-loader.js +0 -21
- package/dist/lerc-loader.js.map +0 -1
- package/dist/lib/parsers/lerc/lerc-types.d.ts +0 -30
- package/dist/lib/parsers/lerc/lerc-types.d.ts.map +0 -1
- package/dist/lib/parsers/lerc/lerc-types.js +0 -2
- package/dist/lib/parsers/lerc/lerc-types.js.map +0 -1
- package/src/lerc-loader.ts +0 -48
- package/src/lib/parsers/lerc/lerc-types.ts +0 -43
package/dist/dist.dev.js
DELETED
|
@@ -1,4194 +0,0 @@
|
|
|
1
|
-
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
-
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
-
module.exports = factory();
|
|
4
|
-
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['loader'] = factory();
|
|
6
|
-
else root['loader'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";
|
|
8
|
-
var __exports__ = (() => {
|
|
9
|
-
var __create = Object.create;
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
14
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
17
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
-
};
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
-
};
|
|
23
|
-
var __copyProps = (to, from, except, desc) => {
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
-
for (let key of __getOwnPropNames(from))
|
|
26
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
-
}
|
|
29
|
-
return to;
|
|
30
|
-
};
|
|
31
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
-
mod
|
|
38
|
-
));
|
|
39
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
-
var __publicField = (obj, key, value) => {
|
|
41
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
42
|
-
return value;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// ../../node_modules/fast-xml-parser/src/util.js
|
|
46
|
-
var require_util = __commonJS({
|
|
47
|
-
"../../node_modules/fast-xml-parser/src/util.js"(exports) {
|
|
48
|
-
"use strict";
|
|
49
|
-
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";
|
|
50
|
-
var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
|
51
|
-
var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
|
|
52
|
-
var regexName = new RegExp("^" + nameRegexp + "$");
|
|
53
|
-
var getAllMatches = function(string, regex) {
|
|
54
|
-
const matches2 = [];
|
|
55
|
-
let match = regex.exec(string);
|
|
56
|
-
while (match) {
|
|
57
|
-
const allmatches = [];
|
|
58
|
-
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
59
|
-
const len = match.length;
|
|
60
|
-
for (let index = 0; index < len; index++) {
|
|
61
|
-
allmatches.push(match[index]);
|
|
62
|
-
}
|
|
63
|
-
matches2.push(allmatches);
|
|
64
|
-
match = regex.exec(string);
|
|
65
|
-
}
|
|
66
|
-
return matches2;
|
|
67
|
-
};
|
|
68
|
-
var isName = function(string) {
|
|
69
|
-
const match = regexName.exec(string);
|
|
70
|
-
return !(match === null || typeof match === "undefined");
|
|
71
|
-
};
|
|
72
|
-
exports.isExist = function(v) {
|
|
73
|
-
return typeof v !== "undefined";
|
|
74
|
-
};
|
|
75
|
-
exports.isEmptyObject = function(obj) {
|
|
76
|
-
return Object.keys(obj).length === 0;
|
|
77
|
-
};
|
|
78
|
-
exports.merge = function(target, a, arrayMode) {
|
|
79
|
-
if (a) {
|
|
80
|
-
const keys = Object.keys(a);
|
|
81
|
-
const len = keys.length;
|
|
82
|
-
for (let i = 0; i < len; i++) {
|
|
83
|
-
if (arrayMode === "strict") {
|
|
84
|
-
target[keys[i]] = [a[keys[i]]];
|
|
85
|
-
} else {
|
|
86
|
-
target[keys[i]] = a[keys[i]];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
exports.getValue = function(v) {
|
|
92
|
-
if (exports.isExist(v)) {
|
|
93
|
-
return v;
|
|
94
|
-
} else {
|
|
95
|
-
return "";
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
exports.isName = isName;
|
|
99
|
-
exports.getAllMatches = getAllMatches;
|
|
100
|
-
exports.nameRegexp = nameRegexp;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// ../../node_modules/fast-xml-parser/src/validator.js
|
|
105
|
-
var require_validator = __commonJS({
|
|
106
|
-
"../../node_modules/fast-xml-parser/src/validator.js"(exports) {
|
|
107
|
-
"use strict";
|
|
108
|
-
var util = require_util();
|
|
109
|
-
var defaultOptions = {
|
|
110
|
-
allowBooleanAttributes: false,
|
|
111
|
-
unpairedTags: []
|
|
112
|
-
};
|
|
113
|
-
exports.validate = function(xmlData, options) {
|
|
114
|
-
options = Object.assign({}, defaultOptions, options);
|
|
115
|
-
const tags = [];
|
|
116
|
-
let tagFound = false;
|
|
117
|
-
let reachedRoot = false;
|
|
118
|
-
if (xmlData[0] === "\uFEFF") {
|
|
119
|
-
xmlData = xmlData.substr(1);
|
|
120
|
-
}
|
|
121
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
122
|
-
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
123
|
-
i += 2;
|
|
124
|
-
i = readPI(xmlData, i);
|
|
125
|
-
if (i.err)
|
|
126
|
-
return i;
|
|
127
|
-
} else if (xmlData[i] === "<") {
|
|
128
|
-
let tagStartPos = i;
|
|
129
|
-
i++;
|
|
130
|
-
if (xmlData[i] === "!") {
|
|
131
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
132
|
-
continue;
|
|
133
|
-
} else {
|
|
134
|
-
let closingTag = false;
|
|
135
|
-
if (xmlData[i] === "/") {
|
|
136
|
-
closingTag = true;
|
|
137
|
-
i++;
|
|
138
|
-
}
|
|
139
|
-
let tagName = "";
|
|
140
|
-
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
|
|
141
|
-
tagName += xmlData[i];
|
|
142
|
-
}
|
|
143
|
-
tagName = tagName.trim();
|
|
144
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
145
|
-
tagName = tagName.substring(0, tagName.length - 1);
|
|
146
|
-
i--;
|
|
147
|
-
}
|
|
148
|
-
if (!validateTagName(tagName)) {
|
|
149
|
-
let msg;
|
|
150
|
-
if (tagName.trim().length === 0) {
|
|
151
|
-
msg = "Invalid space after '<'.";
|
|
152
|
-
} else {
|
|
153
|
-
msg = "Tag '" + tagName + "' is an invalid name.";
|
|
154
|
-
}
|
|
155
|
-
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
156
|
-
}
|
|
157
|
-
const result = readAttributeStr(xmlData, i);
|
|
158
|
-
if (result === false) {
|
|
159
|
-
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
160
|
-
}
|
|
161
|
-
let attrStr = result.value;
|
|
162
|
-
i = result.index;
|
|
163
|
-
if (attrStr[attrStr.length - 1] === "/") {
|
|
164
|
-
const attrStrStart = i - attrStr.length;
|
|
165
|
-
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
166
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
167
|
-
if (isValid === true) {
|
|
168
|
-
tagFound = true;
|
|
169
|
-
} else {
|
|
170
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
171
|
-
}
|
|
172
|
-
} else if (closingTag) {
|
|
173
|
-
if (!result.tagClosed) {
|
|
174
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
175
|
-
} else if (attrStr.trim().length > 0) {
|
|
176
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
177
|
-
} else {
|
|
178
|
-
const otg = tags.pop();
|
|
179
|
-
if (tagName !== otg.tagName) {
|
|
180
|
-
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
181
|
-
return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
182
|
-
}
|
|
183
|
-
if (tags.length == 0) {
|
|
184
|
-
reachedRoot = true;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
189
|
-
if (isValid !== true) {
|
|
190
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
191
|
-
}
|
|
192
|
-
if (reachedRoot === true) {
|
|
193
|
-
return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
|
|
194
|
-
} else if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
195
|
-
} else {
|
|
196
|
-
tags.push({
|
|
197
|
-
tagName,
|
|
198
|
-
tagStartPos
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
tagFound = true;
|
|
202
|
-
}
|
|
203
|
-
for (i++; i < xmlData.length; i++) {
|
|
204
|
-
if (xmlData[i] === "<") {
|
|
205
|
-
if (xmlData[i + 1] === "!") {
|
|
206
|
-
i++;
|
|
207
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
208
|
-
continue;
|
|
209
|
-
} else if (xmlData[i + 1] === "?") {
|
|
210
|
-
i = readPI(xmlData, ++i);
|
|
211
|
-
if (i.err)
|
|
212
|
-
return i;
|
|
213
|
-
} else {
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
} else if (xmlData[i] === "&") {
|
|
217
|
-
const afterAmp = validateAmpersand(xmlData, i);
|
|
218
|
-
if (afterAmp == -1)
|
|
219
|
-
return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
220
|
-
i = afterAmp;
|
|
221
|
-
} else {
|
|
222
|
-
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
223
|
-
return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (xmlData[i] === "<") {
|
|
228
|
-
i--;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
if (isWhiteSpace(xmlData[i])) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (!tagFound) {
|
|
239
|
-
return getErrorObject("InvalidXml", "Start tag expected.", 1);
|
|
240
|
-
} else if (tags.length == 1) {
|
|
241
|
-
return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
242
|
-
} else if (tags.length > 0) {
|
|
243
|
-
return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", {
|
|
244
|
-
line: 1,
|
|
245
|
-
col: 1
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
return true;
|
|
249
|
-
};
|
|
250
|
-
function isWhiteSpace(char) {
|
|
251
|
-
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
252
|
-
}
|
|
253
|
-
function readPI(xmlData, i) {
|
|
254
|
-
const start = i;
|
|
255
|
-
for (; i < xmlData.length; i++) {
|
|
256
|
-
if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
257
|
-
const tagname = xmlData.substr(start, i - start);
|
|
258
|
-
if (i > 5 && tagname === "xml") {
|
|
259
|
-
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
260
|
-
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
261
|
-
i++;
|
|
262
|
-
break;
|
|
263
|
-
} else {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return i;
|
|
269
|
-
}
|
|
270
|
-
function readCommentAndCDATA(xmlData, i) {
|
|
271
|
-
if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
|
|
272
|
-
for (i += 3; i < xmlData.length; i++) {
|
|
273
|
-
if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
|
|
274
|
-
i += 2;
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
} 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") {
|
|
279
|
-
let angleBracketsCount = 1;
|
|
280
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
281
|
-
if (xmlData[i] === "<") {
|
|
282
|
-
angleBracketsCount++;
|
|
283
|
-
} else if (xmlData[i] === ">") {
|
|
284
|
-
angleBracketsCount--;
|
|
285
|
-
if (angleBracketsCount === 0) {
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
} 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] === "[") {
|
|
291
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
292
|
-
if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
|
|
293
|
-
i += 2;
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return i;
|
|
299
|
-
}
|
|
300
|
-
var doubleQuote = '"';
|
|
301
|
-
var singleQuote = "'";
|
|
302
|
-
function readAttributeStr(xmlData, i) {
|
|
303
|
-
let attrStr = "";
|
|
304
|
-
let startChar = "";
|
|
305
|
-
let tagClosed = false;
|
|
306
|
-
for (; i < xmlData.length; i++) {
|
|
307
|
-
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
|
308
|
-
if (startChar === "") {
|
|
309
|
-
startChar = xmlData[i];
|
|
310
|
-
} else if (startChar !== xmlData[i]) {
|
|
311
|
-
} else {
|
|
312
|
-
startChar = "";
|
|
313
|
-
}
|
|
314
|
-
} else if (xmlData[i] === ">") {
|
|
315
|
-
if (startChar === "") {
|
|
316
|
-
tagClosed = true;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
attrStr += xmlData[i];
|
|
321
|
-
}
|
|
322
|
-
if (startChar !== "") {
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
value: attrStr,
|
|
327
|
-
index: i,
|
|
328
|
-
tagClosed
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
|
|
332
|
-
function validateAttributeString(attrStr, options) {
|
|
333
|
-
const matches2 = util.getAllMatches(attrStr, validAttrStrRegxp);
|
|
334
|
-
const attrNames = {};
|
|
335
|
-
for (let i = 0; i < matches2.length; i++) {
|
|
336
|
-
if (matches2[i][1].length === 0) {
|
|
337
|
-
return getErrorObject("InvalidAttr", "Attribute '" + matches2[i][2] + "' has no space in starting.", getPositionFromMatch(matches2[i]));
|
|
338
|
-
} else if (matches2[i][3] !== void 0 && matches2[i][4] === void 0) {
|
|
339
|
-
return getErrorObject("InvalidAttr", "Attribute '" + matches2[i][2] + "' is without value.", getPositionFromMatch(matches2[i]));
|
|
340
|
-
} else if (matches2[i][3] === void 0 && !options.allowBooleanAttributes) {
|
|
341
|
-
return getErrorObject("InvalidAttr", "boolean attribute '" + matches2[i][2] + "' is not allowed.", getPositionFromMatch(matches2[i]));
|
|
342
|
-
}
|
|
343
|
-
const attrName = matches2[i][2];
|
|
344
|
-
if (!validateAttrName(attrName)) {
|
|
345
|
-
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches2[i]));
|
|
346
|
-
}
|
|
347
|
-
if (!attrNames.hasOwnProperty(attrName)) {
|
|
348
|
-
attrNames[attrName] = 1;
|
|
349
|
-
} else {
|
|
350
|
-
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches2[i]));
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return true;
|
|
354
|
-
}
|
|
355
|
-
function validateNumberAmpersand(xmlData, i) {
|
|
356
|
-
let re = /\d/;
|
|
357
|
-
if (xmlData[i] === "x") {
|
|
358
|
-
i++;
|
|
359
|
-
re = /[\da-fA-F]/;
|
|
360
|
-
}
|
|
361
|
-
for (; i < xmlData.length; i++) {
|
|
362
|
-
if (xmlData[i] === ";")
|
|
363
|
-
return i;
|
|
364
|
-
if (!xmlData[i].match(re))
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
return -1;
|
|
368
|
-
}
|
|
369
|
-
function validateAmpersand(xmlData, i) {
|
|
370
|
-
i++;
|
|
371
|
-
if (xmlData[i] === ";")
|
|
372
|
-
return -1;
|
|
373
|
-
if (xmlData[i] === "#") {
|
|
374
|
-
i++;
|
|
375
|
-
return validateNumberAmpersand(xmlData, i);
|
|
376
|
-
}
|
|
377
|
-
let count = 0;
|
|
378
|
-
for (; i < xmlData.length; i++, count++) {
|
|
379
|
-
if (xmlData[i].match(/\w/) && count < 20)
|
|
380
|
-
continue;
|
|
381
|
-
if (xmlData[i] === ";")
|
|
382
|
-
break;
|
|
383
|
-
return -1;
|
|
384
|
-
}
|
|
385
|
-
return i;
|
|
386
|
-
}
|
|
387
|
-
function getErrorObject(code, message, lineNumber) {
|
|
388
|
-
return {
|
|
389
|
-
err: {
|
|
390
|
-
code,
|
|
391
|
-
msg: message,
|
|
392
|
-
line: lineNumber.line || lineNumber,
|
|
393
|
-
col: lineNumber.col
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
function validateAttrName(attrName) {
|
|
398
|
-
return util.isName(attrName);
|
|
399
|
-
}
|
|
400
|
-
function validateTagName(tagname) {
|
|
401
|
-
return util.isName(tagname);
|
|
402
|
-
}
|
|
403
|
-
function getLineNumberForPosition(xmlData, index) {
|
|
404
|
-
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
405
|
-
return {
|
|
406
|
-
line: lines.length,
|
|
407
|
-
col: lines[lines.length - 1].length + 1
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function getPositionFromMatch(match) {
|
|
411
|
-
return match.startIndex + match[1].length;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
// ../../node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
|
|
417
|
-
var require_OptionsBuilder = __commonJS({
|
|
418
|
-
"../../node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports) {
|
|
419
|
-
var defaultOptions = {
|
|
420
|
-
preserveOrder: false,
|
|
421
|
-
attributeNamePrefix: "@_",
|
|
422
|
-
attributesGroupName: false,
|
|
423
|
-
textNodeName: "#text",
|
|
424
|
-
ignoreAttributes: true,
|
|
425
|
-
removeNSPrefix: false,
|
|
426
|
-
allowBooleanAttributes: false,
|
|
427
|
-
parseTagValue: true,
|
|
428
|
-
parseAttributeValue: false,
|
|
429
|
-
trimValues: true,
|
|
430
|
-
cdataPropName: false,
|
|
431
|
-
numberParseOptions: {
|
|
432
|
-
hex: true,
|
|
433
|
-
leadingZeros: true,
|
|
434
|
-
eNotation: true
|
|
435
|
-
},
|
|
436
|
-
tagValueProcessor: function(tagName, val2) {
|
|
437
|
-
return val2;
|
|
438
|
-
},
|
|
439
|
-
attributeValueProcessor: function(attrName, val2) {
|
|
440
|
-
return val2;
|
|
441
|
-
},
|
|
442
|
-
stopNodes: [],
|
|
443
|
-
alwaysCreateTextNode: false,
|
|
444
|
-
isArray: () => false,
|
|
445
|
-
commentPropName: false,
|
|
446
|
-
unpairedTags: [],
|
|
447
|
-
processEntities: true,
|
|
448
|
-
htmlEntities: false,
|
|
449
|
-
ignoreDeclaration: false,
|
|
450
|
-
ignorePiTags: false,
|
|
451
|
-
transformTagName: false,
|
|
452
|
-
transformAttributeName: false,
|
|
453
|
-
updateTag: function(tagName, jPath, attrs) {
|
|
454
|
-
return tagName;
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
var buildOptions = function(options) {
|
|
458
|
-
return Object.assign({}, defaultOptions, options);
|
|
459
|
-
};
|
|
460
|
-
exports.buildOptions = buildOptions;
|
|
461
|
-
exports.defaultOptions = defaultOptions;
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
// ../../node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
|
|
466
|
-
var require_xmlNode = __commonJS({
|
|
467
|
-
"../../node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports, module) {
|
|
468
|
-
"use strict";
|
|
469
|
-
var XmlNode = class {
|
|
470
|
-
constructor(tagname) {
|
|
471
|
-
this.tagname = tagname;
|
|
472
|
-
this.child = [];
|
|
473
|
-
this[":@"] = {};
|
|
474
|
-
}
|
|
475
|
-
add(key, val2) {
|
|
476
|
-
if (key === "__proto__")
|
|
477
|
-
key = "#__proto__";
|
|
478
|
-
this.child.push({
|
|
479
|
-
[key]: val2
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
addChild(node) {
|
|
483
|
-
if (node.tagname === "__proto__")
|
|
484
|
-
node.tagname = "#__proto__";
|
|
485
|
-
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
486
|
-
this.child.push({
|
|
487
|
-
[node.tagname]: node.child,
|
|
488
|
-
[":@"]: node[":@"]
|
|
489
|
-
});
|
|
490
|
-
} else {
|
|
491
|
-
this.child.push({
|
|
492
|
-
[node.tagname]: node.child
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
module.exports = XmlNode;
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// ../../node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
|
|
502
|
-
var require_DocTypeReader = __commonJS({
|
|
503
|
-
"../../node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports, module) {
|
|
504
|
-
var util = require_util();
|
|
505
|
-
function readDocType(xmlData, i) {
|
|
506
|
-
const entities = {};
|
|
507
|
-
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") {
|
|
508
|
-
i = i + 9;
|
|
509
|
-
let angleBracketsCount = 1;
|
|
510
|
-
let hasBody = false, comment = false;
|
|
511
|
-
let exp = "";
|
|
512
|
-
for (; i < xmlData.length; i++) {
|
|
513
|
-
if (xmlData[i] === "<" && !comment) {
|
|
514
|
-
if (hasBody && isEntity(xmlData, i)) {
|
|
515
|
-
i += 7;
|
|
516
|
-
[entityName, val, i] = readEntityExp(xmlData, i + 1);
|
|
517
|
-
if (val.indexOf("&") === -1)
|
|
518
|
-
entities[validateEntityName(entityName)] = {
|
|
519
|
-
regx: RegExp(`&${entityName};`, "g"),
|
|
520
|
-
val
|
|
521
|
-
};
|
|
522
|
-
} else if (hasBody && isElement(xmlData, i))
|
|
523
|
-
i += 8;
|
|
524
|
-
else if (hasBody && isAttlist(xmlData, i))
|
|
525
|
-
i += 8;
|
|
526
|
-
else if (hasBody && isNotation(xmlData, i))
|
|
527
|
-
i += 9;
|
|
528
|
-
else if (isComment)
|
|
529
|
-
comment = true;
|
|
530
|
-
else
|
|
531
|
-
throw new Error("Invalid DOCTYPE");
|
|
532
|
-
angleBracketsCount++;
|
|
533
|
-
exp = "";
|
|
534
|
-
} else if (xmlData[i] === ">") {
|
|
535
|
-
if (comment) {
|
|
536
|
-
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
|
|
537
|
-
comment = false;
|
|
538
|
-
angleBracketsCount--;
|
|
539
|
-
}
|
|
540
|
-
} else {
|
|
541
|
-
angleBracketsCount--;
|
|
542
|
-
}
|
|
543
|
-
if (angleBracketsCount === 0) {
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
} else if (xmlData[i] === "[") {
|
|
547
|
-
hasBody = true;
|
|
548
|
-
} else {
|
|
549
|
-
exp += xmlData[i];
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
if (angleBracketsCount !== 0) {
|
|
553
|
-
throw new Error(`Unclosed DOCTYPE`);
|
|
554
|
-
}
|
|
555
|
-
} else {
|
|
556
|
-
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
557
|
-
}
|
|
558
|
-
return {
|
|
559
|
-
entities,
|
|
560
|
-
i
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
function readEntityExp(xmlData, i) {
|
|
564
|
-
let entityName2 = "";
|
|
565
|
-
for (; i < xmlData.length && xmlData[i] !== "'" && xmlData[i] !== '"'; i++) {
|
|
566
|
-
entityName2 += xmlData[i];
|
|
567
|
-
}
|
|
568
|
-
entityName2 = entityName2.trim();
|
|
569
|
-
if (entityName2.indexOf(" ") !== -1)
|
|
570
|
-
throw new Error("External entites are not supported");
|
|
571
|
-
const startChar = xmlData[i++];
|
|
572
|
-
let val2 = "";
|
|
573
|
-
for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
|
|
574
|
-
val2 += xmlData[i];
|
|
575
|
-
}
|
|
576
|
-
return [entityName2, val2, i];
|
|
577
|
-
}
|
|
578
|
-
function isComment(xmlData, i) {
|
|
579
|
-
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-")
|
|
580
|
-
return true;
|
|
581
|
-
return false;
|
|
582
|
-
}
|
|
583
|
-
function isEntity(xmlData, i) {
|
|
584
|
-
if (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")
|
|
585
|
-
return true;
|
|
586
|
-
return false;
|
|
587
|
-
}
|
|
588
|
-
function isElement(xmlData, i) {
|
|
589
|
-
if (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")
|
|
590
|
-
return true;
|
|
591
|
-
return false;
|
|
592
|
-
}
|
|
593
|
-
function isAttlist(xmlData, i) {
|
|
594
|
-
if (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")
|
|
595
|
-
return true;
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
function isNotation(xmlData, i) {
|
|
599
|
-
if (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")
|
|
600
|
-
return true;
|
|
601
|
-
return false;
|
|
602
|
-
}
|
|
603
|
-
function validateEntityName(name) {
|
|
604
|
-
if (util.isName(name))
|
|
605
|
-
return name;
|
|
606
|
-
else
|
|
607
|
-
throw new Error(`Invalid entity name ${name}`);
|
|
608
|
-
}
|
|
609
|
-
module.exports = readDocType;
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
// ../../node_modules/strnum/strnum.js
|
|
614
|
-
var require_strnum = __commonJS({
|
|
615
|
-
"../../node_modules/strnum/strnum.js"(exports, module) {
|
|
616
|
-
var hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
617
|
-
var numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
|
|
618
|
-
if (!Number.parseInt && window.parseInt) {
|
|
619
|
-
Number.parseInt = window.parseInt;
|
|
620
|
-
}
|
|
621
|
-
if (!Number.parseFloat && window.parseFloat) {
|
|
622
|
-
Number.parseFloat = window.parseFloat;
|
|
623
|
-
}
|
|
624
|
-
var consider = {
|
|
625
|
-
hex: true,
|
|
626
|
-
leadingZeros: true,
|
|
627
|
-
decimalPoint: ".",
|
|
628
|
-
eNotation: true
|
|
629
|
-
//skipLike: /regex/
|
|
630
|
-
};
|
|
631
|
-
function toNumber(str, options = {}) {
|
|
632
|
-
options = Object.assign({}, consider, options);
|
|
633
|
-
if (!str || typeof str !== "string")
|
|
634
|
-
return str;
|
|
635
|
-
let trimmedStr = str.trim();
|
|
636
|
-
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr))
|
|
637
|
-
return str;
|
|
638
|
-
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
639
|
-
return Number.parseInt(trimmedStr, 16);
|
|
640
|
-
} else {
|
|
641
|
-
const match = numRegex.exec(trimmedStr);
|
|
642
|
-
if (match) {
|
|
643
|
-
const sign = match[1];
|
|
644
|
-
const leadingZeros = match[2];
|
|
645
|
-
let numTrimmedByZeros = trimZeros(match[3]);
|
|
646
|
-
const eNotation = match[4] || match[6];
|
|
647
|
-
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".")
|
|
648
|
-
return str;
|
|
649
|
-
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".")
|
|
650
|
-
return str;
|
|
651
|
-
else {
|
|
652
|
-
const num = Number(trimmedStr);
|
|
653
|
-
const numStr = "" + num;
|
|
654
|
-
if (numStr.search(/[eE]/) !== -1) {
|
|
655
|
-
if (options.eNotation)
|
|
656
|
-
return num;
|
|
657
|
-
else
|
|
658
|
-
return str;
|
|
659
|
-
} else if (eNotation) {
|
|
660
|
-
if (options.eNotation)
|
|
661
|
-
return num;
|
|
662
|
-
else
|
|
663
|
-
return str;
|
|
664
|
-
} else if (trimmedStr.indexOf(".") !== -1) {
|
|
665
|
-
if (numStr === "0" && numTrimmedByZeros === "")
|
|
666
|
-
return num;
|
|
667
|
-
else if (numStr === numTrimmedByZeros)
|
|
668
|
-
return num;
|
|
669
|
-
else if (sign && numStr === "-" + numTrimmedByZeros)
|
|
670
|
-
return num;
|
|
671
|
-
else
|
|
672
|
-
return str;
|
|
673
|
-
}
|
|
674
|
-
if (leadingZeros) {
|
|
675
|
-
if (numTrimmedByZeros === numStr)
|
|
676
|
-
return num;
|
|
677
|
-
else if (sign + numTrimmedByZeros === numStr)
|
|
678
|
-
return num;
|
|
679
|
-
else
|
|
680
|
-
return str;
|
|
681
|
-
}
|
|
682
|
-
if (trimmedStr === numStr)
|
|
683
|
-
return num;
|
|
684
|
-
else if (trimmedStr === sign + numStr)
|
|
685
|
-
return num;
|
|
686
|
-
return str;
|
|
687
|
-
}
|
|
688
|
-
} else {
|
|
689
|
-
return str;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
function trimZeros(numStr) {
|
|
694
|
-
if (numStr && numStr.indexOf(".") !== -1) {
|
|
695
|
-
numStr = numStr.replace(/0+$/, "");
|
|
696
|
-
if (numStr === ".")
|
|
697
|
-
numStr = "0";
|
|
698
|
-
else if (numStr[0] === ".")
|
|
699
|
-
numStr = "0" + numStr;
|
|
700
|
-
else if (numStr[numStr.length - 1] === ".")
|
|
701
|
-
numStr = numStr.substr(0, numStr.length - 1);
|
|
702
|
-
return numStr;
|
|
703
|
-
}
|
|
704
|
-
return numStr;
|
|
705
|
-
}
|
|
706
|
-
module.exports = toNumber;
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
// ../../node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
|
|
711
|
-
var require_OrderedObjParser = __commonJS({
|
|
712
|
-
"../../node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js"(exports, module) {
|
|
713
|
-
"use strict";
|
|
714
|
-
var util = require_util();
|
|
715
|
-
var xmlNode = require_xmlNode();
|
|
716
|
-
var readDocType = require_DocTypeReader();
|
|
717
|
-
var toNumber = require_strnum();
|
|
718
|
-
var regx = "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util.nameRegexp);
|
|
719
|
-
var OrderedObjParser = class {
|
|
720
|
-
constructor(options) {
|
|
721
|
-
this.options = options;
|
|
722
|
-
this.currentNode = null;
|
|
723
|
-
this.tagsNodeStack = [];
|
|
724
|
-
this.docTypeEntities = {};
|
|
725
|
-
this.lastEntities = {
|
|
726
|
-
"apos": {
|
|
727
|
-
regex: /&(apos|#39|#x27);/g,
|
|
728
|
-
val: "'"
|
|
729
|
-
},
|
|
730
|
-
"gt": {
|
|
731
|
-
regex: /&(gt|#62|#x3E);/g,
|
|
732
|
-
val: ">"
|
|
733
|
-
},
|
|
734
|
-
"lt": {
|
|
735
|
-
regex: /&(lt|#60|#x3C);/g,
|
|
736
|
-
val: "<"
|
|
737
|
-
},
|
|
738
|
-
"quot": {
|
|
739
|
-
regex: /&(quot|#34|#x22);/g,
|
|
740
|
-
val: '"'
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
this.ampEntity = {
|
|
744
|
-
regex: /&(amp|#38|#x26);/g,
|
|
745
|
-
val: "&"
|
|
746
|
-
};
|
|
747
|
-
this.htmlEntities = {
|
|
748
|
-
"space": {
|
|
749
|
-
regex: /&(nbsp|#160);/g,
|
|
750
|
-
val: " "
|
|
751
|
-
},
|
|
752
|
-
"cent": {
|
|
753
|
-
regex: /&(cent|#162);/g,
|
|
754
|
-
val: "\xA2"
|
|
755
|
-
},
|
|
756
|
-
"pound": {
|
|
757
|
-
regex: /&(pound|#163);/g,
|
|
758
|
-
val: "\xA3"
|
|
759
|
-
},
|
|
760
|
-
"yen": {
|
|
761
|
-
regex: /&(yen|#165);/g,
|
|
762
|
-
val: "\xA5"
|
|
763
|
-
},
|
|
764
|
-
"euro": {
|
|
765
|
-
regex: /&(euro|#8364);/g,
|
|
766
|
-
val: "\u20AC"
|
|
767
|
-
},
|
|
768
|
-
"copyright": {
|
|
769
|
-
regex: /&(copy|#169);/g,
|
|
770
|
-
val: "\xA9"
|
|
771
|
-
},
|
|
772
|
-
"reg": {
|
|
773
|
-
regex: /&(reg|#174);/g,
|
|
774
|
-
val: "\xAE"
|
|
775
|
-
},
|
|
776
|
-
"inr": {
|
|
777
|
-
regex: /&(inr|#8377);/g,
|
|
778
|
-
val: "\u20B9"
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
this.addExternalEntities = addExternalEntities;
|
|
782
|
-
this.parseXml = parseXml;
|
|
783
|
-
this.parseTextData = parseTextData;
|
|
784
|
-
this.resolveNameSpace = resolveNameSpace;
|
|
785
|
-
this.buildAttributesMap = buildAttributesMap;
|
|
786
|
-
this.isItStopNode = isItStopNode;
|
|
787
|
-
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
788
|
-
this.readStopNodeData = readStopNodeData;
|
|
789
|
-
this.saveTextToParentTag = saveTextToParentTag;
|
|
790
|
-
this.addChild = addChild;
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
function addExternalEntities(externalEntities) {
|
|
794
|
-
const entKeys = Object.keys(externalEntities);
|
|
795
|
-
for (let i = 0; i < entKeys.length; i++) {
|
|
796
|
-
const ent = entKeys[i];
|
|
797
|
-
this.lastEntities[ent] = {
|
|
798
|
-
regex: new RegExp("&" + ent + ";", "g"),
|
|
799
|
-
val: externalEntities[ent]
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function parseTextData(val2, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
804
|
-
if (val2 !== void 0) {
|
|
805
|
-
if (this.options.trimValues && !dontTrim) {
|
|
806
|
-
val2 = val2.trim();
|
|
807
|
-
}
|
|
808
|
-
if (val2.length > 0) {
|
|
809
|
-
if (!escapeEntities)
|
|
810
|
-
val2 = this.replaceEntitiesValue(val2);
|
|
811
|
-
const newval = this.options.tagValueProcessor(tagName, val2, jPath, hasAttributes, isLeafNode);
|
|
812
|
-
if (newval === null || newval === void 0) {
|
|
813
|
-
return val2;
|
|
814
|
-
} else if (typeof newval !== typeof val2 || newval !== val2) {
|
|
815
|
-
return newval;
|
|
816
|
-
} else if (this.options.trimValues) {
|
|
817
|
-
return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
|
|
818
|
-
} else {
|
|
819
|
-
const trimmedVal = val2.trim();
|
|
820
|
-
if (trimmedVal === val2) {
|
|
821
|
-
return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
|
|
822
|
-
} else {
|
|
823
|
-
return val2;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
function resolveNameSpace(tagname) {
|
|
830
|
-
if (this.options.removeNSPrefix) {
|
|
831
|
-
const tags = tagname.split(":");
|
|
832
|
-
const prefix = tagname.charAt(0) === "/" ? "/" : "";
|
|
833
|
-
if (tags[0] === "xmlns") {
|
|
834
|
-
return "";
|
|
835
|
-
}
|
|
836
|
-
if (tags.length === 2) {
|
|
837
|
-
tagname = prefix + tags[1];
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
return tagname;
|
|
841
|
-
}
|
|
842
|
-
var attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
|
|
843
|
-
function buildAttributesMap(attrStr, jPath, tagName) {
|
|
844
|
-
if (!this.options.ignoreAttributes && typeof attrStr === "string") {
|
|
845
|
-
const matches2 = util.getAllMatches(attrStr, attrsRegx);
|
|
846
|
-
const len = matches2.length;
|
|
847
|
-
const attrs = {};
|
|
848
|
-
for (let i = 0; i < len; i++) {
|
|
849
|
-
const attrName = this.resolveNameSpace(matches2[i][1]);
|
|
850
|
-
let oldVal = matches2[i][4];
|
|
851
|
-
let aName = this.options.attributeNamePrefix + attrName;
|
|
852
|
-
if (attrName.length) {
|
|
853
|
-
if (this.options.transformAttributeName) {
|
|
854
|
-
aName = this.options.transformAttributeName(aName);
|
|
855
|
-
}
|
|
856
|
-
if (aName === "__proto__")
|
|
857
|
-
aName = "#__proto__";
|
|
858
|
-
if (oldVal !== void 0) {
|
|
859
|
-
if (this.options.trimValues) {
|
|
860
|
-
oldVal = oldVal.trim();
|
|
861
|
-
}
|
|
862
|
-
oldVal = this.replaceEntitiesValue(oldVal);
|
|
863
|
-
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
|
|
864
|
-
if (newVal === null || newVal === void 0) {
|
|
865
|
-
attrs[aName] = oldVal;
|
|
866
|
-
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
|
|
867
|
-
attrs[aName] = newVal;
|
|
868
|
-
} else {
|
|
869
|
-
attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
|
|
870
|
-
}
|
|
871
|
-
} else if (this.options.allowBooleanAttributes) {
|
|
872
|
-
attrs[aName] = true;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
if (!Object.keys(attrs).length) {
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
if (this.options.attributesGroupName) {
|
|
880
|
-
const attrCollection = {};
|
|
881
|
-
attrCollection[this.options.attributesGroupName] = attrs;
|
|
882
|
-
return attrCollection;
|
|
883
|
-
}
|
|
884
|
-
return attrs;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
var parseXml = function(xmlData) {
|
|
888
|
-
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
889
|
-
const xmlObj = new xmlNode("!xml");
|
|
890
|
-
let currentNode = xmlObj;
|
|
891
|
-
let textData = "";
|
|
892
|
-
let jPath = "";
|
|
893
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
894
|
-
const ch = xmlData[i];
|
|
895
|
-
if (ch === "<") {
|
|
896
|
-
if (xmlData[i + 1] === "/") {
|
|
897
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
898
|
-
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
899
|
-
if (this.options.removeNSPrefix) {
|
|
900
|
-
const colonIndex = tagName.indexOf(":");
|
|
901
|
-
if (colonIndex !== -1) {
|
|
902
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
if (this.options.transformTagName) {
|
|
906
|
-
tagName = this.options.transformTagName(tagName);
|
|
907
|
-
}
|
|
908
|
-
if (currentNode) {
|
|
909
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
910
|
-
}
|
|
911
|
-
const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
|
|
912
|
-
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
913
|
-
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
914
|
-
}
|
|
915
|
-
let propIndex = 0;
|
|
916
|
-
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
|
|
917
|
-
propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
|
|
918
|
-
this.tagsNodeStack.pop();
|
|
919
|
-
} else {
|
|
920
|
-
propIndex = jPath.lastIndexOf(".");
|
|
921
|
-
}
|
|
922
|
-
jPath = jPath.substring(0, propIndex);
|
|
923
|
-
currentNode = this.tagsNodeStack.pop();
|
|
924
|
-
textData = "";
|
|
925
|
-
i = closeIndex;
|
|
926
|
-
} else if (xmlData[i + 1] === "?") {
|
|
927
|
-
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
928
|
-
if (!tagData)
|
|
929
|
-
throw new Error("Pi Tag is not closed.");
|
|
930
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
931
|
-
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) {
|
|
932
|
-
} else {
|
|
933
|
-
const childNode = new xmlNode(tagData.tagName);
|
|
934
|
-
childNode.add(this.options.textNodeName, "");
|
|
935
|
-
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
|
|
936
|
-
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
|
|
937
|
-
}
|
|
938
|
-
this.addChild(currentNode, childNode, jPath);
|
|
939
|
-
}
|
|
940
|
-
i = tagData.closeIndex + 1;
|
|
941
|
-
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
942
|
-
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
943
|
-
if (this.options.commentPropName) {
|
|
944
|
-
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
945
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
946
|
-
currentNode.add(this.options.commentPropName, [{
|
|
947
|
-
[this.options.textNodeName]: comment
|
|
948
|
-
}]);
|
|
949
|
-
}
|
|
950
|
-
i = endIndex;
|
|
951
|
-
} else if (xmlData.substr(i + 1, 2) === "!D") {
|
|
952
|
-
const result = readDocType(xmlData, i);
|
|
953
|
-
this.docTypeEntities = result.entities;
|
|
954
|
-
i = result.i;
|
|
955
|
-
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
956
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
957
|
-
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
958
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
959
|
-
if (this.options.cdataPropName) {
|
|
960
|
-
currentNode.add(this.options.cdataPropName, [{
|
|
961
|
-
[this.options.textNodeName]: tagExp
|
|
962
|
-
}]);
|
|
963
|
-
} else {
|
|
964
|
-
let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
|
|
965
|
-
if (val2 == void 0)
|
|
966
|
-
val2 = "";
|
|
967
|
-
currentNode.add(this.options.textNodeName, val2);
|
|
968
|
-
}
|
|
969
|
-
i = closeIndex + 2;
|
|
970
|
-
} else {
|
|
971
|
-
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
972
|
-
let tagName = result.tagName;
|
|
973
|
-
let tagExp = result.tagExp;
|
|
974
|
-
let attrExpPresent = result.attrExpPresent;
|
|
975
|
-
let closeIndex = result.closeIndex;
|
|
976
|
-
if (this.options.transformTagName) {
|
|
977
|
-
tagName = this.options.transformTagName(tagName);
|
|
978
|
-
}
|
|
979
|
-
if (currentNode && textData) {
|
|
980
|
-
if (currentNode.tagname !== "!xml") {
|
|
981
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
const lastTag = currentNode;
|
|
985
|
-
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
|
|
986
|
-
currentNode = this.tagsNodeStack.pop();
|
|
987
|
-
jPath = jPath.substring(0, jPath.lastIndexOf("."));
|
|
988
|
-
}
|
|
989
|
-
if (tagName !== xmlObj.tagname) {
|
|
990
|
-
jPath += jPath ? "." + tagName : tagName;
|
|
991
|
-
}
|
|
992
|
-
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
993
|
-
let tagContent = "";
|
|
994
|
-
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
995
|
-
i = result.closeIndex;
|
|
996
|
-
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
997
|
-
i = result.closeIndex;
|
|
998
|
-
} else {
|
|
999
|
-
const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
|
|
1000
|
-
if (!result2)
|
|
1001
|
-
throw new Error(`Unexpected end of ${tagName}`);
|
|
1002
|
-
i = result2.i;
|
|
1003
|
-
tagContent = result2.tagContent;
|
|
1004
|
-
}
|
|
1005
|
-
const childNode = new xmlNode(tagName);
|
|
1006
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
1007
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1008
|
-
}
|
|
1009
|
-
if (tagContent) {
|
|
1010
|
-
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
1011
|
-
}
|
|
1012
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
1013
|
-
childNode.add(this.options.textNodeName, tagContent);
|
|
1014
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1015
|
-
} else {
|
|
1016
|
-
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
1017
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
1018
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
1019
|
-
tagExp = tagName;
|
|
1020
|
-
} else {
|
|
1021
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
1022
|
-
}
|
|
1023
|
-
if (this.options.transformTagName) {
|
|
1024
|
-
tagName = this.options.transformTagName(tagName);
|
|
1025
|
-
}
|
|
1026
|
-
const childNode = new xmlNode(tagName);
|
|
1027
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
1028
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1029
|
-
}
|
|
1030
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1031
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
1032
|
-
} else {
|
|
1033
|
-
const childNode = new xmlNode(tagName);
|
|
1034
|
-
this.tagsNodeStack.push(currentNode);
|
|
1035
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
1036
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1037
|
-
}
|
|
1038
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1039
|
-
currentNode = childNode;
|
|
1040
|
-
}
|
|
1041
|
-
textData = "";
|
|
1042
|
-
i = closeIndex;
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
} else {
|
|
1046
|
-
textData += xmlData[i];
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
return xmlObj.child;
|
|
1050
|
-
};
|
|
1051
|
-
function addChild(currentNode, childNode, jPath) {
|
|
1052
|
-
const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
|
|
1053
|
-
if (result === false) {
|
|
1054
|
-
} else if (typeof result === "string") {
|
|
1055
|
-
childNode.tagname = result;
|
|
1056
|
-
currentNode.addChild(childNode);
|
|
1057
|
-
} else {
|
|
1058
|
-
currentNode.addChild(childNode);
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
var replaceEntitiesValue = function(val2) {
|
|
1062
|
-
if (this.options.processEntities) {
|
|
1063
|
-
for (let entityName2 in this.docTypeEntities) {
|
|
1064
|
-
const entity = this.docTypeEntities[entityName2];
|
|
1065
|
-
val2 = val2.replace(entity.regx, entity.val);
|
|
1066
|
-
}
|
|
1067
|
-
for (let entityName2 in this.lastEntities) {
|
|
1068
|
-
const entity = this.lastEntities[entityName2];
|
|
1069
|
-
val2 = val2.replace(entity.regex, entity.val);
|
|
1070
|
-
}
|
|
1071
|
-
if (this.options.htmlEntities) {
|
|
1072
|
-
for (let entityName2 in this.htmlEntities) {
|
|
1073
|
-
const entity = this.htmlEntities[entityName2];
|
|
1074
|
-
val2 = val2.replace(entity.regex, entity.val);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
val2 = val2.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
1078
|
-
}
|
|
1079
|
-
return val2;
|
|
1080
|
-
};
|
|
1081
|
-
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
1082
|
-
if (textData) {
|
|
1083
|
-
if (isLeafNode === void 0)
|
|
1084
|
-
isLeafNode = Object.keys(currentNode.child).length === 0;
|
|
1085
|
-
textData = this.parseTextData(textData, currentNode.tagname, jPath, false, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false, isLeafNode);
|
|
1086
|
-
if (textData !== void 0 && textData !== "")
|
|
1087
|
-
currentNode.add(this.options.textNodeName, textData);
|
|
1088
|
-
textData = "";
|
|
1089
|
-
}
|
|
1090
|
-
return textData;
|
|
1091
|
-
}
|
|
1092
|
-
function isItStopNode(stopNodes, jPath, currentTagName) {
|
|
1093
|
-
const allNodesExp = "*." + currentTagName;
|
|
1094
|
-
for (const stopNodePath in stopNodes) {
|
|
1095
|
-
const stopNodeExp = stopNodes[stopNodePath];
|
|
1096
|
-
if (allNodesExp === stopNodeExp || jPath === stopNodeExp)
|
|
1097
|
-
return true;
|
|
1098
|
-
}
|
|
1099
|
-
return false;
|
|
1100
|
-
}
|
|
1101
|
-
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
1102
|
-
let attrBoundary;
|
|
1103
|
-
let tagExp = "";
|
|
1104
|
-
for (let index = i; index < xmlData.length; index++) {
|
|
1105
|
-
let ch = xmlData[index];
|
|
1106
|
-
if (attrBoundary) {
|
|
1107
|
-
if (ch === attrBoundary)
|
|
1108
|
-
attrBoundary = "";
|
|
1109
|
-
} else if (ch === '"' || ch === "'") {
|
|
1110
|
-
attrBoundary = ch;
|
|
1111
|
-
} else if (ch === closingChar[0]) {
|
|
1112
|
-
if (closingChar[1]) {
|
|
1113
|
-
if (xmlData[index + 1] === closingChar[1]) {
|
|
1114
|
-
return {
|
|
1115
|
-
data: tagExp,
|
|
1116
|
-
index
|
|
1117
|
-
};
|
|
1118
|
-
}
|
|
1119
|
-
} else {
|
|
1120
|
-
return {
|
|
1121
|
-
data: tagExp,
|
|
1122
|
-
index
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
} else if (ch === " ") {
|
|
1126
|
-
ch = " ";
|
|
1127
|
-
}
|
|
1128
|
-
tagExp += ch;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
function findClosingIndex(xmlData, str, i, errMsg) {
|
|
1132
|
-
const closingIndex = xmlData.indexOf(str, i);
|
|
1133
|
-
if (closingIndex === -1) {
|
|
1134
|
-
throw new Error(errMsg);
|
|
1135
|
-
} else {
|
|
1136
|
-
return closingIndex + str.length - 1;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
|
|
1140
|
-
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
|
|
1141
|
-
if (!result)
|
|
1142
|
-
return;
|
|
1143
|
-
let tagExp = result.data;
|
|
1144
|
-
const closeIndex = result.index;
|
|
1145
|
-
const separatorIndex = tagExp.search(/\s/);
|
|
1146
|
-
let tagName = tagExp;
|
|
1147
|
-
let attrExpPresent = true;
|
|
1148
|
-
if (separatorIndex !== -1) {
|
|
1149
|
-
tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
|
|
1150
|
-
tagExp = tagExp.substr(separatorIndex + 1);
|
|
1151
|
-
}
|
|
1152
|
-
if (removeNSPrefix) {
|
|
1153
|
-
const colonIndex = tagName.indexOf(":");
|
|
1154
|
-
if (colonIndex !== -1) {
|
|
1155
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
1156
|
-
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
return {
|
|
1160
|
-
tagName,
|
|
1161
|
-
tagExp,
|
|
1162
|
-
closeIndex,
|
|
1163
|
-
attrExpPresent
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
function readStopNodeData(xmlData, tagName, i) {
|
|
1167
|
-
const startIndex = i;
|
|
1168
|
-
let openTagCount = 1;
|
|
1169
|
-
for (; i < xmlData.length; i++) {
|
|
1170
|
-
if (xmlData[i] === "<") {
|
|
1171
|
-
if (xmlData[i + 1] === "/") {
|
|
1172
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
1173
|
-
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1174
|
-
if (closeTagName === tagName) {
|
|
1175
|
-
openTagCount--;
|
|
1176
|
-
if (openTagCount === 0) {
|
|
1177
|
-
return {
|
|
1178
|
-
tagContent: xmlData.substring(startIndex, i),
|
|
1179
|
-
i: closeIndex
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
i = closeIndex;
|
|
1184
|
-
} else if (xmlData[i + 1] === "?") {
|
|
1185
|
-
const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
|
|
1186
|
-
i = closeIndex;
|
|
1187
|
-
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1188
|
-
const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
|
|
1189
|
-
i = closeIndex;
|
|
1190
|
-
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1191
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
1192
|
-
i = closeIndex;
|
|
1193
|
-
} else {
|
|
1194
|
-
const tagData = readTagExp(xmlData, i, ">");
|
|
1195
|
-
if (tagData) {
|
|
1196
|
-
const openTagName = tagData && tagData.tagName;
|
|
1197
|
-
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
|
|
1198
|
-
openTagCount++;
|
|
1199
|
-
}
|
|
1200
|
-
i = tagData.closeIndex;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
function parseValue(val2, shouldParse, options) {
|
|
1207
|
-
if (shouldParse && typeof val2 === "string") {
|
|
1208
|
-
const newval = val2.trim();
|
|
1209
|
-
if (newval === "true")
|
|
1210
|
-
return true;
|
|
1211
|
-
else if (newval === "false")
|
|
1212
|
-
return false;
|
|
1213
|
-
else
|
|
1214
|
-
return toNumber(val2, options);
|
|
1215
|
-
} else {
|
|
1216
|
-
if (util.isExist(val2)) {
|
|
1217
|
-
return val2;
|
|
1218
|
-
} else {
|
|
1219
|
-
return "";
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
module.exports = OrderedObjParser;
|
|
1224
|
-
}
|
|
1225
|
-
});
|
|
1226
|
-
|
|
1227
|
-
// ../../node_modules/fast-xml-parser/src/xmlparser/node2json.js
|
|
1228
|
-
var require_node2json = __commonJS({
|
|
1229
|
-
"../../node_modules/fast-xml-parser/src/xmlparser/node2json.js"(exports) {
|
|
1230
|
-
"use strict";
|
|
1231
|
-
function prettify(node, options) {
|
|
1232
|
-
return compress(node, options);
|
|
1233
|
-
}
|
|
1234
|
-
function compress(arr, options, jPath) {
|
|
1235
|
-
let text;
|
|
1236
|
-
const compressedObj = {};
|
|
1237
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1238
|
-
const tagObj = arr[i];
|
|
1239
|
-
const property = propName(tagObj);
|
|
1240
|
-
let newJpath = "";
|
|
1241
|
-
if (jPath === void 0)
|
|
1242
|
-
newJpath = property;
|
|
1243
|
-
else
|
|
1244
|
-
newJpath = jPath + "." + property;
|
|
1245
|
-
if (property === options.textNodeName) {
|
|
1246
|
-
if (text === void 0)
|
|
1247
|
-
text = tagObj[property];
|
|
1248
|
-
else
|
|
1249
|
-
text += "" + tagObj[property];
|
|
1250
|
-
} else if (property === void 0) {
|
|
1251
|
-
continue;
|
|
1252
|
-
} else if (tagObj[property]) {
|
|
1253
|
-
let val2 = compress(tagObj[property], options, newJpath);
|
|
1254
|
-
const isLeaf = isLeafTag(val2, options);
|
|
1255
|
-
if (tagObj[":@"]) {
|
|
1256
|
-
assignAttributes(val2, tagObj[":@"], newJpath, options);
|
|
1257
|
-
} else if (Object.keys(val2).length === 1 && val2[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
|
|
1258
|
-
val2 = val2[options.textNodeName];
|
|
1259
|
-
} else if (Object.keys(val2).length === 0) {
|
|
1260
|
-
if (options.alwaysCreateTextNode)
|
|
1261
|
-
val2[options.textNodeName] = "";
|
|
1262
|
-
else
|
|
1263
|
-
val2 = "";
|
|
1264
|
-
}
|
|
1265
|
-
if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
|
|
1266
|
-
if (!Array.isArray(compressedObj[property])) {
|
|
1267
|
-
compressedObj[property] = [compressedObj[property]];
|
|
1268
|
-
}
|
|
1269
|
-
compressedObj[property].push(val2);
|
|
1270
|
-
} else {
|
|
1271
|
-
if (options.isArray(property, newJpath, isLeaf)) {
|
|
1272
|
-
compressedObj[property] = [val2];
|
|
1273
|
-
} else {
|
|
1274
|
-
compressedObj[property] = val2;
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
if (typeof text === "string") {
|
|
1280
|
-
if (text.length > 0)
|
|
1281
|
-
compressedObj[options.textNodeName] = text;
|
|
1282
|
-
} else if (text !== void 0)
|
|
1283
|
-
compressedObj[options.textNodeName] = text;
|
|
1284
|
-
return compressedObj;
|
|
1285
|
-
}
|
|
1286
|
-
function propName(obj) {
|
|
1287
|
-
const keys = Object.keys(obj);
|
|
1288
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1289
|
-
const key = keys[i];
|
|
1290
|
-
if (key !== ":@")
|
|
1291
|
-
return key;
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
function assignAttributes(obj, attrMap, jpath, options) {
|
|
1295
|
-
if (attrMap) {
|
|
1296
|
-
const keys = Object.keys(attrMap);
|
|
1297
|
-
const len = keys.length;
|
|
1298
|
-
for (let i = 0; i < len; i++) {
|
|
1299
|
-
const atrrName = keys[i];
|
|
1300
|
-
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
1301
|
-
obj[atrrName] = [attrMap[atrrName]];
|
|
1302
|
-
} else {
|
|
1303
|
-
obj[atrrName] = attrMap[atrrName];
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
function isLeafTag(obj, options) {
|
|
1309
|
-
const {
|
|
1310
|
-
textNodeName
|
|
1311
|
-
} = options;
|
|
1312
|
-
const propCount = Object.keys(obj).length;
|
|
1313
|
-
if (propCount === 0) {
|
|
1314
|
-
return true;
|
|
1315
|
-
}
|
|
1316
|
-
if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) {
|
|
1317
|
-
return true;
|
|
1318
|
-
}
|
|
1319
|
-
return false;
|
|
1320
|
-
}
|
|
1321
|
-
exports.prettify = prettify;
|
|
1322
|
-
}
|
|
1323
|
-
});
|
|
1324
|
-
|
|
1325
|
-
// ../../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
|
|
1326
|
-
var require_XMLParser = __commonJS({
|
|
1327
|
-
"../../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports, module) {
|
|
1328
|
-
var {
|
|
1329
|
-
buildOptions
|
|
1330
|
-
} = require_OptionsBuilder();
|
|
1331
|
-
var OrderedObjParser = require_OrderedObjParser();
|
|
1332
|
-
var {
|
|
1333
|
-
prettify
|
|
1334
|
-
} = require_node2json();
|
|
1335
|
-
var validator = require_validator();
|
|
1336
|
-
var XMLParser = class {
|
|
1337
|
-
constructor(options) {
|
|
1338
|
-
this.externalEntities = {};
|
|
1339
|
-
this.options = buildOptions(options);
|
|
1340
|
-
}
|
|
1341
|
-
parse(xmlData, validationOption) {
|
|
1342
|
-
if (typeof xmlData === "string") {
|
|
1343
|
-
} else if (xmlData.toString) {
|
|
1344
|
-
xmlData = xmlData.toString();
|
|
1345
|
-
} else {
|
|
1346
|
-
throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
1347
|
-
}
|
|
1348
|
-
if (validationOption) {
|
|
1349
|
-
if (validationOption === true)
|
|
1350
|
-
validationOption = {};
|
|
1351
|
-
const result = validator.validate(xmlData, validationOption);
|
|
1352
|
-
if (result !== true) {
|
|
1353
|
-
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
const orderedObjParser = new OrderedObjParser(this.options);
|
|
1357
|
-
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
1358
|
-
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
1359
|
-
if (this.options.preserveOrder || orderedResult === void 0)
|
|
1360
|
-
return orderedResult;
|
|
1361
|
-
else
|
|
1362
|
-
return prettify(orderedResult, this.options);
|
|
1363
|
-
}
|
|
1364
|
-
addEntity(key, value) {
|
|
1365
|
-
if (value.indexOf("&") !== -1) {
|
|
1366
|
-
throw new Error("Entity value can't have '&'");
|
|
1367
|
-
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
1368
|
-
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
1369
|
-
} else if (value === "&") {
|
|
1370
|
-
throw new Error("An entity with value '&' is not permitted");
|
|
1371
|
-
} else {
|
|
1372
|
-
this.externalEntities[key] = value;
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1376
|
-
module.exports = XMLParser;
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
|
|
1380
|
-
// ../../node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js
|
|
1381
|
-
var require_orderedJs2Xml = __commonJS({
|
|
1382
|
-
"../../node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports, module) {
|
|
1383
|
-
var EOL = "\n";
|
|
1384
|
-
function toXml(jArray, options) {
|
|
1385
|
-
let indentation = "";
|
|
1386
|
-
if (options.format && options.indentBy.length > 0) {
|
|
1387
|
-
indentation = EOL;
|
|
1388
|
-
}
|
|
1389
|
-
return arrToStr(jArray, options, "", indentation);
|
|
1390
|
-
}
|
|
1391
|
-
function arrToStr(arr, options, jPath, indentation) {
|
|
1392
|
-
let xmlStr = "";
|
|
1393
|
-
let isPreviousElementTag = false;
|
|
1394
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1395
|
-
const tagObj = arr[i];
|
|
1396
|
-
const tagName = propName(tagObj);
|
|
1397
|
-
let newJPath = "";
|
|
1398
|
-
if (jPath.length === 0)
|
|
1399
|
-
newJPath = tagName;
|
|
1400
|
-
else
|
|
1401
|
-
newJPath = `${jPath}.${tagName}`;
|
|
1402
|
-
if (tagName === options.textNodeName) {
|
|
1403
|
-
let tagText = tagObj[tagName];
|
|
1404
|
-
if (!isStopNode(newJPath, options)) {
|
|
1405
|
-
tagText = options.tagValueProcessor(tagName, tagText);
|
|
1406
|
-
tagText = replaceEntitiesValue(tagText, options);
|
|
1407
|
-
}
|
|
1408
|
-
if (isPreviousElementTag) {
|
|
1409
|
-
xmlStr += indentation;
|
|
1410
|
-
}
|
|
1411
|
-
xmlStr += tagText;
|
|
1412
|
-
isPreviousElementTag = false;
|
|
1413
|
-
continue;
|
|
1414
|
-
} else if (tagName === options.cdataPropName) {
|
|
1415
|
-
if (isPreviousElementTag) {
|
|
1416
|
-
xmlStr += indentation;
|
|
1417
|
-
}
|
|
1418
|
-
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
1419
|
-
isPreviousElementTag = false;
|
|
1420
|
-
continue;
|
|
1421
|
-
} else if (tagName === options.commentPropName) {
|
|
1422
|
-
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
1423
|
-
isPreviousElementTag = true;
|
|
1424
|
-
continue;
|
|
1425
|
-
} else if (tagName[0] === "?") {
|
|
1426
|
-
const attStr2 = attr_to_str(tagObj[":@"], options);
|
|
1427
|
-
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
1428
|
-
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
1429
|
-
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
|
|
1430
|
-
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
|
|
1431
|
-
isPreviousElementTag = true;
|
|
1432
|
-
continue;
|
|
1433
|
-
}
|
|
1434
|
-
let newIdentation = indentation;
|
|
1435
|
-
if (newIdentation !== "") {
|
|
1436
|
-
newIdentation += options.indentBy;
|
|
1437
|
-
}
|
|
1438
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
1439
|
-
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
1440
|
-
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
|
|
1441
|
-
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1442
|
-
if (options.suppressUnpairedNode)
|
|
1443
|
-
xmlStr += tagStart + ">";
|
|
1444
|
-
else
|
|
1445
|
-
xmlStr += tagStart + "/>";
|
|
1446
|
-
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
1447
|
-
xmlStr += tagStart + "/>";
|
|
1448
|
-
} else if (tagValue && tagValue.endsWith(">")) {
|
|
1449
|
-
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
1450
|
-
} else {
|
|
1451
|
-
xmlStr += tagStart + ">";
|
|
1452
|
-
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
1453
|
-
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
1454
|
-
} else {
|
|
1455
|
-
xmlStr += tagValue;
|
|
1456
|
-
}
|
|
1457
|
-
xmlStr += `</${tagName}>`;
|
|
1458
|
-
}
|
|
1459
|
-
isPreviousElementTag = true;
|
|
1460
|
-
}
|
|
1461
|
-
return xmlStr;
|
|
1462
|
-
}
|
|
1463
|
-
function propName(obj) {
|
|
1464
|
-
const keys = Object.keys(obj);
|
|
1465
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1466
|
-
const key = keys[i];
|
|
1467
|
-
if (key !== ":@")
|
|
1468
|
-
return key;
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
function attr_to_str(attrMap, options) {
|
|
1472
|
-
let attrStr = "";
|
|
1473
|
-
if (attrMap && !options.ignoreAttributes) {
|
|
1474
|
-
for (let attr in attrMap) {
|
|
1475
|
-
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
1476
|
-
attrVal = replaceEntitiesValue(attrVal, options);
|
|
1477
|
-
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
1478
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
1479
|
-
} else {
|
|
1480
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
return attrStr;
|
|
1485
|
-
}
|
|
1486
|
-
function isStopNode(jPath, options) {
|
|
1487
|
-
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
1488
|
-
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
1489
|
-
for (let index in options.stopNodes) {
|
|
1490
|
-
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName)
|
|
1491
|
-
return true;
|
|
1492
|
-
}
|
|
1493
|
-
return false;
|
|
1494
|
-
}
|
|
1495
|
-
function replaceEntitiesValue(textValue, options) {
|
|
1496
|
-
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
1497
|
-
for (let i = 0; i < options.entities.length; i++) {
|
|
1498
|
-
const entity = options.entities[i];
|
|
1499
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
return textValue;
|
|
1503
|
-
}
|
|
1504
|
-
module.exports = toXml;
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1507
|
-
|
|
1508
|
-
// ../../node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js
|
|
1509
|
-
var require_json2xml = __commonJS({
|
|
1510
|
-
"../../node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js"(exports, module) {
|
|
1511
|
-
"use strict";
|
|
1512
|
-
var buildFromOrderedJs = require_orderedJs2Xml();
|
|
1513
|
-
var defaultOptions = {
|
|
1514
|
-
attributeNamePrefix: "@_",
|
|
1515
|
-
attributesGroupName: false,
|
|
1516
|
-
textNodeName: "#text",
|
|
1517
|
-
ignoreAttributes: true,
|
|
1518
|
-
cdataPropName: false,
|
|
1519
|
-
format: false,
|
|
1520
|
-
indentBy: " ",
|
|
1521
|
-
suppressEmptyNode: false,
|
|
1522
|
-
suppressUnpairedNode: true,
|
|
1523
|
-
suppressBooleanAttributes: true,
|
|
1524
|
-
tagValueProcessor: function(key, a) {
|
|
1525
|
-
return a;
|
|
1526
|
-
},
|
|
1527
|
-
attributeValueProcessor: function(attrName, a) {
|
|
1528
|
-
return a;
|
|
1529
|
-
},
|
|
1530
|
-
preserveOrder: false,
|
|
1531
|
-
commentPropName: false,
|
|
1532
|
-
unpairedTags: [],
|
|
1533
|
-
entities: [{
|
|
1534
|
-
regex: new RegExp("&", "g"),
|
|
1535
|
-
val: "&"
|
|
1536
|
-
}, {
|
|
1537
|
-
regex: new RegExp(">", "g"),
|
|
1538
|
-
val: ">"
|
|
1539
|
-
}, {
|
|
1540
|
-
regex: new RegExp("<", "g"),
|
|
1541
|
-
val: "<"
|
|
1542
|
-
}, {
|
|
1543
|
-
regex: new RegExp("'", "g"),
|
|
1544
|
-
val: "'"
|
|
1545
|
-
}, {
|
|
1546
|
-
regex: new RegExp('"', "g"),
|
|
1547
|
-
val: """
|
|
1548
|
-
}],
|
|
1549
|
-
processEntities: true,
|
|
1550
|
-
stopNodes: [],
|
|
1551
|
-
oneListGroup: false
|
|
1552
|
-
};
|
|
1553
|
-
function Builder(options) {
|
|
1554
|
-
this.options = Object.assign({}, defaultOptions, options);
|
|
1555
|
-
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
|
|
1556
|
-
this.isAttribute = function() {
|
|
1557
|
-
return false;
|
|
1558
|
-
};
|
|
1559
|
-
} else {
|
|
1560
|
-
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
1561
|
-
this.isAttribute = isAttribute;
|
|
1562
|
-
}
|
|
1563
|
-
this.processTextOrObjNode = processTextOrObjNode;
|
|
1564
|
-
if (this.options.format) {
|
|
1565
|
-
this.indentate = indentate;
|
|
1566
|
-
this.tagEndChar = ">\n";
|
|
1567
|
-
this.newLine = "\n";
|
|
1568
|
-
} else {
|
|
1569
|
-
this.indentate = function() {
|
|
1570
|
-
return "";
|
|
1571
|
-
};
|
|
1572
|
-
this.tagEndChar = ">";
|
|
1573
|
-
this.newLine = "";
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
Builder.prototype.build = function(jObj) {
|
|
1577
|
-
if (this.options.preserveOrder) {
|
|
1578
|
-
return buildFromOrderedJs(jObj, this.options);
|
|
1579
|
-
} else {
|
|
1580
|
-
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
|
|
1581
|
-
jObj = {
|
|
1582
|
-
[this.options.arrayNodeName]: jObj
|
|
1583
|
-
};
|
|
1584
|
-
}
|
|
1585
|
-
return this.j2x(jObj, 0).val;
|
|
1586
|
-
}
|
|
1587
|
-
};
|
|
1588
|
-
Builder.prototype.j2x = function(jObj, level) {
|
|
1589
|
-
let attrStr = "";
|
|
1590
|
-
let val2 = "";
|
|
1591
|
-
for (let key in jObj) {
|
|
1592
|
-
if (typeof jObj[key] === "undefined") {
|
|
1593
|
-
} else if (jObj[key] === null) {
|
|
1594
|
-
if (key[0] === "?")
|
|
1595
|
-
val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
1596
|
-
else
|
|
1597
|
-
val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1598
|
-
} else if (jObj[key] instanceof Date) {
|
|
1599
|
-
val2 += this.buildTextValNode(jObj[key], key, "", level);
|
|
1600
|
-
} else if (typeof jObj[key] !== "object") {
|
|
1601
|
-
const attr = this.isAttribute(key);
|
|
1602
|
-
if (attr) {
|
|
1603
|
-
attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
|
|
1604
|
-
} else {
|
|
1605
|
-
if (key === this.options.textNodeName) {
|
|
1606
|
-
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
|
|
1607
|
-
val2 += this.replaceEntitiesValue(newval);
|
|
1608
|
-
} else {
|
|
1609
|
-
val2 += this.buildTextValNode(jObj[key], key, "", level);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
} else if (Array.isArray(jObj[key])) {
|
|
1613
|
-
const arrLen = jObj[key].length;
|
|
1614
|
-
let listTagVal = "";
|
|
1615
|
-
for (let j = 0; j < arrLen; j++) {
|
|
1616
|
-
const item = jObj[key][j];
|
|
1617
|
-
if (typeof item === "undefined") {
|
|
1618
|
-
} else if (item === null) {
|
|
1619
|
-
if (key[0] === "?")
|
|
1620
|
-
val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
1621
|
-
else
|
|
1622
|
-
val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1623
|
-
} else if (typeof item === "object") {
|
|
1624
|
-
if (this.options.oneListGroup) {
|
|
1625
|
-
listTagVal += this.j2x(item, level + 1).val;
|
|
1626
|
-
} else {
|
|
1627
|
-
listTagVal += this.processTextOrObjNode(item, key, level);
|
|
1628
|
-
}
|
|
1629
|
-
} else {
|
|
1630
|
-
listTagVal += this.buildTextValNode(item, key, "", level);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
if (this.options.oneListGroup) {
|
|
1634
|
-
listTagVal = this.buildObjectNode(listTagVal, key, "", level);
|
|
1635
|
-
}
|
|
1636
|
-
val2 += listTagVal;
|
|
1637
|
-
} else {
|
|
1638
|
-
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
1639
|
-
const Ks = Object.keys(jObj[key]);
|
|
1640
|
-
const L = Ks.length;
|
|
1641
|
-
for (let j = 0; j < L; j++) {
|
|
1642
|
-
attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
|
|
1643
|
-
}
|
|
1644
|
-
} else {
|
|
1645
|
-
val2 += this.processTextOrObjNode(jObj[key], key, level);
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
return {
|
|
1650
|
-
attrStr,
|
|
1651
|
-
val: val2
|
|
1652
|
-
};
|
|
1653
|
-
};
|
|
1654
|
-
Builder.prototype.buildAttrPairStr = function(attrName, val2) {
|
|
1655
|
-
val2 = this.options.attributeValueProcessor(attrName, "" + val2);
|
|
1656
|
-
val2 = this.replaceEntitiesValue(val2);
|
|
1657
|
-
if (this.options.suppressBooleanAttributes && val2 === "true") {
|
|
1658
|
-
return " " + attrName;
|
|
1659
|
-
} else
|
|
1660
|
-
return " " + attrName + '="' + val2 + '"';
|
|
1661
|
-
};
|
|
1662
|
-
function processTextOrObjNode(object, key, level) {
|
|
1663
|
-
const result = this.j2x(object, level + 1);
|
|
1664
|
-
if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
|
|
1665
|
-
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
1666
|
-
} else {
|
|
1667
|
-
return this.buildObjectNode(result.val, key, result.attrStr, level);
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
Builder.prototype.buildObjectNode = function(val2, key, attrStr, level) {
|
|
1671
|
-
if (val2 === "") {
|
|
1672
|
-
if (key[0] === "?")
|
|
1673
|
-
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
1674
|
-
else {
|
|
1675
|
-
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
1676
|
-
}
|
|
1677
|
-
} else {
|
|
1678
|
-
let tagEndExp = "</" + key + this.tagEndChar;
|
|
1679
|
-
let piClosingChar = "";
|
|
1680
|
-
if (key[0] === "?") {
|
|
1681
|
-
piClosingChar = "?";
|
|
1682
|
-
tagEndExp = "";
|
|
1683
|
-
}
|
|
1684
|
-
if (attrStr && val2.indexOf("<") === -1) {
|
|
1685
|
-
return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
|
|
1686
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
1687
|
-
return this.indentate(level) + `<!--${val2}-->` + this.newLine;
|
|
1688
|
-
} else {
|
|
1689
|
-
return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val2 + this.indentate(level) + tagEndExp;
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
};
|
|
1693
|
-
Builder.prototype.closeTag = function(key) {
|
|
1694
|
-
let closeTag = "";
|
|
1695
|
-
if (this.options.unpairedTags.indexOf(key) !== -1) {
|
|
1696
|
-
if (!this.options.suppressUnpairedNode)
|
|
1697
|
-
closeTag = "/";
|
|
1698
|
-
} else if (this.options.suppressEmptyNode) {
|
|
1699
|
-
closeTag = "/";
|
|
1700
|
-
} else {
|
|
1701
|
-
closeTag = `></${key}`;
|
|
1702
|
-
}
|
|
1703
|
-
return closeTag;
|
|
1704
|
-
};
|
|
1705
|
-
Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
|
|
1706
|
-
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
1707
|
-
return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
|
|
1708
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
1709
|
-
return this.indentate(level) + `<!--${val2}-->` + this.newLine;
|
|
1710
|
-
} else if (key[0] === "?") {
|
|
1711
|
-
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
1712
|
-
} else {
|
|
1713
|
-
let textValue = this.options.tagValueProcessor(key, val2);
|
|
1714
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
1715
|
-
if (textValue === "") {
|
|
1716
|
-
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
1717
|
-
} else {
|
|
1718
|
-
return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
};
|
|
1722
|
-
Builder.prototype.replaceEntitiesValue = function(textValue) {
|
|
1723
|
-
if (textValue && textValue.length > 0 && this.options.processEntities) {
|
|
1724
|
-
for (let i = 0; i < this.options.entities.length; i++) {
|
|
1725
|
-
const entity = this.options.entities[i];
|
|
1726
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
return textValue;
|
|
1730
|
-
};
|
|
1731
|
-
function indentate(level) {
|
|
1732
|
-
return this.options.indentBy.repeat(level);
|
|
1733
|
-
}
|
|
1734
|
-
function isAttribute(name) {
|
|
1735
|
-
if (name.startsWith(this.options.attributeNamePrefix)) {
|
|
1736
|
-
return name.substr(this.attrPrefixLen);
|
|
1737
|
-
} else {
|
|
1738
|
-
return false;
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
module.exports = Builder;
|
|
1742
|
-
}
|
|
1743
|
-
});
|
|
1744
|
-
|
|
1745
|
-
// ../../node_modules/fast-xml-parser/src/fxp.js
|
|
1746
|
-
var require_fxp = __commonJS({
|
|
1747
|
-
"../../node_modules/fast-xml-parser/src/fxp.js"(exports, module) {
|
|
1748
|
-
"use strict";
|
|
1749
|
-
var validator = require_validator();
|
|
1750
|
-
var XMLParser = require_XMLParser();
|
|
1751
|
-
var XMLBuilder = require_json2xml();
|
|
1752
|
-
module.exports = {
|
|
1753
|
-
XMLParser,
|
|
1754
|
-
XMLValidator: validator,
|
|
1755
|
-
XMLBuilder
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
});
|
|
1759
|
-
|
|
1760
|
-
// src/index.ts
|
|
1761
|
-
var src_exports = {};
|
|
1762
|
-
__export(src_exports, {
|
|
1763
|
-
CSWCapabilitiesLoader: () => CSWCapabilitiesLoader,
|
|
1764
|
-
CSWDomainLoader: () => CSWDomainLoader,
|
|
1765
|
-
CSWRecordsLoader: () => CSWRecordsLoader,
|
|
1766
|
-
CSWService: () => CSWService,
|
|
1767
|
-
ImageService: () => ImageService,
|
|
1768
|
-
ImageSource: () => ImageSource,
|
|
1769
|
-
WMSCapabilitiesLoader: () => WMSCapabilitiesLoader,
|
|
1770
|
-
WMSErrorLoader: () => WMSErrorLoader,
|
|
1771
|
-
WMSService: () => WMSService,
|
|
1772
|
-
WMSSource: () => WMSSource,
|
|
1773
|
-
_ArcGISImageService: () => ArcGISImageService,
|
|
1774
|
-
_GMLLoader: () => GMLLoader,
|
|
1775
|
-
_WFSCapabilitiesLoader: () => WFSCapabilitiesLoader,
|
|
1776
|
-
_WMSFeatureInfoLoader: () => WMSFeatureInfoLoader,
|
|
1777
|
-
_WMSLayerDescriptionLoader: () => WMSLayerDescriptionLoader,
|
|
1778
|
-
_getArcGISServices: () => getArcGISServices,
|
|
1779
|
-
createImageService: () => createImageService,
|
|
1780
|
-
createImageSource: () => createImageSource
|
|
1781
|
-
});
|
|
1782
|
-
|
|
1783
|
-
// ../xml/src/lib/xml-utils/uncapitalize.ts
|
|
1784
|
-
function uncapitalize(str) {
|
|
1785
|
-
return typeof str === "string" ? str.charAt(0).toLowerCase() + str.slice(1) : str;
|
|
1786
|
-
}
|
|
1787
|
-
function uncapitalizeKeys(object) {
|
|
1788
|
-
if (Array.isArray(object)) {
|
|
1789
|
-
return object.map((element) => uncapitalizeKeys(element));
|
|
1790
|
-
}
|
|
1791
|
-
if (object && typeof object === "object") {
|
|
1792
|
-
const newObject = {};
|
|
1793
|
-
for (const [key, value] of Object.entries(object)) {
|
|
1794
|
-
newObject[uncapitalize(key)] = uncapitalizeKeys(value);
|
|
1795
|
-
}
|
|
1796
|
-
return newObject;
|
|
1797
|
-
}
|
|
1798
|
-
return object;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
// ../xml/src/lib/parsers/parse-xml.ts
|
|
1802
|
-
var import_fast_xml_parser = __toESM(require_fxp(), 1);
|
|
1803
|
-
function parseXMLSync(text, options) {
|
|
1804
|
-
if (options?._parser && options._parser !== "fast-xml-parser") {
|
|
1805
|
-
throw new Error(options?._parser);
|
|
1806
|
-
}
|
|
1807
|
-
const fastXMLOptions = {
|
|
1808
|
-
allowBooleanAttributes: true,
|
|
1809
|
-
ignoreDeclaration: true,
|
|
1810
|
-
removeNSPrefix: options?.removeNSPrefix,
|
|
1811
|
-
textNodeName: options?.textNodeName,
|
|
1812
|
-
isArray: (name, jpath, isLeafNode, isAttribute) => {
|
|
1813
|
-
const array = Boolean(options?.arrayPaths?.some((path) => jpath === path));
|
|
1814
|
-
return array;
|
|
1815
|
-
},
|
|
1816
|
-
...options?._fastXML
|
|
1817
|
-
};
|
|
1818
|
-
const xml = fastParseXML(text, fastXMLOptions);
|
|
1819
|
-
return options?.uncapitalizeKeys ? uncapitalizeKeys(xml) : xml;
|
|
1820
|
-
}
|
|
1821
|
-
function fastParseXML(text, options) {
|
|
1822
|
-
const parser = new import_fast_xml_parser.XMLParser({
|
|
1823
|
-
ignoreAttributes: false,
|
|
1824
|
-
attributeNamePrefix: "",
|
|
1825
|
-
...options
|
|
1826
|
-
});
|
|
1827
|
-
const parsedXML = parser.parse(text);
|
|
1828
|
-
return parsedXML;
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
// ../xml/src/xml-loader.ts
|
|
1832
|
-
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1833
|
-
var XMLLoader = {
|
|
1834
|
-
name: "XML",
|
|
1835
|
-
id: "xml",
|
|
1836
|
-
module: "xml",
|
|
1837
|
-
version: VERSION,
|
|
1838
|
-
worker: false,
|
|
1839
|
-
extensions: ["xml"],
|
|
1840
|
-
mimeTypes: ["application/xml", "text/xml"],
|
|
1841
|
-
testText: testXMLFile,
|
|
1842
|
-
options: {
|
|
1843
|
-
xml: {
|
|
1844
|
-
_parser: "fast-xml-parser",
|
|
1845
|
-
uncapitalizeKeys: false,
|
|
1846
|
-
removeNSPrefix: false,
|
|
1847
|
-
textNodeName: "value",
|
|
1848
|
-
arrayPaths: []
|
|
1849
|
-
}
|
|
1850
|
-
},
|
|
1851
|
-
parse: async (arrayBuffer, options) => parseXMLSync(new TextDecoder().decode(arrayBuffer), {
|
|
1852
|
-
...XMLLoader.options.xml,
|
|
1853
|
-
...options?.xml
|
|
1854
|
-
}),
|
|
1855
|
-
parseTextSync: (text, options) => parseXMLSync(text, {
|
|
1856
|
-
...XMLLoader.options.xml,
|
|
1857
|
-
...options?.xml
|
|
1858
|
-
})
|
|
1859
|
-
};
|
|
1860
|
-
function testXMLFile(text) {
|
|
1861
|
-
return text.startsWith("<?xml");
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
1865
|
-
function assert(condition, message) {
|
|
1866
|
-
if (!condition) {
|
|
1867
|
-
throw new Error(message || "loader assertion failed.");
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
1872
|
-
var globals = {
|
|
1873
|
-
self: typeof self !== "undefined" && self,
|
|
1874
|
-
window: typeof window !== "undefined" && window,
|
|
1875
|
-
global: typeof global !== "undefined" && global,
|
|
1876
|
-
document: typeof document !== "undefined" && document
|
|
1877
|
-
};
|
|
1878
|
-
var self_ = globals.self || globals.window || globals.global || {};
|
|
1879
|
-
var window_ = globals.window || globals.self || globals.global || {};
|
|
1880
|
-
var global_ = globals.global || globals.self || globals.window || {};
|
|
1881
|
-
var document_ = globals.document || {};
|
|
1882
|
-
var isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
|
|
1883
|
-
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
1884
|
-
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
1885
|
-
|
|
1886
|
-
// ../loader-utils/src/lib/option-utils/merge-loader-options.ts
|
|
1887
|
-
function mergeLoaderOptions(baseOptions, newOptions) {
|
|
1888
|
-
return mergeOptionsRecursively(baseOptions || {}, newOptions);
|
|
1889
|
-
}
|
|
1890
|
-
function mergeOptionsRecursively(baseOptions, newOptions) {
|
|
1891
|
-
const options = {
|
|
1892
|
-
...baseOptions
|
|
1893
|
-
};
|
|
1894
|
-
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
1895
|
-
if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
|
|
1896
|
-
options[key] = mergeOptionsRecursively(options[key] || {}, newOptions[key]);
|
|
1897
|
-
} else {
|
|
1898
|
-
options[key] = newOptions[key];
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
return options;
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
// ../loader-utils/src/lib/sources/data-source.ts
|
|
1905
|
-
var DataSource = class {
|
|
1906
|
-
_needsRefresh = true;
|
|
1907
|
-
constructor(props) {
|
|
1908
|
-
this.props = {
|
|
1909
|
-
...props
|
|
1910
|
-
};
|
|
1911
|
-
this.loadOptions = {
|
|
1912
|
-
...props.loadOptions
|
|
1913
|
-
};
|
|
1914
|
-
this.fetch = getFetchFunction(this.loadOptions);
|
|
1915
|
-
}
|
|
1916
|
-
setProps(props) {
|
|
1917
|
-
this.props = Object.assign(this.props, props);
|
|
1918
|
-
this.setNeedsRefresh();
|
|
1919
|
-
}
|
|
1920
|
-
setNeedsRefresh() {
|
|
1921
|
-
this._needsRefresh = true;
|
|
1922
|
-
}
|
|
1923
|
-
getNeedsRefresh(clear = true) {
|
|
1924
|
-
const needsRefresh = this._needsRefresh;
|
|
1925
|
-
if (clear) {
|
|
1926
|
-
this._needsRefresh = false;
|
|
1927
|
-
}
|
|
1928
|
-
return needsRefresh;
|
|
1929
|
-
}
|
|
1930
|
-
};
|
|
1931
|
-
function getFetchFunction(options) {
|
|
1932
|
-
const fetchFunction = options?.fetch;
|
|
1933
|
-
if (fetchFunction && typeof fetchFunction === "function") {
|
|
1934
|
-
return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
|
|
1935
|
-
}
|
|
1936
|
-
const fetchOptions = options?.fetch;
|
|
1937
|
-
if (fetchOptions && typeof fetchOptions !== "function") {
|
|
1938
|
-
return (url) => fetch(url, fetchOptions);
|
|
1939
|
-
}
|
|
1940
|
-
return (url) => fetch(url);
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
// ../loader-utils/src/lib/sources/image-source.ts
|
|
1944
|
-
var ImageSource = class extends DataSource {
|
|
1945
|
-
};
|
|
1946
|
-
__publicField(ImageSource, "type", "template");
|
|
1947
|
-
__publicField(ImageSource, "testURL", (url) => false);
|
|
1948
|
-
|
|
1949
|
-
// ../xml/src/lib/xml-utils/xml-utils.ts
|
|
1950
|
-
function convertXMLValueToArray(xmlValue) {
|
|
1951
|
-
if (Array.isArray(xmlValue)) {
|
|
1952
|
-
return xmlValue;
|
|
1953
|
-
}
|
|
1954
|
-
if (xmlValue && typeof xmlValue === "object" && xmlValue["0"]) {
|
|
1955
|
-
}
|
|
1956
|
-
if (xmlValue) {
|
|
1957
|
-
return [xmlValue];
|
|
1958
|
-
}
|
|
1959
|
-
return [];
|
|
1960
|
-
}
|
|
1961
|
-
function convertXMLFieldToArrayInPlace(xml, key) {
|
|
1962
|
-
xml[key] = convertXMLValueToArray(xml[key]);
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
// src/lib/parsers/csw/parse-exception-report.ts
|
|
1966
|
-
function parseExceptionReport(parsedXML) {
|
|
1967
|
-
const exceptionReport = parsedXML.exceptionReport;
|
|
1968
|
-
if (!exceptionReport) {
|
|
1969
|
-
return;
|
|
1970
|
-
}
|
|
1971
|
-
const errorMessage = exceptionReport.exception?.exceptionText || exceptionReport.exception?.exceptionCode || exceptionReport.exception?.locator || "server error";
|
|
1972
|
-
throw new Error(`Catalog Server: ${errorMessage}`);
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
// src/lib/parsers/csw/parse-csw-capabilities.ts
|
|
1976
|
-
function parseCSWCapabilities(text, options) {
|
|
1977
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, {
|
|
1978
|
-
...options,
|
|
1979
|
-
xml: {
|
|
1980
|
-
...options?.xml,
|
|
1981
|
-
removeNSPrefix: true,
|
|
1982
|
-
uncapitalizeKeys: true
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
parseExceptionReport(parsedXML);
|
|
1986
|
-
const xmlCapabilities = parsedXML.capabilities || parsedXML;
|
|
1987
|
-
return xmlCapabilities;
|
|
1988
|
-
}
|
|
1989
|
-
|
|
1990
|
-
// src/csw-capabilities-loader.ts
|
|
1991
|
-
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1992
|
-
var CSWCapabilitiesLoader = {
|
|
1993
|
-
id: "csw-capabilities",
|
|
1994
|
-
name: "CSW Capabilities",
|
|
1995
|
-
module: "wms",
|
|
1996
|
-
version: VERSION2,
|
|
1997
|
-
worker: false,
|
|
1998
|
-
extensions: ["xml"],
|
|
1999
|
-
mimeTypes: ["application/vnd.ogc.csw_xml", "application/xml", "text/xml"],
|
|
2000
|
-
testText: testXMLFile2,
|
|
2001
|
-
options: {
|
|
2002
|
-
csw: {}
|
|
2003
|
-
},
|
|
2004
|
-
parse: async (arrayBuffer, options) => parseCSWCapabilities(new TextDecoder().decode(arrayBuffer), options),
|
|
2005
|
-
parseTextSync: (text, options) => parseCSWCapabilities(text, options)
|
|
2006
|
-
};
|
|
2007
|
-
function testXMLFile2(text) {
|
|
2008
|
-
return text.startsWith("<?xml");
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
// src/lib/parsers/csw/parse-csw-domain.ts
|
|
2012
|
-
function parseCSWDomain(text, options) {
|
|
2013
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, {
|
|
2014
|
-
...options,
|
|
2015
|
-
xml: {
|
|
2016
|
-
...options?.xml,
|
|
2017
|
-
removeNSPrefix: true,
|
|
2018
|
-
uncapitalizeKeys: true,
|
|
2019
|
-
arrayPaths: ["GetDomainResponse.DomainValues", "GetDomainResponse.DomainValues.ListOfValues.value"]
|
|
2020
|
-
}
|
|
2021
|
-
});
|
|
2022
|
-
parseExceptionReport(parsedXML);
|
|
2023
|
-
const xmlDomain = parsedXML.getDomainResponse;
|
|
2024
|
-
for (const domainValue of xmlDomain.domainValues) {
|
|
2025
|
-
domainValue.values = domainValue.listOfValues?.value;
|
|
2026
|
-
delete domainValue.listOfValues;
|
|
2027
|
-
}
|
|
2028
|
-
return xmlDomain;
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
// src/csw-domain-loader.ts
|
|
2032
|
-
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2033
|
-
var CSWDomainLoader = {
|
|
2034
|
-
id: "csw-domain",
|
|
2035
|
-
name: "CSW Domain",
|
|
2036
|
-
module: "wms",
|
|
2037
|
-
version: VERSION3,
|
|
2038
|
-
worker: false,
|
|
2039
|
-
extensions: ["xml"],
|
|
2040
|
-
mimeTypes: ["application/vnd.ogc.csw_xml", "application/xml", "text/xml"],
|
|
2041
|
-
testText: testXMLFile3,
|
|
2042
|
-
options: {
|
|
2043
|
-
csw: {}
|
|
2044
|
-
},
|
|
2045
|
-
parse: async (arrayBuffer, options) => parseCSWDomain(new TextDecoder().decode(arrayBuffer), options),
|
|
2046
|
-
parseTextSync: (text, options) => parseCSWDomain(text, options)
|
|
2047
|
-
};
|
|
2048
|
-
function testXMLFile3(text) {
|
|
2049
|
-
return text.startsWith("<?xml");
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
// src/lib/parsers/csw/parse-csw-records.ts
|
|
2053
|
-
function parseCSWRecords(text, options) {
|
|
2054
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, {
|
|
2055
|
-
...options,
|
|
2056
|
-
xml: {
|
|
2057
|
-
...options?.xml,
|
|
2058
|
-
removeNSPrefix: true,
|
|
2059
|
-
uncapitalizeKeys: true,
|
|
2060
|
-
arrayPaths: [],
|
|
2061
|
-
_fastXML: {
|
|
2062
|
-
...options?.xml?._fastXML,
|
|
2063
|
-
parseAttributeValue: true
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
});
|
|
2067
|
-
parseExceptionReport(parsedXML);
|
|
2068
|
-
const xmlRecords = parsedXML.getRecordsResponse;
|
|
2069
|
-
const elementSet = xmlRecords.searchResults.elementSet;
|
|
2070
|
-
const recordsFieldName = `${elementSet}Record`;
|
|
2071
|
-
xmlRecords.records = xmlRecords.searchResults[recordsFieldName];
|
|
2072
|
-
delete xmlRecords.searchResults[recordsFieldName];
|
|
2073
|
-
convertXMLFieldToArrayInPlace(xmlRecords, "records");
|
|
2074
|
-
for (const record of xmlRecords.records) {
|
|
2075
|
-
record.boundingBoxes = record.boundingBox;
|
|
2076
|
-
delete record.boundingBox;
|
|
2077
|
-
convertXMLFieldToArrayInPlace(record, "boundingBoxes");
|
|
2078
|
-
for (const boundingBox of record.boundingBoxes) {
|
|
2079
|
-
boundingBox.value = [boundingBox.upperCorner[0], boundingBox.upperCorner[1], boundingBox.lowerCorner[0], boundingBox.lowerCorner[1]];
|
|
2080
|
-
delete boundingBox.upperCorner;
|
|
2081
|
-
delete boundingBox.lowerCorner;
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
return xmlRecords;
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
// src/csw-records-loader.ts
|
|
2088
|
-
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2089
|
-
var CSWRecordsLoader = {
|
|
2090
|
-
id: "csw-records",
|
|
2091
|
-
name: "CSW Records",
|
|
2092
|
-
module: "wms",
|
|
2093
|
-
version: VERSION4,
|
|
2094
|
-
worker: false,
|
|
2095
|
-
extensions: ["xml"],
|
|
2096
|
-
mimeTypes: ["application/vnd.ogc.csw_xml", "application/xml", "text/xml"],
|
|
2097
|
-
testText: testXMLFile4,
|
|
2098
|
-
options: {
|
|
2099
|
-
csw: {}
|
|
2100
|
-
},
|
|
2101
|
-
parse: async (arrayBuffer, options) => parseCSWRecords(new TextDecoder().decode(arrayBuffer), options),
|
|
2102
|
-
parseTextSync: (text, options) => parseCSWRecords(text, options)
|
|
2103
|
-
};
|
|
2104
|
-
function testXMLFile4(text) {
|
|
2105
|
-
return text.startsWith("<?xml");
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
// src/lib/parsers/wms/parse-wms-error.ts
|
|
2109
|
-
function parseWMSError(text, options) {
|
|
2110
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, options);
|
|
2111
|
-
const serviceExceptionXML = parsedXML?.ServiceExceptionReport?.ServiceException || parsedXML?.["ogc:ServiceExceptionReport"]?.["ogc:ServiceException"];
|
|
2112
|
-
const message = typeof serviceExceptionXML === "string" ? serviceExceptionXML : serviceExceptionXML.value || serviceExceptionXML.code || "Unknown error";
|
|
2113
|
-
return message;
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
// src/wms-error-loader.ts
|
|
2117
|
-
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2118
|
-
var WMSErrorLoader = {
|
|
2119
|
-
id: "wms-error",
|
|
2120
|
-
name: "WMS Error",
|
|
2121
|
-
module: "wms",
|
|
2122
|
-
version: VERSION5,
|
|
2123
|
-
worker: false,
|
|
2124
|
-
extensions: ["xml"],
|
|
2125
|
-
mimeTypes: ["application/vnd.ogc.se_xml", "application/xml", "text/xml"],
|
|
2126
|
-
testText: testXMLFile5,
|
|
2127
|
-
options: {
|
|
2128
|
-
wms: {
|
|
2129
|
-
throwOnError: false
|
|
2130
|
-
}
|
|
2131
|
-
},
|
|
2132
|
-
parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
|
|
2133
|
-
parseSync: (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
|
|
2134
|
-
parseTextSync: (text, options) => parseTextSync(text, options)
|
|
2135
|
-
};
|
|
2136
|
-
function testXMLFile5(text) {
|
|
2137
|
-
return text.startsWith("<?xml");
|
|
2138
|
-
}
|
|
2139
|
-
function parseTextSync(text, options) {
|
|
2140
|
-
const wmsOptions = {
|
|
2141
|
-
...WMSErrorLoader.options.wms,
|
|
2142
|
-
...options?.wms
|
|
2143
|
-
};
|
|
2144
|
-
const error = parseWMSError(text, wmsOptions);
|
|
2145
|
-
const message = wmsOptions.minimalErrors ? error : `WMS Service error: ${error}`;
|
|
2146
|
-
if (wmsOptions.throwOnError) {
|
|
2147
|
-
throw new Error(message);
|
|
2148
|
-
}
|
|
2149
|
-
return message;
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
|
-
// src/lib/parsers/xml/parse-xml-helpers.ts
|
|
2153
|
-
function getXMLArray(xmlValue) {
|
|
2154
|
-
if (Array.isArray(xmlValue)) {
|
|
2155
|
-
return xmlValue;
|
|
2156
|
-
}
|
|
2157
|
-
if (xmlValue) {
|
|
2158
|
-
return [xmlValue];
|
|
2159
|
-
}
|
|
2160
|
-
return [];
|
|
2161
|
-
}
|
|
2162
|
-
function getXMLStringArray(xmlValue) {
|
|
2163
|
-
const xmlArray = getXMLArray(xmlValue);
|
|
2164
|
-
if (xmlArray.length > 0 && xmlArray.every((_) => typeof _ === "string")) {
|
|
2165
|
-
return xmlArray;
|
|
2166
|
-
}
|
|
2167
|
-
return [];
|
|
2168
|
-
}
|
|
2169
|
-
function getXMLFloat(xmlValue, defaultValue = void 0) {
|
|
2170
|
-
switch (typeof xmlValue) {
|
|
2171
|
-
case "number":
|
|
2172
|
-
return xmlValue;
|
|
2173
|
-
case "string":
|
|
2174
|
-
return parseFloat(xmlValue);
|
|
2175
|
-
default:
|
|
2176
|
-
return void 0;
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
function getXMLInteger(xmlValue, defaultValue = void 0) {
|
|
2180
|
-
switch (typeof xmlValue) {
|
|
2181
|
-
case "number":
|
|
2182
|
-
return xmlValue;
|
|
2183
|
-
case "string":
|
|
2184
|
-
return parseInt(xmlValue, 10);
|
|
2185
|
-
default:
|
|
2186
|
-
return void 0;
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
function getXMLBoolean(xmlValue) {
|
|
2190
|
-
switch (xmlValue) {
|
|
2191
|
-
case "true":
|
|
2192
|
-
return true;
|
|
2193
|
-
case "false":
|
|
2194
|
-
return false;
|
|
2195
|
-
case "1":
|
|
2196
|
-
return true;
|
|
2197
|
-
case "0":
|
|
2198
|
-
return false;
|
|
2199
|
-
default:
|
|
2200
|
-
return false;
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
|
|
2204
|
-
// src/lib/parsers/wms/parse-wms-capabilities.ts
|
|
2205
|
-
function parseWMSCapabilities(xmlText, options) {
|
|
2206
|
-
const parsedXML = XMLLoader.parseTextSync?.(xmlText, options);
|
|
2207
|
-
const xmlCapabilities = parsedXML.WMT_MS_Capabilities || parsedXML.WMS_Capabilities || parsedXML;
|
|
2208
|
-
const capabilities = extractCapabilities(xmlCapabilities);
|
|
2209
|
-
if (options?.inheritedLayerProps) {
|
|
2210
|
-
for (const layer of capabilities.layers) {
|
|
2211
|
-
addInheritedLayerProps(layer, null);
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
if (options?.includeRawData || options?.raw) {
|
|
2215
|
-
capabilities.raw = xmlCapabilities;
|
|
2216
|
-
}
|
|
2217
|
-
if (options?.includeXMLText) {
|
|
2218
|
-
capabilities.xml = xmlText;
|
|
2219
|
-
}
|
|
2220
|
-
return capabilities;
|
|
2221
|
-
}
|
|
2222
|
-
function extractCapabilities(xml) {
|
|
2223
|
-
const capabilities = {
|
|
2224
|
-
version: String(xml.version || ""),
|
|
2225
|
-
name: String(xml.Service?.Name || "unnamed"),
|
|
2226
|
-
title: xml.Service?.Title ? String(xml.Service?.Title) : void 0,
|
|
2227
|
-
abstract: xml.Service?.Abstract ? String(xml.Service?.Abstract) : void 0,
|
|
2228
|
-
keywords: getXMLStringArray(xml.Service?.KeywordList?.Keyword),
|
|
2229
|
-
fees: xml.Service?.Fees ? JSON.stringify(xml.Service?.Fees) : void 0,
|
|
2230
|
-
accessConstraints: xml.Service?.AccessConstraints ? JSON.stringify(xml.Service?.AccessConstraints) : void 0,
|
|
2231
|
-
layerLimit: getXMLInteger(xml.Service?.LayerLimit),
|
|
2232
|
-
maxWidth: getXMLInteger(xml.Service?.maxWidth),
|
|
2233
|
-
maxHeight: getXMLInteger(xml.Service?.maxHeight),
|
|
2234
|
-
layers: [],
|
|
2235
|
-
requests: extractRequests(xml.Capability?.Request),
|
|
2236
|
-
exceptions: extractExceptions(xml.Exception)
|
|
2237
|
-
};
|
|
2238
|
-
const xmlLayers = getXMLArray(xml.Capability?.Layer);
|
|
2239
|
-
for (const xmlSubLayer of xmlLayers) {
|
|
2240
|
-
capabilities.layers.push(extractLayer(xmlSubLayer));
|
|
2241
|
-
}
|
|
2242
|
-
for (const [key, value] of Object.entries(capabilities)) {
|
|
2243
|
-
if (value === void 0) {
|
|
2244
|
-
delete capabilities[key];
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
return capabilities;
|
|
2248
|
-
}
|
|
2249
|
-
function extractRequests(xmlRequests) {
|
|
2250
|
-
const requests = {};
|
|
2251
|
-
for (const [name, xmlRequest] of Object.entries(xmlRequests || {})) {
|
|
2252
|
-
const mimeTypes = getXMLStringArray(xmlRequest?.Format);
|
|
2253
|
-
requests[name] = {
|
|
2254
|
-
mimeTypes
|
|
2255
|
-
};
|
|
2256
|
-
}
|
|
2257
|
-
return requests;
|
|
2258
|
-
}
|
|
2259
|
-
function extractExceptions(xmlException) {
|
|
2260
|
-
const xmlExceptionFormats = getXMLArray(xmlException?.Format);
|
|
2261
|
-
if (xmlExceptionFormats.length > 0) {
|
|
2262
|
-
return {
|
|
2263
|
-
mimeTypes: getXMLStringArray(xmlException)
|
|
2264
|
-
};
|
|
2265
|
-
}
|
|
2266
|
-
return void 0;
|
|
2267
|
-
}
|
|
2268
|
-
function extractLayer(xmlLayer) {
|
|
2269
|
-
const layer = {
|
|
2270
|
-
title: String(xmlLayer?.Title || ""),
|
|
2271
|
-
name: xmlLayer?.Name && String(xmlLayer?.Name),
|
|
2272
|
-
abstract: xmlLayer?.Name && String(xmlLayer?.Abstract),
|
|
2273
|
-
keywords: getXMLStringArray(xmlLayer.KeywordList?.Keyword)
|
|
2274
|
-
};
|
|
2275
|
-
const crs = xmlLayer?.CRS || xmlLayer?.SRS;
|
|
2276
|
-
if (crs && Array.isArray(crs) && crs.every((_) => typeof _ === "string")) {
|
|
2277
|
-
layer.crs = crs;
|
|
2278
|
-
}
|
|
2279
|
-
let geographicBoundingBox = xmlLayer?.EX_GeographicBoundingBox && extractEXBoundingBox(xmlLayer?.EX_GeographicBoundingBox);
|
|
2280
|
-
if (geographicBoundingBox) {
|
|
2281
|
-
layer.geographicBoundingBox = geographicBoundingBox;
|
|
2282
|
-
}
|
|
2283
|
-
geographicBoundingBox = xmlLayer?.LatLonBoundingBox && extractLatLonBoundingBox(xmlLayer?.LatLonBoundingBox);
|
|
2284
|
-
if (geographicBoundingBox) {
|
|
2285
|
-
layer.geographicBoundingBox = geographicBoundingBox;
|
|
2286
|
-
}
|
|
2287
|
-
const boundingBoxes = xmlLayer?.BoundingBox && extractWMSBoundingBoxes(xmlLayer?.BoundingBox);
|
|
2288
|
-
if (boundingBoxes && boundingBoxes.length > 0) {
|
|
2289
|
-
layer.boundingBoxes = boundingBoxes;
|
|
2290
|
-
}
|
|
2291
|
-
const xmlDimensions = getXMLArray(xmlLayer?.Dimension);
|
|
2292
|
-
const dimensions = xmlDimensions.map((xml) => extractDimension(xml));
|
|
2293
|
-
if (dimensions.length) {
|
|
2294
|
-
layer.dimensions = dimensions;
|
|
2295
|
-
}
|
|
2296
|
-
if (xmlLayer?.opaque) {
|
|
2297
|
-
layer.opaque = getXMLBoolean(xmlLayer?.opaque);
|
|
2298
|
-
}
|
|
2299
|
-
if (xmlLayer?.cascaded) {
|
|
2300
|
-
layer.cascaded = getXMLBoolean(xmlLayer?.cascaded);
|
|
2301
|
-
}
|
|
2302
|
-
if (xmlLayer?.queryable) {
|
|
2303
|
-
layer.queryable = getXMLBoolean(xmlLayer?.queryable);
|
|
2304
|
-
}
|
|
2305
|
-
const xmlLayers = getXMLArray(xmlLayer?.Layer);
|
|
2306
|
-
const layers = [];
|
|
2307
|
-
for (const xmlSubLayer of xmlLayers) {
|
|
2308
|
-
layers.push(extractLayer(xmlSubLayer));
|
|
2309
|
-
}
|
|
2310
|
-
if (layers.length > 0) {
|
|
2311
|
-
layer.layers = layers;
|
|
2312
|
-
}
|
|
2313
|
-
for (const [key, value] of Object.entries(layer)) {
|
|
2314
|
-
if (value === void 0) {
|
|
2315
|
-
delete layer[key];
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
return layer;
|
|
2319
|
-
}
|
|
2320
|
-
function extractEXBoundingBox(xmlBoundingBox) {
|
|
2321
|
-
const {
|
|
2322
|
-
westBoundLongitude: w,
|
|
2323
|
-
northBoundLatitude: n,
|
|
2324
|
-
eastBoundLongitude: e,
|
|
2325
|
-
southBoundLatitude: s
|
|
2326
|
-
} = xmlBoundingBox;
|
|
2327
|
-
return [[w, s], [e, n]];
|
|
2328
|
-
}
|
|
2329
|
-
function extractLatLonBoundingBox(xmlBoundingBox) {
|
|
2330
|
-
const {
|
|
2331
|
-
minx,
|
|
2332
|
-
miny,
|
|
2333
|
-
maxx,
|
|
2334
|
-
maxy
|
|
2335
|
-
} = xmlBoundingBox;
|
|
2336
|
-
return [[minx, miny], [maxx, maxy]];
|
|
2337
|
-
}
|
|
2338
|
-
function extractWMSBoundingBoxes(xmlBoundingBoxes) {
|
|
2339
|
-
const xmlBoxes = getXMLArray(xmlBoundingBoxes);
|
|
2340
|
-
return xmlBoxes.map((xmlBox) => extractWMSBoundingBox(xmlBox));
|
|
2341
|
-
}
|
|
2342
|
-
function extractWMSBoundingBox(xmlBoundingBox) {
|
|
2343
|
-
const {
|
|
2344
|
-
CRS,
|
|
2345
|
-
SRS,
|
|
2346
|
-
minx,
|
|
2347
|
-
miny,
|
|
2348
|
-
maxx,
|
|
2349
|
-
maxy,
|
|
2350
|
-
resx,
|
|
2351
|
-
resy
|
|
2352
|
-
} = xmlBoundingBox;
|
|
2353
|
-
const boundingBox = {
|
|
2354
|
-
crs: CRS || SRS,
|
|
2355
|
-
boundingBox: [[getXMLFloat(minx), getXMLFloat(miny)], [getXMLFloat(maxx), getXMLFloat(maxy)]]
|
|
2356
|
-
};
|
|
2357
|
-
if (resx) {
|
|
2358
|
-
boundingBox.xResolution = resx;
|
|
2359
|
-
}
|
|
2360
|
-
if (resy) {
|
|
2361
|
-
boundingBox.yResolution = resy;
|
|
2362
|
-
}
|
|
2363
|
-
return boundingBox;
|
|
2364
|
-
}
|
|
2365
|
-
function extractDimension(xmlDimension) {
|
|
2366
|
-
const {
|
|
2367
|
-
name,
|
|
2368
|
-
units,
|
|
2369
|
-
value: extent
|
|
2370
|
-
} = xmlDimension;
|
|
2371
|
-
const dimension = {
|
|
2372
|
-
name,
|
|
2373
|
-
units,
|
|
2374
|
-
extent
|
|
2375
|
-
};
|
|
2376
|
-
if (xmlDimension.unitSymbol) {
|
|
2377
|
-
dimension.unitSymbol = xmlDimension.unitSymbol;
|
|
2378
|
-
}
|
|
2379
|
-
if (xmlDimension.default) {
|
|
2380
|
-
dimension.defaultValue = xmlDimension.default;
|
|
2381
|
-
}
|
|
2382
|
-
if (xmlDimension.multipleValues) {
|
|
2383
|
-
dimension.multipleValues = getXMLBoolean(xmlDimension.multipleValues);
|
|
2384
|
-
}
|
|
2385
|
-
if (xmlDimension.nearestValue) {
|
|
2386
|
-
dimension.nearestValue = getXMLBoolean(xmlDimension.nearestValue);
|
|
2387
|
-
}
|
|
2388
|
-
if (xmlDimension.current) {
|
|
2389
|
-
dimension.current = getXMLBoolean(xmlDimension.current);
|
|
2390
|
-
}
|
|
2391
|
-
return dimension;
|
|
2392
|
-
}
|
|
2393
|
-
function addInheritedLayerProps(layer, parent) {
|
|
2394
|
-
if (parent?.geographicBoundingBox && !layer.geographicBoundingBox) {
|
|
2395
|
-
layer.geographicBoundingBox = [...parent.geographicBoundingBox];
|
|
2396
|
-
}
|
|
2397
|
-
if (parent?.crs && !layer.crs) {
|
|
2398
|
-
layer.crs = [...parent.crs];
|
|
2399
|
-
}
|
|
2400
|
-
if (parent?.boundingBoxes && !layer.boundingBoxes) {
|
|
2401
|
-
layer.boundingBoxes = [...parent.boundingBoxes];
|
|
2402
|
-
}
|
|
2403
|
-
if (parent?.dimensions && !layer.dimensions) {
|
|
2404
|
-
layer.dimensions = [...parent.dimensions];
|
|
2405
|
-
}
|
|
2406
|
-
for (const subLayer of layer.layers || []) {
|
|
2407
|
-
addInheritedLayerProps(subLayer, layer);
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
|
|
2411
|
-
// src/wms-capabilities-loader.ts
|
|
2412
|
-
var VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2413
|
-
var WMSCapabilitiesLoader = {
|
|
2414
|
-
id: "wms-capabilities",
|
|
2415
|
-
name: "WMS Capabilities",
|
|
2416
|
-
module: "wms",
|
|
2417
|
-
version: VERSION6,
|
|
2418
|
-
worker: false,
|
|
2419
|
-
extensions: ["xml"],
|
|
2420
|
-
mimeTypes: ["application/vnd.ogc.wms_xml", "application/xml", "text/xml"],
|
|
2421
|
-
testText: testXMLFile6,
|
|
2422
|
-
options: {
|
|
2423
|
-
wms: {}
|
|
2424
|
-
},
|
|
2425
|
-
parse: async (arrayBuffer, options) => parseWMSCapabilities(new TextDecoder().decode(arrayBuffer), options?.wms),
|
|
2426
|
-
parseTextSync: (text, options) => parseWMSCapabilities(text, options?.wms)
|
|
2427
|
-
};
|
|
2428
|
-
function testXMLFile6(text) {
|
|
2429
|
-
return text.startsWith("<?xml");
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
|
-
// src/lib/parsers/wms/parse-wms-features.ts
|
|
2433
|
-
function parseWMSFeatureInfo(text, options) {
|
|
2434
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, options);
|
|
2435
|
-
const xmlFeatureInfo = parsedXML.FeatureInfoResponse?.FIELDS || [];
|
|
2436
|
-
const xmlFeatures = Array.isArray(xmlFeatureInfo) ? xmlFeatureInfo : [xmlFeatureInfo];
|
|
2437
|
-
return {
|
|
2438
|
-
features: xmlFeatures.map((xmlFeature) => extractFeature(xmlFeature))
|
|
2439
|
-
};
|
|
2440
|
-
}
|
|
2441
|
-
function extractFeature(xmlFeature) {
|
|
2442
|
-
const xmlFields = xmlFeature || {};
|
|
2443
|
-
return {
|
|
2444
|
-
attributes: xmlFields,
|
|
2445
|
-
type: "",
|
|
2446
|
-
bounds: {
|
|
2447
|
-
bottom: 0,
|
|
2448
|
-
top: 0,
|
|
2449
|
-
left: 0,
|
|
2450
|
-
right: 0
|
|
2451
|
-
}
|
|
2452
|
-
};
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
// src/wip/wms-feature-info-loader.ts
|
|
2456
|
-
var WMSFeatureInfoLoader = {
|
|
2457
|
-
...WMSCapabilitiesLoader,
|
|
2458
|
-
id: "wms-feature-info",
|
|
2459
|
-
name: "WMS FeatureInfo",
|
|
2460
|
-
parse: async (arrayBuffer, options) => parseWMSFeatureInfo(new TextDecoder().decode(arrayBuffer), options),
|
|
2461
|
-
parseTextSync: (text, options) => parseWMSFeatureInfo(text, options)
|
|
2462
|
-
};
|
|
2463
|
-
|
|
2464
|
-
// src/lib/parsers/wms/parse-wms-layer-description.ts
|
|
2465
|
-
function parseWMSLayerDescription(text, options) {
|
|
2466
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, options);
|
|
2467
|
-
return parsedXML;
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
|
-
// src/wip/wms-layer-description-loader.ts
|
|
2471
|
-
var WMSLayerDescriptionLoader = {
|
|
2472
|
-
...WMSCapabilitiesLoader,
|
|
2473
|
-
id: "wms-layer-description",
|
|
2474
|
-
name: "WMS DescribeLayer",
|
|
2475
|
-
parse: async (arrayBuffer, options) => parseWMSLayerDescription(new TextDecoder().decode(arrayBuffer), options),
|
|
2476
|
-
parseTextSync: (text, options) => parseWMSLayerDescription(text, options)
|
|
2477
|
-
};
|
|
2478
|
-
|
|
2479
|
-
// src/wip/lib/wfs/parse-wfs-capabilities.ts
|
|
2480
|
-
function parseWFSCapabilities(text, options) {
|
|
2481
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, {
|
|
2482
|
-
...options,
|
|
2483
|
-
xml: {
|
|
2484
|
-
...options?.xml,
|
|
2485
|
-
removeNSPrefix: true,
|
|
2486
|
-
uncapitalizeKeys: true
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
const xmlCapabilities = parsedXML.Capabilities || parsedXML;
|
|
2490
|
-
return xmlCapabilities;
|
|
2491
|
-
}
|
|
2492
|
-
|
|
2493
|
-
// src/wip/wfs-capabilities-loader.ts
|
|
2494
|
-
var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2495
|
-
var WFSCapabilitiesLoader = {
|
|
2496
|
-
id: "wfs-capabilities",
|
|
2497
|
-
name: "WFS Capabilities",
|
|
2498
|
-
module: "wms",
|
|
2499
|
-
version: VERSION7,
|
|
2500
|
-
worker: false,
|
|
2501
|
-
extensions: ["xml"],
|
|
2502
|
-
mimeTypes: ["application/vnd.ogc.wfs_xml", "application/xml", "text/xml"],
|
|
2503
|
-
testText: testXMLFile7,
|
|
2504
|
-
options: {
|
|
2505
|
-
wfs: {}
|
|
2506
|
-
},
|
|
2507
|
-
parse: async (arrayBuffer, options) => parseWFSCapabilities(new TextDecoder().decode(arrayBuffer), options),
|
|
2508
|
-
parseTextSync: (text, options) => parseWFSCapabilities(text, options)
|
|
2509
|
-
};
|
|
2510
|
-
function testXMLFile7(text) {
|
|
2511
|
-
return text.startsWith("<?xml");
|
|
2512
|
-
}
|
|
2513
|
-
|
|
2514
|
-
// src/lib/parsers/gml/deep-strict-equal.ts
|
|
2515
|
-
function deepStrictEqual(actual, expected, strict) {
|
|
2516
|
-
if (actual === expected) {
|
|
2517
|
-
return true;
|
|
2518
|
-
} else if (actual instanceof Date && expected instanceof Date) {
|
|
2519
|
-
return actual.getTime() === expected.getTime();
|
|
2520
|
-
} else if (actual instanceof RegExp && expected instanceof RegExp) {
|
|
2521
|
-
return actual.source === expected.source && actual.global === expected.global && actual.multiline === expected.multiline && actual.lastIndex === expected.lastIndex && actual.ignoreCase === expected.ignoreCase;
|
|
2522
|
-
} else if ((actual === null || typeof actual !== "object") && (expected === null || typeof expected !== "object")) {
|
|
2523
|
-
return strict ? actual === expected : actual == expected;
|
|
2524
|
-
}
|
|
2525
|
-
return objEquiv(actual, expected, strict);
|
|
2526
|
-
}
|
|
2527
|
-
var pSlice = Array.prototype.slice;
|
|
2528
|
-
function isPrimitive(arg) {
|
|
2529
|
-
return arg === null || typeof arg !== "object" && typeof arg !== "function";
|
|
2530
|
-
}
|
|
2531
|
-
function isArguments(object) {
|
|
2532
|
-
return Object.prototype.toString.call(object) == "[object Arguments]";
|
|
2533
|
-
}
|
|
2534
|
-
function objEquiv(a, b, strict) {
|
|
2535
|
-
if (a === null || a === void 0 || b === null || b === void 0)
|
|
2536
|
-
return false;
|
|
2537
|
-
if (isPrimitive(a) || isPrimitive(b))
|
|
2538
|
-
return a === b;
|
|
2539
|
-
if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
|
|
2540
|
-
return false;
|
|
2541
|
-
const aIsArgs = isArguments(a);
|
|
2542
|
-
const bIsArgs = isArguments(b);
|
|
2543
|
-
if (aIsArgs && !bIsArgs || !aIsArgs && bIsArgs)
|
|
2544
|
-
return false;
|
|
2545
|
-
if (aIsArgs) {
|
|
2546
|
-
a = pSlice.call(a);
|
|
2547
|
-
b = pSlice.call(b);
|
|
2548
|
-
return deepStrictEqual(a, b, strict);
|
|
2549
|
-
}
|
|
2550
|
-
const ka = Object.keys(a);
|
|
2551
|
-
const kb = Object.keys(b);
|
|
2552
|
-
let key;
|
|
2553
|
-
let i;
|
|
2554
|
-
if (ka.length !== kb.length)
|
|
2555
|
-
return false;
|
|
2556
|
-
ka.sort();
|
|
2557
|
-
kb.sort();
|
|
2558
|
-
for (i = ka.length - 1; i >= 0; i--) {
|
|
2559
|
-
if (ka[i] !== kb[i])
|
|
2560
|
-
return false;
|
|
2561
|
-
}
|
|
2562
|
-
for (i = ka.length - 1; i >= 0; i--) {
|
|
2563
|
-
key = ka[i];
|
|
2564
|
-
if (!deepStrictEqual(a[key], b[key], strict))
|
|
2565
|
-
return false;
|
|
2566
|
-
}
|
|
2567
|
-
return true;
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
-
// ../../node_modules/@turf/clone/main.es.js
|
|
2571
|
-
function clone(geojson) {
|
|
2572
|
-
if (!geojson)
|
|
2573
|
-
throw new Error("geojson is required");
|
|
2574
|
-
switch (geojson.type) {
|
|
2575
|
-
case "Feature":
|
|
2576
|
-
return cloneFeature(geojson);
|
|
2577
|
-
case "FeatureCollection":
|
|
2578
|
-
return cloneFeatureCollection(geojson);
|
|
2579
|
-
case "Point":
|
|
2580
|
-
case "LineString":
|
|
2581
|
-
case "Polygon":
|
|
2582
|
-
case "MultiPoint":
|
|
2583
|
-
case "MultiLineString":
|
|
2584
|
-
case "MultiPolygon":
|
|
2585
|
-
case "GeometryCollection":
|
|
2586
|
-
return cloneGeometry(geojson);
|
|
2587
|
-
default:
|
|
2588
|
-
throw new Error("unknown GeoJSON type");
|
|
2589
|
-
}
|
|
2590
|
-
}
|
|
2591
|
-
function cloneFeature(geojson) {
|
|
2592
|
-
var cloned = { type: "Feature" };
|
|
2593
|
-
Object.keys(geojson).forEach(function(key) {
|
|
2594
|
-
switch (key) {
|
|
2595
|
-
case "type":
|
|
2596
|
-
case "properties":
|
|
2597
|
-
case "geometry":
|
|
2598
|
-
return;
|
|
2599
|
-
default:
|
|
2600
|
-
cloned[key] = geojson[key];
|
|
2601
|
-
}
|
|
2602
|
-
});
|
|
2603
|
-
cloned.properties = cloneProperties(geojson.properties);
|
|
2604
|
-
cloned.geometry = cloneGeometry(geojson.geometry);
|
|
2605
|
-
return cloned;
|
|
2606
|
-
}
|
|
2607
|
-
function cloneProperties(properties) {
|
|
2608
|
-
var cloned = {};
|
|
2609
|
-
if (!properties)
|
|
2610
|
-
return cloned;
|
|
2611
|
-
Object.keys(properties).forEach(function(key) {
|
|
2612
|
-
var value = properties[key];
|
|
2613
|
-
if (typeof value === "object") {
|
|
2614
|
-
if (value === null) {
|
|
2615
|
-
cloned[key] = null;
|
|
2616
|
-
} else if (value.length) {
|
|
2617
|
-
cloned[key] = value.map(function(item) {
|
|
2618
|
-
return item;
|
|
2619
|
-
});
|
|
2620
|
-
} else {
|
|
2621
|
-
cloned[key] = cloneProperties(value);
|
|
2622
|
-
}
|
|
2623
|
-
} else
|
|
2624
|
-
cloned[key] = value;
|
|
2625
|
-
});
|
|
2626
|
-
return cloned;
|
|
2627
|
-
}
|
|
2628
|
-
function cloneFeatureCollection(geojson) {
|
|
2629
|
-
var cloned = { type: "FeatureCollection" };
|
|
2630
|
-
Object.keys(geojson).forEach(function(key) {
|
|
2631
|
-
switch (key) {
|
|
2632
|
-
case "type":
|
|
2633
|
-
case "features":
|
|
2634
|
-
return;
|
|
2635
|
-
default:
|
|
2636
|
-
cloned[key] = geojson[key];
|
|
2637
|
-
}
|
|
2638
|
-
});
|
|
2639
|
-
cloned.features = geojson.features.map(function(feature2) {
|
|
2640
|
-
return cloneFeature(feature2);
|
|
2641
|
-
});
|
|
2642
|
-
return cloned;
|
|
2643
|
-
}
|
|
2644
|
-
function cloneGeometry(geometry) {
|
|
2645
|
-
var geom = { type: geometry.type };
|
|
2646
|
-
if (geometry.bbox)
|
|
2647
|
-
geom.bbox = geometry.bbox;
|
|
2648
|
-
if (geometry.type === "GeometryCollection") {
|
|
2649
|
-
geom.geometries = geometry.geometries.map(function(geom2) {
|
|
2650
|
-
return cloneGeometry(geom2);
|
|
2651
|
-
});
|
|
2652
|
-
return geom;
|
|
2653
|
-
}
|
|
2654
|
-
geom.coordinates = deepSlice(geometry.coordinates);
|
|
2655
|
-
return geom;
|
|
2656
|
-
}
|
|
2657
|
-
function deepSlice(coords) {
|
|
2658
|
-
if (typeof coords[0] !== "object") {
|
|
2659
|
-
return coords.slice();
|
|
2660
|
-
}
|
|
2661
|
-
return coords.map(function(coord) {
|
|
2662
|
-
return deepSlice(coord);
|
|
2663
|
-
});
|
|
2664
|
-
}
|
|
2665
|
-
var main_es_default = clone;
|
|
2666
|
-
|
|
2667
|
-
// ../../node_modules/@turf/helpers/main.es.js
|
|
2668
|
-
var earthRadius = 63710088e-1;
|
|
2669
|
-
var factors = {
|
|
2670
|
-
meters: earthRadius,
|
|
2671
|
-
metres: earthRadius,
|
|
2672
|
-
millimeters: earthRadius * 1e3,
|
|
2673
|
-
millimetres: earthRadius * 1e3,
|
|
2674
|
-
centimeters: earthRadius * 100,
|
|
2675
|
-
centimetres: earthRadius * 100,
|
|
2676
|
-
kilometers: earthRadius / 1e3,
|
|
2677
|
-
kilometres: earthRadius / 1e3,
|
|
2678
|
-
miles: earthRadius / 1609.344,
|
|
2679
|
-
nauticalmiles: earthRadius / 1852,
|
|
2680
|
-
inches: earthRadius * 39.37,
|
|
2681
|
-
yards: earthRadius / 1.0936,
|
|
2682
|
-
feet: earthRadius * 3.28084,
|
|
2683
|
-
radians: 1,
|
|
2684
|
-
degrees: earthRadius / 111325
|
|
2685
|
-
};
|
|
2686
|
-
var unitsFactors = {
|
|
2687
|
-
meters: 1,
|
|
2688
|
-
metres: 1,
|
|
2689
|
-
millimeters: 1e3,
|
|
2690
|
-
millimetres: 1e3,
|
|
2691
|
-
centimeters: 100,
|
|
2692
|
-
centimetres: 100,
|
|
2693
|
-
kilometers: 1 / 1e3,
|
|
2694
|
-
kilometres: 1 / 1e3,
|
|
2695
|
-
miles: 1 / 1609.344,
|
|
2696
|
-
nauticalmiles: 1 / 1852,
|
|
2697
|
-
inches: 39.37,
|
|
2698
|
-
yards: 1 / 1.0936,
|
|
2699
|
-
feet: 3.28084,
|
|
2700
|
-
radians: 1 / earthRadius,
|
|
2701
|
-
degrees: 1 / 111325
|
|
2702
|
-
};
|
|
2703
|
-
function featureCollection(features, options) {
|
|
2704
|
-
options = options || {};
|
|
2705
|
-
if (!isObject(options))
|
|
2706
|
-
throw new Error("options is invalid");
|
|
2707
|
-
var bbox = options.bbox;
|
|
2708
|
-
var id = options.id;
|
|
2709
|
-
if (!features)
|
|
2710
|
-
throw new Error("No features passed");
|
|
2711
|
-
if (!Array.isArray(features))
|
|
2712
|
-
throw new Error("features must be an Array");
|
|
2713
|
-
if (bbox)
|
|
2714
|
-
validateBBox(bbox);
|
|
2715
|
-
if (id)
|
|
2716
|
-
validateId(id);
|
|
2717
|
-
var fc = { type: "FeatureCollection" };
|
|
2718
|
-
if (id)
|
|
2719
|
-
fc.id = id;
|
|
2720
|
-
if (bbox)
|
|
2721
|
-
fc.bbox = bbox;
|
|
2722
|
-
fc.features = features;
|
|
2723
|
-
return fc;
|
|
2724
|
-
}
|
|
2725
|
-
function isNumber(num) {
|
|
2726
|
-
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
2727
|
-
}
|
|
2728
|
-
function isObject(input) {
|
|
2729
|
-
return !!input && input.constructor === Object;
|
|
2730
|
-
}
|
|
2731
|
-
function validateBBox(bbox) {
|
|
2732
|
-
if (!bbox)
|
|
2733
|
-
throw new Error("bbox is required");
|
|
2734
|
-
if (!Array.isArray(bbox))
|
|
2735
|
-
throw new Error("bbox must be an Array");
|
|
2736
|
-
if (bbox.length !== 4 && bbox.length !== 6)
|
|
2737
|
-
throw new Error("bbox must be an Array of 4 or 6 numbers");
|
|
2738
|
-
bbox.forEach(function(num) {
|
|
2739
|
-
if (!isNumber(num))
|
|
2740
|
-
throw new Error("bbox must only contain numbers");
|
|
2741
|
-
});
|
|
2742
|
-
}
|
|
2743
|
-
function validateId(id) {
|
|
2744
|
-
if (!id)
|
|
2745
|
-
throw new Error("id is required");
|
|
2746
|
-
if (["string", "number"].indexOf(typeof id) === -1)
|
|
2747
|
-
throw new Error("id must be a number or a string");
|
|
2748
|
-
}
|
|
2749
|
-
|
|
2750
|
-
// ../../node_modules/@turf/invariant/main.es.js
|
|
2751
|
-
function getCoords(coords) {
|
|
2752
|
-
if (!coords)
|
|
2753
|
-
throw new Error("coords is required");
|
|
2754
|
-
if (coords.type === "Feature" && coords.geometry !== null)
|
|
2755
|
-
return coords.geometry.coordinates;
|
|
2756
|
-
if (coords.coordinates)
|
|
2757
|
-
return coords.coordinates;
|
|
2758
|
-
if (Array.isArray(coords))
|
|
2759
|
-
return coords;
|
|
2760
|
-
throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array");
|
|
2761
|
-
}
|
|
2762
|
-
|
|
2763
|
-
// ../../node_modules/@turf/boolean-clockwise/main.es.js
|
|
2764
|
-
function booleanClockwise(line) {
|
|
2765
|
-
if (!line)
|
|
2766
|
-
throw new Error("line is required");
|
|
2767
|
-
var type = line.geometry ? line.geometry.type : line.type;
|
|
2768
|
-
if (!Array.isArray(line) && type !== "LineString")
|
|
2769
|
-
throw new Error("geometry must be a LineString");
|
|
2770
|
-
var ring = getCoords(line);
|
|
2771
|
-
var sum = 0;
|
|
2772
|
-
var i = 1;
|
|
2773
|
-
var prev, cur;
|
|
2774
|
-
while (i < ring.length) {
|
|
2775
|
-
prev = cur || ring[0];
|
|
2776
|
-
cur = ring[i];
|
|
2777
|
-
sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
|
|
2778
|
-
i++;
|
|
2779
|
-
}
|
|
2780
|
-
return sum > 0;
|
|
2781
|
-
}
|
|
2782
|
-
var main_es_default2 = booleanClockwise;
|
|
2783
|
-
|
|
2784
|
-
// ../../node_modules/@turf/meta/main.es.js
|
|
2785
|
-
function featureEach(geojson, callback) {
|
|
2786
|
-
if (geojson.type === "Feature") {
|
|
2787
|
-
callback(geojson, 0);
|
|
2788
|
-
} else if (geojson.type === "FeatureCollection") {
|
|
2789
|
-
for (var i = 0; i < geojson.features.length; i++) {
|
|
2790
|
-
if (callback(geojson.features[i], i) === false)
|
|
2791
|
-
break;
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
function geomEach(geojson, callback) {
|
|
2796
|
-
var i, j, g, geometry, stopG, geometryMaybeCollection, isGeometryCollection, featureProperties, featureBBox, featureId, featureIndex = 0, isFeatureCollection = geojson.type === "FeatureCollection", isFeature = geojson.type === "Feature", stop = isFeatureCollection ? geojson.features.length : 1;
|
|
2797
|
-
for (i = 0; i < stop; i++) {
|
|
2798
|
-
geometryMaybeCollection = isFeatureCollection ? geojson.features[i].geometry : isFeature ? geojson.geometry : geojson;
|
|
2799
|
-
featureProperties = isFeatureCollection ? geojson.features[i].properties : isFeature ? geojson.properties : {};
|
|
2800
|
-
featureBBox = isFeatureCollection ? geojson.features[i].bbox : isFeature ? geojson.bbox : void 0;
|
|
2801
|
-
featureId = isFeatureCollection ? geojson.features[i].id : isFeature ? geojson.id : void 0;
|
|
2802
|
-
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;
|
|
2803
|
-
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
|
|
2804
|
-
for (g = 0; g < stopG; g++) {
|
|
2805
|
-
geometry = isGeometryCollection ? geometryMaybeCollection.geometries[g] : geometryMaybeCollection;
|
|
2806
|
-
if (geometry === null) {
|
|
2807
|
-
if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false)
|
|
2808
|
-
return false;
|
|
2809
|
-
continue;
|
|
2810
|
-
}
|
|
2811
|
-
switch (geometry.type) {
|
|
2812
|
-
case "Point":
|
|
2813
|
-
case "LineString":
|
|
2814
|
-
case "MultiPoint":
|
|
2815
|
-
case "Polygon":
|
|
2816
|
-
case "MultiLineString":
|
|
2817
|
-
case "MultiPolygon": {
|
|
2818
|
-
if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false)
|
|
2819
|
-
return false;
|
|
2820
|
-
break;
|
|
2821
|
-
}
|
|
2822
|
-
case "GeometryCollection": {
|
|
2823
|
-
for (j = 0; j < geometry.geometries.length; j++) {
|
|
2824
|
-
if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false)
|
|
2825
|
-
return false;
|
|
2826
|
-
}
|
|
2827
|
-
break;
|
|
2828
|
-
}
|
|
2829
|
-
default:
|
|
2830
|
-
throw new Error("Unknown Geometry Type");
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
featureIndex++;
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
// ../../node_modules/@turf/rewind/main.es.js
|
|
2838
|
-
function rewind(geojson, options) {
|
|
2839
|
-
options = options || {};
|
|
2840
|
-
if (!isObject(options))
|
|
2841
|
-
throw new Error("options is invalid");
|
|
2842
|
-
var reverse = options.reverse || false;
|
|
2843
|
-
var mutate = options.mutate || false;
|
|
2844
|
-
if (!geojson)
|
|
2845
|
-
throw new Error("<geojson> is required");
|
|
2846
|
-
if (typeof reverse !== "boolean")
|
|
2847
|
-
throw new Error("<reverse> must be a boolean");
|
|
2848
|
-
if (typeof mutate !== "boolean")
|
|
2849
|
-
throw new Error("<mutate> must be a boolean");
|
|
2850
|
-
if (mutate === false)
|
|
2851
|
-
geojson = main_es_default(geojson);
|
|
2852
|
-
var results = [];
|
|
2853
|
-
switch (geojson.type) {
|
|
2854
|
-
case "GeometryCollection":
|
|
2855
|
-
geomEach(geojson, function(geometry) {
|
|
2856
|
-
rewindFeature(geometry, reverse);
|
|
2857
|
-
});
|
|
2858
|
-
return geojson;
|
|
2859
|
-
case "FeatureCollection":
|
|
2860
|
-
featureEach(geojson, function(feature2) {
|
|
2861
|
-
featureEach(rewindFeature(feature2, reverse), function(result) {
|
|
2862
|
-
results.push(result);
|
|
2863
|
-
});
|
|
2864
|
-
});
|
|
2865
|
-
return featureCollection(results);
|
|
2866
|
-
}
|
|
2867
|
-
return rewindFeature(geojson, reverse);
|
|
2868
|
-
}
|
|
2869
|
-
function rewindFeature(geojson, reverse) {
|
|
2870
|
-
var type = geojson.type === "Feature" ? geojson.geometry.type : geojson.type;
|
|
2871
|
-
switch (type) {
|
|
2872
|
-
case "GeometryCollection":
|
|
2873
|
-
geomEach(geojson, function(geometry) {
|
|
2874
|
-
rewindFeature(geometry, reverse);
|
|
2875
|
-
});
|
|
2876
|
-
return geojson;
|
|
2877
|
-
case "LineString":
|
|
2878
|
-
rewindLineString(getCoords(geojson), reverse);
|
|
2879
|
-
return geojson;
|
|
2880
|
-
case "Polygon":
|
|
2881
|
-
rewindPolygon(getCoords(geojson), reverse);
|
|
2882
|
-
return geojson;
|
|
2883
|
-
case "MultiLineString":
|
|
2884
|
-
getCoords(geojson).forEach(function(lineCoords) {
|
|
2885
|
-
rewindLineString(lineCoords, reverse);
|
|
2886
|
-
});
|
|
2887
|
-
return geojson;
|
|
2888
|
-
case "MultiPolygon":
|
|
2889
|
-
getCoords(geojson).forEach(function(lineCoords) {
|
|
2890
|
-
rewindPolygon(lineCoords, reverse);
|
|
2891
|
-
});
|
|
2892
|
-
return geojson;
|
|
2893
|
-
case "Point":
|
|
2894
|
-
case "MultiPoint":
|
|
2895
|
-
return geojson;
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
function rewindLineString(coords, reverse) {
|
|
2899
|
-
if (main_es_default2(coords) === reverse)
|
|
2900
|
-
coords.reverse();
|
|
2901
|
-
}
|
|
2902
|
-
function rewindPolygon(coords, reverse) {
|
|
2903
|
-
if (main_es_default2(coords[0]) !== reverse) {
|
|
2904
|
-
coords[0].reverse();
|
|
2905
|
-
}
|
|
2906
|
-
for (var i = 1; i < coords.length; i++) {
|
|
2907
|
-
if (main_es_default2(coords[i]) === reverse) {
|
|
2908
|
-
coords[i].reverse();
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
var main_es_default3 = rewind;
|
|
2913
|
-
|
|
2914
|
-
// src/lib/parsers/gml/parse-gml.ts
|
|
2915
|
-
function noTransform(...coords) {
|
|
2916
|
-
return coords;
|
|
2917
|
-
}
|
|
2918
|
-
function parseGML(text, options) {
|
|
2919
|
-
const parsedXML = XMLLoader.parseTextSync?.(text, options);
|
|
2920
|
-
options = {
|
|
2921
|
-
transformCoords: noTransform,
|
|
2922
|
-
stride: 2,
|
|
2923
|
-
...options
|
|
2924
|
-
};
|
|
2925
|
-
const context = createChildContext(parsedXML, options, {});
|
|
2926
|
-
return parseGMLToGeometry(parsedXML, options, context);
|
|
2927
|
-
}
|
|
2928
|
-
function parseGMLToGeometry(inputXML, options, context) {
|
|
2929
|
-
const childContext = createChildContext(inputXML, options, context);
|
|
2930
|
-
let geometry = null;
|
|
2931
|
-
const [name, xml] = getFirstKeyValue(inputXML);
|
|
2932
|
-
switch (name) {
|
|
2933
|
-
case "gml:LineString":
|
|
2934
|
-
geometry = {
|
|
2935
|
-
type: "LineString",
|
|
2936
|
-
coordinates: parseLinearRingOrLineString(xml, options, childContext)
|
|
2937
|
-
};
|
|
2938
|
-
break;
|
|
2939
|
-
case "gml:Polygon":
|
|
2940
|
-
case "gml:Rectangle":
|
|
2941
|
-
geometry = {
|
|
2942
|
-
type: "Polygon",
|
|
2943
|
-
coordinates: parsePolygonOrRectangle(xml, options, childContext)
|
|
2944
|
-
};
|
|
2945
|
-
break;
|
|
2946
|
-
case "gml:Surface":
|
|
2947
|
-
geometry = {
|
|
2948
|
-
type: "MultiPolygon",
|
|
2949
|
-
coordinates: parseSurface(xml, options, childContext)
|
|
2950
|
-
};
|
|
2951
|
-
break;
|
|
2952
|
-
case "gml:MultiSurface":
|
|
2953
|
-
geometry = {
|
|
2954
|
-
type: "MultiPolygon",
|
|
2955
|
-
coordinates: parseMultiSurface(xml, options, childContext)
|
|
2956
|
-
};
|
|
2957
|
-
break;
|
|
2958
|
-
default:
|
|
2959
|
-
return null;
|
|
2960
|
-
}
|
|
2961
|
-
return main_es_default3(geometry, {
|
|
2962
|
-
mutate: true
|
|
2963
|
-
});
|
|
2964
|
-
}
|
|
2965
|
-
function parseCoords(s, options, context) {
|
|
2966
|
-
const stride = context.srsDimension || options.stride || 2;
|
|
2967
|
-
const coords = s.replace(/\s+/g, " ").trim().split(" ");
|
|
2968
|
-
if (coords.length === 0 || coords.length % stride !== 0) {
|
|
2969
|
-
throw new Error(`invalid coordinates list (stride ${stride})`);
|
|
2970
|
-
}
|
|
2971
|
-
const points = [];
|
|
2972
|
-
for (let i = 0; i < coords.length - 1; i += stride) {
|
|
2973
|
-
const point2 = coords.slice(i, i + stride).map(parseFloat);
|
|
2974
|
-
points.push(options.transformCoords?.(...point2) || point2);
|
|
2975
|
-
}
|
|
2976
|
-
return points;
|
|
2977
|
-
}
|
|
2978
|
-
function parsePosList(xml, options, context) {
|
|
2979
|
-
const childContext = createChildContext(xml, options, context);
|
|
2980
|
-
const coords = textOf(xml);
|
|
2981
|
-
if (!coords) {
|
|
2982
|
-
throw new Error("invalid gml:posList element");
|
|
2983
|
-
}
|
|
2984
|
-
return parseCoords(coords, options, childContext);
|
|
2985
|
-
}
|
|
2986
|
-
function parsePos(xml, options, context) {
|
|
2987
|
-
const childContext = createChildContext(xml, options, context);
|
|
2988
|
-
const coords = textOf(xml);
|
|
2989
|
-
if (!coords) {
|
|
2990
|
-
throw new Error("invalid gml:pos element");
|
|
2991
|
-
}
|
|
2992
|
-
const points = parseCoords(coords, options, childContext);
|
|
2993
|
-
if (points.length !== 1) {
|
|
2994
|
-
throw new Error("gml:pos must have 1 point");
|
|
2995
|
-
}
|
|
2996
|
-
return points[0];
|
|
2997
|
-
}
|
|
2998
|
-
function parsePoint(xml, options, context) {
|
|
2999
|
-
const childContext = createChildContext(xml, options, context);
|
|
3000
|
-
const pos = findIn(xml, "gml:pos");
|
|
3001
|
-
if (!pos) {
|
|
3002
|
-
throw new Error("invalid gml:Point element, expected a gml:pos subelement");
|
|
3003
|
-
}
|
|
3004
|
-
return parsePos(pos, options, childContext);
|
|
3005
|
-
}
|
|
3006
|
-
function parseLinearRingOrLineString(xml, options, context) {
|
|
3007
|
-
const childContext = createChildContext(xml, options, context);
|
|
3008
|
-
let points = [];
|
|
3009
|
-
const posList = findIn(xml, "gml:posList");
|
|
3010
|
-
if (posList) {
|
|
3011
|
-
points = parsePosList(posList, options, childContext);
|
|
3012
|
-
} else {
|
|
3013
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
3014
|
-
switch (childName) {
|
|
3015
|
-
case "gml:Point":
|
|
3016
|
-
points.push(parsePoint(childXML, options, childContext));
|
|
3017
|
-
break;
|
|
3018
|
-
case "gml:pos":
|
|
3019
|
-
points.push(parsePos(childXML, options, childContext));
|
|
3020
|
-
break;
|
|
3021
|
-
default:
|
|
3022
|
-
continue;
|
|
3023
|
-
}
|
|
3024
|
-
}
|
|
3025
|
-
}
|
|
3026
|
-
if (points.length === 0) {
|
|
3027
|
-
throw new Error(`${xml.name} must have > 0 points`);
|
|
3028
|
-
}
|
|
3029
|
-
return points;
|
|
3030
|
-
}
|
|
3031
|
-
function parseCurveSegments(xml, options, context) {
|
|
3032
|
-
const points = [];
|
|
3033
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
3034
|
-
switch (childName) {
|
|
3035
|
-
case "gml:LineStringSegment":
|
|
3036
|
-
const points2 = parseLinearRingOrLineString(childXML, options, context);
|
|
3037
|
-
const end = points[points.length - 1];
|
|
3038
|
-
const start = points2[0];
|
|
3039
|
-
if (end && start && deepStrictEqual(end, start)) {
|
|
3040
|
-
points2.shift();
|
|
3041
|
-
}
|
|
3042
|
-
points.push(...points2);
|
|
3043
|
-
break;
|
|
3044
|
-
default:
|
|
3045
|
-
continue;
|
|
3046
|
-
}
|
|
3047
|
-
}
|
|
3048
|
-
if (points.length === 0) {
|
|
3049
|
-
throw new Error("gml:Curve > gml:segments must have > 0 points");
|
|
3050
|
-
}
|
|
3051
|
-
return points;
|
|
3052
|
-
}
|
|
3053
|
-
function parseRing(xml, options, context) {
|
|
3054
|
-
const childContext = createChildContext(xml, options, context);
|
|
3055
|
-
const points = [];
|
|
3056
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
3057
|
-
switch (childName) {
|
|
3058
|
-
case "gml:curveMember":
|
|
3059
|
-
let points2;
|
|
3060
|
-
const lineString2 = findIn(childXML, "gml:LineString");
|
|
3061
|
-
if (lineString2) {
|
|
3062
|
-
points2 = parseLinearRingOrLineString(lineString2, options, childContext);
|
|
3063
|
-
} else {
|
|
3064
|
-
const segments = findIn(childXML, "gml:Curve", "gml:segments");
|
|
3065
|
-
if (!segments) {
|
|
3066
|
-
throw new Error(`invalid ${childName} element`);
|
|
3067
|
-
}
|
|
3068
|
-
points2 = parseCurveSegments(segments, options, childContext);
|
|
3069
|
-
}
|
|
3070
|
-
const end = points[points.length - 1];
|
|
3071
|
-
const start = points2[0];
|
|
3072
|
-
if (end && start && deepStrictEqual(end, start)) {
|
|
3073
|
-
points2.shift();
|
|
3074
|
-
}
|
|
3075
|
-
points.push(...points2);
|
|
3076
|
-
break;
|
|
3077
|
-
}
|
|
3078
|
-
}
|
|
3079
|
-
if (points.length < 4) {
|
|
3080
|
-
throw new Error(`${xml.name} must have >= 4 points`);
|
|
3081
|
-
}
|
|
3082
|
-
return points;
|
|
3083
|
-
}
|
|
3084
|
-
function parseExteriorOrInterior(xml, options, context) {
|
|
3085
|
-
const linearRing = findIn(xml, "gml:LinearRing");
|
|
3086
|
-
if (linearRing) {
|
|
3087
|
-
return parseLinearRingOrLineString(linearRing, options, context);
|
|
3088
|
-
}
|
|
3089
|
-
const ring = findIn(xml, "gml:Ring");
|
|
3090
|
-
if (!ring) {
|
|
3091
|
-
throw new Error(`invalid ${xml.name} element`);
|
|
3092
|
-
}
|
|
3093
|
-
return parseRing(ring, options, context);
|
|
3094
|
-
}
|
|
3095
|
-
function parsePolygonOrRectangle(xml, options, context) {
|
|
3096
|
-
const childContext = createChildContext(xml, options, context);
|
|
3097
|
-
const exterior = findIn(xml, "gml:exterior");
|
|
3098
|
-
if (!exterior) {
|
|
3099
|
-
throw new Error(`invalid ${xml.name} element`);
|
|
3100
|
-
}
|
|
3101
|
-
const pointLists = [parseExteriorOrInterior(exterior, options, childContext)];
|
|
3102
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
3103
|
-
switch (childName) {
|
|
3104
|
-
case "gml:interior":
|
|
3105
|
-
pointLists.push(parseExteriorOrInterior(childXML, options, childContext));
|
|
3106
|
-
break;
|
|
3107
|
-
}
|
|
3108
|
-
}
|
|
3109
|
-
return pointLists;
|
|
3110
|
-
}
|
|
3111
|
-
function parseSurface(xml, options, context) {
|
|
3112
|
-
const childContext = createChildContext(xml, options, context);
|
|
3113
|
-
const patches = findIn(xml, "gml:patches");
|
|
3114
|
-
if (!patches) {
|
|
3115
|
-
throw new Error(`invalid ${xml.name} element`);
|
|
3116
|
-
}
|
|
3117
|
-
const polygons = [];
|
|
3118
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
3119
|
-
switch (childName) {
|
|
3120
|
-
case "gml:PolygonPatch":
|
|
3121
|
-
case "gml:Rectangle":
|
|
3122
|
-
polygons.push(parsePolygonOrRectangle(childXML, options, childContext));
|
|
3123
|
-
break;
|
|
3124
|
-
default:
|
|
3125
|
-
continue;
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
if (polygons.length === 0) {
|
|
3129
|
-
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
3130
|
-
}
|
|
3131
|
-
return polygons;
|
|
3132
|
-
}
|
|
3133
|
-
function parseCompositeSurface(xml, options, context) {
|
|
3134
|
-
const childContext = createChildContext(xml, options, context);
|
|
3135
|
-
const polygons = [];
|
|
3136
|
-
for (const [childName, childXML] of Object.entries(xml)) {
|
|
3137
|
-
switch (childName) {
|
|
3138
|
-
case "gml:surfaceMember":
|
|
3139
|
-
case "gml:surfaceMembers":
|
|
3140
|
-
const [c2Name, c2Xml] = getFirstKeyValue(childXML);
|
|
3141
|
-
switch (c2Name) {
|
|
3142
|
-
case "gml:Surface":
|
|
3143
|
-
polygons.push(...parseSurface(c2Xml, options, childContext));
|
|
3144
|
-
break;
|
|
3145
|
-
case "gml:Polygon":
|
|
3146
|
-
polygons.push(parsePolygonOrRectangle(c2Xml, options, childContext));
|
|
3147
|
-
break;
|
|
3148
|
-
}
|
|
3149
|
-
break;
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
if (polygons.length === 0) {
|
|
3153
|
-
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
3154
|
-
}
|
|
3155
|
-
return polygons;
|
|
3156
|
-
}
|
|
3157
|
-
function parseMultiSurface(xml, options, context) {
|
|
3158
|
-
let el = xml;
|
|
3159
|
-
const surfaceMembers = findIn(xml, "gml:LinearRing");
|
|
3160
|
-
if (surfaceMembers) {
|
|
3161
|
-
el = surfaceMembers;
|
|
3162
|
-
}
|
|
3163
|
-
const polygons = [];
|
|
3164
|
-
for (const [childName, childXML] of Object.entries(el)) {
|
|
3165
|
-
switch (childName) {
|
|
3166
|
-
case "gml:Surface":
|
|
3167
|
-
const polygons2 = parseSurface(childXML, options, context);
|
|
3168
|
-
polygons.push(...polygons2);
|
|
3169
|
-
break;
|
|
3170
|
-
case "gml:surfaceMember":
|
|
3171
|
-
const polygons3 = parseSurfaceMember(childXML, options, context);
|
|
3172
|
-
polygons.push(...polygons3);
|
|
3173
|
-
break;
|
|
3174
|
-
case "gml:surfaceMembers":
|
|
3175
|
-
const polygonXML = findIn(childXML, "gml:Polygon");
|
|
3176
|
-
for (const surfaceMemberXML of polygonXML) {
|
|
3177
|
-
const polygons32 = parseSurfaceMember(surfaceMemberXML, options, context);
|
|
3178
|
-
polygons.push(...polygons32);
|
|
3179
|
-
}
|
|
3180
|
-
break;
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
if (polygons.length === 0) {
|
|
3184
|
-
throw new Error(`${xml.name} must have > 0 polygons`);
|
|
3185
|
-
}
|
|
3186
|
-
return polygons;
|
|
3187
|
-
}
|
|
3188
|
-
function parseSurfaceMember(xml, options, context) {
|
|
3189
|
-
const [childName, childXml] = getFirstKeyValue(xml);
|
|
3190
|
-
switch (childName) {
|
|
3191
|
-
case "gml:CompositeSurface":
|
|
3192
|
-
return parseCompositeSurface(childXml, options, context);
|
|
3193
|
-
case "gml:Surface":
|
|
3194
|
-
return parseSurface(childXml, options, context);
|
|
3195
|
-
case "gml:Polygon":
|
|
3196
|
-
return [parsePolygonOrRectangle(childXml, options, context)];
|
|
3197
|
-
}
|
|
3198
|
-
throw new Error(`${childName} must have polygons`);
|
|
3199
|
-
}
|
|
3200
|
-
function textOf(el) {
|
|
3201
|
-
if (typeof el !== "string") {
|
|
3202
|
-
throw new Error("expected string");
|
|
3203
|
-
}
|
|
3204
|
-
return el;
|
|
3205
|
-
}
|
|
3206
|
-
function findIn(root, ...tags) {
|
|
3207
|
-
let el = root;
|
|
3208
|
-
for (const tag of tags) {
|
|
3209
|
-
const child = el[tag];
|
|
3210
|
-
if (!child) {
|
|
3211
|
-
return null;
|
|
3212
|
-
}
|
|
3213
|
-
el = child;
|
|
3214
|
-
}
|
|
3215
|
-
return el;
|
|
3216
|
-
}
|
|
3217
|
-
function getFirstKeyValue(object) {
|
|
3218
|
-
if (object && typeof object === "object") {
|
|
3219
|
-
for (const [key, value] of Object.entries(object)) {
|
|
3220
|
-
return [key, value];
|
|
3221
|
-
}
|
|
3222
|
-
}
|
|
3223
|
-
return ["", null];
|
|
3224
|
-
}
|
|
3225
|
-
function createChildContext(xml, options, context) {
|
|
3226
|
-
const srsDimensionAttribute = xml.attributes && xml.attributes.srsDimension;
|
|
3227
|
-
if (srsDimensionAttribute) {
|
|
3228
|
-
const srsDimension = parseInt(srsDimensionAttribute);
|
|
3229
|
-
if (Number.isNaN(srsDimension) || srsDimension <= 0) {
|
|
3230
|
-
throw new Error(`invalid srsDimension attribute value "${srsDimensionAttribute}", expected a positive integer`);
|
|
3231
|
-
}
|
|
3232
|
-
const childContext = Object.create(context);
|
|
3233
|
-
childContext.srsDimension = srsDimension;
|
|
3234
|
-
return childContext;
|
|
3235
|
-
}
|
|
3236
|
-
return context;
|
|
3237
|
-
}
|
|
3238
|
-
|
|
3239
|
-
// src/gml-loader.ts
|
|
3240
|
-
var VERSION8 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3241
|
-
var GMLLoader = {
|
|
3242
|
-
name: "GML",
|
|
3243
|
-
id: "gml",
|
|
3244
|
-
module: "wms",
|
|
3245
|
-
version: VERSION8,
|
|
3246
|
-
worker: false,
|
|
3247
|
-
extensions: ["xml"],
|
|
3248
|
-
mimeTypes: ["application/vnd.ogc.gml", "application/xml", "text/xml"],
|
|
3249
|
-
testText: testXMLFile8,
|
|
3250
|
-
options: {
|
|
3251
|
-
gml: {}
|
|
3252
|
-
},
|
|
3253
|
-
parse: async (arrayBuffer, options) => parseGML(new TextDecoder().decode(arrayBuffer), options),
|
|
3254
|
-
parseTextSync: (text, options) => parseGML(text, options)
|
|
3255
|
-
};
|
|
3256
|
-
function testXMLFile8(text) {
|
|
3257
|
-
return text.startsWith("<?xml");
|
|
3258
|
-
}
|
|
3259
|
-
|
|
3260
|
-
// src/lib/services/create-image-service.ts
|
|
3261
|
-
function createImageService(props, services) {
|
|
3262
|
-
const {
|
|
3263
|
-
type = "auto"
|
|
3264
|
-
} = props;
|
|
3265
|
-
const service = type === "auto" ? guessServiceType(props.url, services) : getServiceOfType(type, services);
|
|
3266
|
-
if (!service) {
|
|
3267
|
-
throw new Error("Not a valid image source type");
|
|
3268
|
-
}
|
|
3269
|
-
return service.create(props);
|
|
3270
|
-
}
|
|
3271
|
-
function getServiceOfType(type, services) {
|
|
3272
|
-
for (const service of services) {
|
|
3273
|
-
if (service.type === type) {
|
|
3274
|
-
return service;
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3277
|
-
return null;
|
|
3278
|
-
}
|
|
3279
|
-
function guessServiceType(url, services) {
|
|
3280
|
-
for (const service of services) {
|
|
3281
|
-
if (service.testURL && service.testURL(url)) {
|
|
3282
|
-
return service;
|
|
3283
|
-
}
|
|
3284
|
-
}
|
|
3285
|
-
return null;
|
|
3286
|
-
}
|
|
3287
|
-
|
|
3288
|
-
// ../images/src/lib/utils/version.ts
|
|
3289
|
-
var VERSION9 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3290
|
-
|
|
3291
|
-
// ../images/src/lib/category-api/image-type.ts
|
|
3292
|
-
var parseImageNode = globalThis.loaders?.parseImageNode;
|
|
3293
|
-
var IMAGE_SUPPORTED = typeof Image !== "undefined";
|
|
3294
|
-
var IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
|
|
3295
|
-
var NODE_IMAGE_SUPPORTED = Boolean(parseImageNode);
|
|
3296
|
-
var DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
3297
|
-
function isImageTypeSupported(type) {
|
|
3298
|
-
switch (type) {
|
|
3299
|
-
case "auto":
|
|
3300
|
-
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
3301
|
-
case "imagebitmap":
|
|
3302
|
-
return IMAGE_BITMAP_SUPPORTED;
|
|
3303
|
-
case "image":
|
|
3304
|
-
return IMAGE_SUPPORTED;
|
|
3305
|
-
case "data":
|
|
3306
|
-
return DATA_SUPPORTED;
|
|
3307
|
-
default:
|
|
3308
|
-
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
3309
|
-
}
|
|
3310
|
-
}
|
|
3311
|
-
function getDefaultImageType() {
|
|
3312
|
-
if (IMAGE_BITMAP_SUPPORTED) {
|
|
3313
|
-
return "imagebitmap";
|
|
3314
|
-
}
|
|
3315
|
-
if (IMAGE_SUPPORTED) {
|
|
3316
|
-
return "image";
|
|
3317
|
-
}
|
|
3318
|
-
if (DATA_SUPPORTED) {
|
|
3319
|
-
return "data";
|
|
3320
|
-
}
|
|
3321
|
-
throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
|
|
3322
|
-
}
|
|
3323
|
-
|
|
3324
|
-
// ../images/src/lib/category-api/parsed-image-api.ts
|
|
3325
|
-
function getImageType(image) {
|
|
3326
|
-
const format = getImageTypeOrNull(image);
|
|
3327
|
-
if (!format) {
|
|
3328
|
-
throw new Error("Not an image");
|
|
3329
|
-
}
|
|
3330
|
-
return format;
|
|
3331
|
-
}
|
|
3332
|
-
function getImageData(image) {
|
|
3333
|
-
switch (getImageType(image)) {
|
|
3334
|
-
case "data":
|
|
3335
|
-
return image;
|
|
3336
|
-
case "image":
|
|
3337
|
-
case "imagebitmap":
|
|
3338
|
-
const canvas = document.createElement("canvas");
|
|
3339
|
-
const context = canvas.getContext("2d");
|
|
3340
|
-
if (!context) {
|
|
3341
|
-
throw new Error("getImageData");
|
|
3342
|
-
}
|
|
3343
|
-
canvas.width = image.width;
|
|
3344
|
-
canvas.height = image.height;
|
|
3345
|
-
context.drawImage(image, 0, 0);
|
|
3346
|
-
return context.getImageData(0, 0, image.width, image.height);
|
|
3347
|
-
default:
|
|
3348
|
-
throw new Error("getImageData");
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
function getImageTypeOrNull(image) {
|
|
3352
|
-
if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
3353
|
-
return "imagebitmap";
|
|
3354
|
-
}
|
|
3355
|
-
if (typeof Image !== "undefined" && image instanceof Image) {
|
|
3356
|
-
return "image";
|
|
3357
|
-
}
|
|
3358
|
-
if (image && typeof image === "object" && image.data && image.width && image.height) {
|
|
3359
|
-
return "data";
|
|
3360
|
-
}
|
|
3361
|
-
return null;
|
|
3362
|
-
}
|
|
3363
|
-
|
|
3364
|
-
// ../images/src/lib/parsers/svg-utils.ts
|
|
3365
|
-
var SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
3366
|
-
var SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
3367
|
-
function isSVG(url) {
|
|
3368
|
-
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
3369
|
-
}
|
|
3370
|
-
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
3371
|
-
if (isSVG(url)) {
|
|
3372
|
-
const textDecoder = new TextDecoder();
|
|
3373
|
-
let xmlText = textDecoder.decode(arrayBuffer);
|
|
3374
|
-
try {
|
|
3375
|
-
if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
|
|
3376
|
-
xmlText = unescape(encodeURIComponent(xmlText));
|
|
3377
|
-
}
|
|
3378
|
-
} catch (error) {
|
|
3379
|
-
throw new Error(error.message);
|
|
3380
|
-
}
|
|
3381
|
-
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
3382
|
-
return src;
|
|
3383
|
-
}
|
|
3384
|
-
return getBlob(arrayBuffer, url);
|
|
3385
|
-
}
|
|
3386
|
-
function getBlob(arrayBuffer, url) {
|
|
3387
|
-
if (isSVG(url)) {
|
|
3388
|
-
throw new Error("SVG cannot be parsed directly to imagebitmap");
|
|
3389
|
-
}
|
|
3390
|
-
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
3391
|
-
}
|
|
3392
|
-
|
|
3393
|
-
// ../images/src/lib/parsers/parse-to-image.ts
|
|
3394
|
-
async function parseToImage(arrayBuffer, options, url) {
|
|
3395
|
-
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
3396
|
-
const URL = self.URL || self.webkitURL;
|
|
3397
|
-
const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
|
|
3398
|
-
try {
|
|
3399
|
-
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
3400
|
-
} finally {
|
|
3401
|
-
if (objectUrl) {
|
|
3402
|
-
URL.revokeObjectURL(objectUrl);
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
async function loadToImage(url, options) {
|
|
3407
|
-
const image = new Image();
|
|
3408
|
-
image.src = url;
|
|
3409
|
-
if (options.image && options.image.decode && image.decode) {
|
|
3410
|
-
await image.decode();
|
|
3411
|
-
return image;
|
|
3412
|
-
}
|
|
3413
|
-
return await new Promise((resolve, reject) => {
|
|
3414
|
-
try {
|
|
3415
|
-
image.onload = () => resolve(image);
|
|
3416
|
-
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
3417
|
-
} catch (error) {
|
|
3418
|
-
reject(error);
|
|
3419
|
-
}
|
|
3420
|
-
});
|
|
3421
|
-
}
|
|
3422
|
-
|
|
3423
|
-
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
3424
|
-
var EMPTY_OBJECT = {};
|
|
3425
|
-
var imagebitmapOptionsSupported = true;
|
|
3426
|
-
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
3427
|
-
let blob;
|
|
3428
|
-
if (isSVG(url)) {
|
|
3429
|
-
const image = await parseToImage(arrayBuffer, options, url);
|
|
3430
|
-
blob = image;
|
|
3431
|
-
} else {
|
|
3432
|
-
blob = getBlob(arrayBuffer, url);
|
|
3433
|
-
}
|
|
3434
|
-
const imagebitmapOptions = options && options.imagebitmap;
|
|
3435
|
-
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
3436
|
-
}
|
|
3437
|
-
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
3438
|
-
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
3439
|
-
imagebitmapOptions = null;
|
|
3440
|
-
}
|
|
3441
|
-
if (imagebitmapOptions) {
|
|
3442
|
-
try {
|
|
3443
|
-
return await createImageBitmap(blob, imagebitmapOptions);
|
|
3444
|
-
} catch (error) {
|
|
3445
|
-
console.warn(error);
|
|
3446
|
-
imagebitmapOptionsSupported = false;
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
return await createImageBitmap(blob);
|
|
3450
|
-
}
|
|
3451
|
-
function isEmptyObject(object) {
|
|
3452
|
-
for (const key in object || EMPTY_OBJECT) {
|
|
3453
|
-
return false;
|
|
3454
|
-
}
|
|
3455
|
-
return true;
|
|
3456
|
-
}
|
|
3457
|
-
|
|
3458
|
-
// ../images/src/lib/category-api/parse-isobmff-binary.ts
|
|
3459
|
-
function getISOBMFFMediaType(buffer) {
|
|
3460
|
-
if (!checkString(buffer, "ftyp", 4)) {
|
|
3461
|
-
return null;
|
|
3462
|
-
}
|
|
3463
|
-
if ((buffer[8] & 96) === 0) {
|
|
3464
|
-
return null;
|
|
3465
|
-
}
|
|
3466
|
-
return decodeMajorBrand(buffer);
|
|
3467
|
-
}
|
|
3468
|
-
function decodeMajorBrand(buffer) {
|
|
3469
|
-
const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
|
|
3470
|
-
switch (brandMajor) {
|
|
3471
|
-
case "avif":
|
|
3472
|
-
case "avis":
|
|
3473
|
-
return {
|
|
3474
|
-
extension: "avif",
|
|
3475
|
-
mimeType: "image/avif"
|
|
3476
|
-
};
|
|
3477
|
-
default:
|
|
3478
|
-
return null;
|
|
3479
|
-
}
|
|
3480
|
-
}
|
|
3481
|
-
function getUTF8String(array, start, end) {
|
|
3482
|
-
return String.fromCharCode(...array.slice(start, end));
|
|
3483
|
-
}
|
|
3484
|
-
function stringToBytes(string) {
|
|
3485
|
-
return [...string].map((character) => character.charCodeAt(0));
|
|
3486
|
-
}
|
|
3487
|
-
function checkString(buffer, header, offset = 0) {
|
|
3488
|
-
const headerBytes = stringToBytes(header);
|
|
3489
|
-
for (let i = 0; i < headerBytes.length; ++i) {
|
|
3490
|
-
if (headerBytes[i] !== buffer[i + offset]) {
|
|
3491
|
-
return false;
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
return true;
|
|
3495
|
-
}
|
|
3496
|
-
|
|
3497
|
-
// ../images/src/lib/category-api/binary-image-api.ts
|
|
3498
|
-
var BIG_ENDIAN = false;
|
|
3499
|
-
var LITTLE_ENDIAN = true;
|
|
3500
|
-
function getBinaryImageMetadata(binaryData) {
|
|
3501
|
-
const dataView = toDataView(binaryData);
|
|
3502
|
-
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
|
|
3503
|
-
}
|
|
3504
|
-
function getISOBMFFMetadata(binaryData) {
|
|
3505
|
-
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
3506
|
-
const mediaType = getISOBMFFMediaType(buffer);
|
|
3507
|
-
if (!mediaType) {
|
|
3508
|
-
return null;
|
|
3509
|
-
}
|
|
3510
|
-
return {
|
|
3511
|
-
mimeType: mediaType.mimeType,
|
|
3512
|
-
width: 0,
|
|
3513
|
-
height: 0
|
|
3514
|
-
};
|
|
3515
|
-
}
|
|
3516
|
-
function getPngMetadata(binaryData) {
|
|
3517
|
-
const dataView = toDataView(binaryData);
|
|
3518
|
-
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
|
|
3519
|
-
if (!isPng) {
|
|
3520
|
-
return null;
|
|
3521
|
-
}
|
|
3522
|
-
return {
|
|
3523
|
-
mimeType: "image/png",
|
|
3524
|
-
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
3525
|
-
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
3526
|
-
};
|
|
3527
|
-
}
|
|
3528
|
-
function getGifMetadata(binaryData) {
|
|
3529
|
-
const dataView = toDataView(binaryData);
|
|
3530
|
-
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
|
|
3531
|
-
if (!isGif) {
|
|
3532
|
-
return null;
|
|
3533
|
-
}
|
|
3534
|
-
return {
|
|
3535
|
-
mimeType: "image/gif",
|
|
3536
|
-
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
3537
|
-
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
3538
|
-
};
|
|
3539
|
-
}
|
|
3540
|
-
function getBmpMetadata(binaryData) {
|
|
3541
|
-
const dataView = toDataView(binaryData);
|
|
3542
|
-
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
3543
|
-
if (!isBmp) {
|
|
3544
|
-
return null;
|
|
3545
|
-
}
|
|
3546
|
-
return {
|
|
3547
|
-
mimeType: "image/bmp",
|
|
3548
|
-
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
3549
|
-
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
3550
|
-
};
|
|
3551
|
-
}
|
|
3552
|
-
function getJpegMetadata(binaryData) {
|
|
3553
|
-
const dataView = toDataView(binaryData);
|
|
3554
|
-
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
|
|
3555
|
-
if (!isJpeg) {
|
|
3556
|
-
return null;
|
|
3557
|
-
}
|
|
3558
|
-
const {
|
|
3559
|
-
tableMarkers,
|
|
3560
|
-
sofMarkers
|
|
3561
|
-
} = getJpegMarkers();
|
|
3562
|
-
let i = 2;
|
|
3563
|
-
while (i + 9 < dataView.byteLength) {
|
|
3564
|
-
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
3565
|
-
if (sofMarkers.has(marker)) {
|
|
3566
|
-
return {
|
|
3567
|
-
mimeType: "image/jpeg",
|
|
3568
|
-
height: dataView.getUint16(i + 5, BIG_ENDIAN),
|
|
3569
|
-
width: dataView.getUint16(i + 7, BIG_ENDIAN)
|
|
3570
|
-
};
|
|
3571
|
-
}
|
|
3572
|
-
if (!tableMarkers.has(marker)) {
|
|
3573
|
-
return null;
|
|
3574
|
-
}
|
|
3575
|
-
i += 2;
|
|
3576
|
-
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
3577
|
-
}
|
|
3578
|
-
return null;
|
|
3579
|
-
}
|
|
3580
|
-
function getJpegMarkers() {
|
|
3581
|
-
const tableMarkers = /* @__PURE__ */ new Set([65499, 65476, 65484, 65501, 65534]);
|
|
3582
|
-
for (let i = 65504; i < 65520; ++i) {
|
|
3583
|
-
tableMarkers.add(i);
|
|
3584
|
-
}
|
|
3585
|
-
const sofMarkers = /* @__PURE__ */ new Set([65472, 65473, 65474, 65475, 65477, 65478, 65479, 65481, 65482, 65483, 65485, 65486, 65487, 65502]);
|
|
3586
|
-
return {
|
|
3587
|
-
tableMarkers,
|
|
3588
|
-
sofMarkers
|
|
3589
|
-
};
|
|
3590
|
-
}
|
|
3591
|
-
function toDataView(data) {
|
|
3592
|
-
if (data instanceof DataView) {
|
|
3593
|
-
return data;
|
|
3594
|
-
}
|
|
3595
|
-
if (ArrayBuffer.isView(data)) {
|
|
3596
|
-
return new DataView(data.buffer);
|
|
3597
|
-
}
|
|
3598
|
-
if (data instanceof ArrayBuffer) {
|
|
3599
|
-
return new DataView(data);
|
|
3600
|
-
}
|
|
3601
|
-
throw new Error("toDataView");
|
|
3602
|
-
}
|
|
3603
|
-
|
|
3604
|
-
// ../images/src/lib/parsers/parse-to-node-image.ts
|
|
3605
|
-
async function parseToNodeImage(arrayBuffer, options) {
|
|
3606
|
-
const {
|
|
3607
|
-
mimeType
|
|
3608
|
-
} = getBinaryImageMetadata(arrayBuffer) || {};
|
|
3609
|
-
const parseImageNode2 = globalThis.loaders?.parseImageNode;
|
|
3610
|
-
assert(parseImageNode2);
|
|
3611
|
-
return await parseImageNode2(arrayBuffer, mimeType);
|
|
3612
|
-
}
|
|
3613
|
-
|
|
3614
|
-
// ../images/src/lib/parsers/parse-image.ts
|
|
3615
|
-
async function parseImage(arrayBuffer, options, context) {
|
|
3616
|
-
options = options || {};
|
|
3617
|
-
const imageOptions = options.image || {};
|
|
3618
|
-
const imageType = imageOptions.type || "auto";
|
|
3619
|
-
const {
|
|
3620
|
-
url
|
|
3621
|
-
} = context || {};
|
|
3622
|
-
const loadType = getLoadableImageType(imageType);
|
|
3623
|
-
let image;
|
|
3624
|
-
switch (loadType) {
|
|
3625
|
-
case "imagebitmap":
|
|
3626
|
-
image = await parseToImageBitmap(arrayBuffer, options, url);
|
|
3627
|
-
break;
|
|
3628
|
-
case "image":
|
|
3629
|
-
image = await parseToImage(arrayBuffer, options, url);
|
|
3630
|
-
break;
|
|
3631
|
-
case "data":
|
|
3632
|
-
image = await parseToNodeImage(arrayBuffer, options);
|
|
3633
|
-
break;
|
|
3634
|
-
default:
|
|
3635
|
-
assert(false);
|
|
3636
|
-
}
|
|
3637
|
-
if (imageType === "data") {
|
|
3638
|
-
image = getImageData(image);
|
|
3639
|
-
}
|
|
3640
|
-
return image;
|
|
3641
|
-
}
|
|
3642
|
-
function getLoadableImageType(type) {
|
|
3643
|
-
switch (type) {
|
|
3644
|
-
case "auto":
|
|
3645
|
-
case "data":
|
|
3646
|
-
return getDefaultImageType();
|
|
3647
|
-
default:
|
|
3648
|
-
isImageTypeSupported(type);
|
|
3649
|
-
return type;
|
|
3650
|
-
}
|
|
3651
|
-
}
|
|
3652
|
-
|
|
3653
|
-
// ../images/src/image-loader.ts
|
|
3654
|
-
var EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
|
|
3655
|
-
var MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif", "image/bmp", "image/vnd.microsoft.icon", "image/svg+xml"];
|
|
3656
|
-
var DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
3657
|
-
image: {
|
|
3658
|
-
type: "auto",
|
|
3659
|
-
decode: true
|
|
3660
|
-
}
|
|
3661
|
-
};
|
|
3662
|
-
var ImageLoader = {
|
|
3663
|
-
id: "image",
|
|
3664
|
-
module: "images",
|
|
3665
|
-
name: "Images",
|
|
3666
|
-
version: VERSION9,
|
|
3667
|
-
mimeTypes: MIME_TYPES,
|
|
3668
|
-
extensions: EXTENSIONS,
|
|
3669
|
-
parse: parseImage,
|
|
3670
|
-
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
3671
|
-
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
3672
|
-
};
|
|
3673
|
-
|
|
3674
|
-
// src/services/ogc/wms-service.ts
|
|
3675
|
-
var WMSService = {
|
|
3676
|
-
type: "wms",
|
|
3677
|
-
testURL: (url) => url.toLowerCase().includes("wms"),
|
|
3678
|
-
create: (props) => new WMSSource(props)
|
|
3679
|
-
};
|
|
3680
|
-
var WMSSource = class extends ImageSource {
|
|
3681
|
-
capabilities = null;
|
|
3682
|
-
constructor(props) {
|
|
3683
|
-
super(props);
|
|
3684
|
-
this.url = props.url;
|
|
3685
|
-
this.substituteCRS84 = props.substituteCRS84 ?? false;
|
|
3686
|
-
this.flipCRS = ["EPSG:4326"];
|
|
3687
|
-
this.wmsParameters = {
|
|
3688
|
-
layers: void 0,
|
|
3689
|
-
query_layers: void 0,
|
|
3690
|
-
styles: void 0,
|
|
3691
|
-
version: "1.3.0",
|
|
3692
|
-
crs: "EPSG:4326",
|
|
3693
|
-
format: "image/png",
|
|
3694
|
-
info_format: "text/plain",
|
|
3695
|
-
transparent: void 0,
|
|
3696
|
-
time: void 0,
|
|
3697
|
-
elevation: void 0,
|
|
3698
|
-
...props.wmsParameters
|
|
3699
|
-
};
|
|
3700
|
-
this.vendorParameters = props.vendorParameters || {};
|
|
3701
|
-
}
|
|
3702
|
-
async getMetadata() {
|
|
3703
|
-
const capabilities = await this.getCapabilities();
|
|
3704
|
-
return this.normalizeMetadata(capabilities);
|
|
3705
|
-
}
|
|
3706
|
-
async getImage(parameters) {
|
|
3707
|
-
return await this.getMap(parameters);
|
|
3708
|
-
}
|
|
3709
|
-
normalizeMetadata(capabilities) {
|
|
3710
|
-
return capabilities;
|
|
3711
|
-
}
|
|
3712
|
-
async getCapabilities(wmsParameters, vendorParameters) {
|
|
3713
|
-
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
|
|
3714
|
-
const response = await this.fetch(url);
|
|
3715
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3716
|
-
this._checkResponse(response, arrayBuffer);
|
|
3717
|
-
const capabilities = await WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions);
|
|
3718
|
-
this.capabilities = capabilities;
|
|
3719
|
-
return capabilities;
|
|
3720
|
-
}
|
|
3721
|
-
async getMap(wmsParameters, vendorParameters) {
|
|
3722
|
-
const url = this.getMapURL(wmsParameters, vendorParameters);
|
|
3723
|
-
const response = await this.fetch(url);
|
|
3724
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3725
|
-
this._checkResponse(response, arrayBuffer);
|
|
3726
|
-
try {
|
|
3727
|
-
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
3728
|
-
} catch {
|
|
3729
|
-
throw this._parseError(arrayBuffer);
|
|
3730
|
-
}
|
|
3731
|
-
}
|
|
3732
|
-
async getFeatureInfo(wmsParameters, vendorParameters) {
|
|
3733
|
-
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
3734
|
-
const response = await this.fetch(url);
|
|
3735
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3736
|
-
this._checkResponse(response, arrayBuffer);
|
|
3737
|
-
return await WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions);
|
|
3738
|
-
}
|
|
3739
|
-
async getFeatureInfoText(wmsParameters, vendorParameters) {
|
|
3740
|
-
const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
|
|
3741
|
-
const response = await this.fetch(url);
|
|
3742
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3743
|
-
this._checkResponse(response, arrayBuffer);
|
|
3744
|
-
return new TextDecoder().decode(arrayBuffer);
|
|
3745
|
-
}
|
|
3746
|
-
async describeLayer(wmsParameters, vendorParameters) {
|
|
3747
|
-
const url = this.describeLayerURL(wmsParameters, vendorParameters);
|
|
3748
|
-
const response = await this.fetch(url);
|
|
3749
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3750
|
-
this._checkResponse(response, arrayBuffer);
|
|
3751
|
-
return await WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions);
|
|
3752
|
-
}
|
|
3753
|
-
async getLegendGraphic(wmsParameters, vendorParameters) {
|
|
3754
|
-
const url = this.getLegendGraphicURL(wmsParameters, vendorParameters);
|
|
3755
|
-
const response = await this.fetch(url);
|
|
3756
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3757
|
-
this._checkResponse(response, arrayBuffer);
|
|
3758
|
-
try {
|
|
3759
|
-
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
3760
|
-
} catch {
|
|
3761
|
-
throw this._parseError(arrayBuffer);
|
|
3762
|
-
}
|
|
3763
|
-
}
|
|
3764
|
-
getCapabilitiesURL(wmsParameters, vendorParameters) {
|
|
3765
|
-
const options = {
|
|
3766
|
-
version: this.wmsParameters.version,
|
|
3767
|
-
...wmsParameters
|
|
3768
|
-
};
|
|
3769
|
-
return this._getWMSUrl("GetCapabilities", options, vendorParameters);
|
|
3770
|
-
}
|
|
3771
|
-
getMapURL(wmsParameters, vendorParameters) {
|
|
3772
|
-
wmsParameters = this._getWMS130Parameters(wmsParameters);
|
|
3773
|
-
const options = {
|
|
3774
|
-
version: this.wmsParameters.version,
|
|
3775
|
-
format: this.wmsParameters.format,
|
|
3776
|
-
transparent: this.wmsParameters.transparent,
|
|
3777
|
-
time: this.wmsParameters.time,
|
|
3778
|
-
elevation: this.wmsParameters.elevation,
|
|
3779
|
-
layers: this.wmsParameters.layers,
|
|
3780
|
-
styles: this.wmsParameters.styles,
|
|
3781
|
-
crs: this.wmsParameters.crs,
|
|
3782
|
-
...wmsParameters
|
|
3783
|
-
};
|
|
3784
|
-
return this._getWMSUrl("GetMap", options, vendorParameters);
|
|
3785
|
-
}
|
|
3786
|
-
getFeatureInfoURL(wmsParameters, vendorParameters) {
|
|
3787
|
-
wmsParameters = this._getWMS130Parameters(wmsParameters);
|
|
3788
|
-
const options = {
|
|
3789
|
-
version: this.wmsParameters.version,
|
|
3790
|
-
info_format: this.wmsParameters.info_format,
|
|
3791
|
-
layers: this.wmsParameters.layers,
|
|
3792
|
-
query_layers: this.wmsParameters.query_layers,
|
|
3793
|
-
styles: this.wmsParameters.styles,
|
|
3794
|
-
crs: this.wmsParameters.crs,
|
|
3795
|
-
...wmsParameters
|
|
3796
|
-
};
|
|
3797
|
-
return this._getWMSUrl("GetFeatureInfo", options, vendorParameters);
|
|
3798
|
-
}
|
|
3799
|
-
describeLayerURL(wmsParameters, vendorParameters) {
|
|
3800
|
-
const options = {
|
|
3801
|
-
version: this.wmsParameters.version,
|
|
3802
|
-
...wmsParameters
|
|
3803
|
-
};
|
|
3804
|
-
return this._getWMSUrl("DescribeLayer", options, vendorParameters);
|
|
3805
|
-
}
|
|
3806
|
-
getLegendGraphicURL(wmsParameters, vendorParameters) {
|
|
3807
|
-
const options = {
|
|
3808
|
-
version: this.wmsParameters.version,
|
|
3809
|
-
...wmsParameters
|
|
3810
|
-
};
|
|
3811
|
-
return this._getWMSUrl("GetLegendGraphic", options, vendorParameters);
|
|
3812
|
-
}
|
|
3813
|
-
_parseWMSUrl(url) {
|
|
3814
|
-
const [baseUrl, search] = url.split("?");
|
|
3815
|
-
const searchParams = search.split("&");
|
|
3816
|
-
const parameters = {};
|
|
3817
|
-
for (const parameter of searchParams) {
|
|
3818
|
-
const [key, value] = parameter.split("=");
|
|
3819
|
-
parameters[key] = value;
|
|
3820
|
-
}
|
|
3821
|
-
return {
|
|
3822
|
-
url: baseUrl,
|
|
3823
|
-
parameters
|
|
3824
|
-
};
|
|
3825
|
-
}
|
|
3826
|
-
_getWMSUrl(request, wmsParameters, vendorParameters) {
|
|
3827
|
-
let url = this.url;
|
|
3828
|
-
let first = true;
|
|
3829
|
-
const allParameters = {
|
|
3830
|
-
service: "WMS",
|
|
3831
|
-
version: wmsParameters.version,
|
|
3832
|
-
request,
|
|
3833
|
-
...wmsParameters,
|
|
3834
|
-
...this.vendorParameters,
|
|
3835
|
-
...vendorParameters
|
|
3836
|
-
};
|
|
3837
|
-
const IGNORE_EMPTY_KEYS = ["transparent", "time", "elevation"];
|
|
3838
|
-
for (const [key, value] of Object.entries(allParameters)) {
|
|
3839
|
-
if (!IGNORE_EMPTY_KEYS.includes(key) || value) {
|
|
3840
|
-
url += first ? "?" : "&";
|
|
3841
|
-
first = false;
|
|
3842
|
-
url += this._getURLParameter(key, value, wmsParameters);
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
return encodeURI(url);
|
|
3846
|
-
}
|
|
3847
|
-
_getWMS130Parameters(wmsParameters) {
|
|
3848
|
-
const newParameters = {
|
|
3849
|
-
...wmsParameters
|
|
3850
|
-
};
|
|
3851
|
-
if (newParameters.srs) {
|
|
3852
|
-
newParameters.crs = newParameters.crs || newParameters.srs;
|
|
3853
|
-
delete newParameters.srs;
|
|
3854
|
-
}
|
|
3855
|
-
return newParameters;
|
|
3856
|
-
}
|
|
3857
|
-
_getURLParameter(key, value, wmsParameters) {
|
|
3858
|
-
switch (key) {
|
|
3859
|
-
case "crs":
|
|
3860
|
-
if (wmsParameters.version !== "1.3.0") {
|
|
3861
|
-
key = "srs";
|
|
3862
|
-
} else if (this.substituteCRS84 && value === "EPSG:4326") {
|
|
3863
|
-
value = "CRS:84";
|
|
3864
|
-
}
|
|
3865
|
-
break;
|
|
3866
|
-
case "srs":
|
|
3867
|
-
if (wmsParameters.version === "1.3.0") {
|
|
3868
|
-
key = "crs";
|
|
3869
|
-
}
|
|
3870
|
-
break;
|
|
3871
|
-
case "bbox":
|
|
3872
|
-
const bbox = this._flipBoundingBox(value, wmsParameters);
|
|
3873
|
-
if (bbox) {
|
|
3874
|
-
value = bbox;
|
|
3875
|
-
}
|
|
3876
|
-
break;
|
|
3877
|
-
default:
|
|
3878
|
-
}
|
|
3879
|
-
key = key.toUpperCase();
|
|
3880
|
-
return Array.isArray(value) ? `${key}=${value.join(",")}` : `${key}=${value ? String(value) : ""}`;
|
|
3881
|
-
}
|
|
3882
|
-
_flipBoundingBox(bboxValue, wmsParameters) {
|
|
3883
|
-
if (!Array.isArray(bboxValue) || bboxValue.length !== 4) {
|
|
3884
|
-
return null;
|
|
3885
|
-
}
|
|
3886
|
-
const flipCoordinates = wmsParameters.version === "1.3.0" && this.flipCRS.includes(wmsParameters.crs || "") && !(this.substituteCRS84 && wmsParameters.crs === "EPSG:4326");
|
|
3887
|
-
const bbox = bboxValue;
|
|
3888
|
-
return flipCoordinates ? [bbox[1], bbox[0], bbox[3], bbox[2]] : bbox;
|
|
3889
|
-
}
|
|
3890
|
-
async _fetchArrayBuffer(url) {
|
|
3891
|
-
const response = await this.fetch(url);
|
|
3892
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3893
|
-
this._checkResponse(response, arrayBuffer);
|
|
3894
|
-
return arrayBuffer;
|
|
3895
|
-
}
|
|
3896
|
-
_checkResponse(response, arrayBuffer) {
|
|
3897
|
-
const contentType = response.headers["content-type"];
|
|
3898
|
-
if (!response.ok || WMSErrorLoader.mimeTypes.includes(contentType)) {
|
|
3899
|
-
const loadOptions = mergeLoaderOptions(this.loadOptions, {
|
|
3900
|
-
wms: {
|
|
3901
|
-
throwOnError: true
|
|
3902
|
-
}
|
|
3903
|
-
});
|
|
3904
|
-
const error = WMSErrorLoader.parseSync?.(arrayBuffer, loadOptions);
|
|
3905
|
-
throw new Error(error);
|
|
3906
|
-
}
|
|
3907
|
-
}
|
|
3908
|
-
_parseError(arrayBuffer) {
|
|
3909
|
-
const error = WMSErrorLoader.parseSync?.(arrayBuffer, this.loadOptions);
|
|
3910
|
-
return new Error(error);
|
|
3911
|
-
}
|
|
3912
|
-
};
|
|
3913
|
-
|
|
3914
|
-
// src/lib/services/image-service.ts
|
|
3915
|
-
var ImageService = class extends ImageSource {
|
|
3916
|
-
constructor(props) {
|
|
3917
|
-
super(props);
|
|
3918
|
-
}
|
|
3919
|
-
async getMetadata() {
|
|
3920
|
-
throw new Error("ImageSource.getMetadata not implemented");
|
|
3921
|
-
}
|
|
3922
|
-
async getImage(parameters) {
|
|
3923
|
-
const granularParameters = this.getGranularParameters(parameters);
|
|
3924
|
-
const url = this.getURLFromTemplate(granularParameters);
|
|
3925
|
-
const response = await this.fetch(url);
|
|
3926
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
3927
|
-
return await ImageLoader.parse(arrayBuffer);
|
|
3928
|
-
}
|
|
3929
|
-
getGranularParameters(parameters) {
|
|
3930
|
-
const [east, north, west, south] = parameters.bbox;
|
|
3931
|
-
return {
|
|
3932
|
-
...parameters,
|
|
3933
|
-
east,
|
|
3934
|
-
north,
|
|
3935
|
-
south,
|
|
3936
|
-
west
|
|
3937
|
-
};
|
|
3938
|
-
}
|
|
3939
|
-
getURLFromTemplate(parameters) {
|
|
3940
|
-
let url = this.props.url;
|
|
3941
|
-
for (const [key, value] of Object.entries(parameters)) {
|
|
3942
|
-
url = url.replace(`\${${key}}`, String(value));
|
|
3943
|
-
url = url.replace(`{${key}}`, String(value));
|
|
3944
|
-
}
|
|
3945
|
-
return url;
|
|
3946
|
-
}
|
|
3947
|
-
};
|
|
3948
|
-
__publicField(ImageService, "type", "template");
|
|
3949
|
-
__publicField(ImageService, "testURL", (url) => url.toLowerCase().includes("{"));
|
|
3950
|
-
|
|
3951
|
-
// src/services/arcgis/arcgis-image-service.ts
|
|
3952
|
-
var ArcGISImageSource = class extends ImageService {
|
|
3953
|
-
constructor(props) {
|
|
3954
|
-
super(props);
|
|
3955
|
-
}
|
|
3956
|
-
async getMetadata() {
|
|
3957
|
-
return await this.metadata();
|
|
3958
|
-
}
|
|
3959
|
-
async getImage(parameters) {
|
|
3960
|
-
throw new Error("not implemented");
|
|
3961
|
-
}
|
|
3962
|
-
async metadata() {
|
|
3963
|
-
throw new Error("not implemented");
|
|
3964
|
-
}
|
|
3965
|
-
exportImage(options) {
|
|
3966
|
-
throw new Error("not implemented");
|
|
3967
|
-
}
|
|
3968
|
-
metadataURL(options) {
|
|
3969
|
-
return `${this.props.url}?f=pjson`;
|
|
3970
|
-
}
|
|
3971
|
-
exportImageURL(options) {
|
|
3972
|
-
const bbox = `bbox=${options.bbox[0]},${options.bbox[1]},${options.bbox[2]},${options.bbox[3]}`;
|
|
3973
|
-
const size = `size=${options.width},${options.height}`;
|
|
3974
|
-
const arcgisOptions = {
|
|
3975
|
-
...options,
|
|
3976
|
-
bbox,
|
|
3977
|
-
size
|
|
3978
|
-
};
|
|
3979
|
-
delete arcgisOptions.width;
|
|
3980
|
-
delete arcgisOptions.height;
|
|
3981
|
-
return this.getUrl("exportImage", arcgisOptions);
|
|
3982
|
-
}
|
|
3983
|
-
getUrl(path, options, extra) {
|
|
3984
|
-
let url = `${this.props.url}/${path}`;
|
|
3985
|
-
let first = true;
|
|
3986
|
-
for (const [key, value] of Object.entries(options)) {
|
|
3987
|
-
url += first ? "?" : "&";
|
|
3988
|
-
first = false;
|
|
3989
|
-
if (Array.isArray(value)) {
|
|
3990
|
-
url += `${key.toUpperCase()}=${value.join(",")}`;
|
|
3991
|
-
} else {
|
|
3992
|
-
url += `${key.toUpperCase()}=${value ? String(value) : ""}`;
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
return url;
|
|
3996
|
-
}
|
|
3997
|
-
async checkResponse(response) {
|
|
3998
|
-
if (!response.ok) {
|
|
3999
|
-
throw new Error("error");
|
|
4000
|
-
}
|
|
4001
|
-
}
|
|
4002
|
-
};
|
|
4003
|
-
var ArcGISImageService = {
|
|
4004
|
-
type: "arcgis-image-server",
|
|
4005
|
-
testURL: (url) => url.toLowerCase().includes("ImageServer"),
|
|
4006
|
-
create: (props) => new ArcGISImageSource(props)
|
|
4007
|
-
};
|
|
4008
|
-
|
|
4009
|
-
// src/services/create-image-source.ts
|
|
4010
|
-
var SERVICES = [WMSService, ArcGISImageService];
|
|
4011
|
-
function createImageSource(props) {
|
|
4012
|
-
return createImageService(props, SERVICES);
|
|
4013
|
-
}
|
|
4014
|
-
|
|
4015
|
-
// src/services/ogc/csw-service.ts
|
|
4016
|
-
var CSWService = class extends DataSource {
|
|
4017
|
-
capabilities = null;
|
|
4018
|
-
loaders = [WMSErrorLoader, CSWCapabilitiesLoader];
|
|
4019
|
-
constructor(props) {
|
|
4020
|
-
super(props);
|
|
4021
|
-
}
|
|
4022
|
-
async getMetadata() {
|
|
4023
|
-
const capabilities = await this.getCapabilities();
|
|
4024
|
-
return this.normalizeMetadata(capabilities);
|
|
4025
|
-
}
|
|
4026
|
-
normalizeMetadata(capabilities) {
|
|
4027
|
-
return capabilities;
|
|
4028
|
-
}
|
|
4029
|
-
async getServiceDirectory(options) {
|
|
4030
|
-
const services = [];
|
|
4031
|
-
const unknownServices = [];
|
|
4032
|
-
const records = await this.getRecords();
|
|
4033
|
-
for (const record of records.records) {
|
|
4034
|
-
for (const reference of record.references) {
|
|
4035
|
-
const url = reference.value;
|
|
4036
|
-
switch (reference.scheme) {
|
|
4037
|
-
case "OGC:WMS":
|
|
4038
|
-
services.push({
|
|
4039
|
-
name: record.title,
|
|
4040
|
-
type: "ogc-wms-service",
|
|
4041
|
-
...this._parseOGCUrl(url)
|
|
4042
|
-
});
|
|
4043
|
-
break;
|
|
4044
|
-
case "OGC:WMTS":
|
|
4045
|
-
services.push({
|
|
4046
|
-
name: record.title,
|
|
4047
|
-
type: "ogc-wmts-service",
|
|
4048
|
-
...this._parseOGCUrl(url)
|
|
4049
|
-
});
|
|
4050
|
-
break;
|
|
4051
|
-
case "OGC:WFS":
|
|
4052
|
-
services.push({
|
|
4053
|
-
name: record.title,
|
|
4054
|
-
type: "ogc-wfs-service",
|
|
4055
|
-
...this._parseOGCUrl(url)
|
|
4056
|
-
});
|
|
4057
|
-
break;
|
|
4058
|
-
default:
|
|
4059
|
-
unknownServices.push({
|
|
4060
|
-
name: record.title,
|
|
4061
|
-
type: "unknown",
|
|
4062
|
-
url: reference.value,
|
|
4063
|
-
scheme: reference.scheme
|
|
4064
|
-
});
|
|
4065
|
-
}
|
|
4066
|
-
}
|
|
4067
|
-
}
|
|
4068
|
-
return options?.includeUnknown ? services.concat(unknownServices) : services;
|
|
4069
|
-
}
|
|
4070
|
-
_parseOGCUrl(url) {
|
|
4071
|
-
const parts = url.split("?");
|
|
4072
|
-
return {
|
|
4073
|
-
url: parts[0],
|
|
4074
|
-
params: parts[1] || ""
|
|
4075
|
-
};
|
|
4076
|
-
}
|
|
4077
|
-
async getCapabilities(wmsParameters, vendorParameters) {
|
|
4078
|
-
const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
|
|
4079
|
-
const response = await this.fetch(url);
|
|
4080
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4081
|
-
this._checkResponse(response, arrayBuffer);
|
|
4082
|
-
const capabilities = await CSWCapabilitiesLoader.parse(arrayBuffer, this.props.loadOptions);
|
|
4083
|
-
return capabilities;
|
|
4084
|
-
}
|
|
4085
|
-
async getRecords(wmsParameters, vendorParameters) {
|
|
4086
|
-
const url = this.getRecordsURL(wmsParameters, vendorParameters);
|
|
4087
|
-
const response = await this.fetch(url);
|
|
4088
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4089
|
-
this._checkResponse(response, arrayBuffer);
|
|
4090
|
-
return await CSWRecordsLoader.parse(arrayBuffer, this.props.loadOptions);
|
|
4091
|
-
}
|
|
4092
|
-
async getDomain(wmsParameters, vendorParameters) {
|
|
4093
|
-
const url = this.getDomainURL(wmsParameters, vendorParameters);
|
|
4094
|
-
const response = await this.fetch(url);
|
|
4095
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4096
|
-
this._checkResponse(response, arrayBuffer);
|
|
4097
|
-
return await CSWDomainLoader.parse(arrayBuffer, this.props.loadOptions);
|
|
4098
|
-
}
|
|
4099
|
-
getCapabilitiesURL(wmsParameters, vendorParameters) {
|
|
4100
|
-
const options = {
|
|
4101
|
-
version: "3.0.0",
|
|
4102
|
-
...wmsParameters,
|
|
4103
|
-
...vendorParameters,
|
|
4104
|
-
service: "CSW",
|
|
4105
|
-
request: "GetCapabilities"
|
|
4106
|
-
};
|
|
4107
|
-
return this._getCSWUrl(options, vendorParameters);
|
|
4108
|
-
}
|
|
4109
|
-
getRecordsURL(wmsParameters, vendorParameters) {
|
|
4110
|
-
const options = {
|
|
4111
|
-
version: "3.0.0",
|
|
4112
|
-
typenames: "csw:Record",
|
|
4113
|
-
...wmsParameters,
|
|
4114
|
-
...vendorParameters,
|
|
4115
|
-
service: "CSW",
|
|
4116
|
-
request: "GetRecords"
|
|
4117
|
-
};
|
|
4118
|
-
return this._getCSWUrl(options, vendorParameters);
|
|
4119
|
-
}
|
|
4120
|
-
getDomainURL(wmsParameters, vendorParameters) {
|
|
4121
|
-
const options = {
|
|
4122
|
-
version: "3.0.0",
|
|
4123
|
-
...wmsParameters,
|
|
4124
|
-
...vendorParameters,
|
|
4125
|
-
service: "CSW",
|
|
4126
|
-
request: "GetDomain"
|
|
4127
|
-
};
|
|
4128
|
-
return this._getCSWUrl(options, vendorParameters);
|
|
4129
|
-
}
|
|
4130
|
-
_getCSWUrl(options, vendorParameters) {
|
|
4131
|
-
let url = this.props.url;
|
|
4132
|
-
let first = true;
|
|
4133
|
-
for (const [key, value] of Object.entries(options)) {
|
|
4134
|
-
url += first ? "?" : "&";
|
|
4135
|
-
first = false;
|
|
4136
|
-
if (Array.isArray(value)) {
|
|
4137
|
-
url += `${key.toUpperCase()}=${value.join(",")}`;
|
|
4138
|
-
} else {
|
|
4139
|
-
url += `${key.toUpperCase()}=${value ? String(value) : ""}`;
|
|
4140
|
-
}
|
|
4141
|
-
}
|
|
4142
|
-
return encodeURI(url);
|
|
4143
|
-
}
|
|
4144
|
-
_checkResponse(response, arrayBuffer) {
|
|
4145
|
-
const contentType = response.headers["content-type"];
|
|
4146
|
-
if (!response.ok || WMSErrorLoader.mimeTypes.includes(contentType)) {
|
|
4147
|
-
const error = WMSErrorLoader.parseSync?.(arrayBuffer, this.props.loadOptions);
|
|
4148
|
-
throw new Error(error);
|
|
4149
|
-
}
|
|
4150
|
-
}
|
|
4151
|
-
_parseError(arrayBuffer) {
|
|
4152
|
-
const error = WMSErrorLoader.parseSync?.(arrayBuffer, this.props.loadOptions);
|
|
4153
|
-
return new Error(error);
|
|
4154
|
-
}
|
|
4155
|
-
};
|
|
4156
|
-
__publicField(CSWService, "type", "csw");
|
|
4157
|
-
__publicField(CSWService, "testURL", (url) => url.toLowerCase().includes("csw"));
|
|
4158
|
-
|
|
4159
|
-
// src/services/arcgis/arcgis-server.ts
|
|
4160
|
-
async function getArcGISServices(url, fetchFile = fetch) {
|
|
4161
|
-
if (url.includes("rest/services")) {
|
|
4162
|
-
const serverUrl = url.replace(/rest\/services.*$/i, "rest/services");
|
|
4163
|
-
return loadServiceDirectory(serverUrl, fetchFile, []);
|
|
4164
|
-
}
|
|
4165
|
-
return null;
|
|
4166
|
-
}
|
|
4167
|
-
async function loadServiceDirectory(serverUrl, fetch2, path) {
|
|
4168
|
-
const serviceUrl = `${serverUrl}/${path.join("/")}`;
|
|
4169
|
-
const response = await fetch2(`${serviceUrl}?f=pjson`);
|
|
4170
|
-
const directory = await response.json();
|
|
4171
|
-
const services = extractServices(directory, serviceUrl);
|
|
4172
|
-
const folders = directory.folders || [];
|
|
4173
|
-
const promises = folders.map((folder) => loadServiceDirectory(`${serverUrl}`, fetch2, [...path, folder]));
|
|
4174
|
-
for (const folderServices of await Promise.all(promises)) {
|
|
4175
|
-
services.push(...folderServices);
|
|
4176
|
-
}
|
|
4177
|
-
return services;
|
|
4178
|
-
}
|
|
4179
|
-
function extractServices(directory, url) {
|
|
4180
|
-
const arcgisServices = directory.services || [];
|
|
4181
|
-
const services = [];
|
|
4182
|
-
for (const service of arcgisServices) {
|
|
4183
|
-
services.push({
|
|
4184
|
-
name: service.name,
|
|
4185
|
-
type: `arcgis-${service.type.toLocaleLowerCase().replace("server", "-server")}`,
|
|
4186
|
-
url: `${url}${service.name}/${service.type}`
|
|
4187
|
-
});
|
|
4188
|
-
}
|
|
4189
|
-
return services;
|
|
4190
|
-
}
|
|
4191
|
-
return __toCommonJS(src_exports);
|
|
4192
|
-
})();
|
|
4193
|
-
return __exports__;
|
|
4194
|
-
});
|