@kalisio/common-geospatial 0.8.0 → 0.10.0

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.
@@ -0,0 +1,539 @@
1
+ import { aj as Y, ag as j, ah as ge, ak as _e, al as De } from "../ring-Cks2pGr8.js";
2
+ import { v as me } from "../geojson-CJ6QZ9pN.js";
3
+ import "@turf/convex";
4
+ import "@turf/meta";
5
+ import "@turf/helpers";
6
+ import { gpx as xe, kml as Ae } from "@tmcw/togeojson";
7
+ var he = { exports: {} };
8
+ var Ce = he.exports, Oe;
9
+ function Ie() {
10
+ return Oe || (Oe = 1, (function(o, E) {
11
+ ((R, l) => {
12
+ o.exports = l();
13
+ })(Ce, function R() {
14
+ var l = typeof self < "u" ? self : typeof window < "u" ? window : l !== void 0 ? l : {}, U = !l.document && !!l.postMessage, de = l.IS_PAPA_WORKER || !1, se = {}, be = 0, u = {};
15
+ function Ee(t) {
16
+ return t.charCodeAt(0) === 65279 ? t.slice(1) : t;
17
+ }
18
+ function W(t) {
19
+ this._handle = null, this._finished = !1, this._completed = !1, this._halted = !1, this._input = null, this._baseIndex = 0, this._partialLine = "", this._rowCount = 0, this._start = 0, this._nextChunk = null, this.isFirstChunk = !0, this._completeResults = { data: [], errors: [], meta: {} }, (function(e) {
20
+ var r = fe(e);
21
+ r.chunkSize = parseInt(r.chunkSize), e.step || e.chunk || (r.chunkSize = null), this._handle = new Re(r), (this._handle.streamer = this)._config = r;
22
+ }).call(this, t), this.parseChunk = function(e, r) {
23
+ var s = parseInt(this._config.skipFirstNLines) || 0;
24
+ if (this.isFirstChunk && 0 < s) {
25
+ let m = this._config.newline;
26
+ m || (n = this._config.quoteChar || '"', m = this._handle.guessLineEndings(e, n)), e = [...e.split(m).slice(s)].join(m);
27
+ }
28
+ this.isFirstChunk && b(this._config.beforeFirstChunk) && (n = this._config.beforeFirstChunk(e)) !== void 0 && (e = n), this.isFirstChunk = !1, this._halted = !1;
29
+ var s = this._partialLine + e, n = (this._partialLine = "", this._handle.parse(s, this._baseIndex, !this._finished));
30
+ if (!this._handle.paused() && !this._handle.aborted()) {
31
+ if (e = n.meta.cursor, s = (this._finished || (this._partialLine = s.substring(e - this._baseIndex), this._baseIndex = e), n && n.data && (this._rowCount += n.data.length), this._finished || this._config.preview && this._rowCount >= this._config.preview), de) l.postMessage({ results: n, workerId: u.WORKER_ID, finished: s });
32
+ else if (b(this._config.chunk) && !r) {
33
+ if (this._config.chunk(n, this._handle), this._handle.paused() || this._handle.aborted()) return void (this._halted = !0);
34
+ this._completeResults = n = void 0;
35
+ }
36
+ return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(n.data), this._completeResults.errors = this._completeResults.errors.concat(n.errors), this._completeResults.meta = n.meta), this._completed || !s || !b(this._config.complete) || n && n.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = !0), s || n && n.meta.paused || this._nextChunk(), n;
37
+ }
38
+ this._halted = !0;
39
+ }, this._sendError = function(e) {
40
+ b(this._config.error) ? this._config.error(e) : de && this._config.error && l.postMessage({ workerId: u.WORKER_ID, error: e, finished: !1 });
41
+ };
42
+ }
43
+ function ae(t) {
44
+ var e;
45
+ (t = t || {}).chunkSize || (t.chunkSize = u.RemoteChunkSize), W.call(this, t), this._nextChunk = U ? function() {
46
+ this._readChunk(), this._chunkLoaded();
47
+ } : function() {
48
+ this._readChunk();
49
+ }, this.stream = function(r) {
50
+ this._input = r, this._nextChunk();
51
+ }, this._readChunk = function() {
52
+ if (this._finished) this._chunkLoaded();
53
+ else {
54
+ if (e = new XMLHttpRequest(), this._config.withCredentials && (e.withCredentials = this._config.withCredentials), U || (e.onload = $(this._chunkLoaded, this), e.onerror = $(this._chunkError, this)), e.ontimeout = $(this._chunkTimeout, this), e.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !U), this._config.downloadTimeout && !U && (e.timeout = this._config.downloadTimeout), this._config.downloadRequestHeaders) {
55
+ var r, s = this._config.downloadRequestHeaders;
56
+ for (r in s) e.setRequestHeader(r, s[r]);
57
+ }
58
+ var n;
59
+ this._config.chunkSize && (n = this._start + this._config.chunkSize - 1, e.setRequestHeader("Range", "bytes=" + this._start + "-" + n));
60
+ try {
61
+ e.send(this._config.downloadRequestBody);
62
+ } catch (m) {
63
+ this._chunkError(m.message);
64
+ }
65
+ U && e.status === 0 && this._chunkError();
66
+ }
67
+ }, this._chunkLoaded = function() {
68
+ e.readyState === 4 && (e.status < 200 || 400 <= e.status ? this._chunkError() : (this._start += this._config.chunkSize || e.responseText.length, this._finished = !this._config.chunkSize || this._start >= ((r) => (r = r.getResponseHeader("Content-Range")) !== null ? parseInt(r.substring(r.lastIndexOf("/") + 1)) : -1)(e), this.parseChunk(e.responseText)));
69
+ }, this._chunkError = function(r) {
70
+ r = e.statusText || r, this._sendError(new Error(r));
71
+ }, this._chunkTimeout = function() {
72
+ this._chunkError("Request timed out after " + this._config.downloadTimeout + "ms");
73
+ };
74
+ }
75
+ function oe(t) {
76
+ (t = t || {}).chunkSize || (t.chunkSize = u.LocalChunkSize), W.call(this, t);
77
+ var e, r, s = typeof FileReader < "u";
78
+ this.stream = function(n) {
79
+ this._input = n, r = n.slice || n.webkitSlice || n.mozSlice, s ? ((e = new FileReader()).onload = $(this._chunkLoaded, this), e.onerror = $(this._chunkError, this)) : e = new FileReaderSync(), this._nextChunk();
80
+ }, this._nextChunk = function() {
81
+ this._finished || this._config.preview && !(this._rowCount < this._config.preview) || this._readChunk();
82
+ }, this._readChunk = function() {
83
+ var n = this._input, m = (this._config.chunkSize && (m = Math.min(this._start + this._config.chunkSize, this._input.size), n = r.call(n, this._start, m)), e.readAsText(n, this._config.encoding));
84
+ s || this._chunkLoaded({ target: { result: m } });
85
+ }, this._chunkLoaded = function(n) {
86
+ this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(n.target.result);
87
+ }, this._chunkError = function() {
88
+ this._sendError(e.error);
89
+ };
90
+ }
91
+ function ee(t) {
92
+ var e;
93
+ W.call(this, t = t || {}), this.stream = function(r) {
94
+ return e = r, this._nextChunk();
95
+ }, this._nextChunk = function() {
96
+ var r, s;
97
+ if (!this._finished) return r = this._config.chunkSize, e = r ? (s = e.substring(0, r), e.substring(r)) : (s = e, ""), this._finished = !e, this.parseChunk(s);
98
+ };
99
+ }
100
+ function ue(t) {
101
+ W.call(this, t = t || {});
102
+ var e = [], r = !0, s = !1;
103
+ this.pause = function() {
104
+ W.prototype.pause.apply(this, arguments), this._input.pause();
105
+ }, this.resume = function() {
106
+ W.prototype.resume.apply(this, arguments), this._input.resume();
107
+ }, this.stream = function(n) {
108
+ this._input = n, this._input.on("data", this._streamData), this._input.on("end", this._streamEnd), this._input.on("error", this._streamError);
109
+ }, this._checkIsFinished = function() {
110
+ s && e.length === 1 && (this._finished = !0);
111
+ }, this._nextChunk = function() {
112
+ this._checkIsFinished(), e.length ? this.parseChunk(e.shift()) : r = !0;
113
+ }, this._streamData = $(function(n) {
114
+ try {
115
+ e.push(typeof n == "string" ? n : n.toString(this._config.encoding)), r && (r = !1, this._checkIsFinished(), this.parseChunk(e.shift()));
116
+ } catch (m) {
117
+ this._streamError(m);
118
+ }
119
+ }, this), this._streamError = $(function(n) {
120
+ this._streamCleanUp(), this._sendError(n);
121
+ }, this), this._streamEnd = $(function() {
122
+ this._streamCleanUp(), s = !0, this._streamData("");
123
+ }, this), this._streamCleanUp = $(function() {
124
+ this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError);
125
+ }, this);
126
+ }
127
+ function Re(t) {
128
+ var e, r, s, n, m = Math.pow(2, 53), I = -m, q = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/, J = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/, v = this, L = 0, h = 0, F = !1, f = !1, c = [], i = { data: [], errors: [], meta: {} };
129
+ function M(_) {
130
+ return t.skipEmptyLines === "greedy" ? _.join("").trim() === "" : _.length === 1 && _[0].length === 0;
131
+ }
132
+ function k() {
133
+ if (i && s && (N("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + u.DefaultDelimiter + "'"), s = !1), t.skipEmptyLines && (i.data = i.data.filter(function(a) {
134
+ return !M(a);
135
+ })), T()) {
136
+ let a = function(D) {
137
+ c.push(D);
138
+ };
139
+ if (i) if (Array.isArray(i.data[0])) {
140
+ for (var _ = 0; T() && _ < i.data.length; _++) i.data[_].forEach(a);
141
+ i.data.splice(0, 1);
142
+ } else i.data.forEach(a);
143
+ }
144
+ function p(a, D) {
145
+ for (var A = t.header ? {} : [], y = 0; y < a.length; y++) {
146
+ var w = y, g = a[y], g = ((z, d) => ((O) => (t.dynamicTypingFunction && t.dynamicTyping[O] === void 0 && (t.dynamicTyping[O] = t.dynamicTypingFunction(O)), (t.dynamicTyping[O] || t.dynamicTyping) === !0))(z) ? d === "true" || d === "TRUE" || d !== "false" && d !== "FALSE" && (((O) => {
147
+ if (q.test(O) && (O = parseFloat(O), I < O && O < m))
148
+ return 1;
149
+ })(d) ? parseFloat(d) : J.test(d) ? new Date(d) : d === "" ? null : d) : d)(w = t.header ? y >= c.length ? "__parsed_extra" : c[y] : w, g = t.transform ? t.transform(g, w) : g);
150
+ w === "__parsed_extra" ? (A[w] = A[w] || [], A[w].push(g)) : A[w] = g;
151
+ }
152
+ return t.header && (y > c.length ? N("FieldMismatch", "TooManyFields", "Too many fields: expected " + c.length + " fields but parsed " + y, h + D) : y < c.length && N("FieldMismatch", "TooFewFields", "Too few fields: expected " + c.length + " fields but parsed " + y, h + D)), A;
153
+ }
154
+ var S;
155
+ i && (t.header || t.dynamicTyping || t.transform) && (S = 1, !i.data.length || Array.isArray(i.data[0]) ? (i.data = i.data.map(p), S = i.data.length) : i.data = p(i.data, 0), t.header && i.meta && (i.meta.fields = c), h += S);
156
+ }
157
+ function T() {
158
+ return t.header && c.length === 0;
159
+ }
160
+ function N(_, p, S, a) {
161
+ _ = { type: _, code: p, message: S }, a !== void 0 && (_.row = a), i.errors.push(_);
162
+ }
163
+ b(t.step) && (n = t.step, t.step = function(_) {
164
+ i = _, T() ? k() : (k(), i.data.length !== 0 && (L += _.data.length, t.preview && L > t.preview ? r.abort() : (i.data = i.data[0], n(i, v))));
165
+ }), this.parse = function(_, p, S) {
166
+ var a = t.quoteChar || '"', a = (t.newline || (t.newline = this.guessLineEndings(_, a)), s = !1, t.delimiter ? b(t.delimiter) && (t.delimiter = t.delimiter(_), i.meta.delimiter = t.delimiter) : ((a = ((D, A, y, w, g) => {
167
+ var z, d, O, Q;
168
+ g = g || [",", " ", "|", ";", u.RECORD_SEP, u.UNIT_SEP];
169
+ for (var V = 0; V < g.length; V++) {
170
+ for (var B, re = g[V], C = 0, H = 0, x = 0, P = (O = void 0, new le({ comments: w, delimiter: re, newline: A, preview: 10 }).parse(D)), X = 0; X < P.data.length; X++) y && M(P.data[X]) ? x++ : (B = P.data[X].length, H += B, O === void 0 ? O = B : 0 < B && (C += Math.abs(B - O), O = B));
171
+ 0 < P.data.length && (H /= P.data.length - x), 1.99 < H && (d === void 0 || C < d || C === d && Q < H) && (d = C, z = re, Q = H);
172
+ }
173
+ return { successful: !!(t.delimiter = z), bestDelimiter: z };
174
+ })(_, t.newline, t.skipEmptyLines, t.comments, t.delimitersToGuess)).successful ? t.delimiter = a.bestDelimiter : (s = !0, t.delimiter = u.DefaultDelimiter), i.meta.delimiter = t.delimiter), fe(t));
175
+ return a.header = T(), t.preview && t.header && a.preview++, e = _, r = new le(a), i = r.parse(e, p, S), k(), F ? { meta: { paused: !0 } } : i || { meta: { paused: !1 } };
176
+ }, this.paused = function() {
177
+ return F;
178
+ }, this.pause = function() {
179
+ F = !0, r.abort(), e = b(t.chunk) ? "" : e.substring(r.getCharIndex());
180
+ }, this.resume = function() {
181
+ v.streamer._halted ? (F = !1, v.streamer.parseChunk(e, !0)) : setTimeout(v.resume, 3);
182
+ }, this.aborted = function() {
183
+ return f;
184
+ }, this.abort = function() {
185
+ f = !0, r.abort(), i.meta.aborted = !0, b(t.complete) && t.complete(i), e = "";
186
+ }, this.guessLineEndings = function(D, a) {
187
+ D = D.substring(0, 1048576);
188
+ var a = new RegExp(te(a) + "([^]*?)" + te(a), "gm"), S = (D = D.replace(a, "")).split("\r"), a = D.split(`
189
+ `), D = 1 < a.length && a[0].length < S[0].length;
190
+ if (S.length === 1 || D) return `
191
+ `;
192
+ for (var A = 0, y = 0; y < S.length; y++) S[y][0] === `
193
+ ` && A++;
194
+ return A >= S.length / 2 ? `\r
195
+ ` : "\r";
196
+ };
197
+ }
198
+ function te(t) {
199
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
200
+ }
201
+ function le(t) {
202
+ var e = (t = t || {}).delimiter, r = t.newline, s = t.comments, n = t.step, m = t.preview, I = t.fastMode, q = null, J = !1, v = t.quoteChar == null ? '"' : t.quoteChar, L = v;
203
+ if (t.escapeChar !== void 0 && (L = t.escapeChar), (typeof e != "string" || -1 < u.BAD_DELIMITERS.indexOf(e)) && (e = ","), s === e) throw new Error("Comment character same as delimiter");
204
+ s === !0 ? s = "#" : (typeof s != "string" || -1 < u.BAD_DELIMITERS.indexOf(s)) && (s = !1), r !== `
205
+ ` && r !== "\r" && r !== `\r
206
+ ` && (r = `
207
+ `);
208
+ var h = 0, F = !1;
209
+ this.parse = function(f, c, i) {
210
+ if (typeof f != "string") throw new Error("Input must be a string");
211
+ var M = f.length, k = e.length, T = r.length, N = s.length, _ = b(n), p = [], S = [], a = [], D = h = 0;
212
+ if (!f) return C();
213
+ if (I || I !== !1 && f.indexOf(v) === -1) {
214
+ for (var A = f.split(r), y = 0; y < A.length; y++) {
215
+ if (a = A[y], h += a.length, y !== A.length - 1) h += r.length;
216
+ else if (i) return C();
217
+ if (!s || a.substring(0, N) !== s) {
218
+ if (_) {
219
+ if (p = [], Q(a.split(e)), H(), F) return C();
220
+ } else Q(a.split(e));
221
+ if (m && m <= y) return p = p.slice(0, m), C(!0);
222
+ }
223
+ }
224
+ return C();
225
+ }
226
+ for (var w = f.indexOf(e, h), g = f.indexOf(r, h), z = new RegExp(te(L) + te(v), "g"), d = f.indexOf(v, h); ; ) if (f[h] === v) for (d = h, h++; ; ) {
227
+ if ((d = f.indexOf(v, d + 1)) === -1) return i || S.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: p.length, index: h }), B();
228
+ if (d === M - 1) return B(f.substring(h, d).replace(z, v));
229
+ if (v === L && f[d + 1] === L) d++;
230
+ else if (v === L || d === 0 || f[d - 1] !== L) {
231
+ w !== -1 && w < d + 1 && (w = f.indexOf(e, d + 1));
232
+ var O = V((g = g !== -1 && g < d + 1 ? f.indexOf(r, d + 1) : g) === -1 ? w : Math.min(w, g));
233
+ if (f.substr(d + 1 + O, k) === e) {
234
+ a.push(f.substring(h, d).replace(z, v)), f[h = d + 1 + O + k] !== v && (d = f.indexOf(v, h)), w = f.indexOf(e, h), g = f.indexOf(r, h);
235
+ break;
236
+ }
237
+ if (O = V(g), f.substring(d + 1 + O, d + 1 + O + T) === r) {
238
+ if (a.push(f.substring(h, d).replace(z, v)), re(d + 1 + O + T), w = f.indexOf(e, h), d = f.indexOf(v, h), _ && (H(), F)) return C();
239
+ if (m && p.length >= m) return C(!0);
240
+ break;
241
+ }
242
+ S.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: p.length, index: h }), d++;
243
+ }
244
+ }
245
+ else if (s && a.length === 0 && f.substring(h, h + N) === s) {
246
+ if (g === -1) return C();
247
+ h = g + T, g = f.indexOf(r, h), w = f.indexOf(e, h);
248
+ } else if (w !== -1 && (w < g || g === -1)) a.push(f.substring(h, w)), h = w + k, w = f.indexOf(e, h);
249
+ else {
250
+ if (g === -1) break;
251
+ if (a.push(f.substring(h, g)), re(g + T), _ && (H(), F)) return C();
252
+ if (m && p.length >= m) return C(!0);
253
+ }
254
+ return B();
255
+ function Q(x) {
256
+ p.push(x), D = h;
257
+ }
258
+ function V(x) {
259
+ var P = 0;
260
+ return P = x !== -1 && (x = f.substring(d + 1, x)) && x.trim() === "" ? x.length : P;
261
+ }
262
+ function B(x) {
263
+ return i || (x === void 0 && (x = f.substring(h)), a.push(x), h = M, Q(a), _ && H()), C();
264
+ }
265
+ function re(x) {
266
+ h = x, Q(a), a = [], g = f.indexOf(r, h);
267
+ }
268
+ function C(x) {
269
+ if (t.header && !c && p.length && !J) {
270
+ var P = p[0], X = /* @__PURE__ */ Object.create(null), ce = new Set(P);
271
+ let ke = !1;
272
+ for (let Z = 0; Z < P.length; Z++) {
273
+ let K = Ee(P[Z]);
274
+ if (X[K = b(t.transformHeader) ? t.transformHeader(K, Z) : K]) {
275
+ let ne, ve = X[K];
276
+ for (; ne = K + "_" + ve, ve++, ce.has(ne); ) ;
277
+ ce.add(ne), P[Z] = ne, X[K]++, ke = !0, (q = q === null ? {} : q)[ne] = K;
278
+ } else X[K] = 1, P[Z] = K;
279
+ ce.add(K);
280
+ }
281
+ ke && console.warn("Duplicate headers found and renamed."), J = !0;
282
+ }
283
+ return { data: p, errors: S, meta: { delimiter: e, linebreak: r, aborted: F, truncated: !!x, cursor: D + (c || 0), renamedHeaders: q } };
284
+ }
285
+ function H() {
286
+ n(C()), p = [], S = [];
287
+ }
288
+ }, this.abort = function() {
289
+ F = !0;
290
+ }, this.getCharIndex = function() {
291
+ return h;
292
+ };
293
+ }
294
+ function Te(t) {
295
+ var e = t.data, r = se[e.workerId], s = !1;
296
+ if (e.error) r.userError(e.error, e.file);
297
+ else if (e.results && e.results.data) {
298
+ var n = { abort: function() {
299
+ s = !0, ye(e.workerId, { data: [], errors: [], meta: { aborted: !0 } });
300
+ }, pause: we, resume: we };
301
+ if (b(r.userStep)) {
302
+ for (var m = 0; m < e.results.data.length && (r.userStep({ data: e.results.data[m], errors: e.results.errors, meta: e.results.meta }, n), !s); m++) ;
303
+ delete e.results;
304
+ } else b(r.userChunk) && (r.userChunk(e.results, n, e.file), delete e.results);
305
+ }
306
+ e.finished && !s && ye(e.workerId, e.results);
307
+ }
308
+ function ye(t, e) {
309
+ var r = se[t];
310
+ b(r.userComplete) && r.userComplete(e), r.terminate(), delete se[t];
311
+ }
312
+ function we() {
313
+ throw new Error("Not implemented.");
314
+ }
315
+ function fe(t) {
316
+ if (typeof t != "object" || t === null) return t;
317
+ var e, r = Array.isArray(t) ? [] : {};
318
+ for (e in t) r[e] = fe(t[e]);
319
+ return r;
320
+ }
321
+ function $(t, e) {
322
+ return function() {
323
+ t.apply(e, arguments);
324
+ };
325
+ }
326
+ function b(t) {
327
+ return typeof t == "function";
328
+ }
329
+ return u.parse = function(t, e) {
330
+ var r = (e = e || {}).dynamicTyping || !1;
331
+ if (b(r) && (e.dynamicTypingFunction = r, r = {}), e.dynamicTyping = r, e.transform = !!b(e.transform) && e.transform, e.downloadTimeout !== void 0) {
332
+ var r = parseInt(e.downloadTimeout);
333
+ if (isNaN(r)) throw new Error("Config downloadTimeout value (" + e.downloadTimeout + ") not parsable by parseInt(val).");
334
+ e.downloadTimeout = r;
335
+ }
336
+ if (!e.worker || !u.WORKERS_SUPPORTED) return r = null, u.NODE_STREAM_INPUT, typeof t == "string" ? (t = Ee(t), r = new (e.download ? ae : ee)(e)) : t.readable === !0 && b(t.read) && b(t.on) ? r = new ue(e) : (l.File && t instanceof File || t instanceof Object) && (r = new oe(e)), r.stream(t);
337
+ (r = (() => {
338
+ var s;
339
+ return !!u.WORKERS_SUPPORTED && (s = (() => {
340
+ var n = l.URL || l.webkitURL || null, m = R.toString();
341
+ return u.BLOB_URL || (u.BLOB_URL = n.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ", "(", m, ")();"], { type: "text/javascript" })));
342
+ })(), (s = new l.Worker(s)).onmessage = Te, s.id = be++, se[s.id] = s);
343
+ })()).userStep = e.step, r.userChunk = e.chunk, r.userComplete = e.complete, r.userError = e.error, e.step = b(e.step), e.chunk = b(e.chunk), e.complete = b(e.complete), e.error = b(e.error), delete e.worker, r.postMessage({ input: t, config: e, workerId: r.id });
344
+ }, u.unparse = function(t, e) {
345
+ var r = !1, s = !0, n = ",", m = `\r
346
+ `, I = '"', q = I + I, J = !1, v = null, L = !1, h = ((() => {
347
+ if (typeof e == "object") {
348
+ if (typeof e.delimiter != "string" || u.BAD_DELIMITERS.filter(function(c) {
349
+ return e.delimiter.indexOf(c) !== -1;
350
+ }).length || (n = e.delimiter), typeof e.quotes != "boolean" && typeof e.quotes != "function" && !Array.isArray(e.quotes) || (r = e.quotes), typeof e.skipEmptyLines != "boolean" && typeof e.skipEmptyLines != "string" || (J = e.skipEmptyLines), typeof e.newline == "string" && (m = e.newline), typeof e.quoteChar == "string" && (I = e.quoteChar, q = I + I), typeof e.header == "boolean" && (s = e.header), Array.isArray(e.columns)) {
351
+ if (e.columns.length === 0) throw new Error("Option columns is empty");
352
+ v = e.columns;
353
+ }
354
+ e.escapeChar !== void 0 && (q = e.escapeChar + I), e.escapeFormulae instanceof RegExp ? L = e.escapeFormulae : typeof e.escapeFormulae == "boolean" && e.escapeFormulae && (L = /^[=+\-@\t\r].*$/);
355
+ }
356
+ })(), new RegExp(te(I), "g"));
357
+ if (typeof t == "string" && (t = JSON.parse(t)), Array.isArray(t)) {
358
+ if (!t.length || Array.isArray(t[0])) return F(null, t, J);
359
+ if (typeof t[0] == "object") return F(v || Object.keys(t[0]), t, J);
360
+ } else if (typeof t == "object") return typeof t.data == "string" && (t.data = JSON.parse(t.data)), Array.isArray(t.data) && (t.fields || (t.fields = t.meta && t.meta.fields || v), t.fields || (t.fields = Array.isArray(t.data[0]) ? t.fields : typeof t.data[0] == "object" ? Object.keys(t.data[0]) : []), Array.isArray(t.data[0]) || typeof t.data[0] == "object" || (t.data = [t.data])), F(t.fields || [], t.data || [], J);
361
+ throw new Error("Unable to serialize unrecognized input");
362
+ function F(c, i, M) {
363
+ var k = "", T = (typeof c == "string" && (c = JSON.parse(c)), typeof i == "string" && (i = JSON.parse(i)), Array.isArray(c) && 0 < c.length), N = !Array.isArray(i[0]);
364
+ if (T && s) {
365
+ for (var _ = 0; _ < c.length; _++) 0 < _ && (k += n), k += f(c[_], _);
366
+ 0 < i.length && (k += m);
367
+ }
368
+ for (var p = 0; p < i.length; p++) {
369
+ var S = (T ? c : i[p]).length, a = !1, D = T ? Object.keys(i[p]).length === 0 : i[p].length === 0;
370
+ if (M && !T && (a = M === "greedy" ? i[p].join("").trim() === "" : i[p].length === 1 && i[p][0].length === 0), M === "greedy" && T) {
371
+ for (var A = [], y = 0; y < S; y++) {
372
+ var w = N ? c[y] : y;
373
+ A.push(i[p][w]);
374
+ }
375
+ a = A.join("").trim() === "";
376
+ }
377
+ if (!a) {
378
+ for (var g = 0; g < S; g++) {
379
+ 0 < g && !D && (k += n);
380
+ var z = T && N ? c[g] : g;
381
+ k += f(i[p][z], g);
382
+ }
383
+ p < i.length - 1 && (!M || 0 < S && !D) && (k += m);
384
+ }
385
+ }
386
+ return k;
387
+ }
388
+ function f(c, i) {
389
+ var M, k, T;
390
+ return c == null ? "" : c.constructor === Date ? isNaN(c.getTime()) ? "" : c.toISOString() : (T = !1, L && typeof c == "string" && L.test(c) && (c = "'" + c, T = !0), k = (M = c.toString()).replace(h, q), (T = T || r === !0 || typeof r == "function" && r(c, i) || Array.isArray(r) && r[i] || ((N, _) => {
391
+ for (var p = 0; p < _.length; p++) if (-1 < N.indexOf(_[p])) return !0;
392
+ return !1;
393
+ })(k, u.BAD_DELIMITERS) || -1 < k.indexOf(n) || -1 < M.indexOf(I) || k.charAt(0) === " " || k.charAt(k.length - 1) === " ") ? I + k + I : k);
394
+ }
395
+ }, u.RECORD_SEP = "", u.UNIT_SEP = "", u.BYTE_ORDER_MARK = "\uFEFF", u.BAD_DELIMITERS = ["\r", `
396
+ `, '"', u.BYTE_ORDER_MARK], u.WORKERS_SUPPORTED = !U && !!l.Worker, u.NODE_STREAM_INPUT = 1, u.LocalChunkSize = 10485760, u.RemoteChunkSize = 5242880, u.DefaultDelimiter = ",", u.Parser = le, u.ParserHandle = Re, u.NetworkStreamer = ae, u.FileStreamer = oe, u.StringStreamer = ee, u.ReadableStreamStreamer = ue, de && (l.onmessage = function(t) {
397
+ t = t.data, u.WORKER_ID === void 0 && t && (u.WORKER_ID = t.workerId), typeof t.input == "string" ? l.postMessage({ workerId: u.WORKER_ID, results: u.parse(t.input, t.config), finished: !0 }) : (l.File && t.input instanceof File || t.input instanceof Object) && (t = u.parse(t.input, t.config)) && l.postMessage({ workerId: u.WORKER_ID, results: t, finished: !0 });
398
+ }), (ae.prototype = Object.create(W.prototype)).constructor = ae, (oe.prototype = Object.create(W.prototype)).constructor = oe, (ee.prototype = Object.create(ee.prototype)).constructor = ee, (ue.prototype = Object.create(W.prototype)).constructor = ue, u;
399
+ });
400
+ })(he)), he.exports;
401
+ }
402
+ Ie();
403
+ async function Se(o) {
404
+ const E = await fetch(o);
405
+ if (!E.ok) {
406
+ const R = new Error(`HTTP ${E.status} ${E.statusText}`);
407
+ throw R.code = G.ERROR_CODES.HTTP_ERROR, R.status = E.status, R.statusText = E.statusText, R;
408
+ }
409
+ return E.text();
410
+ }
411
+ function Le(o, E = {}) {
412
+ const { encoding: R = "utf-8" } = E;
413
+ if (typeof Blob < "u" && o instanceof Blob) return () => o.text();
414
+ if (o instanceof URL) return () => Se(o);
415
+ if (j.string(o))
416
+ return De.node && !j.url(o) ? async () => {
417
+ const { readFile: U } = await import("node:fs/promises");
418
+ return U(o, R);
419
+ } : () => Se(o);
420
+ const l = new Error("source must be a URL, a string locator or a File/Blob");
421
+ throw l.code = G.ERROR_CODES.UNSUPPORTED_SOURCE, l;
422
+ }
423
+ const G = {
424
+ ERROR_CODES: {
425
+ UNSUPPORTED_SOURCE: "UNSUPPORTED_SOURCE",
426
+ READ_FAILED: "READ_FAILED",
427
+ HTTP_ERROR: "HTTP_ERROR"
428
+ },
429
+ READ_OPTIONS_SCHEMA: {
430
+ encoding: Y(j.nonEmptyString)
431
+ },
432
+ async readAsText(o, E = {}) {
433
+ ge.all([
434
+ { value: o, validator: j.defined, message: "source must be defined" },
435
+ {
436
+ value: E,
437
+ validator: (l) => _e.schema(l, G.READ_OPTIONS_SCHEMA),
438
+ message: "options must be a valid options object"
439
+ }
440
+ ]);
441
+ const R = Le(o, E);
442
+ try {
443
+ return await R();
444
+ } catch (l) {
445
+ const U = new Error(`Failed to read source ${o}`, { cause: l });
446
+ throw U.code = G.ERROR_CODES.READ_FAILED, U;
447
+ }
448
+ }
449
+ }, Fe = (o) => o === !0 || j.nonEmptyArray(o) && o.every(j.nonEmptyString) && new Set(o).size === o.length;
450
+ Y(Fe), Y(j.plainObject), Y(j.plainObject);
451
+ const Pe = {
452
+ reviver: Y(j.function)
453
+ }, pe = {
454
+ ERROR_CODES: {
455
+ ...G.ERROR_CODES,
456
+ PARSE_FAILED: "PARSE_FAILED"
457
+ },
458
+ parse(o, E = {}) {
459
+ ge.all([
460
+ { value: o, validator: j.string, message: "text must be a string" },
461
+ {
462
+ value: E,
463
+ validator: (R) => _e.schema(R, Pe),
464
+ message: "options must be a valid options object"
465
+ }
466
+ ]);
467
+ try {
468
+ return JSON.parse(o, E.reviver);
469
+ } catch (R) {
470
+ const l = new Error("Failed to parse JSON", { cause: R });
471
+ throw l.code = pe.ERROR_CODES.PARSE_FAILED, l;
472
+ }
473
+ },
474
+ async read(o, E = {}) {
475
+ return pe.parse(await G.readAsText(o, E), E);
476
+ }
477
+ }, Me = {
478
+ domParser: Y((o) => j.function(o?.parseFromString))
479
+ };
480
+ async function je() {
481
+ if (typeof globalThis.DOMParser < "u") return new globalThis.DOMParser();
482
+ const { DOMParser: o } = await import(
483
+ /* webpackIgnore: true */
484
+ "@xmldom/xmldom"
485
+ );
486
+ return new o();
487
+ }
488
+ function Ue(o) {
489
+ return o.getElementsByTagName("parsererror").length > 0;
490
+ }
491
+ const ie = {
492
+ ERROR_CODES: {
493
+ ...G.ERROR_CODES,
494
+ PARSE_FAILED: "PARSE_FAILED",
495
+ INVALID_XML: "INVALID_XML"
496
+ },
497
+ async parse(o, E = {}) {
498
+ ge.all([
499
+ { value: o, validator: j.string, message: "text must be a string" },
500
+ {
501
+ value: E,
502
+ validator: (R) => _e.schema(R, Me),
503
+ message: "options must be a valid options object"
504
+ }
505
+ ]);
506
+ try {
507
+ const R = (E.domParser ?? await je()).parseFromString(o, "text/xml");
508
+ if (Ue(R)) {
509
+ const l = new Error("Invalid XML");
510
+ throw l.code = ie.ERROR_CODES.INVALID_XML, l;
511
+ }
512
+ return R;
513
+ } catch (R) {
514
+ const l = new Error("Failed to parse XML", { cause: R });
515
+ throw l.code = ie.ERROR_CODES.PARSE_FAILED, l;
516
+ }
517
+ },
518
+ async read(o, E = {}) {
519
+ return ie.parse(await G.readAsText(o, E), E);
520
+ }
521
+ };
522
+ async function We(o, E = {}) {
523
+ const R = await pe.read(o, E);
524
+ return { geojson: R, ...me(R) };
525
+ }
526
+ async function $e(o, E = {}) {
527
+ const R = await ie.read(o, E), l = xe(R);
528
+ return { geojson: l, ...me(l) };
529
+ }
530
+ async function Je(o, E = {}) {
531
+ const R = await ie.read(o, E), l = Ae(R);
532
+ return { geojson: l, ...me(l) };
533
+ }
534
+ export {
535
+ We as readGeoJson,
536
+ $e as readGpx,
537
+ Je as readKml
538
+ };
539
+ //# sourceMappingURL=index.mjs.map