@kerros/schema 0.0.0-stage → 0.1.0-rc.2

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.js ADDED
@@ -0,0 +1,3735 @@
1
+ var _n = Object.defineProperty;
2
+ var Rn = (e, t, n) => t in e ? _n(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var re = (e, t, n) => Rn(e, typeof t != "symbol" ? t + "" : t, n);
4
+ class dt {
5
+ constructor(t, n) {
6
+ this.next = null, this.key = t, this.data = n, this.left = null, this.right = null;
7
+ }
8
+ }
9
+ function Pn(e, t) {
10
+ return e > t ? 1 : e < t ? -1 : 0;
11
+ }
12
+ function it(e, t, n) {
13
+ const s = new dt(null, null);
14
+ let o = s, i = s;
15
+ for (; ; ) {
16
+ const a = n(e, t.key);
17
+ if (a < 0) {
18
+ if (t.left === null) break;
19
+ if (n(e, t.left.key) < 0) {
20
+ const r = t.left;
21
+ if (t.left = r.right, r.right = t, t = r, t.left === null) break;
22
+ }
23
+ i.left = t, i = t, t = t.left;
24
+ } else if (a > 0) {
25
+ if (t.right === null) break;
26
+ if (n(e, t.right.key) > 0) {
27
+ const r = t.right;
28
+ if (t.right = r.left, r.left = t, t = r, t.right === null) break;
29
+ }
30
+ o.right = t, o = t, t = t.right;
31
+ } else break;
32
+ }
33
+ return o.right = t.left, i.left = t.right, t.left = s.right, t.right = s.left, t;
34
+ }
35
+ function ae(e, t, n, s) {
36
+ const o = new dt(e, t);
37
+ if (n === null)
38
+ return o.left = o.right = null, o;
39
+ n = it(e, n, s);
40
+ const i = s(e, n.key);
41
+ return i < 0 ? (o.left = n.left, o.right = n, n.left = null) : i >= 0 && (o.right = n.right, o.left = n, n.right = null), o;
42
+ }
43
+ function Ne(e, t, n) {
44
+ let s = null, o = null;
45
+ if (t) {
46
+ t = it(e, t, n);
47
+ const i = n(t.key, e);
48
+ i === 0 ? (s = t.left, o = t.right) : i < 0 ? (o = t.right, t.right = null, s = t) : (s = t.left, t.left = null, o = t);
49
+ }
50
+ return { left: s, right: o };
51
+ }
52
+ function $n(e, t, n) {
53
+ return t === null ? e : (e === null || (t = it(e.key, t, n), t.left = e), t);
54
+ }
55
+ function ge(e, t, n, s, o) {
56
+ if (e) {
57
+ s(`${t}${n ? "└── " : "├── "}${o(e)}
58
+ `);
59
+ const i = t + (n ? " " : "│ ");
60
+ e.left && ge(e.left, i, !1, s, o), e.right && ge(e.right, i, !0, s, o);
61
+ }
62
+ }
63
+ class Ee {
64
+ constructor(t = Pn) {
65
+ this._root = null, this._size = 0, this._comparator = t;
66
+ }
67
+ /**
68
+ * Inserts a key, allows duplicates
69
+ */
70
+ insert(t, n) {
71
+ return this._size++, this._root = ae(t, n, this._root, this._comparator);
72
+ }
73
+ /**
74
+ * Adds a key, if it is not present in the tree
75
+ */
76
+ add(t, n) {
77
+ const s = new dt(t, n);
78
+ this._root === null && (s.left = s.right = null, this._size++, this._root = s);
79
+ const o = this._comparator, i = it(t, this._root, o), a = o(t, i.key);
80
+ return a === 0 ? this._root = i : (a < 0 ? (s.left = i.left, s.right = i, i.left = null) : a > 0 && (s.right = i.right, s.left = i, i.right = null), this._size++, this._root = s), this._root;
81
+ }
82
+ /**
83
+ * @param {Key} key
84
+ * @return {Node|null}
85
+ */
86
+ remove(t) {
87
+ this._root = this._remove(t, this._root, this._comparator);
88
+ }
89
+ /**
90
+ * Deletes i from the tree if it's there
91
+ */
92
+ _remove(t, n, s) {
93
+ let o;
94
+ return n === null ? null : (n = it(t, n, s), s(t, n.key) === 0 ? (n.left === null ? o = n.right : (o = it(t, n.left, s), o.right = n.right), this._size--, o) : n);
95
+ }
96
+ /**
97
+ * Removes and returns the node with smallest key
98
+ */
99
+ pop() {
100
+ let t = this._root;
101
+ if (t) {
102
+ for (; t.left; ) t = t.left;
103
+ return this._root = it(t.key, this._root, this._comparator), this._root = this._remove(t.key, this._root, this._comparator), { key: t.key, data: t.data };
104
+ }
105
+ return null;
106
+ }
107
+ /**
108
+ * Find without splaying
109
+ */
110
+ findStatic(t) {
111
+ let n = this._root;
112
+ const s = this._comparator;
113
+ for (; n; ) {
114
+ const o = s(t, n.key);
115
+ if (o === 0) return n;
116
+ o < 0 ? n = n.left : n = n.right;
117
+ }
118
+ return null;
119
+ }
120
+ find(t) {
121
+ return this._root && (this._root = it(t, this._root, this._comparator), this._comparator(t, this._root.key) !== 0) ? null : this._root;
122
+ }
123
+ contains(t) {
124
+ let n = this._root;
125
+ const s = this._comparator;
126
+ for (; n; ) {
127
+ const o = s(t, n.key);
128
+ if (o === 0) return !0;
129
+ o < 0 ? n = n.left : n = n.right;
130
+ }
131
+ return !1;
132
+ }
133
+ forEach(t, n) {
134
+ let s = this._root;
135
+ const o = [];
136
+ let i = !1;
137
+ for (; !i; )
138
+ s !== null ? (o.push(s), s = s.left) : o.length !== 0 ? (s = o.pop(), t.call(n, s), s = s.right) : i = !0;
139
+ return this;
140
+ }
141
+ /**
142
+ * Walk key range from `low` to `high`. Stops if `fn` returns a value.
143
+ */
144
+ range(t, n, s, o) {
145
+ const i = [], a = this._comparator;
146
+ let r = this._root, l;
147
+ for (; i.length !== 0 || r; )
148
+ if (r)
149
+ i.push(r), r = r.left;
150
+ else {
151
+ if (r = i.pop(), l = a(r.key, n), l > 0)
152
+ break;
153
+ if (a(r.key, t) >= 0 && s.call(o, r))
154
+ return this;
155
+ r = r.right;
156
+ }
157
+ return this;
158
+ }
159
+ /**
160
+ * Returns array of keys
161
+ */
162
+ keys() {
163
+ const t = [];
164
+ return this.forEach(({ key: n }) => {
165
+ t.push(n);
166
+ }), t;
167
+ }
168
+ /**
169
+ * Returns array of all the data in the nodes
170
+ */
171
+ values() {
172
+ const t = [];
173
+ return this.forEach(({ data: n }) => {
174
+ t.push(n);
175
+ }), t;
176
+ }
177
+ min() {
178
+ return this._root ? this.minNode(this._root).key : null;
179
+ }
180
+ max() {
181
+ return this._root ? this.maxNode(this._root).key : null;
182
+ }
183
+ minNode(t = this._root) {
184
+ if (t) for (; t.left; ) t = t.left;
185
+ return t;
186
+ }
187
+ maxNode(t = this._root) {
188
+ if (t) for (; t.right; ) t = t.right;
189
+ return t;
190
+ }
191
+ /**
192
+ * Returns node at given index
193
+ */
194
+ at(t) {
195
+ let n = this._root, s = !1, o = 0;
196
+ const i = [];
197
+ for (; !s; )
198
+ if (n)
199
+ i.push(n), n = n.left;
200
+ else if (i.length > 0) {
201
+ if (n = i.pop(), o === t) return n;
202
+ o++, n = n.right;
203
+ } else s = !0;
204
+ return null;
205
+ }
206
+ next(t) {
207
+ let n = this._root, s = null;
208
+ if (t.right) {
209
+ for (s = t.right; s.left; ) s = s.left;
210
+ return s;
211
+ }
212
+ const o = this._comparator;
213
+ for (; n; ) {
214
+ const i = o(t.key, n.key);
215
+ if (i === 0) break;
216
+ i < 0 ? (s = n, n = n.left) : n = n.right;
217
+ }
218
+ return s;
219
+ }
220
+ prev(t) {
221
+ let n = this._root, s = null;
222
+ if (t.left !== null) {
223
+ for (s = t.left; s.right; ) s = s.right;
224
+ return s;
225
+ }
226
+ const o = this._comparator;
227
+ for (; n; ) {
228
+ const i = o(t.key, n.key);
229
+ if (i === 0) break;
230
+ i < 0 ? n = n.left : (s = n, n = n.right);
231
+ }
232
+ return s;
233
+ }
234
+ clear() {
235
+ return this._root = null, this._size = 0, this;
236
+ }
237
+ toList() {
238
+ return On(this._root);
239
+ }
240
+ /**
241
+ * Bulk-load items. Both array have to be same size
242
+ */
243
+ load(t, n = [], s = !1) {
244
+ let o = t.length;
245
+ const i = this._comparator;
246
+ if (s && Ie(t, n, 0, o - 1, i), this._root === null)
247
+ this._root = me(t, n, 0, o), this._size = o;
248
+ else {
249
+ const a = Bn(
250
+ this.toList(),
251
+ Nn(t, n),
252
+ i
253
+ );
254
+ o = this._size + o, this._root = pe({ head: a }, 0, o);
255
+ }
256
+ return this;
257
+ }
258
+ isEmpty() {
259
+ return this._root === null;
260
+ }
261
+ get size() {
262
+ return this._size;
263
+ }
264
+ get root() {
265
+ return this._root;
266
+ }
267
+ toString(t = (n) => String(n.key)) {
268
+ const n = [];
269
+ return ge(this._root, "", !0, (s) => n.push(s), t), n.join("");
270
+ }
271
+ update(t, n, s) {
272
+ const o = this._comparator;
273
+ let { left: i, right: a } = Ne(t, this._root, o);
274
+ o(t, n) < 0 ? a = ae(n, s, a, o) : i = ae(n, s, i, o), this._root = $n(i, a, o);
275
+ }
276
+ split(t) {
277
+ return Ne(t, this._root, this._comparator);
278
+ }
279
+ *[Symbol.iterator]() {
280
+ let t = this._root;
281
+ const n = [];
282
+ let s = !1;
283
+ for (; !s; )
284
+ t !== null ? (n.push(t), t = t.left) : n.length !== 0 ? (t = n.pop(), yield t, t = t.right) : s = !0;
285
+ }
286
+ }
287
+ function me(e, t, n, s) {
288
+ const o = s - n;
289
+ if (o > 0) {
290
+ const i = n + Math.floor(o / 2), a = e[i], r = t[i], l = new dt(a, r);
291
+ return l.left = me(e, t, n, i), l.right = me(e, t, i + 1, s), l;
292
+ }
293
+ return null;
294
+ }
295
+ function Nn(e, t) {
296
+ const n = new dt(null, null);
297
+ let s = n;
298
+ for (let o = 0; o < e.length; o++)
299
+ s = s.next = new dt(e[o], t[o]);
300
+ return s.next = null, n.next;
301
+ }
302
+ function On(e) {
303
+ let t = e;
304
+ const n = [];
305
+ let s = !1;
306
+ const o = new dt(null, null);
307
+ let i = o;
308
+ for (; !s; )
309
+ t ? (n.push(t), t = t.left) : n.length > 0 ? (t = i = i.next = n.pop(), t = t.right) : s = !0;
310
+ return i.next = null, o.next;
311
+ }
312
+ function pe(e, t, n) {
313
+ const s = n - t;
314
+ if (s > 0) {
315
+ const o = t + Math.floor(s / 2), i = pe(e, t, o), a = e.head;
316
+ return a.left = i, e.head = e.head.next, a.right = pe(e, o + 1, n), a;
317
+ }
318
+ return null;
319
+ }
320
+ function Bn(e, t, n) {
321
+ const s = new dt(null, null);
322
+ let o = s, i = e, a = t;
323
+ for (; i !== null && a !== null; )
324
+ n(i.key, a.key) < 0 ? (o.next = i, i = i.next) : (o.next = a, a = a.next), o = o.next;
325
+ return i !== null ? o.next = i : a !== null && (o.next = a), s.next;
326
+ }
327
+ function Ie(e, t, n, s, o) {
328
+ if (n >= s) return;
329
+ const i = e[n + s >> 1];
330
+ let a = n - 1, r = s + 1;
331
+ for (; ; ) {
332
+ do
333
+ a++;
334
+ while (o(e[a], i) < 0);
335
+ do
336
+ r--;
337
+ while (o(e[r], i) > 0);
338
+ if (a >= r) break;
339
+ let l = e[a];
340
+ e[a] = e[r], e[r] = l, l = t[a], t[a] = t[r], t[r] = l;
341
+ }
342
+ Ie(e, t, n, r, o), Ie(e, t, r + 1, s, o);
343
+ }
344
+ const ot = 11102230246251565e-32, j = 134217729, zn = (3 + 8 * ot) * ot;
345
+ function le(e, t, n, s, o) {
346
+ let i, a, r, l, d = t[0], u = s[0], c = 0, f = 0;
347
+ u > d == u > -d ? (i = d, d = t[++c]) : (i = u, u = s[++f]);
348
+ let h = 0;
349
+ if (c < e && f < n)
350
+ for (u > d == u > -d ? (a = d + i, r = i - (a - d), d = t[++c]) : (a = u + i, r = i - (a - u), u = s[++f]), i = a, r !== 0 && (o[h++] = r); c < e && f < n; )
351
+ u > d == u > -d ? (a = i + d, l = a - i, r = i - (a - l) + (d - l), d = t[++c]) : (a = i + u, l = a - i, r = i - (a - l) + (u - l), u = s[++f]), i = a, r !== 0 && (o[h++] = r);
352
+ for (; c < e; )
353
+ a = i + d, l = a - i, r = i - (a - l) + (d - l), d = t[++c], i = a, r !== 0 && (o[h++] = r);
354
+ for (; f < n; )
355
+ a = i + u, l = a - i, r = i - (a - l) + (u - l), u = s[++f], i = a, r !== 0 && (o[h++] = r);
356
+ return (i !== 0 || h === 0) && (o[h++] = i), h;
357
+ }
358
+ function Fn(e, t) {
359
+ let n = t[0];
360
+ for (let s = 1; s < e; s++) n += t[s];
361
+ return n;
362
+ }
363
+ function Gt(e) {
364
+ return new Float64Array(e);
365
+ }
366
+ const Tn = (3 + 16 * ot) * ot, Cn = (2 + 12 * ot) * ot, Ln = (9 + 64 * ot) * ot * ot, Et = Gt(4), Oe = Gt(8), Be = Gt(12), ze = Gt(16), q = Gt(4);
367
+ function Gn(e, t, n, s, o, i, a) {
368
+ let r, l, d, u, c, f, h, p, m, I, b, w, g, y, M, _, $, x;
369
+ const E = e - o, A = n - o, v = t - i, k = s - i;
370
+ y = E * k, f = j * E, h = f - (f - E), p = E - h, f = j * k, m = f - (f - k), I = k - m, M = p * I - (y - h * m - p * m - h * I), _ = v * A, f = j * v, h = f - (f - v), p = v - h, f = j * A, m = f - (f - A), I = A - m, $ = p * I - (_ - h * m - p * m - h * I), b = M - $, c = M - b, Et[0] = M - (b + c) + (c - $), w = y + b, c = w - y, g = y - (w - c) + (b - c), b = g - _, c = g - b, Et[1] = g - (b + c) + (c - _), x = w + b, c = x - w, Et[2] = w - (x - c) + (b - c), Et[3] = x;
371
+ let R = Fn(4, Et), P = Cn * a;
372
+ if (R >= P || -R >= P || (c = e - E, r = e - (E + c) + (c - o), c = n - A, d = n - (A + c) + (c - o), c = t - v, l = t - (v + c) + (c - i), c = s - k, u = s - (k + c) + (c - i), r === 0 && l === 0 && d === 0 && u === 0) || (P = Ln * a + zn * Math.abs(R), R += E * u + k * r - (v * d + A * l), R >= P || -R >= P)) return R;
373
+ y = r * k, f = j * r, h = f - (f - r), p = r - h, f = j * k, m = f - (f - k), I = k - m, M = p * I - (y - h * m - p * m - h * I), _ = l * A, f = j * l, h = f - (f - l), p = l - h, f = j * A, m = f - (f - A), I = A - m, $ = p * I - (_ - h * m - p * m - h * I), b = M - $, c = M - b, q[0] = M - (b + c) + (c - $), w = y + b, c = w - y, g = y - (w - c) + (b - c), b = g - _, c = g - b, q[1] = g - (b + c) + (c - _), x = w + b, c = x - w, q[2] = w - (x - c) + (b - c), q[3] = x;
374
+ const O = le(4, Et, 4, q, Oe);
375
+ y = E * u, f = j * E, h = f - (f - E), p = E - h, f = j * u, m = f - (f - u), I = u - m, M = p * I - (y - h * m - p * m - h * I), _ = v * d, f = j * v, h = f - (f - v), p = v - h, f = j * d, m = f - (f - d), I = d - m, $ = p * I - (_ - h * m - p * m - h * I), b = M - $, c = M - b, q[0] = M - (b + c) + (c - $), w = y + b, c = w - y, g = y - (w - c) + (b - c), b = g - _, c = g - b, q[1] = g - (b + c) + (c - _), x = w + b, c = x - w, q[2] = w - (x - c) + (b - c), q[3] = x;
376
+ const z = le(O, Oe, 4, q, Be);
377
+ y = r * u, f = j * r, h = f - (f - r), p = r - h, f = j * u, m = f - (f - u), I = u - m, M = p * I - (y - h * m - p * m - h * I), _ = l * d, f = j * l, h = f - (f - l), p = l - h, f = j * d, m = f - (f - d), I = d - m, $ = p * I - (_ - h * m - p * m - h * I), b = M - $, c = M - b, q[0] = M - (b + c) + (c - $), w = y + b, c = w - y, g = y - (w - c) + (b - c), b = g - _, c = g - b, q[1] = g - (b + c) + (c - _), x = w + b, c = x - w, q[2] = w - (x - c) + (b - c), q[3] = x;
378
+ const F = le(z, Be, 4, q, ze);
379
+ return ze[F - 1];
380
+ }
381
+ function Dn(e, t, n, s, o, i) {
382
+ const a = (t - i) * (n - o), r = (e - o) * (s - i), l = a - r, d = Math.abs(a + r);
383
+ return Math.abs(l) >= Tn * d ? l : -Gn(e, t, n, s, o, i, d);
384
+ }
385
+ const Pt = (e, t) => e.ll.x <= t.x && t.x <= e.ur.x && e.ll.y <= t.y && t.y <= e.ur.y, be = (e, t) => {
386
+ if (t.ur.x < e.ll.x || e.ur.x < t.ll.x || t.ur.y < e.ll.y || e.ur.y < t.ll.y) return null;
387
+ const n = e.ll.x < t.ll.x ? t.ll.x : e.ll.x, s = e.ur.x < t.ur.x ? e.ur.x : t.ur.x, o = e.ll.y < t.ll.y ? t.ll.y : e.ll.y, i = e.ur.y < t.ur.y ? e.ur.y : t.ur.y;
388
+ return {
389
+ ll: {
390
+ x: n,
391
+ y: o
392
+ },
393
+ ur: {
394
+ x: s,
395
+ y: i
396
+ }
397
+ };
398
+ };
399
+ let rt = Number.EPSILON;
400
+ rt === void 0 && (rt = Math.pow(2, -52));
401
+ const Un = rt * rt, Fe = (e, t) => {
402
+ if (-rt < e && e < rt && -rt < t && t < rt)
403
+ return 0;
404
+ const n = e - t;
405
+ return n * n < Un * e * t ? 0 : e < t ? -1 : 1;
406
+ };
407
+ class Zn {
408
+ constructor() {
409
+ this.reset();
410
+ }
411
+ reset() {
412
+ this.xRounder = new Te(), this.yRounder = new Te();
413
+ }
414
+ round(t, n) {
415
+ return {
416
+ x: this.xRounder.round(t),
417
+ y: this.yRounder.round(n)
418
+ };
419
+ }
420
+ }
421
+ class Te {
422
+ constructor() {
423
+ this.tree = new Ee(), this.round(0);
424
+ }
425
+ // Note: this can rounds input values backwards or forwards.
426
+ // You might ask, why not restrict this to just rounding
427
+ // forwards? Wouldn't that allow left endpoints to always
428
+ // remain left endpoints during splitting (never change to
429
+ // right). No - it wouldn't, because we snap intersections
430
+ // to endpoints (to establish independence from the segment
431
+ // angle for t-intersections).
432
+ round(t) {
433
+ const n = this.tree.add(t), s = this.tree.prev(n);
434
+ if (s !== null && Fe(n.key, s.key) === 0)
435
+ return this.tree.remove(t), s.key;
436
+ const o = this.tree.next(n);
437
+ return o !== null && Fe(n.key, o.key) === 0 ? (this.tree.remove(t), o.key) : t;
438
+ }
439
+ }
440
+ const Bt = new Zn(), Yt = (e, t) => e.x * t.y - e.y * t.x, en = (e, t) => e.x * t.x + e.y * t.y, Ce = (e, t, n) => {
441
+ const s = Dn(e.x, e.y, t.x, t.y, n.x, n.y);
442
+ return s > 0 ? -1 : s < 0 ? 1 : 0;
443
+ }, Jt = (e) => Math.sqrt(en(e, e)), Hn = (e, t, n) => {
444
+ const s = {
445
+ x: t.x - e.x,
446
+ y: t.y - e.y
447
+ }, o = {
448
+ x: n.x - e.x,
449
+ y: n.y - e.y
450
+ };
451
+ return Yt(o, s) / Jt(o) / Jt(s);
452
+ }, Wn = (e, t, n) => {
453
+ const s = {
454
+ x: t.x - e.x,
455
+ y: t.y - e.y
456
+ }, o = {
457
+ x: n.x - e.x,
458
+ y: n.y - e.y
459
+ };
460
+ return en(o, s) / Jt(o) / Jt(s);
461
+ }, Le = (e, t, n) => t.y === 0 ? null : {
462
+ x: e.x + t.x / t.y * (n - e.y),
463
+ y: n
464
+ }, Ge = (e, t, n) => t.x === 0 ? null : {
465
+ x: n,
466
+ y: e.y + t.y / t.x * (n - e.x)
467
+ }, jn = (e, t, n, s) => {
468
+ if (t.x === 0) return Ge(n, s, e.x);
469
+ if (s.x === 0) return Ge(e, t, n.x);
470
+ if (t.y === 0) return Le(n, s, e.y);
471
+ if (s.y === 0) return Le(e, t, n.y);
472
+ const o = Yt(t, s);
473
+ if (o == 0) return null;
474
+ const i = {
475
+ x: n.x - e.x,
476
+ y: n.y - e.y
477
+ }, a = Yt(i, t) / o, r = Yt(i, s) / o, l = e.x + r * t.x, d = n.x + a * s.x, u = e.y + r * t.y, c = n.y + a * s.y, f = (l + d) / 2, h = (u + c) / 2;
478
+ return {
479
+ x: f,
480
+ y: h
481
+ };
482
+ };
483
+ class J {
484
+ // for ordering sweep events in the sweep event queue
485
+ static compare(t, n) {
486
+ const s = J.comparePoints(t.point, n.point);
487
+ return s !== 0 ? s : (t.point !== n.point && t.link(n), t.isLeft !== n.isLeft ? t.isLeft ? 1 : -1 : lt.compare(t.segment, n.segment));
488
+ }
489
+ // for ordering points in sweep line order
490
+ static comparePoints(t, n) {
491
+ return t.x < n.x ? -1 : t.x > n.x ? 1 : t.y < n.y ? -1 : t.y > n.y ? 1 : 0;
492
+ }
493
+ // Warning: 'point' input will be modified and re-used (for performance)
494
+ constructor(t, n) {
495
+ t.events === void 0 ? t.events = [this] : t.events.push(this), this.point = t, this.isLeft = n;
496
+ }
497
+ link(t) {
498
+ if (t.point === this.point)
499
+ throw new Error("Tried to link already linked events");
500
+ const n = t.point.events;
501
+ for (let s = 0, o = n.length; s < o; s++) {
502
+ const i = n[s];
503
+ this.point.events.push(i), i.point = this.point;
504
+ }
505
+ this.checkForConsuming();
506
+ }
507
+ /* Do a pass over our linked events and check to see if any pair
508
+ * of segments match, and should be consumed. */
509
+ checkForConsuming() {
510
+ const t = this.point.events.length;
511
+ for (let n = 0; n < t; n++) {
512
+ const s = this.point.events[n];
513
+ if (s.segment.consumedBy === void 0)
514
+ for (let o = n + 1; o < t; o++) {
515
+ const i = this.point.events[o];
516
+ i.consumedBy === void 0 && s.otherSE.point.events === i.otherSE.point.events && s.segment.consume(i.segment);
517
+ }
518
+ }
519
+ }
520
+ getAvailableLinkedEvents() {
521
+ const t = [];
522
+ for (let n = 0, s = this.point.events.length; n < s; n++) {
523
+ const o = this.point.events[n];
524
+ o !== this && !o.segment.ringOut && o.segment.isInResult() && t.push(o);
525
+ }
526
+ return t;
527
+ }
528
+ /**
529
+ * Returns a comparator function for sorting linked events that will
530
+ * favor the event that will give us the smallest left-side angle.
531
+ * All ring construction starts as low as possible heading to the right,
532
+ * so by always turning left as sharp as possible we'll get polygons
533
+ * without uncessary loops & holes.
534
+ *
535
+ * The comparator function has a compute cache such that it avoids
536
+ * re-computing already-computed values.
537
+ */
538
+ getLeftmostComparator(t) {
539
+ const n = /* @__PURE__ */ new Map(), s = (o) => {
540
+ const i = o.otherSE;
541
+ n.set(o, {
542
+ sine: Hn(this.point, t.point, i.point),
543
+ cosine: Wn(this.point, t.point, i.point)
544
+ });
545
+ };
546
+ return (o, i) => {
547
+ n.has(o) || s(o), n.has(i) || s(i);
548
+ const {
549
+ sine: a,
550
+ cosine: r
551
+ } = n.get(o), {
552
+ sine: l,
553
+ cosine: d
554
+ } = n.get(i);
555
+ return a >= 0 && l >= 0 ? r < d ? 1 : r > d ? -1 : 0 : a < 0 && l < 0 ? r < d ? -1 : r > d ? 1 : 0 : l < a ? -1 : l > a ? 1 : 0;
556
+ };
557
+ }
558
+ }
559
+ let Yn = 0;
560
+ class lt {
561
+ /* This compare() function is for ordering segments in the sweep
562
+ * line tree, and does so according to the following criteria:
563
+ *
564
+ * Consider the vertical line that lies an infinestimal step to the
565
+ * right of the right-more of the two left endpoints of the input
566
+ * segments. Imagine slowly moving a point up from negative infinity
567
+ * in the increasing y direction. Which of the two segments will that
568
+ * point intersect first? That segment comes 'before' the other one.
569
+ *
570
+ * If neither segment would be intersected by such a line, (if one
571
+ * or more of the segments are vertical) then the line to be considered
572
+ * is directly on the right-more of the two left inputs.
573
+ */
574
+ static compare(t, n) {
575
+ const s = t.leftSE.point.x, o = n.leftSE.point.x, i = t.rightSE.point.x, a = n.rightSE.point.x;
576
+ if (a < s) return 1;
577
+ if (i < o) return -1;
578
+ const r = t.leftSE.point.y, l = n.leftSE.point.y, d = t.rightSE.point.y, u = n.rightSE.point.y;
579
+ if (s < o) {
580
+ if (l < r && l < d) return 1;
581
+ if (l > r && l > d) return -1;
582
+ const c = t.comparePoint(n.leftSE.point);
583
+ if (c < 0) return 1;
584
+ if (c > 0) return -1;
585
+ const f = n.comparePoint(t.rightSE.point);
586
+ return f !== 0 ? f : -1;
587
+ }
588
+ if (s > o) {
589
+ if (r < l && r < u) return -1;
590
+ if (r > l && r > u) return 1;
591
+ const c = n.comparePoint(t.leftSE.point);
592
+ if (c !== 0) return c;
593
+ const f = t.comparePoint(n.rightSE.point);
594
+ return f < 0 ? 1 : f > 0 ? -1 : 1;
595
+ }
596
+ if (r < l) return -1;
597
+ if (r > l) return 1;
598
+ if (i < a) {
599
+ const c = n.comparePoint(t.rightSE.point);
600
+ if (c !== 0) return c;
601
+ }
602
+ if (i > a) {
603
+ const c = t.comparePoint(n.rightSE.point);
604
+ if (c < 0) return 1;
605
+ if (c > 0) return -1;
606
+ }
607
+ if (i !== a) {
608
+ const c = d - r, f = i - s, h = u - l, p = a - o;
609
+ if (c > f && h < p) return 1;
610
+ if (c < f && h > p) return -1;
611
+ }
612
+ return i > a ? 1 : i < a || d < u ? -1 : d > u ? 1 : t.id < n.id ? -1 : t.id > n.id ? 1 : 0;
613
+ }
614
+ /* Warning: a reference to ringWindings input will be stored,
615
+ * and possibly will be later modified */
616
+ constructor(t, n, s, o) {
617
+ this.id = ++Yn, this.leftSE = t, t.segment = this, t.otherSE = n, this.rightSE = n, n.segment = this, n.otherSE = t, this.rings = s, this.windings = o;
618
+ }
619
+ static fromRing(t, n, s) {
620
+ let o, i, a;
621
+ const r = J.comparePoints(t, n);
622
+ if (r < 0)
623
+ o = t, i = n, a = 1;
624
+ else if (r > 0)
625
+ o = n, i = t, a = -1;
626
+ else throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);
627
+ const l = new J(o, !0), d = new J(i, !1);
628
+ return new lt(l, d, [s], [a]);
629
+ }
630
+ /* When a segment is split, the rightSE is replaced with a new sweep event */
631
+ replaceRightSE(t) {
632
+ this.rightSE = t, this.rightSE.segment = this, this.rightSE.otherSE = this.leftSE, this.leftSE.otherSE = this.rightSE;
633
+ }
634
+ bbox() {
635
+ const t = this.leftSE.point.y, n = this.rightSE.point.y;
636
+ return {
637
+ ll: {
638
+ x: this.leftSE.point.x,
639
+ y: t < n ? t : n
640
+ },
641
+ ur: {
642
+ x: this.rightSE.point.x,
643
+ y: t > n ? t : n
644
+ }
645
+ };
646
+ }
647
+ /* A vector from the left point to the right */
648
+ vector() {
649
+ return {
650
+ x: this.rightSE.point.x - this.leftSE.point.x,
651
+ y: this.rightSE.point.y - this.leftSE.point.y
652
+ };
653
+ }
654
+ isAnEndpoint(t) {
655
+ return t.x === this.leftSE.point.x && t.y === this.leftSE.point.y || t.x === this.rightSE.point.x && t.y === this.rightSE.point.y;
656
+ }
657
+ /* Compare this segment with a point.
658
+ *
659
+ * A point P is considered to be colinear to a segment if there
660
+ * exists a distance D such that if we travel along the segment
661
+ * from one * endpoint towards the other a distance D, we find
662
+ * ourselves at point P.
663
+ *
664
+ * Return value indicates:
665
+ *
666
+ * 1: point lies above the segment (to the left of vertical)
667
+ * 0: point is colinear to segment
668
+ * -1: point lies below the segment (to the right of vertical)
669
+ */
670
+ comparePoint(t) {
671
+ if (this.isAnEndpoint(t)) return 0;
672
+ const n = this.leftSE.point, s = this.rightSE.point, o = this.vector();
673
+ if (n.x === s.x)
674
+ return t.x === n.x ? 0 : t.x < n.x ? 1 : -1;
675
+ const i = (t.y - n.y) / o.y, a = n.x + i * o.x;
676
+ if (t.x === a) return 0;
677
+ const r = (t.x - n.x) / o.x, l = n.y + r * o.y;
678
+ return t.y === l ? 0 : t.y < l ? -1 : 1;
679
+ }
680
+ /**
681
+ * Given another segment, returns the first non-trivial intersection
682
+ * between the two segments (in terms of sweep line ordering), if it exists.
683
+ *
684
+ * A 'non-trivial' intersection is one that will cause one or both of the
685
+ * segments to be split(). As such, 'trivial' vs. 'non-trivial' intersection:
686
+ *
687
+ * * endpoint of segA with endpoint of segB --> trivial
688
+ * * endpoint of segA with point along segB --> non-trivial
689
+ * * endpoint of segB with point along segA --> non-trivial
690
+ * * point along segA with point along segB --> non-trivial
691
+ *
692
+ * If no non-trivial intersection exists, return null
693
+ * Else, return null.
694
+ */
695
+ getIntersection(t) {
696
+ const n = this.bbox(), s = t.bbox(), o = be(n, s);
697
+ if (o === null) return null;
698
+ const i = this.leftSE.point, a = this.rightSE.point, r = t.leftSE.point, l = t.rightSE.point, d = Pt(n, r) && this.comparePoint(r) === 0, u = Pt(s, i) && t.comparePoint(i) === 0, c = Pt(n, l) && this.comparePoint(l) === 0, f = Pt(s, a) && t.comparePoint(a) === 0;
699
+ if (u && d)
700
+ return f && !c ? a : !f && c ? l : null;
701
+ if (u)
702
+ return c && i.x === l.x && i.y === l.y ? null : i;
703
+ if (d)
704
+ return f && a.x === r.x && a.y === r.y ? null : r;
705
+ if (f && c) return null;
706
+ if (f) return a;
707
+ if (c) return l;
708
+ const h = jn(i, this.vector(), r, t.vector());
709
+ return h === null || !Pt(o, h) ? null : Bt.round(h.x, h.y);
710
+ }
711
+ /**
712
+ * Split the given segment into multiple segments on the given points.
713
+ * * Each existing segment will retain its leftSE and a new rightSE will be
714
+ * generated for it.
715
+ * * A new segment will be generated which will adopt the original segment's
716
+ * rightSE, and a new leftSE will be generated for it.
717
+ * * If there are more than two points given to split on, new segments
718
+ * in the middle will be generated with new leftSE and rightSE's.
719
+ * * An array of the newly generated SweepEvents will be returned.
720
+ *
721
+ * Warning: input array of points is modified
722
+ */
723
+ split(t) {
724
+ const n = [], s = t.events !== void 0, o = new J(t, !0), i = new J(t, !1), a = this.rightSE;
725
+ this.replaceRightSE(i), n.push(i), n.push(o);
726
+ const r = new lt(o, a, this.rings.slice(), this.windings.slice());
727
+ return J.comparePoints(r.leftSE.point, r.rightSE.point) > 0 && r.swapEvents(), J.comparePoints(this.leftSE.point, this.rightSE.point) > 0 && this.swapEvents(), s && (o.checkForConsuming(), i.checkForConsuming()), n;
728
+ }
729
+ /* Swap which event is left and right */
730
+ swapEvents() {
731
+ const t = this.rightSE;
732
+ this.rightSE = this.leftSE, this.leftSE = t, this.leftSE.isLeft = !0, this.rightSE.isLeft = !1;
733
+ for (let n = 0, s = this.windings.length; n < s; n++)
734
+ this.windings[n] *= -1;
735
+ }
736
+ /* Consume another segment. We take their rings under our wing
737
+ * and mark them as consumed. Use for perfectly overlapping segments */
738
+ consume(t) {
739
+ let n = this, s = t;
740
+ for (; n.consumedBy; ) n = n.consumedBy;
741
+ for (; s.consumedBy; ) s = s.consumedBy;
742
+ const o = lt.compare(n, s);
743
+ if (o !== 0) {
744
+ if (o > 0) {
745
+ const i = n;
746
+ n = s, s = i;
747
+ }
748
+ if (n.prev === s) {
749
+ const i = n;
750
+ n = s, s = i;
751
+ }
752
+ for (let i = 0, a = s.rings.length; i < a; i++) {
753
+ const r = s.rings[i], l = s.windings[i], d = n.rings.indexOf(r);
754
+ d === -1 ? (n.rings.push(r), n.windings.push(l)) : n.windings[d] += l;
755
+ }
756
+ s.rings = null, s.windings = null, s.consumedBy = n, s.leftSE.consumedBy = n.leftSE, s.rightSE.consumedBy = n.rightSE;
757
+ }
758
+ }
759
+ /* The first segment previous segment chain that is in the result */
760
+ prevInResult() {
761
+ return this._prevInResult !== void 0 ? this._prevInResult : (this.prev ? this.prev.isInResult() ? this._prevInResult = this.prev : this._prevInResult = this.prev.prevInResult() : this._prevInResult = null, this._prevInResult);
762
+ }
763
+ beforeState() {
764
+ if (this._beforeState !== void 0) return this._beforeState;
765
+ if (!this.prev) this._beforeState = {
766
+ rings: [],
767
+ windings: [],
768
+ multiPolys: []
769
+ };
770
+ else {
771
+ const t = this.prev.consumedBy || this.prev;
772
+ this._beforeState = t.afterState();
773
+ }
774
+ return this._beforeState;
775
+ }
776
+ afterState() {
777
+ if (this._afterState !== void 0) return this._afterState;
778
+ const t = this.beforeState();
779
+ this._afterState = {
780
+ rings: t.rings.slice(0),
781
+ windings: t.windings.slice(0),
782
+ multiPolys: []
783
+ };
784
+ const n = this._afterState.rings, s = this._afterState.windings, o = this._afterState.multiPolys;
785
+ for (let r = 0, l = this.rings.length; r < l; r++) {
786
+ const d = this.rings[r], u = this.windings[r], c = n.indexOf(d);
787
+ c === -1 ? (n.push(d), s.push(u)) : s[c] += u;
788
+ }
789
+ const i = [], a = [];
790
+ for (let r = 0, l = n.length; r < l; r++) {
791
+ if (s[r] === 0) continue;
792
+ const d = n[r], u = d.poly;
793
+ if (a.indexOf(u) === -1)
794
+ if (d.isExterior) i.push(u);
795
+ else {
796
+ a.indexOf(u) === -1 && a.push(u);
797
+ const c = i.indexOf(d.poly);
798
+ c !== -1 && i.splice(c, 1);
799
+ }
800
+ }
801
+ for (let r = 0, l = i.length; r < l; r++) {
802
+ const d = i[r].multiPoly;
803
+ o.indexOf(d) === -1 && o.push(d);
804
+ }
805
+ return this._afterState;
806
+ }
807
+ /* Is this segment part of the final result? */
808
+ isInResult() {
809
+ if (this.consumedBy) return !1;
810
+ if (this._isInResult !== void 0) return this._isInResult;
811
+ const t = this.beforeState().multiPolys, n = this.afterState().multiPolys;
812
+ switch (K.type) {
813
+ case "union": {
814
+ const s = t.length === 0, o = n.length === 0;
815
+ this._isInResult = s !== o;
816
+ break;
817
+ }
818
+ case "intersection": {
819
+ let s, o;
820
+ t.length < n.length ? (s = t.length, o = n.length) : (s = n.length, o = t.length), this._isInResult = o === K.numMultiPolys && s < o;
821
+ break;
822
+ }
823
+ case "xor": {
824
+ const s = Math.abs(t.length - n.length);
825
+ this._isInResult = s % 2 === 1;
826
+ break;
827
+ }
828
+ case "difference": {
829
+ const s = (o) => o.length === 1 && o[0].isSubject;
830
+ this._isInResult = s(t) !== s(n);
831
+ break;
832
+ }
833
+ default:
834
+ throw new Error(`Unrecognized operation type found ${K.type}`);
835
+ }
836
+ return this._isInResult;
837
+ }
838
+ }
839
+ class De {
840
+ constructor(t, n, s) {
841
+ if (!Array.isArray(t) || t.length === 0)
842
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
843
+ if (this.poly = n, this.isExterior = s, this.segments = [], typeof t[0][0] != "number" || typeof t[0][1] != "number")
844
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
845
+ const o = Bt.round(t[0][0], t[0][1]);
846
+ this.bbox = {
847
+ ll: {
848
+ x: o.x,
849
+ y: o.y
850
+ },
851
+ ur: {
852
+ x: o.x,
853
+ y: o.y
854
+ }
855
+ };
856
+ let i = o;
857
+ for (let a = 1, r = t.length; a < r; a++) {
858
+ if (typeof t[a][0] != "number" || typeof t[a][1] != "number")
859
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
860
+ let l = Bt.round(t[a][0], t[a][1]);
861
+ l.x === i.x && l.y === i.y || (this.segments.push(lt.fromRing(i, l, this)), l.x < this.bbox.ll.x && (this.bbox.ll.x = l.x), l.y < this.bbox.ll.y && (this.bbox.ll.y = l.y), l.x > this.bbox.ur.x && (this.bbox.ur.x = l.x), l.y > this.bbox.ur.y && (this.bbox.ur.y = l.y), i = l);
862
+ }
863
+ (o.x !== i.x || o.y !== i.y) && this.segments.push(lt.fromRing(i, o, this));
864
+ }
865
+ getSweepEvents() {
866
+ const t = [];
867
+ for (let n = 0, s = this.segments.length; n < s; n++) {
868
+ const o = this.segments[n];
869
+ t.push(o.leftSE), t.push(o.rightSE);
870
+ }
871
+ return t;
872
+ }
873
+ }
874
+ class Vn {
875
+ constructor(t, n) {
876
+ if (!Array.isArray(t))
877
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
878
+ this.exteriorRing = new De(t[0], this, !0), this.bbox = {
879
+ ll: {
880
+ x: this.exteriorRing.bbox.ll.x,
881
+ y: this.exteriorRing.bbox.ll.y
882
+ },
883
+ ur: {
884
+ x: this.exteriorRing.bbox.ur.x,
885
+ y: this.exteriorRing.bbox.ur.y
886
+ }
887
+ }, this.interiorRings = [];
888
+ for (let s = 1, o = t.length; s < o; s++) {
889
+ const i = new De(t[s], this, !1);
890
+ i.bbox.ll.x < this.bbox.ll.x && (this.bbox.ll.x = i.bbox.ll.x), i.bbox.ll.y < this.bbox.ll.y && (this.bbox.ll.y = i.bbox.ll.y), i.bbox.ur.x > this.bbox.ur.x && (this.bbox.ur.x = i.bbox.ur.x), i.bbox.ur.y > this.bbox.ur.y && (this.bbox.ur.y = i.bbox.ur.y), this.interiorRings.push(i);
891
+ }
892
+ this.multiPoly = n;
893
+ }
894
+ getSweepEvents() {
895
+ const t = this.exteriorRing.getSweepEvents();
896
+ for (let n = 0, s = this.interiorRings.length; n < s; n++) {
897
+ const o = this.interiorRings[n].getSweepEvents();
898
+ for (let i = 0, a = o.length; i < a; i++)
899
+ t.push(o[i]);
900
+ }
901
+ return t;
902
+ }
903
+ }
904
+ class Ue {
905
+ constructor(t, n) {
906
+ if (!Array.isArray(t))
907
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
908
+ try {
909
+ typeof t[0][0][0] == "number" && (t = [t]);
910
+ } catch {
911
+ }
912
+ this.polys = [], this.bbox = {
913
+ ll: {
914
+ x: Number.POSITIVE_INFINITY,
915
+ y: Number.POSITIVE_INFINITY
916
+ },
917
+ ur: {
918
+ x: Number.NEGATIVE_INFINITY,
919
+ y: Number.NEGATIVE_INFINITY
920
+ }
921
+ };
922
+ for (let s = 0, o = t.length; s < o; s++) {
923
+ const i = new Vn(t[s], this);
924
+ i.bbox.ll.x < this.bbox.ll.x && (this.bbox.ll.x = i.bbox.ll.x), i.bbox.ll.y < this.bbox.ll.y && (this.bbox.ll.y = i.bbox.ll.y), i.bbox.ur.x > this.bbox.ur.x && (this.bbox.ur.x = i.bbox.ur.x), i.bbox.ur.y > this.bbox.ur.y && (this.bbox.ur.y = i.bbox.ur.y), this.polys.push(i);
925
+ }
926
+ this.isSubject = n;
927
+ }
928
+ getSweepEvents() {
929
+ const t = [];
930
+ for (let n = 0, s = this.polys.length; n < s; n++) {
931
+ const o = this.polys[n].getSweepEvents();
932
+ for (let i = 0, a = o.length; i < a; i++)
933
+ t.push(o[i]);
934
+ }
935
+ return t;
936
+ }
937
+ }
938
+ class Kt {
939
+ /* Given the segments from the sweep line pass, compute & return a series
940
+ * of closed rings from all the segments marked to be part of the result */
941
+ static factory(t) {
942
+ const n = [];
943
+ for (let s = 0, o = t.length; s < o; s++) {
944
+ const i = t[s];
945
+ if (!i.isInResult() || i.ringOut) continue;
946
+ let a = null, r = i.leftSE, l = i.rightSE;
947
+ const d = [r], u = r.point, c = [];
948
+ for (; a = r, r = l, d.push(r), r.point !== u; )
949
+ for (; ; ) {
950
+ const f = r.getAvailableLinkedEvents();
951
+ if (f.length === 0) {
952
+ const m = d[0].point, I = d[d.length - 1].point;
953
+ throw new Error(`Unable to complete output ring starting at [${m.x}, ${m.y}]. Last matching segment found ends at [${I.x}, ${I.y}].`);
954
+ }
955
+ if (f.length === 1) {
956
+ l = f[0].otherSE;
957
+ break;
958
+ }
959
+ let h = null;
960
+ for (let m = 0, I = c.length; m < I; m++)
961
+ if (c[m].point === r.point) {
962
+ h = m;
963
+ break;
964
+ }
965
+ if (h !== null) {
966
+ const m = c.splice(h)[0], I = d.splice(m.index);
967
+ I.unshift(I[0].otherSE), n.push(new Kt(I.reverse()));
968
+ continue;
969
+ }
970
+ c.push({
971
+ index: d.length,
972
+ point: r.point
973
+ });
974
+ const p = r.getLeftmostComparator(a);
975
+ l = f.sort(p)[0].otherSE;
976
+ break;
977
+ }
978
+ n.push(new Kt(d));
979
+ }
980
+ return n;
981
+ }
982
+ constructor(t) {
983
+ this.events = t;
984
+ for (let n = 0, s = t.length; n < s; n++)
985
+ t[n].segment.ringOut = this;
986
+ this.poly = null;
987
+ }
988
+ getGeom() {
989
+ let t = this.events[0].point;
990
+ const n = [t];
991
+ for (let d = 1, u = this.events.length - 1; d < u; d++) {
992
+ const c = this.events[d].point, f = this.events[d + 1].point;
993
+ Ce(c, t, f) !== 0 && (n.push(c), t = c);
994
+ }
995
+ if (n.length === 1) return null;
996
+ const s = n[0], o = n[1];
997
+ Ce(s, t, o) === 0 && n.shift(), n.push(n[0]);
998
+ const i = this.isExteriorRing() ? 1 : -1, a = this.isExteriorRing() ? 0 : n.length - 1, r = this.isExteriorRing() ? n.length : -1, l = [];
999
+ for (let d = a; d != r; d += i) l.push([n[d].x, n[d].y]);
1000
+ return l;
1001
+ }
1002
+ isExteriorRing() {
1003
+ if (this._isExteriorRing === void 0) {
1004
+ const t = this.enclosingRing();
1005
+ this._isExteriorRing = t ? !t.isExteriorRing() : !0;
1006
+ }
1007
+ return this._isExteriorRing;
1008
+ }
1009
+ enclosingRing() {
1010
+ return this._enclosingRing === void 0 && (this._enclosingRing = this._calcEnclosingRing()), this._enclosingRing;
1011
+ }
1012
+ /* Returns the ring that encloses this one, if any */
1013
+ _calcEnclosingRing() {
1014
+ let t = this.events[0];
1015
+ for (let o = 1, i = this.events.length; o < i; o++) {
1016
+ const a = this.events[o];
1017
+ J.compare(t, a) > 0 && (t = a);
1018
+ }
1019
+ let n = t.segment.prevInResult(), s = n ? n.prevInResult() : null;
1020
+ for (; ; ) {
1021
+ if (!n) return null;
1022
+ if (!s) return n.ringOut;
1023
+ if (s.ringOut !== n.ringOut)
1024
+ return s.ringOut.enclosingRing() !== n.ringOut ? n.ringOut : n.ringOut.enclosingRing();
1025
+ n = s.prevInResult(), s = n ? n.prevInResult() : null;
1026
+ }
1027
+ }
1028
+ }
1029
+ class Ze {
1030
+ constructor(t) {
1031
+ this.exteriorRing = t, t.poly = this, this.interiorRings = [];
1032
+ }
1033
+ addInterior(t) {
1034
+ this.interiorRings.push(t), t.poly = this;
1035
+ }
1036
+ getGeom() {
1037
+ const t = [this.exteriorRing.getGeom()];
1038
+ if (t[0] === null) return null;
1039
+ for (let n = 0, s = this.interiorRings.length; n < s; n++) {
1040
+ const o = this.interiorRings[n].getGeom();
1041
+ o !== null && t.push(o);
1042
+ }
1043
+ return t;
1044
+ }
1045
+ }
1046
+ class Xn {
1047
+ constructor(t) {
1048
+ this.rings = t, this.polys = this._composePolys(t);
1049
+ }
1050
+ getGeom() {
1051
+ const t = [];
1052
+ for (let n = 0, s = this.polys.length; n < s; n++) {
1053
+ const o = this.polys[n].getGeom();
1054
+ o !== null && t.push(o);
1055
+ }
1056
+ return t;
1057
+ }
1058
+ _composePolys(t) {
1059
+ const n = [];
1060
+ for (let s = 0, o = t.length; s < o; s++) {
1061
+ const i = t[s];
1062
+ if (!i.poly)
1063
+ if (i.isExteriorRing()) n.push(new Ze(i));
1064
+ else {
1065
+ const a = i.enclosingRing();
1066
+ a.poly || n.push(new Ze(a)), a.poly.addInterior(i);
1067
+ }
1068
+ }
1069
+ return n;
1070
+ }
1071
+ }
1072
+ class qn {
1073
+ constructor(t) {
1074
+ let n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : lt.compare;
1075
+ this.queue = t, this.tree = new Ee(n), this.segments = [];
1076
+ }
1077
+ process(t) {
1078
+ const n = t.segment, s = [];
1079
+ if (t.consumedBy)
1080
+ return t.isLeft ? this.queue.remove(t.otherSE) : this.tree.remove(n), s;
1081
+ const o = t.isLeft ? this.tree.add(n) : this.tree.find(n);
1082
+ if (!o) throw new Error(`Unable to find segment #${n.id} [${n.leftSE.point.x}, ${n.leftSE.point.y}] -> [${n.rightSE.point.x}, ${n.rightSE.point.y}] in SweepLine tree.`);
1083
+ let i = o, a = o, r, l;
1084
+ for (; r === void 0; )
1085
+ i = this.tree.prev(i), i === null ? r = null : i.key.consumedBy === void 0 && (r = i.key);
1086
+ for (; l === void 0; )
1087
+ a = this.tree.next(a), a === null ? l = null : a.key.consumedBy === void 0 && (l = a.key);
1088
+ if (t.isLeft) {
1089
+ let d = null;
1090
+ if (r) {
1091
+ const c = r.getIntersection(n);
1092
+ if (c !== null && (n.isAnEndpoint(c) || (d = c), !r.isAnEndpoint(c))) {
1093
+ const f = this._splitSafely(r, c);
1094
+ for (let h = 0, p = f.length; h < p; h++)
1095
+ s.push(f[h]);
1096
+ }
1097
+ }
1098
+ let u = null;
1099
+ if (l) {
1100
+ const c = l.getIntersection(n);
1101
+ if (c !== null && (n.isAnEndpoint(c) || (u = c), !l.isAnEndpoint(c))) {
1102
+ const f = this._splitSafely(l, c);
1103
+ for (let h = 0, p = f.length; h < p; h++)
1104
+ s.push(f[h]);
1105
+ }
1106
+ }
1107
+ if (d !== null || u !== null) {
1108
+ let c = null;
1109
+ d === null ? c = u : u === null ? c = d : c = J.comparePoints(d, u) <= 0 ? d : u, this.queue.remove(n.rightSE), s.push(n.rightSE);
1110
+ const f = n.split(c);
1111
+ for (let h = 0, p = f.length; h < p; h++)
1112
+ s.push(f[h]);
1113
+ }
1114
+ s.length > 0 ? (this.tree.remove(n), s.push(t)) : (this.segments.push(n), n.prev = r);
1115
+ } else {
1116
+ if (r && l) {
1117
+ const d = r.getIntersection(l);
1118
+ if (d !== null) {
1119
+ if (!r.isAnEndpoint(d)) {
1120
+ const u = this._splitSafely(r, d);
1121
+ for (let c = 0, f = u.length; c < f; c++)
1122
+ s.push(u[c]);
1123
+ }
1124
+ if (!l.isAnEndpoint(d)) {
1125
+ const u = this._splitSafely(l, d);
1126
+ for (let c = 0, f = u.length; c < f; c++)
1127
+ s.push(u[c]);
1128
+ }
1129
+ }
1130
+ }
1131
+ this.tree.remove(n);
1132
+ }
1133
+ return s;
1134
+ }
1135
+ /* Safely split a segment that is currently in the datastructures
1136
+ * IE - a segment other than the one that is currently being processed. */
1137
+ _splitSafely(t, n) {
1138
+ this.tree.remove(t);
1139
+ const s = t.rightSE;
1140
+ this.queue.remove(s);
1141
+ const o = t.split(n);
1142
+ return o.push(s), t.consumedBy === void 0 && this.tree.add(t), o;
1143
+ }
1144
+ }
1145
+ const He = typeof process < "u" && process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE || 1e6, Jn = typeof process < "u" && process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS || 1e6;
1146
+ class Kn {
1147
+ run(t, n, s) {
1148
+ K.type = t, Bt.reset();
1149
+ const o = [new Ue(n, !0)];
1150
+ for (let c = 0, f = s.length; c < f; c++)
1151
+ o.push(new Ue(s[c], !1));
1152
+ if (K.numMultiPolys = o.length, K.type === "difference") {
1153
+ const c = o[0];
1154
+ let f = 1;
1155
+ for (; f < o.length; )
1156
+ be(o[f].bbox, c.bbox) !== null ? f++ : o.splice(f, 1);
1157
+ }
1158
+ if (K.type === "intersection")
1159
+ for (let c = 0, f = o.length; c < f; c++) {
1160
+ const h = o[c];
1161
+ for (let p = c + 1, m = o.length; p < m; p++)
1162
+ if (be(h.bbox, o[p].bbox) === null) return [];
1163
+ }
1164
+ const i = new Ee(J.compare);
1165
+ for (let c = 0, f = o.length; c < f; c++) {
1166
+ const h = o[c].getSweepEvents();
1167
+ for (let p = 0, m = h.length; p < m; p++)
1168
+ if (i.insert(h[p]), i.size > He)
1169
+ throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).");
1170
+ }
1171
+ const a = new qn(i);
1172
+ let r = i.size, l = i.pop();
1173
+ for (; l; ) {
1174
+ const c = l.key;
1175
+ if (i.size === r) {
1176
+ const h = c.segment;
1177
+ throw new Error(`Unable to pop() ${c.isLeft ? "left" : "right"} SweepEvent [${c.point.x}, ${c.point.y}] from segment #${h.id} [${h.leftSE.point.x}, ${h.leftSE.point.y}] -> [${h.rightSE.point.x}, ${h.rightSE.point.y}] from queue.`);
1178
+ }
1179
+ if (i.size > He)
1180
+ throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");
1181
+ if (a.segments.length > Jn)
1182
+ throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");
1183
+ const f = a.process(c);
1184
+ for (let h = 0, p = f.length; h < p; h++) {
1185
+ const m = f[h];
1186
+ m.consumedBy === void 0 && i.insert(m);
1187
+ }
1188
+ r = i.size, l = i.pop();
1189
+ }
1190
+ Bt.reset();
1191
+ const d = Kt.factory(a.segments);
1192
+ return new Xn(d).getGeom();
1193
+ }
1194
+ }
1195
+ const K = new Kn(), Qn = function(e) {
1196
+ for (var t = arguments.length, n = new Array(t > 1 ? t - 1 : 0), s = 1; s < t; s++)
1197
+ n[s - 1] = arguments[s];
1198
+ return K.run("union", e, n);
1199
+ }, to = function(e) {
1200
+ for (var t = arguments.length, n = new Array(t > 1 ? t - 1 : 0), s = 1; s < t; s++)
1201
+ n[s - 1] = arguments[s];
1202
+ return K.run("intersection", e, n);
1203
+ }, eo = function(e) {
1204
+ for (var t = arguments.length, n = new Array(t > 1 ? t - 1 : 0), s = 1; s < t; s++)
1205
+ n[s - 1] = arguments[s];
1206
+ return K.run("xor", e, n);
1207
+ }, no = function(e) {
1208
+ for (var t = arguments.length, n = new Array(t > 1 ? t - 1 : 0), s = 1; s < t; s++)
1209
+ n[s - 1] = arguments[s];
1210
+ return K.run("difference", e, n);
1211
+ };
1212
+ var ct = {
1213
+ union: Qn,
1214
+ intersection: to,
1215
+ xor: eo,
1216
+ difference: no
1217
+ };
1218
+ const oo = [
1219
+ "zone",
1220
+ "room",
1221
+ "parcel",
1222
+ "building",
1223
+ "office",
1224
+ "container",
1225
+ "storage",
1226
+ "door",
1227
+ "window",
1228
+ "gate",
1229
+ "turnstile",
1230
+ "reader",
1231
+ "camera",
1232
+ "elevator",
1233
+ "stairs",
1234
+ "poi",
1235
+ "fixture",
1236
+ "light",
1237
+ "landscape",
1238
+ "sensor",
1239
+ "alarm",
1240
+ "equipment",
1241
+ "evacuation"
1242
+ ], so = ["silent", "office", "backrooms", "plant", "baths", "elevator"], H = () => crypto.randomUUID(), pt = (e) => ["zone", "room", "parcel", "building", "office", "container", "storage", "evacuation"].includes(e), Rs = (e) => ["door", "gate", "turnstile", "reader", "camera", "elevator", "sensor", "alarm", "equipment"].includes(e), nn = (e) => e === "door" || e === "window" || e === "gate", et = (e) => pt(e) || e === "elevator" || e === "stairs", mt = (e, t) => JSON.stringify([e, t].sort());
1243
+ function on(e) {
1244
+ var o;
1245
+ const t = new Map((e.virtualBoundaries ?? []).map((i) => [i.id, i]));
1246
+ if (!t.size) return [];
1247
+ const n = /* @__PURE__ */ new Map();
1248
+ for (const i of e.objects)
1249
+ if (!(!et(i.kind) || ((o = i.geometry) == null ? void 0 : o.mode) !== "boundaries"))
1250
+ for (const a of i.geometry.loops)
1251
+ for (const r of a) {
1252
+ const l = t.get(r.edgeId);
1253
+ if (!l || l.floorId !== i.floorId) continue;
1254
+ const d = n.get(l.id) ?? [];
1255
+ d.some((u) => u.id === i.id) || d.push({ id: i.id, reversed: !!r.reversed }), n.set(l.id, d);
1256
+ }
1257
+ const s = /* @__PURE__ */ new Map();
1258
+ for (const i of n.values())
1259
+ for (let a = 0; a < i.length; a++)
1260
+ for (let r = a + 1; r < i.length; r++) {
1261
+ if (i[a].reversed === i[r].reversed) continue;
1262
+ const [l, d] = [i[a].id, i[r].id].sort();
1263
+ s.set(mt(l, d), { id: `open:${l}:${d}`, a: l, b: d, attests: "none" });
1264
+ }
1265
+ return [...s.values()];
1266
+ }
1267
+ function Dt(e) {
1268
+ const t = on(e), n = new Set(t.map((l) => mt(l.a, l.b))), s = new Set(e.objects.filter((l) => {
1269
+ var d;
1270
+ return ((d = l.geometry) == null ? void 0 : d.mode) === "boundaries";
1271
+ }).map((l) => l.id)), o = (e.portals ?? []).filter(
1272
+ (l) => !l.id.startsWith("open:") || !s.has(l.a) || !s.has(l.b) || n.has(mt(l.a, l.b))
1273
+ ), i = new Set(
1274
+ o.filter((l) => !l.id.startsWith("open:") && !l.id.startsWith("inferred:")).map((l) => mt(l.a, l.b))
1275
+ ), a = o.filter((l) => !l.id.startsWith("open:") || !i.has(mt(l.a, l.b))), r = new Set(a.map((l) => mt(l.a, l.b)));
1276
+ return [...a, ...t.filter((l) => !r.has(mt(l.a, l.b)))];
1277
+ }
1278
+ function Ps(e, t) {
1279
+ const n = e.passage ?? "both";
1280
+ return n === "none" ? null : e.b === t && n !== "b-to-a" ? "a-to-b" : e.a === t && n !== "a-to-b" ? "b-to-a" : null;
1281
+ }
1282
+ const ee = (e, t, n = /* @__PURE__ */ new Set()) => {
1283
+ var o;
1284
+ if (n.has(t.id)) return /* @__PURE__ */ new Set();
1285
+ n.add(t.id);
1286
+ const s = new Set(t.spaceIds);
1287
+ for (const i of t.childZoneIds ?? []) {
1288
+ const a = (o = e.zones) == null ? void 0 : o.find((r) => r.id === i);
1289
+ if (a) for (const r of ee(e, a, n)) s.add(r);
1290
+ }
1291
+ return s;
1292
+ }, io = (e, t) => [...ee(e, t)];
1293
+ function $s(e, t) {
1294
+ const n = ee(e, t);
1295
+ return Dt(e).filter((s) => n.has(s.a) !== n.has(s.b));
1296
+ }
1297
+ function Ns(e, t) {
1298
+ const n = ee(e, t);
1299
+ return Dt(e).filter((s) => n.has(s.a) && n.has(s.b));
1300
+ }
1301
+ function ro(e, t, n, s) {
1302
+ const o = {
1303
+ id: H(),
1304
+ name: t,
1305
+ spaceIds: [...new Set(n)].filter((i) => e.objects.some((a) => a.id === i && et(a.kind)))
1306
+ };
1307
+ return s && (o.purpose = s), (e.zones ?? (e.zones = [])).push(o), o;
1308
+ }
1309
+ function ao(e, t) {
1310
+ var n;
1311
+ e.zones = (e.zones ?? []).filter((s) => s.id !== t);
1312
+ for (const s of e.zones)
1313
+ (n = s.childZoneIds) != null && n.includes(t) && (s.childZoneIds = s.childZoneIds.filter((o) => o !== t));
1314
+ }
1315
+ function lo(e, t, n, s) {
1316
+ var r;
1317
+ const o = (r = e.zones) == null ? void 0 : r.find((l) => l.id === t);
1318
+ if (!o) return;
1319
+ const i = n.filter((l) => e.objects.some((d) => d.id === l && et(d.kind))), a = new Set(o.spaceIds);
1320
+ for (const l of i)
1321
+ s ? a.add(l) : a.delete(l);
1322
+ o.spaceIds = [...a];
1323
+ }
1324
+ function co(e, t, n) {
1325
+ var i, a;
1326
+ const s = (i = e.zones) == null ? void 0 : i.find((r) => r.id === t);
1327
+ if (!s || t === n || !((a = e.zones) != null && a.some((r) => r.id === n))) return !1;
1328
+ const o = (r, l, d = /* @__PURE__ */ new Set()) => {
1329
+ var u, c;
1330
+ return r === l ? !0 : d.has(r) ? !1 : (d.add(r), (((c = (u = e.zones) == null ? void 0 : u.find((f) => f.id === r)) == null ? void 0 : c.childZoneIds) ?? []).some((f) => o(f, l, d)));
1331
+ };
1332
+ return o(n, t) ? !1 : (s.childZoneIds = [.../* @__PURE__ */ new Set([...s.childZoneIds ?? [], n])], !0);
1333
+ }
1334
+ function fo(e, t, n) {
1335
+ e.portals = Dt(e);
1336
+ const s = {
1337
+ id: H(),
1338
+ name: t,
1339
+ portalIds: [...new Set(n)].filter((o) => (e.portals ?? []).some((i) => i.id === o))
1340
+ };
1341
+ return (e.portalGroups ?? (e.portalGroups = [])).push(s), s;
1342
+ }
1343
+ function uo(e, t) {
1344
+ e.portalGroups = (e.portalGroups ?? []).filter((n) => n.id !== t);
1345
+ }
1346
+ function ho(e, t, n, s) {
1347
+ var r;
1348
+ const o = (r = e.portalGroups) == null ? void 0 : r.find((l) => l.id === t);
1349
+ if (!o) return;
1350
+ e.portals = Dt(e);
1351
+ const i = n.filter((l) => (e.portals ?? []).some((d) => d.id === l)), a = new Set(o.portalIds);
1352
+ for (const l of i)
1353
+ s ? a.add(l) : a.delete(l);
1354
+ o.portalIds = [...a];
1355
+ }
1356
+ function Nt(e) {
1357
+ const t = new Set(e.objects.map((o) => o.id)), n = new Set(e.objects.filter((o) => et(o.kind)).map((o) => o.id));
1358
+ e.portals && (e.portals = e.portals.filter(
1359
+ (o) => n.has(o.a) && n.has(o.b) && (!o.openingId || t.has(o.openingId))
1360
+ ));
1361
+ const s = new Set((e.portals ?? []).map((o) => o.id));
1362
+ if (e.zones) {
1363
+ const o = new Set(e.zones.map((i) => i.id));
1364
+ for (const i of e.zones)
1365
+ i.spaceIds = i.spaceIds.filter((a) => n.has(a)), i.childZoneIds && (i.childZoneIds = i.childZoneIds.filter((a) => o.has(a)));
1366
+ }
1367
+ if (e.portalGroups)
1368
+ for (const o of e.portalGroups) o.portalIds = o.portalIds.filter((i) => s.has(i));
1369
+ }
1370
+ const Me = /* @__PURE__ */ new Set(["door", "gate", "turnstile"]), go = (e) => `space:${e}`;
1371
+ function mo(e, t, n) {
1372
+ const s = e.floorId === t.floorId;
1373
+ return !s && e.floorId !== null && t.floorId !== null ? e.kind === "elevator" || t.kind === "elevator" ? "elevator" : "stairs" : s ? n && Me.has(n.kind) ? "door" : "walk" : "door";
1374
+ }
1375
+ function po(e) {
1376
+ const t = new Map(e.objects.map((r) => [r.id, r])), n = new Map(e.floors.map((r) => [r.id, r])), s = /* @__PURE__ */ new Map(), o = (r) => {
1377
+ const l = go(r.id), d = s.get(l);
1378
+ if (d) return d;
1379
+ const u = { id: l, floorId: r.floorId, position: ds(e, r), objectId: r.id };
1380
+ return s.set(l, u), u;
1381
+ };
1382
+ for (const r of e.objects) et(r.kind) && o(r);
1383
+ const i = [], a = (r, l, d, u, c, f = !1) => {
1384
+ if (d.id === u.id) return;
1385
+ const h = { id: r, kind: l, aId: o(d).id, bId: o(u).id };
1386
+ c && (h.objectId = c), f && (h.directed = !0), i.push(h);
1387
+ };
1388
+ for (const r of Dt(e)) {
1389
+ if ((r.passage ?? "both") === "none") continue;
1390
+ const l = t.get(r.a), d = t.get(r.b);
1391
+ if (!l || !d) continue;
1392
+ const u = r.openingId ? t.get(r.openingId) : void 0, c = mo(l, d, u), f = u && (c === "door" ? Me.has(u.kind) : c === "walk" ? !1 : u.kind === c), h = r.passage ?? "both", [p, m] = h === "b-to-a" ? [d, l] : [l, d];
1393
+ a(`portal:${r.id}`, c, p, m, f ? u.id : void 0, h !== "both");
1394
+ }
1395
+ for (const r of e.zones ?? []) {
1396
+ if (!r.connects) continue;
1397
+ const l = io(e, r).map((c) => t.get(c)).filter((c) => !!c && c.floorId !== null).sort((c, f) => {
1398
+ var h, p;
1399
+ return (((h = n.get(c.floorId)) == null ? void 0 : h.elevation) ?? 0) - (((p = n.get(f.floorId)) == null ? void 0 : p.elevation) ?? 0);
1400
+ }), d = l.some((c) => c.kind === "elevator") ? "elevator" : "stairs", u = r.connects === "up" || r.connects === "down";
1401
+ for (let c = 1; c < l.length; c++)
1402
+ for (let f = r.connects === "all" ? 0 : c - 1; f < c; f++)
1403
+ l[f].floorId !== l[c].floorId && a(
1404
+ `zone:${r.id}:${f}:${c}`,
1405
+ d,
1406
+ r.connects === "down" ? l[c] : l[f],
1407
+ r.connects === "down" ? l[f] : l[c],
1408
+ l[c].kind === d ? l[c].id : void 0,
1409
+ u
1410
+ );
1411
+ }
1412
+ return { nodes: [...s.values()], edges: i };
1413
+ }
1414
+ const We = /* @__PURE__ */ new WeakMap();
1415
+ function sn(e) {
1416
+ const t = We.get(e);
1417
+ if (t) return t;
1418
+ const n = po(e);
1419
+ return We.set(e, n), n;
1420
+ }
1421
+ const zt = (e) => e === "stairs" || e === "elevator", It = (e) => `${e.kind}|${e.name}|${e.position[0].toFixed(2)}|${e.position[1].toFixed(2)}`;
1422
+ function wt(e, t) {
1423
+ const n = It(t), s = e.objects.filter((o) => zt(o.kind) && It(o) === n).flatMap((o) => {
1424
+ var i;
1425
+ return (i = o.servedFloorIds) != null && i.length ? o.servedFloorIds : o.floorId ? [o.floorId] : [];
1426
+ });
1427
+ return [...new Set(s.length ? s : t.floorId ? [t.floorId] : [])].map((o) => e.floors.find((i) => i.id === o)).filter((o) => !!o).sort((o, i) => o.elevation - i.elevation);
1428
+ }
1429
+ function Se(e, t) {
1430
+ const n = wt(e, t), s = [];
1431
+ for (let o = 1; o < n.length; o++)
1432
+ s.push({ from: n[o - 1], to: n[o], rise: n[o].elevation - n[o - 1].elevation });
1433
+ return s;
1434
+ }
1435
+ const Os = (e, t, n) => n !== null && (t.floorId === n || wt(e, t).some((s) => s.id === n));
1436
+ function Bs(e, t, n) {
1437
+ const s = Se(e, t);
1438
+ return {
1439
+ up: s.find((o) => o.from.id === n),
1440
+ down: s.find((o) => o.to.id === n)
1441
+ };
1442
+ }
1443
+ function zs(e, t) {
1444
+ const n = wt(e, t);
1445
+ return n.length < 2 ? null : { bottom: n[0].elevation, top: n[n.length - 1].elevation };
1446
+ }
1447
+ const rn = { escalator: 30, stairs: 32 }, Io = (e, t = rn.stairs) => e / Math.tan(t * Math.PI / 180), bo = (e, t) => t > 0 ? Math.atan(e / t) * 180 / Math.PI : 90, yo = 0.32, wo = 0.175, vo = 2.1;
1448
+ function xo(e, t) {
1449
+ const n = Math.max(2, Math.min(24, Math.round(e / wo)));
1450
+ return { steps: n, going: Math.min(yo, t / n) };
1451
+ }
1452
+ function Eo(e, t) {
1453
+ if (t.stairModel) return t.stairModel;
1454
+ const n = Se(e, t)[0];
1455
+ return n && bo(n.rise, Math.max(0.6, t.depth)) > 38 ? "switchback" : "straight";
1456
+ }
1457
+ const Mo = (e, t) => e === "escalator" && t % 2 === 1;
1458
+ function So(e, t, n, s, o = 0) {
1459
+ const i = yt(e, t), a = xn(e, t) + (Mo(s, o) ? 180 : 0), r = a * Math.PI / 180, l = Math.sin(r), d = -Math.cos(r), u = (I) => [i[0] + l * I, i[1] + d * I], c = Math.max(0.6, t.depth), f = c / 2;
1460
+ if (s === "escalator") {
1461
+ const I = Math.min(1, c / 4), b = Math.min(c - I * 2, Math.max(0.4, Io(n, rn.escalator)));
1462
+ return { rotation: a, at: u, length: c, half: f, pad: I, incline: b, topT: -f + I, footT: -f + I + b };
1463
+ }
1464
+ const { steps: h, going: p } = xo(n, c), m = Math.min(c, h * p);
1465
+ return { rotation: a, at: u, length: c, half: f, pad: 0, incline: m, topT: f - m, footT: f };
1466
+ }
1467
+ function ko(e, t, n, s) {
1468
+ const o = t > 0.01 ? e.incline / t : e.incline, a = Math.min(e.footT, Math.max(e.topT + 0.6, e.footT - n * o + vo * o)) - e.topT;
1469
+ return C(Zt(e.at(e.topT + a / 2), s, a, e.rotation));
1470
+ }
1471
+ function Fs(e) {
1472
+ const t = /* @__PURE__ */ new Map();
1473
+ for (const n of e.objects) {
1474
+ if (!zt(n.kind)) continue;
1475
+ const s = It(n), o = t.get(s), i = (a) => {
1476
+ var r;
1477
+ return ((r = e.floors.find((l) => l.id === a.floorId)) == null ? void 0 : r.elevation) ?? 0;
1478
+ };
1479
+ (!o || i(n) < i(o)) && t.set(s, n);
1480
+ }
1481
+ return new Set([...t.values()].map((n) => n.id));
1482
+ }
1483
+ function Ao(e, t, n) {
1484
+ const s = e.floors.find((i) => i.id === n);
1485
+ if (!s) return !1;
1486
+ const o = wt(e, t);
1487
+ return o.some((i) => i.elevation < s.elevation - 0.01) && o.some((i) => i.elevation >= s.elevation - 0.01);
1488
+ }
1489
+ function _o(e, t, n) {
1490
+ const s = e.floors.find((i) => i.id === n);
1491
+ if (!s) return !1;
1492
+ const o = wt(e, t);
1493
+ return o.some((i) => i.elevation <= s.elevation + 0.01) && o.some((i) => i.elevation > s.elevation + 0.01);
1494
+ }
1495
+ const Ts = (e, t, n) => Ao(e, t, n) && _o(e, t, n);
1496
+ function Cs(e, t, n, s = {}) {
1497
+ const o = e.floors.find((d) => d.id === t);
1498
+ if (!o) return [];
1499
+ const i = s.through === "ceiling", a = s.lowest ?? -1 / 0, r = [], l = /* @__PURE__ */ new Map();
1500
+ for (const d of e.objects) {
1501
+ if (!zt(d.kind) || n && !n.has(d.id)) continue;
1502
+ const u = Se(e, d), c = i ? u.findIndex((m) => m.from.elevation <= o.elevation + 0.01 && m.to.elevation > o.elevation + 0.01) : u.findIndex((m) => m.from.elevation < o.elevation - 0.01 && m.to.elevation >= o.elevation - 0.01);
1503
+ if (c < 0) continue;
1504
+ const f = u[c];
1505
+ if (f.from.elevation < a) continue;
1506
+ if (d.kind === "stairs" && d.wellGroup) {
1507
+ const m = l.get(d.wellGroup) ?? [];
1508
+ m.push(d), l.set(d.wellGroup, m);
1509
+ continue;
1510
+ }
1511
+ const h = Eo(e, d);
1512
+ if (d.kind === "stairs" && (h === "straight" || h === "escalator")) {
1513
+ const m = So(e, d, f.rise, h, c), I = o.elevation + (i ? o.height : 0) - f.from.elevation;
1514
+ r.push(ko(m, f.rise, I, d.width));
1515
+ continue;
1516
+ }
1517
+ const p = W(d)[0];
1518
+ p != null && p.length && r.push(C(p.map((m) => [m[0], m[1]])));
1519
+ }
1520
+ for (const d of l.values()) {
1521
+ const u = xn(e, d[0]), c = d.flatMap((w) => W(w)[0]).map((w) => Lt(w, -u)), f = c.map((w) => w[0]), h = c.map((w) => w[1]), p = Math.min(...f), m = Math.max(...f), I = Math.min(...h), b = Math.max(...h);
1522
+ r.push(Zt(Lt([(p + m) / 2, (I + b) / 2], u), m - p, b - I, u));
1523
+ }
1524
+ return r;
1525
+ }
1526
+ const Ot = 0.4, Vt = (e, t = 0) => [
1527
+ Math.min(...e.map((n) => n[0])) - t,
1528
+ Math.min(...e.map((n) => n[1])) - t,
1529
+ Math.max(...e.map((n) => n[0])) + t,
1530
+ Math.max(...e.map((n) => n[1])) + t
1531
+ ], de = (e, t) => e[0] <= t[2] && e[2] >= t[0] && e[1] <= t[3] && e[3] >= t[1], Ro = (e, t, n, s) => Qt(e, t, n, s) ? 0 : Math.min(
1532
+ G(e, n, s).distance,
1533
+ G(t, n, s).distance,
1534
+ G(n, e, t).distance,
1535
+ G(s, e, t).distance
1536
+ );
1537
+ function an(e) {
1538
+ const t = new Map(e.junctions.map((i) => [i.id, i.position])), n = /* @__PURE__ */ new Map();
1539
+ for (const i of e.objects) {
1540
+ if (!i.barrierId || i.kind !== "door" && i.kind !== "gate") continue;
1541
+ const a = n.get(i.barrierId) ?? [];
1542
+ a.push([(i.offset ?? 0) - i.width / 2, (i.offset ?? 0) + i.width / 2]), n.set(i.barrierId, a);
1543
+ }
1544
+ const s = /* @__PURE__ */ new Map();
1545
+ for (const i of e.barriers) {
1546
+ const a = t.get(i.startId), r = t.get(i.endId);
1547
+ if (!a || !r) continue;
1548
+ const l = S(a, r);
1549
+ if (!l) continue;
1550
+ const d = (m) => [a[0] + (r[0] - a[0]) * m / l, a[1] + (r[1] - a[1]) * m / l], u = s.get(i.floorId) ?? [], c = (a[1] - r[1]) / l * i.thickness / 2, f = (r[0] - a[0]) / l * i.thickness / 2, h = (m, I) => {
1551
+ if (I <= m) return;
1552
+ const b = d(m), w = d(I), g = [
1553
+ [b[0] + c, b[1] + f],
1554
+ [w[0] + c, w[1] + f],
1555
+ [w[0] - c, w[1] - f],
1556
+ [b[0] - c, b[1] - f]
1557
+ ];
1558
+ u.push({ ring: g, bounds: Vt(g, Ot) });
1559
+ };
1560
+ let p = 0;
1561
+ for (const [m, I] of (n.get(i.id) ?? []).sort((b, w) => b[0] - w[0]))
1562
+ h(p, Math.min(l, Math.max(0, m))), p = Math.max(p, Math.min(l, I));
1563
+ h(p, l), s.set(i.floorId, u);
1564
+ }
1565
+ const o = /* @__PURE__ */ new Map();
1566
+ for (const i of e.objects) {
1567
+ const a = i.water ? W(i).slice(0, 1) : i.kind === "room" || i.kind === "zone" ? W(i).slice(1) : [], r = o.get(i.floorId) ?? [];
1568
+ for (const l of a) r.push({ ring: T(l), bounds: Vt(l, Ot) });
1569
+ o.set(i.floorId, r);
1570
+ }
1571
+ return (i, a) => {
1572
+ const r = (s.get(i) ?? []).filter((u) => !a || de(a, u.bounds)), l = (o.get(i) ?? []).filter((u) => !a || de(a, u.bounds)), d = [...r, ...l];
1573
+ return (u, c) => {
1574
+ const f = Vt([u, c]);
1575
+ for (const h of d)
1576
+ if (de(f, h.bounds)) {
1577
+ if (D(u, h.ring) || D(c, h.ring)) return !1;
1578
+ for (let p = 0; p < h.ring.length; p++)
1579
+ if (Ro(u, c, h.ring[p], h.ring[(p + 1) % h.ring.length]) < Ot - 1e-7) return !1;
1580
+ }
1581
+ return !0;
1582
+ };
1583
+ };
1584
+ }
1585
+ const je = /* @__PURE__ */ new WeakMap();
1586
+ function Po(e) {
1587
+ let t = je.get(e);
1588
+ return t || (t = an(e), je.set(e, t)), t;
1589
+ }
1590
+ const $o = 25, No = 1, Oo = 5, Bo = 1.5, zo = 0.25, Ft = (e) => e.navNodes ?? sn(e).nodes, ln = (e) => e.navEdges ?? sn(e).edges, dn = (e, t) => t === null ? null : e.floors.find((n) => n.id === t) ?? null, ft = (e, t) => {
1591
+ var n;
1592
+ return ((n = dn(e, t)) == null ? void 0 : n.elevation) ?? 0;
1593
+ };
1594
+ function cn(e, t, n, s) {
1595
+ e.navNodes ?? (e.navNodes = []);
1596
+ const o = e.navNodes.find((a) => a.floorId === t && S(a.position, n) < zo);
1597
+ if (o)
1598
+ return s && !o.objectId && (o.objectId = s), o;
1599
+ const i = { id: H(), floorId: t, position: [n[0], n[1]] };
1600
+ return s && (i.objectId = s), e.navNodes.push(i), i;
1601
+ }
1602
+ function fn(e, t, n, s, o) {
1603
+ e.navEdges ?? (e.navEdges = []);
1604
+ const i = e.navEdges.find(
1605
+ (r) => r.kind === t && (r.aId === n.id && r.bId === s.id || r.aId === s.id && r.bId === n.id)
1606
+ );
1607
+ if (i)
1608
+ return o && !i.objectId && (i.objectId = o), i;
1609
+ const a = { id: H(), kind: t, aId: n.id, bId: s.id };
1610
+ return o && (a.objectId = o), e.navEdges.push(a), a;
1611
+ }
1612
+ function Ls(e, t, n) {
1613
+ const s = n.map((o) => cn(e, t, o));
1614
+ for (let o = 1; o < s.length; o++) s[o - 1].id !== s[o].id && fn(e, "walk", s[o - 1], s[o]);
1615
+ return s;
1616
+ }
1617
+ function Gs(e, t) {
1618
+ const n = t.kind === "elevator" ? "elevator" : "stairs", s = t.stairModel === "escalator" ? t.travel ?? "up" : null, o = wt(e, t), i = It(t), a = /* @__PURE__ */ new Map();
1619
+ for (const d of e.objects)
1620
+ d.kind === t.kind && It(d) === i && !a.has(d.floorId) && a.set(d.floorId, d);
1621
+ const r = (d) => a.get(d) ?? t, l = o.map((d) => {
1622
+ const u = r(d.id);
1623
+ return cn(e, d.id, yt(e, u), u.id);
1624
+ });
1625
+ for (let d = 1; d < l.length; d++)
1626
+ for (let u = n === "elevator" ? 0 : d - 1; u < d; u++) {
1627
+ if (l[u].id === l[d].id) continue;
1628
+ const [c, f] = s === "down" ? [l[d], l[u]] : [l[u], l[d]], h = fn(e, n, c, f, r(l[d].floorId).id);
1629
+ s && (h.directed = !0);
1630
+ }
1631
+ return l;
1632
+ }
1633
+ const Ds = "@here";
1634
+ function Ye(e, t, n, s) {
1635
+ if (t.weight !== void 0) return t.weight;
1636
+ const o = S(n.position, s.position), i = Math.abs(ft(e, n.floorId) - ft(e, s.floorId));
1637
+ return t.kind === "elevator" ? $o + i * No : t.kind === "stairs" ? o + i * Oo : o + (t.kind === "door" ? Bo : 0);
1638
+ }
1639
+ function Xt(e, t, n, s) {
1640
+ const o = t.kind === "stairs" || t.kind === "elevator" ? Math.abs(ft(e, n.floorId) - ft(e, s.floorId)) : 0;
1641
+ return S(n.position, s.position) + o;
1642
+ }
1643
+ function Fo(e, t) {
1644
+ const n = Ft(e).filter((r) => r.objectId === t.id);
1645
+ if (n.length) return n.map((r) => ({ node: r, cost: 0 }));
1646
+ const s = yt(e, t), o = Ft(e).filter((r) => r.floorId === t.floorId), i = t.rings ? o.filter(
1647
+ (r) => D(r.position, t.rings[0]) && !t.rings.slice(1).some((l) => D(r.position, l))
1648
+ ) : [];
1649
+ if (i.length) return i.map((r) => ({ node: r, cost: S(s, r.position) }));
1650
+ const a = o.map((r) => ({ node: r, cost: S(s, r.position) })).sort((r, l) => r.cost - l.cost)[0];
1651
+ return a ? [a] : [];
1652
+ }
1653
+ function Ve(e, t, n) {
1654
+ if (typeof t == "string") {
1655
+ const d = e.objects.find((u) => u.id === t);
1656
+ return d ? { place: d, anchors: Fo(e, d), extraNodes: [], extraEdges: [] } : null;
1657
+ }
1658
+ const s = { id: `@${n}`, floorId: t.floorId, position: t.position }, o = Ft(e).filter((d) => d.floorId === t.floorId), i = ve(e, t.floorId, t.position), a = Po(e)(t.floorId);
1659
+ let r = i ? o.filter((d) => Rt(i, d.position) && a(t.position, d.position)) : [];
1660
+ if (!i) {
1661
+ const d = o.filter((u) => a(t.position, u.position)).sort((u, c) => S(u.position, t.position) - S(c.position, t.position))[0];
1662
+ r = d ? [d] : [];
1663
+ }
1664
+ const l = r.map(
1665
+ (d, u) => ({
1666
+ id: `@${n}-${u}`,
1667
+ kind: "walk",
1668
+ aId: s.id,
1669
+ bId: d.id,
1670
+ weight: S(t.position, d.position)
1671
+ })
1672
+ );
1673
+ return {
1674
+ place: {
1675
+ id: `@${n}`,
1676
+ kind: "poi",
1677
+ name: t.name ?? "Where you are",
1678
+ floorId: t.floorId,
1679
+ position: t.position
1680
+ },
1681
+ anchors: [{ node: s, cost: 0 }],
1682
+ extraNodes: [s],
1683
+ extraEdges: l
1684
+ };
1685
+ }
1686
+ function Us(e, t, n, s = {}) {
1687
+ var $;
1688
+ const o = Ve(e, t, "from"), i = Ve(e, n, "to");
1689
+ if (!o || !i) return null;
1690
+ const a = o.place, r = i.place, l = o.anchors, d = i.anchors;
1691
+ if (!l.length || !d.length) return null;
1692
+ const u = [...Ft(e), ...o.extraNodes, ...i.extraNodes], c = new Map(u.map((x) => [x.id, x])), f = /* @__PURE__ */ new Map();
1693
+ for (const x of [...ln(e), ...o.extraEdges, ...i.extraEdges]) {
1694
+ const E = c.get(x.aId), A = c.get(x.bId);
1695
+ if (!E || !A) continue;
1696
+ const v = x.kind === "stairs" && x.objectId ? e.objects.find((R) => R.id === x.objectId && R.stairModel === "escalator") : void 0, k = v != null && v.feedId ? ($ = s.statuses) == null ? void 0 : $.get(v.feedId) : void 0;
1697
+ if (v && (k != null && k.travel || (k == null ? void 0 : k.running) === !1)) {
1698
+ const R = ft(e, A.floorId) > ft(e, E.floorId), P = (k.travel ?? v.travel ?? "up") === (R ? "up" : "down");
1699
+ (k.running === !1 || P) && (f.get(E.id) ?? f.set(E.id, []).get(E.id)).push({ edge: x, other: A }), (k.running === !1 || !P) && (f.get(A.id) ?? f.set(A.id, []).get(A.id)).push({ edge: x, other: E });
1700
+ continue;
1701
+ }
1702
+ (f.get(E.id) ?? f.set(E.id, []).get(E.id)).push({ edge: x, other: A }), x.directed || (f.get(A.id) ?? f.set(A.id, []).get(A.id)).push({ edge: x, other: E });
1703
+ }
1704
+ const h = new To(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Set();
1705
+ for (const x of l)
1706
+ x.cost < (p.get(x.node.id) ?? 1 / 0) && (p.set(x.node.id, x.cost), h.push(x.node.id, x.cost));
1707
+ const b = new Map(d.map((x) => [x.node.id, x.cost]));
1708
+ let w = 1 / 0;
1709
+ for (; ; ) {
1710
+ const x = h.pop();
1711
+ if (!x || x.cost > w) break;
1712
+ const { id: E, cost: A } = x;
1713
+ if (I.has(E)) continue;
1714
+ I.add(E), b.has(E) && (w = Math.min(w, A + b.get(E)));
1715
+ const v = c.get(E);
1716
+ for (const { edge: k, other: R } of f.get(E) ?? []) {
1717
+ const P = A + Ye(e, k, v, R);
1718
+ P < (p.get(R.id) ?? 1 / 0) && (p.set(R.id, P), m.set(R.id, { node: v, edge: k }), h.push(R.id, P));
1719
+ }
1720
+ }
1721
+ const g = d.map((x) => ({ ...x, total: (p.get(x.node.id) ?? 1 / 0) + x.cost })).sort((x, E) => x.total - E.total)[0];
1722
+ if (!g || !Number.isFinite(g.total)) return null;
1723
+ const y = [];
1724
+ for (let x = g.node; ; ) {
1725
+ const E = m.get(x.id);
1726
+ if (!E) break;
1727
+ y.unshift({ edge: E.edge, from: E.node, to: x, cost: Ye(e, E.edge, E.node, x) }), x = E.node;
1728
+ }
1729
+ const M = [y.length ? y[0].from : g.node, ...y.map((x) => x.to)], _ = y.reduce((x, E) => x + Xt(e, E.edge, E.from, E.to), 0);
1730
+ return {
1731
+ from: a,
1732
+ to: r,
1733
+ nodes: M,
1734
+ legs: y,
1735
+ steps: Co(e, a, r, M, y),
1736
+ distance: _,
1737
+ cost: g.total
1738
+ };
1739
+ }
1740
+ class To {
1741
+ constructor() {
1742
+ re(this, "items", []);
1743
+ re(this, "order", 0);
1744
+ }
1745
+ before(t, n) {
1746
+ return t.cost < n.cost || t.cost === n.cost && t.order < n.order;
1747
+ }
1748
+ push(t, n) {
1749
+ const s = { id: t, cost: n, order: this.order++ };
1750
+ let o = this.items.length;
1751
+ for (this.items.push(s); o > 0; ) {
1752
+ const i = o - 1 >> 1;
1753
+ if (!this.before(s, this.items[i])) break;
1754
+ this.items[o] = this.items[i], o = i;
1755
+ }
1756
+ this.items[o] = s;
1757
+ }
1758
+ pop() {
1759
+ const t = this.items[0], n = this.items.pop();
1760
+ if (this.items.length && n) {
1761
+ let s = 0;
1762
+ for (; s * 2 + 1 < this.items.length; ) {
1763
+ let o = s * 2 + 1;
1764
+ if (o + 1 < this.items.length && this.before(this.items[o + 1], this.items[o]) && o++, !this.before(this.items[o], n)) break;
1765
+ this.items[s] = this.items[o], s = o;
1766
+ }
1767
+ this.items[s] = n;
1768
+ }
1769
+ return t;
1770
+ }
1771
+ }
1772
+ function ce(e, t) {
1773
+ const n = dn(e, t);
1774
+ return n ? n.code ? `${n.name} (level ${n.code})` : n.name : "outside";
1775
+ }
1776
+ const fe = (e, t, n) => {
1777
+ var s;
1778
+ return ((s = e.objects.find((o) => o.id === t.edge.objectId)) == null ? void 0 : s.name) ?? n;
1779
+ };
1780
+ function Co(e, t, n, s, o) {
1781
+ const i = [
1782
+ {
1783
+ kind: "depart",
1784
+ text: `Start at ${t.name}${t.floorId !== null ? ` on ${ce(e, t.floorId)}` : ""}`,
1785
+ floorId: t.floorId,
1786
+ nodeIds: s.length ? [s[0].id] : []
1787
+ }
1788
+ ];
1789
+ for (let a = 0; a < o.length; a++) {
1790
+ const r = o[a];
1791
+ if (r.edge.kind === "walk") {
1792
+ let l = Xt(e, r.edge, r.from, r.to);
1793
+ const d = [r.from.id, r.to.id];
1794
+ for (; a + 1 < o.length && o[a + 1].edge.kind === "walk"; )
1795
+ a++, l += Xt(e, o[a].edge, o[a].from, o[a].to), d.push(o[a].to.id);
1796
+ i.push({
1797
+ kind: "walk",
1798
+ text: `Walk ${Math.max(1, Math.round(l))} m ${o[a].to.floorId === null ? "outside" : `along ${ce(e, r.from.floorId)}`}`,
1799
+ floorId: r.from.floorId,
1800
+ nodeIds: d,
1801
+ distance: l
1802
+ });
1803
+ } else if (r.edge.kind === "door") {
1804
+ const l = fe(e, r, "the door"), d = r.to.floorId === null && r.from.floorId !== null ? `Exit through ${l}` : r.from.floorId === null && r.to.floorId !== null ? `Enter through ${l}` : `Go through ${l}`;
1805
+ i.push({
1806
+ kind: "door",
1807
+ text: d,
1808
+ floorId: r.to.floorId,
1809
+ nodeIds: [r.from.id, r.to.id],
1810
+ objectId: r.edge.objectId,
1811
+ distance: Xt(e, r.edge, r.from, r.to)
1812
+ });
1813
+ } else {
1814
+ const l = r.edge.kind, d = fe(e, r, l === "elevator" ? "the lift" : "the stairs"), u = [r.from.id, r.to.id], c = r.from;
1815
+ let f = r.to, h = r.edge.objectId;
1816
+ for (; a + 1 < o.length && o[a + 1].edge.kind === l && fe(e, o[a + 1], d) === d; )
1817
+ a++, f = o[a].to, u.push(f.id), h = o[a].edge.objectId ?? h;
1818
+ const p = ft(e, f.floorId) - ft(e, c.floorId), m = l === "stairs" && !/\b(up|down)\b/i.test(d) ? `${p > 0 ? "up " : "down "}` : "";
1819
+ i.push({
1820
+ kind: l,
1821
+ text: `Take ${d} ${m}to ${ce(e, f.floorId)}`,
1822
+ floorId: f.floorId,
1823
+ nodeIds: u,
1824
+ objectId: h
1825
+ });
1826
+ }
1827
+ }
1828
+ return i.push({
1829
+ kind: "arrive",
1830
+ text: `Arrive at ${n.name}`,
1831
+ floorId: n.floorId,
1832
+ nodeIds: s.length ? [s[s.length - 1].id] : []
1833
+ }), i;
1834
+ }
1835
+ const Lo = {
1836
+ limestone: { name: "Limestone", material: "stone", color: "#e2e4e6" },
1837
+ brick: { name: "Warm brick", material: "brick", color: "#9b705b" },
1838
+ darkBrick: { name: "Dark brick", material: "brick", color: "#7a4636" },
1839
+ plaster: { name: "Ivory render", material: "plaster", color: "#e0ddd4" },
1840
+ timber: { name: "Cedar cladding", material: "timber", color: "#ab8b68" }
1841
+ }, N = 1e-6, ut = 1e-3, un = 0.01, ne = 1e-3, kt = 1, ke = 1e-8, at = 1e4, Go = 1e5, B = (e) => typeof e == "number" && Number.isFinite(e), St = (e) => Array.isArray(e) && e.length === 2 && e.every((t) => B(t) && Math.abs(t) <= Go), st = (e) => !!e && typeof e == "object" && !Array.isArray(e), Y = (e) => typeof e == "string" && e.length > 0, Mt = (e) => new Set(e).size === e.length;
1842
+ function hn(e, t = 1e-3, n = 0.01) {
1843
+ if (!e.length) return "Draw an outer boundary first.";
1844
+ for (const s of e) {
1845
+ const o = T(s);
1846
+ if (o.length < 3 || V(o) < n) return "An area needs at least three vertices and a non-zero area.";
1847
+ for (let i = 0; i < o.length; i++) {
1848
+ if (S(o[i], o[(i + 1) % o.length]) < t) return "Remove duplicate vertices.";
1849
+ for (let a = i + 1; a < o.length; a++)
1850
+ if (!(a === i + 1 || i === 0 && a === o.length - 1) && Qt(o[i], o[(i + 1) % o.length], o[a], o[(a + 1) % o.length]))
1851
+ return "Area boundaries cannot cross themselves.";
1852
+ }
1853
+ }
1854
+ for (let s = 1; s < e.length; s++) {
1855
+ if (!e[s].every((o) => D(o, e[0]))) return "A hole must be completely inside the outer boundary.";
1856
+ for (let o = 0; o < s; o++) {
1857
+ const i = T(e[s]), a = T(e[o]);
1858
+ for (let r = 0; r < i.length; r++)
1859
+ for (let l = 0; l < a.length; l++)
1860
+ if (Qt(i[r], i[(r + 1) % i.length], a[l], a[(l + 1) % a.length]))
1861
+ return "Hole boundaries must not touch or overlap.";
1862
+ if (o > 0 && (D(i[0], a) || D(a[0], i))) return "Holes cannot overlap.";
1863
+ }
1864
+ }
1865
+ return null;
1866
+ }
1867
+ function Do(e) {
1868
+ var o;
1869
+ const t = new Map(e.objects.map((i) => [i.id, i])), n = new Map(e.barriers.map((i) => [i.id, i])), s = /* @__PURE__ */ new Map();
1870
+ for (const i of e.objects) {
1871
+ if (!i.barrierId) continue;
1872
+ const a = s.get(i.barrierId) ?? [];
1873
+ a.push(i), s.set(i.barrierId, a);
1874
+ }
1875
+ for (const i of e.barriers) {
1876
+ const [a, r] = X(e, i);
1877
+ if (S(a, r) < tt - 1e-6) return `A wall or fence must be at least ${tt} m long.`;
1878
+ }
1879
+ for (const i of e.objects) {
1880
+ if (i.rings) {
1881
+ const a = ((o = i.geometry) == null ? void 0 : o.mode) === "boundaries", r = hn(i.rings, a ? 1e-6 : 1e-3, a ? ke : 0.01);
1882
+ if (r) return r;
1883
+ }
1884
+ if (i.parentId) {
1885
+ const a = t.get(i.parentId);
1886
+ if (!(a != null && a.rings) || !i.rings || a.floorId !== i.floorId || !is(i.rings, a.rings))
1887
+ return "A nested zone must remain inside its parent on the same floor.";
1888
+ const r = /* @__PURE__ */ new Set([i.id]);
1889
+ let l = a;
1890
+ for (; l; ) {
1891
+ if (r.has(l.id)) return "Zone parents cannot form a cycle.";
1892
+ r.add(l.id), l = l.parentId ? t.get(l.parentId) : void 0;
1893
+ }
1894
+ }
1895
+ if (i.barrierId) {
1896
+ if (!nn(i.kind)) return "Only a door, window or gate can sit in a barrier.";
1897
+ const a = n.get(i.barrierId);
1898
+ if (!a || a.floorId !== i.floorId)
1899
+ return "Opening references a missing barrier or a different floor.";
1900
+ const [r, l] = X(e, a);
1901
+ if (S(r, l) < te - 1e-6)
1902
+ return `A door, window or gate needs a segment at least ${te} m long to sit in.`;
1903
+ const d = i.offset ?? 0;
1904
+ if (d - i.width / 2 < -1e-3 || d + i.width / 2 > S(r, l) + 1e-3)
1905
+ return `The barrier is too short for its attached opening. Opening "${i.name || i.id}" (${i.id}) on barrier ${a.id}: width ${i.width.toFixed(2)} m, centre offset ${d.toFixed(2)} m, segment length ${S(r, l).toFixed(2)} m. The centre offset must be between ${(i.width / 2).toFixed(2)} and ${(S(r, l) - i.width / 2).toFixed(2)} m; if that interval is empty, choose a longer host segment.`;
1906
+ if (s.get(a.id).some((u) => u.id !== i.id && Math.abs((u.offset ?? 0) - d) < (u.width + i.width) / 2 - 1e-3))
1907
+ return "Attached openings cannot overlap.";
1908
+ }
1909
+ }
1910
+ return null;
1911
+ }
1912
+ function Uo(e) {
1913
+ const t = Ft(e), n = new Map(t.map((i) => [i.id, i])), s = new Map(e.objects.map((i) => [i.id, i])), o = new Set(e.floors.map((i) => i.id));
1914
+ for (const i of t) {
1915
+ if (!St(i.position)) return "A route node needs a valid position.";
1916
+ if (i.floorId !== null && !o.has(i.floorId)) return "A route node references an unknown floor.";
1917
+ if (i.objectId !== void 0 && !s.has(i.objectId)) return "A route node references a missing object.";
1918
+ }
1919
+ for (const i of ln(e)) {
1920
+ if (!["walk", "door", "stairs", "elevator"].includes(i.kind)) return "Unknown route edge kind.";
1921
+ const a = n.get(i.aId), r = n.get(i.bId);
1922
+ if (!a || !r || i.aId === i.bId) return "A route edge must join two different route nodes.";
1923
+ if (i.weight !== void 0 && (typeof i.weight != "number" || !Number.isFinite(i.weight) || i.weight <= 0))
1924
+ return "A route edge weight must be a positive number.";
1925
+ const l = i.kind === "stairs" || i.kind === "elevator";
1926
+ if (l && a.floorId === r.floorId) return "Stairs and elevator edges must join different floors.";
1927
+ if (i.kind === "walk" && a.floorId !== r.floorId) return "Walk edges must stay on one floor.";
1928
+ if (i.kind === "door" && a.floorId !== r.floorId && a.floorId !== null && r.floorId !== null)
1929
+ return "Door edges must stay on one floor or step outside.";
1930
+ if (i.objectId === void 0) continue;
1931
+ const d = s.get(i.objectId);
1932
+ if (!d) return "A route edge references a missing object.";
1933
+ if (i.kind === "door" && !["door", "gate", "turnstile"].includes(d.kind))
1934
+ return "A door edge must bind a door, gate or turnstile.";
1935
+ if (l && d.kind !== i.kind) return "A vertical edge must bind a matching stairs or elevator object.";
1936
+ if (l && d.servedFloorIds && [a, r].some((u) => u.floorId !== null && !d.servedFloorIds.includes(u.floorId)))
1937
+ return "A vertical edge joins a floor its stairs or elevator does not serve.";
1938
+ }
1939
+ return null;
1940
+ }
1941
+ function Ae(e) {
1942
+ const t = (g) => {
1943
+ throw new Error(`Invalid project: ${g}`);
1944
+ };
1945
+ (!st(e) || e.schemaVersion !== 1) && t(
1946
+ "unsupported schema version (expected 1). The schema is still changing before release — re-create the project."
1947
+ );
1948
+ const n = e, s = (g) => Array.isArray(g) && (g.length === 2 || g.length === 3) && g.every(B) && Math.abs(g[0]) <= 180 && Math.abs(g[1]) <= 90;
1949
+ (!Y(n.id) || !Y(n.name) || !s(n.origin) || typeof n.description != "string" || typeof n.datum != "string" || !Y(n.updatedAt)) && t("missing project metadata.");
1950
+ for (const g of ["buildings", "floors", "junctions", "barriers", "objects", "drawings"])
1951
+ (!Array.isArray(n[g]) || n[g].some((y) => !st(y) || !Y(y.id))) && t(`malformed ${g}.`);
1952
+ for (const g of ["navNodes", "navEdges", "zones", "portals", "portalGroups", "virtualBoundaries"])
1953
+ n[g] !== void 0 && (!Array.isArray(n[g]) || n[g].some((y) => !st(y) || !Y(y.id))) && t(`malformed ${g}.`);
1954
+ const o = n, i = [
1955
+ ...o.buildings,
1956
+ ...o.floors,
1957
+ ...o.junctions,
1958
+ ...o.barriers,
1959
+ ...o.virtualBoundaries ?? [],
1960
+ ...o.objects,
1961
+ ...o.drawings,
1962
+ ...o.navNodes ?? [],
1963
+ ...o.navEdges ?? [],
1964
+ ...o.zones ?? [],
1965
+ ...o.portals ?? [],
1966
+ ...o.portalGroups ?? []
1967
+ ];
1968
+ new Set(i.map((g) => g.id)).size !== i.length && t("duplicate entity IDs.");
1969
+ const a = new Set(o.floors.map((g) => g.id)), r = new Set(o.buildings.map((g) => g.id));
1970
+ (!o.buildings.length || o.buildings.some(
1971
+ (g) => !Y(g.name) || g.sourceId !== void 0 && !Y(g.sourceId) && !B(g.sourceId)
1972
+ ) || !o.floors.length || o.floors.some(
1973
+ (g) => !r.has(g.buildingId) || !Y(g.name) || !B(g.elevation) || !B(g.height) || g.height <= 0
1974
+ )) && t("invalid buildings or floors."), o.objects.some((g) => g.travel !== void 0 && (g.kind !== "stairs" || g.travel !== "up" && g.travel !== "down")) && t("travel belongs to an escalator and must be up or down."), o.floors.some(
1975
+ (g) => g.light !== void 0 && (!B(g.light.kelvin) || g.light.kelvin < 1e3 || g.light.kelvin > 12e3 || !B(g.light.level) || g.light.level < 0 || g.light.level > 1 || g.light.tint !== void 0 && (typeof g.light.tint != "string" || !/^#[0-9a-f]{6}$/i.test(g.light.tint)))
1976
+ ) && t("a floor names a light that is not a lamp.");
1977
+ const l = (g) => g !== void 0 && (!so.includes(g.preset) || g.level !== void 0 && (!B(g.level) || g.level < 0 || g.level > 1));
1978
+ (o.floors.some((g) => l(g.ambience)) || o.objects.some((g) => l(g.ambience))) && t("an ambience names a preset that does not exist, or a level outside 0..1."), o.initialFloorId !== void 0 && o.initialFloorId !== null && !o.floors.some((g) => g.id === o.initialFloorId) && t("initialFloorId names a floor that does not exist."), o.buildings.some((g) => g.exteriorPreset !== void 0 && !Object.hasOwn(Lo, g.exteriorPreset)) && t("unknown exterior preset.");
1979
+ for (const g of [...o.junctions, ...o.barriers, ...o.objects, ...o.drawings])
1980
+ g.floorId !== null && !a.has(g.floorId) && t("unknown floor reference.");
1981
+ o.junctions.some((g) => !St(g.position)) && t("invalid junction coordinates.");
1982
+ for (const g of o.virtualBoundaries ?? []) {
1983
+ const y = o.junctions.find((_) => _.id === g.startId), M = o.junctions.find((_) => _.id === g.endId);
1984
+ (!y || !M || y.floorId !== g.floorId || M.floorId !== g.floorId || S(y.position, M.position) < 1e-3 - 1e-6) && t("invalid virtual boundary.");
1985
+ }
1986
+ o.barriers.some(
1987
+ (g) => !["wall", "fence"].includes(g.kind) || !Y(g.name) || !o.junctions.some((y) => y.id === g.startId && y.floorId === g.floorId) || !o.junctions.some((y) => y.id === g.endId && y.floorId === g.floorId) || g.startId === g.endId || !B(g.height) || g.height <= 0 || !B(g.thickness) || g.thickness <= 0
1988
+ ) && t("invalid barrier.");
1989
+ const d = /* @__PURE__ */ new Map();
1990
+ for (const g of o.objects)
1991
+ g.floorId && pt(g.kind) && Array.isArray(g.rings) && Array.isArray(g.rings[0]) && d.set(g.floorId, [...d.get(g.floorId) ?? [], g]);
1992
+ for (const g of o.objects) {
1993
+ if ((!oo.includes(g.kind) || !Y(g.name) || !St(g.position) || !B(g.rotation) || !B(g.width) || g.width <= 0 || !B(g.depth) || g.depth <= 0 || !B(g.height) || g.height < 0) && t("invalid object dimensions or type."), g.rings && (!Array.isArray(g.rings) || g.rings.some((y) => !Array.isArray(y) || y.some((M) => !St(M)))) && t("invalid polygon coordinates."), g.servedFloorIds && (!Array.isArray(g.servedFloorIds) || g.servedFloorIds.some((y) => !a.has(y))) && t("unknown served floor."), g.servedFloorIds && !Mt(g.servedFloorIds) && t("served floors must be listed once each."), g.servedFloorIds && (g.kind === "stairs" || g.kind === "elevator")) {
1994
+ const M = g.servedFloorIds.map((_) => d.get(_)).filter((_) => !!(_ != null && _.length)).map((_) => _.some(($) => D(g.position, $.rings[0])));
1995
+ M.some(Boolean) && !M.every(Boolean) && t("a stair or lift serves a level it does not stand on — its landing there opens onto nothing.");
1996
+ }
1997
+ if ((g.doorHinge !== void 0 || g.doorSwing !== void 0 || g.doorType !== void 0) && (g.kind !== "door" && t("only doors carry mechanism, hinge and swing settings."), g.doorType !== void 0 && !["hinged", "sliding", "double"].includes(g.doorType) && t("door type must be hinged, sliding or double."), g.doorHinge !== void 0 && !["left", "right"].includes(g.doorHinge) && t("door hinge must be left or right."), g.doorSwing !== void 0 && g.doorSwing !== 1 && g.doorSwing !== -1 && t("door swing must be 1 or -1.")), g.doorSides !== void 0 && (g.kind !== "elevator" && t("only an elevator lists door sides."), (!Array.isArray(g.doorSides) || !g.doorSides.length || g.doorSides.some((y) => !["front", "back", "left", "right"].includes(y)) || !Mt(g.doorSides)) && t("door sides are front, back, left or right, listed once each.")), g.wellGroup !== void 0 && (g.kind !== "stairs" || !Y(g.wellGroup) || !g.wellGroup.trim()) && t("only stairs carry a non-empty shared well group."), g.stairModel !== void 0 && (g.kind !== "stairs" && t("only stairs carry a stair model."), ["straight", "switchback", "dogleg", "spiral", "escalator"].includes(g.stairModel) || t("a stair model is straight, switchback, dogleg, spiral or escalator.")), g.light !== void 0 || g.kind === "light") {
1998
+ const y = g.light;
1999
+ (g.kind !== "light" || !st(y) || y.mountHeight !== void 0 && (!B(y.mountHeight) || y.mountHeight < -20 || y.mountHeight > 100) || !B(y.kelvin) || y.kelvin < 1e3 || y.kelvin > 12e3 || !B(y.intensity) || y.intensity < 0 || y.intensity > 1e4 || !B(y.range) || y.range <= 0 || y.range > 100 || y.flicker !== void 0 && (!B(y.flicker) || y.flicker < 0 || y.flicker > 1)) && t("a light needs a valid colour temperature, intensity, range and optional flicker.");
2000
+ }
2001
+ if (g.watchedIds && (!Array.isArray(g.watchedIds) || g.watchedIds.some((y) => !o.objects.some((M) => M.id === y))) && t("unknown watched object."), g.watchedIds && !Mt(g.watchedIds) && t("watched objects must be listed once each."), g.ceilingHeight !== void 0 && (!["room", "zone"].includes(g.kind) || !B(g.ceilingHeight) || g.ceilingHeight <= 0) && t("a space ceiling height must be positive."), g.baseHeight !== void 0 && (g.kind !== "fixture" || !B(g.baseHeight) || g.baseHeight < 0 || g.baseHeight > 100) && t("a raised fixture needs a base height between 0 and 100 m."), g.water !== void 0) {
2002
+ const y = g.water;
2003
+ (!["room", "zone"].includes(g.kind) || !g.rings || !st(y) || !B(y.depth) || y.depth <= 0 || y.depth > 20 || y.ripple !== void 0 && (!B(y.ripple) || y.ripple < 0 || y.ripple > 0.1)) && t("water needs an area, a depth up to 20 m and ripples up to 10 cm.");
2004
+ }
2005
+ if (g.slide !== void 0) {
2006
+ const y = g.slide;
2007
+ (g.kind !== "fixture" || !st(y) || !B(y.radius) || y.radius <= 0 || !Array.isArray(y.path) || y.path.length < 2 || y.path.length > 100 || !y.path.every((M) => Array.isArray(M) && M.length === 3 && M.every(B) && M[2] >= 0)) && t("a water slide needs a positive radius and a finite path above its floor.");
2008
+ }
2009
+ if (g.slope !== void 0) {
2010
+ const y = g.slope;
2011
+ (!st(y) || !Array.isArray(y.axis) || y.axis.length !== 2 || !y.axis.every(St) || !B(y.high) || !B(y.low) || S(y.axis[0], y.axis[1]) < 0.01 || y.high < y.low) && t("invalid slope: needs a downhill two-point axis (high >= low) of non-zero length."), g.rings || t("a sloped object must be an area with a footprint.");
2012
+ }
2013
+ g.category !== void 0 && !Y(g.category) && t("object category must be a string."), g.metadata !== void 0 && !st(g.metadata) && t("object metadata must be an object."), g.barrierId && !B(g.offset) && t("missing opening offset."), g.feedId !== void 0 && typeof g.feedId != "string" && t("invalid feed binding."), g.coverageRange !== void 0 && (!B(g.coverageRange) || g.coverageRange <= 0) && t("invalid camera range."), g.coverageAngle !== void 0 && (!B(g.coverageAngle) || g.coverageAngle <= 0 || g.coverageAngle > 360) && t("invalid camera angle.");
2014
+ }
2015
+ for (const g of o.drawings)
2016
+ (!Y(g.assetId) || !Y(g.name) || !St(g.origin) || !B(g.scale) || g.scale <= 0 || !B(g.width) || g.width <= 0 || !B(g.height) || g.height <= 0 || !B(g.rotation) || !B(g.opacity) || g.opacity < 0 || g.opacity > 1 || typeof g.visible != "boolean" || typeof g.locked != "boolean") && t("invalid reference drawing.");
2017
+ const u = new Set(o.objects.filter((g) => et(g.kind)).map((g) => g.id)), c = new Map(o.objects.map((g) => [g.id, g.kind])), f = new Set((o.zones ?? []).map((g) => g.id));
2018
+ for (const g of o.zones ?? [])
2019
+ (!Y(g.name) || !Array.isArray(g.spaceIds)) && t("a zone needs a name and a list of spaces."), g.spaceIds.some((y) => !u.has(y)) && t("a zone lists a space that is not an area object."), Mt(g.spaceIds) || t("a zone must list each space once — membership is a set."), g.childZoneIds && g.childZoneIds.some((y) => !f.has(y)) && t("a zone nests a zone that does not exist."), g.childZoneIds && !Mt(g.childZoneIds) && t("a zone must nest each child once."), g.connects !== void 0 && !["all", "adjacent", "up", "down"].includes(g.connects) && t("a zone's connects must be 'all', 'adjacent', 'up' or 'down'.");
2020
+ const h = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set(), m = (g) => {
2021
+ var M;
2022
+ if (p.has(g)) return !1;
2023
+ if (h.has(g)) return !0;
2024
+ h.add(g);
2025
+ const y = (((M = (o.zones ?? []).find((_) => _.id === g)) == null ? void 0 : M.childZoneIds) ?? []).some(m);
2026
+ return h.delete(g), p.add(g), y;
2027
+ };
2028
+ [...f].some(m) && t("zones cannot contain themselves.");
2029
+ for (const g of o.portals ?? [])
2030
+ (!u.has(g.a) || !u.has(g.b)) && t("a portal must join two areas that exist on the plan."), g.a === g.b && t("a portal must join two different spaces."), g.openingId && !["door", "gate", "turnstile"].includes(c.get(g.openingId) ?? "") && t("a portal's opening must be a door, gate or turnstile."), g.passage !== void 0 && !["both", "a-to-b", "b-to-a", "none"].includes(g.passage) && t("invalid portal passage direction."), g.attests !== void 0 && !["confirmed", "assumed", "none"].includes(g.attests) && t("invalid portal attestation.");
2031
+ const I = new Set((o.portals ?? []).map((g) => g.id));
2032
+ for (const g of o.portalGroups ?? [])
2033
+ (!Y(g.name) || !Array.isArray(g.portalIds) || g.portalIds.some((y) => !I.has(y))) && t("a portal group needs a name and must list portals that exist."), Mt(g.portalIds) || t("a portal group must list each portal once.");
2034
+ const b = Do(o);
2035
+ b && t(b), ns(o);
2036
+ const w = Uo(o);
2037
+ return w && t(w), o;
2038
+ }
2039
+ function Zo(e) {
2040
+ const t = (n) => {
2041
+ if (n && typeof n == "object" && !Object.isFrozen(n)) {
2042
+ Object.freeze(n);
2043
+ for (const s of Object.values(n)) t(s);
2044
+ }
2045
+ };
2046
+ return t(e), e;
2047
+ }
2048
+ function Ho(e, t, n) {
2049
+ try {
2050
+ const s = structuredClone(e);
2051
+ t(s), es(e, s);
2052
+ for (const o of s.objects)
2053
+ if (pt(o.kind) && nt(o) < kt) {
2054
+ const i = e.objects.find((a) => a.id === o.id && pt(a.kind));
2055
+ if (!i || nt(i) !== nt(o))
2056
+ throw new Error(
2057
+ `A space needs at least ${kt} m² of usable area. "${o.name || o.id}" (${o.id}) has ${nt(o).toFixed(3)} m².`
2058
+ );
2059
+ }
2060
+ return Ae(s), { ok: !0, project: (n == null ? void 0 : n.freeze) === !1 ? s : Zo(s) };
2061
+ } catch (s) {
2062
+ return { ok: !1, error: s instanceof Error ? s.message : String(s) };
2063
+ }
2064
+ }
2065
+ const Z = (e) => [...e.barriers, ...e.virtualBoundaries ?? []], Zs = (e) => {
2066
+ var t;
2067
+ return ((t = e.geometry) == null ? void 0 : t.mode) === "boundaries";
2068
+ }, ht = (e, t) => {
2069
+ const n = e.junctions.find((o) => o.id === t.startId), s = e.junctions.find((o) => o.id === t.endId);
2070
+ if (!n || !s) throw new Error("A space boundary references a missing junction.");
2071
+ return [n.position, s.position];
2072
+ }, gn = (e) => [...e].reverse().map((t) => ({ edgeId: t.edgeId, reversed: !t.reversed })), bt = (e) => e.reduce((t, n, s) => {
2073
+ const o = e[(s + 1) % e.length];
2074
+ return t + n[0] * o[1] - o[0] * n[1];
2075
+ }, 0) / 2, Q = (e) => V(e[0]) - e.slice(1).reduce((t, n) => t + V(n), 0), mn = (e) => e.reduce((t, n) => t + Q(n), 0), pn = (e) => e.map(
2076
+ (t) => C(t).map(
2077
+ (n) => [Math.round(n[0] * at) / at, Math.round(n[1] * at) / at]
2078
+ )
2079
+ );
2080
+ function _e(e, ...t) {
2081
+ const n = (a) => a.map((r) => C(r).map((l) => [Math.round(l[0] * at), Math.round(l[1] * at)])), s = n(e), o = t.map(n);
2082
+ let i;
2083
+ try {
2084
+ i = ct.difference(s, ...o);
2085
+ } catch {
2086
+ i = [s];
2087
+ for (const a of o) {
2088
+ if (!i.length) break;
2089
+ i = ct.difference(i, a);
2090
+ }
2091
+ }
2092
+ return i.map(
2093
+ (a) => a.map(
2094
+ (r) => r.map(
2095
+ (l) => [Math.round(l[0] / at * 1e10) / 1e10, Math.round(l[1] / at * 1e10) / 1e10]
2096
+ )
2097
+ )
2098
+ );
2099
+ }
2100
+ function Re(e, t, n) {
2101
+ var s;
2102
+ for (const o of e.objects)
2103
+ ((s = o.geometry) == null ? void 0 : s.mode) === "boundaries" && (o.geometry.loops = o.geometry.loops.map(
2104
+ (i) => i.flatMap((a) => a.edgeId !== t ? [a] : a.reversed ? gn(n) : n)
2105
+ ));
2106
+ }
2107
+ function At(e, t, n) {
2108
+ const s = new Map(Z(e).map((o) => [o.id, o]));
2109
+ return t.map((o) => {
2110
+ if (o.length < 3) throw new Error("A space boundary must form a closed loop.");
2111
+ const i = [];
2112
+ for (let a = 0; a < o.length; a++) {
2113
+ const r = o[a], l = o[(a + 1) % o.length], d = s.get(r.edgeId), u = s.get(l.edgeId);
2114
+ if (!d || !u || d.floorId !== n || u.floorId !== n)
2115
+ throw new Error("A space boundary references a missing edge or another floor.");
2116
+ if ((r.reversed ? d.startId : d.endId) !== (l.reversed ? u.endId : u.startId))
2117
+ throw new Error("Space boundary edges must share their junctions in order.");
2118
+ i.push(ht(e, d)[r.reversed ? 1 : 0]);
2119
+ }
2120
+ return C(i);
2121
+ });
2122
+ }
2123
+ function In(e, t, n) {
2124
+ const [s, o] = ht(e, t), i = S(s, o), a = n.filter((f) => f.t > N / i && f.t < 1 - N / i).sort((f, h) => f.t - h.t), r = a.filter((f, h) => h === 0 || f.id !== a[h - 1].id);
2125
+ if (!r.length) return;
2126
+ const l = [{ t: 0, id: t.startId }, ...r, { t: 1, id: t.endId }], d = e.objects.filter((f) => f.barrierId === t.id);
2127
+ for (const f of r)
2128
+ for (const h of d)
2129
+ if (Math.abs((h.offset ?? 0) - f.t * i) < h.width / 2 - N)
2130
+ throw new Error("A junction cannot split an opening.");
2131
+ const u = "kind" in t, c = l.slice(1).map((f, h) => {
2132
+ const p = l[h];
2133
+ if ((f.t - p.t) * i < (u ? un : ne) - N)
2134
+ throw new Error(
2135
+ `That crossing would leave a boundary segment too short. "${"name" in t ? t.name : t.id}" would be ${((f.t - p.t) * i).toFixed(4)} m long.`
2136
+ );
2137
+ return { ...t, id: h === 0 ? t.id : H(), startId: p.id, endId: f.id };
2138
+ });
2139
+ for (const f of d) {
2140
+ const h = (f.offset ?? 0) / i, p = l.slice(1).findIndex((m) => h <= m.t + N);
2141
+ f.barrierId = c[p].id, f.offset = (f.offset ?? 0) - l[p].t * i;
2142
+ }
2143
+ Re(
2144
+ e,
2145
+ t.id,
2146
+ c.map((f) => ({ edgeId: f.id }))
2147
+ ), Object.assign(t, c[0]), u ? e.barriers.push(...c.slice(1)) : (e.virtualBoundaries ?? (e.virtualBoundaries = [])).push(...c.slice(1));
2148
+ }
2149
+ function Tt(e, t) {
2150
+ const n = Z(e).filter((h) => h.floorId === t), s = e.junctions.filter((h) => h.floorId === t), o = /* @__PURE__ */ new Map(), i = [];
2151
+ for (const h of s) {
2152
+ const p = i.find((m) => S(m.position, h.position) <= N);
2153
+ p ? o.set(h.id, p.id) : i.push(h);
2154
+ }
2155
+ for (const h of n)
2156
+ h.startId = o.get(h.startId) ?? h.startId, h.endId = o.get(h.endId) ?? h.endId;
2157
+ e.junctions = e.junctions.filter((h) => !o.has(h.id));
2158
+ const a = new Map(e.junctions.map((h) => [h.id, h.position])), r = n.map((h) => ({
2159
+ points: [a.get(h.startId), a.get(h.endId)],
2160
+ box: ye([a.get(h.startId), a.get(h.endId)])
2161
+ })), l = /* @__PURE__ */ new Map(), d = (h, p) => {
2162
+ const [m, I] = ht(e, h), b = G(p, m, I);
2163
+ let w = e.junctions.find((y) => y.floorId === t && S(y.position, p) <= N);
2164
+ w || (w = { id: H(), floorId: t, position: p }, e.junctions.push(w));
2165
+ const g = l.get(h.id) ?? [];
2166
+ g.push({ t: b.t, id: w.id }), l.set(h.id, g);
2167
+ };
2168
+ for (let h = 0; h < n.length; h++)
2169
+ for (let p = h + 1; p < n.length; p++) {
2170
+ if (!bn(r[h].box, r[p].box)) continue;
2171
+ const m = n[h], I = n[p], [b, w] = r[h].points, [g, y] = r[p].points, M = w[0] - b[0], _ = w[1] - b[1], $ = y[0] - g[0], x = y[1] - g[1], E = M * x - _ * $;
2172
+ if (!(m.startId === I.startId || m.startId === I.endId || m.endId === I.startId || m.endId === I.endId) && Math.abs(E) > 1e-12 * Math.hypot(M, _) * Math.hypot($, x)) {
2173
+ const v = ((g[0] - b[0]) * x - (g[1] - b[1]) * $) / E, k = ((g[0] - b[0]) * _ - (g[1] - b[1]) * M) / E;
2174
+ if (v >= -N / Math.hypot(M, _) && v <= 1 + N / Math.hypot(M, _) && k >= -N / Math.hypot($, x) && k <= 1 + N / Math.hypot($, x)) {
2175
+ const R = [b[0] + Math.max(0, Math.min(1, v)) * M, b[1] + Math.max(0, Math.min(1, v)) * _];
2176
+ d(m, R), d(I, R);
2177
+ }
2178
+ } else {
2179
+ for (const v of [b, w])
2180
+ G(v, g, y).distance <= N && (d(m, v), d(I, v));
2181
+ for (const v of [g, y])
2182
+ G(v, b, w).distance <= N && (d(m, v), d(I, v));
2183
+ }
2184
+ }
2185
+ for (const h of n) In(e, h, l.get(h.id) ?? []);
2186
+ const u = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
2187
+ for (const h of Z(e).filter((p) => p.floorId === t)) {
2188
+ const p = [h.startId, h.endId].sort().join("|"), m = u.get(p);
2189
+ if (!m) {
2190
+ u.set(p, h);
2191
+ continue;
2192
+ }
2193
+ const I = h.startId !== m.startId;
2194
+ Re(e, h.id, [{ edgeId: m.id, reversed: I }]);
2195
+ for (const b of e.objects.filter((w) => w.barrierId === h.id))
2196
+ b.barrierId = m.id, I && (b.offset = S(...ht(e, m)) - (b.offset ?? 0), b.kind === "door" && (b.doorHinge = b.doorHinge === "right" ? "left" : "right", b.doorSwing = b.doorSwing === -1 ? 1 : -1));
2197
+ c.add(h.id);
2198
+ }
2199
+ e.barriers = e.barriers.filter((h) => !c.has(h.id)), e.virtualBoundaries && (e.virtualBoundaries = e.virtualBoundaries.filter((h) => !c.has(h.id)));
2200
+ const f = new Set(Z(e).flatMap((h) => [h.startId, h.endId]));
2201
+ e.junctions = e.junctions.filter((h) => !o.has(h.id) || f.has(h.id));
2202
+ }
2203
+ function oe(e, t) {
2204
+ const n = Z(e).filter((h) => h.floorId === t), s = /* @__PURE__ */ new Map();
2205
+ for (const h of n)
2206
+ for (const [p, m] of [
2207
+ [h.startId, h.endId],
2208
+ [h.endId, h.startId]
2209
+ ]) {
2210
+ const I = s.get(p) ?? [];
2211
+ I.push({ edge: h, to: m }), s.set(p, I);
2212
+ }
2213
+ const o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
2214
+ let r = 0;
2215
+ const l = (h, p) => {
2216
+ o.set(h, ++r), i.set(h, r);
2217
+ for (const { edge: m, to: I } of s.get(h) ?? [])
2218
+ m.id !== p && (o.has(I) ? i.set(h, Math.min(i.get(h), o.get(I))) : (l(I, m.id), i.set(h, Math.min(i.get(h), i.get(I))), i.get(I) > o.get(h) && a.add(m.id)));
2219
+ };
2220
+ for (const h of s.keys()) o.has(h) || l(h);
2221
+ const d = new Map(e.junctions.map((h) => [h.id, h.position]));
2222
+ for (const [h, p] of s) {
2223
+ const m = d.get(h);
2224
+ s.set(
2225
+ h,
2226
+ p.filter((I) => !a.has(I.edge.id)).sort((I, b) => {
2227
+ const w = d.get(I.to), g = d.get(b.to);
2228
+ return Math.atan2(w[1] - m[1], w[0] - m[0]) - Math.atan2(g[1] - m[1], g[0] - m[0]);
2229
+ })
2230
+ );
2231
+ }
2232
+ const u = /* @__PURE__ */ new Set(), c = [];
2233
+ for (const h of n.filter((p) => !a.has(p.id)))
2234
+ for (const p of [!1, !0]) {
2235
+ let m = { edgeId: h.id, reversed: p }, I = h;
2236
+ const b = `${h.id}:${p}`, w = [], g = [];
2237
+ if (!u.has(b)) {
2238
+ for (let y = 0; y <= n.length * 2; y++) {
2239
+ const M = `${m.edgeId}:${!!m.reversed}`;
2240
+ if (u.has(M)) break;
2241
+ u.add(M), w.push(m);
2242
+ const _ = m.reversed ? I.endId : I.startId, $ = m.reversed ? I.startId : I.endId;
2243
+ g.push(d.get(_));
2244
+ const x = s.get($), E = x.findIndex((v) => v.edge.id === I.id);
2245
+ if (I = x[(E + x.length - 1) % x.length].edge, m = { edgeId: I.id, reversed: I.endId === $ }, `${m.edgeId}:${!!m.reversed}` === b) break;
2246
+ }
2247
+ bt(g) >= ke && c.push({ loop: w, ring: C(g) });
2248
+ }
2249
+ }
2250
+ const f = c.map(
2251
+ (h, p) => {
2252
+ var m;
2253
+ return (m = c.map((I, b) => ({ j: b, candidate: I })).filter(
2254
+ ({ candidate: I, j: b }) => b !== p && V(I.ring) > V(h.ring) + N && h.ring.every((w) => D(w, I.ring)) && !h.loop.some((w) => I.loop.some((g) => g.edgeId === w.edgeId))
2255
+ ).sort((I, b) => V(I.candidate.ring) - V(b.candidate.ring))[0]) == null ? void 0 : m.j;
2256
+ }
2257
+ );
2258
+ return c.map((h, p) => {
2259
+ const m = c.filter((I, b) => f[b] === p);
2260
+ return {
2261
+ loops: [h.loop, ...m.map((I) => gn(I.loop))],
2262
+ rings: [h.ring, ...m.map((I) => C([...T(I.ring)].reverse()))]
2263
+ };
2264
+ });
2265
+ }
2266
+ function Wo(e, t) {
2267
+ const n = new Map(e.junctions.map((o) => [o.id, o.position])), s = e.barriers.filter((o) => o.floorId === t).map((o) => ({
2268
+ points: [n.get(o.startId), n.get(o.endId)],
2269
+ thickness: o.thickness
2270
+ }));
2271
+ for (let o = 0; o < s.length; o++) {
2272
+ let i = !0;
2273
+ for (; i; ) {
2274
+ i = !1;
2275
+ for (let a = o + 1; a < s.length; a++) {
2276
+ const r = s[o], l = s[a];
2277
+ if (r.thickness !== l.thickness) continue;
2278
+ const [d, u] = r.points, [c, f] = l.points, h = S(d, u), p = S(c, f);
2279
+ if (Math.abs((u[0] - d[0]) * (f[1] - c[1]) - (u[1] - d[1]) * (f[0] - c[0])) > N * h * p) continue;
2280
+ const m = [
2281
+ [d, c, u, f],
2282
+ [d, f, u, c],
2283
+ [u, c, d, f],
2284
+ [u, f, d, c]
2285
+ ].find(([I, b]) => S(I, b) <= N);
2286
+ if (m) {
2287
+ r.points = [m[2], m[3]], s.splice(a, 1), i = !0;
2288
+ break;
2289
+ }
2290
+ }
2291
+ }
2292
+ }
2293
+ return s.map(({ points: [o, i], thickness: a }) => {
2294
+ (o[0] > i[0] || o[0] === i[0] && o[1] > i[1]) && ([o, i] = [i, o]);
2295
+ const r = S(o, i);
2296
+ return pn([
2297
+ Zt(
2298
+ [(o[0] + i[0]) / 2, (o[1] + i[1]) / 2],
2299
+ r + a,
2300
+ a,
2301
+ Math.atan2(i[1] - o[1], i[0] - o[0]) * 180 / Math.PI
2302
+ )
2303
+ ]);
2304
+ });
2305
+ }
2306
+ function jo(e) {
2307
+ const t = [];
2308
+ for (const n of T(e)) (!t.length || S(t.at(-1), n) >= N) && t.push(n);
2309
+ return t.length > 1 && S(t[0], t.at(-1)) < N && t.pop(), C(t);
2310
+ }
2311
+ const ye = (e) => {
2312
+ let t = 1 / 0, n = 1 / 0, s = -1 / 0, o = -1 / 0;
2313
+ for (const [i, a] of e)
2314
+ t = Math.min(t, i), n = Math.min(n, a), s = Math.max(s, i), o = Math.max(o, a);
2315
+ return { minX: t, minY: n, maxX: s, maxY: o };
2316
+ }, bn = (e, t) => e.minX <= t.maxX + N && e.maxX + N >= t.minX && e.minY <= t.maxY + N && e.maxY + N >= t.minY;
2317
+ function Pe(e) {
2318
+ const t = /* @__PURE__ */ new Map();
2319
+ return (n, s, o = !1) => {
2320
+ let i = t.get(n);
2321
+ i || (i = Wo(e, n).map((l) => ({ rings: l, box: ye(l[0]) })), t.set(n, i));
2322
+ const a = ye(s[0]), r = i.filter((l) => bn(l.box, a)).map((l) => l.rings);
2323
+ return Yo(s, r, o);
2324
+ };
2325
+ }
2326
+ function Yo(e, t, n = !1) {
2327
+ const s = t.length ? _e(e, ...t) : [pn(e)], o = s.filter((i) => Q(i) >= kt);
2328
+ if (!o.length && n) return [];
2329
+ if (!o.length)
2330
+ throw new Error(
2331
+ `A space needs at least ${kt} m² of usable area. Largest region after subtracting walls: ${Math.max(0, ...s.map((i) => Q(i))).toFixed(3)} m².`
2332
+ );
2333
+ if (o.length !== 1)
2334
+ throw new Error(
2335
+ `The wall would leave ${o.length} disconnected usable regions (${o.map((i) => Q(i).toFixed(2)).join(", ")} m²). Extend it to a boundary to divide the space.`
2336
+ );
2337
+ return o[0].map(jo);
2338
+ }
2339
+ function se(e, t) {
2340
+ var n;
2341
+ return ((n = t.geometry) == null ? void 0 : n.mode) !== "boundaries" ? W(t) : Pe(e)(t.floorId, At(e, t.geometry.loops, t.floorId));
2342
+ }
2343
+ function Ct(e, t) {
2344
+ e.rings = t, e.position = vt(t[0]), e.rotation = 0;
2345
+ const n = t[0].map((o) => o[0]), s = t[0].map((o) => o[1]);
2346
+ e.width = Math.max(...n) - Math.min(...n), e.depth = Math.max(...s) - Math.min(...s);
2347
+ }
2348
+ function yn(e, t, n) {
2349
+ if (!pt(t.kind)) throw new Error("Only a drawn area can use shared boundaries.");
2350
+ t.geometry = { mode: "boundaries", loops: structuredClone(n.loops) }, Ct(t, se(e, t));
2351
+ }
2352
+ function Vo(e, t, n) {
2353
+ return oe(e, t).filter((s) => D(n, s.rings[0]) && !s.rings.slice(1).some((o) => D(n, o))).sort((s, o) => Q(s.rings) - Q(o.rings))[0] ?? null;
2354
+ }
2355
+ function we(e, t, n) {
2356
+ const s = e.junctions.find((i) => i.floorId === t && S(i.position, n) <= N);
2357
+ if (s) return s.id;
2358
+ const o = H();
2359
+ return e.junctions.push({ id: o, floorId: t, position: n }), o;
2360
+ }
2361
+ function Ut(e, t, n, s) {
2362
+ if (S(n, s) < ne) throw new Error("A space boundary is too short.");
2363
+ const o = we(e, t, n), i = we(e, t, s), a = Z(e).find(
2364
+ (l) => l.floorId === t && (l.startId === o && l.endId === i || l.startId === i && l.endId === o)
2365
+ );
2366
+ if (a) return a.id;
2367
+ const r = H();
2368
+ return (e.virtualBoundaries ?? (e.virtualBoundaries = [])).push({ id: r, floorId: t, startId: o, endId: i }), r;
2369
+ }
2370
+ function Xo(e, t, n, s) {
2371
+ const o = S(n, s);
2372
+ if (o < ne) throw new Error("A space boundary is too short.");
2373
+ const i = (a) => Math.abs((s[0] - n[0]) * (a[1] - n[1]) - (s[1] - n[1]) * (a[0] - n[0])) / o <= N;
2374
+ for (const a of [...e.barriers].filter((r) => r.floorId === t)) {
2375
+ const [r, l] = ht(e, a);
2376
+ if (!i(r) || !i(l)) continue;
2377
+ const d = [n, s].flatMap((u) => {
2378
+ const c = G(u, r, l);
2379
+ return c.distance <= N && c.t > 0 && c.t < 1 ? [{ t: c.t, id: we(e, t, c.point) }] : [];
2380
+ });
2381
+ In(e, a, d);
2382
+ }
2383
+ for (const a of [...e.barriers].filter((r) => r.floorId === t))
2384
+ ht(e, a).every((r) => G(r, n, s).distance <= N) && ((e.virtualBoundaries ?? (e.virtualBoundaries = [])).push({ id: a.id, floorId: t, startId: a.startId, endId: a.endId }), En(e, a.id));
2385
+ return Ut(e, t, n, s);
2386
+ }
2387
+ function qo(e, t, n = "outline") {
2388
+ var i;
2389
+ const s = e.objects.find((a) => a.id === t);
2390
+ if (!s || !pt(s.kind)) throw new Error("Select an area to connect to boundaries.");
2391
+ if (n === "walls") {
2392
+ Tt(e, s.floorId);
2393
+ const a = W(s), r = Q(a), l = oe(e, s.floorId).map((u) => ({
2394
+ region: u,
2395
+ overlap: r - mn(_e(a, u.rings))
2396
+ })).filter((u) => u.overlap > N).sort((u, c) => c.overlap - u.overlap);
2397
+ if (l.length > 1 && Math.abs(l[0].overlap - l[1].overlap) < N)
2398
+ throw new Error("More than one region matches this outline. Use Space from walls inside the intended region.");
2399
+ const d = (i = l[0]) == null ? void 0 : i.region;
2400
+ if (!d) throw new Error("No closed wall boundary surrounds this space.");
2401
+ yn(e, s, d);
2402
+ return;
2403
+ }
2404
+ const o = W(s).map((a, r) => {
2405
+ let l = T(a);
2406
+ return bt(l) > 0 != (r === 0) && (l = [...l].reverse()), l.map((d, u) => {
2407
+ const c = l[(u + 1) % l.length], f = Ut(e, s.floorId, d, c), h = Z(e).find((p) => p.id === f);
2408
+ return { edgeId: f, reversed: S(ht(e, h)[0], d) > N };
2409
+ });
2410
+ });
2411
+ s.geometry = { mode: "boundaries", loops: o }, Tt(e, s.floorId), Ct(s, se(e, s));
2412
+ }
2413
+ function Jo(e, t) {
2414
+ const n = e.objects.find((s) => s.id === t);
2415
+ n && (n.geometry = { mode: "independent" });
2416
+ }
2417
+ function Ko(e, t, n) {
2418
+ var i;
2419
+ if (((i = t.geometry) == null ? void 0 : i.mode) !== "boundaries") throw new Error("Select a space with shared boundaries.");
2420
+ let s = T(n);
2421
+ bt(s) > 0 && (s = [...s].reverse());
2422
+ const o = s.map((a, r) => {
2423
+ const l = Ut(e, t.floorId, a, s[(r + 1) % s.length]), d = Z(e).find((u) => u.id === l);
2424
+ return { edgeId: l, reversed: S(ht(e, d)[0], a) > N };
2425
+ });
2426
+ t.geometry.loops.push(o);
2427
+ }
2428
+ function Qo(e, t, n, s, o = !0) {
2429
+ var c;
2430
+ if (((c = t.geometry) == null ? void 0 : c.mode) !== "boundaries") throw new Error("This space has no shared boundaries.");
2431
+ const i = S(n, s);
2432
+ if (i < N) throw new Error("Draw a line across the space.");
2433
+ const a = (s[0] - n[0]) / i, r = (s[1] - n[1]) / i, l = [];
2434
+ for (const f of At(e, t.geometry.loops, t.floorId)) {
2435
+ const h = T(f);
2436
+ for (let p = 0; p < h.length; p++) {
2437
+ const m = h[p], I = h[(p + 1) % h.length], b = I[0] - m[0], w = I[1] - m[1], g = a * w - r * b;
2438
+ if (Math.abs(g) < 1e-12) continue;
2439
+ const y = ((m[0] - n[0]) * r - (m[1] - n[1]) * a) / g;
2440
+ y >= -N && y <= 1 + N && l.push(((m[0] - n[0]) * w - (m[1] - n[1]) * b) / g);
2441
+ }
2442
+ }
2443
+ l.sort((f, h) => f - h);
2444
+ const d = l.filter((f, h) => h === 0 || f - l[h - 1] > N);
2445
+ for (let f = 0; f + 1 < d.length; f += 2) {
2446
+ const h = [n[0] + d[f] * a, n[1] + d[f] * r], p = [n[0] + d[f + 1] * a, n[1] + d[f + 1] * r];
2447
+ if (o) {
2448
+ const m = ie(e, h, p, t.floorId, "wall");
2449
+ m && (m.name = "Partition", m.thickness = 0.18);
2450
+ } else Ut(e, t.floorId, h, p);
2451
+ }
2452
+ Tt(e, t.floorId);
2453
+ const u = vn(e);
2454
+ if (!u.length) throw new Error("The cut must divide the space into usable regions.");
2455
+ return u[0];
2456
+ }
2457
+ function ts(e, t, n) {
2458
+ var d, u;
2459
+ if (((d = t.geometry) == null ? void 0 : d.mode) !== "boundaries" || ((u = n.geometry) == null ? void 0 : u.mode) !== "boundaries")
2460
+ throw new Error("Connect both spaces to shared boundaries before merging their boundaries.");
2461
+ const s = t.geometry.loops.flat(), o = n.geometry.loops.flat(), i = new Set(
2462
+ s.filter((c) => o.some((f) => f.edgeId === c.edgeId && !!f.reversed != !!c.reversed)).map((c) => c.edgeId)
2463
+ );
2464
+ if (!i.size) return !1;
2465
+ if (e.barriers.some((c) => i.has(c.id))) throw new Error("Remove the dividing wall before merging these spaces.");
2466
+ const a = new Map(Z(e).map((c) => [c.id, c])), r = [...s, ...o].filter((c) => !i.has(c.edgeId)), l = [];
2467
+ for (; r.length; ) {
2468
+ const c = [r.shift()], f = a.get(c[0].edgeId), h = c[0].reversed ? f.endId : f.startId;
2469
+ let p = c[0].reversed ? f.startId : f.endId;
2470
+ for (; p !== h; ) {
2471
+ const m = r.findIndex((w) => {
2472
+ const g = a.get(w.edgeId);
2473
+ return (w.reversed ? g.endId : g.startId) === p;
2474
+ });
2475
+ if (m < 0) throw new Error("The merged space boundary is not closed.");
2476
+ const I = r.splice(m, 1)[0], b = a.get(I.edgeId);
2477
+ c.push(I), p = I.reversed ? b.startId : b.endId;
2478
+ }
2479
+ l.push(c);
2480
+ }
2481
+ return l.sort(
2482
+ (c, f) => bt(T(At(e, [f], t.floorId)[0])) - bt(T(At(e, [c], t.floorId)[0]))
2483
+ ), t.geometry = { mode: "boundaries", loops: l }, e.virtualBoundaries = (e.virtualBoundaries ?? []).filter(
2484
+ (c) => !i.has(c.id) || e.objects.some(
2485
+ (f) => {
2486
+ var h;
2487
+ return f.id !== n.id && ((h = f.geometry) == null ? void 0 : h.mode) === "boundaries" && f.geometry.loops.some((p) => p.some((m) => m.edgeId === c.id));
2488
+ }
2489
+ )
2490
+ ), Ct(t, se(e, t)), !0;
2491
+ }
2492
+ function wn(e, t) {
2493
+ e.objects.some(
2494
+ (n) => {
2495
+ var s;
2496
+ return ((s = n.geometry) == null ? void 0 : s.mode) === "boundaries" && n.geometry.loops.some((o) => o.some((i) => i.edgeId === t.id));
2497
+ }
2498
+ ) && ((e.virtualBoundaries ?? []).some((n) => n.id === t.id) || (e.virtualBoundaries ?? (e.virtualBoundaries = [])).push({ id: t.id, floorId: t.floorId, startId: t.startId, endId: t.endId }));
2499
+ }
2500
+ function vn(e, t) {
2501
+ var i;
2502
+ const n = [], s = /* @__PURE__ */ new Map(), o = Pe(e);
2503
+ for (const a of [...e.objects]) {
2504
+ if (((i = a.geometry) == null ? void 0 : i.mode) !== "boundaries") continue;
2505
+ const r = At(e, a.geometry.loops, a.floorId);
2506
+ if (t && !t.has(a.floorId)) {
2507
+ Ct(a, o(a.floorId, r));
2508
+ continue;
2509
+ }
2510
+ s.has(a.floorId) || s.set(a.floorId, oe(e, a.floorId));
2511
+ const l = s.get(a.floorId).filter((u) => mn(_e(u.rings, r)) < N);
2512
+ if (!l.length) throw new Error("The space boundaries no longer form a closed region.");
2513
+ l.sort((u, c) => Q(c.rings) - Q(u.rings));
2514
+ const d = l.map((u) => ({ region: u, rings: o(a.floorId, u.rings, l.length > 1) })).filter((u) => u.rings.length).sort((u, c) => Q(c.rings) - Q(u.rings));
2515
+ if (!d.length) throw new Error("The walls would remove all usable area from this space.");
2516
+ for (let u = 0; u < d.length; u++) {
2517
+ const c = u === 0 ? a : { ...structuredClone(a), id: H(), name: `${a.name} ${u + 1}`, feedId: void 0 };
2518
+ if (c.geometry = { mode: "boundaries", loops: structuredClone(d[u].region.loops) }, Ct(c, d[u].rings), u > 0) {
2519
+ e.objects.push(c), n.push(c.id);
2520
+ for (const f of e.zones ?? []) f.spaceIds.includes(a.id) && f.spaceIds.push(c.id);
2521
+ }
2522
+ }
2523
+ }
2524
+ return n;
2525
+ }
2526
+ function es(e, t) {
2527
+ for (const l of ["barriers", "junctions", "objects", "virtualBoundaries", "zones"]) {
2528
+ const d = t[l];
2529
+ d && (Object.isFrozen(d) || d.some((u) => Object.isFrozen(u))) && Object.assign(t, { [l]: structuredClone(d) });
2530
+ }
2531
+ const n = Z(t), s = new Set(n.map((l) => l.id));
2532
+ for (const l of Z(e))
2533
+ if (!s.has(l.id) && (wn(t, l), (t.virtualBoundaries ?? []).some((d) => d.id === l.id))) {
2534
+ for (const d of [l.startId, l.endId])
2535
+ if (!t.junctions.some((u) => u.id === d)) {
2536
+ const u = e.junctions.find((c) => c.id === d);
2537
+ u && t.junctions.push(structuredClone(u));
2538
+ }
2539
+ }
2540
+ const o = (l, d) => JSON.stringify([
2541
+ Z(l).filter((u) => u.floorId === d).map((u) => [u.id, u.startId, u.endId]),
2542
+ l.junctions.filter((u) => u.floorId === d).map((u) => [u.id, u.position])
2543
+ ]), i = new Set(Z(t).map((l) => l.floorId));
2544
+ for (const l of i) o(e, l) !== o(t, l) && Tt(t, l);
2545
+ const a = (l, d) => JSON.stringify(
2546
+ Z(l).filter((u) => u.floorId === d).map((u) => [u.id, u.startId, u.endId])
2547
+ ), r = new Set([...i].filter((l) => a(e, l) !== a(t, l)));
2548
+ vn(t, r);
2549
+ }
2550
+ function ns(e) {
2551
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), s = Pe(e), o = (i) => i.flat().map((a) => `${a.edgeId}:${!!a.reversed}`).sort().join("|");
2552
+ for (const i of e.objects) {
2553
+ if (i.geometry === void 0) continue;
2554
+ if (!i.geometry || !["independent", "boundaries"].includes(i.geometry.mode))
2555
+ throw new Error("Unknown space geometry mode.");
2556
+ if (i.geometry.mode === "independent") continue;
2557
+ if (!pt(i.kind) || !Array.isArray(i.geometry.loops) || !i.geometry.loops.length || i.geometry.loops.some(
2558
+ (c) => !Array.isArray(c) || c.some(
2559
+ (f) => !f || typeof f.edgeId != "string" || f.reversed !== void 0 && typeof f.reversed != "boolean"
2560
+ )
2561
+ ))
2562
+ throw new Error("Malformed space boundary loops.");
2563
+ const a = At(e, i.geometry.loops, i.floorId), r = hn(a, N, ke);
2564
+ if (r) throw new Error(r);
2565
+ if (bt(T(a[0])) <= 0 || a.slice(1).some((c) => bt(T(c)) >= 0))
2566
+ throw new Error("Space boundary loops must keep the space on their left.");
2567
+ if (n.has(i.floorId) || n.set(i.floorId, new Set(oe(e, i.floorId).map((c) => o(c.loops)))), !n.get(i.floorId).has(o(i.geometry.loops)))
2568
+ throw new Error("A connected space must follow one face of the boundary network.");
2569
+ for (const c of i.geometry.loops)
2570
+ for (const f of c) {
2571
+ const h = `${f.edgeId}:${!!f.reversed}`;
2572
+ if (t.has(h)) throw new Error("Two spaces cannot occupy the same side of a shared boundary.");
2573
+ t.add(h);
2574
+ }
2575
+ const l = s(i.floorId, a);
2576
+ if (!i.rings || l.length !== i.rings.length || l.some(
2577
+ (c, f) => c.length !== i.rings[f].length || c.some((h, p) => S(h, i.rings[f][p]) > N)
2578
+ ))
2579
+ throw new Error("The space footprint is stale. Update it through a geometry transaction.");
2580
+ const d = l[0].map((c) => c[0]), u = l[0].map((c) => c[1]);
2581
+ if (S(i.position, vt(l[0])) > N || Math.abs(i.width - (Math.max(...d) - Math.min(...d))) > N || Math.abs(i.depth - (Math.max(...u) - Math.min(...u))) > N || i.rotation !== 0)
2582
+ throw new Error("A boundary-driven space has stale calculated dimensions.");
2583
+ }
2584
+ }
2585
+ const S = (e, t) => Math.hypot(e[0] - t[0], e[1] - t[1]), Lt = (e, t) => {
2586
+ const n = t * Math.PI / 180;
2587
+ return [e[0] * Math.cos(n) - e[1] * Math.sin(n), e[0] * Math.sin(n) + e[1] * Math.cos(n)];
2588
+ }, Wt = Math.PI / 180, Xe = 6378137, ue = 0.00669437999014, $e = (e) => {
2589
+ const t = Math.sin(e * Wt) ** 2;
2590
+ return {
2591
+ lng: Wt * (Xe / Math.sqrt(1 - ue * t)) * Math.cos(e * Wt),
2592
+ lat: Wt * (Xe * (1 - ue)) / (1 - ue * t) ** 1.5
2593
+ };
2594
+ }, Hs = (e, t = 0) => t ? [e[0], e[1], t] : [e[0], e[1]], Ws = (e, t, n) => {
2595
+ const s = $e(e[1]), o = [e[0] + t / s.lng, e[1] + n / s.lat];
2596
+ return e[2] ? [o[0], o[1], e[2]] : o;
2597
+ }, js = (e, t) => {
2598
+ const n = $e(t[1]), s = [(e[0] - t[0]) * n.lng, (e[1] - t[1]) * n.lat];
2599
+ return t[2] ? Lt(s, t[2]) : s;
2600
+ }, Ys = (e, t) => {
2601
+ const n = $e(t[1]), s = t[2] ? Lt(e, -t[2]) : e;
2602
+ return [t[0] + s[0] / n.lng, t[1] + s[1] / n.lat];
2603
+ }, os = (e, t) => [e[0] + t[0], e[1] + t[1]], C = (e) => e.length ? S(e[0], e[e.length - 1]) < 1e-8 ? e : [...e, e[0]] : [], T = (e) => e.length > 1 && S(e[0], e[e.length - 1]) < 1e-8 ? e.slice(0, -1) : e, V = (e) => Math.abs(
2604
+ e.reduce((t, n, s) => {
2605
+ const o = e[(s + 1) % e.length];
2606
+ return t + n[0] * o[1] - o[0] * n[1];
2607
+ }, 0)
2608
+ ) / 2, nt = (e) => e.rings ? V(e.rings[0]) - e.rings.slice(1).reduce((t, n) => t + V(n), 0) : e.width * e.depth, vt = (e) => {
2609
+ const t = T(e);
2610
+ return [t.reduce((n, s) => n + s[0], 0) / t.length, t.reduce((n, s) => n + s[1], 0) / t.length];
2611
+ }, Zt = (e, t, n, s = 0) => C(
2612
+ [
2613
+ [-t / 2, -n / 2],
2614
+ [t / 2, -n / 2],
2615
+ [t / 2, n / 2],
2616
+ [-t / 2, n / 2]
2617
+ ].map((o) => os(e, Lt(o, s)))
2618
+ );
2619
+ function ss(e, t, n, s) {
2620
+ const o = (u, c, f) => (c[0] - u[0]) * (f[1] - u[1]) - (c[1] - u[1]) * (f[0] - u[0]), [i, a, r, l] = [o(e, t, n), o(e, t, s), o(n, s, e), o(n, s, t)], d = 1e-9;
2621
+ return (i > d && a < -d || i < -d && a > d) && (r > d && l < -d || r < -d && l > d);
2622
+ }
2623
+ function G(e, t, n) {
2624
+ const s = S(t, n), o = s ? Math.max(0, Math.min(1, ((e[0] - t[0]) * (n[0] - t[0]) + (e[1] - t[1]) * (n[1] - t[1])) / s ** 2)) : 0, i = [t[0] + (n[0] - t[0]) * o, t[1] + (n[1] - t[1]) * o];
2625
+ return { point: i, t: o, distance: S(e, i), length: s };
2626
+ }
2627
+ function Vs(e, t) {
2628
+ const { t: n } = G(t, e.axis[0], e.axis[1]);
2629
+ return e.high + (e.low - e.high) * n;
2630
+ }
2631
+ const W = (e) => e.rings ?? [Zt(e.position, e.width, e.depth, e.rotation)], qe = /* @__PURE__ */ new WeakMap();
2632
+ function Je(e, t) {
2633
+ var i;
2634
+ let n = qe.get(e);
2635
+ const s = n == null ? void 0 : n.ids.get(t);
2636
+ if (!n || n.length !== e.length || s === void 0 || ((i = e[s]) == null ? void 0 : i.id) !== t) {
2637
+ const a = /* @__PURE__ */ new Map();
2638
+ e.forEach((r, l) => {
2639
+ a.has(r.id) || a.set(r.id, l);
2640
+ }), n = { length: e.length, ids: a }, qe.set(e, n);
2641
+ }
2642
+ const o = n.ids.get(t);
2643
+ return o === void 0 ? void 0 : e[o];
2644
+ }
2645
+ function X(e, t) {
2646
+ return [
2647
+ Je(e.junctions, t.startId).position,
2648
+ Je(e.junctions, t.endId).position
2649
+ ];
2650
+ }
2651
+ function yt(e, t) {
2652
+ const n = e.barriers.find((r) => r.id === t.barrierId);
2653
+ if (!n) return t.position;
2654
+ const [s, o] = X(e, n), i = S(s, o), a = i ? (t.offset ?? i / 2) / i : 0;
2655
+ return [s[0] + (o[0] - s[0]) * a, s[1] + (o[1] - s[1]) * a];
2656
+ }
2657
+ function xn(e, t) {
2658
+ const n = e.barriers.find((i) => i.id === t.barrierId);
2659
+ if (!n) return t.rotation;
2660
+ const [s, o] = X(e, n);
2661
+ return Math.atan2(o[1] - s[1], o[0] - s[0]) * 180 / Math.PI;
2662
+ }
2663
+ function D(e, t) {
2664
+ let n = !1;
2665
+ for (let s = 0, o = t.length - 1; s < t.length; o = s++) {
2666
+ const i = t[s], a = t[o];
2667
+ i[1] > e[1] != a[1] > e[1] && e[0] < (a[0] - i[0]) * (e[1] - i[1]) / (a[1] - i[1]) + i[0] && (n = !n);
2668
+ }
2669
+ return n;
2670
+ }
2671
+ const $t = (e, t, n) => (t[0] - e[0]) * (n[1] - e[1]) - (t[1] - e[1]) * (n[0] - e[0]);
2672
+ function Qt(e, t, n, s) {
2673
+ const o = (i, a, r) => Math.abs($t(a, r, i)) < 1e-8 * S(a, r) && i[0] >= Math.min(a[0], r[0]) - 1e-8 && i[0] <= Math.max(a[0], r[0]) + 1e-8 && i[1] >= Math.min(a[1], r[1]) - 1e-8 && i[1] <= Math.max(a[1], r[1]) + 1e-8;
2674
+ return $t(e, t, n) * $t(e, t, s) < 0 && $t(n, s, e) * $t(n, s, t) < 0 || o(n, e, t) || o(s, e, t) || o(e, n, s) || o(t, n, s);
2675
+ }
2676
+ function is(e, t) {
2677
+ try {
2678
+ return ct.difference(e, t).every((n) => V(n[0]) < 1e-3);
2679
+ } catch {
2680
+ return !1;
2681
+ }
2682
+ }
2683
+ const tt = un, te = tt;
2684
+ function _t(e, t, n) {
2685
+ const s = e.junctions.find((o) => o.floorId === n && S(o.position, t) < ut);
2686
+ if (s) return s.position;
2687
+ for (const o of e.barriers) {
2688
+ if (o.floorId !== n) continue;
2689
+ const [i, a] = X(e, o), r = G(t, i, a);
2690
+ if (r.distance > ut) continue;
2691
+ const l = r.t <= 0.5 ? i : a;
2692
+ if (S(r.point, l) < tt - 1e-6) return l;
2693
+ }
2694
+ return t;
2695
+ }
2696
+ function qt(e, t, n) {
2697
+ if (t = _t(e, t, n), e.junctions.some((s) => s.floorId === n && S(s.position, t) < ut)) return null;
2698
+ for (const s of e.barriers.filter((o) => o.floorId === n)) {
2699
+ const [o, i] = X(e, s), a = G(t, o, i);
2700
+ if (a.distance > ut || a.t <= 0 || a.t >= 1) continue;
2701
+ const r = S(o, t);
2702
+ for (const l of e.objects.filter((d) => d.barrierId === s.id)) {
2703
+ if (Math.abs((l.offset ?? 0) - r) < l.width / 2) return "A junction cannot split an opening.";
2704
+ if (((l.offset ?? 0) < r ? r : S(t, i)) < te - 1e-6)
2705
+ return `Leave at least ${te} m of wall around an opening.`;
2706
+ }
2707
+ }
2708
+ return null;
2709
+ }
2710
+ function rs(e, t, n, s) {
2711
+ t = _t(e, t, s), n = _t(e, n, s);
2712
+ const o = qt(e, t, s) ?? qt(e, n, s);
2713
+ if (o) return o;
2714
+ const i = n[0] - t[0], a = n[1] - t[1], r = S(t, n), l = [0, r], d = (u, c) => u > N && u < c - N;
2715
+ for (const u of Z(e).filter((c) => c.floorId === s)) {
2716
+ const [c, f] = X(e, u), h = f[0] - c[0], p = f[1] - c[1], m = i * p - a * h;
2717
+ if (Math.abs(m) < 1e-12 * r * S(c, f)) {
2718
+ for (const g of [c, f]) {
2719
+ const y = G(g, t, n);
2720
+ y.distance <= N && l.push(y.t * r);
2721
+ }
2722
+ continue;
2723
+ }
2724
+ const I = ((c[0] - t[0]) * p - (c[1] - t[1]) * h) / m, b = ((c[0] - t[0]) * a - (c[1] - t[1]) * i) / m;
2725
+ if (I < 0 || I > 1 || b < 0 || b > 1) continue;
2726
+ if (l.push(I * r), d(Math.min(b, 1 - b) * S(c, f), "kind" in u ? tt : ne))
2727
+ return "That crossing would leave a boundary segment too short.";
2728
+ const w = qt(e, [t[0] + I * i, t[1] + I * a], s);
2729
+ if (w) return w;
2730
+ }
2731
+ return l.sort((u, c) => u - c), l.some((u, c) => c > 0 && d(u - l[c - 1], tt)) ? "That crossing would leave a boundary segment too short." : null;
2732
+ }
2733
+ function Ke(e, t, n) {
2734
+ t = _t(e, t, n);
2735
+ const s = e.junctions.find((a) => a.floorId === n && S(a.position, t) < ut);
2736
+ if (s) return s.id;
2737
+ const o = qt(e, t, n);
2738
+ if (o) throw new Error(o);
2739
+ const i = H();
2740
+ e.junctions.push({ id: i, floorId: n, position: t });
2741
+ for (const a of [...e.barriers].filter((r) => r.floorId === n)) {
2742
+ const [r, l] = X(e, a), d = G(t, r, l);
2743
+ if (d.distance > ut || d.t <= 0 || d.t >= 1) continue;
2744
+ const u = S(r, t), c = e.objects.filter((p) => p.barrierId === a.id), f = H(), h = a.endId;
2745
+ a.endId = i, e.barriers.push({ ...a, id: f, startId: i, endId: h }), Re(e, a.id, [{ edgeId: a.id }, { edgeId: f }]), c.forEach((p) => {
2746
+ (p.offset ?? 0) > u && (p.barrierId = f, p.offset = (p.offset ?? 0) - u);
2747
+ });
2748
+ }
2749
+ return i;
2750
+ }
2751
+ function En(e, t) {
2752
+ var o;
2753
+ const n = e.barriers.find((i) => i.id === t);
2754
+ n && wn(e, n);
2755
+ const s = new Set(e.objects.filter((i) => i.barrierId === t).map((i) => i.id));
2756
+ e.objects = e.objects.filter((i) => !s.has(i.id));
2757
+ for (const i of e.objects) i.parentId && s.has(i.parentId) && (i.parentId = void 0);
2758
+ if (e.barriers = e.barriers.filter((i) => i.id !== t), e.junctions = e.junctions.filter(
2759
+ (i) => Z(e).some((a) => a.startId === i.id || a.endId === i.id)
2760
+ ), (o = e.navNodes) != null && o.length) {
2761
+ const i = new Set(e.objects.map((r) => r.id));
2762
+ e.navNodes = e.navNodes.filter((r) => r.objectId === void 0 || i.has(r.objectId));
2763
+ const a = new Set(e.navNodes.map((r) => r.id));
2764
+ e.navEdges = (e.navEdges ?? []).filter(
2765
+ (r) => a.has(r.aId) && a.has(r.bId) && (r.objectId === void 0 || i.has(r.objectId))
2766
+ );
2767
+ }
2768
+ }
2769
+ function ie(e, t, n, s, o) {
2770
+ if (S(t, n) < tt - 1e-6) throw new Error(`A segment must be at least ${tt} m long.`);
2771
+ if (t = _t(e, t, s), n = _t(e, n, s), S(t, n) < tt - 1e-6) return;
2772
+ const i = Ke(e, t, s), a = Ke(e, n, s);
2773
+ if (i === a || e.barriers.some(
2774
+ (l) => l.floorId === s && l.kind === o && (l.startId === i && l.endId === a || l.startId === a && l.endId === i)
2775
+ ))
2776
+ return;
2777
+ const r = {
2778
+ id: H(),
2779
+ floorId: s,
2780
+ startId: i,
2781
+ endId: a,
2782
+ kind: o,
2783
+ name: o === "wall" ? "Wall" : "Site fence",
2784
+ thickness: o === "wall" ? 0.3 : 0.1,
2785
+ height: o === "wall" ? 3.5 : 2
2786
+ };
2787
+ return e.barriers.push(r), r;
2788
+ }
2789
+ function Mn(e, t, n, s, o = !0) {
2790
+ var E, A;
2791
+ const i = e.objects.find((v) => v.id === t);
2792
+ if (!((E = i == null ? void 0 : i.rings) != null && E.length)) throw new Error("Pick a room or zone to split.");
2793
+ if (((A = i.geometry) == null ? void 0 : A.mode) === "boundaries") return Qo(e, i, n, s, o);
2794
+ const a = S(n, s);
2795
+ if (a < 1e-6) throw new Error("Draw a line across the room to split it.");
2796
+ const r = [(s[0] - n[0]) / a, (s[1] - n[1]) / a], l = [r[1], -r[0]], d = i.rings.map(C), u = Math.max(a, ...d.flat().map((v) => S(n, v))) * 4 + 10, c = [n[0] - r[0] * u, n[1] - r[1] * u], f = [n[0] + r[0] * u, n[1] + r[1] * u], h = (v) => C([
2797
+ c,
2798
+ f,
2799
+ [f[0] + l[0] * u * v, f[1] + l[1] * u * v],
2800
+ [c[0] + l[0] * u * v, c[1] + l[1] * u * v]
2801
+ ]), p = (v) => {
2802
+ const k = ct.intersection(d, [h(v)]);
2803
+ if (!k.length) throw new Error("The cut must cross the room from one wall to the opposite wall.");
2804
+ const R = (O) => V(O[0]) - O.slice(1).reduce((z, F) => z + V(F), 0), P = k.filter((O) => R(O) >= kt).sort((O, z) => R(z) - R(O));
2805
+ if (!P.length) throw new Error(`Each split space needs at least ${kt} m² of usable area.`);
2806
+ if (P.length > 1)
2807
+ throw new Error("That cut would leave disconnected pieces — draw a single straight line across the room.");
2808
+ return P[0].map(C);
2809
+ }, m = (v) => `${v[0].toFixed(4)},${v[1].toFixed(4)}`, I = new Set(d.flat().map(m)), b = (v) => v.map((k) => {
2810
+ const R = T(k), P = R.filter((z, F) => {
2811
+ if (I.has(m(z))) return !0;
2812
+ const U = R[(F + R.length - 1) % R.length], L = R[(F + 1) % R.length];
2813
+ return !(I.has(m(U)) && S(z, U) < ut || I.has(m(L)) && S(z, L) < ut);
2814
+ }), O = P.some(
2815
+ (z, F) => P.some(
2816
+ (U, L) => L > F + 1 && !(F === 0 && L === P.length - 1) && Qt(z, P[(F + 1) % P.length], U, P[(L + 1) % P.length])
2817
+ )
2818
+ );
2819
+ return P.length >= 3 && V(P) >= 0.01 && !O ? C(P) : k;
2820
+ }), w = b(p(1)), g = b(p(-1)), y = (v, k) => {
2821
+ v.rings = k, v.position = vt(k[0]);
2822
+ const R = T(k[0]), P = R.map((z) => z[0]), O = R.map((z) => z[1]);
2823
+ v.width = Math.max(...P) - Math.min(...P), v.depth = Math.max(...O) - Math.min(...O);
2824
+ }, M = structuredClone(i);
2825
+ if (M.id = H(), M.name = `${i.name} 2`, M.feedId = void 0, y(i, w), y(M, g), e.objects.push(M), !o) return M.id;
2826
+ const _ = [];
2827
+ for (const v of d) {
2828
+ const k = T(v);
2829
+ for (let R = 0; R < k.length; R++) {
2830
+ const P = k[R], O = k[(R + 1) % k.length], z = [O[0] - P[0], O[1] - P[1]], F = r[0] * z[1] - r[1] * z[0];
2831
+ if (Math.abs(F) < 1e-12) continue;
2832
+ const U = [P[0] - n[0], P[1] - n[1]], L = (U[0] * r[1] - U[1] * r[0]) / F;
2833
+ L < -1e-9 || L > 1 + 1e-9 || _.push((U[0] * z[1] - U[1] * z[0]) / F);
2834
+ }
2835
+ }
2836
+ _.sort((v, k) => v - k);
2837
+ const $ = _.filter((v, k) => k === 0 || v - _[k - 1] > 1e-4), x = e.barriers.length;
2838
+ for (let v = 0; v + 1 < $.length; v += 2) {
2839
+ const k = [n[0] + r[0] * $[v], n[1] + r[1] * $[v]], R = [n[0] + r[0] * $[v + 1], n[1] + r[1] * $[v + 1]];
2840
+ S(k, R) >= tt - 1e-6 && ie(e, k, R, i.floorId, "wall");
2841
+ }
2842
+ return e.barriers.slice(x).forEach((v) => {
2843
+ v.name = "Partition", v.thickness = 0.18;
2844
+ }), M.id;
2845
+ }
2846
+ function as(e, t) {
2847
+ var r;
2848
+ if (!e.floors.find((l) => l.id === t)) throw new Error("That floor is not part of this project.");
2849
+ if (e.floors.length <= 1) throw new Error("A project needs at least one floor.");
2850
+ const s = new Set(e.objects.filter((l) => l.floorId === t).map((l) => l.id)), o = new Set(e.barriers.filter((l) => l.floorId === t).map((l) => l.id)), i = [t, ...s, ...o];
2851
+ e.floors = e.floors.filter((l) => l.id !== t), e.junctions = e.junctions.filter((l) => l.floorId !== t), e.barriers = e.barriers.filter((l) => l.floorId !== t), e.virtualBoundaries && (e.virtualBoundaries = e.virtualBoundaries.filter((l) => l.floorId !== t)), e.objects = e.objects.filter((l) => l.floorId !== t), e.drawings = e.drawings.filter((l) => l.floorId !== t);
2852
+ for (const l of e.objects)
2853
+ l.barrierId && o.has(l.barrierId) && (l.barrierId = void 0, l.offset = void 0), l.parentId && s.has(l.parentId) && (l.parentId = void 0), l.watchedIds && (l.watchedIds = l.watchedIds.filter((d) => !s.has(d)), l.watchedIds.length || (l.watchedIds = void 0)), l.servedFloorIds && (l.servedFloorIds = l.servedFloorIds.filter((d) => d !== t), l.servedFloorIds.length || (l.servedFloorIds = void 0));
2854
+ if (e.navNodes) {
2855
+ const l = new Set(
2856
+ e.navNodes.filter((d) => d.floorId === t || d.objectId && s.has(d.objectId)).map((d) => d.id)
2857
+ );
2858
+ e.navNodes = e.navNodes.filter((d) => !l.has(d.id)), e.navEdges = (e.navEdges ?? []).filter(
2859
+ (d) => !l.has(d.aId) && !l.has(d.bId) && !(d.objectId && s.has(d.objectId))
2860
+ );
2861
+ }
2862
+ e.portals && (e.portals = e.portals.filter(
2863
+ (l) => !s.has(l.a) && !s.has(l.b) && !(l.openingId && s.has(l.openingId))
2864
+ ));
2865
+ const a = new Set((e.portals ?? []).map((l) => l.id));
2866
+ for (const l of e.zones ?? []) l.spaceIds = l.spaceIds.filter((d) => !s.has(d));
2867
+ for (const l of e.portalGroups ?? []) l.portalIds = l.portalIds.filter((d) => a.has(d));
2868
+ for (const l of e.buildings) ((r = l.roof) == null ? void 0 : r.floorId) === t && (l.roof = void 0);
2869
+ return e.initialFloorId === t && (e.initialFloorId = void 0), i;
2870
+ }
2871
+ function ls(e, t) {
2872
+ var a, r, l;
2873
+ const n = e.floors.find((d) => d.id === t), s = H(), o = /* @__PURE__ */ new Map(), i = (d) => (o.has(d) || o.set(d, H()), o.get(d));
2874
+ return e.floors.push({
2875
+ ...n,
2876
+ id: s,
2877
+ name: `${n.name} copy`,
2878
+ elevation: Math.max(
2879
+ ...e.floors.filter((d) => d.buildingId === n.buildingId).map((d) => d.elevation + d.height)
2880
+ )
2881
+ }), e.junctions.filter((d) => d.floorId === t).forEach((d) => e.junctions.push({ ...structuredClone(d), id: i(d.id), floorId: s })), e.barriers.filter((d) => d.floorId === t).forEach(
2882
+ (d) => e.barriers.push({
2883
+ ...d,
2884
+ id: i(d.id),
2885
+ floorId: s,
2886
+ startId: i(d.startId),
2887
+ endId: i(d.endId)
2888
+ })
2889
+ ), e.objects.filter((d) => d.floorId === t).forEach(
2890
+ (d) => {
2891
+ var u, c;
2892
+ return e.objects.push({
2893
+ ...structuredClone(d),
2894
+ id: i(d.id),
2895
+ floorId: s,
2896
+ feedId: void 0,
2897
+ parentId: d.parentId ? i(d.parentId) : void 0,
2898
+ barrierId: d.barrierId ? i(d.barrierId) : void 0,
2899
+ servedFloorIds: (u = d.servedFloorIds) == null ? void 0 : u.map((f) => f === t ? s : f),
2900
+ geometry: ((c = d.geometry) == null ? void 0 : c.mode) === "boundaries" ? {
2901
+ mode: "boundaries",
2902
+ loops: d.geometry.loops.map((f) => f.map((h) => ({ ...h, edgeId: i(h.edgeId) })))
2903
+ } : d.geometry
2904
+ });
2905
+ }
2906
+ ), (a = e.virtualBoundaries) == null || a.filter((d) => d.floorId === t).forEach(
2907
+ (d) => e.virtualBoundaries.push({
2908
+ ...d,
2909
+ id: i(d.id),
2910
+ floorId: s,
2911
+ startId: i(d.startId),
2912
+ endId: i(d.endId)
2913
+ })
2914
+ ), e.drawings.filter((d) => d.floorId === t).forEach((d) => e.drawings.push({ ...d, id: H(), floorId: s })), (r = e.navNodes) == null || r.filter((d) => d.floorId === t).forEach(
2915
+ (d) => e.navNodes.push({
2916
+ ...structuredClone(d),
2917
+ id: i(d.id),
2918
+ floorId: s,
2919
+ objectId: d.objectId && o.has(d.objectId) ? o.get(d.objectId) : void 0
2920
+ })
2921
+ ), (l = e.navEdges) == null || l.filter((d) => o.has(d.aId) && o.has(d.bId)).forEach(
2922
+ (d) => e.navEdges.push({
2923
+ ...d,
2924
+ id: i(d.id),
2925
+ aId: o.get(d.aId),
2926
+ bId: o.get(d.bId),
2927
+ objectId: d.objectId && o.has(d.objectId) ? o.get(d.objectId) : void 0
2928
+ })
2929
+ ), s;
2930
+ }
2931
+ function Xs(e, t, n) {
2932
+ let s = null;
2933
+ for (const o of Sn(e, t))
2934
+ D(n, o) && (!s || Math.abs(V(o)) < Math.abs(V(s))) && (s = o);
2935
+ return s;
2936
+ }
2937
+ function Sn(e, t, n = 1) {
2938
+ const s = e.barriers.filter((m) => m.floorId === t);
2939
+ if (!s.length) return [];
2940
+ const o = s.flatMap((m) => X(e, m)), i = 2, a = Math.min(...o.map((m) => m[0])) - i, r = Math.max(...o.map((m) => m[0])) + i, l = Math.min(...o.map((m) => m[1])) - i, d = Math.max(...o.map((m) => m[1])) + i, u = [
2941
+ [a, l],
2942
+ [r, l],
2943
+ [r, d],
2944
+ [a, d],
2945
+ [a, l]
2946
+ ], c = s.map((m) => {
2947
+ const [I, b] = X(e, m), w = S(I, b) || 1e-3, g = Math.atan2(b[1] - I[1], b[0] - I[0]) * 180 / Math.PI, y = [(I[0] + b[0]) / 2, (I[1] + b[1]) / 2];
2948
+ return [
2949
+ C(Zt(y, w + m.thickness, m.thickness, g)).map(
2950
+ (M) => [Math.round(M[0] * 1e4) / 1e4, Math.round(M[1] * 1e4) / 1e4]
2951
+ )
2952
+ ];
2953
+ });
2954
+ let f;
2955
+ try {
2956
+ f = ct.difference([u], ...c);
2957
+ } catch {
2958
+ return [];
2959
+ }
2960
+ const h = (m) => Math.abs(
2961
+ m.reduce((I, b, w) => {
2962
+ const g = m[(w + 1) % m.length];
2963
+ return I + b[0] * g[1] - g[0] * b[1];
2964
+ }, 0) / 2
2965
+ ), p = (m) => {
2966
+ const b = [];
2967
+ for (const g of m) (!b.length || S(b[b.length - 1], g) > 1e-3) && b.push(g);
2968
+ b.length > 1 && S(b[0], b[b.length - 1]) <= 1e-3 && b.pop();
2969
+ const w = [];
2970
+ for (let g = 0; g < b.length; g++) {
2971
+ const y = b[(g + b.length - 1) % b.length], M = b[g], _ = b[(g + 1) % b.length], $ = M[0] - y[0], x = M[1] - y[1], E = _[0] - M[0], A = _[1] - M[1];
2972
+ Math.abs($ * A - x * E) / (Math.hypot($, x) * Math.hypot(E, A) || 1) > 1e-4 && w.push(M);
2973
+ }
2974
+ return w.length >= 3 ? w : b;
2975
+ };
2976
+ return f.filter((m) => !m[0].some((I) => I[0] <= a + 1e-6 || I[0] >= r - 1e-6 || I[1] <= l + 1e-6 || I[1] >= d - 1e-6)).map((m) => p(T(m[0]))).filter((m) => m.length >= 3 && h(m) >= n).sort((m, I) => h(I) - h(m));
2977
+ }
2978
+ function qs(e, t, n) {
2979
+ var l, d;
2980
+ if (!n.length) return 0;
2981
+ const s = Sn(e, t), o = (u, c) => {
2982
+ try {
2983
+ const f = ct.intersection([C(u)], [C(c)]), h = ct.union([C(u)], [C(c)]), p = (I) => I.reduce((b, w) => b + Math.abs(V(w[0])), 0), m = p(h);
2984
+ return m > 0 ? p(f) / m : 0;
2985
+ } catch {
2986
+ return 0;
2987
+ }
2988
+ }, i = (u, c) => c.find((f) => o(u, f) > 0.95), a = [];
2989
+ for (const u of e.objects) {
2990
+ if (u.floorId !== t || u.kind !== "room" || !((l = u.rings) != null && l.length) || u.geometry !== void 0 || !i(u.rings[0], n)) continue;
2991
+ const c = (d = s.map((f) => ({ r: f, score: o(u.rings[0], f) })).filter((f) => f.score > 0.2).sort((f, h) => h.score - f.score)[0]) == null ? void 0 : d.r;
2992
+ c && a.push({ room: u, ring: c });
2993
+ }
2994
+ let r = 0;
2995
+ for (const { room: u, ring: c } of a) {
2996
+ if (a.some((m) => m.room !== u && m.ring === c)) continue;
2997
+ const f = u.rings.slice(1);
2998
+ u.rings = [C(c), ...f], u.position = vt(c);
2999
+ const h = c.map((m) => m[0]), p = c.map((m) => m[1]);
3000
+ u.width = Math.max(...h) - Math.min(...h), u.depth = Math.max(...p) - Math.min(...p), r++;
3001
+ }
3002
+ return r;
3003
+ }
3004
+ const Js = (e) => e.objects.filter((t) => et(t.kind));
3005
+ function ds(e, t) {
3006
+ const n = W(t)[0];
3007
+ return n != null && n.length ? vt(n) : yt(e, t);
3008
+ }
3009
+ function Rt(e, t) {
3010
+ const [n, ...s] = W(e);
3011
+ return !!n && D(t, n) && !s.some((o) => D(t, o));
3012
+ }
3013
+ function ve(e, t, n) {
3014
+ let s = null, o = Number.POSITIVE_INFINITY;
3015
+ for (const i of e.objects) {
3016
+ if (i.floorId !== t || !et(i.kind) || !Rt(i, n)) continue;
3017
+ const a = nt(i);
3018
+ a >= o || (o = a, s = i);
3019
+ }
3020
+ return s;
3021
+ }
3022
+ const cs = 0.35;
3023
+ function fs(e) {
3024
+ const t = new Map(e.barriers.map((s) => [s.id, s])), n = [];
3025
+ for (const s of e.objects) {
3026
+ if (!Me.has(s.kind)) continue;
3027
+ const o = yt(e, s);
3028
+ let i, a, r = cs;
3029
+ const l = s.barrierId ? t.get(s.barrierId) : void 0;
3030
+ if (l) {
3031
+ const [f, h] = X(e, l), p = S(f, h) || 1;
3032
+ i = (h[1] - f[1]) / p, a = -(h[0] - f[0]) / p, r += l.thickness / 2;
3033
+ } else {
3034
+ const f = (s.rotation ?? 0) * Math.PI / 180;
3035
+ i = -Math.sin(f), a = Math.cos(f), r += s.depth / 2;
3036
+ }
3037
+ const d = (f) => {
3038
+ const h = [o[0] + i * r * f, o[1] + a * r * f];
3039
+ return ve(e, s.floorId, h) ?? (s.floorId === null ? null : ve(e, null, h));
3040
+ }, u = d(1), c = d(-1);
3041
+ !u || !c || u.id === c.id || n.push({ id: `inferred:${s.id}`, openingId: s.id, a: u.id, b: c.id, attests: "assumed" });
3042
+ }
3043
+ return n;
3044
+ }
3045
+ const us = 1, jt = 0.45, hs = 1.2;
3046
+ function xe(e) {
3047
+ var c, f;
3048
+ const t = /* @__PURE__ */ new Map(), n = (h, p) => {
3049
+ const m = t.get(p);
3050
+ m ? m.push(h) : t.set(p, [h]);
3051
+ }, s = /* @__PURE__ */ new Map();
3052
+ for (const h of e.objects) {
3053
+ if (!zt(h.kind) || !h.floorId) continue;
3054
+ const p = It(h), m = s.get(p);
3055
+ m ? m.add(h.floorId) : s.set(p, /* @__PURE__ */ new Set([h.floorId]));
3056
+ }
3057
+ for (const h of e.objects) {
3058
+ if (!et(h.kind) || (n(h, h.floorId ?? ""), !zt(h.kind))) continue;
3059
+ const p = s.get(It(h));
3060
+ for (const m of wt(e, h))
3061
+ m.id !== h.floorId && !(p != null && p.has(m.id)) && n(h, m.id);
3062
+ }
3063
+ const o = (h, p = 0) => {
3064
+ const m = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
3065
+ for (const [I, b] of h)
3066
+ m[0] = Math.min(m[0], I - p), m[1] = Math.min(m[1], b - p), m[2] = Math.max(m[2], I + p), m[3] = Math.max(m[3], b + p);
3067
+ return m;
3068
+ }, i = (h, p, m) => p >= h[0] && m >= h[1] && p <= h[2] && m <= h[3], a = new Map(
3069
+ [...t.values()].flat().map((h) => {
3070
+ const p = W(h);
3071
+ return [h.id, { rings: p, bounds: o(p[0] ?? []) }];
3072
+ })
3073
+ ), r = (h, p) => {
3074
+ const m = a.get(h.id);
3075
+ return i(m.bounds, ...p) && !!m.rings[0] && D(p, m.rings[0]) && !m.rings.slice(1).some((I) => D(p, I));
3076
+ }, l = /* @__PURE__ */ new Map();
3077
+ for (const h of e.barriers) {
3078
+ const p = h.floorId ?? "", m = l.get(p), I = X(e, h), b = { ends: I, bounds: o(I, jt) };
3079
+ m ? m.push(b) : l.set(p, [b]);
3080
+ }
3081
+ const d = /* @__PURE__ */ new Map();
3082
+ for (const [h, p] of t) {
3083
+ const m = l.get(h) ?? [], I = [...p].sort((b, w) => nt(b) - nt(w));
3084
+ for (const b of p)
3085
+ for (const w of a.get(b.id).rings) {
3086
+ if (!(w != null && w.length)) continue;
3087
+ const g = T(w);
3088
+ for (let y = 0; y < g.length; y++) {
3089
+ const M = g[y], _ = g[(y + 1) % g.length], $ = S(M, _);
3090
+ if ($ < 0.05) continue;
3091
+ const x = (_[0] - M[0]) / $, E = (_[1] - M[1]) / $, A = E, v = -x, k = Math.max(1, Math.round($ / us));
3092
+ for (let R = 0; R < k; R++) {
3093
+ const P = (R + 0.5) / k * $, O = M[0] + x * P, z = M[1] + E * P;
3094
+ if (!m.some((F) => i(F.bounds, O, z) && G([O, z], ...F.ends).distance < jt))
3095
+ for (const F of [1, -1]) {
3096
+ const U = [O + A * jt * F, z + v * jt * F];
3097
+ if (r(b, U)) continue;
3098
+ const L = I.find((Ht) => Ht.id !== b.id && r(Ht, U));
3099
+ if (!L || ((c = b.geometry) == null ? void 0 : c.mode) === "boundaries" && ((f = L.geometry) == null ? void 0 : f.mode) === "boundaries") continue;
3100
+ const xt = b.id < L.id ? `${b.id}|${L.id}` : `${L.id}|${b.id}`;
3101
+ d.set(xt, (d.get(xt) ?? 0) + $ / k);
3102
+ }
3103
+ }
3104
+ }
3105
+ }
3106
+ }
3107
+ const u = on(e);
3108
+ for (const [h, p] of d) {
3109
+ if (p < hs) continue;
3110
+ const [m, I] = h.split("|");
3111
+ u.push({ id: `open:${m}:${I}`, a: m, b: I, attests: "none" });
3112
+ }
3113
+ return u;
3114
+ }
3115
+ const Qe = (e) => e.startsWith("inferred:") || e.startsWith("open:");
3116
+ function gs(e) {
3117
+ const t = e.portals ?? [], n = t.filter((r) => !Qe(r.id)), s = new Set(n.flatMap((r) => r.openingId ? [r.openingId] : [])), o = new Set(n.map((r) => JSON.stringify([r.a, r.b].sort()))), i = new Map(t.filter((r) => Qe(r.id)).map((r) => [r.id, r])), a = [...fs(e), ...xe(e)].filter((r) => !r.openingId || !s.has(r.openingId)).filter((r) => !r.id.startsWith("open:") || !o.has(JSON.stringify([r.a, r.b].sort()))).map((r) => {
3118
+ const l = i.get(r.id);
3119
+ return l && (l.passage !== void 0 && (r.passage = l.passage), l.attests !== void 0 && (r.attests = l.attests), l.name !== void 0 && (r.name = l.name), l.metadata !== void 0 && (r.metadata = l.metadata)), r;
3120
+ });
3121
+ return e.portals = [...n, ...a], a.length;
3122
+ }
3123
+ function ms(e, t, n, s) {
3124
+ var i;
3125
+ const o = [];
3126
+ for (const a of e.objects) {
3127
+ if (a.floorId !== t || !et(a.kind) || ((i = a.geometry) == null ? void 0 : i.mode) === "boundaries" || e.objects.some((c) => c.parentId === a.id)) continue;
3128
+ const r = W(a)[0];
3129
+ if (!(r != null && r.length)) continue;
3130
+ const l = (c) => Rt(a, c) && !W(a).some((f) => {
3131
+ const h = T(f);
3132
+ return h.some((p, m) => G(c, p, h[(m + 1) % h.length]).distance < 1e-6);
3133
+ });
3134
+ if (l(n) || l(s)) continue;
3135
+ const d = Math.max(8, Math.min(200, Math.round(S(n, s) / 0.25)));
3136
+ let u = !1;
3137
+ for (let c = 1; c < d && !u; c++) {
3138
+ const f = c / d;
3139
+ u = Rt(a, [n[0] + (s[0] - n[0]) * f, n[1] + (s[1] - n[1]) * f]);
3140
+ }
3141
+ u && o.push(a);
3142
+ }
3143
+ return o;
3144
+ }
3145
+ function kn(e, t, n, s) {
3146
+ const o = [];
3147
+ for (const i of ms(e, t, n, s))
3148
+ try {
3149
+ o.push(Mn(e, i.id, n, s, !1));
3150
+ } catch {
3151
+ }
3152
+ return o;
3153
+ }
3154
+ function Ks(e, t) {
3155
+ if (!e.barriers.find((i) => i.id === t)) return null;
3156
+ const s = { ...e, barriers: e.barriers.filter((i) => i.id !== t) }, o = new Set(xe(e).map((i) => [i.a, i.b].sort().join("|")));
3157
+ for (const i of xe(s)) {
3158
+ if (o.has([i.a, i.b].sort().join("|"))) continue;
3159
+ const a = e.objects.find((l) => l.id === i.a), r = e.objects.find((l) => l.id === i.b);
3160
+ if (a && r) return [a, r];
3161
+ }
3162
+ return null;
3163
+ }
3164
+ function ps(e, t, n) {
3165
+ var i, a;
3166
+ const s = e.objects.find((r) => r.id === t), o = e.objects.find((r) => r.id === n);
3167
+ if (!s || !o || s.id === o.id) return !1;
3168
+ if (((i = s.geometry) == null ? void 0 : i.mode) === "boundaries" || ((a = o.geometry) == null ? void 0 : a.mode) === "boundaries") {
3169
+ if (!ts(e, s, o)) return !1;
3170
+ } else {
3171
+ const r = ct.union(W(s).map(C), W(o).map(C));
3172
+ if (r.length !== 1) return !1;
3173
+ s.rings = r[0].map((l) => C(l));
3174
+ }
3175
+ e.objects = e.objects.filter((r) => r.id !== n);
3176
+ for (const r of e.objects) r.parentId === n && (r.parentId = t);
3177
+ for (const r of e.portals ?? [])
3178
+ r.a === n && (r.a = t), r.b === n && (r.b = t);
3179
+ e.portals = (e.portals ?? []).filter((r) => r.a !== r.b);
3180
+ for (const r of e.zones ?? [])
3181
+ r.spaceIds = [...new Set(r.spaceIds.map((l) => l === n ? t : l))];
3182
+ return Nt(e), !0;
3183
+ }
3184
+ function Qs(e, t = "Untitled site", n = "Site ground level = 0 m") {
3185
+ return {
3186
+ schemaVersion: 1,
3187
+ id: crypto.randomUUID(),
3188
+ name: t,
3189
+ description: t,
3190
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
3191
+ origin: e,
3192
+ datum: n,
3193
+ buildings: [{ id: "building-main", name: "Main building" }],
3194
+ floors: [{ id: "floor-ground", buildingId: "building-main", name: "Ground floor", elevation: 0, height: 3.5 }],
3195
+ junctions: [],
3196
+ barriers: [],
3197
+ objects: [],
3198
+ drawings: []
3199
+ };
3200
+ }
3201
+ function An(e, t, n, s) {
3202
+ const o = {
3203
+ door: [1, 0.2, 2.1],
3204
+ window: [1.2, 0.15, 1.6],
3205
+ gate: [4, 0.15, 2],
3206
+ turnstile: [1, 1, 1.1],
3207
+ elevator: [2.6, 2.6, 2.5],
3208
+ stairs: [2.5, 4.5, 2.7],
3209
+ office: [6, 3, 2.6],
3210
+ container: [6, 2.4, 2.6],
3211
+ storage: [8, 6, 0.1],
3212
+ camera: [0.5, 0.5, 2.4],
3213
+ sensor: [0.35, 0.35, 0.25],
3214
+ light: [1.2, 0.3, 2.8],
3215
+ alarm: [0.4, 0.4, 0.4],
3216
+ equipment: [1.4, 0.9, 1.4]
3217
+ }, [i, a, r] = o[e] ?? [1, 1, 0];
3218
+ return {
3219
+ id: crypto.randomUUID(),
3220
+ kind: e,
3221
+ floorId: n,
3222
+ name: s ?? e[0].toUpperCase() + e.slice(1),
3223
+ position: t,
3224
+ rotation: 0,
3225
+ width: i,
3226
+ depth: a,
3227
+ height: r,
3228
+ symbol: e === "poi" ? "personnel" : void 0,
3229
+ coverageAngle: e === "camera" ? 70 : void 0,
3230
+ coverageRange: e === "camera" ? 12 : void 0,
3231
+ servedFloorIds: e === "stairs" || e === "elevator" ? n ? [n] : [] : void 0,
3232
+ ...e === "light" ? { light: { kelvin: 4e3, intensity: 45, range: 12 } } : {}
3233
+ };
3234
+ }
3235
+ const Is = 12, bs = 70;
3236
+ function ti(e, t) {
3237
+ var d;
3238
+ const n = t.coverageRange ?? Is, s = (t.coverageAngle ?? bs) / 2, o = yt(e, t), i = t.rotation ?? 0, a = e.barriers.filter((u) => u.floorId === t.floorId), r = new Map(a.map((u) => [u.id, X(e, u)])), l = [];
3239
+ for (const u of e.objects) {
3240
+ if (u.id === t.id || u.floorId !== t.floorId || !et(u.kind) && !nn(u.kind)) continue;
3241
+ if ((d = u.rings) != null && d.length && D(o, u.rings[0])) {
3242
+ l.push(u.id);
3243
+ continue;
3244
+ }
3245
+ const c = yt(e, u), f = S(o, c);
3246
+ if (f < 0.01 || f > n) continue;
3247
+ const h = Math.atan2(c[1] - o[1], c[0] - o[0]) * 180 / Math.PI;
3248
+ if (Math.abs(((h - i) % 360 + 540) % 360 - 180) > s) continue;
3249
+ a.some((I) => {
3250
+ if (I.id === u.barrierId) return !1;
3251
+ const [b, w] = r.get(I.id);
3252
+ return ss(o, c, b, w);
3253
+ }) || l.push(u.id);
3254
+ }
3255
+ return l;
3256
+ }
3257
+ function ei(e) {
3258
+ const t = structuredClone(e);
3259
+ return t.id = crypto.randomUUID(), t.name = `${e.name} copy`, t.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), t.objects.forEach((n) => {
3260
+ delete n.feedId;
3261
+ }), t;
3262
+ }
3263
+ function ni(e) {
3264
+ var n, s;
3265
+ const t = e.initialFloorId;
3266
+ return t === null ? null : t !== void 0 && e.floors.some((o) => o.id === t) ? t : ((n = e.floors.find((o) => o.elevation === 0)) == null ? void 0 : n.id) ?? ((s = e.floors[0]) == null ? void 0 : s.id) ?? null;
3267
+ }
3268
+ async function ys(e) {
3269
+ return new Promise((t, n) => {
3270
+ const s = new FileReader();
3271
+ s.onload = () => t(String(s.result)), s.onerror = () => n(s.error), s.readAsDataURL(e);
3272
+ });
3273
+ }
3274
+ async function oi(e, t) {
3275
+ const n = {};
3276
+ for (const s of new Set(e.drawings.map((o) => o.assetId))) {
3277
+ const o = await t.get(s);
3278
+ if (!o) throw new Error("A reference drawing is missing. Reattach it or remove its reference before exporting.");
3279
+ n[s] = await ys(o);
3280
+ }
3281
+ return JSON.stringify({ ...e, embeddedAssets: n }, null, 2);
3282
+ }
3283
+ async function si(e, t) {
3284
+ const n = JSON.parse(e), s = Ae(n), o = n.embeddedAssets ?? {}, i = [];
3285
+ for (const r of new Set(s.drawings.map((l) => l.assetId))) {
3286
+ const l = o[r];
3287
+ if (typeof l != "string" || !/^data:image\/(png|jpeg|webp);base64,/.test(l))
3288
+ throw new Error("Project export is missing a supported reference image.");
3289
+ const d = await fetch(l);
3290
+ i.push([r, await d.blob()]);
3291
+ }
3292
+ const a = structuredClone(s);
3293
+ delete a.embeddedAssets;
3294
+ for (const [r, l] of i) {
3295
+ const d = crypto.randomUUID();
3296
+ await t.put(d, l), a.drawings.filter((u) => u.assetId === r).forEach((u) => {
3297
+ u.assetId = d;
3298
+ });
3299
+ }
3300
+ return a.id = crypto.randomUUID(), a.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), a;
3301
+ }
3302
+ function ii(e) {
3303
+ const t = JSON.parse(e), n = Ae(t), s = t.embeddedAssets ?? {}, o = structuredClone(n);
3304
+ return delete o.embeddedAssets, { project: o, assets: { get: async (a) => {
3305
+ const r = s[a];
3306
+ if (!(typeof r != "string" || !/^data:image\/(png|jpeg|webp);base64,/.test(r)))
3307
+ return (await fetch(r)).blob();
3308
+ }, put: async () => {
3309
+ }, delete: async () => {
3310
+ } } };
3311
+ }
3312
+ function ws(e, t, n, s, o = "wall") {
3313
+ if (S(n, s) < tt - 1e-6) return;
3314
+ const i = rs(e, n, s, t);
3315
+ if (i) throw new Error(i);
3316
+ const a = ie(e, n, s, t, o);
3317
+ return a && o === "wall" && kn(e, t, ...X(e, a)), a;
3318
+ }
3319
+ function vs(e, t, n) {
3320
+ Tt(e, t);
3321
+ const s = Vo(e, t, n);
3322
+ if (!s) return null;
3323
+ const o = s.rings[0], i = e.objects.filter((u) => u.floorId === t && u.kind === "room" && Rt(u, n)).sort((u, c) => nt(u) - nt(c))[0], a = i ?? An("room", vt(o), t, "Room"), r = { ...a, geometry: { mode: "boundaries", loops: s.loops } };
3324
+ if (r.rings = se(e, r), !Rt(r, n)) return null;
3325
+ const l = (u) => u.flat().map((c) => `${c.edgeId}:${!!c.reversed}`).sort().join("|"), d = e.objects.find(
3326
+ (u) => {
3327
+ var c;
3328
+ return ((c = u.geometry) == null ? void 0 : c.mode) === "boundaries" && l(u.geometry.loops) === l(s.loops);
3329
+ }
3330
+ );
3331
+ return d ? { room: d, existing: !0 } : (yn(e, a, s), i || e.objects.push(a), { room: a, existing: !!i });
3332
+ }
3333
+ function xs(e, t) {
3334
+ for (const n of e.barriers) {
3335
+ if (!t.has(n.startId) && !t.has(n.endId)) continue;
3336
+ const s = S(...X(e, n)), o = e.objects.filter((r) => r.barrierId === n.id).sort((r, l) => (r.offset ?? 0) - (l.offset ?? 0));
3337
+ let i = s;
3338
+ for (const r of [...o].reverse())
3339
+ r.offset = Math.min(r.offset ?? 0, i - r.width / 2), i = r.offset - r.width / 2;
3340
+ let a = 0;
3341
+ for (const r of o)
3342
+ r.offset = Math.max(r.offset ?? 0, a + r.width / 2), a = r.offset + r.width / 2;
3343
+ }
3344
+ }
3345
+ function Es(e, t) {
3346
+ var o, i, a, r;
3347
+ const n = /* @__PURE__ */ new Map();
3348
+ let s;
3349
+ if (t.kind === "junction") {
3350
+ const l = e.junctions.find((d) => d.id === t.id);
3351
+ if (!l) return;
3352
+ n.set(l.id, [t.point[0] - l.position[0], t.point[1] - l.position[1]]);
3353
+ } else if (t.kind === "barrier") {
3354
+ const l = Z(e).find((m) => m.id === t.id);
3355
+ if (!l) return;
3356
+ const [d, u] = X(e, l), c = S(d, u), f = -(u[1] - d[1]) / c, h = (u[0] - d[0]) / c, p = (t.point[0] - (d[0] + u[0]) / 2) * f + (t.point[1] - (d[1] + u[1]) / 2) * h;
3357
+ for (const m of [l.startId, l.endId]) n.set(m, [f * p, h * p]);
3358
+ } else {
3359
+ const l = (i = (o = e.objects.find((d) => d.id === t.id)) == null ? void 0 : o.rings) == null ? void 0 : i[t.ringIndex];
3360
+ if (((r = (a = e.objects.find((d) => d.id === t.id)) == null ? void 0 : a.geometry) == null ? void 0 : r.mode) === "boundaries" || (s = l && T(l)[t.index], !s)) return;
3361
+ }
3362
+ return (l, d) => {
3363
+ for (const u of l.junctions) {
3364
+ const c = n.get(u.id);
3365
+ c && (u.position = [u.position[0] + c[0] * d, u.position[1] + c[1] * d]);
3366
+ }
3367
+ if (t.kind === "ring") {
3368
+ const u = l.objects.find((f) => f.id === t.id), c = T(u.rings[t.ringIndex]);
3369
+ c[t.index] = [
3370
+ s[0] + (t.point[0] - s[0]) * d,
3371
+ s[1] + (t.point[1] - s[1]) * d
3372
+ ], u.rings[t.ringIndex] = C(c), u.position = vt(u.rings[0]);
3373
+ } else
3374
+ xs(l, new Set(n.keys()));
3375
+ };
3376
+ }
3377
+ function Ms(e, t) {
3378
+ var n;
3379
+ (n = Es(e, t)) == null || n(e, 1);
3380
+ }
3381
+ const Ss = (e, t) => {
3382
+ var n, s, o, i;
3383
+ switch (t.kind) {
3384
+ case "addBuilding":
3385
+ return e.buildings.push(structuredClone(t.building)), t.building.id;
3386
+ case "patchBuilding":
3387
+ return gt(e.buildings, t.buildingId, t.set, ["id"]);
3388
+ case "addFloor":
3389
+ return e.floors.push(structuredClone(t.floor)), t.floor.id;
3390
+ case "patchFloor":
3391
+ return gt(e.floors, t.floorId, t.set, ["id", "buildingId"]);
3392
+ case "removeFloor":
3393
+ return as(e, t.floorId);
3394
+ case "duplicateFloor":
3395
+ if (!e.floors.some((a) => a.id === t.floorId)) throw new Error("No such floor.");
3396
+ return ls(e, t.floorId);
3397
+ case "patchProject":
3398
+ for (const a of Object.keys(t.set))
3399
+ if (!["name", "description", "datum", "initialFloorId"].includes(a))
3400
+ throw new Error(`Cannot patch project ${a}.`);
3401
+ return Object.assign(e, t.set), e.id;
3402
+ case "patchBarrier":
3403
+ return gt(e.barriers, t.barrierId, t.set, ["id", "startId", "endId", "floorId"]);
3404
+ case "removeBarrier":
3405
+ En(e, t.barrierId), Nt(e);
3406
+ return;
3407
+ case "moveGeometry":
3408
+ return Ms(e, t.move), t.move.id;
3409
+ case "drawBoundary":
3410
+ return Xo(e, t.floorId, t.a, t.b);
3411
+ case "drawBarrier":
3412
+ return (n = ws(e, t.floorId, t.a, t.b, t.barrierKind)) == null ? void 0 : n.id;
3413
+ case "encloseRoom": {
3414
+ const a = vs(e, t.floorId, t.point);
3415
+ if (!a) throw new Error("No enclosed region at that point. Complete its walls or virtual boundaries first.");
3416
+ return t.name && (a.room.name = t.name), a.room.id;
3417
+ }
3418
+ case "addHole": {
3419
+ const a = e.objects.find((r) => r.id === t.objectId);
3420
+ if (!((s = a == null ? void 0 : a.rings) != null && s.length)) throw new Error("Select an area with a footprint.");
3421
+ return ((o = a.geometry) == null ? void 0 : o.mode) === "boundaries" ? Ko(e, a, t.ring) : a.rings.push(structuredClone(t.ring)), a.id;
3422
+ }
3423
+ case "patchZone":
3424
+ for (const a of Object.keys(t.set))
3425
+ if (!["name", "purpose", "connects", "metadata"].includes(a)) throw new Error(`Cannot patch zone ${a}.`);
3426
+ return gt(e.zones ?? [], t.zoneId, t.set, ["id"]);
3427
+ case "addPortal": {
3428
+ const a = H();
3429
+ return (e.portals ?? (e.portals = [])).push({ ...structuredClone(t.portal), id: a }), a;
3430
+ }
3431
+ case "removePortal":
3432
+ e.portals = (e.portals ?? []).filter((a) => a.id !== t.portalId), Nt(e);
3433
+ return;
3434
+ case "setNavigation":
3435
+ e.navNodes = structuredClone(t.nodes), e.navEdges = structuredClone(t.edges);
3436
+ return;
3437
+ case "addZone":
3438
+ return ro(e, t.name, t.spaceIds, t.purpose);
3439
+ case "removeZone":
3440
+ ao(e, t.zoneId);
3441
+ return;
3442
+ case "setZoneMembers":
3443
+ lo(e, t.zoneId, t.spaceIds, t.member);
3444
+ return;
3445
+ case "nestZone": {
3446
+ if (!co(e, t.parentId, t.childId)) throw new Error("That nesting would make a zone contain itself.");
3447
+ return !0;
3448
+ }
3449
+ case "addPortalGroup":
3450
+ return fo(e, t.name, t.portalIds);
3451
+ case "removePortalGroup":
3452
+ uo(e, t.groupId);
3453
+ return;
3454
+ case "setPortalGroupMembers":
3455
+ ho(e, t.groupId, t.portalIds, t.member);
3456
+ return;
3457
+ case "patchPortal":
3458
+ return gt(e.portals ?? [], t.portalId, t.set, ["id", "a", "b", "openingId"]);
3459
+ case "patchObject":
3460
+ return gt(e.objects, t.objectId, t.set, ["id", "kind"]);
3461
+ case "addObject": {
3462
+ const a = An(t.objectKind, t.position, t.floorId, t.name);
3463
+ return t.set && gt([a], a.id, t.set, ["id", "kind"]), e.objects.push(a), a.id;
3464
+ }
3465
+ case "removeObjects": {
3466
+ const a = new Set(t.ids), r = e.objects.length;
3467
+ if (e.objects = e.objects.filter((l) => !a.has(l.id)), e.navNodes) {
3468
+ const l = new Set(e.navNodes.filter((d) => d.objectId && a.has(d.objectId)).map((d) => d.id));
3469
+ e.navNodes = e.navNodes.filter((d) => !l.has(d.id)), e.navEdges = (e.navEdges ?? []).filter(
3470
+ (d) => !l.has(d.aId) && !l.has(d.bId) && (!d.objectId || !a.has(d.objectId))
3471
+ );
3472
+ }
3473
+ return Nt(e), r - e.objects.length;
3474
+ }
3475
+ case "refreshPortals":
3476
+ return gs(e);
3477
+ case "pruneOntology":
3478
+ Nt(e);
3479
+ return;
3480
+ case "addBarrier":
3481
+ return (i = ie(e, t.a, t.b, t.floorId, t.barrierKind)) == null ? void 0 : i.id;
3482
+ case "addBoundary":
3483
+ return Ut(e, t.floorId, t.a, t.b);
3484
+ case "connectSpace":
3485
+ return qo(e, t.objectId, t.source), t.objectId;
3486
+ case "disconnectSpace":
3487
+ return Jo(e, t.objectId), t.objectId;
3488
+ case "splitRoom":
3489
+ return Mn(e, t.roomId, t.a, t.b, t.wall);
3490
+ case "divideSpaces":
3491
+ return kn(e, t.floorId, t.a, t.b);
3492
+ case "setOrigin":
3493
+ return e.origin = [...t.origin], e.origin.join(",");
3494
+ case "mergeSpaces": {
3495
+ if (!ps(e, t.keepId, t.absorbedId))
3496
+ throw new Error("Those spaces do not touch, so there is nothing to merge.");
3497
+ return !0;
3498
+ }
3499
+ default:
3500
+ throw new Error(`Unknown mutation: ${String(t.kind)}`);
3501
+ }
3502
+ };
3503
+ function gt(e, t, n, s) {
3504
+ const o = e.find((i) => i.id === t);
3505
+ if (!o) throw new Error(`No such entity: ${t}`);
3506
+ for (const i of Object.keys(n))
3507
+ if (s.includes(i) || ["__proto__", "constructor", "prototype"].includes(i))
3508
+ throw new Error(`Cannot patch ${i}.`);
3509
+ return Object.assign(o, structuredClone(n)), t;
3510
+ }
3511
+ const ri = (e, t) => ks(e, [t]);
3512
+ function ks(e, t) {
3513
+ const n = [], s = Ho(e, (o) => {
3514
+ for (const [i, a] of t.entries())
3515
+ try {
3516
+ n.push(Ss(o, a));
3517
+ } catch (r) {
3518
+ throw new Error(
3519
+ `Mutation #${i + 1} (${a.kind}): ${r instanceof Error ? r.message : String(r)}`
3520
+ );
3521
+ }
3522
+ });
3523
+ return s.ok ? { ...s, outcomes: n } : s;
3524
+ }
3525
+ const he = "@room-nav:", tn = (e) => Math.sign(
3526
+ e.reduce((t, n, s) => {
3527
+ const o = e[(s + 1) % e.length];
3528
+ return t + n[0] * o[1] - o[0] * n[1];
3529
+ }, 0)
3530
+ ) || 1;
3531
+ function ai(e, t, n = { nodes: [], edges: [] }) {
3532
+ var c;
3533
+ const s = e.objects.filter((f) => {
3534
+ var h;
3535
+ return f.kind === "room" && ((h = W(f)[0]) == null ? void 0 : h.length);
3536
+ }), o = n.nodes.filter((f) => !f.id.startsWith(he)).map((f) => ({ ...f, position: [...f.position] })), i = n.edges.filter((f) => !f.id.startsWith(he)), a = new Map(o.map((f) => [f.id, f])), r = new Map(s.map((f) => [f.id, []])), l = new Map(s.map((f) => [f.id, f.floorId]));
3537
+ for (const f of o)
3538
+ f.objectId && l.get(f.objectId) === f.floorId && ((c = r.get(f.objectId)) == null || c.push(f));
3539
+ for (const { spaceId: f, nodeId: h } of t) {
3540
+ const p = a.get(h), m = r.get(f);
3541
+ p && m && l.get(f) === p.floorId && !m.includes(p) && m.push(p);
3542
+ }
3543
+ const d = /* @__PURE__ */ new Map();
3544
+ for (const f of e.objects)
3545
+ if (f.water && f.parentId) {
3546
+ const h = d.get(f.parentId) ?? [];
3547
+ h.push(...W(f).slice(0, 1)), d.set(f.parentId, h);
3548
+ }
3549
+ const u = an(e);
3550
+ for (const f of s) {
3551
+ const h = `${he}${encodeURIComponent(f.id)}:`, p = r.get(f.id), [m, ...I] = W(f), b = u(f.floorId, Vt(m)), w = (E, A) => As(E, A, m) && b(E, A), g = [...I, ...d.get(f.id) ?? []], y = (E) => {
3552
+ if (!w(E, E) || p.some((v) => S(v.position, E) < 0.01)) return;
3553
+ const A = { id: `${h}point:${p.length}`, floorId: f.floorId, position: E };
3554
+ o.push(A), p.push(A);
3555
+ }, M = (E, A) => {
3556
+ const v = T(E), k = tn(E), R = (P, O) => {
3557
+ const z = S(P, O) || 1;
3558
+ return [k * (P[1] - O[1]) / z, k * (O[0] - P[0]) / z];
3559
+ };
3560
+ for (let P = 0; P < v.length; P++) {
3561
+ const O = v[P], z = v[(P + v.length - 1) % v.length], F = v[(P + 1) % v.length], U = R(z, O), L = R(O, F), xt = 1 + U[0] * L[0] + U[1] * L[1], Ht = k * ((O[0] - z[0]) * (F[1] - O[1]) - (O[1] - z[1]) * (F[0] - O[0]));
3562
+ A > 0 && Ht >= 0 || (xt > 0.05 && y([O[0] + A * (U[0] + L[0]) / xt, O[1] + A * (U[1] + L[1]) / xt]), A < 0 && y([(O[0] + F[0]) / 2 + A * L[0], (O[1] + F[1]) / 2 + A * L[1]]));
3563
+ }
3564
+ };
3565
+ M(m, Ot + 0.2);
3566
+ for (const E of g) M(E, -Ot - 0.1);
3567
+ const _ = T(m), $ = tn(m);
3568
+ for (const E of [...p])
3569
+ for (let A = 0; A < _.length; A++) {
3570
+ const v = _[A], k = _[(A + 1) % _.length], R = S(v, k);
3571
+ R && G(E.position, v, k).distance < 0.01 && y([
3572
+ E.position[0] + $ * (v[1] - k[1]) / R * 0.9,
3573
+ E.position[1] + $ * (k[0] - v[0]) / R * 0.9
3574
+ ]);
3575
+ }
3576
+ let x = p.find((E) => E.objectId === f.id);
3577
+ if (x || (x = { id: `${h}anchor`, floorId: f.floorId, position: [...f.position], objectId: f.id }, o.push(x), p.push(x)), !w(x.position, x.position)) {
3578
+ const E = p.filter((A) => w(A.position, A.position)).sort((A, v) => S(A.position, f.position) - S(v.position, f.position))[0];
3579
+ E && (x.position = [...E.position]);
3580
+ }
3581
+ for (let E = 0; E < p.length; E++)
3582
+ for (let A = E + 1; A < p.length; A++) {
3583
+ const v = p[E], k = p[A];
3584
+ w(v.position, k.position) && i.push({ id: `${h}edge:${E}:${A}`, kind: "walk", aId: v.id, bId: k.id });
3585
+ }
3586
+ }
3587
+ return { nodes: o, edges: i };
3588
+ }
3589
+ function As(e, t, n) {
3590
+ const s = T(n), o = (d) => D(d, s) || s.some((u, c) => G(d, u, s[(c + 1) % s.length]).distance < 1e-7);
3591
+ if (!o(e) || !o(t)) return !1;
3592
+ const i = t[0] - e[0], a = t[1] - e[1];
3593
+ if (S(e, t) < 1e-8) return !0;
3594
+ const l = [0, 1];
3595
+ for (let d = 0; d < s.length; d++) {
3596
+ const u = s[d], c = s[(d + 1) % s.length], f = c[0] - u[0], h = c[1] - u[1], p = i * h - a * f;
3597
+ if (Math.abs(p) < 1e-9)
3598
+ for (const m of [u, c]) G(m, e, t).distance < 1e-7 && l.push(G(m, e, t).t);
3599
+ else {
3600
+ const m = ((u[0] - e[0]) * h - (u[1] - e[1]) * f) / p, I = ((u[0] - e[0]) * a - (u[1] - e[1]) * i) / p;
3601
+ m > 0 && m < 1 && I >= 0 && I <= 1 && l.push(m);
3602
+ }
3603
+ }
3604
+ return l.sort((d, u) => d - u), l.slice(1).every((d, u) => o([e[0] + i * (d + l[u]) / 2, e[1] + a * (d + l[u]) / 2]));
3605
+ }
3606
+ export {
3607
+ Go as COORD_LIMIT,
3608
+ bs as DEFAULT_FOV,
3609
+ Is as DEFAULT_RANGE,
3610
+ Bo as DOOR_COST,
3611
+ $o as ELEVATOR_BASE,
3612
+ No as ELEVATOR_PER_METRE,
3613
+ Lo as EXTERIOR_PRESETS,
3614
+ Ds as HERE,
3615
+ tt as MIN_SEGMENT,
3616
+ zo as NAV_WELD,
3617
+ oo as OBJECT_KINDS,
3618
+ te as OPENING_MIN_SEGMENT,
3619
+ rn as PITCH,
3620
+ Oo as STAIR_CLIMB_FACTOR,
3621
+ ie as addBarrier,
3622
+ Ko as addBoundaryHole,
3623
+ fn as addNavEdge,
3624
+ cn as addNavNode,
3625
+ fo as addPortalGroup,
3626
+ Ut as addVirtualBoundary,
3627
+ ro as addZone,
3628
+ ri as applyMutation,
3629
+ ks as applyMutations,
3630
+ X as barrierEnds,
3631
+ yn as bindSpaceToRegion,
3632
+ ys as blobDataUrl,
3633
+ Z as boundaryEdges,
3634
+ Vo as boundaryRegionAt,
3635
+ oe as boundaryRegions,
3636
+ At as boundaryRings,
3637
+ ai as buildRoomNavigation,
3638
+ Ns as captive,
3639
+ vt as centroid,
3640
+ Gs as chainVertical,
3641
+ C as closeRing,
3642
+ qo as connectSpace,
3643
+ ei as copyProject,
3644
+ ti as coverageOf,
3645
+ An as createObject,
3646
+ po as derivedGraph,
3647
+ se as derivedSpaceRings,
3648
+ Jo as disconnectSpace,
3649
+ S as distance,
3650
+ kn as divideSpaces,
3651
+ Xo as drawVirtualBoundary,
3652
+ ls as duplicateFloor,
3653
+ Ye as edgeCost,
3654
+ Xt as edgeLength,
3655
+ Dt as effectivePortals,
3656
+ Qs as emptyProject,
3657
+ Xs as enclosedRegion,
3658
+ Sn as enclosedRegions,
3659
+ Ps as entryInto,
3660
+ oi as exportProject,
3661
+ Us as findRoute,
3662
+ Se as flights,
3663
+ Bs as flightsAt,
3664
+ ce as floorPhrase,
3665
+ Zs as followsBoundaries,
3666
+ W as footprint,
3667
+ Zo as freezeProject,
3668
+ Hs as geoOrigin,
3669
+ si as importProject,
3670
+ Rt as inSpace,
3671
+ xe as inferOpenBoundaries,
3672
+ fs as inferPortals,
3673
+ pt as isArea,
3674
+ Rs as isDevice,
3675
+ nn as isOpening,
3676
+ et as isSpace,
3677
+ zt as isVertical,
3678
+ ps as mergeSpaces,
3679
+ Ws as moveOrigin,
3680
+ ln as navEdges,
3681
+ Ft as navNodes,
3682
+ Ls as navPath,
3683
+ co as nestZone,
3684
+ Tt as normalizeBoundaries,
3685
+ nt as objectArea,
3686
+ yt as objectPosition,
3687
+ xn as objectRotation,
3688
+ T as openRing,
3689
+ ni as openingFloorId,
3690
+ ii as parseExport,
3691
+ Ts as passesThrough,
3692
+ $s as perimeter,
3693
+ bo as pitchOf,
3694
+ D as pointInRing,
3695
+ Fs as primaryShafts,
3696
+ Nt as pruneOntology,
3697
+ Os as reaches,
3698
+ Zt as rectangle,
3699
+ qs as refitEnclosedRooms,
3700
+ vn as refreshBoundarySpaces,
3701
+ gs as refreshPortals,
3702
+ as as removeFloor,
3703
+ uo as removePortalGroup,
3704
+ ao as removeZone,
3705
+ V as ringArea,
3706
+ Lt as rotate,
3707
+ Fo as routeAnchors,
3708
+ Co as routeSteps,
3709
+ Io as runFor,
3710
+ G as segmentProjection,
3711
+ ss as segmentsCross,
3712
+ wt as servedFloors,
3713
+ ho as setPortalGroupMembers,
3714
+ lo as setZoneMembers,
3715
+ It as shaftKey,
3716
+ Cs as shaftVoids,
3717
+ on as sharedBoundaryPortals,
3718
+ Vs as slopeElevation,
3719
+ ve as spaceAt,
3720
+ ds as spacePoint,
3721
+ Js as spaces,
3722
+ ms as spacesDividedBy,
3723
+ Ks as spacesRejoinedBy,
3724
+ zs as span,
3725
+ Ys as toLngLat,
3726
+ js as toLocal,
3727
+ Ho as transact,
3728
+ H as uid,
3729
+ Uo as validateNavigation,
3730
+ Ae as validateProject,
3731
+ Do as validateRelationships,
3732
+ hn as validateRings,
3733
+ io as zoneSpaces
3734
+ };
3735
+ //# sourceMappingURL=index.js.map