@kalisio/common-geospatial 0.4.1 → 0.5.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.
package/dist/index.mjs CHANGED
@@ -1,116 +1,121 @@
1
- import { assert as p, is as f, has as ie, conform as P, optional as ae } from "@kalisio/common-core";
2
- const w = {
1
+ import { assert as l, is as i, has as M, conform as T, optional as $ } from "@kalisio/common-core";
2
+ import { getLogger as j } from "@logtape/logtape";
3
+ import { Heap as se } from "heap-js";
4
+ import ae from "@turf/truncate";
5
+ import oe from "@turf/boolean-clockwise";
6
+ import le from "@turf/kinks";
7
+ const d = {
3
8
  LATITUDE: "LAT",
4
9
  LONGITUDE: "LON",
5
10
  ALTITUDE: "ALT"
6
11
  };
7
- function je(t) {
8
- return p.that(t, f.string, "axis must be a string"), Object.values(w).includes(t);
12
+ function ue(e) {
13
+ return l.that(e, i.string, "axis must be a string"), Object.values(d).includes(e);
9
14
  }
10
- function ee(t) {
11
- return p.that(t, f.string, "axis must be a string"), t === w.LATITUDE;
15
+ function N(e) {
16
+ return l.that(e, i.string, "axis must be a string"), e === d.LATITUDE;
12
17
  }
13
- function Se(t) {
14
- return p.that(t, f.string, "axis must be a string"), t === w.LONGITUDE;
18
+ function Y(e) {
19
+ return l.that(e, i.string, "axis must be a string"), e === d.LONGITUDE;
15
20
  }
16
- function tr(t) {
17
- return p.that(t, f.string, "axis must be a string"), t === w.ALTITUDE;
21
+ function et(e) {
22
+ return l.that(e, i.string, "axis must be a string"), e === d.ALTITUDE;
18
23
  }
19
- const We = { NORTH: { label: "Nord", symbol: "N" }, SOUTH: { label: "Sud", symbol: "S" }, EAST: { label: "Est", symbol: "E" }, WEST: { label: "Ouest", symbol: "O" } }, Ve = {
20
- DIRECTIONS: We
21
- }, Be = { NORTH: { label: "North", symbol: "N" }, SOUTH: { label: "South", symbol: "S" }, EAST: { label: "East", symbol: "E" }, WEST: { label: "West", symbol: "W" } }, Ke = {
22
- DIRECTIONS: Be
23
- }, Ze = {
24
+ const ce = { NORTH: { label: "Nord", symbol: "N" }, SOUTH: { label: "Sud", symbol: "S" }, EAST: { label: "Est", symbol: "E" }, WEST: { label: "Ouest", symbol: "O" } }, ge = {
25
+ DIRECTIONS: ce
26
+ }, fe = { NORTH: { label: "North", symbol: "N" }, SOUTH: { label: "South", symbol: "S" }, EAST: { label: "East", symbol: "E" }, WEST: { label: "West", symbol: "W" } }, me = {
27
+ DIRECTIONS: fe
28
+ }, de = {
24
29
  DIRECTIONS: {
25
- NORTH: { label: f.string, symbol: f.string },
26
- SOUTH: { label: f.string, symbol: f.string },
27
- EAST: { label: f.string, symbol: f.string },
28
- WEST: { label: f.string, symbol: f.string }
29
- }
30
- }, k = {
31
- en: Ke,
32
- fr: Ve
30
+ NORTH: { label: i.string, symbol: i.string },
31
+ SOUTH: { label: i.string, symbol: i.string },
32
+ EAST: { label: i.string, symbol: i.string },
33
+ WEST: { label: i.string, symbol: i.string }
34
+ }
35
+ }, O = {
36
+ en: me,
37
+ fr: ge
33
38
  };
34
- let te = "en";
35
- function rr() {
36
- return Object.keys(k);
37
- }
38
- function nr(t, e) {
39
- p.all([
40
- { value: t, validator: f.string, message: "code must be a string" },
41
- { value: t, validator: (r) => !ie.key(k, r), message: "locale already registered" },
42
- { value: e, validator: f.plainObject, message: "content must be an object" },
43
- { value: e, validator: (r) => P.schema(r, Ze), message: "content does not conform to schema" }
44
- ]), k[t] = e;
45
- }
46
- function ir(t) {
47
- p.all([
48
- { value: t, validator: f.string, message: "code must be a string" },
49
- { value: t, validator: (e) => ie.key(k, e), message: "code is unknown" }
50
- ]), te = t;
51
- }
52
- function Ye() {
39
+ let A = "en";
40
+ function tt() {
41
+ return Object.keys(O);
42
+ }
43
+ function nt(e, t) {
44
+ l.all([
45
+ { value: e, validator: i.string, message: "code must be a string" },
46
+ { value: e, validator: (r) => !M.key(O, r), message: "locale already registered" },
47
+ { value: t, validator: i.plainObject, message: "content must be an object" },
48
+ { value: t, validator: (r) => T.schema(r, de), message: "content does not conform to schema" }
49
+ ]), O[e] = t;
50
+ }
51
+ function rt(e) {
52
+ l.all([
53
+ { value: e, validator: i.string, message: "code must be a string" },
54
+ { value: e, validator: (t) => M.key(O, t), message: "code is unknown" }
55
+ ]), A = e;
56
+ }
57
+ function pe() {
53
58
  return {
54
- code: te,
55
- content: k[te]
59
+ code: A,
60
+ content: O[A]
56
61
  };
57
62
  }
58
- function R() {
59
- return Ye().content.DIRECTIONS;
63
+ function b() {
64
+ return pe().content.DIRECTIONS;
60
65
  }
61
- function W(t, e) {
62
- const r = R(), n = r[t].label.toUpperCase(), i = r[t].symbol.toUpperCase();
63
- return e.toUpperCase() === n || e.toUpperCase() === i;
66
+ function R(e, t) {
67
+ const r = b(), n = r[e].label.toUpperCase(), s = r[e].symbol.toUpperCase();
68
+ return t.toUpperCase() === n || t.toUpperCase() === s;
64
69
  }
65
- function ar(t = null) {
66
- const e = R();
67
- return f.defined(t) ? (p.that(t, je, "axis must be a valid axis"), ee(t) ? [e.SOUTH, e.NORTH] : Se(t) ? [e.EAST, e.WEST] : []) : [e.SOUTH, e.NORTH, e.EAST, e.WEST];
70
+ function it(e = null) {
71
+ const t = b();
72
+ return i.defined(e) ? (l.that(e, ue, "axis must be a valid axis"), N(e) ? [t.SOUTH, t.NORTH] : Y(e) ? [t.EAST, t.WEST] : []) : [t.SOUTH, t.NORTH, t.EAST, t.WEST];
68
73
  }
69
- function sr() {
70
- return R().NORTH;
74
+ function st() {
75
+ return b().NORTH;
71
76
  }
72
- function or() {
73
- return R().SOUTH;
77
+ function at() {
78
+ return b().SOUTH;
74
79
  }
75
- function lr() {
76
- return R().EAST;
80
+ function ot() {
81
+ return b().EAST;
77
82
  }
78
- function ur() {
79
- return R().WEST;
83
+ function lt() {
84
+ return b().WEST;
80
85
  }
81
- function D(t) {
82
- return p.that(t, f.string, "dir must be a string"), Je(t) || Le(t) || Te(t) || se(t);
86
+ function E(e) {
87
+ return l.that(e, i.string, "dir must be a string"), ve(e) || B(e) || X(e) || _(e);
83
88
  }
84
- function Je(t) {
85
- return p.that(t, f.string, "dir must be a string"), W("NORTH", t);
89
+ function ve(e) {
90
+ return l.that(e, i.string, "dir must be a string"), R("NORTH", e);
86
91
  }
87
- function Le(t) {
88
- return p.that(t, f.string, "dir must be a string"), W("SOUTH", t);
92
+ function B(e) {
93
+ return l.that(e, i.string, "dir must be a string"), R("SOUTH", e);
89
94
  }
90
- function Te(t) {
91
- return p.that(t, f.string, "dir must be a string"), W("EAST", t);
95
+ function X(e) {
96
+ return l.that(e, i.string, "dir must be a string"), R("EAST", e);
92
97
  }
93
- function se(t) {
94
- return p.that(t, f.string, "dir must be a string"), W("WEST", t);
98
+ function _(e) {
99
+ return l.that(e, i.string, "dir must be a string"), R("WEST", e);
95
100
  }
96
- function Qe(t) {
97
- return p.that(t, D, "dir must be a direction"), se(t) || Te(t) ? w.LONGITUDE : w.LATITUDE;
101
+ function Ee(e) {
102
+ return l.that(e, E, "dir must be a direction"), _(e) || X(e) ? d.LONGITUDE : d.LATITUDE;
98
103
  }
99
- const Xe = {
100
- degrees: f.number,
101
- direction: ae(D)
102
- }, et = /^(-?\d{1,3}(?:\.\d+)?)°?$/, tt = /^(\d{1,3}(?:\.\d+)?)°?([NSEW])$/;
103
- function U(t) {
104
- let e = null, r = null;
105
- if (f.plainObject(t) && P.schema(t, Xe))
106
- f.defined(t.direction) ? t.degrees >= 0 && (e = t.degrees, r = t.direction) : e = t.degrees;
107
- else if (f.string(t)) {
108
- const n = t.replace(/\s+/g, ""), i = n.match(et) ?? n.match(tt);
109
- i && (e = parseFloat(i[1]), r = i[2] ?? null);
104
+ const be = {
105
+ degrees: i.number,
106
+ direction: $(E)
107
+ }, he = /^(-?\d{1,3}(?:\.\d+)?)°?$/, ye = /^(\d{1,3}(?:\.\d+)?)°?([NSEW])$/;
108
+ function I(e) {
109
+ let t = null, r = null;
110
+ if (i.plainObject(e) && T.schema(e, be))
111
+ i.defined(e.direction) ? e.degrees >= 0 && (t = e.degrees, r = e.direction) : t = e.degrees;
112
+ else if (i.string(e)) {
113
+ const n = e.replace(/\s+/g, ""), s = n.match(he) ?? n.match(ye);
114
+ s && (t = parseFloat(s[1]), r = s[2] ?? null);
110
115
  }
111
116
  return {
112
117
  get degrees() {
113
- return e;
118
+ return t;
114
119
  },
115
120
  get direction() {
116
121
  return r;
@@ -119,34 +124,34 @@ function U(t) {
119
124
  return "DD";
120
125
  },
121
126
  isValid() {
122
- return f.number(e);
127
+ return i.number(t);
123
128
  },
124
129
  toString(n) {
125
- if (p.that(n, f.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
126
- let i = `${e.toFixed(n)}°`;
127
- return r && (i += ` ${r}`), i;
130
+ if (l.that(n, i.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
131
+ let s = `${t.toFixed(n)}°`;
132
+ return r && (s += ` ${r}`), s;
128
133
  },
129
134
  toDecimal() {
130
- return this.isValid() ? U({ degrees: e, direction: r }) : null;
135
+ return this.isValid() ? I({ degrees: t, direction: r }) : null;
131
136
  }
132
137
  };
133
138
  }
134
- const rt = {
135
- degrees: f.integer,
136
- minutes: (t) => f.inRangeExclusiveMax(t, 0, 60),
137
- direction: ae(D)
138
- }, nt = /^(-?\d{1,3})°(\d{1,2}(?:\.\d+)?)'?$/, it = /^(\d{1,3})°(\d{1,2}(?:\.\d+)?)'?([NSEW])$/;
139
- function Ce(t) {
140
- let e = null, r = null, n = null;
141
- if (f.plainObject(t) && P.schema(t, rt))
142
- f.defined(t.direction) ? t.degrees >= 0 && (e = t.degrees, r = t.minutes, n = t.direction) : (e = t.degrees, r = t.minutes);
143
- else if (f.string(t)) {
144
- const i = t.replace(/\s+/g, ""), a = i.match(nt) ?? i.match(it);
145
- a && (e = parseFloat(a[1]), r = parseFloat(a[2]), n = a[3] ?? null);
139
+ const Oe = {
140
+ degrees: i.integer,
141
+ minutes: (e) => i.inRangeExclusiveMax(e, 0, 60),
142
+ direction: $(E)
143
+ }, Te = /^(-?\d{1,3})°(\d{1,2}(?:\.\d+)?)'?$/, Ie = /^(\d{1,3})°(\d{1,2}(?:\.\d+)?)'?([NSEW])$/;
144
+ function K(e) {
145
+ let t = null, r = null, n = null;
146
+ if (i.plainObject(e) && T.schema(e, Oe))
147
+ i.defined(e.direction) ? e.degrees >= 0 && (t = e.degrees, r = e.minutes, n = e.direction) : (t = e.degrees, r = e.minutes);
148
+ else if (i.string(e)) {
149
+ const s = e.replace(/\s+/g, ""), o = s.match(Te) ?? s.match(Ie);
150
+ o && (t = parseFloat(o[1]), r = parseFloat(o[2]), n = o[3] ?? null);
146
151
  }
147
152
  return {
148
153
  get degrees() {
149
- return e;
154
+ return t;
150
155
  },
151
156
  get minutes() {
152
157
  return r;
@@ -158,34 +163,34 @@ function Ce(t) {
158
163
  return "DDM";
159
164
  },
160
165
  isValid() {
161
- return f.integer(e) && f.inRangeExclusiveMax(r, 0, 60);
166
+ return i.integer(t) && i.inRangeExclusiveMax(r, 0, 60);
162
167
  },
163
- toString(i) {
164
- if (p.that(i, f.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
165
- let a = `${e}° ${r.toFixed(i)}'`;
166
- return n && (a += ` ${n}`), a;
168
+ toString(s) {
169
+ if (l.that(s, i.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
170
+ let o = `${t}° ${r.toFixed(s)}'`;
171
+ return n && (o += ` ${n}`), o;
167
172
  },
168
173
  toDecimal() {
169
- return this.isValid() ? U({ degrees: e + r / 60, direction: n }) : null;
174
+ return this.isValid() ? I({ degrees: t + r / 60, direction: n }) : null;
170
175
  }
171
176
  };
172
177
  }
173
- const at = {
174
- degrees: f.nonNegativeInteger,
175
- minutes: (t) => f.inRangeExclusiveMax(t, 0, 60),
176
- direction: D
177
- }, st = /^(\d{2})(\d{3})([NS])$/, ot = /^(\d{3})(\d{3})([EW])$/;
178
- function Ie(t) {
179
- let e = null, r = null, n = null;
180
- if (f.plainObject(t) && P.schema(t, at))
181
- e = t.degrees, r = t.minutes, n = t.direction;
182
- else if (f.string(t)) {
183
- const i = t.trim(), a = i.match(st) ?? i.match(ot);
184
- a && (e = parseFloat(a[1]), r = parseFloat(a[2]) / 10, n = a[3]);
178
+ const Le = {
179
+ degrees: i.nonNegativeInteger,
180
+ minutes: (e) => i.inRangeExclusiveMax(e, 0, 60),
181
+ direction: E
182
+ }, De = /^(\d{2})(\d{3})([NS])$/, Re = /^(\d{3})(\d{3})([EW])$/;
183
+ function z(e) {
184
+ let t = null, r = null, n = null;
185
+ if (i.plainObject(e) && T.schema(e, Le))
186
+ t = e.degrees, r = e.minutes, n = e.direction;
187
+ else if (i.string(e)) {
188
+ const s = e.trim(), o = s.match(De) ?? s.match(Re);
189
+ o && (t = parseFloat(o[1]), r = parseFloat(o[2]) / 10, n = o[3]);
185
190
  }
186
191
  return {
187
192
  get degrees() {
188
- return e;
193
+ return t;
189
194
  },
190
195
  get minutes() {
191
196
  return r;
@@ -197,35 +202,35 @@ function Ie(t) {
197
202
  return "DDM_AERO";
198
203
  },
199
204
  isValid() {
200
- return f.nonNegativeInteger(e) && f.inRangeExclusiveMax(r, 0, 60) && D(n);
205
+ return i.nonNegativeInteger(t) && i.inRangeExclusiveMax(r, 0, 60) && E(n);
201
206
  },
202
207
  toString() {
203
208
  if (!this.isValid()) return "";
204
- const i = n === "E" || n === "W", a = String(e).padStart(i ? 3 : 2, "0"), s = Math.floor(r * 10).toString().padStart(3, "0");
205
- return `${a}${s}${n}`;
209
+ const s = n === "E" || n === "W", o = String(t).padStart(s ? 3 : 2, "0"), u = Math.floor(r * 10).toString().padStart(3, "0");
210
+ return `${o}${u}${n}`;
206
211
  },
207
212
  toDecimal() {
208
- return this.isValid() ? U({ degrees: e + r / 60, direction: n }) : null;
213
+ return this.isValid() ? I({ degrees: t + r / 60, direction: n }) : null;
209
214
  }
210
215
  };
211
216
  }
212
- const lt = {
213
- degrees: f.integer,
214
- minutes: (t) => f.integer(t) && f.inRange(t, 0, 59),
215
- seconds: (t) => f.inRangeExclusiveMax(t, 0, 60),
216
- direction: ae(D)
217
- }, ut = /^(-?\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?$/, ft = /^(\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?([NSEW])$/;
218
- function Ne(t) {
219
- let e = null, r = null, n = null, i = null;
220
- if (f.plainObject(t) && P.schema(t, lt))
221
- f.defined(t.direction) ? t.degrees >= 0 && (e = t.degrees, r = t.minutes, n = t.seconds, i = t.direction) : (e = t.degrees, r = t.minutes, n = t.seconds);
222
- else if (f.string(t)) {
223
- const a = t.replace(/\s+/g, ""), s = a.match(ut) ?? a.match(ft);
224
- s && (e = parseFloat(s[1]), r = parseFloat(s[2]), n = parseFloat(s[3]), i = s[4] ?? null);
217
+ const Se = {
218
+ degrees: i.integer,
219
+ minutes: (e) => i.integer(e) && i.inRange(e, 0, 59),
220
+ seconds: (e) => i.inRangeExclusiveMax(e, 0, 60),
221
+ direction: $(E)
222
+ }, Ne = /^(-?\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?$/, Ae = /^(\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?([NSEW])$/;
223
+ function q(e) {
224
+ let t = null, r = null, n = null, s = null;
225
+ if (i.plainObject(e) && T.schema(e, Se))
226
+ i.defined(e.direction) ? e.degrees >= 0 && (t = e.degrees, r = e.minutes, n = e.seconds, s = e.direction) : (t = e.degrees, r = e.minutes, n = e.seconds);
227
+ else if (i.string(e)) {
228
+ const o = e.replace(/\s+/g, ""), u = o.match(Ne) ?? o.match(Ae);
229
+ u && (t = parseFloat(u[1]), r = parseFloat(u[2]), n = parseFloat(u[3]), s = u[4] ?? null);
225
230
  }
226
231
  return {
227
232
  get degrees() {
228
- return e;
233
+ return t;
229
234
  },
230
235
  get minutes() {
231
236
  return r;
@@ -234,136 +239,136 @@ function Ne(t) {
234
239
  return n;
235
240
  },
236
241
  get direction() {
237
- return i;
242
+ return s;
238
243
  },
239
244
  get format() {
240
245
  return "DMS";
241
246
  },
242
247
  isValid() {
243
- return f.integer(e) && f.integer(r) && f.inRange(r, 0, 59) && f.inRangeExclusiveMax(n, 0, 60);
248
+ return i.integer(t) && i.integer(r) && i.inRange(r, 0, 59) && i.inRangeExclusiveMax(n, 0, 60);
244
249
  },
245
- toString(a) {
246
- if (p.that(a, f.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
247
- let s = `${e}° ${r}' ${n.toFixed(a)}"`;
248
- return i && (s += ` ${i}`), s;
250
+ toString(o) {
251
+ if (l.that(o, i.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
252
+ let u = `${t}° ${r}' ${n.toFixed(o)}"`;
253
+ return s && (u += ` ${s}`), u;
249
254
  },
250
255
  toDecimal() {
251
- return this.isValid() ? U({ degrees: e + r / 60 + n / 3600, direction: i }) : null;
256
+ return this.isValid() ? I({ degrees: t + r / 60 + n / 3600, direction: s }) : null;
252
257
  }
253
258
  };
254
259
  }
255
- function pe(t) {
256
- const e = Math.floor(t.degrees), r = (t.degrees - e) * 60;
257
- return { degrees: e, minutes: r, direction: t.direction };
260
+ function P(e) {
261
+ const t = Math.floor(e.degrees), r = (e.degrees - t) * 60;
262
+ return { degrees: t, minutes: r, direction: e.direction };
258
263
  }
259
- function ct(t) {
260
- const e = Math.floor(t.degrees), r = (t.degrees - e) * 60, n = Math.floor(r), i = (r - n) * 60;
261
- return { degrees: e, minutes: n, seconds: i, direction: t.direction };
264
+ function Ce(e) {
265
+ const t = Math.floor(e.degrees), r = (e.degrees - t) * 60, n = Math.floor(r), s = (r - n) * 60;
266
+ return { degrees: t, minutes: n, seconds: s, direction: e.direction };
262
267
  }
263
- const ge = {
264
- DD: (t) => (p.that(t, (e) => e.isValid(), "dd must be a valid coordinate"), t),
265
- DDM: (t) => {
266
- p.that(t, (i) => i.isValid(), "dd must be a valid coordinate");
267
- const { degrees: e, minutes: r, direction: n } = pe(t);
268
- return Ce(n ? { degrees: e, minutes: r, direction: n } : { degrees: e, minutes: r });
268
+ const H = {
269
+ DD: (e) => (l.that(e, (t) => t.isValid(), "dd must be a valid coordinate"), e),
270
+ DDM: (e) => {
271
+ l.that(e, (s) => s.isValid(), "dd must be a valid coordinate");
272
+ const { degrees: t, minutes: r, direction: n } = P(e);
273
+ return K(n ? { degrees: t, minutes: r, direction: n } : { degrees: t, minutes: r });
269
274
  },
270
- DMS: (t) => {
271
- p.that(t, (a) => a.isValid(), "dd must be a valid coordinate");
272
- const { degrees: e, minutes: r, seconds: n, direction: i } = ct(t);
273
- return Ne(i ? { degrees: e, minutes: r, seconds: n, direction: i } : { degrees: e, minutes: r, seconds: n });
275
+ DMS: (e) => {
276
+ l.that(e, (o) => o.isValid(), "dd must be a valid coordinate");
277
+ const { degrees: t, minutes: r, seconds: n, direction: s } = Ce(e);
278
+ return q(s ? { degrees: t, minutes: r, seconds: n, direction: s } : { degrees: t, minutes: r, seconds: n });
274
279
  },
275
- DDM_AERO: (t) => {
276
- p.that(t, (i) => i.isValid(), "dd must be a valid coordinate");
277
- const { degrees: e, minutes: r, direction: n } = pe(t);
278
- return Ie({ degrees: e, minutes: r, direction: n });
280
+ DDM_AERO: (e) => {
281
+ l.that(e, (s) => s.isValid(), "dd must be a valid coordinate");
282
+ const { degrees: t, minutes: r, direction: n } = P(e);
283
+ return z({ degrees: t, minutes: r, direction: n });
279
284
  }
280
- }, re = {
285
+ }, C = {
281
286
  DD: "DD",
282
287
  DDM: "DDM",
283
288
  DDM_AERO: "DDM_AERO",
284
289
  DMS: "DMS"
285
- }, ht = {
286
- DD: U,
287
- DDM: Ce,
288
- DDM_AERO: Ie,
289
- DMS: Ne
290
- }, oe = Array.from({ length: 9 }, (t, e) => 10 ** e);
291
- function ye(t, e) {
292
- if (p.that(t, f.number, "coord must be a number"), f.defined(e))
293
- return p.that(e, D, "dir must be a direction"), Qe(e);
294
- if (Math.abs(t) > 90) return w.LONGITUDE;
295
- }
296
- function de(t) {
297
- p.that(t, f.number, "coord must be a number");
298
- const e = t.toExponential(), [r, n] = e.split("e").map(Number), i = (r.toString().split(".")[1] || "").length;
299
- return Math.max(0, i - n);
300
- }
301
- function fr(t, e = 7) {
302
- p.all([
303
- { value: t, validator: f.number, message: "coord must be a number" },
304
- { value: e, validator: (n) => f.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
290
+ }, we = {
291
+ DD: I,
292
+ DDM: K,
293
+ DDM_AERO: z,
294
+ DMS: q
295
+ }, x = Array.from({ length: 9 }, (e, t) => 10 ** t);
296
+ function V(e, t) {
297
+ if (l.that(e, i.number, "coord must be a number"), i.defined(t))
298
+ return l.that(t, E, "dir must be a direction"), Ee(t);
299
+ if (Math.abs(e) > 90) return d.LONGITUDE;
300
+ }
301
+ function W(e) {
302
+ l.that(e, i.number, "coord must be a number");
303
+ const t = e.toExponential(), [r, n] = t.split("e").map(Number), s = (r.toString().split(".")[1] || "").length;
304
+ return Math.max(0, s - n);
305
+ }
306
+ function ut(e, t = 7) {
307
+ l.all([
308
+ { value: e, validator: i.number, message: "coord must be a number" },
309
+ { value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
305
310
  ]);
306
- const r = oe[e];
307
- return Math.round(t * r) / r;
308
- }
309
- function cr(t, e) {
310
- if (p.all([
311
- { value: t, validator: f.number, message: "coord must be a number" },
312
- { value: e, validator: (n) => Se(n) || ee(n), message: "axis must be either a longitude or latitude" }
313
- ]), ee(e))
314
- return Math.max(-90, Math.min(90, t));
315
- let r = ((t + 180) % 360 + 360) % 360 - 180;
311
+ const r = x[t];
312
+ return Math.round(e * r) / r;
313
+ }
314
+ function ct(e, t) {
315
+ if (l.all([
316
+ { value: e, validator: i.number, message: "coord must be a number" },
317
+ { value: t, validator: (n) => Y(n) || N(n), message: "axis must be either a longitude or latitude" }
318
+ ]), N(t))
319
+ return Math.max(-90, Math.min(90, e));
320
+ let r = ((e + 180) % 360 + 360) % 360 - 180;
316
321
  return r === -180 && (r = 180), Object.is(r, -0) && (r = 0), r;
317
322
  }
318
- function hr(t, e) {
319
- p.all([
320
- { value: t, validator: (n) => f.defined(n) && n.isValid(), message: "from must be a valid coordinate" },
321
- { value: e, validator: (n) => ie.key(ge, n), message: `unknown format: ${e}` }
323
+ function gt(e, t) {
324
+ l.all([
325
+ { value: e, validator: (n) => i.defined(n) && n.isValid(), message: "from must be a valid coordinate" },
326
+ { value: t, validator: (n) => M.key(H, n), message: `unknown format: ${t}` }
322
327
  ]);
323
- const r = t.format === re.DD ? t : t.toDecimal();
324
- return r.isValid() ? e === re.DD ? r : ge[e](r) : null;
328
+ const r = e.format === C.DD ? e : e.toDecimal();
329
+ return r.isValid() ? t === C.DD ? r : H[t](r) : null;
325
330
  }
326
- function pt(t) {
327
- p.that(t, f.nonEmptyString, "pattern must be a non empty string");
328
- for (const e of Object.keys(re)) {
329
- const r = ht[e](t);
331
+ function Me(e) {
332
+ l.that(e, i.nonEmptyString, "pattern must be a non empty string");
333
+ for (const t of Object.keys(C)) {
334
+ const r = we[t](e);
330
335
  if (r.isValid()) return r;
331
336
  }
332
337
  return null;
333
338
  }
334
- function pr(t) {
335
- p.that(t, (o) => f.nonEmptyString(o), "pattern must be a non-empty string");
336
- const e = t.split(/[,;|]/);
337
- if (e.length !== 2) return null;
338
- const [r, n] = e.map(pt);
339
+ function ft(e) {
340
+ l.that(e, (a) => i.nonEmptyString(a), "pattern must be a non-empty string");
341
+ const t = e.split(/[,;|]/);
342
+ if (t.length !== 2) return null;
343
+ const [r, n] = t.map(Me);
339
344
  if (!r || !n) return null;
340
- const i = r.toDecimal(), a = n.toDecimal(), s = ye(i.degrees, i.direction), l = ye(a.degrees, a.direction), u = (o) => {
341
- const { degrees: c, direction: h } = o;
342
- return h && (se(h) || Le(h)) ? -c : c;
345
+ const s = r.toDecimal(), o = n.toDecimal(), u = V(s.degrees, s.direction), g = V(o.degrees, o.direction), c = (a) => {
346
+ const { degrees: p, direction: m } = a;
347
+ return m && (_(m) || B(m)) ? -p : p;
343
348
  };
344
- if (s === w.LONGITUDE && l === w.LATITUDE) return [u(i), u(a)];
345
- if (l === w.LONGITUDE && s === w.LATITUDE) return [u(a), u(i)];
346
- if (s === w.LONGITUDE && !l) return [u(i), a];
347
- if (s === w.LATITUDE && !l) return [u(a), u(i)];
348
- if (l === w.LONGITUDE && !s) return [u(a), u(i)];
349
- if (l === w.LATITUDE && !s) return [u(i), u(a)];
350
- if (!s && !l)
349
+ if (u === d.LONGITUDE && g === d.LATITUDE) return [c(s), c(o)];
350
+ if (g === d.LONGITUDE && u === d.LATITUDE) return [c(o), c(s)];
351
+ if (u === d.LONGITUDE && !g) return [c(s), o];
352
+ if (u === d.LATITUDE && !g) return [c(o), c(s)];
353
+ if (g === d.LONGITUDE && !u) return [c(o), c(s)];
354
+ if (g === d.LATITUDE && !u) return [c(s), c(o)];
355
+ if (!u && !g)
351
356
  return [
352
- [u(i), u(a)],
353
- [u(a), u(i)]
357
+ [c(s), c(o)],
358
+ [c(o), c(s)]
354
359
  ];
355
360
  }
356
- function gt(t) {
357
- return !f.arrayOfLength(t, 4) && !f.arrayOfLength(t, 6) ? !1 : t.every(f.number);
361
+ function $e(e) {
362
+ return !i.arrayOfLength(e, 4) && !i.arrayOfLength(e, 6) ? !1 : e.every(i.number);
358
363
  }
359
- const z = {
364
+ const L = {
360
365
  NAME: "name",
361
366
  LINK: "link"
362
367
  };
363
- function gr(t) {
364
- return f.plainObject(t) ? t.type === z.NAME ? f.nonEmptyString(t.properties?.name) : t.type === z.LINK ? f.nonEmptyString(t.properties?.href) : !1 : !1;
368
+ function mt(e) {
369
+ return i.plainObject(e) ? e.type === L.NAME ? i.nonEmptyString(e.properties?.name) : e.type === L.LINK ? i.nonEmptyString(e.properties?.href) : !1 : !1;
365
370
  }
366
- const v = {
371
+ const f = {
367
372
  POINT: "Point",
368
373
  MULTI_POINT: "MultiPoint",
369
374
  LINESTRING: "LineString",
@@ -372,1910 +377,208 @@ const v = {
372
377
  MULTI_POLYGON: "MultiPolygon",
373
378
  GEOMETRY_COLLECTION: "GeometryCollection"
374
379
  };
375
- function le(t) {
376
- return !f.plainObject(t) || !f.oneOf(t.type, Object.values(v)) ? !1 : t.type === v.GEOMETRY_COLLECTION ? f.array(t.geometries) : f.array(t.coordinates);
380
+ function G(e) {
381
+ return !i.plainObject(e) || !i.oneOf(e.type, Object.values(f)) ? !1 : e.type === f.GEOMETRY_COLLECTION ? i.array(e.geometries) : i.array(e.coordinates);
377
382
  }
378
- const I = {
383
+ const v = {
379
384
  FEATURE: "Feature",
380
385
  FEATURE_COLLECTION: "FeatureCollection"
381
386
  };
382
- function yt(t) {
383
- return f.plainObject(t) ? I.FEATURE === t.type : !1;
384
- }
385
- function dt(t) {
386
- return !f.plainObject(t) || t.type !== I.FEATURE_COLLECTION ? !1 : f.array(t.features);
387
- }
388
- function De(t) {
389
- return f.plainObject(t) ? le(t) || yt(t) ? !0 : dt(t) : !1;
390
- }
391
- function mt(t) {
392
- return f.arrayOfLengthBetween(t, 2, 3) ? t.every(f.number) : !1;
387
+ function _e(e) {
388
+ return i.plainObject(e) ? v.FEATURE === e.type : !1;
393
389
  }
394
- const vt = {}, H = bt(globalThis, vt);
395
- function bt(t, e) {
396
- return new Proxy(t, {
397
- get(r, n, i) {
398
- return n in e ? e[n] : t[n];
399
- },
400
- set(r, n, i) {
401
- return n in e && delete e[n], t[n] = i, !0;
402
- },
403
- deleteProperty(r, n) {
404
- let i = !1;
405
- return n in e && (delete e[n], i = !0), n in t && (delete t[n], i = !0), i;
406
- },
407
- ownKeys(r) {
408
- const n = Reflect.ownKeys(t), i = Reflect.ownKeys(e), a = new Set(i);
409
- return [...n.filter((s) => !a.has(s)), ...i];
410
- },
411
- defineProperty(r, n, i) {
412
- return n in e && delete e[n], Reflect.defineProperty(t, n, i), !0;
413
- },
414
- getOwnPropertyDescriptor(r, n) {
415
- return n in e ? Reflect.getOwnPropertyDescriptor(e, n) : Reflect.getOwnPropertyDescriptor(t, n);
416
- },
417
- has(r, n) {
418
- return n in e || n in t;
419
- }
420
- });
390
+ function xe(e) {
391
+ return !i.plainObject(e) || e.type !== v.FEATURE_COLLECTION ? !1 : i.array(e.features);
421
392
  }
422
- function xe(t = []) {
423
- return C.getLogger(t);
393
+ function Q(e) {
394
+ return i.plainObject(e) ? G(e) || _e(e) ? !0 : xe(e) : !1;
424
395
  }
425
- const B = /* @__PURE__ */ Symbol.for("logtape.rootLogger");
426
- class C {
427
- static getLogger(e = []) {
428
- let r = B in H ? H[B] ?? null : null;
429
- return r == null && (r = new C(null, []), H[B] = r), typeof e == "string" ? r.getChild(e) : e.length === 0 ? r : r.getChild(e);
430
- }
431
- constructor(e, r) {
432
- Object.defineProperty(this, "parent", {
433
- enumerable: !0,
434
- configurable: !0,
435
- writable: !0,
436
- value: void 0
437
- }), Object.defineProperty(this, "children", {
438
- enumerable: !0,
439
- configurable: !0,
440
- writable: !0,
441
- value: void 0
442
- }), Object.defineProperty(this, "category", {
443
- enumerable: !0,
444
- configurable: !0,
445
- writable: !0,
446
- value: void 0
447
- }), Object.defineProperty(this, "sinks", {
448
- enumerable: !0,
449
- configurable: !0,
450
- writable: !0,
451
- value: void 0
452
- }), Object.defineProperty(this, "parentSinks", {
453
- enumerable: !0,
454
- configurable: !0,
455
- writable: !0,
456
- value: "inherit"
457
- }), Object.defineProperty(this, "filters", {
458
- enumerable: !0,
459
- configurable: !0,
460
- writable: !0,
461
- value: void 0
462
- }), Object.defineProperty(this, "contextLocalStorage", {
463
- enumerable: !0,
464
- configurable: !0,
465
- writable: !0,
466
- value: void 0
467
- }), this.parent = e, this.children = {}, this.category = r, this.sinks = [], this.filters = [];
468
- }
469
- getChild(e) {
470
- const r = typeof e == "string" ? e : e[0], n = this.children[r];
471
- let i = n instanceof C ? n : n?.deref();
472
- return i == null && (i = new C(this, [...this.category, r]), this.children[r] = "WeakRef" in H ? new WeakRef(i) : i), typeof e == "string" || e.length === 1 ? i : i.getChild(e.slice(1));
473
- }
474
- /**
475
- * Reset the logger. This removes all sinks and filters from the logger.
476
- */
477
- reset() {
478
- for (; this.sinks.length > 0; )
479
- this.sinks.shift();
480
- for (this.parentSinks = "inherit"; this.filters.length > 0; )
481
- this.filters.shift();
482
- }
483
- /**
484
- * Reset the logger and all its descendants. This removes all sinks and
485
- * filters from the logger and all its descendants.
486
- */
487
- resetDescendants() {
488
- for (const e of Object.values(this.children)) {
489
- const r = e instanceof C ? e : e.deref();
490
- r?.resetDescendants();
491
- }
492
- this.reset();
493
- }
494
- with(e) {
495
- return new ue(this, { ...e });
496
- }
497
- filter(e) {
498
- for (const r of this.filters)
499
- if (!r(e))
500
- return !1;
501
- return this.filters.length < 1 ? this.parent?.filter(e) ?? !0 : !0;
502
- }
503
- *getSinks() {
504
- if (this.parent != null && this.parentSinks === "inherit")
505
- for (const e of this.parent.getSinks())
506
- yield e;
507
- for (const e of this.sinks)
508
- yield e;
509
- }
510
- emit(e, r) {
511
- if (this.filter(e)) {
512
- for (const n of this.getSinks())
513
- if (!r?.has(n))
514
- try {
515
- n(e);
516
- } catch (i) {
517
- const a = new Set(r);
518
- a.add(n), At.log("fatal", "Failed to emit a log record to sink {sink}: {error}", { sink: n, error: i, record: e }, a);
519
- }
520
- }
521
- }
522
- log(e, r, n, i) {
523
- const a = C.getLogger().contextLocalStorage?.getStore() ?? {};
524
- let s;
525
- const l = typeof n == "function" ? {
526
- category: this.category,
527
- level: e,
528
- timestamp: Date.now(),
529
- get message() {
530
- return me(r, this.properties);
531
- },
532
- rawMessage: r,
533
- get properties() {
534
- return s == null && (s = {
535
- ...a,
536
- ...n()
537
- }), s;
538
- }
539
- } : {
540
- category: this.category,
541
- level: e,
542
- timestamp: Date.now(),
543
- message: me(r, {
544
- ...a,
545
- ...n
546
- }),
547
- rawMessage: r,
548
- properties: { ...a, ...n }
549
- };
550
- this.emit(l, i);
551
- }
552
- logLazily(e, r, n = {}) {
553
- const i = C.getLogger().contextLocalStorage?.getStore() ?? {};
554
- let a, s;
555
- function l() {
556
- if ((s == null || a == null) && (s = r((u, ...o) => (a = u, ve(u, o))), a == null))
557
- throw new TypeError("No log record was made.");
558
- return [s, a];
559
- }
560
- this.emit({
561
- category: this.category,
562
- level: e,
563
- get message() {
564
- return l()[0];
565
- },
566
- get rawMessage() {
567
- return l()[1];
568
- },
569
- timestamp: Date.now(),
570
- properties: { ...i, ...n }
571
- });
572
- }
573
- logTemplate(e, r, n, i = {}) {
574
- const a = C.getLogger().contextLocalStorage?.getStore() ?? {};
575
- this.emit({
576
- category: this.category,
577
- level: e,
578
- message: ve(r, n),
579
- rawMessage: r,
580
- timestamp: Date.now(),
581
- properties: { ...a, ...i }
582
- });
583
- }
584
- debug(e, ...r) {
585
- typeof e == "string" ? this.log("debug", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("debug", e) : this.logTemplate("debug", e, r);
586
- }
587
- info(e, ...r) {
588
- typeof e == "string" ? this.log("info", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("info", e) : this.logTemplate("info", e, r);
589
- }
590
- warn(e, ...r) {
591
- typeof e == "string" ? this.log("warning", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("warning", e) : this.logTemplate("warning", e, r);
592
- }
593
- error(e, ...r) {
594
- typeof e == "string" ? this.log("error", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("error", e) : this.logTemplate("error", e, r);
595
- }
596
- fatal(e, ...r) {
597
- typeof e == "string" ? this.log("fatal", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("fatal", e) : this.logTemplate("fatal", e, r);
598
- }
396
+ function Ge(e) {
397
+ return i.arrayOfLengthBetween(e, 2, 3) ? e.every(i.number) : !1;
599
398
  }
600
- class ue {
601
- constructor(e, r) {
602
- Object.defineProperty(this, "logger", {
603
- enumerable: !0,
604
- configurable: !0,
605
- writable: !0,
606
- value: void 0
607
- }), Object.defineProperty(this, "properties", {
608
- enumerable: !0,
609
- configurable: !0,
610
- writable: !0,
611
- value: void 0
612
- }), this.logger = e, this.properties = r;
613
- }
614
- get category() {
615
- return this.logger.category;
616
- }
617
- get parent() {
618
- return this.logger.parent;
619
- }
620
- getChild(e) {
621
- return this.logger.getChild(e).with(this.properties);
622
- }
623
- with(e) {
624
- return new ue(this.logger, { ...this.properties, ...e });
625
- }
626
- log(e, r, n, i) {
627
- this.logger.log(e, r, typeof n == "function" ? () => ({
628
- ...this.properties,
629
- ...n()
630
- }) : { ...this.properties, ...n }, i);
631
- }
632
- logLazily(e, r) {
633
- this.logger.logLazily(e, r, this.properties);
634
- }
635
- logTemplate(e, r, n) {
636
- this.logger.logTemplate(e, r, n, this.properties);
637
- }
638
- debug(e, ...r) {
639
- typeof e == "string" ? this.log("debug", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("debug", e) : this.logTemplate("debug", e, r);
640
- }
641
- info(e, ...r) {
642
- typeof e == "string" ? this.log("info", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("info", e) : this.logTemplate("info", e, r);
643
- }
644
- warn(e, ...r) {
645
- typeof e == "string" ? this.log("warning", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("warning", e) : this.logTemplate("warning", e, r);
646
- }
647
- error(e, ...r) {
648
- typeof e == "string" ? this.log("error", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("error", e) : this.logTemplate("error", e, r);
649
- }
650
- fatal(e, ...r) {
651
- typeof e == "string" ? this.log("fatal", e, r[0] ?? {}) : typeof e == "function" ? this.logLazily("fatal", e) : this.logTemplate("fatal", e, r);
652
- }
653
- }
654
- const At = C.getLogger(["logtape", "meta"]);
655
- function me(t, e) {
656
- const r = [];
657
- let n = "";
658
- for (let i = 0; i < t.length; i++) {
659
- const a = t.charAt(i), s = t.charAt(i + 1);
660
- if (a === "{" && s === "{")
661
- n = n + a, i++;
662
- else if (a === "}" && s === "}")
663
- n = n + a, i++;
664
- else if (a === "{")
665
- r.push(n), n = "";
666
- else if (a === "}") {
667
- let l;
668
- n.match(/^\s|\s$/) ? l = n in e ? e[n] : e[n.trim()] : l = e[n], r.push(l), n = "";
669
- } else
670
- n = n + a;
671
- }
672
- return r.push(n), r;
673
- }
674
- function ve(t, e) {
675
- const r = [];
676
- for (let n = 0; n < t.length; n++)
677
- r.push(t[n]), n < e.length && r.push(e[n]);
678
- return r;
679
- }
680
- function _e(t) {
681
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
682
- }
683
- function Re(t) {
684
- throw new Error('Could not dynamically require "' + t + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
685
- }
686
- var K, be;
687
- function wt() {
688
- if (be) return K;
689
- be = 1;
690
- let t = null;
691
- if (typeof window > "u" && ("process" in globalThis && "versions" in globalThis.process && "node" in globalThis.process.versions && typeof globalThis.caches > "u" && typeof globalThis.addEventListener != "function" || "Bun" in globalThis))
692
- try {
693
- t = [Re][0](`${["node", "util"].join(":")}`);
694
- } catch {
695
- t = null;
696
- }
697
- return K = t, K;
698
- }
699
- var Ot = wt();
700
- const q = /* @__PURE__ */ _e(Ot), Ae = {
701
- debug: "DBG",
702
- info: "INF",
703
- warning: "WRN",
704
- error: "ERR",
705
- fatal: "FTL"
706
- }, Me = (
707
- // @ts-ignore: Deno global
708
- // dnt-shim-ignore
709
- "Deno" in globalThis && "inspect" in globalThis.Deno && // @ts-ignore: Deno global
710
- // dnt-shim-ignore
711
- typeof globalThis.Deno.inspect == "function" ? (t, e) => (
712
- // @ts-ignore: Deno global
713
- // dnt-shim-ignore
714
- globalThis.Deno.inspect(t, {
715
- strAbbreviateSize: 1 / 0,
716
- iterableLimit: 1 / 0,
717
- ...e
718
- })
719
- ) : q != null && "inspect" in q && typeof q.inspect == "function" ? (t, e) => (
720
- // @ts-ignore: Node.js global
721
- // dnt-shim-ignore
722
- q.inspect(t, {
723
- maxArrayLength: 1 / 0,
724
- maxStringLength: 1 / 0,
725
- ...e
726
- })
727
- ) : (t) => JSON.stringify(t)
728
- );
729
- function $e(t = {}) {
730
- const e = t.timestamp == null || t.timestamp === "date-time-timezone" ? (s) => new Date(s).toISOString().replace("T", " ").replace("Z", " +00:00") : t.timestamp === "date-time-tz" ? (s) => new Date(s).toISOString().replace("T", " ").replace("Z", " +00") : t.timestamp === "date-time" ? (s) => new Date(s).toISOString().replace("T", " ").replace("Z", "") : t.timestamp === "time-timezone" ? (s) => new Date(s).toISOString().replace(/.*T/, "").replace("Z", " +00:00") : t.timestamp === "time-tz" ? (s) => new Date(s).toISOString().replace(/.*T/, "").replace("Z", " +00") : t.timestamp === "time" ? (s) => new Date(s).toISOString().replace(/.*T/, "").replace("Z", "") : t.timestamp === "date" ? (s) => new Date(s).toISOString().replace(/T.*/, "") : t.timestamp === "rfc3339" ? (s) => new Date(s).toISOString() : t.timestamp, r = t.category ?? "·", n = t.value ?? Me, i = t.level == null || t.level === "ABBR" ? (s) => Ae[s] : t.level === "abbr" ? (s) => Ae[s].toLowerCase() : t.level === "FULL" ? (s) => s.toUpperCase() : t.level === "full" ? (s) => s : t.level === "L" ? (s) => s.charAt(0).toUpperCase() : t.level === "l" ? (s) => s.charAt(0) : t.level, a = t.format ?? (({ timestamp: s, level: l, category: u, message: o }) => `${s} [${l}] ${u}: ${o}`);
731
- return (s) => {
732
- let l = "";
733
- for (let g = 0; g < s.message.length; g++)
734
- g % 2 === 0 ? l += s.message[g] : l += n(s.message[g]);
735
- const u = e(s.timestamp), o = i(s.level), c = typeof r == "function" ? r(s.category) : s.category.join(r);
736
- return `${a({
737
- timestamp: u,
738
- level: o,
739
- category: c,
740
- message: l,
741
- record: s
742
- })}
743
- `;
744
- };
745
- }
746
- $e();
747
- const Z = "\x1B[0m", Y = {
748
- black: "\x1B[30m",
749
- red: "\x1B[31m",
750
- green: "\x1B[32m",
751
- yellow: "\x1B[33m",
752
- blue: "\x1B[34m",
753
- magenta: "\x1B[35m",
754
- cyan: "\x1B[36m",
755
- white: "\x1B[37m"
756
- }, J = {
757
- bold: "\x1B[1m",
758
- dim: "\x1B[2m",
759
- italic: "\x1B[3m",
760
- underline: "\x1B[4m",
761
- strikethrough: "\x1B[9m"
762
- }, Et = {
763
- debug: "blue",
764
- info: "green",
765
- warning: "yellow",
766
- error: "red",
767
- fatal: "magenta"
768
- };
769
- function St(t = {}) {
770
- const e = t.format, r = typeof t.timestampStyle > "u" ? "dim" : t.timestampStyle, n = t.timestampColor ?? null, i = `${r == null ? "" : J[r]}${n == null ? "" : Y[n]}`, a = r == null && n == null ? "" : Z, s = typeof t.levelStyle > "u" ? "bold" : t.levelStyle, l = t.levelColors ?? Et, u = typeof t.categoryStyle > "u" ? "dim" : t.categoryStyle, o = t.categoryColor ?? null, c = `${u == null ? "" : J[u]}${o == null ? "" : Y[o]}`, h = u == null && o == null ? "" : Z;
771
- return $e({
772
- timestamp: "date-time-tz",
773
- value(g) {
774
- return Me(g, { colors: !0 });
775
- },
776
- ...t,
777
- format({ timestamp: g, level: m, category: S, message: G, record: F }) {
778
- const L = l[F.level];
779
- return g = `${i}${g}${a}`, m = `${s == null ? "" : J[s]}${L == null ? "" : Y[L]}${m}${s == null && L == null ? "" : Z}`, e == null ? `${g} ${m} ${c}${S}:${h} ${G}` : e({
780
- timestamp: g,
781
- level: m,
782
- category: `${c}${S}${h}`,
783
- message: G,
784
- record: F
785
- });
786
- }
787
- });
788
- }
789
- St();
790
- var Q, we;
791
- function Lt() {
792
- if (we) return Q;
793
- we = 1;
794
- let t = null;
795
- if (typeof window > "u" && ("process" in globalThis && "versions" in globalThis.process && "node" in globalThis.process.versions && typeof globalThis.caches > "u" && typeof globalThis.addEventListener != "function" || "Bun" in globalThis))
796
- try {
797
- t = [Re][0](`${["node", "fs"].join(":")}`);
798
- } catch {
799
- t = null;
800
- }
801
- return Q = t, Q;
802
- }
803
- var Tt = Lt();
804
- const Ct = /* @__PURE__ */ _e(Tt), It = {}, _ = Ct;
805
- _ == null || (_.writeSync, _.fsyncSync, _.closeSync, _.statSync, _.renameSync);
806
- var d = function(t, e, r, n) {
807
- function i(a) {
808
- return a instanceof r ? a : new r(function(s) {
809
- s(a);
810
- });
811
- }
812
- return new (r || (r = Promise))(function(a, s) {
813
- function l(c) {
814
- try {
815
- o(n.next(c));
816
- } catch (h) {
817
- s(h);
818
- }
819
- }
820
- function u(c) {
821
- try {
822
- o(n.throw(c));
823
- } catch (h) {
824
- s(h);
825
- }
826
- }
827
- function o(c) {
828
- c.done ? a(c.value) : i(c.value).then(l, u);
829
- }
830
- o((n = n.apply(t, e || [])).next());
831
- });
832
- }, y = function(t, e) {
833
- var r = { label: 0, sent: function() {
834
- if (a[0] & 1) throw a[1];
835
- return a[1];
836
- }, trys: [], ops: [] }, n, i, a, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
837
- return s.next = l(0), s.throw = l(1), s.return = l(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() {
838
- return this;
839
- }), s;
840
- function l(o) {
841
- return function(c) {
842
- return u([o, c]);
843
- };
844
- }
845
- function u(o) {
846
- if (n) throw new TypeError("Generator is already executing.");
847
- for (; s && (s = 0, o[0] && (r = 0)), r; ) try {
848
- if (n = 1, i && (a = o[0] & 2 ? i.return : o[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, o[1])).done) return a;
849
- switch (i = 0, a && (o = [o[0] & 2, a.value]), o[0]) {
850
- case 0:
851
- case 1:
852
- a = o;
853
- break;
854
- case 4:
855
- return r.label++, { value: o[1], done: !1 };
856
- case 5:
857
- r.label++, i = o[1], o = [0];
858
- continue;
859
- case 7:
860
- o = r.ops.pop(), r.trys.pop();
861
- continue;
862
- default:
863
- if (a = r.trys, !(a = a.length > 0 && a[a.length - 1]) && (o[0] === 6 || o[0] === 2)) {
864
- r = 0;
865
- continue;
866
- }
867
- if (o[0] === 3 && (!a || o[1] > a[0] && o[1] < a[3])) {
868
- r.label = o[1];
869
- break;
870
- }
871
- if (o[0] === 6 && r.label < a[1]) {
872
- r.label = a[1], a = o;
873
- break;
874
- }
875
- if (a && r.label < a[2]) {
876
- r.label = a[2], r.ops.push(o);
877
- break;
878
- }
879
- a[2] && r.ops.pop(), r.trys.pop();
880
- continue;
881
- }
882
- o = e.call(t, r);
883
- } catch (c) {
884
- o = [6, c], i = 0;
885
- } finally {
886
- n = a = 0;
887
- }
888
- if (o[0] & 5) throw o[1];
889
- return { value: o[0] ? o[1] : void 0, done: !0 };
890
- }
891
- }, O = function(t, e) {
892
- var r = typeof Symbol == "function" && t[Symbol.iterator];
893
- if (!r) return t;
894
- var n = r.call(t), i, a = [], s;
895
- try {
896
- for (; (e === void 0 || e-- > 0) && !(i = n.next()).done; ) a.push(i.value);
897
- } catch (l) {
898
- s = { error: l };
899
- } finally {
900
- try {
901
- i && !i.done && (r = n.return) && r.call(n);
902
- } finally {
903
- if (s) throw s.error;
904
- }
905
- }
906
- return a;
907
- }, E = function(t, e, r) {
908
- if (r || arguments.length === 2) for (var n = 0, i = e.length, a; n < i; n++)
909
- (a || !(n in e)) && (a || (a = Array.prototype.slice.call(e, 0, n)), a[n] = e[n]);
910
- return t.concat(a || Array.prototype.slice.call(e));
911
- }, Oe = function(t) {
912
- var e = typeof Symbol == "function" && Symbol.iterator, r = e && t[e], n = 0;
913
- if (r) return r.call(t);
914
- if (t && typeof t.length == "number") return {
915
- next: function() {
916
- return t && n >= t.length && (t = void 0), { value: t && t[n++], done: !t };
917
- }
918
- };
919
- throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
920
- };
921
- (function() {
922
- function t(e) {
923
- e === void 0 && (e = t.minComparator);
924
- var r = this;
925
- this.compare = e, this.heapArray = [], this._limit = 0, this.offer = this.add, this.element = this.peek, this.poll = this.pop, this._invertedCompare = function(n, i) {
926
- return r.compare(n, i).then(function(a) {
927
- return -1 * a;
928
- });
929
- };
930
- }
931
- return t.getChildrenIndexOf = function(e) {
932
- return [e * 2 + 1, e * 2 + 2];
933
- }, t.getParentIndexOf = function(e) {
934
- if (e <= 0)
935
- return -1;
936
- var r = e % 2 ? 1 : 2;
937
- return Math.floor((e - r) / 2);
938
- }, t.getSiblingIndexOf = function(e) {
939
- if (e <= 0)
940
- return -1;
941
- var r = e % 2 ? 1 : -1;
942
- return e + r;
943
- }, t.minComparator = function(e, r) {
944
- return d(this, void 0, void 0, function() {
945
- return y(this, function(n) {
946
- return e > r ? [2, 1] : e < r ? [2, -1] : [2, 0];
947
- });
948
- });
949
- }, t.maxComparator = function(e, r) {
950
- return d(this, void 0, void 0, function() {
951
- return y(this, function(n) {
952
- return r > e ? [2, 1] : r < e ? [2, -1] : [2, 0];
953
- });
954
- });
955
- }, t.minComparatorNumber = function(e, r) {
956
- return d(this, void 0, void 0, function() {
957
- return y(this, function(n) {
958
- return [2, e - r];
959
- });
960
- });
961
- }, t.maxComparatorNumber = function(e, r) {
962
- return d(this, void 0, void 0, function() {
963
- return y(this, function(n) {
964
- return [2, r - e];
965
- });
966
- });
967
- }, t.defaultIsEqual = function(e, r) {
968
- return d(this, void 0, void 0, function() {
969
- return y(this, function(n) {
970
- return [2, e === r];
971
- });
972
- });
973
- }, t.print = function(e) {
974
- function r(c) {
975
- var h = t.getParentIndexOf(c);
976
- return Math.floor(Math.log2(h + 1));
977
- }
978
- function n(c, h) {
979
- for (var g = ""; h > 0; --h)
980
- g += c;
981
- return g;
982
- }
983
- for (var i = 0, a = [], s = r(e.length - 1) + 2, l = 0; i < e.length; ) {
984
- var u = r(i) + 1;
985
- i === 0 && (u = 0);
986
- var o = String(e.get(i));
987
- o.length > l && (l = o.length), a[u] = a[u] || [], a[u].push(o), i += 1;
988
- }
989
- return a.map(function(c, h) {
990
- var g = Math.pow(2, s - h) - 1;
991
- return n(" ", Math.floor(g / 2) * l) + c.map(function(m) {
992
- var S = (l - m.length) / 2;
993
- return n(" ", Math.ceil(S)) + m + n(" ", Math.floor(S));
994
- }).join(n(" ", g * l));
995
- }).join(`
996
- `);
997
- }, t.heapify = function(e, r) {
998
- return d(this, void 0, void 0, function() {
999
- var n;
1000
- return y(this, function(i) {
1001
- switch (i.label) {
1002
- case 0:
1003
- return n = new t(r), n.heapArray = e, [4, n.init()];
1004
- case 1:
1005
- return i.sent(), [2, n];
1006
- }
1007
- });
1008
- });
1009
- }, t.heappop = function(e, r) {
1010
- var n = new t(r);
1011
- return n.heapArray = e, n.pop();
1012
- }, t.heappush = function(e, r, n) {
1013
- return d(this, void 0, void 0, function() {
1014
- var i;
1015
- return y(this, function(a) {
1016
- switch (a.label) {
1017
- case 0:
1018
- return i = new t(n), i.heapArray = e, [4, i.push(r)];
1019
- case 1:
1020
- return a.sent(), [
1021
- 2
1022
- /*return*/
1023
- ];
1024
- }
1025
- });
1026
- });
1027
- }, t.heappushpop = function(e, r, n) {
1028
- var i = new t(n);
1029
- return i.heapArray = e, i.pushpop(r);
1030
- }, t.heapreplace = function(e, r, n) {
1031
- var i = new t(n);
1032
- return i.heapArray = e, i.replace(r);
1033
- }, t.heaptop = function(e, r, n) {
1034
- r === void 0 && (r = 1);
1035
- var i = new t(n);
1036
- return i.heapArray = e, i.top(r);
1037
- }, t.heapbottom = function(e, r, n) {
1038
- r === void 0 && (r = 1);
1039
- var i = new t(n);
1040
- return i.heapArray = e, i.bottom(r);
1041
- }, t.nlargest = function(e, r, n) {
1042
- return d(this, void 0, void 0, function() {
1043
- var i;
1044
- return y(this, function(a) {
1045
- switch (a.label) {
1046
- case 0:
1047
- return i = new t(n), i.heapArray = E([], O(r), !1), [4, i.init()];
1048
- case 1:
1049
- return a.sent(), [2, i.top(e)];
1050
- }
1051
- });
1052
- });
1053
- }, t.nsmallest = function(e, r, n) {
1054
- return d(this, void 0, void 0, function() {
1055
- var i;
1056
- return y(this, function(a) {
1057
- switch (a.label) {
1058
- case 0:
1059
- return i = new t(n), i.heapArray = E([], O(r), !1), [4, i.init()];
1060
- case 1:
1061
- return a.sent(), [2, i.bottom(e)];
1062
- }
1063
- });
1064
- });
1065
- }, t.prototype.add = function(e) {
1066
- return d(this, void 0, void 0, function() {
1067
- return y(this, function(r) {
1068
- switch (r.label) {
1069
- case 0:
1070
- return [4, this._sortNodeUp(this.heapArray.push(e) - 1)];
1071
- case 1:
1072
- return r.sent(), this._applyLimit(), [2, !0];
1073
- }
1074
- });
1075
- });
1076
- }, t.prototype.addAll = function(e) {
1077
- return d(this, void 0, void 0, function() {
1078
- var r, n, i;
1079
- return y(this, function(a) {
1080
- switch (a.label) {
1081
- case 0:
1082
- r = this.length, (i = this.heapArray).push.apply(i, E([], O(e), !1)), n = this.length, a.label = 1;
1083
- case 1:
1084
- return r < n ? [4, this._sortNodeUp(r)] : [3, 4];
1085
- case 2:
1086
- a.sent(), a.label = 3;
1087
- case 3:
1088
- return ++r, [3, 1];
1089
- case 4:
1090
- return this._applyLimit(), [2, !0];
1091
- }
1092
- });
1093
- });
1094
- }, t.prototype.bottom = function() {
1095
- return d(this, arguments, void 0, function(e) {
1096
- return e === void 0 && (e = 1), y(this, function(r) {
1097
- return this.heapArray.length === 0 || e <= 0 ? [2, []] : this.heapArray.length === 1 ? [2, [this.heapArray[0]]] : e >= this.heapArray.length ? [2, E([], O(this.heapArray), !1)] : [2, this._bottomN_push(~~e)];
1098
- });
1099
- });
1100
- }, t.prototype.check = function() {
1101
- return d(this, void 0, void 0, function() {
1102
- var e, r, n, i, a, s, l, u, o;
1103
- return y(this, function(c) {
1104
- switch (c.label) {
1105
- case 0:
1106
- e = 0, c.label = 1;
1107
- case 1:
1108
- if (!(e < this.heapArray.length)) return [3, 10];
1109
- r = this.heapArray[e], n = this.getChildrenOf(e), c.label = 2;
1110
- case 2:
1111
- c.trys.push([2, 7, 8, 9]), i = (u = void 0, Oe(n)), a = i.next(), c.label = 3;
1112
- case 3:
1113
- return a.done ? [3, 6] : (s = a.value, [4, this.compare(r, s)]);
1114
- case 4:
1115
- if (c.sent() > 0)
1116
- return [2, r];
1117
- c.label = 5;
1118
- case 5:
1119
- return a = i.next(), [3, 3];
1120
- case 6:
1121
- return [3, 9];
1122
- case 7:
1123
- return l = c.sent(), u = { error: l }, [3, 9];
1124
- case 8:
1125
- try {
1126
- a && !a.done && (o = i.return) && o.call(i);
1127
- } finally {
1128
- if (u) throw u.error;
1129
- }
1130
- return [
1131
- 7
1132
- /*endfinally*/
1133
- ];
1134
- case 9:
1135
- return ++e, [3, 1];
1136
- case 10:
1137
- return [
1138
- 2
1139
- /*return*/
1140
- ];
1141
- }
1142
- });
1143
- });
1144
- }, t.prototype.clear = function() {
1145
- this.heapArray = [];
1146
- }, t.prototype.clone = function() {
1147
- var e = new t(this.comparator());
1148
- return e.heapArray = this.toArray(), e._limit = this._limit, e;
1149
- }, t.prototype.comparator = function() {
1150
- return this.compare;
1151
- }, t.prototype.contains = function(e) {
1152
- return d(this, arguments, void 0, function(r, n) {
1153
- var i, a, s, l, u, o;
1154
- return n === void 0 && (n = t.defaultIsEqual), y(this, function(c) {
1155
- switch (c.label) {
1156
- case 0:
1157
- c.trys.push([0, 5, 6, 7]), i = Oe(this.heapArray), a = i.next(), c.label = 1;
1158
- case 1:
1159
- return a.done ? [3, 4] : (s = a.value, [4, n(s, r)]);
1160
- case 2:
1161
- if (c.sent())
1162
- return [2, !0];
1163
- c.label = 3;
1164
- case 3:
1165
- return a = i.next(), [3, 1];
1166
- case 4:
1167
- return [3, 7];
1168
- case 5:
1169
- return l = c.sent(), u = { error: l }, [3, 7];
1170
- case 6:
1171
- try {
1172
- a && !a.done && (o = i.return) && o.call(i);
1173
- } finally {
1174
- if (u) throw u.error;
1175
- }
1176
- return [
1177
- 7
1178
- /*endfinally*/
1179
- ];
1180
- case 7:
1181
- return [2, !1];
1182
- }
1183
- });
1184
- });
1185
- }, t.prototype.init = function(e) {
1186
- return d(this, void 0, void 0, function() {
1187
- var r;
1188
- return y(this, function(n) {
1189
- switch (n.label) {
1190
- case 0:
1191
- e && (this.heapArray = E([], O(e), !1)), r = t.getParentIndexOf(this.length - 1), n.label = 1;
1192
- case 1:
1193
- return r >= 0 ? [4, this._sortNodeDown(r)] : [3, 4];
1194
- case 2:
1195
- n.sent(), n.label = 3;
1196
- case 3:
1197
- return --r, [3, 1];
1198
- case 4:
1199
- return this._applyLimit(), [
1200
- 2
1201
- /*return*/
1202
- ];
1203
- }
1204
- });
1205
- });
1206
- }, t.prototype.isEmpty = function() {
1207
- return this.length === 0;
1208
- }, t.prototype.leafs = function() {
1209
- if (this.heapArray.length === 0)
1210
- return [];
1211
- var e = t.getParentIndexOf(this.heapArray.length - 1);
1212
- return this.heapArray.slice(e + 1);
1213
- }, Object.defineProperty(t.prototype, "length", {
1214
- /**
1215
- * Length of the heap.
1216
- * @return {Number}
1217
- */
1218
- get: function() {
1219
- return this.heapArray.length;
1220
- },
1221
- enumerable: !1,
1222
- configurable: !0
1223
- }), Object.defineProperty(t.prototype, "limit", {
1224
- /**
1225
- * Get length limit of the heap.
1226
- * @return {Number}
1227
- */
1228
- get: function() {
1229
- return this._limit;
1230
- },
1231
- /**
1232
- * Set length limit of the heap.
1233
- * @return {Number}
1234
- */
1235
- set: function(e) {
1236
- this._limit = ~~e, this._applyLimit();
1237
- },
1238
- enumerable: !1,
1239
- configurable: !0
1240
- }), t.prototype.peek = function() {
1241
- return this.heapArray[0];
1242
- }, t.prototype.pop = function() {
1243
- return d(this, void 0, void 0, function() {
1244
- var e;
1245
- return y(this, function(r) {
1246
- return e = this.heapArray.pop(), this.length > 0 && e !== void 0 ? [2, this.replace(e)] : [2, e];
1247
- });
1248
- });
1249
- }, t.prototype.push = function() {
1250
- for (var e = [], r = 0; r < arguments.length; r++)
1251
- e[r] = arguments[r];
1252
- return d(this, void 0, void 0, function() {
1253
- return y(this, function(n) {
1254
- return e.length < 1 ? [2, !1] : e.length === 1 ? [2, this.add(e[0])] : [2, this.addAll(e)];
1255
- });
1256
- });
1257
- }, t.prototype.pushpop = function(e) {
1258
- return d(this, void 0, void 0, function() {
1259
- var r;
1260
- return y(this, function(n) {
1261
- switch (n.label) {
1262
- case 0:
1263
- return [4, this.compare(this.heapArray[0], e)];
1264
- case 1:
1265
- return n.sent() < 0 ? (r = O([this.heapArray[0], e], 2), e = r[0], this.heapArray[0] = r[1], [4, this._sortNodeDown(0)]) : [3, 3];
1266
- case 2:
1267
- n.sent(), n.label = 3;
1268
- case 3:
1269
- return [2, e];
1270
- }
1271
- });
1272
- });
1273
- }, t.prototype.remove = function(e) {
1274
- return d(this, arguments, void 0, function(r, n) {
1275
- var i, a, s, l = this;
1276
- return n === void 0 && (n = t.defaultIsEqual), y(this, function(u) {
1277
- switch (u.label) {
1278
- case 0:
1279
- return this.heapArray.length ? r !== void 0 ? [3, 2] : [4, this.pop()] : [2, !1];
1280
- case 1:
1281
- return u.sent(), [2, !0];
1282
- case 2:
1283
- i = [0], u.label = 3;
1284
- case 3:
1285
- return i.length ? (a = i.shift(), [4, n(this.heapArray[a], r)]) : [3, 13];
1286
- case 4:
1287
- return u.sent() ? a !== 0 ? [3, 6] : [4, this.pop()] : [3, 11];
1288
- case 5:
1289
- return u.sent(), [3, 10];
1290
- case 6:
1291
- return a !== this.heapArray.length - 1 ? [3, 7] : (this.heapArray.pop(), [3, 10]);
1292
- case 7:
1293
- return this.heapArray.splice(a, 1, this.heapArray.pop()), [4, this._sortNodeUp(a)];
1294
- case 8:
1295
- return u.sent(), [4, this._sortNodeDown(a)];
1296
- case 9:
1297
- u.sent(), u.label = 10;
1298
- case 10:
1299
- return [2, !0];
1300
- case 11:
1301
- s = t.getChildrenIndexOf(a).filter(function(o) {
1302
- return o < l.heapArray.length;
1303
- }), i.push.apply(i, E([], O(s), !1)), u.label = 12;
1304
- case 12:
1305
- return [3, 3];
1306
- case 13:
1307
- return [2, !1];
1308
- }
1309
- });
1310
- });
1311
- }, t.prototype.replace = function(e) {
1312
- return d(this, void 0, void 0, function() {
1313
- var r;
1314
- return y(this, function(n) {
1315
- switch (n.label) {
1316
- case 0:
1317
- return r = this.heapArray[0], this.heapArray[0] = e, [4, this._sortNodeDown(0)];
1318
- case 1:
1319
- return n.sent(), [2, r];
1320
- }
1321
- });
1322
- });
1323
- }, t.prototype.size = function() {
1324
- return this.length;
1325
- }, t.prototype.top = function() {
1326
- return d(this, arguments, void 0, function(e) {
1327
- return e === void 0 && (e = 1), y(this, function(r) {
1328
- return this.heapArray.length === 0 || e <= 0 ? [2, []] : this.heapArray.length === 1 || e === 1 ? [2, [this.heapArray[0]]] : e >= this.heapArray.length ? [2, E([], O(this.heapArray), !1)] : [2, this._topN_push(~~e)];
1329
- });
1330
- });
1331
- }, t.prototype.toArray = function() {
1332
- return E([], O(this.heapArray), !1);
1333
- }, t.prototype.toString = function() {
1334
- return this.heapArray.toString();
1335
- }, t.prototype.get = function(e) {
1336
- return this.heapArray[e];
1337
- }, t.prototype.getChildrenOf = function(e) {
1338
- var r = this;
1339
- return t.getChildrenIndexOf(e).map(function(n) {
1340
- return r.heapArray[n];
1341
- }).filter(function(n) {
1342
- return n !== void 0;
1343
- });
1344
- }, t.prototype.getParentOf = function(e) {
1345
- var r = t.getParentIndexOf(e);
1346
- return this.heapArray[r];
1347
- }, t.prototype[Symbol.iterator] = function() {
1348
- return y(this, function(e) {
1349
- switch (e.label) {
1350
- case 0:
1351
- return this.length ? [4, this.pop()] : [3, 2];
1352
- case 1:
1353
- return e.sent(), [3, 0];
1354
- case 2:
1355
- return [
1356
- 2
1357
- /*return*/
1358
- ];
1359
- }
1360
- });
1361
- }, t.prototype.iterator = function() {
1362
- return this;
1363
- }, t.prototype._applyLimit = function() {
1364
- if (this._limit && this._limit < this.heapArray.length)
1365
- for (var e = this.heapArray.length - this._limit; e; )
1366
- this.heapArray.pop(), --e;
1367
- }, t.prototype._bottomN_push = function(e) {
1368
- return d(this, void 0, void 0, function() {
1369
- var r, n, i, a, l, s, l;
1370
- return y(this, function(u) {
1371
- switch (u.label) {
1372
- case 0:
1373
- return r = new t(this.compare), r.limit = e, r.heapArray = this.heapArray.slice(-e), [4, r.init()];
1374
- case 1:
1375
- for (u.sent(), n = this.heapArray.length - 1 - e, i = t.getParentIndexOf(n), a = [], l = n; l > i; --l)
1376
- a.push(l);
1377
- s = this.heapArray, u.label = 2;
1378
- case 2:
1379
- return a.length ? (l = a.shift(), [4, this.compare(s[l], r.peek())]) : [3, 6];
1380
- case 3:
1381
- return u.sent() > 0 ? [4, r.replace(s[l])] : [3, 5];
1382
- case 4:
1383
- u.sent(), l % 2 && a.push(t.getParentIndexOf(l)), u.label = 5;
1384
- case 5:
1385
- return [3, 2];
1386
- case 6:
1387
- return [2, r.toArray()];
1388
- }
1389
- });
1390
- });
1391
- }, t.prototype._moveNode = function(e, r) {
1392
- var n = this.heapArray[e];
1393
- this.heapArray[e] = this.heapArray[r], this.heapArray[r] = n;
1394
- }, t.prototype._sortNodeDown = function(e) {
1395
- return d(this, void 0, void 0, function() {
1396
- var r, n, i, a, s, l, u;
1397
- return y(this, function(o) {
1398
- switch (o.label) {
1399
- case 0:
1400
- r = this.heapArray.length, n = e, i = this.heapArray[e], a = 2 * e + 1, o.label = 1;
1401
- case 1:
1402
- return a < r ? (s = a + 1, u = s >= r, u ? [3, 3] : [4, this.compare(this.heapArray[a], this.heapArray[s])]) : [3, 5];
1403
- case 2:
1404
- u = o.sent() < 0, o.label = 3;
1405
- case 3:
1406
- return l = u ? a : s, [4, this.compare(this.heapArray[l], i)];
1407
- case 4:
1408
- if (o.sent() < 0)
1409
- this.heapArray[e] = this.heapArray[l], e = l, a = 2 * e + 1;
1410
- else
1411
- return [3, 5];
1412
- return [3, 1];
1413
- case 5:
1414
- return e !== n && (this.heapArray[e] = i), [
1415
- 2
1416
- /*return*/
1417
- ];
1418
- }
1419
- });
1420
- });
1421
- }, t.prototype._sortNodeUp = function(e) {
1422
- return d(this, void 0, void 0, function() {
1423
- var r, n, i;
1424
- return y(this, function(a) {
1425
- switch (a.label) {
1426
- case 0:
1427
- r = this.heapArray[e], n = e, a.label = 1;
1428
- case 1:
1429
- return e > 0 ? (i = t.getParentIndexOf(e), [4, this.compare(r, this.heapArray[i])]) : [3, 3];
1430
- case 2:
1431
- if (a.sent() < 0)
1432
- this.heapArray[e] = this.heapArray[i], e = i;
1433
- else
1434
- return [3, 3];
1435
- return [3, 1];
1436
- case 3:
1437
- return e !== n && (this.heapArray[e] = r), [
1438
- 2
1439
- /*return*/
1440
- ];
1441
- }
1442
- });
1443
- });
1444
- }, t.prototype._topN_push = function(e) {
1445
- return d(this, void 0, void 0, function() {
1446
- var r, n, i, a;
1447
- return y(this, function(s) {
1448
- switch (s.label) {
1449
- case 0:
1450
- r = new t(this._invertedCompare), r.limit = e, n = [0], i = this.heapArray, s.label = 1;
1451
- case 1:
1452
- return n.length ? (a = n.shift(), a < i.length ? r.length < e ? [4, r.push(i[a])] : [3, 3] : [3, 6]) : [3, 7];
1453
- case 2:
1454
- return s.sent(), n.push.apply(n, E([], O(t.getChildrenIndexOf(a)), !1)), [3, 6];
1455
- case 3:
1456
- return [4, this.compare(i[a], r.peek())];
1457
- case 4:
1458
- return s.sent() < 0 ? [4, r.replace(i[a])] : [3, 6];
1459
- case 5:
1460
- s.sent(), n.push.apply(n, E([], O(t.getChildrenIndexOf(a)), !1)), s.label = 6;
1461
- case 6:
1462
- return [3, 1];
1463
- case 7:
1464
- return [2, r.toArray()];
1465
- }
1466
- });
1467
- });
1468
- }, t.prototype._topN_fill = function(e) {
1469
- return d(this, void 0, void 0, function() {
1470
- var r, n, i, a, s, s;
1471
- return y(this, function(l) {
1472
- switch (l.label) {
1473
- case 0:
1474
- return r = this.heapArray, n = new t(this._invertedCompare), n.limit = e, n.heapArray = r.slice(0, e), [4, n.init()];
1475
- case 1:
1476
- for (l.sent(), i = t.getParentIndexOf(e - 1) + 1, a = [], s = i; s < e; ++s)
1477
- a.push.apply(a, E([], O(t.getChildrenIndexOf(s).filter(function(u) {
1478
- return u < r.length;
1479
- })), !1));
1480
- (e - 1) % 2 && a.push(e), l.label = 2;
1481
- case 2:
1482
- return a.length ? (s = a.shift(), s < r.length ? [4, this.compare(r[s], n.peek())] : [3, 5]) : [3, 6];
1483
- case 3:
1484
- return l.sent() < 0 ? [4, n.replace(r[s])] : [3, 5];
1485
- case 4:
1486
- l.sent(), a.push.apply(a, E([], O(t.getChildrenIndexOf(s)), !1)), l.label = 5;
1487
- case 5:
1488
- return [3, 2];
1489
- case 6:
1490
- return [2, n.toArray()];
1491
- }
1492
- });
1493
- });
1494
- }, t.prototype._topN_heap = function(e) {
1495
- return d(this, void 0, void 0, function() {
1496
- var r, n, i, a, s;
1497
- return y(this, function(l) {
1498
- switch (l.label) {
1499
- case 0:
1500
- r = this.clone(), n = [], i = 0, l.label = 1;
1501
- case 1:
1502
- return i < e ? (s = (a = n).push, [4, r.pop()]) : [3, 4];
1503
- case 2:
1504
- s.apply(a, [l.sent()]), l.label = 3;
1505
- case 3:
1506
- return ++i, [3, 1];
1507
- case 4:
1508
- return [2, n];
1509
- }
1510
- });
1511
- });
1512
- }, t.prototype._topIdxOf = function(e) {
1513
- return d(this, void 0, void 0, function() {
1514
- var r, n, i, a;
1515
- return y(this, function(s) {
1516
- switch (s.label) {
1517
- case 0:
1518
- if (!e.length)
1519
- return [2, -1];
1520
- r = 0, n = e[r], i = 1, s.label = 1;
1521
- case 1:
1522
- return i < e.length ? [4, this.compare(e[i], n)] : [3, 4];
1523
- case 2:
1524
- a = s.sent(), a < 0 && (r = i, n = e[i]), s.label = 3;
1525
- case 3:
1526
- return ++i, [3, 1];
1527
- case 4:
1528
- return [2, r];
1529
- }
1530
- });
1531
- });
1532
- }, t.prototype._topOf = function() {
1533
- for (var e = [], r = 0; r < arguments.length; r++)
1534
- e[r] = arguments[r];
1535
- return d(this, void 0, void 0, function() {
1536
- var n;
1537
- return y(this, function(i) {
1538
- switch (i.label) {
1539
- case 0:
1540
- return n = new t(this.compare), [4, n.init(e)];
1541
- case 1:
1542
- return i.sent(), [2, n.peek()];
1543
- }
1544
- });
1545
- });
1546
- }, t;
1547
- })();
1548
- var Nt = function(t, e) {
1549
- var r = { label: 0, sent: function() {
1550
- if (a[0] & 1) throw a[1];
1551
- return a[1];
1552
- }, trys: [], ops: [] }, n, i, a, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
1553
- return s.next = l(0), s.throw = l(1), s.return = l(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() {
1554
- return this;
1555
- }), s;
1556
- function l(o) {
1557
- return function(c) {
1558
- return u([o, c]);
1559
- };
1560
- }
1561
- function u(o) {
1562
- if (n) throw new TypeError("Generator is already executing.");
1563
- for (; s && (s = 0, o[0] && (r = 0)), r; ) try {
1564
- if (n = 1, i && (a = o[0] & 2 ? i.return : o[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, o[1])).done) return a;
1565
- switch (i = 0, a && (o = [o[0] & 2, a.value]), o[0]) {
1566
- case 0:
1567
- case 1:
1568
- a = o;
1569
- break;
1570
- case 4:
1571
- return r.label++, { value: o[1], done: !1 };
1572
- case 5:
1573
- r.label++, i = o[1], o = [0];
1574
- continue;
1575
- case 7:
1576
- o = r.ops.pop(), r.trys.pop();
1577
- continue;
1578
- default:
1579
- if (a = r.trys, !(a = a.length > 0 && a[a.length - 1]) && (o[0] === 6 || o[0] === 2)) {
1580
- r = 0;
1581
- continue;
1582
- }
1583
- if (o[0] === 3 && (!a || o[1] > a[0] && o[1] < a[3])) {
1584
- r.label = o[1];
1585
- break;
1586
- }
1587
- if (o[0] === 6 && r.label < a[1]) {
1588
- r.label = a[1], a = o;
1589
- break;
1590
- }
1591
- if (a && r.label < a[2]) {
1592
- r.label = a[2], r.ops.push(o);
1593
- break;
1594
- }
1595
- a[2] && r.ops.pop(), r.trys.pop();
1596
- continue;
1597
- }
1598
- o = e.call(t, r);
1599
- } catch (c) {
1600
- o = [6, c], i = 0;
1601
- } finally {
1602
- n = a = 0;
1603
- }
1604
- if (o[0] & 5) throw o[1];
1605
- return { value: o[0] ? o[1] : void 0, done: !0 };
1606
- }
1607
- }, b = function(t, e) {
1608
- var r = typeof Symbol == "function" && t[Symbol.iterator];
1609
- if (!r) return t;
1610
- var n = r.call(t), i, a = [], s;
1611
- try {
1612
- for (; (e === void 0 || e-- > 0) && !(i = n.next()).done; ) a.push(i.value);
1613
- } catch (l) {
1614
- s = { error: l };
1615
- } finally {
1616
- try {
1617
- i && !i.done && (r = n.return) && r.call(n);
1618
- } finally {
1619
- if (s) throw s.error;
1620
- }
1621
- }
1622
- return a;
1623
- }, A = function(t, e, r) {
1624
- if (r || arguments.length === 2) for (var n = 0, i = e.length, a; n < i; n++)
1625
- (a || !(n in e)) && (a || (a = Array.prototype.slice.call(e, 0, n)), a[n] = e[n]);
1626
- return t.concat(a || Array.prototype.slice.call(e));
1627
- }, Dt = (
1628
- /** @class */
1629
- (function() {
1630
- function t(e) {
1631
- e === void 0 && (e = t.minComparator);
1632
- var r = this;
1633
- this.compare = e, this.heapArray = [], this._limit = 0, this.offer = this.add, this.element = this.peek, this.poll = this.pop, this.removeAll = this.clear, this._invertedCompare = function(n, i) {
1634
- return -1 * r.compare(n, i);
1635
- };
1636
- }
1637
- return t.getChildrenIndexOf = function(e) {
1638
- return [e * 2 + 1, e * 2 + 2];
1639
- }, t.getParentIndexOf = function(e) {
1640
- return e <= 0 ? -1 : e - 1 >> 1;
1641
- }, t.getSiblingIndexOf = function(e) {
1642
- if (e <= 0)
1643
- return -1;
1644
- var r = e % 2 ? 1 : -1;
1645
- return e + r;
1646
- }, t.minComparator = function(e, r) {
1647
- return e > r ? 1 : e < r ? -1 : 0;
1648
- }, t.maxComparator = function(e, r) {
1649
- return r > e ? 1 : r < e ? -1 : 0;
1650
- }, t.minComparatorNumber = function(e, r) {
1651
- return e - r;
1652
- }, t.maxComparatorNumber = function(e, r) {
1653
- return r - e;
1654
- }, t.defaultIsEqual = function(e, r) {
1655
- return e === r;
1656
- }, t.print = function(e) {
1657
- function r(c) {
1658
- var h = t.getParentIndexOf(c);
1659
- return Math.floor(Math.log2(h + 1));
1660
- }
1661
- function n(c, h) {
1662
- for (var g = ""; h > 0; --h)
1663
- g += c;
1664
- return g;
1665
- }
1666
- for (var i = 0, a = [], s = r(e.length - 1) + 2, l = 0; i < e.length; ) {
1667
- var u = r(i) + 1;
1668
- i === 0 && (u = 0);
1669
- var o = String(e.get(i));
1670
- o.length > l && (l = o.length), a[u] = a[u] || [], a[u].push(o), i += 1;
1671
- }
1672
- return a.map(function(c, h) {
1673
- var g = Math.pow(2, s - h) - 1;
1674
- return n(" ", Math.floor(g / 2) * l) + c.map(function(m) {
1675
- var S = (l - m.length) / 2;
1676
- return n(" ", Math.ceil(S)) + m + n(" ", Math.floor(S));
1677
- }).join(n(" ", g * l));
1678
- }).join(`
1679
- `);
1680
- }, t.heapify = function(e, r) {
1681
- var n = new t(r);
1682
- return n.heapArray = e, n.init(), n;
1683
- }, t.heappop = function(e, r) {
1684
- var n = new t(r);
1685
- return n.heapArray = e, n.pop();
1686
- }, t.heappush = function(e, r, n) {
1687
- var i = new t(n);
1688
- i.heapArray = e, i.push(r);
1689
- }, t.heappushpop = function(e, r, n) {
1690
- var i = new t(n);
1691
- return i.heapArray = e, i.pushpop(r);
1692
- }, t.heapreplace = function(e, r, n) {
1693
- var i = new t(n);
1694
- return i.heapArray = e, i.replace(r);
1695
- }, t.heaptop = function(e, r, n) {
1696
- r === void 0 && (r = 1);
1697
- var i = new t(n);
1698
- return i.heapArray = e, i.top(r);
1699
- }, t.heapbottom = function(e, r, n) {
1700
- r === void 0 && (r = 1);
1701
- var i = new t(n);
1702
- return i.heapArray = e, i.bottom(r);
1703
- }, t.nlargest = function(e, r, n) {
1704
- var i = new t(n);
1705
- return i.heapArray = A([], b(r), !1), i.init(), i.top(e);
1706
- }, t.nsmallest = function(e, r, n) {
1707
- var i = new t(n);
1708
- return i.heapArray = A([], b(r), !1), i.init(), i.bottom(e);
1709
- }, t.prototype.add = function(e) {
1710
- return this._sortNodeUp(this.heapArray.push(e) - 1), this._applyLimit(), !0;
1711
- }, t.prototype.addAll = function(e) {
1712
- var r, n = this.length;
1713
- (r = this.heapArray).push.apply(r, A([], b(e), !1));
1714
- for (var i = this.length; n < i; ++n)
1715
- this._sortNodeUp(n);
1716
- return this._applyLimit(), !0;
1717
- }, t.prototype.bottom = function(e) {
1718
- return e === void 0 && (e = 1), this.heapArray.length === 0 || e <= 0 ? [] : this.heapArray.length === 1 ? [this.heapArray[0]] : e >= this.heapArray.length ? A([], b(this.heapArray), !1) : this._bottomN_push(~~e);
1719
- }, t.prototype.check = function() {
1720
- var e = this;
1721
- return this.heapArray.find(function(r, n) {
1722
- return !!e.getChildrenOf(n).find(function(i) {
1723
- return e.compare(r, i) > 0;
1724
- });
1725
- });
1726
- }, t.prototype.clear = function() {
1727
- this.heapArray = [];
1728
- }, t.prototype.clone = function() {
1729
- var e = new t(this.comparator());
1730
- return e.heapArray = this.toArray(), e._limit = this._limit, e;
1731
- }, t.prototype.comparator = function() {
1732
- return this.compare;
1733
- }, t.prototype.contains = function(e, r) {
1734
- return r === void 0 && (r = t.defaultIsEqual), this.indexOf(e, r) !== -1;
1735
- }, t.prototype.init = function(e) {
1736
- e && (this.heapArray = A([], b(e), !1));
1737
- for (var r = t.getParentIndexOf(this.length - 1); r >= 0; --r)
1738
- this._sortNodeDown(r);
1739
- this._applyLimit();
1740
- }, t.prototype.isEmpty = function() {
1741
- return this.length === 0;
1742
- }, t.prototype.indexOf = function(e, r) {
1743
- if (r === void 0 && (r = t.defaultIsEqual), this.heapArray.length === 0)
1744
- return -1;
1745
- for (var n = [], i = 0; i < this.heapArray.length; ) {
1746
- var a = this.heapArray[i];
1747
- if (r(a, e))
1748
- return i;
1749
- this.compare(a, e) <= 0 && n.push.apply(n, A([], b(t.getChildrenIndexOf(i)), !1)), i = n.shift() || this.heapArray.length;
1750
- }
1751
- return -1;
1752
- }, t.prototype.indexOfEvery = function(e, r) {
1753
- if (r === void 0 && (r = t.defaultIsEqual), this.heapArray.length === 0)
1754
- return [];
1755
- for (var n = [], i = [], a = 0; a < this.heapArray.length; ) {
1756
- var s = this.heapArray[a];
1757
- r(s, e) ? (i.push(a), n.push.apply(n, A([], b(t.getChildrenIndexOf(a)), !1))) : this.compare(s, e) <= 0 && n.push.apply(n, A([], b(t.getChildrenIndexOf(a)), !1)), a = n.shift() || this.heapArray.length;
1758
- }
1759
- return i;
1760
- }, t.prototype.leafs = function() {
1761
- if (this.heapArray.length === 0)
1762
- return [];
1763
- var e = t.getParentIndexOf(this.heapArray.length - 1);
1764
- return this.heapArray.slice(e + 1);
1765
- }, Object.defineProperty(t.prototype, "length", {
1766
- /**
1767
- * Length of the heap. Aliases: {@link size}.
1768
- * @return {Number}
1769
- * @see size
1770
- */
1771
- get: function() {
1772
- return this.heapArray.length;
1773
- },
1774
- enumerable: !1,
1775
- configurable: !0
1776
- }), Object.defineProperty(t.prototype, "limit", {
1777
- /**
1778
- * Get length limit of the heap.
1779
- * Use {@link setLimit} or {@link limit} to set the limit.
1780
- * @return {Number}
1781
- * @see setLimit
1782
- */
1783
- get: function() {
1784
- return this._limit;
1785
- },
1786
- /**
1787
- * Set length limit of the heap. Same as using {@link setLimit}.
1788
- * @description If the heap is longer than the limit, the needed amount of leafs are removed.
1789
- * @param {Number} _l Limit, defaults to 0 (no limit). Negative, Infinity, or NaN values set the limit to 0.
1790
- * @see setLimit
1791
- */
1792
- set: function(e) {
1793
- e < 0 || isNaN(e) ? this._limit = 0 : this._limit = ~~e, this._applyLimit();
1794
- },
1795
- enumerable: !1,
1796
- configurable: !0
1797
- }), t.prototype.setLimit = function(e) {
1798
- return this.limit = e, e < 0 || isNaN(e) ? NaN : this._limit;
1799
- }, t.prototype.peek = function() {
1800
- return this.heapArray[0];
1801
- }, t.prototype.pop = function() {
1802
- var e = this.heapArray.pop();
1803
- return this.length > 0 && e !== void 0 ? this.replace(e) : e;
1804
- }, t.prototype.push = function() {
1805
- for (var e = [], r = 0; r < arguments.length; r++)
1806
- e[r] = arguments[r];
1807
- return e.length < 1 ? !1 : e.length === 1 ? this.add(e[0]) : this.addAll(e);
1808
- }, t.prototype.pushpop = function(e) {
1809
- var r;
1810
- return this.compare(this.heapArray[0], e) < 0 && (r = b([this.heapArray[0], e], 2), e = r[0], this.heapArray[0] = r[1], this._sortNodeDown(0)), e;
1811
- }, t.prototype.remove = function(e, r) {
1812
- var n = this;
1813
- if (r === void 0 && (r = t.defaultIsEqual), !this.heapArray.length)
1814
- return !1;
1815
- if (e === void 0)
1816
- return this.pop(), !0;
1817
- for (var i = [0]; i.length; ) {
1818
- var a = i.shift();
1819
- if (r(this.heapArray[a], e))
1820
- return a === 0 ? this.pop() : a === this.heapArray.length - 1 ? this.heapArray.pop() : (this.heapArray.splice(a, 1, this.heapArray.pop()), this._sortNodeUp(a), this._sortNodeDown(a)), !0;
1821
- if (this.compare(this.heapArray[a], e) <= 0) {
1822
- var s = t.getChildrenIndexOf(a).filter(function(l) {
1823
- return l < n.heapArray.length;
1824
- });
1825
- i.push.apply(i, A([], b(s), !1));
1826
- }
1827
- }
1828
- return !1;
1829
- }, t.prototype.replace = function(e) {
1830
- var r = this.heapArray[0];
1831
- return this.heapArray[0] = e, this._sortNodeDown(0), r;
1832
- }, t.prototype.size = function() {
1833
- return this.length;
1834
- }, t.prototype.top = function(e) {
1835
- return e === void 0 && (e = 1), this.heapArray.length === 0 || e <= 0 ? [] : this.heapArray.length === 1 || e === 1 ? [this.heapArray[0]] : e >= this.heapArray.length ? A([], b(this.heapArray), !1) : this._topN_push(~~e);
1836
- }, t.prototype.toArray = function() {
1837
- return A([], b(this.heapArray), !1);
1838
- }, t.prototype.toString = function() {
1839
- return this.heapArray.toString();
1840
- }, t.prototype.get = function(e) {
1841
- return this.heapArray[e];
1842
- }, t.prototype.getChildrenOf = function(e) {
1843
- var r = this;
1844
- return t.getChildrenIndexOf(e).map(function(n) {
1845
- return r.heapArray[n];
1846
- }).filter(function(n) {
1847
- return n !== void 0;
1848
- });
1849
- }, t.prototype.getParentOf = function(e) {
1850
- var r = t.getParentIndexOf(e);
1851
- return this.heapArray[r];
1852
- }, t.prototype[Symbol.iterator] = function() {
1853
- return Nt(this, function(e) {
1854
- switch (e.label) {
1855
- case 0:
1856
- return this.length ? [4, this.pop()] : [3, 2];
1857
- case 1:
1858
- return e.sent(), [3, 0];
1859
- case 2:
1860
- return [
1861
- 2
1862
- /*return*/
1863
- ];
1864
- }
1865
- });
1866
- }, t.prototype.iterator = function() {
1867
- return this.toArray();
1868
- }, t.prototype._applyLimit = function() {
1869
- if (this._limit > 0 && this._limit < this.heapArray.length)
1870
- for (var e = this.heapArray.length - this._limit; e; )
1871
- this.heapArray.pop(), --e;
1872
- }, t.prototype._bottomN_push = function(e) {
1873
- var r = new t(this.compare);
1874
- r.limit = e, r.heapArray = this.heapArray.slice(-e), r.init();
1875
- for (var n = this.heapArray.length - 1 - e, i = t.getParentIndexOf(n), a = [], s = n; s > i; --s)
1876
- a.push(s);
1877
- for (var l = this.heapArray; a.length; ) {
1878
- var s = a.shift();
1879
- this.compare(l[s], r.peek()) > 0 && (r.replace(l[s]), s % 2 && a.push(t.getParentIndexOf(s)));
1880
- }
1881
- return r.toArray();
1882
- }, t.prototype._moveNode = function(e, r) {
1883
- var n = this.heapArray[e];
1884
- this.heapArray[e] = this.heapArray[r], this.heapArray[r] = n;
1885
- }, t.prototype._sortNodeDown = function(e) {
1886
- for (var r = this.heapArray.length, n = e, i = this.heapArray[e], a = 2 * e + 1; a < r; ) {
1887
- var s = a + 1, l = s >= r || this.compare(this.heapArray[a], this.heapArray[s]) < 0 ? a : s;
1888
- if (this.compare(this.heapArray[l], i) < 0)
1889
- this.heapArray[e] = this.heapArray[l], e = l, a = 2 * e + 1;
1890
- else
1891
- break;
1892
- }
1893
- e !== n && (this.heapArray[e] = i);
1894
- }, t.prototype._sortNodeUp = function(e) {
1895
- for (var r = this.heapArray[e], n = e; e > 0; ) {
1896
- var i = t.getParentIndexOf(e);
1897
- if (this.compare(r, this.heapArray[i]) < 0)
1898
- this.heapArray[e] = this.heapArray[i], e = i;
1899
- else
1900
- break;
1901
- }
1902
- e !== n && (this.heapArray[e] = r);
1903
- }, t.prototype._topN_push = function(e) {
1904
- var r = new t(this._invertedCompare);
1905
- r.limit = e;
1906
- for (var n = [0], i = this.heapArray; n.length; ) {
1907
- var a = n.shift();
1908
- a < i.length && (r.length < e ? (r.push(i[a]), n.push.apply(n, A([], b(t.getChildrenIndexOf(a)), !1))) : this.compare(i[a], r.peek()) < 0 && (r.replace(i[a]), n.push.apply(n, A([], b(t.getChildrenIndexOf(a)), !1))));
1909
- }
1910
- return r.toArray();
1911
- }, t.prototype._topN_fill = function(e) {
1912
- var r = this.heapArray, n = new t(this._invertedCompare);
1913
- n.limit = e, n.heapArray = r.slice(0, e), n.init();
1914
- for (var i = t.getParentIndexOf(e - 1) + 1, a = [], s = i; s < e; ++s)
1915
- a.push.apply(a, A([], b(t.getChildrenIndexOf(s).filter(function(l) {
1916
- return l < r.length;
1917
- })), !1));
1918
- for ((e - 1) % 2 && a.push(e); a.length; ) {
1919
- var s = a.shift();
1920
- s < r.length && this.compare(r[s], n.peek()) < 0 && (n.replace(r[s]), a.push.apply(a, A([], b(t.getChildrenIndexOf(s)), !1)));
1921
- }
1922
- return n.toArray();
1923
- }, t.prototype._topN_heap = function(e) {
1924
- for (var r = this.clone(), n = [], i = 0; i < e; ++i)
1925
- n.push(r.pop());
1926
- return n;
1927
- }, t.prototype._topIdxOf = function(e) {
1928
- if (!e.length)
1929
- return -1;
1930
- for (var r = 0, n = e[r], i = 1; i < e.length; ++i) {
1931
- var a = this.compare(e[i], n);
1932
- a < 0 && (r = i, n = e[i]);
1933
- }
1934
- return r;
1935
- }, t.prototype._topOf = function() {
1936
- for (var e = [], r = 0; r < arguments.length; r++)
1937
- e[r] = arguments[r];
1938
- var n = new t(this.compare);
1939
- return n.init(e), n.peek();
1940
- }, t;
1941
- })()
1942
- );
1943
- function xt(t, e, r) {
399
+ function Ue(e, t, r) {
1944
400
  return Math.abs(
1945
- (t[0] * (e[1] - r[1]) + e[0] * (r[1] - t[1]) + r[0] * (t[1] - e[1])) / 2
401
+ (e[0] * (t[1] - r[1]) + t[0] * (r[1] - e[1]) + r[0] * (e[1] - t[1])) / 2
1946
402
  );
1947
403
  }
1948
- function X(t, { tolerance: e = 0, getWeight: r = () => 1 } = {}) {
1949
- if (t.length <= 2) return t;
1950
- const n = t.map((o, c) => ({ coord: o, i: c, area: 1 / 0, removed: !1, prev: null, next: null }));
1951
- for (let o = 0; o < n.length; o++)
1952
- o > 0 && (n[o].prev = n[o - 1]), o < n.length - 1 && (n[o].next = n[o + 1]);
1953
- const i = (o) => !o.prev || !o.next ? 1 / 0 : xt(o.prev.coord, o.coord, o.next.coord) * r(o.coord, o.i), a = new Dt((o, c) => o.area - c.area);
1954
- for (let o = 1; o < n.length - 1; o++)
1955
- n[o].area = i(n[o]), n[o]._currentArea = n[o].area, a.push(n[o]);
1956
- let s = 0;
1957
- for (; a.size() > 0; ) {
1958
- const o = a.pop();
1959
- if (!o.removed && o.area === o._currentArea) {
1960
- if (o.area < s ? o.area = s : s = o.area, o.area >= e) break;
1961
- o.removed = !0, o.prev && (o.prev.next = o.next), o.next && (o.next.prev = o.prev), o.prev?.prev && (o.prev.area = i(o.prev), o.prev._currentArea = o.prev.area, a.push(o.prev)), o.next?.next && (o.next.area = i(o.next), o.next._currentArea = o.next.area, a.push(o.next));
1962
- }
1963
- }
1964
- const l = [];
1965
- let u = n[0];
1966
- for (; u; )
1967
- u.removed || l.push(u.coord), u = u.next;
1968
- return l;
1969
- }
1970
- function fe(t, e) {
1971
- switch (p.all([
1972
- { value: t, validator: le, message: "geometry must be a GeoJson geometry" }
1973
- ]), t.type) {
1974
- case v.LINESTRING:
1975
- t.coordinates = X(t.coordinates, e);
404
+ function S(e, { tolerance: t = 0, getWeight: r = () => 1 } = {}) {
405
+ if (e.length <= 2) return e;
406
+ const n = e.map((a, p) => ({ coord: a, i: p, area: 1 / 0, removed: !1, prev: null, next: null }));
407
+ for (let a = 0; a < n.length; a++)
408
+ a > 0 && (n[a].prev = n[a - 1]), a < n.length - 1 && (n[a].next = n[a + 1]);
409
+ const s = (a) => !a.prev || !a.next ? 1 / 0 : Ue(a.prev.coord, a.coord, a.next.coord) * r(a.coord, a.i), o = new se((a, p) => a.area - p.area);
410
+ for (let a = 1; a < n.length - 1; a++)
411
+ n[a].area = s(n[a]), n[a]._currentArea = n[a].area, o.push(n[a]);
412
+ let u = 0;
413
+ for (; o.size() > 0; ) {
414
+ const a = o.pop();
415
+ if (!a.removed && a.area === a._currentArea) {
416
+ if (a.area < u ? a.area = u : u = a.area, a.area >= t) break;
417
+ a.removed = !0, a.prev && (a.prev.next = a.next), a.next && (a.next.prev = a.prev), a.prev?.prev && (a.prev.area = s(a.prev), a.prev._currentArea = a.prev.area, o.push(a.prev)), a.next?.next && (a.next.area = s(a.next), a.next._currentArea = a.next.area, o.push(a.next));
418
+ }
419
+ }
420
+ const g = [];
421
+ let c = n[0];
422
+ for (; c; )
423
+ c.removed || g.push(c.coord), c = c.next;
424
+ return g;
425
+ }
426
+ function U(e, t) {
427
+ switch (l.all([
428
+ { value: e, validator: G, message: "geometry must be a GeoJson geometry" }
429
+ ]), e.type) {
430
+ case f.LINESTRING:
431
+ e.coordinates = S(e.coordinates, t);
1976
432
  break;
1977
- case v.POLYGON:
1978
- case v.MULTI_LINESTRING:
1979
- t.coordinates = t.coordinates.map((r) => X(r, e));
433
+ case f.POLYGON:
434
+ case f.MULTI_LINESTRING:
435
+ e.coordinates = e.coordinates.map((r) => S(r, t));
1980
436
  break;
1981
- case v.MULTI_POLYGON:
1982
- t.coordinates = t.coordinates.map((r) => r.map((n) => X(n, e)));
437
+ case f.MULTI_POLYGON:
438
+ e.coordinates = e.coordinates.map((r) => r.map((n) => S(n, t)));
1983
439
  break;
1984
- case v.GEOMETRY_COLLECTION:
1985
- t.geometries.forEach((r) => fe(r, e));
440
+ case f.GEOMETRY_COLLECTION:
441
+ e.geometries.forEach((r) => U(r, t));
1986
442
  break;
1987
443
  }
1988
- return t;
444
+ return e;
1989
445
  }
1990
- const _t = xe(["common-ekosystem", "simplify", "geojson"]);
1991
- function ke(t, e) {
1992
- if (t.type === I.FEATURE)
1993
- t.geometry && fe(t.geometry, e);
1994
- else if (t.type === I.FEATURE_COLLECTION)
1995
- for (const r of t.features) ke(r, e);
446
+ const Fe = j(["common-ekosystem", "simplify", "geojson"]);
447
+ function Z(e, t) {
448
+ if (e.type === v.FEATURE)
449
+ e.geometry && U(e.geometry, t);
450
+ else if (e.type === v.FEATURE_COLLECTION)
451
+ for (const r of e.features) Z(r, t);
1996
452
  else
1997
- _t.warn('Unknown feature type "{type}", skipping.', { type: t.type });
1998
- return t;
453
+ Fe.warn('Unknown feature type "{type}", skipping.', { type: e.type });
454
+ return e;
1999
455
  }
2000
- function yr(t, e) {
2001
- return p.all([
2002
- { value: t, validator: De, message: "geoJson must be a GeoJson object" }
2003
- ]), f.oneOf(t.type, Object.values(v)) ? fe(t, e) : ke(t, e);
456
+ function dt(e, t) {
457
+ return l.all([
458
+ { value: e, validator: Q, message: "geoJson must be a GeoJson object" }
459
+ ]), i.oneOf(e.type, Object.values(f)) ? U(e, t) : Z(e, t);
2004
460
  }
2005
- function Pe(t, e = 7) {
2006
- p.all([
2007
- { value: t, validator: gt, message: "bbox must be bounding box" },
2008
- { value: e, validator: (n) => f.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
461
+ function J(e, t = 7) {
462
+ l.all([
463
+ { value: e, validator: $e, message: "bbox must be bounding box" },
464
+ { value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
2009
465
  ]);
2010
- const r = oe[e];
2011
- for (let n = 0; n < t.length; n++)
2012
- t[n] = Math.round(t[n] * r) / r;
2013
- return t;
2014
- }
2015
- function Rt(t, e, r = {}) {
2016
- const n = { type: "Feature" };
2017
- return (r.id === 0 || r.id) && (n.id = r.id), r.bbox && (n.bbox = r.bbox), n.properties = {}, n.geometry = t, n;
2018
- }
2019
- function Mt(t, e, r = {}) {
2020
- if (!t)
2021
- throw new Error("coordinates is required");
2022
- if (!Array.isArray(t))
2023
- throw new Error("coordinates must be an Array");
2024
- if (t.length < 2)
2025
- throw new Error("coordinates must be at least 2 numbers long");
2026
- if (!Ee(t[0]) || !Ee(t[1]))
2027
- throw new Error("coordinates must contain numbers");
2028
- return Rt({
2029
- type: "Point",
2030
- coordinates: t
2031
- }, e, r);
2032
- }
2033
- function Ee(t) {
2034
- return !isNaN(t) && t !== null && !Array.isArray(t);
2035
- }
2036
- function $t(t) {
2037
- return t !== null && typeof t == "object" && !Array.isArray(t);
2038
- }
2039
- function Ue(t, e, r) {
2040
- if (t !== null)
2041
- for (var n, i, a, s, l, u, o, c = 0, h = 0, g, m = t.type, S = m === "FeatureCollection", G = m === "Feature", F = S ? t.features.length : 1, L = 0; L < F; L++) {
2042
- o = S ? (
2043
- // @ts-expect-error: Known type conflict
2044
- t.features[L].geometry
2045
- ) : G ? (
2046
- // @ts-expect-error: Known type conflict
2047
- t.geometry
2048
- ) : t, g = o ? o.type === "GeometryCollection" : !1, l = g ? o.geometries.length : 1;
2049
- for (var V = 0; V < l; V++) {
2050
- var T = 0, N = 0;
2051
- if (s = g ? o.geometries[V] : o, s !== null) {
2052
- u = s.coordinates;
2053
- var x = s.type;
2054
- switch (c = 0, x) {
2055
- case null:
2056
- break;
2057
- case "Point":
2058
- if (
2059
- // @ts-expect-error: Known type conflict
2060
- e(
2061
- u,
2062
- h,
2063
- L,
2064
- T,
2065
- N
2066
- ) === !1
2067
- )
2068
- return !1;
2069
- h++, T++;
2070
- break;
2071
- case "LineString":
2072
- case "MultiPoint":
2073
- for (n = 0; n < u.length; n++) {
2074
- if (
2075
- // @ts-expect-error: Known type conflict
2076
- e(
2077
- u[n],
2078
- h,
2079
- L,
2080
- T,
2081
- N
2082
- ) === !1
2083
- )
2084
- return !1;
2085
- h++, x === "MultiPoint" && T++;
2086
- }
2087
- x === "LineString" && T++;
2088
- break;
2089
- case "Polygon":
2090
- case "MultiLineString":
2091
- for (n = 0; n < u.length; n++) {
2092
- for (i = 0; i < u[n].length - c; i++) {
2093
- if (
2094
- // @ts-expect-error: Known type conflict
2095
- e(
2096
- u[n][i],
2097
- h,
2098
- L,
2099
- T,
2100
- N
2101
- ) === !1
2102
- )
2103
- return !1;
2104
- h++;
2105
- }
2106
- x === "MultiLineString" && T++, x === "Polygon" && N++;
2107
- }
2108
- x === "Polygon" && T++;
2109
- break;
2110
- case "MultiPolygon":
2111
- for (n = 0; n < u.length; n++) {
2112
- for (N = 0, i = 0; i < u[n].length; i++) {
2113
- for (a = 0; a < u[n][i].length - c; a++) {
2114
- if (
2115
- // @ts-expect-error: Known type conflict
2116
- e(
2117
- u[n][i][a],
2118
- h,
2119
- L,
2120
- T,
2121
- N
2122
- ) === !1
2123
- )
2124
- return !1;
2125
- h++;
2126
- }
2127
- N++;
2128
- }
2129
- T++;
2130
- }
2131
- break;
2132
- case "GeometryCollection":
2133
- for (n = 0; n < s.geometries.length; n++)
2134
- if (
2135
- // @ts-expect-error: Known type conflict
2136
- Ue(s.geometries[n], e) === !1
2137
- )
2138
- return !1;
2139
- break;
2140
- default:
2141
- throw new Error("Unknown Geometry Type");
2142
- }
2143
- }
2144
- }
2145
- }
2146
- }
2147
- function kt(t, e) {
2148
- if (e = e ?? {}, !$t(e)) throw new Error("options is invalid");
2149
- var r = e.precision, n = e.coordinates, i = e.mutate;
2150
- if (r = r == null || isNaN(r) ? 6 : r, n = n == null || isNaN(n) ? 3 : n, !t) throw new Error("<geojson> is required");
2151
- if (typeof r != "number")
2152
- throw new Error("<precision> must be a number");
2153
- if (typeof n != "number")
2154
- throw new Error("<coordinates> must be a number");
2155
- (i === !1 || i === void 0) && (t = JSON.parse(JSON.stringify(t)));
2156
- var a = Math.pow(10, r);
2157
- return Ue(t, function(s) {
2158
- Pt(s, a, n);
2159
- }), t;
2160
- }
2161
- function Pt(t, e, r) {
2162
- t.length > r && t.splice(r, t.length);
2163
- for (var n = 0; n < t.length; n++)
2164
- t[n] = Math.round(t[n] * e) / e;
2165
- return t;
466
+ const r = x[t];
467
+ for (let n = 0; n < e.length; n++)
468
+ e[n] = Math.round(e[n] * r) / r;
469
+ return e;
2166
470
  }
2167
- var Ut = kt;
2168
- function Ge(t, e = 7) {
2169
- p.all([
2170
- { value: t, validator: le, message: "geometry must be a GeoJson geometry" },
2171
- { value: e, validator: (n) => f.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
471
+ function ee(e, t = 7) {
472
+ l.all([
473
+ { value: e, validator: G, message: "geometry must be a GeoJson geometry" },
474
+ { value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
2172
475
  ]);
2173
- const r = Ut(t, { precision: e, mutate: !0 });
2174
- return r.bbox && Pe(r.bbox, e), r;
2175
- }
2176
- const Gt = xe(["common-ekosystem", "truncate", "geojson"]);
2177
- function Fe(t, e) {
2178
- if (t.type === I.FEATURE)
2179
- t.geometry && Ge(t.geometry, e);
2180
- else if (t.type === I.FEATURE_COLLECTION)
2181
- for (const r of t.features) Fe(r, e);
476
+ const r = ae(e, { precision: t, mutate: !0 });
477
+ return r.bbox && J(r.bbox, t), r;
478
+ }
479
+ const ke = j(["common-ekosystem", "truncate", "geojson"]);
480
+ function te(e, t) {
481
+ if (e.type === v.FEATURE)
482
+ e.geometry && ee(e.geometry, t);
483
+ else if (e.type === v.FEATURE_COLLECTION)
484
+ for (const r of e.features) te(r, t);
2182
485
  else
2183
- Gt.warn('Unknown feature type "{type}", skipping.', { type: t.type });
2184
- return t.bbox && Pe(t.bbox, e), t;
2185
- }
2186
- function dr(t, e = 7) {
2187
- return p.all([
2188
- { value: t, validator: De, message: "geoJson must be a valid GeoJson" },
2189
- { value: e, validator: (r) => f.inRange(r, 0, 8), message: "precision must be in range [0, 8]" }
2190
- ]), f.oneOf(t.type, Object.values(v)) ? Ge(t, e) : Fe(t, e);
2191
- }
2192
- function mr(t, e = 7) {
2193
- p.all([
2194
- { value: t, validator: mt, message: "position must be a position" },
2195
- { value: e, validator: (n) => f.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
486
+ ke.warn('Unknown feature type "{type}", skipping.', { type: e.type });
487
+ return e.bbox && J(e.bbox, t), e;
488
+ }
489
+ function pt(e, t = 7) {
490
+ return l.all([
491
+ { value: e, validator: Q, message: "geoJson must be a valid GeoJson" },
492
+ { value: t, validator: (r) => i.inRange(r, 0, 8), message: "precision must be in range [0, 8]" }
493
+ ]), i.oneOf(e.type, Object.values(f)) ? ee(e, t) : te(e, t);
494
+ }
495
+ function vt(e, t = 7) {
496
+ l.all([
497
+ { value: e, validator: Ge, message: "position must be a position" },
498
+ { value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
2196
499
  ]);
2197
- const r = oe[e];
2198
- for (let n = 0; n < t.length; n++)
2199
- t[n] = Math.round(t[n] * r) / r;
2200
- return t;
500
+ const r = x[t];
501
+ for (let n = 0; n < e.length; n++)
502
+ e[n] = Math.round(e[n] * r) / r;
503
+ return e;
2201
504
  }
2202
- function j(t) {
2203
- if (!f.arrayOfLengthBetween(t, 2, 3))
505
+ function D(e) {
506
+ if (!i.arrayOfLengthBetween(e, 2, 3))
2204
507
  return {
2205
508
  valid: !1,
2206
509
  errors: [{ message: "Invalid coordinates: must be an array of 2 or 3 coordinates" }],
2207
510
  warnings: []
2208
511
  };
2209
- if (!f.inRange(t[0], -180, 180))
512
+ if (!i.inRange(e[0], -180, 180))
2210
513
  return {
2211
514
  valid: !1,
2212
515
  errors: [{ message: "Invalid coordinates: longitude must be in the range -180 to 180" }],
2213
516
  warnings: []
2214
517
  };
2215
- if (!f.inRange(t[1], -90, 90))
518
+ if (!i.inRange(e[1], -90, 90))
2216
519
  return {
2217
520
  valid: !1,
2218
521
  errors: [{ message: "Invalid coordinates: latitude must be in the range -90 to 90" }],
2219
522
  warnings: []
2220
523
  };
2221
- if (t.length === 3 && !f.number(t[2]))
524
+ if (e.length === 3 && !i.number(e[2]))
2222
525
  return {
2223
526
  valid: !1,
2224
527
  errors: [{ message: "Invalid coordinates: altitude must be a number" }],
2225
528
  warnings: []
2226
529
  };
2227
- const e = { valid: !0, errors: [], warnings: [] }, r = de(t[0]);
2228
- r > 6 && e.warnings.push({ message: `longitude precision is high (${r} decimals, max recommended: 6)` });
2229
- const n = de(t[1]);
2230
- return n > 6 && e.warnings.push({ message: `latitude precision is high (${n} decimals, max recommended: 6)` }), e;
530
+ const t = { valid: !0, errors: [], warnings: [] }, r = W(e[0]);
531
+ r > 6 && t.warnings.push({ message: `longitude precision is high (${r} decimals, max recommended: 6)` });
532
+ const n = W(e[1]);
533
+ return n > 6 && t.warnings.push({ message: `latitude precision is high (${n} decimals, max recommended: 6)` }), t;
2231
534
  }
2232
- function Ft(t) {
2233
- if (!f.arrayOfLength(t, 4) && !f.arrayOfLength(t, 6))
535
+ function Pe(e) {
536
+ if (!i.arrayOfLength(e, 4) && !i.arrayOfLength(e, 6))
2234
537
  return {
2235
538
  valid: !1,
2236
539
  errors: [{ message: "Invalid bbox: must be an array of 4 (2D) or 6 (3D) numbers" }],
2237
540
  warnings: []
2238
541
  };
2239
- const e = t.length === 4, r = e ? [t[0], t[1]] : [t[0], t[1], t[2]], n = e ? [t[2], t[3]] : [t[3], t[4], t[5]], i = j(r);
2240
- if (!i.valid)
542
+ const t = e.length === 4, r = t ? [e[0], e[1]] : [e[0], e[1], e[2]], n = t ? [e[2], e[3]] : [e[3], e[4], e[5]], s = D(r);
543
+ if (!s.valid)
2241
544
  return {
2242
545
  valid: !1,
2243
- errors: i.errors.map((h) => ({ ...h, message: `Invalid bbox south-west: ${h.message}` })),
546
+ errors: s.errors.map((m) => ({ ...m, message: `Invalid bbox south-west: ${m.message}` })),
2244
547
  warnings: []
2245
548
  };
2246
- const a = j(n);
2247
- if (!a.valid)
549
+ const o = D(n);
550
+ if (!o.valid)
2248
551
  return {
2249
552
  valid: !1,
2250
- errors: a.errors.map((h) => ({ ...h, message: `Invalid bbox north-east: ${h.message}` })),
553
+ errors: o.errors.map((m) => ({ ...m, message: `Invalid bbox north-east: ${m.message}` })),
2251
554
  warnings: []
2252
555
  };
2253
- const [s, l] = r, [u, o] = n;
2254
- if (l > o)
556
+ const [u, g] = r, [c, a] = n;
557
+ if (g > a)
2255
558
  return {
2256
559
  valid: !1,
2257
- errors: [{ message: `Invalid bbox: south (${l}) must be <= north (${o})` }],
560
+ errors: [{ message: `Invalid bbox: south (${g}) must be <= north (${a})` }],
2258
561
  warnings: []
2259
562
  };
2260
- const c = { valid: !0, errors: [], warnings: [] };
2261
- return s > u && c.warnings.push({ message: `bbox crosses the antimeridian (west: ${s} > east: ${u})` }), c.warnings.push(...i.warnings.map((h) => ({ ...h, message: `south-west: ${h.message}` }))), c.warnings.push(...a.warnings.map((h) => ({ ...h, message: `north-east: ${h.message}` }))), c;
563
+ const p = { valid: !0, errors: [], warnings: [] };
564
+ return u > c && p.warnings.push({ message: `bbox crosses the antimeridian (west: ${u} > east: ${c})` }), p.warnings.push(...s.warnings.map((m) => ({ ...m, message: `south-west: ${m.message}` }))), p.warnings.push(...o.warnings.map((m) => ({ ...m, message: `north-east: ${m.message}` }))), p;
2262
565
  }
2263
- function Ht(t) {
2264
- if (!f.plainObject(t))
566
+ function He(e) {
567
+ if (!i.plainObject(e))
2265
568
  return {
2266
569
  valid: !1,
2267
570
  errors: [{ message: "Invalid crs: must be an object" }],
2268
571
  warnings: []
2269
572
  };
2270
- switch (t.type) {
2271
- case z.NAME:
2272
- return f.nonEmptyString(t.properties?.name) ? { valid: !0, errors: [], warnings: [] } : {
573
+ switch (e.type) {
574
+ case L.NAME:
575
+ return i.nonEmptyString(e.properties?.name) ? { valid: !0, errors: [], warnings: [] } : {
2273
576
  valid: !1,
2274
577
  errors: [{ message: "Invalid crs: linked crs must have a non-empty properties.name string" }],
2275
578
  warnings: []
2276
579
  };
2277
- case z.LINK:
2278
- return f.nonEmptyString(t.properties?.href) ? { valid: !0, errors: [], warnings: [] } : {
580
+ case L.LINK:
581
+ return i.nonEmptyString(e.properties?.href) ? { valid: !0, errors: [], warnings: [] } : {
2279
582
  valid: !1,
2280
583
  errors: [{ message: "Invalid crs: linked crs must have a non-empty properties.href string" }],
2281
584
  warnings: []
@@ -2283,351 +586,279 @@ function Ht(t) {
2283
586
  default:
2284
587
  return {
2285
588
  valid: !1,
2286
- errors: [{ message: `Invalid crs: unknown type: ${t.type}` }],
589
+ errors: [{ message: `Invalid crs: unknown type: ${e.type}` }],
2287
590
  warnings: []
2288
591
  };
2289
592
  }
2290
593
  }
2291
- function qt(t) {
2292
- if (Array.isArray(t))
2293
- return t;
2294
- if (t.type === "Feature") {
2295
- if (t.geometry !== null)
2296
- return t.geometry.coordinates;
2297
- } else if (t.coordinates)
2298
- return t.coordinates;
2299
- throw new Error(
2300
- "coords must be GeoJSON Feature, Geometry Object or an Array"
2301
- );
2302
- }
2303
- function zt(t) {
2304
- const e = qt(t);
2305
- let r = 0, n = 1, i, a;
2306
- for (; n < e.length; )
2307
- i = a || e[0], a = e[n], r += (a[0] - i[0]) * (a[1] + i[1]), n++;
2308
- return r > 0;
2309
- }
2310
- var jt = zt;
2311
- function Wt(t) {
2312
- let e, r;
2313
- const n = {
2314
- type: "FeatureCollection",
2315
- features: []
2316
- };
2317
- if (t.type === "Feature" ? r = t.geometry : r = t, r.type === "LineString")
2318
- e = [r.coordinates];
2319
- else if (r.type === "MultiLineString")
2320
- e = r.coordinates;
2321
- else if (r.type === "MultiPolygon")
2322
- e = [].concat(...r.coordinates);
2323
- else if (r.type === "Polygon")
2324
- e = r.coordinates;
2325
- else
2326
- throw new Error(
2327
- "Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry"
2328
- );
2329
- return e.forEach((i) => {
2330
- e.forEach((a) => {
2331
- for (let s = 0; s < i.length - 1; s++)
2332
- for (let l = s; l < a.length - 1; l++) {
2333
- if (i === a && (Math.abs(s - l) === 1 || // segments are first and last segment of lineString
2334
- s === 0 && l === i.length - 2 && // lineString is closed
2335
- i[s][0] === i[i.length - 1][0] && i[s][1] === i[i.length - 1][1]))
2336
- continue;
2337
- const u = Vt(
2338
- i[s][0],
2339
- i[s][1],
2340
- i[s + 1][0],
2341
- i[s + 1][1],
2342
- a[l][0],
2343
- a[l][1],
2344
- a[l + 1][0],
2345
- a[l + 1][1]
2346
- );
2347
- u && n.features.push(Mt([u[0], u[1]]));
2348
- }
2349
- });
2350
- }), n;
2351
- }
2352
- function Vt(t, e, r, n, i, a, s, l) {
2353
- let u, o, c, h, g;
2354
- const m = {
2355
- x: null,
2356
- y: null,
2357
- onLine1: !1,
2358
- onLine2: !1
2359
- };
2360
- return u = (l - a) * (r - t) - (s - i) * (n - e), u === 0 ? m.x !== null && m.y !== null ? m : !1 : (o = e - a, c = t - i, h = (s - i) * o - (l - a) * c, g = (r - t) * o - (n - e) * c, o = h / u, c = g / u, m.x = t + o * (r - t), m.y = e + o * (n - e), o >= 0 && o <= 1 && (m.onLine1 = !0), c >= 0 && c <= 1 && (m.onLine2 = !0), m.onLine1 && m.onLine2 ? [m.x, m.y] : !1);
2361
- }
2362
- var Bt = Wt;
2363
- function $() {
594
+ function y() {
2364
595
  return { Feature: 0, FeatureCollection: 0, geometries: {} };
2365
596
  }
2366
- function Kt(...t) {
2367
- const e = $();
2368
- for (const r of t) {
597
+ function Ve(...e) {
598
+ const t = y();
599
+ for (const r of e) {
2369
600
  const n = r.statistics;
2370
601
  if (n) {
2371
- e.Feature += n.Feature ?? 0, e.FeatureCollection += n.FeatureCollection ?? 0;
2372
- for (const [i, a] of Object.entries(n.geometries ?? {}))
2373
- e.geometries[i] = (e.geometries[i] ?? 0) + a;
602
+ t.Feature += n.Feature ?? 0, t.FeatureCollection += n.FeatureCollection ?? 0;
603
+ for (const [s, o] of Object.entries(n.geometries ?? {}))
604
+ t.geometries[s] = (t.geometries[s] ?? 0) + o;
2374
605
  }
2375
606
  }
2376
- return e;
607
+ return t;
2377
608
  }
2378
- function M(t, e, r = "") {
609
+ function h(e, t, r = "") {
2379
610
  const n = {
2380
611
  valid: !0,
2381
612
  errors: [],
2382
613
  warnings: []
2383
614
  };
2384
- for (let i = 0; i < t.length; i++) {
2385
- const a = `${r}/${i}`, s = e(t[i], a, i);
2386
- if (!s.valid) {
2387
- n.valid = !1, n.errors = n.errors.concat(s.errors.map((l) => ({ ...l, path: l.path || a, index: i })));
615
+ for (let s = 0; s < e.length; s++) {
616
+ const o = `${r}/${s}`, u = t(e[s], o, s);
617
+ if (!u.valid) {
618
+ n.valid = !1, n.errors = n.errors.concat(u.errors.map((g) => ({ ...g, path: g.path || o, index: s })));
2388
619
  continue;
2389
620
  }
2390
- f.empty(s.warnings) || (n.warnings = n.warnings.concat(s.warnings.map((l) => ({ ...l, path: l.path || a, index: i })))), s.statistics && (n.statistics = Kt(n, s));
621
+ i.empty(u.warnings) || (n.warnings = n.warnings.concat(u.warnings.map((g) => ({ ...g, path: g.path || o, index: s })))), u.statistics && (n.statistics = Ve(n, u));
2391
622
  }
2392
623
  return n;
2393
624
  }
2394
- function Zt(t, e) {
2395
- if (!f.defined(t.crs)) return e;
2396
- const r = Ht(t.crs);
2397
- return r.valid || (e.valid = !1, e.errors.push(...r.errors.map((n) => ({ ...n, path: "/crs" })))), e.warnings.push(...r.warnings.map((n) => ({ ...n, path: "/crs" }))), e;
625
+ function We(e, t) {
626
+ if (!i.defined(e.crs)) return t;
627
+ const r = He(e.crs);
628
+ return r.valid || (t.valid = !1, t.errors.push(...r.errors.map((n) => ({ ...n, path: "/crs" })))), t.warnings.push(...r.warnings.map((n) => ({ ...n, path: "/crs" }))), t;
2398
629
  }
2399
- function ne(t, e, r = "") {
2400
- if (!f.defined(t.bbox)) return e;
2401
- const n = Ft(t.bbox);
2402
- return n.valid || (e.valid = !1, e.errors.push(...n.errors.map((i) => ({ ...i, path: `${r}/bbox` })))), e.warnings.push(...n.warnings.map((i) => ({ ...i, path: `${r}/bbox` }))), e;
630
+ function w(e, t, r = "") {
631
+ if (!i.defined(e.bbox)) return t;
632
+ const n = Pe(e.bbox);
633
+ return n.valid || (t.valid = !1, t.errors.push(...n.errors.map((s) => ({ ...s, path: `${r}/bbox` })))), t.warnings.push(...n.warnings.map((s) => ({ ...s, path: `${r}/bbox` }))), t;
2403
634
  }
2404
- function ce(t, e = 0, r = "") {
2405
- return f.arrayOfLengthAtLeast(t, e) ? M(t, j, r) : {
635
+ function F(e, t = 0, r = "") {
636
+ return i.arrayOfLengthAtLeast(e, t) ? h(e, D, r) : {
2406
637
  valid: !1,
2407
- errors: [{ message: `Invalid coordinates: must have at least ${e} positions`, path: r }],
638
+ errors: [{ message: `Invalid coordinates: must have at least ${t} positions`, path: r }],
2408
639
  warnings: []
2409
640
  };
2410
641
  }
2411
- function He(t, e = "") {
2412
- const r = ce(t, 2, e);
642
+ function ne(e, t = "") {
643
+ const r = F(e, 2, t);
2413
644
  if (!r.valid) return r;
2414
- for (let n = 0; n < t.length - 1; n++) {
2415
- const i = t[n][0], a = t[n + 1][0];
2416
- Math.abs(a - i) > 180 && r.warnings.push({
645
+ for (let n = 0; n < e.length - 1; n++) {
646
+ const s = e[n][0], o = e[n + 1][0];
647
+ Math.abs(o - s) > 180 && r.warnings.push({
2417
648
  message: `LineString crosses the antimeridian between positions ${n} and ${n + 1}, consider using MultiLineString`,
2418
- path: `${e}/${n}`
649
+ path: `${t}/${n}`
2419
650
  });
2420
651
  }
2421
652
  return r;
2422
653
  }
2423
- function Yt(t, e = "") {
2424
- return f.nonEmptyArray(t) ? M(t, He, e) : {
654
+ function je(e, t = "") {
655
+ return i.nonEmptyArray(e) ? h(e, ne, t) : {
2425
656
  valid: !1,
2426
- errors: [{ message: "Invalid MultiLineString: coordinates must be a non empty array", path: e }],
657
+ errors: [{ message: "Invalid MultiLineString: coordinates must be a non empty array", path: t }],
2427
658
  warnings: []
2428
659
  };
2429
660
  }
2430
- function Jt(t, e, r = "") {
2431
- const n = ce(t, 4, r);
661
+ function Ye(e, t, r = "") {
662
+ const n = F(e, 4, r);
2432
663
  if (!n.valid) return n;
2433
- const i = t[0], a = t[t.length - 1];
2434
- if (i[0] !== a[0] || i[1] !== a[1])
664
+ const s = e[0], o = e[e.length - 1];
665
+ if (s[0] !== o[0] || s[1] !== o[1])
2435
666
  return n.valid = !1, n.errors.push({ message: "Invalid LinearRing: first and last position must be identical", path: r }), n;
2436
- const l = jt(t) ? "clockwise" : "counter-clockwise";
2437
- l !== e && n.warnings.push({ message: `Ring must be ${e} but is ${l}`, path: r });
2438
- const u = Bt({ type: "Polygon", coordinates: [t] });
2439
- return u.features.length > 0 && (n.valid = !1, n.errors.push({ message: `Invalid LinearRing: ${u.features.length} self-intersection(s) detected`, path: r })), n;
667
+ const g = oe(e) ? "clockwise" : "counter-clockwise";
668
+ g !== t && n.warnings.push({ message: `Ring must be ${t} but is ${g}`, path: r });
669
+ const c = le({ type: "Polygon", coordinates: [e] });
670
+ return c.features.length > 0 && (n.valid = !1, n.errors.push({ message: `Invalid LinearRing: ${c.features.length} self-intersection(s) detected`, path: r })), n;
2440
671
  }
2441
- function qe(t, e = "") {
2442
- return f.nonEmptyArray(t) ? M(t, (r, n, i) => Jt(r, i === 0 ? "counter-clockwise" : "clockwise", n), e) : {
672
+ function re(e, t = "") {
673
+ return i.nonEmptyArray(e) ? h(e, (r, n, s) => Ye(r, s === 0 ? "counter-clockwise" : "clockwise", n), t) : {
2443
674
  valid: !1,
2444
- errors: [{ message: "Invalid Polygon: coordinates must be a non empty array", path: e }],
675
+ errors: [{ message: "Invalid Polygon: coordinates must be a non empty array", path: t }],
2445
676
  warnings: []
2446
677
  };
2447
678
  }
2448
- function Qt(t, e = "") {
2449
- return f.nonEmptyArray(t) ? M(t, (r, n) => qe(r, n), e) : {
679
+ function Be(e, t = "") {
680
+ return i.nonEmptyArray(e) ? h(e, (r, n) => re(r, n), t) : {
2450
681
  valid: !1,
2451
- errors: [{ message: "Invalid MultiPolygon: coordinates must be a non empty array", path: e }],
682
+ errors: [{ message: "Invalid MultiPolygon: coordinates must be a non empty array", path: t }],
2452
683
  warnings: []
2453
684
  };
2454
685
  }
2455
- function Xt(t, e = "") {
2456
- return f.nonEmptyArray(t) ? M(t, (r, n) => he(r, n), e) : {
686
+ function Xe(e, t = "") {
687
+ return i.nonEmptyArray(e) ? h(e, (r, n) => k(r, n), t) : {
2457
688
  valid: !1,
2458
- errors: [{ message: "Invalid geometries: geometries must be a non empty array", path: e }],
689
+ errors: [{ message: "Invalid geometries: geometries must be a non empty array", path: t }],
2459
690
  warnings: []
2460
691
  };
2461
692
  }
2462
- function he(t, e = "") {
2463
- if (!f.nonEmptyObject(t))
693
+ function k(e, t = "") {
694
+ if (!i.nonEmptyObject(e))
2464
695
  return {
2465
696
  valid: !1,
2466
- errors: [{ message: "Invalid geometry: geometry must be a non empty object", path: e }],
697
+ errors: [{ message: "Invalid geometry: geometry must be a non empty object", path: t }],
2467
698
  warnings: []
2468
699
  };
2469
- const r = `${e}/coordinates`;
700
+ const r = `${t}/coordinates`;
2470
701
  let n;
2471
- switch (t.type) {
2472
- case v.POINT: {
2473
- const i = j(t.coordinates);
702
+ switch (e.type) {
703
+ case f.POINT: {
704
+ const s = D(e.coordinates);
2474
705
  n = {
2475
- valid: i.valid,
2476
- errors: i.errors.map((a) => ({ ...a, path: r })),
2477
- warnings: i.warnings.map((a) => ({ ...a, path: r }))
706
+ valid: s.valid,
707
+ errors: s.errors.map((o) => ({ ...o, path: r })),
708
+ warnings: s.warnings.map((o) => ({ ...o, path: r }))
2478
709
  };
2479
710
  break;
2480
711
  }
2481
- case v.MULTI_POINT: {
2482
- n = ce(t.coordinates, 0, r);
712
+ case f.MULTI_POINT: {
713
+ n = F(e.coordinates, 0, r);
2483
714
  break;
2484
715
  }
2485
- case v.LINESTRING: {
2486
- n = He(t.coordinates, r);
716
+ case f.LINESTRING: {
717
+ n = ne(e.coordinates, r);
2487
718
  break;
2488
719
  }
2489
- case v.MULTI_LINESTRING: {
2490
- n = Yt(t.coordinates, r);
720
+ case f.MULTI_LINESTRING: {
721
+ n = je(e.coordinates, r);
2491
722
  break;
2492
723
  }
2493
- case v.POLYGON: {
2494
- n = qe(t.coordinates, r);
724
+ case f.POLYGON: {
725
+ n = re(e.coordinates, r);
2495
726
  break;
2496
727
  }
2497
- case v.MULTI_POLYGON: {
2498
- n = Qt(t.coordinates, r);
728
+ case f.MULTI_POLYGON: {
729
+ n = Be(e.coordinates, r);
2499
730
  break;
2500
731
  }
2501
- case v.GEOMETRY_COLLECTION: {
2502
- n = Xt(t.geometries, `${e}/geometries`);
732
+ case f.GEOMETRY_COLLECTION: {
733
+ n = Xe(e.geometries, `${t}/geometries`);
2503
734
  break;
2504
735
  }
2505
736
  default:
2506
737
  return {
2507
738
  valid: !1,
2508
- errors: [{ message: `Invalid geometry type: ${t.type}`, path: e }],
739
+ errors: [{ message: `Invalid geometry type: ${e.type}`, path: t }],
2509
740
  warnings: []
2510
741
  };
2511
742
  }
2512
- return ne(t, n, e);
743
+ return w(e, n, t);
2513
744
  }
2514
- function ze(t, e = "") {
2515
- if (!f.nonEmptyObject(t))
745
+ function ie(e, t = "") {
746
+ if (!i.nonEmptyObject(e))
2516
747
  return {
2517
748
  valid: !1,
2518
- errors: [{ message: "Invalid feature: must be a non empty object", path: e }],
749
+ errors: [{ message: "Invalid feature: must be a non empty object", path: t }],
2519
750
  warnings: [],
2520
- statistics: $()
751
+ statistics: y()
2521
752
  };
2522
- if (t.type === I.FEATURE) {
2523
- if (f.nonEmptyObject(t.geometry)) {
2524
- const r = he(t.geometry, `${e}/geometry`);
753
+ if (e.type === v.FEATURE) {
754
+ if (i.nonEmptyObject(e.geometry)) {
755
+ const r = k(e.geometry, `${t}/geometry`);
2525
756
  return {
2526
- ...ne(t, r, e),
757
+ ...w(e, r, t),
2527
758
  statistics: {
2528
759
  Feature: 1,
2529
760
  FeatureCollection: 0,
2530
- geometries: { [t.geometry.type]: 1 }
761
+ geometries: { [e.geometry.type]: 1 }
2531
762
  }
2532
763
  };
2533
764
  }
2534
765
  return {
2535
766
  valid: !0,
2536
767
  errors: [],
2537
- warnings: [{ message: "Feature has no geometry", path: e }],
768
+ warnings: [{ message: "Feature has no geometry", path: t }],
2538
769
  statistics: { Feature: 1, FeatureCollection: 0, geometries: {} }
2539
770
  };
2540
771
  }
2541
- if (t.type === I.FEATURE_COLLECTION) {
2542
- if (f.nonEmptyArray(t.features)) {
2543
- const r = M(t.features, ze, `${e}/features`);
772
+ if (e.type === v.FEATURE_COLLECTION) {
773
+ if (i.nonEmptyArray(e.features)) {
774
+ const r = h(e.features, ie, `${t}/features`);
2544
775
  return {
2545
- ...ne(t, r, e),
776
+ ...w(e, r, t),
2546
777
  statistics: { ...r.statistics, FeatureCollection: r.statistics.FeatureCollection + 1 }
2547
778
  };
2548
779
  }
2549
780
  return {
2550
781
  valid: !1,
2551
- errors: [{ message: "Invalid FeatureCollection: features must be a non empty array", path: e }],
782
+ errors: [{ message: "Invalid FeatureCollection: features must be a non empty array", path: t }],
2552
783
  warnings: [],
2553
- statistics: $()
784
+ statistics: y()
2554
785
  };
2555
786
  }
2556
787
  return {
2557
788
  valid: !1,
2558
- errors: [{ message: `Invalid feature: unknown type: ${t.type}`, path: e }],
789
+ errors: [{ message: `Invalid feature: unknown type: ${e.type}`, path: t }],
2559
790
  warnings: [],
2560
- statistics: $()
791
+ statistics: y()
2561
792
  };
2562
793
  }
2563
- function vr(t) {
2564
- if (p.that(t, f.nonEmptyObject, "geojson must be a non empty object"), f.oneOf(t.type, Object.values(v)))
794
+ function Et(e) {
795
+ if (l.that(e, i.nonEmptyObject, "geojson must be a non empty object"), i.oneOf(e.type, Object.values(f)))
2565
796
  return {
2566
- ...he(t, ""),
2567
- statistics: { Feature: 0, FeatureCollection: 0, geometries: { [t.type]: 1 } }
797
+ ...k(e, ""),
798
+ statistics: { Feature: 0, FeatureCollection: 0, geometries: { [e.type]: 1 } }
2568
799
  };
2569
- if (t.type === I.FEATURE || t.type === I.FEATURE_COLLECTION) {
2570
- const e = ze(t, "");
2571
- return Zt(t, e);
800
+ if (e.type === v.FEATURE || e.type === v.FEATURE_COLLECTION) {
801
+ const t = ie(e, "");
802
+ return We(e, t);
2572
803
  }
2573
804
  return {
2574
805
  valid: !1,
2575
806
  errors: [{ message: "Invalid GeoJson: type must be either a Geometry, a Feature or a FeatureCollection" }],
2576
807
  warnings: [],
2577
- statistics: $()
808
+ statistics: y()
2578
809
  };
2579
810
  }
2580
811
  export {
2581
- w as AXES,
2582
- re as COORDINATE_FORMATS,
2583
- ht as COORDINATE_MODELS,
2584
- oe as COORDINATE_TRUNCATION_FACTORS,
2585
- z as CRS_TYPES,
2586
- I as FEATURE_TYPES,
2587
- v as GEOMETRY_TYPES,
2588
- hr as convertCoordinate,
2589
- de as getCoordinatePrecision,
2590
- Qe as getDirectionAxis,
2591
- ar as getDirections,
2592
- lr as getEast,
2593
- Ye as getLocale,
2594
- sr as getNorth,
2595
- or as getSouth,
2596
- ur as getWest,
2597
- ye as guessCoordinateAxis,
2598
- tr as isAltitude,
2599
- je as isAxis,
2600
- D as isDirection,
2601
- Te as isEast,
2602
- ee as isLatitude,
2603
- gt as isLikeBBox,
2604
- gr as isLikeCRS,
2605
- yt as isLikeFeature,
2606
- dt as isLikeFeatureCollection,
2607
- De as isLikeGeoJson,
2608
- le as isLikeGeometry,
2609
- mt as isLikePosition,
2610
- Se as isLongitude,
2611
- Je as isNorth,
2612
- Le as isSouth,
2613
- se as isWest,
2614
- rr as listLocales,
2615
- cr as normalizeCoordinate,
2616
- pt as parseCoordinate,
2617
- pr as parsePosition,
2618
- nr as registerLocale,
2619
- ir as setLocale,
2620
- yr as simplifyGeoJson,
2621
- fe as simplifyGeometry,
2622
- Pe as truncateBBox,
2623
- fr as truncateCoordinate,
2624
- dr as truncateGeoJson,
2625
- Ge as truncateGeometry,
2626
- mr as truncatePosition,
2627
- Ft as validateBBox,
2628
- Ht as validateCRS,
2629
- vr as validateGeoJson,
2630
- he as validateGeometry,
2631
- j as validatePosition
812
+ d as AXES,
813
+ C as COORDINATE_FORMATS,
814
+ we as COORDINATE_MODELS,
815
+ x as COORDINATE_TRUNCATION_FACTORS,
816
+ L as CRS_TYPES,
817
+ v as FEATURE_TYPES,
818
+ f as GEOMETRY_TYPES,
819
+ gt as convertCoordinate,
820
+ W as getCoordinatePrecision,
821
+ Ee as getDirectionAxis,
822
+ it as getDirections,
823
+ ot as getEast,
824
+ pe as getLocale,
825
+ st as getNorth,
826
+ at as getSouth,
827
+ lt as getWest,
828
+ V as guessCoordinateAxis,
829
+ et as isAltitude,
830
+ ue as isAxis,
831
+ E as isDirection,
832
+ X as isEast,
833
+ N as isLatitude,
834
+ $e as isLikeBBox,
835
+ mt as isLikeCRS,
836
+ _e as isLikeFeature,
837
+ xe as isLikeFeatureCollection,
838
+ Q as isLikeGeoJson,
839
+ G as isLikeGeometry,
840
+ Ge as isLikePosition,
841
+ Y as isLongitude,
842
+ ve as isNorth,
843
+ B as isSouth,
844
+ _ as isWest,
845
+ tt as listLocales,
846
+ ct as normalizeCoordinate,
847
+ Me as parseCoordinate,
848
+ ft as parsePosition,
849
+ nt as registerLocale,
850
+ rt as setLocale,
851
+ dt as simplifyGeoJson,
852
+ U as simplifyGeometry,
853
+ J as truncateBBox,
854
+ ut as truncateCoordinate,
855
+ pt as truncateGeoJson,
856
+ ee as truncateGeometry,
857
+ vt as truncatePosition,
858
+ Pe as validateBBox,
859
+ He as validateCRS,
860
+ Et as validateGeoJson,
861
+ k as validateGeometry,
862
+ D as validatePosition
2632
863
  };
2633
864
  //# sourceMappingURL=index.mjs.map