@loaders.gl/kml 4.0.0-alpha.1 → 4.0.0-alpha.11

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.
Files changed (46) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +4277 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/gpx-loader.js +82 -0
  8. package/dist/es5/gpx-loader.js.map +1 -0
  9. package/dist/es5/index.js +27 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/kml-loader.js +82 -0
  12. package/dist/es5/kml-loader.js.map +1 -0
  13. package/dist/es5/tcx-loader.js +82 -0
  14. package/dist/es5/tcx-loader.js.map +1 -0
  15. package/dist/esm/bundle.js +4 -0
  16. package/dist/esm/bundle.js.map +1 -0
  17. package/dist/esm/gpx-loader.js +55 -0
  18. package/dist/esm/gpx-loader.js.map +1 -0
  19. package/dist/esm/index.js +4 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/kml-loader.js +55 -0
  22. package/dist/esm/kml-loader.js.map +1 -0
  23. package/dist/esm/tcx-loader.js +55 -0
  24. package/dist/esm/tcx-loader.js.map +1 -0
  25. package/dist/gpx-loader.d.ts +36 -0
  26. package/dist/gpx-loader.d.ts.map +1 -0
  27. package/dist/gpx-loader.js +58 -49
  28. package/dist/index.d.ts +7 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +12 -4
  31. package/dist/kml-loader.d.ts +36 -0
  32. package/dist/kml-loader.d.ts.map +1 -0
  33. package/dist/kml-loader.js +59 -49
  34. package/dist/tcx-loader.d.ts +36 -0
  35. package/dist/tcx-loader.d.ts.map +1 -0
  36. package/dist/tcx-loader.js +60 -50
  37. package/package.json +11 -13
  38. package/src/gpx-loader.ts +35 -14
  39. package/src/index.ts +4 -0
  40. package/src/kml-loader.ts +34 -13
  41. package/src/tcx-loader.ts +34 -12
  42. package/dist/bundle.js.map +0 -1
  43. package/dist/gpx-loader.js.map +0 -1
  44. package/dist/index.js.map +0 -1
  45. package/dist/kml-loader.js.map +0 -1
  46. package/dist/tcx-loader.js.map +0 -1
@@ -0,0 +1,4277 @@
1
+ (() => {
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
15
+ var __export = (target, all) => {
16
+ __markAsModule(target);
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __reExport = (target, module, desc) => {
21
+ if (module && typeof module === "object" || typeof module === "function") {
22
+ for (let key of __getOwnPropNames(module))
23
+ if (!__hasOwnProp.call(target, key) && key !== "default")
24
+ __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
25
+ }
26
+ return target;
27
+ };
28
+ var __toModule = (module) => {
29
+ return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
30
+ };
31
+
32
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
33
+ var init_typeof = __esm({
34
+ "../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
35
+ }
36
+ });
37
+
38
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
39
+ var init_toPrimitive = __esm({
40
+ "../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() {
41
+ init_typeof();
42
+ }
43
+ });
44
+
45
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
46
+ var init_toPropertyKey = __esm({
47
+ "../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() {
48
+ init_typeof();
49
+ init_toPrimitive();
50
+ }
51
+ });
52
+
53
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
54
+ var init_defineProperty = __esm({
55
+ "../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
56
+ init_toPropertyKey();
57
+ }
58
+ });
59
+
60
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
61
+ function getPolygonSignedArea(points, options = {}) {
62
+ const {
63
+ start = 0,
64
+ end = points.length
65
+ } = options;
66
+ const dim = options.size || 2;
67
+ let area2 = 0;
68
+ for (let i = start, j = end - dim; i < end; i += dim) {
69
+ area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
70
+ j = i;
71
+ }
72
+ return area2 / 2;
73
+ }
74
+ var init_polygon_utils = __esm({
75
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
76
+ }
77
+ });
78
+
79
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
80
+ var init_polygon = __esm({
81
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
82
+ init_defineProperty();
83
+ init_polygon_utils();
84
+ }
85
+ });
86
+
87
+ // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
88
+ function earcut(positions, holeIndices, dim = 2, areas) {
89
+ const hasHoles = holeIndices && holeIndices.length;
90
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
91
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
92
+ const triangles = [];
93
+ if (!outerNode || outerNode.next === outerNode.prev)
94
+ return triangles;
95
+ let invSize;
96
+ let maxX;
97
+ let maxY;
98
+ let minX;
99
+ let minY;
100
+ let x;
101
+ let y;
102
+ if (hasHoles)
103
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
104
+ if (positions.length > 80 * dim) {
105
+ minX = maxX = positions[0];
106
+ minY = maxY = positions[1];
107
+ for (let i = dim; i < outerLen; i += dim) {
108
+ x = positions[i];
109
+ y = positions[i + 1];
110
+ if (x < minX)
111
+ minX = x;
112
+ if (y < minY)
113
+ minY = y;
114
+ if (x > maxX)
115
+ maxX = x;
116
+ if (y > maxY)
117
+ maxY = y;
118
+ }
119
+ invSize = Math.max(maxX - minX, maxY - minY);
120
+ invSize = invSize !== 0 ? 1 / invSize : 0;
121
+ }
122
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
123
+ return triangles;
124
+ }
125
+ function linkedList(data, start, end, dim, clockwise, area2) {
126
+ let i;
127
+ let last;
128
+ if (area2 === void 0) {
129
+ area2 = getPolygonSignedArea(data, {
130
+ start,
131
+ end,
132
+ size: dim
133
+ });
134
+ }
135
+ if (clockwise === area2 < 0) {
136
+ for (i = start; i < end; i += dim)
137
+ last = insertNode(i, data[i], data[i + 1], last);
138
+ } else {
139
+ for (i = end - dim; i >= start; i -= dim)
140
+ last = insertNode(i, data[i], data[i + 1], last);
141
+ }
142
+ if (last && equals(last, last.next)) {
143
+ removeNode(last);
144
+ last = last.next;
145
+ }
146
+ return last;
147
+ }
148
+ function filterPoints(start, end) {
149
+ if (!start)
150
+ return start;
151
+ if (!end)
152
+ end = start;
153
+ let p = start;
154
+ let again;
155
+ do {
156
+ again = false;
157
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
158
+ removeNode(p);
159
+ p = end = p.prev;
160
+ if (p === p.next)
161
+ break;
162
+ again = true;
163
+ } else {
164
+ p = p.next;
165
+ }
166
+ } while (again || p !== end);
167
+ return end;
168
+ }
169
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
170
+ if (!ear)
171
+ return;
172
+ if (!pass && invSize)
173
+ indexCurve(ear, minX, minY, invSize);
174
+ let stop = ear;
175
+ let prev;
176
+ let next;
177
+ while (ear.prev !== ear.next) {
178
+ prev = ear.prev;
179
+ next = ear.next;
180
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
181
+ triangles.push(prev.i / dim);
182
+ triangles.push(ear.i / dim);
183
+ triangles.push(next.i / dim);
184
+ removeNode(ear);
185
+ ear = next.next;
186
+ stop = next.next;
187
+ continue;
188
+ }
189
+ ear = next;
190
+ if (ear === stop) {
191
+ if (!pass) {
192
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
193
+ } else if (pass === 1) {
194
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
195
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
196
+ } else if (pass === 2) {
197
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
198
+ }
199
+ break;
200
+ }
201
+ }
202
+ }
203
+ function isEar(ear) {
204
+ const a = ear.prev;
205
+ const b = ear;
206
+ const c = ear.next;
207
+ if (area(a, b, c) >= 0)
208
+ return false;
209
+ let p = ear.next.next;
210
+ while (p !== ear.prev) {
211
+ if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
212
+ return false;
213
+ p = p.next;
214
+ }
215
+ return true;
216
+ }
217
+ function isEarHashed(ear, minX, minY, invSize) {
218
+ const a = ear.prev;
219
+ const b = ear;
220
+ const c = ear.next;
221
+ if (area(a, b, c) >= 0)
222
+ return false;
223
+ const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
224
+ const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
225
+ const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
226
+ const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
227
+ const minZ = zOrder(minTX, minTY, minX, minY, invSize);
228
+ const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
229
+ let p = ear.prevZ;
230
+ let n = ear.nextZ;
231
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
232
+ if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
233
+ return false;
234
+ p = p.prevZ;
235
+ if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
236
+ return false;
237
+ n = n.nextZ;
238
+ }
239
+ while (p && p.z >= minZ) {
240
+ if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
241
+ return false;
242
+ p = p.prevZ;
243
+ }
244
+ while (n && n.z <= maxZ) {
245
+ if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
246
+ return false;
247
+ n = n.nextZ;
248
+ }
249
+ return true;
250
+ }
251
+ function cureLocalIntersections(start, triangles, dim) {
252
+ let p = start;
253
+ do {
254
+ const a = p.prev;
255
+ const b = p.next.next;
256
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
257
+ triangles.push(a.i / dim);
258
+ triangles.push(p.i / dim);
259
+ triangles.push(b.i / dim);
260
+ removeNode(p);
261
+ removeNode(p.next);
262
+ p = start = b;
263
+ }
264
+ p = p.next;
265
+ } while (p !== start);
266
+ return filterPoints(p);
267
+ }
268
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
269
+ let a = start;
270
+ do {
271
+ let b = a.next.next;
272
+ while (b !== a.prev) {
273
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
274
+ let c = splitPolygon(a, b);
275
+ a = filterPoints(a, a.next);
276
+ c = filterPoints(c, c.next);
277
+ earcutLinked(a, triangles, dim, minX, minY, invSize);
278
+ earcutLinked(c, triangles, dim, minX, minY, invSize);
279
+ return;
280
+ }
281
+ b = b.next;
282
+ }
283
+ a = a.next;
284
+ } while (a !== start);
285
+ }
286
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
287
+ const queue = [];
288
+ let i;
289
+ let len;
290
+ let start;
291
+ let end;
292
+ let list;
293
+ for (i = 0, len = holeIndices.length; i < len; i++) {
294
+ start = holeIndices[i] * dim;
295
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
296
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
297
+ if (list === list.next)
298
+ list.steiner = true;
299
+ queue.push(getLeftmost(list));
300
+ }
301
+ queue.sort(compareX);
302
+ for (i = 0; i < queue.length; i++) {
303
+ eliminateHole(queue[i], outerNode);
304
+ outerNode = filterPoints(outerNode, outerNode.next);
305
+ }
306
+ return outerNode;
307
+ }
308
+ function compareX(a, b) {
309
+ return a.x - b.x;
310
+ }
311
+ function eliminateHole(hole, outerNode) {
312
+ outerNode = findHoleBridge(hole, outerNode);
313
+ if (outerNode) {
314
+ const b = splitPolygon(outerNode, hole);
315
+ filterPoints(outerNode, outerNode.next);
316
+ filterPoints(b, b.next);
317
+ }
318
+ }
319
+ function findHoleBridge(hole, outerNode) {
320
+ let p = outerNode;
321
+ const hx = hole.x;
322
+ const hy = hole.y;
323
+ let qx = -Infinity;
324
+ let m;
325
+ do {
326
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
327
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
328
+ if (x <= hx && x > qx) {
329
+ qx = x;
330
+ if (x === hx) {
331
+ if (hy === p.y)
332
+ return p;
333
+ if (hy === p.next.y)
334
+ return p.next;
335
+ }
336
+ m = p.x < p.next.x ? p : p.next;
337
+ }
338
+ }
339
+ p = p.next;
340
+ } while (p !== outerNode);
341
+ if (!m)
342
+ return null;
343
+ if (hx === qx)
344
+ return m;
345
+ const stop = m;
346
+ const mx = m.x;
347
+ const my = m.y;
348
+ let tanMin = Infinity;
349
+ let tan;
350
+ p = m;
351
+ do {
352
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
353
+ tan = Math.abs(hy - p.y) / (hx - p.x);
354
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
355
+ m = p;
356
+ tanMin = tan;
357
+ }
358
+ }
359
+ p = p.next;
360
+ } while (p !== stop);
361
+ return m;
362
+ }
363
+ function sectorContainsSector(m, p) {
364
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
365
+ }
366
+ function indexCurve(start, minX, minY, invSize) {
367
+ let p = start;
368
+ do {
369
+ if (p.z === null)
370
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
371
+ p.prevZ = p.prev;
372
+ p.nextZ = p.next;
373
+ p = p.next;
374
+ } while (p !== start);
375
+ p.prevZ.nextZ = null;
376
+ p.prevZ = null;
377
+ sortLinked(p);
378
+ }
379
+ function sortLinked(list) {
380
+ let e;
381
+ let i;
382
+ let inSize = 1;
383
+ let numMerges;
384
+ let p;
385
+ let pSize;
386
+ let q;
387
+ let qSize;
388
+ let tail;
389
+ do {
390
+ p = list;
391
+ list = null;
392
+ tail = null;
393
+ numMerges = 0;
394
+ while (p) {
395
+ numMerges++;
396
+ q = p;
397
+ pSize = 0;
398
+ for (i = 0; i < inSize; i++) {
399
+ pSize++;
400
+ q = q.nextZ;
401
+ if (!q)
402
+ break;
403
+ }
404
+ qSize = inSize;
405
+ while (pSize > 0 || qSize > 0 && q) {
406
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
407
+ e = p;
408
+ p = p.nextZ;
409
+ pSize--;
410
+ } else {
411
+ e = q;
412
+ q = q.nextZ;
413
+ qSize--;
414
+ }
415
+ if (tail)
416
+ tail.nextZ = e;
417
+ else
418
+ list = e;
419
+ e.prevZ = tail;
420
+ tail = e;
421
+ }
422
+ p = q;
423
+ }
424
+ tail.nextZ = null;
425
+ inSize *= 2;
426
+ } while (numMerges > 1);
427
+ return list;
428
+ }
429
+ function zOrder(x, y, minX, minY, invSize) {
430
+ x = 32767 * (x - minX) * invSize;
431
+ y = 32767 * (y - minY) * invSize;
432
+ x = (x | x << 8) & 16711935;
433
+ x = (x | x << 4) & 252645135;
434
+ x = (x | x << 2) & 858993459;
435
+ x = (x | x << 1) & 1431655765;
436
+ y = (y | y << 8) & 16711935;
437
+ y = (y | y << 4) & 252645135;
438
+ y = (y | y << 2) & 858993459;
439
+ y = (y | y << 1) & 1431655765;
440
+ return x | y << 1;
441
+ }
442
+ function getLeftmost(start) {
443
+ let p = start;
444
+ let leftmost = start;
445
+ do {
446
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
447
+ leftmost = p;
448
+ p = p.next;
449
+ } while (p !== start);
450
+ return leftmost;
451
+ }
452
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
453
+ return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
454
+ }
455
+ function isValidDiagonal(a, b) {
456
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
457
+ }
458
+ function area(p, q, r) {
459
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
460
+ }
461
+ function equals(p1, p2) {
462
+ return p1.x === p2.x && p1.y === p2.y;
463
+ }
464
+ function intersects(p1, q1, p2, q2) {
465
+ const o1 = sign(area(p1, q1, p2));
466
+ const o2 = sign(area(p1, q1, q2));
467
+ const o3 = sign(area(p2, q2, p1));
468
+ const o4 = sign(area(p2, q2, q1));
469
+ if (o1 !== o2 && o3 !== o4)
470
+ return true;
471
+ if (o1 === 0 && onSegment(p1, p2, q1))
472
+ return true;
473
+ if (o2 === 0 && onSegment(p1, q2, q1))
474
+ return true;
475
+ if (o3 === 0 && onSegment(p2, p1, q2))
476
+ return true;
477
+ if (o4 === 0 && onSegment(p2, q1, q2))
478
+ return true;
479
+ return false;
480
+ }
481
+ function onSegment(p, q, r) {
482
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
483
+ }
484
+ function sign(num) {
485
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
486
+ }
487
+ function intersectsPolygon(a, b) {
488
+ let p = a;
489
+ do {
490
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
491
+ return true;
492
+ p = p.next;
493
+ } while (p !== a);
494
+ return false;
495
+ }
496
+ function locallyInside(a, b) {
497
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
498
+ }
499
+ function middleInside(a, b) {
500
+ let p = a;
501
+ let inside = false;
502
+ const px = (a.x + b.x) / 2;
503
+ const py = (a.y + b.y) / 2;
504
+ do {
505
+ if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
506
+ inside = !inside;
507
+ p = p.next;
508
+ } while (p !== a);
509
+ return inside;
510
+ }
511
+ function splitPolygon(a, b) {
512
+ const a2 = new Node(a.i, a.x, a.y);
513
+ const b2 = new Node(b.i, b.x, b.y);
514
+ const an = a.next;
515
+ const bp = b.prev;
516
+ a.next = b;
517
+ b.prev = a;
518
+ a2.next = an;
519
+ an.prev = a2;
520
+ b2.next = a2;
521
+ a2.prev = b2;
522
+ bp.next = b2;
523
+ b2.prev = bp;
524
+ return b2;
525
+ }
526
+ function insertNode(i, x, y, last) {
527
+ const p = new Node(i, x, y);
528
+ if (!last) {
529
+ p.prev = p;
530
+ p.next = p;
531
+ } else {
532
+ p.next = last.next;
533
+ p.prev = last;
534
+ last.next.prev = p;
535
+ last.next = p;
536
+ }
537
+ return p;
538
+ }
539
+ function removeNode(p) {
540
+ p.next.prev = p.prev;
541
+ p.prev.next = p.next;
542
+ if (p.prevZ)
543
+ p.prevZ.nextZ = p.nextZ;
544
+ if (p.nextZ)
545
+ p.nextZ.prevZ = p.prevZ;
546
+ }
547
+ function Node(i, x, y) {
548
+ this.i = i;
549
+ this.x = x;
550
+ this.y = y;
551
+ this.prev = null;
552
+ this.next = null;
553
+ this.z = null;
554
+ this.prevZ = null;
555
+ this.nextZ = null;
556
+ this.steiner = false;
557
+ }
558
+ var init_earcut = __esm({
559
+ "../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
560
+ init_polygon_utils();
561
+ }
562
+ });
563
+
564
+ // ../../node_modules/@math.gl/polygon/dist/esm/utils.js
565
+ var init_utils = __esm({
566
+ "../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
567
+ }
568
+ });
569
+
570
+ // ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
571
+ var init_lineclip = __esm({
572
+ "../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
573
+ init_utils();
574
+ }
575
+ });
576
+
577
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
578
+ var init_cut_by_grid = __esm({
579
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
580
+ init_lineclip();
581
+ init_utils();
582
+ }
583
+ });
584
+
585
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
586
+ var init_cut_by_mercator_bounds = __esm({
587
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
588
+ init_cut_by_grid();
589
+ init_utils();
590
+ }
591
+ });
592
+
593
+ // ../../node_modules/@math.gl/polygon/dist/esm/index.js
594
+ var init_esm = __esm({
595
+ "../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
596
+ init_polygon();
597
+ init_polygon_utils();
598
+ init_earcut();
599
+ init_lineclip();
600
+ init_cut_by_grid();
601
+ init_cut_by_mercator_bounds();
602
+ init_polygon();
603
+ }
604
+ });
605
+
606
+ // ../gis/src/lib/flat-geojson-to-binary.ts
607
+ function flatGeojsonToBinary(features, geometryInfo, options) {
608
+ const propArrayTypes = extractNumericPropTypes(features);
609
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
610
+ return fillArrays(features, {
611
+ propArrayTypes,
612
+ ...geometryInfo
613
+ }, {
614
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
615
+ PositionDataType: options ? options.PositionDataType : Float32Array
616
+ });
617
+ }
618
+ function extractNumericPropTypes(features) {
619
+ const propArrayTypes = {};
620
+ for (const feature of features) {
621
+ if (feature.properties) {
622
+ for (const key in feature.properties) {
623
+ const val = feature.properties[key];
624
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
625
+ }
626
+ }
627
+ }
628
+ return propArrayTypes;
629
+ }
630
+ function fillArrays(features, geometryInfo, options) {
631
+ const {
632
+ pointPositionsCount,
633
+ pointFeaturesCount,
634
+ linePositionsCount,
635
+ linePathsCount,
636
+ lineFeaturesCount,
637
+ polygonPositionsCount,
638
+ polygonObjectsCount,
639
+ polygonRingsCount,
640
+ polygonFeaturesCount,
641
+ propArrayTypes,
642
+ coordLength
643
+ } = geometryInfo;
644
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
645
+ const hasGlobalId = features[0] && "id" in features[0];
646
+ const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
647
+ const points = {
648
+ type: "Point",
649
+ positions: new PositionDataType(pointPositionsCount * coordLength),
650
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
651
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
652
+ numericProps: {},
653
+ properties: [],
654
+ fields: []
655
+ };
656
+ const lines = {
657
+ type: "LineString",
658
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
659
+ positions: new PositionDataType(linePositionsCount * coordLength),
660
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
661
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
662
+ numericProps: {},
663
+ properties: [],
664
+ fields: []
665
+ };
666
+ const polygons = {
667
+ type: "Polygon",
668
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
669
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
670
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
671
+ triangles: [],
672
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
673
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
674
+ numericProps: {},
675
+ properties: [],
676
+ fields: []
677
+ };
678
+ for (const object of [points, lines, polygons]) {
679
+ for (const propName of numericPropKeys) {
680
+ const T = propArrayTypes[propName];
681
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
682
+ }
683
+ }
684
+ lines.pathIndices[linePathsCount] = linePositionsCount;
685
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
686
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
687
+ const indexMap = {
688
+ pointPosition: 0,
689
+ pointFeature: 0,
690
+ linePosition: 0,
691
+ linePath: 0,
692
+ lineFeature: 0,
693
+ polygonPosition: 0,
694
+ polygonObject: 0,
695
+ polygonRing: 0,
696
+ polygonFeature: 0,
697
+ feature: 0
698
+ };
699
+ for (const feature of features) {
700
+ const geometry = feature.geometry;
701
+ const properties = feature.properties || {};
702
+ switch (geometry.type) {
703
+ case "Point":
704
+ handlePoint(geometry, points, indexMap, coordLength, properties);
705
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
706
+ if (hasGlobalId) {
707
+ points.fields.push({ id: feature.id });
708
+ }
709
+ indexMap.pointFeature++;
710
+ break;
711
+ case "LineString":
712
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
713
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
714
+ if (hasGlobalId) {
715
+ lines.fields.push({ id: feature.id });
716
+ }
717
+ indexMap.lineFeature++;
718
+ break;
719
+ case "Polygon":
720
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
721
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
722
+ if (hasGlobalId) {
723
+ polygons.fields.push({ id: feature.id });
724
+ }
725
+ indexMap.polygonFeature++;
726
+ break;
727
+ default:
728
+ throw new Error("Invalid geometry type");
729
+ }
730
+ indexMap.feature++;
731
+ }
732
+ return makeAccessorObjects(points, lines, polygons, coordLength);
733
+ }
734
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
735
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
736
+ const nPositions = geometry.data.length / coordLength;
737
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
738
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
739
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
740
+ indexMap.pointPosition += nPositions;
741
+ }
742
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
743
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
744
+ const nPositions = geometry.data.length / coordLength;
745
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
746
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
747
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
748
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
749
+ const start = geometry.indices[i];
750
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
751
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
752
+ indexMap.linePosition += (end - start) / coordLength;
753
+ }
754
+ }
755
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
756
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
757
+ const nPositions = geometry.data.length / coordLength;
758
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
759
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
760
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
761
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
762
+ const startPosition = indexMap.polygonPosition;
763
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
764
+ const areas = geometry.areas[l];
765
+ const indices = geometry.indices[l];
766
+ const nextIndices = geometry.indices[l + 1];
767
+ for (let i = 0, il = indices.length; i < il; ++i) {
768
+ const start = indices[i];
769
+ const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
770
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
771
+ indexMap.polygonPosition += (end - start) / coordLength;
772
+ }
773
+ const endPosition = indexMap.polygonPosition;
774
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
775
+ }
776
+ }
777
+ function triangulatePolygon(polygons, areas, indices, {
778
+ startPosition,
779
+ endPosition,
780
+ coordLength
781
+ }) {
782
+ const start = startPosition * coordLength;
783
+ const end = endPosition * coordLength;
784
+ const polygonPositions = polygons.positions.subarray(start, end);
785
+ const offset = indices[0];
786
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
787
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
788
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
789
+ polygons.triangles.push(startPosition + triangles[t]);
790
+ }
791
+ }
792
+ function wrapProps(obj, size) {
793
+ const returnObj = {};
794
+ for (const key in obj) {
795
+ returnObj[key] = { value: obj[key], size };
796
+ }
797
+ return returnObj;
798
+ }
799
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
800
+ return {
801
+ points: {
802
+ ...points,
803
+ positions: { value: points.positions, size: coordLength },
804
+ globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
805
+ featureIds: { value: points.featureIds, size: 1 },
806
+ numericProps: wrapProps(points.numericProps, 1)
807
+ },
808
+ lines: {
809
+ ...lines,
810
+ positions: { value: lines.positions, size: coordLength },
811
+ pathIndices: { value: lines.pathIndices, size: 1 },
812
+ globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
813
+ featureIds: { value: lines.featureIds, size: 1 },
814
+ numericProps: wrapProps(lines.numericProps, 1)
815
+ },
816
+ polygons: {
817
+ ...polygons,
818
+ positions: { value: polygons.positions, size: coordLength },
819
+ polygonIndices: { value: polygons.polygonIndices, size: 1 },
820
+ primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
821
+ triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
822
+ globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
823
+ featureIds: { value: polygons.featureIds, size: 1 },
824
+ numericProps: wrapProps(polygons.numericProps, 1)
825
+ }
826
+ };
827
+ }
828
+ function fillNumericProperties(object, properties, index, length) {
829
+ for (const numericPropName in object.numericProps) {
830
+ if (numericPropName in properties) {
831
+ const value = properties[numericPropName];
832
+ object.numericProps[numericPropName].fill(value, index, index + length);
833
+ }
834
+ }
835
+ }
836
+ function keepStringProperties(properties, numericKeys) {
837
+ const props = {};
838
+ for (const key in properties) {
839
+ if (!numericKeys.includes(key)) {
840
+ props[key] = properties[key];
841
+ }
842
+ }
843
+ return props;
844
+ }
845
+ function deduceArrayType(x, constructor) {
846
+ if (constructor === Array || !Number.isFinite(x)) {
847
+ return Array;
848
+ }
849
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
850
+ }
851
+ var init_flat_geojson_to_binary = __esm({
852
+ "../gis/src/lib/flat-geojson-to-binary.ts"() {
853
+ init_esm();
854
+ }
855
+ });
856
+
857
+ // ../gis/src/lib/extract-geometry-info.ts
858
+ function extractGeometryInfo(features) {
859
+ let pointPositionsCount = 0;
860
+ let pointFeaturesCount = 0;
861
+ let linePositionsCount = 0;
862
+ let linePathsCount = 0;
863
+ let lineFeaturesCount = 0;
864
+ let polygonPositionsCount = 0;
865
+ let polygonObjectsCount = 0;
866
+ let polygonRingsCount = 0;
867
+ let polygonFeaturesCount = 0;
868
+ const coordLengths = new Set();
869
+ for (const feature of features) {
870
+ const geometry = feature.geometry;
871
+ switch (geometry.type) {
872
+ case "Point":
873
+ pointFeaturesCount++;
874
+ pointPositionsCount++;
875
+ coordLengths.add(geometry.coordinates.length);
876
+ break;
877
+ case "MultiPoint":
878
+ pointFeaturesCount++;
879
+ pointPositionsCount += geometry.coordinates.length;
880
+ for (const point of geometry.coordinates) {
881
+ coordLengths.add(point.length);
882
+ }
883
+ break;
884
+ case "LineString":
885
+ lineFeaturesCount++;
886
+ linePositionsCount += geometry.coordinates.length;
887
+ linePathsCount++;
888
+ for (const coord2 of geometry.coordinates) {
889
+ coordLengths.add(coord2.length);
890
+ }
891
+ break;
892
+ case "MultiLineString":
893
+ lineFeaturesCount++;
894
+ for (const line of geometry.coordinates) {
895
+ linePositionsCount += line.length;
896
+ linePathsCount++;
897
+ for (const coord2 of line) {
898
+ coordLengths.add(coord2.length);
899
+ }
900
+ }
901
+ break;
902
+ case "Polygon":
903
+ polygonFeaturesCount++;
904
+ polygonObjectsCount++;
905
+ polygonRingsCount += geometry.coordinates.length;
906
+ const flattened = geometry.coordinates.flat();
907
+ polygonPositionsCount += flattened.length;
908
+ for (const coord2 of flattened) {
909
+ coordLengths.add(coord2.length);
910
+ }
911
+ break;
912
+ case "MultiPolygon":
913
+ polygonFeaturesCount++;
914
+ for (const polygon of geometry.coordinates) {
915
+ polygonObjectsCount++;
916
+ polygonRingsCount += polygon.length;
917
+ const flattened2 = polygon.flat();
918
+ polygonPositionsCount += flattened2.length;
919
+ for (const coord2 of flattened2) {
920
+ coordLengths.add(coord2.length);
921
+ }
922
+ }
923
+ break;
924
+ default:
925
+ throw new Error(`Unsupported geometry type: ${geometry.type}`);
926
+ }
927
+ }
928
+ return {
929
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
930
+ pointPositionsCount,
931
+ pointFeaturesCount,
932
+ linePositionsCount,
933
+ linePathsCount,
934
+ lineFeaturesCount,
935
+ polygonPositionsCount,
936
+ polygonObjectsCount,
937
+ polygonRingsCount,
938
+ polygonFeaturesCount
939
+ };
940
+ }
941
+ var init_extract_geometry_info = __esm({
942
+ "../gis/src/lib/extract-geometry-info.ts"() {
943
+ }
944
+ });
945
+
946
+ // ../gis/src/lib/geojson-to-flat-geojson.ts
947
+ function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
948
+ return features.map((feature) => flattenFeature(feature, options));
949
+ }
950
+ function flattenPoint(coordinates, data, indices, options) {
951
+ indices.push(data.length);
952
+ data.push(...coordinates);
953
+ for (let i = coordinates.length; i < options.coordLength; i++) {
954
+ data.push(0);
955
+ }
956
+ }
957
+ function flattenLineString(coordinates, data, indices, options) {
958
+ indices.push(data.length);
959
+ for (const c of coordinates) {
960
+ data.push(...c);
961
+ for (let i = c.length; i < options.coordLength; i++) {
962
+ data.push(0);
963
+ }
964
+ }
965
+ }
966
+ function flattenPolygon(coordinates, data, indices, areas, options) {
967
+ let count = 0;
968
+ const ringAreas = [];
969
+ const polygons = [];
970
+ for (const lineString of coordinates) {
971
+ const lineString2d = lineString.map((p) => p.slice(0, 2));
972
+ let area2 = getPolygonSignedArea(lineString2d.flat());
973
+ const ccw = area2 < 0;
974
+ if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
975
+ lineString.reverse();
976
+ area2 = -area2;
977
+ }
978
+ ringAreas.push(area2);
979
+ flattenLineString(lineString, data, polygons, options);
980
+ count++;
981
+ }
982
+ if (count > 0) {
983
+ areas.push(ringAreas);
984
+ indices.push(polygons);
985
+ }
986
+ }
987
+ function flattenFeature(feature, options) {
988
+ const { geometry } = feature;
989
+ if (geometry.type === "GeometryCollection") {
990
+ throw new Error("GeometryCollection type not supported");
991
+ }
992
+ const data = [];
993
+ const indices = [];
994
+ let areas;
995
+ let type;
996
+ switch (geometry.type) {
997
+ case "Point":
998
+ type = "Point";
999
+ flattenPoint(geometry.coordinates, data, indices, options);
1000
+ break;
1001
+ case "MultiPoint":
1002
+ type = "Point";
1003
+ geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
1004
+ break;
1005
+ case "LineString":
1006
+ type = "LineString";
1007
+ flattenLineString(geometry.coordinates, data, indices, options);
1008
+ break;
1009
+ case "MultiLineString":
1010
+ type = "LineString";
1011
+ geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
1012
+ break;
1013
+ case "Polygon":
1014
+ type = "Polygon";
1015
+ areas = [];
1016
+ flattenPolygon(geometry.coordinates, data, indices, areas, options);
1017
+ break;
1018
+ case "MultiPolygon":
1019
+ type = "Polygon";
1020
+ areas = [];
1021
+ geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
1022
+ break;
1023
+ default:
1024
+ throw new Error(`Unknown type: ${type}`);
1025
+ }
1026
+ return { ...feature, geometry: { type, indices, data, areas } };
1027
+ }
1028
+ var init_geojson_to_flat_geojson = __esm({
1029
+ "../gis/src/lib/geojson-to-flat-geojson.ts"() {
1030
+ init_esm();
1031
+ }
1032
+ });
1033
+
1034
+ // ../gis/src/lib/geojson-to-binary.ts
1035
+ function geojsonToBinary(features, options = { fixRingWinding: true }) {
1036
+ const geometryInfo = extractGeometryInfo(features);
1037
+ const coordLength = geometryInfo.coordLength;
1038
+ const { fixRingWinding } = options;
1039
+ const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
1040
+ return flatGeojsonToBinary(flatFeatures, geometryInfo, {
1041
+ numericPropKeys: options.numericPropKeys,
1042
+ PositionDataType: options.PositionDataType || Float32Array
1043
+ });
1044
+ }
1045
+ var init_geojson_to_binary = __esm({
1046
+ "../gis/src/lib/geojson-to-binary.ts"() {
1047
+ init_extract_geometry_info();
1048
+ init_geojson_to_flat_geojson();
1049
+ init_flat_geojson_to_binary();
1050
+ }
1051
+ });
1052
+
1053
+ // ../gis/src/index.ts
1054
+ var init_src = __esm({
1055
+ "../gis/src/index.ts"() {
1056
+ init_geojson_to_binary();
1057
+ }
1058
+ });
1059
+
1060
+ // ../../node_modules/@tmcw/togeojson/dist/togeojson.es.js
1061
+ function nodeVal(x) {
1062
+ if (x && x.normalize) {
1063
+ x.normalize();
1064
+ }
1065
+ return x && x.textContent || "";
1066
+ }
1067
+ function get1(x, y) {
1068
+ const n = x.getElementsByTagName(y);
1069
+ return n.length ? n[0] : null;
1070
+ }
1071
+ function getLineStyle(extensions) {
1072
+ const style = {};
1073
+ if (extensions) {
1074
+ const lineStyle = get1(extensions, "line");
1075
+ if (lineStyle) {
1076
+ const color = nodeVal(get1(lineStyle, "color")), opacity = parseFloat(nodeVal(get1(lineStyle, "opacity"))), width = parseFloat(nodeVal(get1(lineStyle, "width")));
1077
+ if (color)
1078
+ style.stroke = color;
1079
+ if (!isNaN(opacity))
1080
+ style["stroke-opacity"] = opacity;
1081
+ if (!isNaN(width))
1082
+ style["stroke-width"] = width * 96 / 25.4;
1083
+ }
1084
+ }
1085
+ return style;
1086
+ }
1087
+ function getExtensions(node) {
1088
+ let values = [];
1089
+ if (node !== null) {
1090
+ for (let i = 0; i < node.childNodes.length; i++) {
1091
+ const child = node.childNodes[i];
1092
+ if (child.nodeType !== 1)
1093
+ continue;
1094
+ const name = ["heart", "gpxtpx:hr", "hr"].includes(child.nodeName) ? "heart" : child.nodeName;
1095
+ if (name === "gpxtpx:TrackPointExtension") {
1096
+ values = values.concat(getExtensions(child));
1097
+ } else {
1098
+ const val = nodeVal(child);
1099
+ values.push([name, isNaN(val) ? val : parseFloat(val)]);
1100
+ }
1101
+ }
1102
+ }
1103
+ return values;
1104
+ }
1105
+ function getMulti(x, ys) {
1106
+ const o = {};
1107
+ let n;
1108
+ let k;
1109
+ for (k = 0; k < ys.length; k++) {
1110
+ n = get1(x, ys[k]);
1111
+ if (n)
1112
+ o[ys[k]] = nodeVal(n);
1113
+ }
1114
+ return o;
1115
+ }
1116
+ function getProperties$1(node) {
1117
+ const prop = getMulti(node, [
1118
+ "name",
1119
+ "cmt",
1120
+ "desc",
1121
+ "type",
1122
+ "time",
1123
+ "keywords"
1124
+ ]);
1125
+ const extensions = node.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3", "*");
1126
+ for (let i = 0; i < extensions.length; i++) {
1127
+ const extension = extensions[i];
1128
+ if (extension.parentNode.parentNode === node) {
1129
+ prop[extension.tagName.replace(":", "_")] = nodeVal(extension);
1130
+ }
1131
+ }
1132
+ const links = node.getElementsByTagName("link");
1133
+ if (links.length)
1134
+ prop.links = [];
1135
+ for (let i = 0; i < links.length; i++) {
1136
+ prop.links.push(Object.assign({ href: links[i].getAttribute("href") }, getMulti(links[i], ["text", "type"])));
1137
+ }
1138
+ return prop;
1139
+ }
1140
+ function coordPair$1(x) {
1141
+ const ll = [
1142
+ parseFloat(x.getAttribute("lon")),
1143
+ parseFloat(x.getAttribute("lat"))
1144
+ ];
1145
+ const ele = get1(x, "ele");
1146
+ const time = get1(x, "time");
1147
+ if (ele) {
1148
+ const e = parseFloat(nodeVal(ele));
1149
+ if (!isNaN(e)) {
1150
+ ll.push(e);
1151
+ }
1152
+ }
1153
+ return {
1154
+ coordinates: ll,
1155
+ time: time ? nodeVal(time) : null,
1156
+ extendedValues: getExtensions(get1(x, "extensions"))
1157
+ };
1158
+ }
1159
+ function getRoute(node) {
1160
+ const line = getPoints$1(node, "rtept");
1161
+ if (!line)
1162
+ return;
1163
+ return {
1164
+ type: "Feature",
1165
+ properties: Object.assign(getProperties$1(node), getLineStyle(get1(node, "extensions")), { _gpxType: "rte" }),
1166
+ geometry: {
1167
+ type: "LineString",
1168
+ coordinates: line.line
1169
+ }
1170
+ };
1171
+ }
1172
+ function getPoints$1(node, pointname) {
1173
+ const pts = node.getElementsByTagName(pointname);
1174
+ if (pts.length < 2)
1175
+ return;
1176
+ const line = [];
1177
+ const times = [];
1178
+ const extendedValues = {};
1179
+ for (let i = 0; i < pts.length; i++) {
1180
+ const c = coordPair$1(pts[i]);
1181
+ line.push(c.coordinates);
1182
+ if (c.time)
1183
+ times.push(c.time);
1184
+ for (let j = 0; j < c.extendedValues.length; j++) {
1185
+ const [name, val] = c.extendedValues[j];
1186
+ const plural = name === "heart" ? name : name.replace("gpxtpx:", "") + "s";
1187
+ if (!extendedValues[plural]) {
1188
+ extendedValues[plural] = Array(pts.length).fill(null);
1189
+ }
1190
+ extendedValues[plural][i] = val;
1191
+ }
1192
+ }
1193
+ return {
1194
+ line,
1195
+ times,
1196
+ extendedValues
1197
+ };
1198
+ }
1199
+ function getTrack(node) {
1200
+ const segments = node.getElementsByTagName("trkseg");
1201
+ const track = [];
1202
+ const times = [];
1203
+ const extractedLines = [];
1204
+ for (let i = 0; i < segments.length; i++) {
1205
+ const line = getPoints$1(segments[i], "trkpt");
1206
+ if (line) {
1207
+ extractedLines.push(line);
1208
+ if (line.times && line.times.length)
1209
+ times.push(line.times);
1210
+ }
1211
+ }
1212
+ if (extractedLines.length === 0)
1213
+ return;
1214
+ const multi = extractedLines.length > 1;
1215
+ const properties = Object.assign(getProperties$1(node), getLineStyle(get1(node, "extensions")), { _gpxType: "trk" }, times.length ? {
1216
+ coordinateProperties: {
1217
+ times: multi ? times : times[0]
1218
+ }
1219
+ } : {});
1220
+ for (let i = 0; i < extractedLines.length; i++) {
1221
+ const line = extractedLines[i];
1222
+ track.push(line.line);
1223
+ for (const [name, val] of Object.entries(line.extendedValues)) {
1224
+ if (!properties.coordinateProperties) {
1225
+ properties.coordinateProperties = {};
1226
+ }
1227
+ const props = properties.coordinateProperties;
1228
+ if (multi) {
1229
+ if (!props[name])
1230
+ props[name] = extractedLines.map((line2) => new Array(line2.line.length).fill(null));
1231
+ props[name][i] = val;
1232
+ } else {
1233
+ props[name] = val;
1234
+ }
1235
+ }
1236
+ }
1237
+ return {
1238
+ type: "Feature",
1239
+ properties,
1240
+ geometry: multi ? {
1241
+ type: "MultiLineString",
1242
+ coordinates: track
1243
+ } : {
1244
+ type: "LineString",
1245
+ coordinates: track[0]
1246
+ }
1247
+ };
1248
+ }
1249
+ function getPoint(node) {
1250
+ return {
1251
+ type: "Feature",
1252
+ properties: Object.assign(getProperties$1(node), getMulti(node, ["sym"])),
1253
+ geometry: {
1254
+ type: "Point",
1255
+ coordinates: coordPair$1(node).coordinates
1256
+ }
1257
+ };
1258
+ }
1259
+ function* gpxGen(doc) {
1260
+ const tracks = doc.getElementsByTagName("trk");
1261
+ const routes = doc.getElementsByTagName("rte");
1262
+ const waypoints = doc.getElementsByTagName("wpt");
1263
+ for (let i = 0; i < tracks.length; i++) {
1264
+ const feature = getTrack(tracks[i]);
1265
+ if (feature)
1266
+ yield feature;
1267
+ }
1268
+ for (let i = 0; i < routes.length; i++) {
1269
+ const feature = getRoute(routes[i]);
1270
+ if (feature)
1271
+ yield feature;
1272
+ }
1273
+ for (let i = 0; i < waypoints.length; i++) {
1274
+ yield getPoint(waypoints[i]);
1275
+ }
1276
+ }
1277
+ function gpx(doc) {
1278
+ return {
1279
+ type: "FeatureCollection",
1280
+ features: Array.from(gpxGen(doc))
1281
+ };
1282
+ }
1283
+ function fromEntries(arr) {
1284
+ const obj = {};
1285
+ for (const [key, value] of arr) {
1286
+ obj[key] = value;
1287
+ }
1288
+ return obj;
1289
+ }
1290
+ function getProperties(node, attributeNames) {
1291
+ const properties = [];
1292
+ for (const [tag, alias] of attributeNames) {
1293
+ let elem = get1(node, tag);
1294
+ if (!elem) {
1295
+ const elements = node.getElementsByTagNameNS(EXTENSIONS_NS, tag);
1296
+ if (elements.length) {
1297
+ elem = elements[0];
1298
+ }
1299
+ }
1300
+ const val = parseFloat(nodeVal(elem));
1301
+ if (!isNaN(val)) {
1302
+ properties.push([alias, val]);
1303
+ }
1304
+ }
1305
+ return properties;
1306
+ }
1307
+ function coordPair(x) {
1308
+ const lon = nodeVal(get1(x, "LongitudeDegrees"));
1309
+ const lat = nodeVal(get1(x, "LatitudeDegrees"));
1310
+ if (!lon.length || !lat.length) {
1311
+ return null;
1312
+ }
1313
+ const ll = [parseFloat(lon), parseFloat(lat)];
1314
+ const alt = get1(x, "AltitudeMeters");
1315
+ const heartRate = get1(x, "HeartRateBpm");
1316
+ const time = get1(x, "Time");
1317
+ let a;
1318
+ if (alt) {
1319
+ a = parseFloat(nodeVal(alt));
1320
+ if (!isNaN(a)) {
1321
+ ll.push(a);
1322
+ }
1323
+ }
1324
+ return {
1325
+ coordinates: ll,
1326
+ time: time ? nodeVal(time) : null,
1327
+ heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,
1328
+ extensions: getProperties(x, TRACKPOINT_ATTRIBUTES)
1329
+ };
1330
+ }
1331
+ function getPoints(node, pointname) {
1332
+ const pts = node.getElementsByTagName(pointname);
1333
+ const line = [];
1334
+ const times = [];
1335
+ const heartRates = [];
1336
+ if (pts.length < 2)
1337
+ return null;
1338
+ const result = { extendedProperties: {} };
1339
+ for (let i = 0; i < pts.length; i++) {
1340
+ const c = coordPair(pts[i]);
1341
+ if (c === null)
1342
+ continue;
1343
+ line.push(c.coordinates);
1344
+ if (c.time)
1345
+ times.push(c.time);
1346
+ if (c.heartRate)
1347
+ heartRates.push(c.heartRate);
1348
+ for (const [alias, value] of c.extensions) {
1349
+ if (!result.extendedProperties[alias]) {
1350
+ result.extendedProperties[alias] = Array(pts.length).fill(null);
1351
+ }
1352
+ result.extendedProperties[alias][i] = value;
1353
+ }
1354
+ }
1355
+ return Object.assign(result, {
1356
+ line,
1357
+ times,
1358
+ heartRates
1359
+ });
1360
+ }
1361
+ function getLap(node) {
1362
+ const segments = node.getElementsByTagName("Track");
1363
+ const track = [];
1364
+ const times = [];
1365
+ const heartRates = [];
1366
+ const allExtendedProperties = [];
1367
+ let line;
1368
+ const properties = fromEntries(getProperties(node, LAP_ATTRIBUTES));
1369
+ const nameElement = get1(node, "Name");
1370
+ if (nameElement) {
1371
+ properties.name = nodeVal(nameElement);
1372
+ }
1373
+ for (let i = 0; i < segments.length; i++) {
1374
+ line = getPoints(segments[i], "Trackpoint");
1375
+ if (line) {
1376
+ track.push(line.line);
1377
+ if (line.times.length)
1378
+ times.push(line.times);
1379
+ if (line.heartRates.length)
1380
+ heartRates.push(line.heartRates);
1381
+ allExtendedProperties.push(line.extendedProperties);
1382
+ }
1383
+ }
1384
+ for (let i = 0; i < allExtendedProperties.length; i++) {
1385
+ const extendedProperties = allExtendedProperties[i];
1386
+ for (const property in extendedProperties) {
1387
+ if (segments.length === 1) {
1388
+ properties[property] = line.extendedProperties[property];
1389
+ } else {
1390
+ if (!properties[property]) {
1391
+ properties[property] = track.map((track2) => Array(track2.length).fill(null));
1392
+ }
1393
+ properties[property][i] = extendedProperties[property];
1394
+ }
1395
+ }
1396
+ }
1397
+ if (track.length === 0)
1398
+ return;
1399
+ if (times.length || heartRates.length) {
1400
+ properties.coordinateProperties = Object.assign(times.length ? {
1401
+ times: track.length === 1 ? times[0] : times
1402
+ } : {}, heartRates.length ? {
1403
+ heart: track.length === 1 ? heartRates[0] : heartRates
1404
+ } : {});
1405
+ }
1406
+ return {
1407
+ type: "Feature",
1408
+ properties,
1409
+ geometry: {
1410
+ type: track.length === 1 ? "LineString" : "MultiLineString",
1411
+ coordinates: track.length === 1 ? track[0] : track
1412
+ }
1413
+ };
1414
+ }
1415
+ function* tcxGen(doc) {
1416
+ const laps = doc.getElementsByTagName("Lap");
1417
+ for (let i = 0; i < laps.length; i++) {
1418
+ const feature = getLap(laps[i]);
1419
+ if (feature)
1420
+ yield feature;
1421
+ }
1422
+ const courses = doc.getElementsByTagName("Courses");
1423
+ for (let i = 0; i < courses.length; i++) {
1424
+ const feature = getLap(courses[i]);
1425
+ if (feature)
1426
+ yield feature;
1427
+ }
1428
+ }
1429
+ function tcx(doc) {
1430
+ return {
1431
+ type: "FeatureCollection",
1432
+ features: Array.from(tcxGen(doc))
1433
+ };
1434
+ }
1435
+ function okhash(x) {
1436
+ if (!x || !x.length)
1437
+ return 0;
1438
+ let h = 0;
1439
+ for (let i = 0; i < x.length; i++) {
1440
+ h = (h << 5) - h + x.charCodeAt(i) | 0;
1441
+ }
1442
+ return h;
1443
+ }
1444
+ function coord1(v) {
1445
+ return v.replace(removeSpace, "").split(",").map(parseFloat);
1446
+ }
1447
+ function coord(v) {
1448
+ return v.replace(trimSpace, "").split(splitSpace).map(coord1);
1449
+ }
1450
+ function xml2str(node) {
1451
+ if (node.xml !== void 0)
1452
+ return node.xml;
1453
+ if (node.tagName) {
1454
+ let output = node.tagName;
1455
+ for (let i = 0; i < node.attributes.length; i++) {
1456
+ output += node.attributes[i].name + node.attributes[i].value;
1457
+ }
1458
+ for (let i = 0; i < node.childNodes.length; i++) {
1459
+ output += xml2str(node.childNodes[i]);
1460
+ }
1461
+ return output;
1462
+ }
1463
+ if (node.nodeName === "#text") {
1464
+ return (node.nodeValue || node.value || "").trim();
1465
+ }
1466
+ if (node.nodeName === "#cdata-section") {
1467
+ return node.nodeValue;
1468
+ }
1469
+ return "";
1470
+ }
1471
+ function kmlColor(properties, elem, prefix) {
1472
+ let v = nodeVal(get1(elem, "color")) || "";
1473
+ const colorProp = prefix == "stroke" || prefix === "fill" ? prefix : prefix + "-color";
1474
+ if (v.substr(0, 1) === "#") {
1475
+ v = v.substr(1);
1476
+ }
1477
+ if (v.length === 6 || v.length === 3) {
1478
+ properties[colorProp] = v;
1479
+ } else if (v.length === 8) {
1480
+ properties[prefix + "-opacity"] = parseInt(v.substr(0, 2), 16) / 255;
1481
+ properties[colorProp] = "#" + v.substr(6, 2) + v.substr(4, 2) + v.substr(2, 2);
1482
+ }
1483
+ }
1484
+ function numericProperty(properties, elem, source, target) {
1485
+ const val = parseFloat(nodeVal(get1(elem, source)));
1486
+ if (!isNaN(val))
1487
+ properties[target] = val;
1488
+ }
1489
+ function gxCoords(root) {
1490
+ let elems = root.getElementsByTagName("coord");
1491
+ const coords = [];
1492
+ const times = [];
1493
+ if (elems.length === 0)
1494
+ elems = root.getElementsByTagName("gx:coord");
1495
+ for (let i = 0; i < elems.length; i++) {
1496
+ coords.push(nodeVal(elems[i]).split(" ").map(parseFloat));
1497
+ }
1498
+ const timeElems = root.getElementsByTagName("when");
1499
+ for (let j = 0; j < timeElems.length; j++)
1500
+ times.push(nodeVal(timeElems[j]));
1501
+ return {
1502
+ coords,
1503
+ times
1504
+ };
1505
+ }
1506
+ function getGeometry(root) {
1507
+ let geomNode;
1508
+ let geomNodes;
1509
+ let i;
1510
+ let j;
1511
+ let k;
1512
+ const geoms = [];
1513
+ const coordTimes = [];
1514
+ if (get1(root, "MultiGeometry")) {
1515
+ return getGeometry(get1(root, "MultiGeometry"));
1516
+ }
1517
+ if (get1(root, "MultiTrack")) {
1518
+ return getGeometry(get1(root, "MultiTrack"));
1519
+ }
1520
+ if (get1(root, "gx:MultiTrack")) {
1521
+ return getGeometry(get1(root, "gx:MultiTrack"));
1522
+ }
1523
+ for (i = 0; i < geotypes.length; i++) {
1524
+ geomNodes = root.getElementsByTagName(geotypes[i]);
1525
+ if (geomNodes) {
1526
+ for (j = 0; j < geomNodes.length; j++) {
1527
+ geomNode = geomNodes[j];
1528
+ if (geotypes[i] === "Point") {
1529
+ geoms.push({
1530
+ type: "Point",
1531
+ coordinates: coord1(nodeVal(get1(geomNode, "coordinates")))
1532
+ });
1533
+ } else if (geotypes[i] === "LineString") {
1534
+ geoms.push({
1535
+ type: "LineString",
1536
+ coordinates: coord(nodeVal(get1(geomNode, "coordinates")))
1537
+ });
1538
+ } else if (geotypes[i] === "Polygon") {
1539
+ const rings = geomNode.getElementsByTagName("LinearRing"), coords = [];
1540
+ for (k = 0; k < rings.length; k++) {
1541
+ coords.push(coord(nodeVal(get1(rings[k], "coordinates"))));
1542
+ }
1543
+ geoms.push({
1544
+ type: "Polygon",
1545
+ coordinates: coords
1546
+ });
1547
+ } else if (geotypes[i] === "Track" || geotypes[i] === "gx:Track") {
1548
+ const track = gxCoords(geomNode);
1549
+ geoms.push({
1550
+ type: "LineString",
1551
+ coordinates: track.coords
1552
+ });
1553
+ if (track.times.length)
1554
+ coordTimes.push(track.times);
1555
+ }
1556
+ }
1557
+ }
1558
+ }
1559
+ return {
1560
+ geoms,
1561
+ coordTimes
1562
+ };
1563
+ }
1564
+ function getPlacemark(root, styleIndex, styleMapIndex, styleByHash) {
1565
+ const geomsAndTimes = getGeometry(root);
1566
+ let i;
1567
+ const properties = {};
1568
+ const name = nodeVal(get1(root, "name"));
1569
+ const address = nodeVal(get1(root, "address"));
1570
+ let styleUrl = nodeVal(get1(root, "styleUrl"));
1571
+ const description = nodeVal(get1(root, "description"));
1572
+ const timeSpan = get1(root, "TimeSpan");
1573
+ const timeStamp = get1(root, "TimeStamp");
1574
+ const extendedData = get1(root, "ExtendedData");
1575
+ let iconStyle = get1(root, "IconStyle");
1576
+ let labelStyle = get1(root, "LabelStyle");
1577
+ let lineStyle = get1(root, "LineStyle");
1578
+ let polyStyle = get1(root, "PolyStyle");
1579
+ const visibility = get1(root, "visibility");
1580
+ if (name)
1581
+ properties.name = name;
1582
+ if (address)
1583
+ properties.address = address;
1584
+ if (styleUrl) {
1585
+ if (styleUrl[0] !== "#") {
1586
+ styleUrl = "#" + styleUrl;
1587
+ }
1588
+ properties.styleUrl = styleUrl;
1589
+ if (styleIndex[styleUrl]) {
1590
+ properties.styleHash = styleIndex[styleUrl];
1591
+ }
1592
+ if (styleMapIndex[styleUrl]) {
1593
+ properties.styleMapHash = styleMapIndex[styleUrl];
1594
+ properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];
1595
+ }
1596
+ const style = styleByHash[properties.styleHash];
1597
+ if (style) {
1598
+ if (!iconStyle)
1599
+ iconStyle = get1(style, "IconStyle");
1600
+ if (!labelStyle)
1601
+ labelStyle = get1(style, "LabelStyle");
1602
+ if (!lineStyle)
1603
+ lineStyle = get1(style, "LineStyle");
1604
+ if (!polyStyle)
1605
+ polyStyle = get1(style, "PolyStyle");
1606
+ }
1607
+ }
1608
+ if (description)
1609
+ properties.description = description;
1610
+ if (timeSpan) {
1611
+ const begin = nodeVal(get1(timeSpan, "begin"));
1612
+ const end = nodeVal(get1(timeSpan, "end"));
1613
+ properties.timespan = { begin, end };
1614
+ }
1615
+ if (timeStamp) {
1616
+ properties.timestamp = nodeVal(get1(timeStamp, "when"));
1617
+ }
1618
+ if (iconStyle) {
1619
+ kmlColor(properties, iconStyle, "icon");
1620
+ numericProperty(properties, iconStyle, "scale", "icon-scale");
1621
+ numericProperty(properties, iconStyle, "heading", "icon-heading");
1622
+ const hotspot = get1(iconStyle, "hotSpot");
1623
+ if (hotspot) {
1624
+ const left = parseFloat(hotspot.getAttribute("x"));
1625
+ const top = parseFloat(hotspot.getAttribute("y"));
1626
+ if (!isNaN(left) && !isNaN(top))
1627
+ properties["icon-offset"] = [left, top];
1628
+ }
1629
+ const icon = get1(iconStyle, "Icon");
1630
+ if (icon) {
1631
+ const href = nodeVal(get1(icon, "href"));
1632
+ if (href)
1633
+ properties.icon = href;
1634
+ }
1635
+ }
1636
+ if (labelStyle) {
1637
+ kmlColor(properties, labelStyle, "label");
1638
+ numericProperty(properties, labelStyle, "scale", "label-scale");
1639
+ }
1640
+ if (lineStyle) {
1641
+ kmlColor(properties, lineStyle, "stroke");
1642
+ numericProperty(properties, lineStyle, "width", "stroke-width");
1643
+ }
1644
+ if (polyStyle) {
1645
+ kmlColor(properties, polyStyle, "fill");
1646
+ const fill = nodeVal(get1(polyStyle, "fill"));
1647
+ const outline = nodeVal(get1(polyStyle, "outline"));
1648
+ if (fill)
1649
+ properties["fill-opacity"] = fill === "1" ? properties["fill-opacity"] || 1 : 0;
1650
+ if (outline)
1651
+ properties["stroke-opacity"] = outline === "1" ? properties["stroke-opacity"] || 1 : 0;
1652
+ }
1653
+ if (extendedData) {
1654
+ const datas = extendedData.getElementsByTagName("Data"), simpleDatas = extendedData.getElementsByTagName("SimpleData");
1655
+ for (i = 0; i < datas.length; i++) {
1656
+ properties[datas[i].getAttribute("name")] = nodeVal(get1(datas[i], "value"));
1657
+ }
1658
+ for (i = 0; i < simpleDatas.length; i++) {
1659
+ properties[simpleDatas[i].getAttribute("name")] = nodeVal(simpleDatas[i]);
1660
+ }
1661
+ }
1662
+ if (visibility) {
1663
+ properties.visibility = nodeVal(visibility);
1664
+ }
1665
+ if (geomsAndTimes.coordTimes.length) {
1666
+ properties.coordinateProperties = {
1667
+ times: geomsAndTimes.coordTimes.length === 1 ? geomsAndTimes.coordTimes[0] : geomsAndTimes.coordTimes
1668
+ };
1669
+ }
1670
+ const feature = {
1671
+ type: "Feature",
1672
+ geometry: geomsAndTimes.geoms.length === 0 ? null : geomsAndTimes.geoms.length === 1 ? geomsAndTimes.geoms[0] : {
1673
+ type: "GeometryCollection",
1674
+ geometries: geomsAndTimes.geoms
1675
+ },
1676
+ properties
1677
+ };
1678
+ if (root.getAttribute("id"))
1679
+ feature.id = root.getAttribute("id");
1680
+ return feature;
1681
+ }
1682
+ function* kmlGen(doc) {
1683
+ const styleIndex = {};
1684
+ const styleByHash = {};
1685
+ const styleMapIndex = {};
1686
+ const placemarks = doc.getElementsByTagName("Placemark");
1687
+ const styles = doc.getElementsByTagName("Style");
1688
+ const styleMaps = doc.getElementsByTagName("StyleMap");
1689
+ for (let k = 0; k < styles.length; k++) {
1690
+ const style = styles[k];
1691
+ const hash = okhash(xml2str(style)).toString(16);
1692
+ let id = style.getAttribute("id");
1693
+ if (!id && style.parentNode.tagName.replace("gx:", "") === "CascadingStyle") {
1694
+ id = style.parentNode.getAttribute("kml:id") || style.parentNode.getAttribute("id");
1695
+ }
1696
+ styleIndex["#" + id] = hash;
1697
+ styleByHash[hash] = style;
1698
+ }
1699
+ for (let l = 0; l < styleMaps.length; l++) {
1700
+ styleIndex["#" + styleMaps[l].getAttribute("id")] = okhash(xml2str(styleMaps[l])).toString(16);
1701
+ const pairs = styleMaps[l].getElementsByTagName("Pair");
1702
+ const pairsMap = {};
1703
+ for (let m = 0; m < pairs.length; m++) {
1704
+ pairsMap[nodeVal(get1(pairs[m], "key"))] = nodeVal(get1(pairs[m], "styleUrl"));
1705
+ }
1706
+ styleMapIndex["#" + styleMaps[l].getAttribute("id")] = pairsMap;
1707
+ }
1708
+ for (let j = 0; j < placemarks.length; j++) {
1709
+ const feature = getPlacemark(placemarks[j], styleIndex, styleMapIndex, styleByHash);
1710
+ if (feature)
1711
+ yield feature;
1712
+ }
1713
+ }
1714
+ function kml(doc) {
1715
+ return {
1716
+ type: "FeatureCollection",
1717
+ features: Array.from(kmlGen(doc))
1718
+ };
1719
+ }
1720
+ var EXTENSIONS_NS, TRACKPOINT_ATTRIBUTES, LAP_ATTRIBUTES, removeSpace, trimSpace, splitSpace, geotypes;
1721
+ var init_togeojson_es = __esm({
1722
+ "../../node_modules/@tmcw/togeojson/dist/togeojson.es.js"() {
1723
+ EXTENSIONS_NS = "http://www.garmin.com/xmlschemas/ActivityExtension/v2";
1724
+ TRACKPOINT_ATTRIBUTES = [
1725
+ ["heartRate", "heartRates"],
1726
+ ["Cadence", "cadences"],
1727
+ ["Speed", "speeds"],
1728
+ ["Watts", "watts"]
1729
+ ];
1730
+ LAP_ATTRIBUTES = [
1731
+ ["TotalTimeSeconds", "totalTimeSeconds"],
1732
+ ["DistanceMeters", "distanceMeters"],
1733
+ ["MaximumSpeed", "maxSpeed"],
1734
+ ["AverageHeartRateBpm", "avgHeartRate"],
1735
+ ["MaximumHeartRateBpm", "maxHeartRate"],
1736
+ ["AvgSpeed", "avgSpeed"],
1737
+ ["AvgWatts", "avgWatts"],
1738
+ ["MaxWatts", "maxWatts"]
1739
+ ];
1740
+ removeSpace = /\s*/g;
1741
+ trimSpace = /^\s*|\s*$/g;
1742
+ splitSpace = /\s+/;
1743
+ geotypes = ["Polygon", "LineString", "Point", "Track", "gx:Track"];
1744
+ }
1745
+ });
1746
+
1747
+ // ../../node_modules/@xmldom/xmldom/lib/conventions.js
1748
+ var require_conventions = __commonJS({
1749
+ "../../node_modules/@xmldom/xmldom/lib/conventions.js"(exports) {
1750
+ "use strict";
1751
+ function find(list, predicate, ac) {
1752
+ if (ac === void 0) {
1753
+ ac = Array.prototype;
1754
+ }
1755
+ if (list && typeof ac.find === "function") {
1756
+ return ac.find.call(list, predicate);
1757
+ }
1758
+ for (var i = 0; i < list.length; i++) {
1759
+ if (Object.prototype.hasOwnProperty.call(list, i)) {
1760
+ var item = list[i];
1761
+ if (predicate.call(void 0, item, i, list)) {
1762
+ return item;
1763
+ }
1764
+ }
1765
+ }
1766
+ }
1767
+ function freeze(object, oc) {
1768
+ if (oc === void 0) {
1769
+ oc = Object;
1770
+ }
1771
+ return oc && typeof oc.freeze === "function" ? oc.freeze(object) : object;
1772
+ }
1773
+ var MIME_TYPE = freeze({
1774
+ HTML: "text/html",
1775
+ isHTML: function(value) {
1776
+ return value === MIME_TYPE.HTML;
1777
+ },
1778
+ XML_APPLICATION: "application/xml",
1779
+ XML_TEXT: "text/xml",
1780
+ XML_XHTML_APPLICATION: "application/xhtml+xml",
1781
+ XML_SVG_IMAGE: "image/svg+xml"
1782
+ });
1783
+ var NAMESPACE = freeze({
1784
+ HTML: "http://www.w3.org/1999/xhtml",
1785
+ isHTML: function(uri) {
1786
+ return uri === NAMESPACE.HTML;
1787
+ },
1788
+ SVG: "http://www.w3.org/2000/svg",
1789
+ XML: "http://www.w3.org/XML/1998/namespace",
1790
+ XMLNS: "http://www.w3.org/2000/xmlns/"
1791
+ });
1792
+ exports.find = find;
1793
+ exports.freeze = freeze;
1794
+ exports.MIME_TYPE = MIME_TYPE;
1795
+ exports.NAMESPACE = NAMESPACE;
1796
+ }
1797
+ });
1798
+
1799
+ // ../../node_modules/@xmldom/xmldom/lib/dom.js
1800
+ var require_dom = __commonJS({
1801
+ "../../node_modules/@xmldom/xmldom/lib/dom.js"(exports) {
1802
+ var conventions = require_conventions();
1803
+ var find = conventions.find;
1804
+ var NAMESPACE = conventions.NAMESPACE;
1805
+ function notEmptyString(input) {
1806
+ return input !== "";
1807
+ }
1808
+ function splitOnASCIIWhitespace(input) {
1809
+ return input ? input.split(/[\t\n\f\r ]+/).filter(notEmptyString) : [];
1810
+ }
1811
+ function orderedSetReducer(current, element) {
1812
+ if (!current.hasOwnProperty(element)) {
1813
+ current[element] = true;
1814
+ }
1815
+ return current;
1816
+ }
1817
+ function toOrderedSet(input) {
1818
+ if (!input)
1819
+ return [];
1820
+ var list = splitOnASCIIWhitespace(input);
1821
+ return Object.keys(list.reduce(orderedSetReducer, {}));
1822
+ }
1823
+ function arrayIncludes(list) {
1824
+ return function(element) {
1825
+ return list && list.indexOf(element) !== -1;
1826
+ };
1827
+ }
1828
+ function copy2(src, dest) {
1829
+ for (var p in src) {
1830
+ if (Object.prototype.hasOwnProperty.call(src, p)) {
1831
+ dest[p] = src[p];
1832
+ }
1833
+ }
1834
+ }
1835
+ function _extends(Class, Super) {
1836
+ var pt = Class.prototype;
1837
+ if (!(pt instanceof Super)) {
1838
+ let t2 = function() {
1839
+ };
1840
+ var t = t2;
1841
+ ;
1842
+ t2.prototype = Super.prototype;
1843
+ t2 = new t2();
1844
+ copy2(pt, t2);
1845
+ Class.prototype = pt = t2;
1846
+ }
1847
+ if (pt.constructor != Class) {
1848
+ if (typeof Class != "function") {
1849
+ console.error("unknown Class:" + Class);
1850
+ }
1851
+ pt.constructor = Class;
1852
+ }
1853
+ }
1854
+ var NodeType = {};
1855
+ var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
1856
+ var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
1857
+ var TEXT_NODE = NodeType.TEXT_NODE = 3;
1858
+ var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
1859
+ var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
1860
+ var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
1861
+ var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
1862
+ var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
1863
+ var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
1864
+ var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
1865
+ var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
1866
+ var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
1867
+ var ExceptionCode = {};
1868
+ var ExceptionMessage = {};
1869
+ var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = (ExceptionMessage[1] = "Index size error", 1);
1870
+ var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = (ExceptionMessage[2] = "DOMString size error", 2);
1871
+ var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = (ExceptionMessage[3] = "Hierarchy request error", 3);
1872
+ var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = (ExceptionMessage[4] = "Wrong document", 4);
1873
+ var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = (ExceptionMessage[5] = "Invalid character", 5);
1874
+ var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = (ExceptionMessage[6] = "No data allowed", 6);
1875
+ var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = (ExceptionMessage[7] = "No modification allowed", 7);
1876
+ var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = (ExceptionMessage[8] = "Not found", 8);
1877
+ var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = (ExceptionMessage[9] = "Not supported", 9);
1878
+ var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = (ExceptionMessage[10] = "Attribute in use", 10);
1879
+ var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = (ExceptionMessage[11] = "Invalid state", 11);
1880
+ var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = (ExceptionMessage[12] = "Syntax error", 12);
1881
+ var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = (ExceptionMessage[13] = "Invalid modification", 13);
1882
+ var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = (ExceptionMessage[14] = "Invalid namespace", 14);
1883
+ var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = (ExceptionMessage[15] = "Invalid access", 15);
1884
+ function DOMException(code, message) {
1885
+ if (message instanceof Error) {
1886
+ var error = message;
1887
+ } else {
1888
+ error = this;
1889
+ Error.call(this, ExceptionMessage[code]);
1890
+ this.message = ExceptionMessage[code];
1891
+ if (Error.captureStackTrace)
1892
+ Error.captureStackTrace(this, DOMException);
1893
+ }
1894
+ error.code = code;
1895
+ if (message)
1896
+ this.message = this.message + ": " + message;
1897
+ return error;
1898
+ }
1899
+ DOMException.prototype = Error.prototype;
1900
+ copy2(ExceptionCode, DOMException);
1901
+ function NodeList() {
1902
+ }
1903
+ NodeList.prototype = {
1904
+ length: 0,
1905
+ item: function(index) {
1906
+ return this[index] || null;
1907
+ },
1908
+ toString: function(isHTML, nodeFilter) {
1909
+ for (var buf = [], i = 0; i < this.length; i++) {
1910
+ serializeToString(this[i], buf, isHTML, nodeFilter);
1911
+ }
1912
+ return buf.join("");
1913
+ },
1914
+ filter: function(predicate) {
1915
+ return Array.prototype.filter.call(this, predicate);
1916
+ },
1917
+ indexOf: function(item) {
1918
+ return Array.prototype.indexOf.call(this, item);
1919
+ }
1920
+ };
1921
+ function LiveNodeList(node, refresh) {
1922
+ this._node = node;
1923
+ this._refresh = refresh;
1924
+ _updateLiveList(this);
1925
+ }
1926
+ function _updateLiveList(list) {
1927
+ var inc = list._node._inc || list._node.ownerDocument._inc;
1928
+ if (list._inc != inc) {
1929
+ var ls = list._refresh(list._node);
1930
+ __set__(list, "length", ls.length);
1931
+ copy2(ls, list);
1932
+ list._inc = inc;
1933
+ }
1934
+ }
1935
+ LiveNodeList.prototype.item = function(i) {
1936
+ _updateLiveList(this);
1937
+ return this[i];
1938
+ };
1939
+ _extends(LiveNodeList, NodeList);
1940
+ function NamedNodeMap() {
1941
+ }
1942
+ function _findNodeIndex(list, node) {
1943
+ var i = list.length;
1944
+ while (i--) {
1945
+ if (list[i] === node) {
1946
+ return i;
1947
+ }
1948
+ }
1949
+ }
1950
+ function _addNamedNode(el, list, newAttr, oldAttr) {
1951
+ if (oldAttr) {
1952
+ list[_findNodeIndex(list, oldAttr)] = newAttr;
1953
+ } else {
1954
+ list[list.length++] = newAttr;
1955
+ }
1956
+ if (el) {
1957
+ newAttr.ownerElement = el;
1958
+ var doc = el.ownerDocument;
1959
+ if (doc) {
1960
+ oldAttr && _onRemoveAttribute(doc, el, oldAttr);
1961
+ _onAddAttribute(doc, el, newAttr);
1962
+ }
1963
+ }
1964
+ }
1965
+ function _removeNamedNode(el, list, attr) {
1966
+ var i = _findNodeIndex(list, attr);
1967
+ if (i >= 0) {
1968
+ var lastIndex = list.length - 1;
1969
+ while (i < lastIndex) {
1970
+ list[i] = list[++i];
1971
+ }
1972
+ list.length = lastIndex;
1973
+ if (el) {
1974
+ var doc = el.ownerDocument;
1975
+ if (doc) {
1976
+ _onRemoveAttribute(doc, el, attr);
1977
+ attr.ownerElement = null;
1978
+ }
1979
+ }
1980
+ } else {
1981
+ throw new DOMException(NOT_FOUND_ERR, new Error(el.tagName + "@" + attr));
1982
+ }
1983
+ }
1984
+ NamedNodeMap.prototype = {
1985
+ length: 0,
1986
+ item: NodeList.prototype.item,
1987
+ getNamedItem: function(key) {
1988
+ var i = this.length;
1989
+ while (i--) {
1990
+ var attr = this[i];
1991
+ if (attr.nodeName == key) {
1992
+ return attr;
1993
+ }
1994
+ }
1995
+ },
1996
+ setNamedItem: function(attr) {
1997
+ var el = attr.ownerElement;
1998
+ if (el && el != this._ownerElement) {
1999
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
2000
+ }
2001
+ var oldAttr = this.getNamedItem(attr.nodeName);
2002
+ _addNamedNode(this._ownerElement, this, attr, oldAttr);
2003
+ return oldAttr;
2004
+ },
2005
+ setNamedItemNS: function(attr) {
2006
+ var el = attr.ownerElement, oldAttr;
2007
+ if (el && el != this._ownerElement) {
2008
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
2009
+ }
2010
+ oldAttr = this.getNamedItemNS(attr.namespaceURI, attr.localName);
2011
+ _addNamedNode(this._ownerElement, this, attr, oldAttr);
2012
+ return oldAttr;
2013
+ },
2014
+ removeNamedItem: function(key) {
2015
+ var attr = this.getNamedItem(key);
2016
+ _removeNamedNode(this._ownerElement, this, attr);
2017
+ return attr;
2018
+ },
2019
+ removeNamedItemNS: function(namespaceURI, localName) {
2020
+ var attr = this.getNamedItemNS(namespaceURI, localName);
2021
+ _removeNamedNode(this._ownerElement, this, attr);
2022
+ return attr;
2023
+ },
2024
+ getNamedItemNS: function(namespaceURI, localName) {
2025
+ var i = this.length;
2026
+ while (i--) {
2027
+ var node = this[i];
2028
+ if (node.localName == localName && node.namespaceURI == namespaceURI) {
2029
+ return node;
2030
+ }
2031
+ }
2032
+ return null;
2033
+ }
2034
+ };
2035
+ function DOMImplementation() {
2036
+ }
2037
+ DOMImplementation.prototype = {
2038
+ hasFeature: function(feature, version) {
2039
+ return true;
2040
+ },
2041
+ createDocument: function(namespaceURI, qualifiedName, doctype) {
2042
+ var doc = new Document();
2043
+ doc.implementation = this;
2044
+ doc.childNodes = new NodeList();
2045
+ doc.doctype = doctype || null;
2046
+ if (doctype) {
2047
+ doc.appendChild(doctype);
2048
+ }
2049
+ if (qualifiedName) {
2050
+ var root = doc.createElementNS(namespaceURI, qualifiedName);
2051
+ doc.appendChild(root);
2052
+ }
2053
+ return doc;
2054
+ },
2055
+ createDocumentType: function(qualifiedName, publicId, systemId) {
2056
+ var node = new DocumentType();
2057
+ node.name = qualifiedName;
2058
+ node.nodeName = qualifiedName;
2059
+ node.publicId = publicId || "";
2060
+ node.systemId = systemId || "";
2061
+ return node;
2062
+ }
2063
+ };
2064
+ function Node2() {
2065
+ }
2066
+ Node2.prototype = {
2067
+ firstChild: null,
2068
+ lastChild: null,
2069
+ previousSibling: null,
2070
+ nextSibling: null,
2071
+ attributes: null,
2072
+ parentNode: null,
2073
+ childNodes: null,
2074
+ ownerDocument: null,
2075
+ nodeValue: null,
2076
+ namespaceURI: null,
2077
+ prefix: null,
2078
+ localName: null,
2079
+ insertBefore: function(newChild, refChild) {
2080
+ return _insertBefore(this, newChild, refChild);
2081
+ },
2082
+ replaceChild: function(newChild, oldChild) {
2083
+ _insertBefore(this, newChild, oldChild, assertPreReplacementValidityInDocument);
2084
+ if (oldChild) {
2085
+ this.removeChild(oldChild);
2086
+ }
2087
+ },
2088
+ removeChild: function(oldChild) {
2089
+ return _removeChild(this, oldChild);
2090
+ },
2091
+ appendChild: function(newChild) {
2092
+ return this.insertBefore(newChild, null);
2093
+ },
2094
+ hasChildNodes: function() {
2095
+ return this.firstChild != null;
2096
+ },
2097
+ cloneNode: function(deep) {
2098
+ return cloneNode(this.ownerDocument || this, this, deep);
2099
+ },
2100
+ normalize: function() {
2101
+ var child = this.firstChild;
2102
+ while (child) {
2103
+ var next = child.nextSibling;
2104
+ if (next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE) {
2105
+ this.removeChild(next);
2106
+ child.appendData(next.data);
2107
+ } else {
2108
+ child.normalize();
2109
+ child = next;
2110
+ }
2111
+ }
2112
+ },
2113
+ isSupported: function(feature, version) {
2114
+ return this.ownerDocument.implementation.hasFeature(feature, version);
2115
+ },
2116
+ hasAttributes: function() {
2117
+ return this.attributes.length > 0;
2118
+ },
2119
+ lookupPrefix: function(namespaceURI) {
2120
+ var el = this;
2121
+ while (el) {
2122
+ var map = el._nsMap;
2123
+ if (map) {
2124
+ for (var n in map) {
2125
+ if (Object.prototype.hasOwnProperty.call(map, n) && map[n] === namespaceURI) {
2126
+ return n;
2127
+ }
2128
+ }
2129
+ }
2130
+ el = el.nodeType == ATTRIBUTE_NODE ? el.ownerDocument : el.parentNode;
2131
+ }
2132
+ return null;
2133
+ },
2134
+ lookupNamespaceURI: function(prefix) {
2135
+ var el = this;
2136
+ while (el) {
2137
+ var map = el._nsMap;
2138
+ if (map) {
2139
+ if (prefix in map) {
2140
+ if (Object.prototype.hasOwnProperty.call(map, prefix)) {
2141
+ return map[prefix];
2142
+ }
2143
+ }
2144
+ }
2145
+ el = el.nodeType == ATTRIBUTE_NODE ? el.ownerDocument : el.parentNode;
2146
+ }
2147
+ return null;
2148
+ },
2149
+ isDefaultNamespace: function(namespaceURI) {
2150
+ var prefix = this.lookupPrefix(namespaceURI);
2151
+ return prefix == null;
2152
+ }
2153
+ };
2154
+ function _xmlEncoder(c) {
2155
+ return c == "<" && "&lt;" || c == ">" && "&gt;" || c == "&" && "&amp;" || c == '"' && "&quot;" || "&#" + c.charCodeAt() + ";";
2156
+ }
2157
+ copy2(NodeType, Node2);
2158
+ copy2(NodeType, Node2.prototype);
2159
+ function _visitNode(node, callback) {
2160
+ if (callback(node)) {
2161
+ return true;
2162
+ }
2163
+ if (node = node.firstChild) {
2164
+ do {
2165
+ if (_visitNode(node, callback)) {
2166
+ return true;
2167
+ }
2168
+ } while (node = node.nextSibling);
2169
+ }
2170
+ }
2171
+ function Document() {
2172
+ this.ownerDocument = this;
2173
+ }
2174
+ function _onAddAttribute(doc, el, newAttr) {
2175
+ doc && doc._inc++;
2176
+ var ns = newAttr.namespaceURI;
2177
+ if (ns === NAMESPACE.XMLNS) {
2178
+ el._nsMap[newAttr.prefix ? newAttr.localName : ""] = newAttr.value;
2179
+ }
2180
+ }
2181
+ function _onRemoveAttribute(doc, el, newAttr, remove) {
2182
+ doc && doc._inc++;
2183
+ var ns = newAttr.namespaceURI;
2184
+ if (ns === NAMESPACE.XMLNS) {
2185
+ delete el._nsMap[newAttr.prefix ? newAttr.localName : ""];
2186
+ }
2187
+ }
2188
+ function _onUpdateChild(doc, el, newChild) {
2189
+ if (doc && doc._inc) {
2190
+ doc._inc++;
2191
+ var cs = el.childNodes;
2192
+ if (newChild) {
2193
+ cs[cs.length++] = newChild;
2194
+ } else {
2195
+ var child = el.firstChild;
2196
+ var i = 0;
2197
+ while (child) {
2198
+ cs[i++] = child;
2199
+ child = child.nextSibling;
2200
+ }
2201
+ cs.length = i;
2202
+ delete cs[cs.length];
2203
+ }
2204
+ }
2205
+ }
2206
+ function _removeChild(parentNode, child) {
2207
+ var previous = child.previousSibling;
2208
+ var next = child.nextSibling;
2209
+ if (previous) {
2210
+ previous.nextSibling = next;
2211
+ } else {
2212
+ parentNode.firstChild = next;
2213
+ }
2214
+ if (next) {
2215
+ next.previousSibling = previous;
2216
+ } else {
2217
+ parentNode.lastChild = previous;
2218
+ }
2219
+ child.parentNode = null;
2220
+ child.previousSibling = null;
2221
+ child.nextSibling = null;
2222
+ _onUpdateChild(parentNode.ownerDocument, parentNode);
2223
+ return child;
2224
+ }
2225
+ function hasValidParentNodeType(node) {
2226
+ return node && (node.nodeType === Node2.DOCUMENT_NODE || node.nodeType === Node2.DOCUMENT_FRAGMENT_NODE || node.nodeType === Node2.ELEMENT_NODE);
2227
+ }
2228
+ function hasInsertableNodeType(node) {
2229
+ return node && (isElementNode(node) || isTextNode(node) || isDocTypeNode(node) || node.nodeType === Node2.DOCUMENT_FRAGMENT_NODE || node.nodeType === Node2.COMMENT_NODE || node.nodeType === Node2.PROCESSING_INSTRUCTION_NODE);
2230
+ }
2231
+ function isDocTypeNode(node) {
2232
+ return node && node.nodeType === Node2.DOCUMENT_TYPE_NODE;
2233
+ }
2234
+ function isElementNode(node) {
2235
+ return node && node.nodeType === Node2.ELEMENT_NODE;
2236
+ }
2237
+ function isTextNode(node) {
2238
+ return node && node.nodeType === Node2.TEXT_NODE;
2239
+ }
2240
+ function isElementInsertionPossible(doc, child) {
2241
+ var parentChildNodes = doc.childNodes || [];
2242
+ if (find(parentChildNodes, isElementNode) || isDocTypeNode(child)) {
2243
+ return false;
2244
+ }
2245
+ var docTypeNode = find(parentChildNodes, isDocTypeNode);
2246
+ return !(child && docTypeNode && parentChildNodes.indexOf(docTypeNode) > parentChildNodes.indexOf(child));
2247
+ }
2248
+ function isElementReplacementPossible(doc, child) {
2249
+ var parentChildNodes = doc.childNodes || [];
2250
+ function hasElementChildThatIsNotChild(node) {
2251
+ return isElementNode(node) && node !== child;
2252
+ }
2253
+ if (find(parentChildNodes, hasElementChildThatIsNotChild)) {
2254
+ return false;
2255
+ }
2256
+ var docTypeNode = find(parentChildNodes, isDocTypeNode);
2257
+ return !(child && docTypeNode && parentChildNodes.indexOf(docTypeNode) > parentChildNodes.indexOf(child));
2258
+ }
2259
+ function assertPreInsertionValidity1to5(parent, node, child) {
2260
+ if (!hasValidParentNodeType(parent)) {
2261
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Unexpected parent node type " + parent.nodeType);
2262
+ }
2263
+ if (child && child.parentNode !== parent) {
2264
+ throw new DOMException(NOT_FOUND_ERR, "child not in parent");
2265
+ }
2266
+ if (!hasInsertableNodeType(node) || isDocTypeNode(node) && parent.nodeType !== Node2.DOCUMENT_NODE) {
2267
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Unexpected node type " + node.nodeType + " for parent node type " + parent.nodeType);
2268
+ }
2269
+ }
2270
+ function assertPreInsertionValidityInDocument(parent, node, child) {
2271
+ var parentChildNodes = parent.childNodes || [];
2272
+ var nodeChildNodes = node.childNodes || [];
2273
+ if (node.nodeType === Node2.DOCUMENT_FRAGMENT_NODE) {
2274
+ var nodeChildElements = nodeChildNodes.filter(isElementNode);
2275
+ if (nodeChildElements.length > 1 || find(nodeChildNodes, isTextNode)) {
2276
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "More than one element or text in fragment");
2277
+ }
2278
+ if (nodeChildElements.length === 1 && !isElementInsertionPossible(parent, child)) {
2279
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Element in fragment can not be inserted before doctype");
2280
+ }
2281
+ }
2282
+ if (isElementNode(node)) {
2283
+ if (!isElementInsertionPossible(parent, child)) {
2284
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Only one element can be added and only after doctype");
2285
+ }
2286
+ }
2287
+ if (isDocTypeNode(node)) {
2288
+ if (find(parentChildNodes, isDocTypeNode)) {
2289
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Only one doctype is allowed");
2290
+ }
2291
+ var parentElementChild = find(parentChildNodes, isElementNode);
2292
+ if (child && parentChildNodes.indexOf(parentElementChild) < parentChildNodes.indexOf(child)) {
2293
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Doctype can only be inserted before an element");
2294
+ }
2295
+ if (!child && parentElementChild) {
2296
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Doctype can not be appended since element is present");
2297
+ }
2298
+ }
2299
+ }
2300
+ function assertPreReplacementValidityInDocument(parent, node, child) {
2301
+ var parentChildNodes = parent.childNodes || [];
2302
+ var nodeChildNodes = node.childNodes || [];
2303
+ if (node.nodeType === Node2.DOCUMENT_FRAGMENT_NODE) {
2304
+ var nodeChildElements = nodeChildNodes.filter(isElementNode);
2305
+ if (nodeChildElements.length > 1 || find(nodeChildNodes, isTextNode)) {
2306
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "More than one element or text in fragment");
2307
+ }
2308
+ if (nodeChildElements.length === 1 && !isElementReplacementPossible(parent, child)) {
2309
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Element in fragment can not be inserted before doctype");
2310
+ }
2311
+ }
2312
+ if (isElementNode(node)) {
2313
+ if (!isElementReplacementPossible(parent, child)) {
2314
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Only one element can be added and only after doctype");
2315
+ }
2316
+ }
2317
+ if (isDocTypeNode(node)) {
2318
+ let hasDoctypeChildThatIsNotChild2 = function(node2) {
2319
+ return isDocTypeNode(node2) && node2 !== child;
2320
+ };
2321
+ var hasDoctypeChildThatIsNotChild = hasDoctypeChildThatIsNotChild2;
2322
+ if (find(parentChildNodes, hasDoctypeChildThatIsNotChild2)) {
2323
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Only one doctype is allowed");
2324
+ }
2325
+ var parentElementChild = find(parentChildNodes, isElementNode);
2326
+ if (child && parentChildNodes.indexOf(parentElementChild) < parentChildNodes.indexOf(child)) {
2327
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Doctype can only be inserted before an element");
2328
+ }
2329
+ }
2330
+ }
2331
+ function _insertBefore(parent, node, child, _inDocumentAssertion) {
2332
+ assertPreInsertionValidity1to5(parent, node, child);
2333
+ if (parent.nodeType === Node2.DOCUMENT_NODE) {
2334
+ (_inDocumentAssertion || assertPreInsertionValidityInDocument)(parent, node, child);
2335
+ }
2336
+ var cp = node.parentNode;
2337
+ if (cp) {
2338
+ cp.removeChild(node);
2339
+ }
2340
+ if (node.nodeType === DOCUMENT_FRAGMENT_NODE) {
2341
+ var newFirst = node.firstChild;
2342
+ if (newFirst == null) {
2343
+ return node;
2344
+ }
2345
+ var newLast = node.lastChild;
2346
+ } else {
2347
+ newFirst = newLast = node;
2348
+ }
2349
+ var pre = child ? child.previousSibling : parent.lastChild;
2350
+ newFirst.previousSibling = pre;
2351
+ newLast.nextSibling = child;
2352
+ if (pre) {
2353
+ pre.nextSibling = newFirst;
2354
+ } else {
2355
+ parent.firstChild = newFirst;
2356
+ }
2357
+ if (child == null) {
2358
+ parent.lastChild = newLast;
2359
+ } else {
2360
+ child.previousSibling = newLast;
2361
+ }
2362
+ do {
2363
+ newFirst.parentNode = parent;
2364
+ } while (newFirst !== newLast && (newFirst = newFirst.nextSibling));
2365
+ _onUpdateChild(parent.ownerDocument || parent, parent);
2366
+ if (node.nodeType == DOCUMENT_FRAGMENT_NODE) {
2367
+ node.firstChild = node.lastChild = null;
2368
+ }
2369
+ return node;
2370
+ }
2371
+ function _appendSingleChild(parentNode, newChild) {
2372
+ if (newChild.parentNode) {
2373
+ newChild.parentNode.removeChild(newChild);
2374
+ }
2375
+ newChild.parentNode = parentNode;
2376
+ newChild.previousSibling = parentNode.lastChild;
2377
+ newChild.nextSibling = null;
2378
+ if (newChild.previousSibling) {
2379
+ newChild.previousSibling.nextSibling = newChild;
2380
+ } else {
2381
+ parentNode.firstChild = newChild;
2382
+ }
2383
+ parentNode.lastChild = newChild;
2384
+ _onUpdateChild(parentNode.ownerDocument, parentNode, newChild);
2385
+ return newChild;
2386
+ }
2387
+ Document.prototype = {
2388
+ nodeName: "#document",
2389
+ nodeType: DOCUMENT_NODE,
2390
+ doctype: null,
2391
+ documentElement: null,
2392
+ _inc: 1,
2393
+ insertBefore: function(newChild, refChild) {
2394
+ if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
2395
+ var child = newChild.firstChild;
2396
+ while (child) {
2397
+ var next = child.nextSibling;
2398
+ this.insertBefore(child, refChild);
2399
+ child = next;
2400
+ }
2401
+ return newChild;
2402
+ }
2403
+ _insertBefore(this, newChild, refChild);
2404
+ newChild.ownerDocument = this;
2405
+ if (this.documentElement === null && newChild.nodeType === ELEMENT_NODE) {
2406
+ this.documentElement = newChild;
2407
+ }
2408
+ return newChild;
2409
+ },
2410
+ removeChild: function(oldChild) {
2411
+ if (this.documentElement == oldChild) {
2412
+ this.documentElement = null;
2413
+ }
2414
+ return _removeChild(this, oldChild);
2415
+ },
2416
+ replaceChild: function(newChild, oldChild) {
2417
+ _insertBefore(this, newChild, oldChild, assertPreReplacementValidityInDocument);
2418
+ newChild.ownerDocument = this;
2419
+ if (oldChild) {
2420
+ this.removeChild(oldChild);
2421
+ }
2422
+ if (isElementNode(newChild)) {
2423
+ this.documentElement = newChild;
2424
+ }
2425
+ },
2426
+ importNode: function(importedNode, deep) {
2427
+ return importNode(this, importedNode, deep);
2428
+ },
2429
+ getElementById: function(id) {
2430
+ var rtv = null;
2431
+ _visitNode(this.documentElement, function(node) {
2432
+ if (node.nodeType == ELEMENT_NODE) {
2433
+ if (node.getAttribute("id") == id) {
2434
+ rtv = node;
2435
+ return true;
2436
+ }
2437
+ }
2438
+ });
2439
+ return rtv;
2440
+ },
2441
+ getElementsByClassName: function(classNames) {
2442
+ var classNamesSet = toOrderedSet(classNames);
2443
+ return new LiveNodeList(this, function(base) {
2444
+ var ls = [];
2445
+ if (classNamesSet.length > 0) {
2446
+ _visitNode(base.documentElement, function(node) {
2447
+ if (node !== base && node.nodeType === ELEMENT_NODE) {
2448
+ var nodeClassNames = node.getAttribute("class");
2449
+ if (nodeClassNames) {
2450
+ var matches = classNames === nodeClassNames;
2451
+ if (!matches) {
2452
+ var nodeClassNamesSet = toOrderedSet(nodeClassNames);
2453
+ matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
2454
+ }
2455
+ if (matches) {
2456
+ ls.push(node);
2457
+ }
2458
+ }
2459
+ }
2460
+ });
2461
+ }
2462
+ return ls;
2463
+ });
2464
+ },
2465
+ createElement: function(tagName) {
2466
+ var node = new Element();
2467
+ node.ownerDocument = this;
2468
+ node.nodeName = tagName;
2469
+ node.tagName = tagName;
2470
+ node.localName = tagName;
2471
+ node.childNodes = new NodeList();
2472
+ var attrs = node.attributes = new NamedNodeMap();
2473
+ attrs._ownerElement = node;
2474
+ return node;
2475
+ },
2476
+ createDocumentFragment: function() {
2477
+ var node = new DocumentFragment();
2478
+ node.ownerDocument = this;
2479
+ node.childNodes = new NodeList();
2480
+ return node;
2481
+ },
2482
+ createTextNode: function(data) {
2483
+ var node = new Text();
2484
+ node.ownerDocument = this;
2485
+ node.appendData(data);
2486
+ return node;
2487
+ },
2488
+ createComment: function(data) {
2489
+ var node = new Comment();
2490
+ node.ownerDocument = this;
2491
+ node.appendData(data);
2492
+ return node;
2493
+ },
2494
+ createCDATASection: function(data) {
2495
+ var node = new CDATASection();
2496
+ node.ownerDocument = this;
2497
+ node.appendData(data);
2498
+ return node;
2499
+ },
2500
+ createProcessingInstruction: function(target, data) {
2501
+ var node = new ProcessingInstruction();
2502
+ node.ownerDocument = this;
2503
+ node.tagName = node.target = target;
2504
+ node.nodeValue = node.data = data;
2505
+ return node;
2506
+ },
2507
+ createAttribute: function(name) {
2508
+ var node = new Attr();
2509
+ node.ownerDocument = this;
2510
+ node.name = name;
2511
+ node.nodeName = name;
2512
+ node.localName = name;
2513
+ node.specified = true;
2514
+ return node;
2515
+ },
2516
+ createEntityReference: function(name) {
2517
+ var node = new EntityReference();
2518
+ node.ownerDocument = this;
2519
+ node.nodeName = name;
2520
+ return node;
2521
+ },
2522
+ createElementNS: function(namespaceURI, qualifiedName) {
2523
+ var node = new Element();
2524
+ var pl = qualifiedName.split(":");
2525
+ var attrs = node.attributes = new NamedNodeMap();
2526
+ node.childNodes = new NodeList();
2527
+ node.ownerDocument = this;
2528
+ node.nodeName = qualifiedName;
2529
+ node.tagName = qualifiedName;
2530
+ node.namespaceURI = namespaceURI;
2531
+ if (pl.length == 2) {
2532
+ node.prefix = pl[0];
2533
+ node.localName = pl[1];
2534
+ } else {
2535
+ node.localName = qualifiedName;
2536
+ }
2537
+ attrs._ownerElement = node;
2538
+ return node;
2539
+ },
2540
+ createAttributeNS: function(namespaceURI, qualifiedName) {
2541
+ var node = new Attr();
2542
+ var pl = qualifiedName.split(":");
2543
+ node.ownerDocument = this;
2544
+ node.nodeName = qualifiedName;
2545
+ node.name = qualifiedName;
2546
+ node.namespaceURI = namespaceURI;
2547
+ node.specified = true;
2548
+ if (pl.length == 2) {
2549
+ node.prefix = pl[0];
2550
+ node.localName = pl[1];
2551
+ } else {
2552
+ node.localName = qualifiedName;
2553
+ }
2554
+ return node;
2555
+ }
2556
+ };
2557
+ _extends(Document, Node2);
2558
+ function Element() {
2559
+ this._nsMap = {};
2560
+ }
2561
+ Element.prototype = {
2562
+ nodeType: ELEMENT_NODE,
2563
+ hasAttribute: function(name) {
2564
+ return this.getAttributeNode(name) != null;
2565
+ },
2566
+ getAttribute: function(name) {
2567
+ var attr = this.getAttributeNode(name);
2568
+ return attr && attr.value || "";
2569
+ },
2570
+ getAttributeNode: function(name) {
2571
+ return this.attributes.getNamedItem(name);
2572
+ },
2573
+ setAttribute: function(name, value) {
2574
+ var attr = this.ownerDocument.createAttribute(name);
2575
+ attr.value = attr.nodeValue = "" + value;
2576
+ this.setAttributeNode(attr);
2577
+ },
2578
+ removeAttribute: function(name) {
2579
+ var attr = this.getAttributeNode(name);
2580
+ attr && this.removeAttributeNode(attr);
2581
+ },
2582
+ appendChild: function(newChild) {
2583
+ if (newChild.nodeType === DOCUMENT_FRAGMENT_NODE) {
2584
+ return this.insertBefore(newChild, null);
2585
+ } else {
2586
+ return _appendSingleChild(this, newChild);
2587
+ }
2588
+ },
2589
+ setAttributeNode: function(newAttr) {
2590
+ return this.attributes.setNamedItem(newAttr);
2591
+ },
2592
+ setAttributeNodeNS: function(newAttr) {
2593
+ return this.attributes.setNamedItemNS(newAttr);
2594
+ },
2595
+ removeAttributeNode: function(oldAttr) {
2596
+ return this.attributes.removeNamedItem(oldAttr.nodeName);
2597
+ },
2598
+ removeAttributeNS: function(namespaceURI, localName) {
2599
+ var old = this.getAttributeNodeNS(namespaceURI, localName);
2600
+ old && this.removeAttributeNode(old);
2601
+ },
2602
+ hasAttributeNS: function(namespaceURI, localName) {
2603
+ return this.getAttributeNodeNS(namespaceURI, localName) != null;
2604
+ },
2605
+ getAttributeNS: function(namespaceURI, localName) {
2606
+ var attr = this.getAttributeNodeNS(namespaceURI, localName);
2607
+ return attr && attr.value || "";
2608
+ },
2609
+ setAttributeNS: function(namespaceURI, qualifiedName, value) {
2610
+ var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
2611
+ attr.value = attr.nodeValue = "" + value;
2612
+ this.setAttributeNode(attr);
2613
+ },
2614
+ getAttributeNodeNS: function(namespaceURI, localName) {
2615
+ return this.attributes.getNamedItemNS(namespaceURI, localName);
2616
+ },
2617
+ getElementsByTagName: function(tagName) {
2618
+ return new LiveNodeList(this, function(base) {
2619
+ var ls = [];
2620
+ _visitNode(base, function(node) {
2621
+ if (node !== base && node.nodeType == ELEMENT_NODE && (tagName === "*" || node.tagName == tagName)) {
2622
+ ls.push(node);
2623
+ }
2624
+ });
2625
+ return ls;
2626
+ });
2627
+ },
2628
+ getElementsByTagNameNS: function(namespaceURI, localName) {
2629
+ return new LiveNodeList(this, function(base) {
2630
+ var ls = [];
2631
+ _visitNode(base, function(node) {
2632
+ if (node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === "*" || node.namespaceURI === namespaceURI) && (localName === "*" || node.localName == localName)) {
2633
+ ls.push(node);
2634
+ }
2635
+ });
2636
+ return ls;
2637
+ });
2638
+ }
2639
+ };
2640
+ Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
2641
+ Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
2642
+ _extends(Element, Node2);
2643
+ function Attr() {
2644
+ }
2645
+ Attr.prototype.nodeType = ATTRIBUTE_NODE;
2646
+ _extends(Attr, Node2);
2647
+ function CharacterData() {
2648
+ }
2649
+ CharacterData.prototype = {
2650
+ data: "",
2651
+ substringData: function(offset, count) {
2652
+ return this.data.substring(offset, offset + count);
2653
+ },
2654
+ appendData: function(text) {
2655
+ text = this.data + text;
2656
+ this.nodeValue = this.data = text;
2657
+ this.length = text.length;
2658
+ },
2659
+ insertData: function(offset, text) {
2660
+ this.replaceData(offset, 0, text);
2661
+ },
2662
+ appendChild: function(newChild) {
2663
+ throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR]);
2664
+ },
2665
+ deleteData: function(offset, count) {
2666
+ this.replaceData(offset, count, "");
2667
+ },
2668
+ replaceData: function(offset, count, text) {
2669
+ var start = this.data.substring(0, offset);
2670
+ var end = this.data.substring(offset + count);
2671
+ text = start + text + end;
2672
+ this.nodeValue = this.data = text;
2673
+ this.length = text.length;
2674
+ }
2675
+ };
2676
+ _extends(CharacterData, Node2);
2677
+ function Text() {
2678
+ }
2679
+ Text.prototype = {
2680
+ nodeName: "#text",
2681
+ nodeType: TEXT_NODE,
2682
+ splitText: function(offset) {
2683
+ var text = this.data;
2684
+ var newText = text.substring(offset);
2685
+ text = text.substring(0, offset);
2686
+ this.data = this.nodeValue = text;
2687
+ this.length = text.length;
2688
+ var newNode = this.ownerDocument.createTextNode(newText);
2689
+ if (this.parentNode) {
2690
+ this.parentNode.insertBefore(newNode, this.nextSibling);
2691
+ }
2692
+ return newNode;
2693
+ }
2694
+ };
2695
+ _extends(Text, CharacterData);
2696
+ function Comment() {
2697
+ }
2698
+ Comment.prototype = {
2699
+ nodeName: "#comment",
2700
+ nodeType: COMMENT_NODE
2701
+ };
2702
+ _extends(Comment, CharacterData);
2703
+ function CDATASection() {
2704
+ }
2705
+ CDATASection.prototype = {
2706
+ nodeName: "#cdata-section",
2707
+ nodeType: CDATA_SECTION_NODE
2708
+ };
2709
+ _extends(CDATASection, CharacterData);
2710
+ function DocumentType() {
2711
+ }
2712
+ DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
2713
+ _extends(DocumentType, Node2);
2714
+ function Notation() {
2715
+ }
2716
+ Notation.prototype.nodeType = NOTATION_NODE;
2717
+ _extends(Notation, Node2);
2718
+ function Entity() {
2719
+ }
2720
+ Entity.prototype.nodeType = ENTITY_NODE;
2721
+ _extends(Entity, Node2);
2722
+ function EntityReference() {
2723
+ }
2724
+ EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
2725
+ _extends(EntityReference, Node2);
2726
+ function DocumentFragment() {
2727
+ }
2728
+ DocumentFragment.prototype.nodeName = "#document-fragment";
2729
+ DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
2730
+ _extends(DocumentFragment, Node2);
2731
+ function ProcessingInstruction() {
2732
+ }
2733
+ ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
2734
+ _extends(ProcessingInstruction, Node2);
2735
+ function XMLSerializer() {
2736
+ }
2737
+ XMLSerializer.prototype.serializeToString = function(node, isHtml, nodeFilter) {
2738
+ return nodeSerializeToString.call(node, isHtml, nodeFilter);
2739
+ };
2740
+ Node2.prototype.toString = nodeSerializeToString;
2741
+ function nodeSerializeToString(isHtml, nodeFilter) {
2742
+ var buf = [];
2743
+ var refNode = this.nodeType == 9 && this.documentElement || this;
2744
+ var prefix = refNode.prefix;
2745
+ var uri = refNode.namespaceURI;
2746
+ if (uri && prefix == null) {
2747
+ var prefix = refNode.lookupPrefix(uri);
2748
+ if (prefix == null) {
2749
+ var visibleNamespaces = [
2750
+ { namespace: uri, prefix: null }
2751
+ ];
2752
+ }
2753
+ }
2754
+ serializeToString(this, buf, isHtml, nodeFilter, visibleNamespaces);
2755
+ return buf.join("");
2756
+ }
2757
+ function needNamespaceDefine(node, isHTML, visibleNamespaces) {
2758
+ var prefix = node.prefix || "";
2759
+ var uri = node.namespaceURI;
2760
+ if (!uri) {
2761
+ return false;
2762
+ }
2763
+ if (prefix === "xml" && uri === NAMESPACE.XML || uri === NAMESPACE.XMLNS) {
2764
+ return false;
2765
+ }
2766
+ var i = visibleNamespaces.length;
2767
+ while (i--) {
2768
+ var ns = visibleNamespaces[i];
2769
+ if (ns.prefix === prefix) {
2770
+ return ns.namespace !== uri;
2771
+ }
2772
+ }
2773
+ return true;
2774
+ }
2775
+ function addSerializedAttribute(buf, qualifiedName, value) {
2776
+ buf.push(" ", qualifiedName, '="', value.replace(/[<&"]/g, _xmlEncoder), '"');
2777
+ }
2778
+ function serializeToString(node, buf, isHTML, nodeFilter, visibleNamespaces) {
2779
+ if (!visibleNamespaces) {
2780
+ visibleNamespaces = [];
2781
+ }
2782
+ if (nodeFilter) {
2783
+ node = nodeFilter(node);
2784
+ if (node) {
2785
+ if (typeof node == "string") {
2786
+ buf.push(node);
2787
+ return;
2788
+ }
2789
+ } else {
2790
+ return;
2791
+ }
2792
+ }
2793
+ switch (node.nodeType) {
2794
+ case ELEMENT_NODE:
2795
+ var attrs = node.attributes;
2796
+ var len = attrs.length;
2797
+ var child = node.firstChild;
2798
+ var nodeName = node.tagName;
2799
+ isHTML = NAMESPACE.isHTML(node.namespaceURI) || isHTML;
2800
+ var prefixedNodeName = nodeName;
2801
+ if (!isHTML && !node.prefix && node.namespaceURI) {
2802
+ var defaultNS;
2803
+ for (var ai = 0; ai < attrs.length; ai++) {
2804
+ if (attrs.item(ai).name === "xmlns") {
2805
+ defaultNS = attrs.item(ai).value;
2806
+ break;
2807
+ }
2808
+ }
2809
+ if (!defaultNS) {
2810
+ for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
2811
+ var namespace = visibleNamespaces[nsi];
2812
+ if (namespace.prefix === "" && namespace.namespace === node.namespaceURI) {
2813
+ defaultNS = namespace.namespace;
2814
+ break;
2815
+ }
2816
+ }
2817
+ }
2818
+ if (defaultNS !== node.namespaceURI) {
2819
+ for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
2820
+ var namespace = visibleNamespaces[nsi];
2821
+ if (namespace.namespace === node.namespaceURI) {
2822
+ if (namespace.prefix) {
2823
+ prefixedNodeName = namespace.prefix + ":" + nodeName;
2824
+ }
2825
+ break;
2826
+ }
2827
+ }
2828
+ }
2829
+ }
2830
+ buf.push("<", prefixedNodeName);
2831
+ for (var i = 0; i < len; i++) {
2832
+ var attr = attrs.item(i);
2833
+ if (attr.prefix == "xmlns") {
2834
+ visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });
2835
+ } else if (attr.nodeName == "xmlns") {
2836
+ visibleNamespaces.push({ prefix: "", namespace: attr.value });
2837
+ }
2838
+ }
2839
+ for (var i = 0; i < len; i++) {
2840
+ var attr = attrs.item(i);
2841
+ if (needNamespaceDefine(attr, isHTML, visibleNamespaces)) {
2842
+ var prefix = attr.prefix || "";
2843
+ var uri = attr.namespaceURI;
2844
+ addSerializedAttribute(buf, prefix ? "xmlns:" + prefix : "xmlns", uri);
2845
+ visibleNamespaces.push({ prefix, namespace: uri });
2846
+ }
2847
+ serializeToString(attr, buf, isHTML, nodeFilter, visibleNamespaces);
2848
+ }
2849
+ if (nodeName === prefixedNodeName && needNamespaceDefine(node, isHTML, visibleNamespaces)) {
2850
+ var prefix = node.prefix || "";
2851
+ var uri = node.namespaceURI;
2852
+ addSerializedAttribute(buf, prefix ? "xmlns:" + prefix : "xmlns", uri);
2853
+ visibleNamespaces.push({ prefix, namespace: uri });
2854
+ }
2855
+ if (child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)) {
2856
+ buf.push(">");
2857
+ if (isHTML && /^script$/i.test(nodeName)) {
2858
+ while (child) {
2859
+ if (child.data) {
2860
+ buf.push(child.data);
2861
+ } else {
2862
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
2863
+ }
2864
+ child = child.nextSibling;
2865
+ }
2866
+ } else {
2867
+ while (child) {
2868
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
2869
+ child = child.nextSibling;
2870
+ }
2871
+ }
2872
+ buf.push("</", prefixedNodeName, ">");
2873
+ } else {
2874
+ buf.push("/>");
2875
+ }
2876
+ return;
2877
+ case DOCUMENT_NODE:
2878
+ case DOCUMENT_FRAGMENT_NODE:
2879
+ var child = node.firstChild;
2880
+ while (child) {
2881
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
2882
+ child = child.nextSibling;
2883
+ }
2884
+ return;
2885
+ case ATTRIBUTE_NODE:
2886
+ return addSerializedAttribute(buf, node.name, node.value);
2887
+ case TEXT_NODE:
2888
+ return buf.push(node.data.replace(/[<&]/g, _xmlEncoder).replace(/]]>/g, "]]&gt;"));
2889
+ case CDATA_SECTION_NODE:
2890
+ return buf.push("<![CDATA[", node.data, "]]>");
2891
+ case COMMENT_NODE:
2892
+ return buf.push("<!--", node.data, "-->");
2893
+ case DOCUMENT_TYPE_NODE:
2894
+ var pubid = node.publicId;
2895
+ var sysid = node.systemId;
2896
+ buf.push("<!DOCTYPE ", node.name);
2897
+ if (pubid) {
2898
+ buf.push(" PUBLIC ", pubid);
2899
+ if (sysid && sysid != ".") {
2900
+ buf.push(" ", sysid);
2901
+ }
2902
+ buf.push(">");
2903
+ } else if (sysid && sysid != ".") {
2904
+ buf.push(" SYSTEM ", sysid, ">");
2905
+ } else {
2906
+ var sub = node.internalSubset;
2907
+ if (sub) {
2908
+ buf.push(" [", sub, "]");
2909
+ }
2910
+ buf.push(">");
2911
+ }
2912
+ return;
2913
+ case PROCESSING_INSTRUCTION_NODE:
2914
+ return buf.push("<?", node.target, " ", node.data, "?>");
2915
+ case ENTITY_REFERENCE_NODE:
2916
+ return buf.push("&", node.nodeName, ";");
2917
+ default:
2918
+ buf.push("??", node.nodeName);
2919
+ }
2920
+ }
2921
+ function importNode(doc, node, deep) {
2922
+ var node2;
2923
+ switch (node.nodeType) {
2924
+ case ELEMENT_NODE:
2925
+ node2 = node.cloneNode(false);
2926
+ node2.ownerDocument = doc;
2927
+ case DOCUMENT_FRAGMENT_NODE:
2928
+ break;
2929
+ case ATTRIBUTE_NODE:
2930
+ deep = true;
2931
+ break;
2932
+ }
2933
+ if (!node2) {
2934
+ node2 = node.cloneNode(false);
2935
+ }
2936
+ node2.ownerDocument = doc;
2937
+ node2.parentNode = null;
2938
+ if (deep) {
2939
+ var child = node.firstChild;
2940
+ while (child) {
2941
+ node2.appendChild(importNode(doc, child, deep));
2942
+ child = child.nextSibling;
2943
+ }
2944
+ }
2945
+ return node2;
2946
+ }
2947
+ function cloneNode(doc, node, deep) {
2948
+ var node2 = new node.constructor();
2949
+ for (var n in node) {
2950
+ if (Object.prototype.hasOwnProperty.call(node, n)) {
2951
+ var v = node[n];
2952
+ if (typeof v != "object") {
2953
+ if (v != node2[n]) {
2954
+ node2[n] = v;
2955
+ }
2956
+ }
2957
+ }
2958
+ }
2959
+ if (node.childNodes) {
2960
+ node2.childNodes = new NodeList();
2961
+ }
2962
+ node2.ownerDocument = doc;
2963
+ switch (node2.nodeType) {
2964
+ case ELEMENT_NODE:
2965
+ var attrs = node.attributes;
2966
+ var attrs2 = node2.attributes = new NamedNodeMap();
2967
+ var len = attrs.length;
2968
+ attrs2._ownerElement = node2;
2969
+ for (var i = 0; i < len; i++) {
2970
+ node2.setAttributeNode(cloneNode(doc, attrs.item(i), true));
2971
+ }
2972
+ break;
2973
+ ;
2974
+ case ATTRIBUTE_NODE:
2975
+ deep = true;
2976
+ }
2977
+ if (deep) {
2978
+ var child = node.firstChild;
2979
+ while (child) {
2980
+ node2.appendChild(cloneNode(doc, child, deep));
2981
+ child = child.nextSibling;
2982
+ }
2983
+ }
2984
+ return node2;
2985
+ }
2986
+ function __set__(object, key, value) {
2987
+ object[key] = value;
2988
+ }
2989
+ try {
2990
+ if (Object.defineProperty) {
2991
+ let getTextContent2 = function(node) {
2992
+ switch (node.nodeType) {
2993
+ case ELEMENT_NODE:
2994
+ case DOCUMENT_FRAGMENT_NODE:
2995
+ var buf = [];
2996
+ node = node.firstChild;
2997
+ while (node) {
2998
+ if (node.nodeType !== 7 && node.nodeType !== 8) {
2999
+ buf.push(getTextContent2(node));
3000
+ }
3001
+ node = node.nextSibling;
3002
+ }
3003
+ return buf.join("");
3004
+ default:
3005
+ return node.nodeValue;
3006
+ }
3007
+ };
3008
+ getTextContent = getTextContent2;
3009
+ Object.defineProperty(LiveNodeList.prototype, "length", {
3010
+ get: function() {
3011
+ _updateLiveList(this);
3012
+ return this.$$length;
3013
+ }
3014
+ });
3015
+ Object.defineProperty(Node2.prototype, "textContent", {
3016
+ get: function() {
3017
+ return getTextContent2(this);
3018
+ },
3019
+ set: function(data) {
3020
+ switch (this.nodeType) {
3021
+ case ELEMENT_NODE:
3022
+ case DOCUMENT_FRAGMENT_NODE:
3023
+ while (this.firstChild) {
3024
+ this.removeChild(this.firstChild);
3025
+ }
3026
+ if (data || String(data)) {
3027
+ this.appendChild(this.ownerDocument.createTextNode(data));
3028
+ }
3029
+ break;
3030
+ default:
3031
+ this.data = data;
3032
+ this.value = data;
3033
+ this.nodeValue = data;
3034
+ }
3035
+ }
3036
+ });
3037
+ __set__ = function(object, key, value) {
3038
+ object["$$" + key] = value;
3039
+ };
3040
+ }
3041
+ } catch (e) {
3042
+ }
3043
+ var getTextContent;
3044
+ exports.DocumentType = DocumentType;
3045
+ exports.DOMException = DOMException;
3046
+ exports.DOMImplementation = DOMImplementation;
3047
+ exports.Element = Element;
3048
+ exports.Node = Node2;
3049
+ exports.NodeList = NodeList;
3050
+ exports.XMLSerializer = XMLSerializer;
3051
+ }
3052
+ });
3053
+
3054
+ // ../../node_modules/@xmldom/xmldom/lib/entities.js
3055
+ var require_entities = __commonJS({
3056
+ "../../node_modules/@xmldom/xmldom/lib/entities.js"(exports) {
3057
+ var freeze = require_conventions().freeze;
3058
+ exports.XML_ENTITIES = freeze({ amp: "&", apos: "'", gt: ">", lt: "<", quot: '"' });
3059
+ exports.HTML_ENTITIES = freeze({
3060
+ lt: "<",
3061
+ gt: ">",
3062
+ amp: "&",
3063
+ quot: '"',
3064
+ apos: "'",
3065
+ Agrave: "\xC0",
3066
+ Aacute: "\xC1",
3067
+ Acirc: "\xC2",
3068
+ Atilde: "\xC3",
3069
+ Auml: "\xC4",
3070
+ Aring: "\xC5",
3071
+ AElig: "\xC6",
3072
+ Ccedil: "\xC7",
3073
+ Egrave: "\xC8",
3074
+ Eacute: "\xC9",
3075
+ Ecirc: "\xCA",
3076
+ Euml: "\xCB",
3077
+ Igrave: "\xCC",
3078
+ Iacute: "\xCD",
3079
+ Icirc: "\xCE",
3080
+ Iuml: "\xCF",
3081
+ ETH: "\xD0",
3082
+ Ntilde: "\xD1",
3083
+ Ograve: "\xD2",
3084
+ Oacute: "\xD3",
3085
+ Ocirc: "\xD4",
3086
+ Otilde: "\xD5",
3087
+ Ouml: "\xD6",
3088
+ Oslash: "\xD8",
3089
+ Ugrave: "\xD9",
3090
+ Uacute: "\xDA",
3091
+ Ucirc: "\xDB",
3092
+ Uuml: "\xDC",
3093
+ Yacute: "\xDD",
3094
+ THORN: "\xDE",
3095
+ szlig: "\xDF",
3096
+ agrave: "\xE0",
3097
+ aacute: "\xE1",
3098
+ acirc: "\xE2",
3099
+ atilde: "\xE3",
3100
+ auml: "\xE4",
3101
+ aring: "\xE5",
3102
+ aelig: "\xE6",
3103
+ ccedil: "\xE7",
3104
+ egrave: "\xE8",
3105
+ eacute: "\xE9",
3106
+ ecirc: "\xEA",
3107
+ euml: "\xEB",
3108
+ igrave: "\xEC",
3109
+ iacute: "\xED",
3110
+ icirc: "\xEE",
3111
+ iuml: "\xEF",
3112
+ eth: "\xF0",
3113
+ ntilde: "\xF1",
3114
+ ograve: "\xF2",
3115
+ oacute: "\xF3",
3116
+ ocirc: "\xF4",
3117
+ otilde: "\xF5",
3118
+ ouml: "\xF6",
3119
+ oslash: "\xF8",
3120
+ ugrave: "\xF9",
3121
+ uacute: "\xFA",
3122
+ ucirc: "\xFB",
3123
+ uuml: "\xFC",
3124
+ yacute: "\xFD",
3125
+ thorn: "\xFE",
3126
+ yuml: "\xFF",
3127
+ nbsp: "\xA0",
3128
+ iexcl: "\xA1",
3129
+ cent: "\xA2",
3130
+ pound: "\xA3",
3131
+ curren: "\xA4",
3132
+ yen: "\xA5",
3133
+ brvbar: "\xA6",
3134
+ sect: "\xA7",
3135
+ uml: "\xA8",
3136
+ copy: "\xA9",
3137
+ ordf: "\xAA",
3138
+ laquo: "\xAB",
3139
+ not: "\xAC",
3140
+ shy: "\xAD\xAD",
3141
+ reg: "\xAE",
3142
+ macr: "\xAF",
3143
+ deg: "\xB0",
3144
+ plusmn: "\xB1",
3145
+ sup2: "\xB2",
3146
+ sup3: "\xB3",
3147
+ acute: "\xB4",
3148
+ micro: "\xB5",
3149
+ para: "\xB6",
3150
+ middot: "\xB7",
3151
+ cedil: "\xB8",
3152
+ sup1: "\xB9",
3153
+ ordm: "\xBA",
3154
+ raquo: "\xBB",
3155
+ frac14: "\xBC",
3156
+ frac12: "\xBD",
3157
+ frac34: "\xBE",
3158
+ iquest: "\xBF",
3159
+ times: "\xD7",
3160
+ divide: "\xF7",
3161
+ forall: "\u2200",
3162
+ part: "\u2202",
3163
+ exist: "\u2203",
3164
+ empty: "\u2205",
3165
+ nabla: "\u2207",
3166
+ isin: "\u2208",
3167
+ notin: "\u2209",
3168
+ ni: "\u220B",
3169
+ prod: "\u220F",
3170
+ sum: "\u2211",
3171
+ minus: "\u2212",
3172
+ lowast: "\u2217",
3173
+ radic: "\u221A",
3174
+ prop: "\u221D",
3175
+ infin: "\u221E",
3176
+ ang: "\u2220",
3177
+ and: "\u2227",
3178
+ or: "\u2228",
3179
+ cap: "\u2229",
3180
+ cup: "\u222A",
3181
+ "int": "\u222B",
3182
+ there4: "\u2234",
3183
+ sim: "\u223C",
3184
+ cong: "\u2245",
3185
+ asymp: "\u2248",
3186
+ ne: "\u2260",
3187
+ equiv: "\u2261",
3188
+ le: "\u2264",
3189
+ ge: "\u2265",
3190
+ sub: "\u2282",
3191
+ sup: "\u2283",
3192
+ nsub: "\u2284",
3193
+ sube: "\u2286",
3194
+ supe: "\u2287",
3195
+ oplus: "\u2295",
3196
+ otimes: "\u2297",
3197
+ perp: "\u22A5",
3198
+ sdot: "\u22C5",
3199
+ Alpha: "\u0391",
3200
+ Beta: "\u0392",
3201
+ Gamma: "\u0393",
3202
+ Delta: "\u0394",
3203
+ Epsilon: "\u0395",
3204
+ Zeta: "\u0396",
3205
+ Eta: "\u0397",
3206
+ Theta: "\u0398",
3207
+ Iota: "\u0399",
3208
+ Kappa: "\u039A",
3209
+ Lambda: "\u039B",
3210
+ Mu: "\u039C",
3211
+ Nu: "\u039D",
3212
+ Xi: "\u039E",
3213
+ Omicron: "\u039F",
3214
+ Pi: "\u03A0",
3215
+ Rho: "\u03A1",
3216
+ Sigma: "\u03A3",
3217
+ Tau: "\u03A4",
3218
+ Upsilon: "\u03A5",
3219
+ Phi: "\u03A6",
3220
+ Chi: "\u03A7",
3221
+ Psi: "\u03A8",
3222
+ Omega: "\u03A9",
3223
+ alpha: "\u03B1",
3224
+ beta: "\u03B2",
3225
+ gamma: "\u03B3",
3226
+ delta: "\u03B4",
3227
+ epsilon: "\u03B5",
3228
+ zeta: "\u03B6",
3229
+ eta: "\u03B7",
3230
+ theta: "\u03B8",
3231
+ iota: "\u03B9",
3232
+ kappa: "\u03BA",
3233
+ lambda: "\u03BB",
3234
+ mu: "\u03BC",
3235
+ nu: "\u03BD",
3236
+ xi: "\u03BE",
3237
+ omicron: "\u03BF",
3238
+ pi: "\u03C0",
3239
+ rho: "\u03C1",
3240
+ sigmaf: "\u03C2",
3241
+ sigma: "\u03C3",
3242
+ tau: "\u03C4",
3243
+ upsilon: "\u03C5",
3244
+ phi: "\u03C6",
3245
+ chi: "\u03C7",
3246
+ psi: "\u03C8",
3247
+ omega: "\u03C9",
3248
+ thetasym: "\u03D1",
3249
+ upsih: "\u03D2",
3250
+ piv: "\u03D6",
3251
+ OElig: "\u0152",
3252
+ oelig: "\u0153",
3253
+ Scaron: "\u0160",
3254
+ scaron: "\u0161",
3255
+ Yuml: "\u0178",
3256
+ fnof: "\u0192",
3257
+ circ: "\u02C6",
3258
+ tilde: "\u02DC",
3259
+ ensp: "\u2002",
3260
+ emsp: "\u2003",
3261
+ thinsp: "\u2009",
3262
+ zwnj: "\u200C",
3263
+ zwj: "\u200D",
3264
+ lrm: "\u200E",
3265
+ rlm: "\u200F",
3266
+ ndash: "\u2013",
3267
+ mdash: "\u2014",
3268
+ lsquo: "\u2018",
3269
+ rsquo: "\u2019",
3270
+ sbquo: "\u201A",
3271
+ ldquo: "\u201C",
3272
+ rdquo: "\u201D",
3273
+ bdquo: "\u201E",
3274
+ dagger: "\u2020",
3275
+ Dagger: "\u2021",
3276
+ bull: "\u2022",
3277
+ hellip: "\u2026",
3278
+ permil: "\u2030",
3279
+ prime: "\u2032",
3280
+ Prime: "\u2033",
3281
+ lsaquo: "\u2039",
3282
+ rsaquo: "\u203A",
3283
+ oline: "\u203E",
3284
+ euro: "\u20AC",
3285
+ trade: "\u2122",
3286
+ larr: "\u2190",
3287
+ uarr: "\u2191",
3288
+ rarr: "\u2192",
3289
+ darr: "\u2193",
3290
+ harr: "\u2194",
3291
+ crarr: "\u21B5",
3292
+ lceil: "\u2308",
3293
+ rceil: "\u2309",
3294
+ lfloor: "\u230A",
3295
+ rfloor: "\u230B",
3296
+ loz: "\u25CA",
3297
+ spades: "\u2660",
3298
+ clubs: "\u2663",
3299
+ hearts: "\u2665",
3300
+ diams: "\u2666"
3301
+ });
3302
+ exports.entityMap = exports.HTML_ENTITIES;
3303
+ }
3304
+ });
3305
+
3306
+ // ../../node_modules/@xmldom/xmldom/lib/sax.js
3307
+ var require_sax = __commonJS({
3308
+ "../../node_modules/@xmldom/xmldom/lib/sax.js"(exports) {
3309
+ var NAMESPACE = require_conventions().NAMESPACE;
3310
+ var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
3311
+ var nameChar = new RegExp("[\\-\\.0-9" + nameStartChar.source.slice(1, -1) + "\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
3312
+ var tagNamePattern = new RegExp("^" + nameStartChar.source + nameChar.source + "*(?::" + nameStartChar.source + nameChar.source + "*)?$");
3313
+ var S_TAG = 0;
3314
+ var S_ATTR = 1;
3315
+ var S_ATTR_SPACE = 2;
3316
+ var S_EQ = 3;
3317
+ var S_ATTR_NOQUOT_VALUE = 4;
3318
+ var S_ATTR_END = 5;
3319
+ var S_TAG_SPACE = 6;
3320
+ var S_TAG_CLOSE = 7;
3321
+ function ParseError(message, locator) {
3322
+ this.message = message;
3323
+ this.locator = locator;
3324
+ if (Error.captureStackTrace)
3325
+ Error.captureStackTrace(this, ParseError);
3326
+ }
3327
+ ParseError.prototype = new Error();
3328
+ ParseError.prototype.name = ParseError.name;
3329
+ function XMLReader() {
3330
+ }
3331
+ XMLReader.prototype = {
3332
+ parse: function(source, defaultNSMap, entityMap) {
3333
+ var domBuilder = this.domBuilder;
3334
+ domBuilder.startDocument();
3335
+ _copy(defaultNSMap, defaultNSMap = {});
3336
+ parse(source, defaultNSMap, entityMap, domBuilder, this.errorHandler);
3337
+ domBuilder.endDocument();
3338
+ }
3339
+ };
3340
+ function parse(source, defaultNSMapCopy, entityMap, domBuilder, errorHandler) {
3341
+ function fixedFromCharCode(code) {
3342
+ if (code > 65535) {
3343
+ code -= 65536;
3344
+ var surrogate1 = 55296 + (code >> 10), surrogate2 = 56320 + (code & 1023);
3345
+ return String.fromCharCode(surrogate1, surrogate2);
3346
+ } else {
3347
+ return String.fromCharCode(code);
3348
+ }
3349
+ }
3350
+ function entityReplacer(a2) {
3351
+ var k = a2.slice(1, -1);
3352
+ if (k in entityMap) {
3353
+ return entityMap[k];
3354
+ } else if (k.charAt(0) === "#") {
3355
+ return fixedFromCharCode(parseInt(k.substr(1).replace("x", "0x")));
3356
+ } else {
3357
+ errorHandler.error("entity not found:" + a2);
3358
+ return a2;
3359
+ }
3360
+ }
3361
+ function appendText(end2) {
3362
+ if (end2 > start) {
3363
+ var xt = source.substring(start, end2).replace(/&#?\w+;/g, entityReplacer);
3364
+ locator && position(start);
3365
+ domBuilder.characters(xt, 0, end2 - start);
3366
+ start = end2;
3367
+ }
3368
+ }
3369
+ function position(p, m) {
3370
+ while (p >= lineEnd && (m = linePattern.exec(source))) {
3371
+ lineStart = m.index;
3372
+ lineEnd = lineStart + m[0].length;
3373
+ locator.lineNumber++;
3374
+ }
3375
+ locator.columnNumber = p - lineStart + 1;
3376
+ }
3377
+ var lineStart = 0;
3378
+ var lineEnd = 0;
3379
+ var linePattern = /.*(?:\r\n?|\n)|.*$/g;
3380
+ var locator = domBuilder.locator;
3381
+ var parseStack = [{ currentNSMap: defaultNSMapCopy }];
3382
+ var closeMap = {};
3383
+ var start = 0;
3384
+ while (true) {
3385
+ try {
3386
+ var tagStart = source.indexOf("<", start);
3387
+ if (tagStart < 0) {
3388
+ if (!source.substr(start).match(/^\s*$/)) {
3389
+ var doc = domBuilder.doc;
3390
+ var text = doc.createTextNode(source.substr(start));
3391
+ doc.appendChild(text);
3392
+ domBuilder.currentElement = text;
3393
+ }
3394
+ return;
3395
+ }
3396
+ if (tagStart > start) {
3397
+ appendText(tagStart);
3398
+ }
3399
+ switch (source.charAt(tagStart + 1)) {
3400
+ case "/":
3401
+ var end = source.indexOf(">", tagStart + 3);
3402
+ var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, "");
3403
+ var config = parseStack.pop();
3404
+ if (end < 0) {
3405
+ tagName = source.substring(tagStart + 2).replace(/[\s<].*/, "");
3406
+ errorHandler.error("end tag name: " + tagName + " is not complete:" + config.tagName);
3407
+ end = tagStart + 1 + tagName.length;
3408
+ } else if (tagName.match(/\s</)) {
3409
+ tagName = tagName.replace(/[\s<].*/, "");
3410
+ errorHandler.error("end tag name: " + tagName + " maybe not complete");
3411
+ end = tagStart + 1 + tagName.length;
3412
+ }
3413
+ var localNSMap = config.localNSMap;
3414
+ var endMatch = config.tagName == tagName;
3415
+ var endIgnoreCaseMach = endMatch || config.tagName && config.tagName.toLowerCase() == tagName.toLowerCase();
3416
+ if (endIgnoreCaseMach) {
3417
+ domBuilder.endElement(config.uri, config.localName, tagName);
3418
+ if (localNSMap) {
3419
+ for (var prefix in localNSMap) {
3420
+ if (Object.prototype.hasOwnProperty.call(localNSMap, prefix)) {
3421
+ domBuilder.endPrefixMapping(prefix);
3422
+ }
3423
+ }
3424
+ }
3425
+ if (!endMatch) {
3426
+ errorHandler.fatalError("end tag name: " + tagName + " is not match the current start tagName:" + config.tagName);
3427
+ }
3428
+ } else {
3429
+ parseStack.push(config);
3430
+ }
3431
+ end++;
3432
+ break;
3433
+ case "?":
3434
+ locator && position(tagStart);
3435
+ end = parseInstruction(source, tagStart, domBuilder);
3436
+ break;
3437
+ case "!":
3438
+ locator && position(tagStart);
3439
+ end = parseDCC(source, tagStart, domBuilder, errorHandler);
3440
+ break;
3441
+ default:
3442
+ locator && position(tagStart);
3443
+ var el = new ElementAttributes();
3444
+ var currentNSMap = parseStack[parseStack.length - 1].currentNSMap;
3445
+ var end = parseElementStartPart(source, tagStart, el, currentNSMap, entityReplacer, errorHandler);
3446
+ var len = el.length;
3447
+ if (!el.closed && fixSelfClosed(source, end, el.tagName, closeMap)) {
3448
+ el.closed = true;
3449
+ if (!entityMap.nbsp) {
3450
+ errorHandler.warning("unclosed xml attribute");
3451
+ }
3452
+ }
3453
+ if (locator && len) {
3454
+ var locator2 = copyLocator(locator, {});
3455
+ for (var i = 0; i < len; i++) {
3456
+ var a = el[i];
3457
+ position(a.offset);
3458
+ a.locator = copyLocator(locator, {});
3459
+ }
3460
+ domBuilder.locator = locator2;
3461
+ if (appendElement(el, domBuilder, currentNSMap)) {
3462
+ parseStack.push(el);
3463
+ }
3464
+ domBuilder.locator = locator;
3465
+ } else {
3466
+ if (appendElement(el, domBuilder, currentNSMap)) {
3467
+ parseStack.push(el);
3468
+ }
3469
+ }
3470
+ if (NAMESPACE.isHTML(el.uri) && !el.closed) {
3471
+ end = parseHtmlSpecialContent(source, end, el.tagName, entityReplacer, domBuilder);
3472
+ } else {
3473
+ end++;
3474
+ }
3475
+ }
3476
+ } catch (e) {
3477
+ if (e instanceof ParseError) {
3478
+ throw e;
3479
+ }
3480
+ errorHandler.error("element parse error: " + e);
3481
+ end = -1;
3482
+ }
3483
+ if (end > start) {
3484
+ start = end;
3485
+ } else {
3486
+ appendText(Math.max(tagStart, start) + 1);
3487
+ }
3488
+ }
3489
+ }
3490
+ function copyLocator(f, t) {
3491
+ t.lineNumber = f.lineNumber;
3492
+ t.columnNumber = f.columnNumber;
3493
+ return t;
3494
+ }
3495
+ function parseElementStartPart(source, start, el, currentNSMap, entityReplacer, errorHandler) {
3496
+ function addAttribute(qname, value2, startIndex) {
3497
+ if (el.attributeNames.hasOwnProperty(qname)) {
3498
+ errorHandler.fatalError("Attribute " + qname + " redefined");
3499
+ }
3500
+ el.addValue(qname, value2, startIndex);
3501
+ }
3502
+ var attrName;
3503
+ var value;
3504
+ var p = ++start;
3505
+ var s = S_TAG;
3506
+ while (true) {
3507
+ var c = source.charAt(p);
3508
+ switch (c) {
3509
+ case "=":
3510
+ if (s === S_ATTR) {
3511
+ attrName = source.slice(start, p);
3512
+ s = S_EQ;
3513
+ } else if (s === S_ATTR_SPACE) {
3514
+ s = S_EQ;
3515
+ } else {
3516
+ throw new Error("attribute equal must after attrName");
3517
+ }
3518
+ break;
3519
+ case "'":
3520
+ case '"':
3521
+ if (s === S_EQ || s === S_ATTR) {
3522
+ if (s === S_ATTR) {
3523
+ errorHandler.warning('attribute value must after "="');
3524
+ attrName = source.slice(start, p);
3525
+ }
3526
+ start = p + 1;
3527
+ p = source.indexOf(c, start);
3528
+ if (p > 0) {
3529
+ value = source.slice(start, p).replace(/&#?\w+;/g, entityReplacer);
3530
+ addAttribute(attrName, value, start - 1);
3531
+ s = S_ATTR_END;
3532
+ } else {
3533
+ throw new Error("attribute value no end '" + c + "' match");
3534
+ }
3535
+ } else if (s == S_ATTR_NOQUOT_VALUE) {
3536
+ value = source.slice(start, p).replace(/&#?\w+;/g, entityReplacer);
3537
+ addAttribute(attrName, value, start);
3538
+ errorHandler.warning('attribute "' + attrName + '" missed start quot(' + c + ")!!");
3539
+ start = p + 1;
3540
+ s = S_ATTR_END;
3541
+ } else {
3542
+ throw new Error('attribute value must after "="');
3543
+ }
3544
+ break;
3545
+ case "/":
3546
+ switch (s) {
3547
+ case S_TAG:
3548
+ el.setTagName(source.slice(start, p));
3549
+ case S_ATTR_END:
3550
+ case S_TAG_SPACE:
3551
+ case S_TAG_CLOSE:
3552
+ s = S_TAG_CLOSE;
3553
+ el.closed = true;
3554
+ case S_ATTR_NOQUOT_VALUE:
3555
+ case S_ATTR:
3556
+ break;
3557
+ case S_ATTR_SPACE:
3558
+ el.closed = true;
3559
+ break;
3560
+ default:
3561
+ throw new Error("attribute invalid close char('/')");
3562
+ }
3563
+ break;
3564
+ case "":
3565
+ errorHandler.error("unexpected end of input");
3566
+ if (s == S_TAG) {
3567
+ el.setTagName(source.slice(start, p));
3568
+ }
3569
+ return p;
3570
+ case ">":
3571
+ switch (s) {
3572
+ case S_TAG:
3573
+ el.setTagName(source.slice(start, p));
3574
+ case S_ATTR_END:
3575
+ case S_TAG_SPACE:
3576
+ case S_TAG_CLOSE:
3577
+ break;
3578
+ case S_ATTR_NOQUOT_VALUE:
3579
+ case S_ATTR:
3580
+ value = source.slice(start, p);
3581
+ if (value.slice(-1) === "/") {
3582
+ el.closed = true;
3583
+ value = value.slice(0, -1);
3584
+ }
3585
+ case S_ATTR_SPACE:
3586
+ if (s === S_ATTR_SPACE) {
3587
+ value = attrName;
3588
+ }
3589
+ if (s == S_ATTR_NOQUOT_VALUE) {
3590
+ errorHandler.warning('attribute "' + value + '" missed quot(")!');
3591
+ addAttribute(attrName, value.replace(/&#?\w+;/g, entityReplacer), start);
3592
+ } else {
3593
+ if (!NAMESPACE.isHTML(currentNSMap[""]) || !value.match(/^(?:disabled|checked|selected)$/i)) {
3594
+ errorHandler.warning('attribute "' + value + '" missed value!! "' + value + '" instead!!');
3595
+ }
3596
+ addAttribute(value, value, start);
3597
+ }
3598
+ break;
3599
+ case S_EQ:
3600
+ throw new Error("attribute value missed!!");
3601
+ }
3602
+ return p;
3603
+ case "\x80":
3604
+ c = " ";
3605
+ default:
3606
+ if (c <= " ") {
3607
+ switch (s) {
3608
+ case S_TAG:
3609
+ el.setTagName(source.slice(start, p));
3610
+ s = S_TAG_SPACE;
3611
+ break;
3612
+ case S_ATTR:
3613
+ attrName = source.slice(start, p);
3614
+ s = S_ATTR_SPACE;
3615
+ break;
3616
+ case S_ATTR_NOQUOT_VALUE:
3617
+ var value = source.slice(start, p).replace(/&#?\w+;/g, entityReplacer);
3618
+ errorHandler.warning('attribute "' + value + '" missed quot(")!!');
3619
+ addAttribute(attrName, value, start);
3620
+ case S_ATTR_END:
3621
+ s = S_TAG_SPACE;
3622
+ break;
3623
+ }
3624
+ } else {
3625
+ switch (s) {
3626
+ case S_ATTR_SPACE:
3627
+ var tagName = el.tagName;
3628
+ if (!NAMESPACE.isHTML(currentNSMap[""]) || !attrName.match(/^(?:disabled|checked|selected)$/i)) {
3629
+ errorHandler.warning('attribute "' + attrName + '" missed value!! "' + attrName + '" instead2!!');
3630
+ }
3631
+ addAttribute(attrName, attrName, start);
3632
+ start = p;
3633
+ s = S_ATTR;
3634
+ break;
3635
+ case S_ATTR_END:
3636
+ errorHandler.warning('attribute space is required"' + attrName + '"!!');
3637
+ case S_TAG_SPACE:
3638
+ s = S_ATTR;
3639
+ start = p;
3640
+ break;
3641
+ case S_EQ:
3642
+ s = S_ATTR_NOQUOT_VALUE;
3643
+ start = p;
3644
+ break;
3645
+ case S_TAG_CLOSE:
3646
+ throw new Error("elements closed character '/' and '>' must be connected to");
3647
+ }
3648
+ }
3649
+ }
3650
+ p++;
3651
+ }
3652
+ }
3653
+ function appendElement(el, domBuilder, currentNSMap) {
3654
+ var tagName = el.tagName;
3655
+ var localNSMap = null;
3656
+ var i = el.length;
3657
+ while (i--) {
3658
+ var a = el[i];
3659
+ var qName = a.qName;
3660
+ var value = a.value;
3661
+ var nsp = qName.indexOf(":");
3662
+ if (nsp > 0) {
3663
+ var prefix = a.prefix = qName.slice(0, nsp);
3664
+ var localName = qName.slice(nsp + 1);
3665
+ var nsPrefix = prefix === "xmlns" && localName;
3666
+ } else {
3667
+ localName = qName;
3668
+ prefix = null;
3669
+ nsPrefix = qName === "xmlns" && "";
3670
+ }
3671
+ a.localName = localName;
3672
+ if (nsPrefix !== false) {
3673
+ if (localNSMap == null) {
3674
+ localNSMap = {};
3675
+ _copy(currentNSMap, currentNSMap = {});
3676
+ }
3677
+ currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
3678
+ a.uri = NAMESPACE.XMLNS;
3679
+ domBuilder.startPrefixMapping(nsPrefix, value);
3680
+ }
3681
+ }
3682
+ var i = el.length;
3683
+ while (i--) {
3684
+ a = el[i];
3685
+ var prefix = a.prefix;
3686
+ if (prefix) {
3687
+ if (prefix === "xml") {
3688
+ a.uri = NAMESPACE.XML;
3689
+ }
3690
+ if (prefix !== "xmlns") {
3691
+ a.uri = currentNSMap[prefix || ""];
3692
+ }
3693
+ }
3694
+ }
3695
+ var nsp = tagName.indexOf(":");
3696
+ if (nsp > 0) {
3697
+ prefix = el.prefix = tagName.slice(0, nsp);
3698
+ localName = el.localName = tagName.slice(nsp + 1);
3699
+ } else {
3700
+ prefix = null;
3701
+ localName = el.localName = tagName;
3702
+ }
3703
+ var ns = el.uri = currentNSMap[prefix || ""];
3704
+ domBuilder.startElement(ns, localName, tagName, el);
3705
+ if (el.closed) {
3706
+ domBuilder.endElement(ns, localName, tagName);
3707
+ if (localNSMap) {
3708
+ for (prefix in localNSMap) {
3709
+ if (Object.prototype.hasOwnProperty.call(localNSMap, prefix)) {
3710
+ domBuilder.endPrefixMapping(prefix);
3711
+ }
3712
+ }
3713
+ }
3714
+ } else {
3715
+ el.currentNSMap = currentNSMap;
3716
+ el.localNSMap = localNSMap;
3717
+ return true;
3718
+ }
3719
+ }
3720
+ function parseHtmlSpecialContent(source, elStartEnd, tagName, entityReplacer, domBuilder) {
3721
+ if (/^(?:script|textarea)$/i.test(tagName)) {
3722
+ var elEndStart = source.indexOf("</" + tagName + ">", elStartEnd);
3723
+ var text = source.substring(elStartEnd + 1, elEndStart);
3724
+ if (/[&<]/.test(text)) {
3725
+ if (/^script$/i.test(tagName)) {
3726
+ domBuilder.characters(text, 0, text.length);
3727
+ return elEndStart;
3728
+ }
3729
+ text = text.replace(/&#?\w+;/g, entityReplacer);
3730
+ domBuilder.characters(text, 0, text.length);
3731
+ return elEndStart;
3732
+ }
3733
+ }
3734
+ return elStartEnd + 1;
3735
+ }
3736
+ function fixSelfClosed(source, elStartEnd, tagName, closeMap) {
3737
+ var pos = closeMap[tagName];
3738
+ if (pos == null) {
3739
+ pos = source.lastIndexOf("</" + tagName + ">");
3740
+ if (pos < elStartEnd) {
3741
+ pos = source.lastIndexOf("</" + tagName);
3742
+ }
3743
+ closeMap[tagName] = pos;
3744
+ }
3745
+ return pos < elStartEnd;
3746
+ }
3747
+ function _copy(source, target) {
3748
+ for (var n in source) {
3749
+ if (Object.prototype.hasOwnProperty.call(source, n)) {
3750
+ target[n] = source[n];
3751
+ }
3752
+ }
3753
+ }
3754
+ function parseDCC(source, start, domBuilder, errorHandler) {
3755
+ var next = source.charAt(start + 2);
3756
+ switch (next) {
3757
+ case "-":
3758
+ if (source.charAt(start + 3) === "-") {
3759
+ var end = source.indexOf("-->", start + 4);
3760
+ if (end > start) {
3761
+ domBuilder.comment(source, start + 4, end - start - 4);
3762
+ return end + 3;
3763
+ } else {
3764
+ errorHandler.error("Unclosed comment");
3765
+ return -1;
3766
+ }
3767
+ } else {
3768
+ return -1;
3769
+ }
3770
+ default:
3771
+ if (source.substr(start + 3, 6) == "CDATA[") {
3772
+ var end = source.indexOf("]]>", start + 9);
3773
+ domBuilder.startCDATA();
3774
+ domBuilder.characters(source, start + 9, end - start - 9);
3775
+ domBuilder.endCDATA();
3776
+ return end + 3;
3777
+ }
3778
+ var matchs = split(source, start);
3779
+ var len = matchs.length;
3780
+ if (len > 1 && /!doctype/i.test(matchs[0][0])) {
3781
+ var name = matchs[1][0];
3782
+ var pubid = false;
3783
+ var sysid = false;
3784
+ if (len > 3) {
3785
+ if (/^public$/i.test(matchs[2][0])) {
3786
+ pubid = matchs[3][0];
3787
+ sysid = len > 4 && matchs[4][0];
3788
+ } else if (/^system$/i.test(matchs[2][0])) {
3789
+ sysid = matchs[3][0];
3790
+ }
3791
+ }
3792
+ var lastMatch = matchs[len - 1];
3793
+ domBuilder.startDTD(name, pubid, sysid);
3794
+ domBuilder.endDTD();
3795
+ return lastMatch.index + lastMatch[0].length;
3796
+ }
3797
+ }
3798
+ return -1;
3799
+ }
3800
+ function parseInstruction(source, start, domBuilder) {
3801
+ var end = source.indexOf("?>", start);
3802
+ if (end) {
3803
+ var match = source.substring(start, end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
3804
+ if (match) {
3805
+ var len = match[0].length;
3806
+ domBuilder.processingInstruction(match[1], match[2]);
3807
+ return end + 2;
3808
+ } else {
3809
+ return -1;
3810
+ }
3811
+ }
3812
+ return -1;
3813
+ }
3814
+ function ElementAttributes() {
3815
+ this.attributeNames = {};
3816
+ }
3817
+ ElementAttributes.prototype = {
3818
+ setTagName: function(tagName) {
3819
+ if (!tagNamePattern.test(tagName)) {
3820
+ throw new Error("invalid tagName:" + tagName);
3821
+ }
3822
+ this.tagName = tagName;
3823
+ },
3824
+ addValue: function(qName, value, offset) {
3825
+ if (!tagNamePattern.test(qName)) {
3826
+ throw new Error("invalid attribute:" + qName);
3827
+ }
3828
+ this.attributeNames[qName] = this.length;
3829
+ this[this.length++] = { qName, value, offset };
3830
+ },
3831
+ length: 0,
3832
+ getLocalName: function(i) {
3833
+ return this[i].localName;
3834
+ },
3835
+ getLocator: function(i) {
3836
+ return this[i].locator;
3837
+ },
3838
+ getQName: function(i) {
3839
+ return this[i].qName;
3840
+ },
3841
+ getURI: function(i) {
3842
+ return this[i].uri;
3843
+ },
3844
+ getValue: function(i) {
3845
+ return this[i].value;
3846
+ }
3847
+ };
3848
+ function split(source, start) {
3849
+ var match;
3850
+ var buf = [];
3851
+ var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
3852
+ reg.lastIndex = start;
3853
+ reg.exec(source);
3854
+ while (match = reg.exec(source)) {
3855
+ buf.push(match);
3856
+ if (match[1])
3857
+ return buf;
3858
+ }
3859
+ }
3860
+ exports.XMLReader = XMLReader;
3861
+ exports.ParseError = ParseError;
3862
+ }
3863
+ });
3864
+
3865
+ // ../../node_modules/@xmldom/xmldom/lib/dom-parser.js
3866
+ var require_dom_parser = __commonJS({
3867
+ "../../node_modules/@xmldom/xmldom/lib/dom-parser.js"(exports) {
3868
+ var conventions = require_conventions();
3869
+ var dom = require_dom();
3870
+ var entities = require_entities();
3871
+ var sax = require_sax();
3872
+ var DOMImplementation = dom.DOMImplementation;
3873
+ var NAMESPACE = conventions.NAMESPACE;
3874
+ var ParseError = sax.ParseError;
3875
+ var XMLReader = sax.XMLReader;
3876
+ function DOMParser4(options) {
3877
+ this.options = options || { locator: {} };
3878
+ }
3879
+ DOMParser4.prototype.parseFromString = function(source, mimeType) {
3880
+ var options = this.options;
3881
+ var sax2 = new XMLReader();
3882
+ var domBuilder = options.domBuilder || new DOMHandler();
3883
+ var errorHandler = options.errorHandler;
3884
+ var locator = options.locator;
3885
+ var defaultNSMap = options.xmlns || {};
3886
+ var isHTML = /\/x?html?$/.test(mimeType);
3887
+ var entityMap = isHTML ? entities.HTML_ENTITIES : entities.XML_ENTITIES;
3888
+ if (locator) {
3889
+ domBuilder.setDocumentLocator(locator);
3890
+ }
3891
+ sax2.errorHandler = buildErrorHandler(errorHandler, domBuilder, locator);
3892
+ sax2.domBuilder = options.domBuilder || domBuilder;
3893
+ if (isHTML) {
3894
+ defaultNSMap[""] = NAMESPACE.HTML;
3895
+ }
3896
+ defaultNSMap.xml = defaultNSMap.xml || NAMESPACE.XML;
3897
+ if (source && typeof source === "string") {
3898
+ sax2.parse(source, defaultNSMap, entityMap);
3899
+ } else {
3900
+ sax2.errorHandler.error("invalid doc source");
3901
+ }
3902
+ return domBuilder.doc;
3903
+ };
3904
+ function buildErrorHandler(errorImpl, domBuilder, locator) {
3905
+ if (!errorImpl) {
3906
+ if (domBuilder instanceof DOMHandler) {
3907
+ return domBuilder;
3908
+ }
3909
+ errorImpl = domBuilder;
3910
+ }
3911
+ var errorHandler = {};
3912
+ var isCallback = errorImpl instanceof Function;
3913
+ locator = locator || {};
3914
+ function build(key) {
3915
+ var fn = errorImpl[key];
3916
+ if (!fn && isCallback) {
3917
+ fn = errorImpl.length == 2 ? function(msg) {
3918
+ errorImpl(key, msg);
3919
+ } : errorImpl;
3920
+ }
3921
+ errorHandler[key] = fn && function(msg) {
3922
+ fn("[xmldom " + key + "] " + msg + _locator(locator));
3923
+ } || function() {
3924
+ };
3925
+ }
3926
+ build("warning");
3927
+ build("error");
3928
+ build("fatalError");
3929
+ return errorHandler;
3930
+ }
3931
+ function DOMHandler() {
3932
+ this.cdata = false;
3933
+ }
3934
+ function position(locator, node) {
3935
+ node.lineNumber = locator.lineNumber;
3936
+ node.columnNumber = locator.columnNumber;
3937
+ }
3938
+ DOMHandler.prototype = {
3939
+ startDocument: function() {
3940
+ this.doc = new DOMImplementation().createDocument(null, null, null);
3941
+ if (this.locator) {
3942
+ this.doc.documentURI = this.locator.systemId;
3943
+ }
3944
+ },
3945
+ startElement: function(namespaceURI, localName, qName, attrs) {
3946
+ var doc = this.doc;
3947
+ var el = doc.createElementNS(namespaceURI, qName || localName);
3948
+ var len = attrs.length;
3949
+ appendElement(this, el);
3950
+ this.currentElement = el;
3951
+ this.locator && position(this.locator, el);
3952
+ for (var i = 0; i < len; i++) {
3953
+ var namespaceURI = attrs.getURI(i);
3954
+ var value = attrs.getValue(i);
3955
+ var qName = attrs.getQName(i);
3956
+ var attr = doc.createAttributeNS(namespaceURI, qName);
3957
+ this.locator && position(attrs.getLocator(i), attr);
3958
+ attr.value = attr.nodeValue = value;
3959
+ el.setAttributeNode(attr);
3960
+ }
3961
+ },
3962
+ endElement: function(namespaceURI, localName, qName) {
3963
+ var current = this.currentElement;
3964
+ var tagName = current.tagName;
3965
+ this.currentElement = current.parentNode;
3966
+ },
3967
+ startPrefixMapping: function(prefix, uri) {
3968
+ },
3969
+ endPrefixMapping: function(prefix) {
3970
+ },
3971
+ processingInstruction: function(target, data) {
3972
+ var ins = this.doc.createProcessingInstruction(target, data);
3973
+ this.locator && position(this.locator, ins);
3974
+ appendElement(this, ins);
3975
+ },
3976
+ ignorableWhitespace: function(ch, start, length) {
3977
+ },
3978
+ characters: function(chars, start, length) {
3979
+ chars = _toString.apply(this, arguments);
3980
+ if (chars) {
3981
+ if (this.cdata) {
3982
+ var charNode = this.doc.createCDATASection(chars);
3983
+ } else {
3984
+ var charNode = this.doc.createTextNode(chars);
3985
+ }
3986
+ if (this.currentElement) {
3987
+ this.currentElement.appendChild(charNode);
3988
+ } else if (/^\s*$/.test(chars)) {
3989
+ this.doc.appendChild(charNode);
3990
+ }
3991
+ this.locator && position(this.locator, charNode);
3992
+ }
3993
+ },
3994
+ skippedEntity: function(name) {
3995
+ },
3996
+ endDocument: function() {
3997
+ this.doc.normalize();
3998
+ },
3999
+ setDocumentLocator: function(locator) {
4000
+ if (this.locator = locator) {
4001
+ locator.lineNumber = 0;
4002
+ }
4003
+ },
4004
+ comment: function(chars, start, length) {
4005
+ chars = _toString.apply(this, arguments);
4006
+ var comm = this.doc.createComment(chars);
4007
+ this.locator && position(this.locator, comm);
4008
+ appendElement(this, comm);
4009
+ },
4010
+ startCDATA: function() {
4011
+ this.cdata = true;
4012
+ },
4013
+ endCDATA: function() {
4014
+ this.cdata = false;
4015
+ },
4016
+ startDTD: function(name, publicId, systemId) {
4017
+ var impl = this.doc.implementation;
4018
+ if (impl && impl.createDocumentType) {
4019
+ var dt = impl.createDocumentType(name, publicId, systemId);
4020
+ this.locator && position(this.locator, dt);
4021
+ appendElement(this, dt);
4022
+ this.doc.doctype = dt;
4023
+ }
4024
+ },
4025
+ warning: function(error) {
4026
+ console.warn("[xmldom warning] " + error, _locator(this.locator));
4027
+ },
4028
+ error: function(error) {
4029
+ console.error("[xmldom error] " + error, _locator(this.locator));
4030
+ },
4031
+ fatalError: function(error) {
4032
+ throw new ParseError(error, this.locator);
4033
+ }
4034
+ };
4035
+ function _locator(l) {
4036
+ if (l) {
4037
+ return "\n@" + (l.systemId || "") + "#[line:" + l.lineNumber + ",col:" + l.columnNumber + "]";
4038
+ }
4039
+ }
4040
+ function _toString(chars, start, length) {
4041
+ if (typeof chars == "string") {
4042
+ return chars.substr(start, length);
4043
+ } else {
4044
+ if (chars.length >= start + length || start) {
4045
+ return new java.lang.String(chars, start, length) + "";
4046
+ }
4047
+ return chars;
4048
+ }
4049
+ }
4050
+ "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g, function(key) {
4051
+ DOMHandler.prototype[key] = function() {
4052
+ return null;
4053
+ };
4054
+ });
4055
+ function appendElement(hander, node) {
4056
+ if (!hander.currentElement) {
4057
+ hander.doc.appendChild(node);
4058
+ } else {
4059
+ hander.currentElement.appendChild(node);
4060
+ }
4061
+ }
4062
+ exports.__DOMHandler = DOMHandler;
4063
+ exports.DOMParser = DOMParser4;
4064
+ exports.DOMImplementation = dom.DOMImplementation;
4065
+ exports.XMLSerializer = dom.XMLSerializer;
4066
+ }
4067
+ });
4068
+
4069
+ // ../../node_modules/@xmldom/xmldom/lib/index.js
4070
+ var require_lib = __commonJS({
4071
+ "../../node_modules/@xmldom/xmldom/lib/index.js"(exports) {
4072
+ var dom = require_dom();
4073
+ exports.DOMImplementation = dom.DOMImplementation;
4074
+ exports.XMLSerializer = dom.XMLSerializer;
4075
+ exports.DOMParser = require_dom_parser().DOMParser;
4076
+ }
4077
+ });
4078
+
4079
+ // src/gpx-loader.ts
4080
+ function parseTextSync(text, options) {
4081
+ const doc = new import_xmldom.DOMParser().parseFromString(text, "text/xml");
4082
+ const geojson = gpx(doc);
4083
+ const shape = options?.gis?.format || options?.gpx?.type || options?.gpx?.shape;
4084
+ switch (shape) {
4085
+ case "object-row-table": {
4086
+ const table = {
4087
+ shape: "object-row-table",
4088
+ data: geojson.features
4089
+ };
4090
+ return table;
4091
+ }
4092
+ case "geojson-row-table": {
4093
+ const table = {
4094
+ shape: "geojson-row-table",
4095
+ data: geojson.features
4096
+ };
4097
+ return table;
4098
+ }
4099
+ case "geojson":
4100
+ return geojson;
4101
+ case "binary":
4102
+ return geojsonToBinary(geojson.features);
4103
+ case "raw":
4104
+ return doc;
4105
+ default:
4106
+ return geojson;
4107
+ }
4108
+ }
4109
+ var import_xmldom, VERSION, GPX_HEADER, GPXLoader;
4110
+ var init_gpx_loader = __esm({
4111
+ "src/gpx-loader.ts"() {
4112
+ init_src();
4113
+ init_togeojson_es();
4114
+ import_xmldom = __toModule(require_lib());
4115
+ VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
4116
+ GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
4117
+ <gpx`;
4118
+ GPXLoader = {
4119
+ name: "GPX (GPS exchange format)",
4120
+ id: "gpx",
4121
+ module: "kml",
4122
+ version: VERSION,
4123
+ extensions: ["gpx"],
4124
+ mimeTypes: ["application/gpx+xml"],
4125
+ text: true,
4126
+ tests: [GPX_HEADER],
4127
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
4128
+ parseTextSync,
4129
+ options: {
4130
+ gpx: {},
4131
+ gis: {}
4132
+ }
4133
+ };
4134
+ }
4135
+ });
4136
+
4137
+ // src/kml-loader.ts
4138
+ function parseTextSync2(text, options) {
4139
+ const doc = new import_xmldom2.DOMParser().parseFromString(text, "text/xml");
4140
+ const geojson = kml(doc);
4141
+ const shape = options?.gis?.format || options?.kml?.type || options?.kml?.shape;
4142
+ switch (shape) {
4143
+ case "object-row-table": {
4144
+ const table = {
4145
+ shape: "object-row-table",
4146
+ data: geojson.features
4147
+ };
4148
+ return table;
4149
+ }
4150
+ case "geojson-row-table": {
4151
+ const table = {
4152
+ shape: "geojson-row-table",
4153
+ data: geojson.features
4154
+ };
4155
+ return table;
4156
+ }
4157
+ case "geojson":
4158
+ return geojson;
4159
+ case "binary":
4160
+ return geojsonToBinary(geojson.features);
4161
+ case "raw":
4162
+ return doc;
4163
+ default:
4164
+ return geojson;
4165
+ }
4166
+ }
4167
+ var import_xmldom2, VERSION2, KML_HEADER, KMLLoader;
4168
+ var init_kml_loader = __esm({
4169
+ "src/kml-loader.ts"() {
4170
+ init_src();
4171
+ init_togeojson_es();
4172
+ import_xmldom2 = __toModule(require_lib());
4173
+ VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
4174
+ KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
4175
+ <kml xmlns="http://www.opengis.net/kml/2.2">`;
4176
+ KMLLoader = {
4177
+ name: "KML (Keyhole Markup Language)",
4178
+ id: "kml",
4179
+ module: "kml",
4180
+ version: VERSION2,
4181
+ extensions: ["kml"],
4182
+ mimeTypes: ["application/vnd.google-earth.kml+xml"],
4183
+ text: true,
4184
+ tests: [KML_HEADER],
4185
+ parse: async (arrayBuffer, options) => parseTextSync2(new TextDecoder().decode(arrayBuffer), options),
4186
+ parseTextSync: parseTextSync2,
4187
+ options: {
4188
+ kml: {},
4189
+ gis: {}
4190
+ }
4191
+ };
4192
+ }
4193
+ });
4194
+
4195
+ // src/tcx-loader.ts
4196
+ function parseTextSync3(text, options) {
4197
+ const doc = new import_xmldom3.DOMParser().parseFromString(text, "text/xml");
4198
+ const geojson = tcx(doc);
4199
+ const shape = options?.gis?.format || options?.tcx?.type || options?.tcx?.shape;
4200
+ switch (shape) {
4201
+ case "object-row-table": {
4202
+ const table = {
4203
+ shape: "object-row-table",
4204
+ data: geojson.features
4205
+ };
4206
+ return table;
4207
+ }
4208
+ case "geojson-row-table": {
4209
+ const table = {
4210
+ shape: "geojson-row-table",
4211
+ data: geojson.features
4212
+ };
4213
+ return table;
4214
+ }
4215
+ case "geojson":
4216
+ return geojson;
4217
+ case "binary":
4218
+ return geojsonToBinary(geojson.features);
4219
+ case "raw":
4220
+ return doc;
4221
+ default:
4222
+ return geojson;
4223
+ }
4224
+ }
4225
+ var import_xmldom3, VERSION3, TCX_HEADER, TCXLoader;
4226
+ var init_tcx_loader = __esm({
4227
+ "src/tcx-loader.ts"() {
4228
+ init_src();
4229
+ init_togeojson_es();
4230
+ import_xmldom3 = __toModule(require_lib());
4231
+ VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
4232
+ TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
4233
+ <TrainingCenterDatabase`;
4234
+ TCXLoader = {
4235
+ name: "TCX (Training Center XML)",
4236
+ id: "tcx",
4237
+ module: "kml",
4238
+ version: VERSION3,
4239
+ extensions: ["tcx"],
4240
+ mimeTypes: ["application/vnd.garmin.tcx+xml"],
4241
+ text: true,
4242
+ tests: [TCX_HEADER],
4243
+ parse: async (arrayBuffer, options) => parseTextSync3(new TextDecoder().decode(arrayBuffer), options),
4244
+ parseTextSync: parseTextSync3,
4245
+ options: {
4246
+ tcx: {},
4247
+ gis: {}
4248
+ }
4249
+ };
4250
+ }
4251
+ });
4252
+
4253
+ // src/index.ts
4254
+ var src_exports = {};
4255
+ __export(src_exports, {
4256
+ GPXLoader: () => GPXLoader,
4257
+ KMLLoader: () => KMLLoader,
4258
+ TCXLoader: () => TCXLoader
4259
+ });
4260
+ var init_src2 = __esm({
4261
+ "src/index.ts"() {
4262
+ init_gpx_loader();
4263
+ init_kml_loader();
4264
+ init_tcx_loader();
4265
+ }
4266
+ });
4267
+
4268
+ // src/bundle.ts
4269
+ var require_bundle = __commonJS({
4270
+ "src/bundle.ts"(exports, module) {
4271
+ var moduleExports = (init_src2(), src_exports);
4272
+ globalThis.loaders = globalThis.loaders || {};
4273
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
4274
+ }
4275
+ });
4276
+ require_bundle();
4277
+ })();