open-plant 1.2.7 → 1.2.9

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 CHANGED
@@ -1,9 +1,9 @@
1
- var rr = Object.defineProperty;
2
- var ir = (e, t, n) => t in e ? rr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var b = (e, t, n) => ir(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as Ut, jsxs as mn, Fragment as or } from "react/jsx-runtime";
5
- import { useRef as j, useMemo as tt, useCallback as B, useEffect as X, useState as Jt } from "react";
6
- function gn(e, t, n) {
1
+ var mr = Object.defineProperty;
2
+ var gr = (e, t, n) => t in e ? mr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var b = (e, t, n) => gr(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as Ut, jsxs as xn, Fragment as pr } from "react/jsx-runtime";
5
+ import { useRef as j, useMemo as q, useCallback as B, useEffect as k, useState as te } from "react";
6
+ function Tn(e, t, n) {
7
7
  const r = e.createShader(t);
8
8
  if (!r)
9
9
  throw new Error("Failed to create shader.");
@@ -13,8 +13,8 @@ function gn(e, t, n) {
13
13
  }
14
14
  return r;
15
15
  }
16
- function sr(e, t, n) {
17
- const r = gn(e, e.VERTEX_SHADER, t), i = gn(e, e.FRAGMENT_SHADER, n), o = e.createProgram();
16
+ function br(e, t, n) {
17
+ const r = Tn(e, e.VERTEX_SHADER, t), i = Tn(e, e.FRAGMENT_SHADER, n), o = e.createProgram();
18
18
  if (!o)
19
19
  throw e.deleteShader(r), e.deleteShader(i), new Error("Failed to create program.");
20
20
  if (e.attachShader(o, r), e.attachShader(o, i), e.linkProgram(o), e.deleteShader(r), e.deleteShader(i), !e.getProgramParameter(o, e.LINK_STATUS)) {
@@ -23,13 +23,13 @@ function sr(e, t, n) {
23
23
  }
24
24
  return o;
25
25
  }
26
- function _e(e, t, n) {
26
+ function Le(e, t, n) {
27
27
  const r = e.getUniformLocation(t, n);
28
28
  if (!r)
29
29
  throw new Error(`Failed to get uniform location: ${n}`);
30
30
  return r;
31
31
  }
32
- function ar(e) {
32
+ function wr(e) {
33
33
  const t = e.getContext("webgl2", {
34
34
  alpha: !1,
35
35
  antialias: !1,
@@ -42,7 +42,7 @@ function ar(e) {
42
42
  throw new Error("WebGL2 is not available.");
43
43
  return t;
44
44
  }
45
- let ur = class {
45
+ let yr = class {
46
46
  constructor() {
47
47
  b(this, "viewportWidth", 1);
48
48
  b(this, "viewportHeight", 1);
@@ -82,7 +82,7 @@ let ur = class {
82
82
  ]);
83
83
  }
84
84
  };
85
- const cr = `#version 300 es
85
+ const Sr = `#version 300 es
86
86
  precision highp float;
87
87
 
88
88
  in vec2 aUnit;
@@ -102,7 +102,7 @@ void main() {
102
102
  gl_Position = vec4(clip.xy, 0.0, 1.0);
103
103
  vUv = aUv;
104
104
  }
105
- `, lr = `#version 300 es
105
+ `, xr = `#version 300 es
106
106
  precision highp float;
107
107
 
108
108
  in vec2 vUv;
@@ -114,11 +114,11 @@ void main() {
114
114
  outColor = texture(uTexture, vUv);
115
115
  }
116
116
  `;
117
- class hr {
117
+ class Tr {
118
118
  constructor(t) {
119
119
  b(this, "canvas");
120
120
  b(this, "gl");
121
- b(this, "camera", new ur());
121
+ b(this, "camera", new yr());
122
122
  b(this, "imageWidth");
123
123
  b(this, "imageHeight");
124
124
  b(this, "clearColor");
@@ -135,7 +135,7 @@ class hr {
135
135
  b(this, "destroyed", !1);
136
136
  b(this, "fitted", !1);
137
137
  b(this, "controlledViewState", !1);
138
- this.canvas = t.canvas, this.imageWidth = Math.max(1, t.imageWidth), this.imageHeight = Math.max(1, t.imageHeight), this.clearColor = t.clearColor ?? [0.03, 0.05, 0.08, 1], this.gl = ar(this.canvas), this.program = sr(this.gl, cr, lr);
138
+ this.canvas = t.canvas, this.imageWidth = Math.max(1, t.imageWidth), this.imageHeight = Math.max(1, t.imageHeight), this.clearColor = t.clearColor ?? [0.03, 0.05, 0.08, 1], this.gl = wr(this.canvas), this.program = br(this.gl, Sr, xr);
139
139
  const n = this.gl.createVertexArray(), r = this.gl.createBuffer();
140
140
  if (!n || !r)
141
141
  throw new Error("Failed to create WebGL buffers.");
@@ -177,15 +177,15 @@ class hr {
177
177
  !1,
178
178
  a,
179
179
  2 * Float32Array.BYTES_PER_ELEMENT
180
- ), this.gl.bindVertexArray(null), this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null), this.uCameraLocation = _e(
180
+ ), this.gl.bindVertexArray(null), this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null), this.uCameraLocation = Le(
181
181
  this.gl,
182
182
  this.program,
183
183
  "uCamera"
184
- ), this.uBoundsLocation = _e(
184
+ ), this.uBoundsLocation = Le(
185
185
  this.gl,
186
186
  this.program,
187
187
  "uBounds"
188
- ), this.uTextureLocation = _e(
188
+ ), this.uTextureLocation = Le(
189
189
  this.gl,
190
190
  this.program,
191
191
  "uTexture"
@@ -310,16 +310,16 @@ class hr {
310
310
  this.gl.deleteTexture(n.texture);
311
311
  }
312
312
  }
313
- const fr = 0.1, dr = 4e6, mr = 4096, gr = 64, Fn = 1e-6, pr = 24;
314
- function Ne(e, t, n) {
313
+ const Mr = 0.1, Ar = 4e6, Pr = 4096, Rr = 64, Er = 1, vr = 4, On = 1e-6, Cr = 24;
314
+ function Ee(e, t, n) {
315
315
  return Math.max(t, Math.min(n, e));
316
316
  }
317
- function Wt(e) {
317
+ function Ft(e) {
318
318
  if (!Array.isArray(e) || e.length < 3) return [];
319
319
  const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
320
320
  return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
321
321
  }
322
- function br(e) {
322
+ function Ir(e) {
323
323
  if (!Array.isArray(e) || e.length === 0) return [];
324
324
  const t = [];
325
325
  for (const n of e) {
@@ -331,8 +331,8 @@ function br(e) {
331
331
  }
332
332
  return t;
333
333
  }
334
- function wr(e, t, n) {
335
- if (t <= Fn || n < 8) return [];
334
+ function _r(e, t, n) {
335
+ if (t <= On || n < 8) return [];
336
336
  const r = [];
337
337
  for (let i = 0; i <= n; i += 1) {
338
338
  const o = i / n * Math.PI * 2;
@@ -341,53 +341,53 @@ function wr(e, t, n) {
341
341
  e[1] + Math.sin(o) * t
342
342
  ]);
343
343
  }
344
- return Wt(r);
344
+ return Ft(r);
345
345
  }
346
- function Be(e, t) {
346
+ function De(e, t) {
347
347
  if (!e.length) return [];
348
348
  let n = 1 / 0, r = 1 / 0, i = -1 / 0, o = -1 / 0;
349
- for (const [a, u] of e)
350
- a < n && (n = a), a > i && (i = a), u < r && (r = u), u > o && (o = u);
349
+ for (const [a, c] of e)
350
+ a < n && (n = a), a > i && (i = a), c < r && (r = c), c > o && (o = c);
351
351
  if (!Number.isFinite(n) || !Number.isFinite(r)) return [];
352
352
  const s = Math.max(t, 1);
353
- return Wt([
353
+ return Ft([
354
354
  [n - s, r - s],
355
355
  [i + s, r - s],
356
356
  [i + s, o + s],
357
357
  [n - s, o + s]
358
358
  ]);
359
359
  }
360
- function yr(e, t) {
360
+ function Br(e, t) {
361
361
  let n = 1 / 0, r = 1 / 0, i = -1 / 0, o = -1 / 0;
362
- for (const [a, u] of e)
363
- a < n && (n = a), a > i && (i = a), u < r && (r = u), u > o && (o = u);
362
+ for (const [a, c] of e)
363
+ a < n && (n = a), a > i && (i = a), c < r && (r = c), c > o && (o = c);
364
364
  const s = Math.max(t, 1);
365
365
  return [n - s, r - s, i + s, o + s];
366
366
  }
367
- function xr(e, t, n) {
367
+ function Ur(e, t, n) {
368
368
  const r = Math.max(
369
- fr,
369
+ Mr,
370
370
  Number(n.minRasterStep) || 0
371
371
  ), i = Math.max(
372
372
  32768,
373
- Math.floor(n.maxRasterPixels || dr)
373
+ Math.floor(n.maxRasterPixels || Ar)
374
374
  ), o = Math.max(
375
375
  256,
376
- Math.floor(n.maxRasterSize || mr)
376
+ Math.floor(n.maxRasterSize || Pr)
377
377
  ), s = Math.max(1e-3, e[2] - e[0]), a = Math.max(1e-3, e[3] - e[1]);
378
- let u = Math.max(r, Number.EPSILON), c = 3, h = Math.ceil(s / u) + c * 2 + 1, g = Math.ceil(a / u) + c * 2 + 1;
379
- for (; (h > o || g > o || h * g > i) && (u *= 1.15, h = Math.ceil(s / u) + c * 2 + 1, g = Math.ceil(a / u) + c * 2 + 1, !(u > Math.max(s, a))); )
378
+ let c = Math.max(r, Number.EPSILON), h = 3, l = Math.ceil(s / c) + h * 2 + 1, m = Math.ceil(a / c) + h * 2 + 1;
379
+ for (; (l > o || m > o || l * m > i) && (c *= 1.15, l = Math.ceil(s / c) + h * 2 + 1, m = Math.ceil(a / c) + h * 2 + 1, !(c > Math.max(s, a))); )
380
380
  ;
381
- return h = Math.max(8, h), g = Math.max(8, g), {
381
+ return l = Math.max(8, l), m = Math.max(8, m), {
382
382
  minX: e[0],
383
383
  minY: e[1],
384
- step: u,
385
- padding: c,
386
- width: h,
387
- height: g
384
+ step: c,
385
+ padding: h,
386
+ width: l,
387
+ height: m
388
388
  };
389
389
  }
390
- function Sr(e, t) {
390
+ function Fr(e, t) {
391
391
  if (typeof OffscreenCanvas < "u") {
392
392
  const r = new OffscreenCanvas(e, t).getContext("2d", { willReadFrequently: !0 });
393
393
  if (r) return r;
@@ -398,17 +398,17 @@ function Sr(e, t) {
398
398
  }
399
399
  return null;
400
400
  }
401
- function Tr(e, t) {
401
+ function zr(e, t) {
402
402
  return [
403
403
  (e[0] - t.minX) / t.step + t.padding,
404
404
  (e[1] - t.minY) / t.step + t.padding
405
405
  ];
406
406
  }
407
- function Mr(e, t, n) {
408
- const r = Sr(n.width, n.height);
407
+ function Lr(e, t, n) {
408
+ const r = Fr(n.width, n.height);
409
409
  if (!r) return new Uint8Array(0);
410
410
  r.clearRect(0, 0, n.width, n.height), r.fillStyle = "#ffffff", r.strokeStyle = "#ffffff", r.lineCap = "round", r.lineJoin = "round", r.lineWidth = t * 2 / n.step;
411
- const i = e.map((a) => Tr(a, n));
411
+ const i = e.map((a) => zr(a, n));
412
412
  if (i.length <= 1) {
413
413
  const a = i[0];
414
414
  if (!a) return new Uint8Array(0);
@@ -421,37 +421,37 @@ function Mr(e, t, n) {
421
421
  }
422
422
  const o = r.getImageData(0, 0, n.width, n.height), s = new Uint8Array(n.width * n.height);
423
423
  for (let a = 0; a < s.length; a += 1)
424
- s[a] = o.data[a * 4 + 3] >= pr ? 1 : 0;
424
+ s[a] = o.data[a * 4 + 3] >= Cr ? 1 : 0;
425
425
  return s;
426
426
  }
427
- function Ar(e, t, n) {
428
- const r = [], i = t + 1, o = (a, u) => u * i + a, s = (a, u) => a >= 0 && u >= 0 && a < t && u < n && e[u * t + a] > 0;
427
+ function Dr(e, t, n) {
428
+ const r = [], i = t + 1, o = (a, c) => c * i + a, s = (a, c) => a >= 0 && c >= 0 && a < t && c < n && e[c * t + a] > 0;
429
429
  for (let a = 0; a < n; a += 1)
430
- for (let u = 0; u < t; u += 1)
431
- s(u, a) && (s(u, a - 1) || r.push({
432
- start: o(u, a),
433
- end: o(u + 1, a),
430
+ for (let c = 0; c < t; c += 1)
431
+ s(c, a) && (s(c, a - 1) || r.push({
432
+ start: o(c, a),
433
+ end: o(c + 1, a),
434
434
  dir: 0
435
- }), s(u + 1, a) || r.push({
436
- start: o(u + 1, a),
437
- end: o(u + 1, a + 1),
435
+ }), s(c + 1, a) || r.push({
436
+ start: o(c + 1, a),
437
+ end: o(c + 1, a + 1),
438
438
  dir: 1
439
- }), s(u, a + 1) || r.push({
440
- start: o(u + 1, a + 1),
441
- end: o(u, a + 1),
439
+ }), s(c, a + 1) || r.push({
440
+ start: o(c + 1, a + 1),
441
+ end: o(c, a + 1),
442
442
  dir: 2
443
- }), s(u - 1, a) || r.push({
444
- start: o(u, a + 1),
445
- end: o(u, a),
443
+ }), s(c - 1, a) || r.push({
444
+ start: o(c, a + 1),
445
+ end: o(c, a),
446
446
  dir: 3
447
447
  }));
448
448
  return r;
449
449
  }
450
- function Pr(e, t) {
450
+ function Nr(e, t) {
451
451
  const n = (t - e + 4) % 4;
452
452
  return n === 1 ? 0 : n === 0 ? 1 : n === 3 ? 2 : 3;
453
453
  }
454
- function Er(e) {
454
+ function kr(e) {
455
455
  if (!e.length) return [];
456
456
  const t = /* @__PURE__ */ new Map();
457
457
  for (let i = 0; i < e.length; i += 1) {
@@ -462,30 +462,30 @@ function Er(e) {
462
462
  for (let i = 0; i < e.length; i += 1) {
463
463
  if (n[i]) continue;
464
464
  const o = e[i], s = o.start;
465
- let a = o.end, u = o.dir;
466
- const c = [o.start, o.end];
465
+ let a = o.end, c = o.dir;
466
+ const h = [o.start, o.end];
467
467
  n[i] = 1;
468
- let h = 0;
469
- const g = e.length * 3;
470
- for (; a !== s && h < g; ) {
468
+ let l = 0;
469
+ const m = e.length * 3;
470
+ for (; a !== s && l < m; ) {
471
471
  const d = t.get(a);
472
472
  if (!d || d.length === 0) break;
473
- let p = -1, x = 1 / 0;
474
- for (const P of d) {
475
- if (n[P]) continue;
476
- const k = e[P], C = Pr(u, k.dir);
477
- C < x && (x = C, p = P);
473
+ let w = -1, S = 1 / 0;
474
+ for (const T of d) {
475
+ if (n[T]) continue;
476
+ const L = e[T], v = Nr(c, L.dir);
477
+ v < S && (S = v, w = T);
478
478
  }
479
- if (p < 0) break;
480
- n[p] = 1;
481
- const S = e[p];
482
- a = S.end, u = S.dir, c.push(a), h += 1;
479
+ if (w < 0) break;
480
+ n[w] = 1;
481
+ const x = e[w];
482
+ a = x.end, c = x.dir, h.push(a), l += 1;
483
483
  }
484
- c.length >= 4 && c[0] === c[c.length - 1] && r.push(c);
484
+ h.length >= 4 && h[0] === h[h.length - 1] && r.push(h);
485
485
  }
486
486
  return r;
487
487
  }
488
- function Rr(e, t, n) {
488
+ function Xr(e, t, n) {
489
489
  const r = t + 1, i = [];
490
490
  for (const o of e) {
491
491
  const s = o % r, a = Math.floor(o / r);
@@ -494,9 +494,9 @@ function Rr(e, t, n) {
494
494
  n.minY + (a - n.padding) * n.step
495
495
  ]);
496
496
  }
497
- return Wt(i);
497
+ return Ft(i);
498
498
  }
499
- function vr(e) {
499
+ function Yr(e) {
500
500
  if (e.length < 4) return 0;
501
501
  let t = 0;
502
502
  for (let n = 0; n < e.length - 1; n += 1) {
@@ -505,30 +505,30 @@ function vr(e) {
505
505
  }
506
506
  return t * 0.5;
507
507
  }
508
- function Cr(e, t = 1e-9) {
509
- const n = Wt(e);
508
+ function Wr(e, t = 1e-9) {
509
+ const n = Ft(e);
510
510
  if (n.length < 5) return n;
511
511
  const r = [n[0]];
512
512
  for (let i = 1; i < n.length - 1; i += 1) {
513
- const o = r[r.length - 1], s = n[i], a = n[i + 1], u = (s[0] - o[0]) * (a[1] - s[1]) - (s[1] - o[1]) * (a[0] - s[0]);
514
- Math.abs(u) <= t || r.push(s);
513
+ const o = r[r.length - 1], s = n[i], a = n[i + 1], c = (s[0] - o[0]) * (a[1] - s[1]) - (s[1] - o[1]) * (a[0] - s[0]);
514
+ Math.abs(c) <= t || r.push(s);
515
515
  }
516
- return r.push(r[0]), Wt(r);
516
+ return r.push(r[0]), Ft(r);
517
517
  }
518
- function Ir(e, t, n) {
518
+ function Or(e, t, n) {
519
519
  const r = n[0] - t[0], i = n[1] - t[1], o = r * r + i * i;
520
520
  if (o <= 1e-12) {
521
- const g = e[0] - t[0], d = e[1] - t[1];
522
- return g * g + d * d;
521
+ const m = e[0] - t[0], d = e[1] - t[1];
522
+ return m * m + d * d;
523
523
  }
524
- const s = Ne(
524
+ const s = Ee(
525
525
  ((e[0] - t[0]) * r + (e[1] - t[1]) * i) / o,
526
526
  0,
527
527
  1
528
- ), a = t[0] + r * s, u = t[1] + i * s, c = e[0] - a, h = e[1] - u;
529
- return c * c + h * h;
528
+ ), a = t[0] + r * s, c = t[1] + i * s, h = e[0] - a, l = e[1] - c;
529
+ return h * h + l * l;
530
530
  }
531
- function _r(e, t) {
531
+ function Vr(e, t) {
532
532
  if (e.length <= 2 || t <= 0) return e.slice();
533
533
  const n = new Uint8Array(e.length);
534
534
  n[0] = 1, n[e.length - 1] = 1;
@@ -536,87 +536,233 @@ function _r(e, t) {
536
536
  for (; i.length > 0; ) {
537
537
  const s = i.pop();
538
538
  if (!s) break;
539
- const [a, u] = s;
540
- if (u - a <= 1) continue;
541
- let c = 0, h = -1;
542
- for (let g = a + 1; g < u; g += 1) {
543
- const d = Ir(e[g], e[a], e[u]);
544
- d > c && (c = d, h = g);
539
+ const [a, c] = s;
540
+ if (c - a <= 1) continue;
541
+ let h = 0, l = -1;
542
+ for (let m = a + 1; m < c; m += 1) {
543
+ const d = Or(e[m], e[a], e[c]);
544
+ d > h && (h = d, l = m);
545
545
  }
546
- h >= 0 && c > r && (n[h] = 1, i.push([a, h], [h, u]));
546
+ l >= 0 && h > r && (n[l] = 1, i.push([a, l], [l, c]));
547
547
  }
548
548
  const o = [];
549
549
  for (let s = 0; s < e.length; s += 1)
550
550
  n[s] && o.push(e[s]);
551
551
  return o;
552
552
  }
553
- function Br(e, t) {
554
- const n = Wt(e);
553
+ function Gr(e, t) {
554
+ const n = Ft(e);
555
555
  if (n.length < 5 || t <= 0) return n;
556
- const r = n.slice(0, -1), i = _r(r, t);
557
- return i.length < 3 ? n : Wt(i);
556
+ const r = n.slice(0, -1), i = Vr(r, t);
557
+ return i.length < 3 ? n : Ft(i);
558
+ }
559
+ function qr(e, t) {
560
+ let n = Ft(e);
561
+ if (t <= 0 || n.length < 5) return n;
562
+ for (let r = 0; r < t; r += 1) {
563
+ const i = n.slice(0, -1);
564
+ if (i.length < 3) break;
565
+ const o = [];
566
+ for (let s = 0; s < i.length; s += 1) {
567
+ const a = i[s], c = i[(s + 1) % i.length];
568
+ o.push(
569
+ [a[0] * 0.75 + c[0] * 0.25, a[1] * 0.75 + c[1] * 0.25],
570
+ [a[0] * 0.25 + c[0] * 0.75, a[1] * 0.25 + c[1] * 0.75]
571
+ );
572
+ }
573
+ n = Ft(o);
574
+ }
575
+ return n;
558
576
  }
559
- function ie(e, t) {
560
- return t ? Wt(
577
+ function se(e, t) {
578
+ return t ? Ft(
561
579
  e.map(([n, r]) => [
562
- Ne(n, t[0], t[2]),
563
- Ne(r, t[1], t[3])
580
+ Ee(n, t[0], t[2]),
581
+ Ee(r, t[1], t[3])
564
582
  ])
565
583
  ) : e;
566
584
  }
567
- function Fr(e, t) {
568
- const n = br(e), r = Math.max(Fn, Number(t.radius) || 0);
585
+ function Hr(e, t) {
586
+ const n = Ir(e), r = Math.max(On, Number(t.radius) || 0);
569
587
  if (n.length === 0 || !Number.isFinite(r)) return [];
570
- const i = Math.max(12, Math.floor(t.circleSides || gr));
588
+ const i = Math.max(12, Math.floor(t.circleSides || Rr));
571
589
  if (n.length === 1)
572
- return ie(
573
- wr(n[0], r, i),
590
+ return se(
591
+ _r(n[0], r, i),
574
592
  t.clipBounds
575
593
  );
576
- const o = yr(n, r), s = xr(o, r, t), a = Mr(n, r, s);
594
+ const o = Br(n, r), s = Ur(o, r, t), a = Lr(n, r, s);
577
595
  if (!a.length)
578
- return ie(Be(n, r), t.clipBounds);
579
- const u = Ar(a, s.width, s.height), c = Er(u);
580
- if (!c.length)
581
- return ie(Be(n, r), t.clipBounds);
582
- let h = [], g = 0;
583
- for (const x of c) {
584
- const S = Rr(x, s.width, s), P = Math.abs(vr(S));
585
- P <= g || (g = P, h = S);
586
- }
596
+ return se(De(n, r), t.clipBounds);
597
+ const c = Dr(a, s.width, s.height), h = kr(c);
587
598
  if (!h.length)
588
- return ie(Be(n, r), t.clipBounds);
589
- const d = typeof t.simplifyTolerance == "number" && Number.isFinite(t.simplifyTolerance) ? Math.max(0, t.simplifyTolerance) : s.step * 0.2, p = Br(
590
- Cr(h, s.step * 1e-3),
599
+ return se(De(n, r), t.clipBounds);
600
+ let l = [], m = 0;
601
+ for (const x of h) {
602
+ const T = Xr(x, s.width, s), L = Math.abs(Yr(T));
603
+ L <= m || (m = L, l = T);
604
+ }
605
+ if (!l.length)
606
+ return se(De(n, r), t.clipBounds);
607
+ const d = typeof t.simplifyTolerance == "number" && Number.isFinite(t.simplifyTolerance) ? Math.max(0, t.simplifyTolerance) : s.step * 0.2, w = typeof t.smoothingPasses == "number" && Number.isFinite(t.smoothingPasses) ? Math.round(Ee(t.smoothingPasses, 0, vr)) : Er, S = Gr(
608
+ qr(
609
+ Wr(l, s.step * 1e-3),
610
+ w
611
+ ),
591
612
  d
592
613
  );
593
- return ie(p, t.clipBounds);
614
+ return se(S, t.clipBounds);
615
+ }
616
+ function Mn(e) {
617
+ return typeof e == "number" && Number.isFinite(e);
618
+ }
619
+ function $r(e) {
620
+ return Array.isArray(e) && e.length >= 2 && Mn(e[0]) && Mn(e[1]);
621
+ }
622
+ function Vn(e) {
623
+ return Array.isArray(e) && e.length > 0 && e.every((t) => $r(t));
624
+ }
625
+ function Gn(e) {
626
+ return Array.isArray(e) && e.length > 0 && e.every((t) => Vn(t));
627
+ }
628
+ function Zr(e) {
629
+ return Array.isArray(e) && e.length > 0 && e.every((t) => Gn(t));
630
+ }
631
+ function Kr(e) {
632
+ if (!Array.isArray(e) || e.length < 3) return [];
633
+ const t = [];
634
+ for (const i of e) {
635
+ if (!Array.isArray(i) || i.length < 2) continue;
636
+ const o = Number(i[0]), s = Number(i[1]);
637
+ if (!Number.isFinite(o) || !Number.isFinite(s)) continue;
638
+ const a = t[t.length - 1];
639
+ a && a[0] === o && a[1] === s || t.push([o, s]);
640
+ }
641
+ if (t.length < 3) return [];
642
+ const n = t[0], r = t[t.length - 1];
643
+ return (n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t.length >= 4 ? t : [];
644
+ }
645
+ function Ve(e) {
646
+ if (!Array.isArray(e) || e.length < 4) return 0;
647
+ let t = 0;
648
+ for (let n = 0; n < e.length - 1; n += 1) {
649
+ const r = e[n], i = e[n + 1];
650
+ t += r[0] * i[1] - i[0] * r[1];
651
+ }
652
+ return t * 0.5;
653
+ }
654
+ function Ne(e) {
655
+ if (!Array.isArray(e) || e.length === 0) return [];
656
+ const t = [];
657
+ for (const o of e) {
658
+ const s = Kr(o);
659
+ s.length >= 4 && t.push(s);
660
+ }
661
+ if (t.length === 0) return [];
662
+ if (t.length === 1) return [t[0]];
663
+ let n = 0, r = 0;
664
+ for (let o = 0; o < t.length; o += 1) {
665
+ const s = Math.abs(Ve(t[o]));
666
+ s <= r || (r = s, n = o);
667
+ }
668
+ const i = [t[n]];
669
+ for (let o = 0; o < t.length; o += 1)
670
+ o !== n && i.push(t[o]);
671
+ return i;
672
+ }
673
+ function qn(e) {
674
+ if (!e) return [];
675
+ if (Vn(e)) {
676
+ const t = Ne([e]);
677
+ return t.length > 0 ? [t] : [];
678
+ }
679
+ if (Gn(e)) {
680
+ const t = Ne(e);
681
+ return t.length > 0 ? [t] : [];
682
+ }
683
+ if (Zr(e)) {
684
+ const t = [];
685
+ for (const n of e) {
686
+ const r = Ne(n);
687
+ r.length > 0 && t.push(r);
688
+ }
689
+ return t;
690
+ }
691
+ return [];
692
+ }
693
+ function An(e, t, n) {
694
+ let r = !1;
695
+ for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
696
+ const s = n[i][0], a = n[i][1], c = n[o][0], h = n[o][1];
697
+ a > t != h > t && e < (c - s) * (t - a) / (h - a || Number.EPSILON) + s && (r = !r);
698
+ }
699
+ return r;
700
+ }
701
+ function le(e) {
702
+ const t = [];
703
+ for (const n of e ?? []) {
704
+ const r = qn(n);
705
+ for (const i of r) {
706
+ const o = i[0];
707
+ if (!o || o.length < 4) continue;
708
+ let s = 1 / 0, a = 1 / 0, c = -1 / 0, h = -1 / 0;
709
+ for (const [m, d] of o)
710
+ m < s && (s = m), m > c && (c = m), d < a && (a = d), d > h && (h = d);
711
+ if (!Number.isFinite(s) || !Number.isFinite(a) || !Number.isFinite(c) || !Number.isFinite(h))
712
+ continue;
713
+ let l = Math.abs(Ve(o));
714
+ for (let m = 1; m < i.length; m += 1)
715
+ l -= Math.abs(Ve(i[m]));
716
+ t.push({
717
+ outer: o,
718
+ holes: i.slice(1),
719
+ minX: s,
720
+ minY: a,
721
+ maxX: c,
722
+ maxY: h,
723
+ area: Math.max(1e-6, l)
724
+ });
725
+ }
726
+ }
727
+ return t;
728
+ }
729
+ function je(e, t, n) {
730
+ if (e < n.minX || e > n.maxX || t < n.minY || t > n.maxY || !An(e, t, n.outer)) return !1;
731
+ for (const r of n.holes)
732
+ if (An(e, t, r)) return !1;
733
+ return !0;
594
734
  }
595
- const Un = [
735
+ function ve(e, t, n) {
736
+ for (const r of n)
737
+ if (je(e, t, r))
738
+ return !0;
739
+ return !1;
740
+ }
741
+ const Hn = [
596
742
  160,
597
743
  160,
598
744
  160,
599
745
  255
600
746
  ];
601
- function it(e, t, n) {
747
+ function et(e, t, n) {
602
748
  return Math.max(t, Math.min(n, e));
603
749
  }
604
- function zn(e, t, n) {
750
+ function $n(e, t, n) {
605
751
  const r = Number(e), i = Number(t), o = Number(n);
606
752
  return !Number.isFinite(r) || r <= 0 ? 1 : !Number.isFinite(i) || !Number.isFinite(o) ? r : Math.pow(2, i - o) * r;
607
753
  }
608
- function co(e, t, n) {
609
- let i = 100 * zn(e, t, n);
754
+ function vo(e, t, n) {
755
+ let i = 100 * $n(e, t, n);
610
756
  if (Number(e)) {
611
757
  let o = "μm";
612
758
  return i > 1e3 && (i /= 1e3, o = "mm"), `${i.toPrecision(3)} ${o}`;
613
759
  }
614
760
  return `${Math.round(i * 1e3) / 1e3} pixels`;
615
761
  }
616
- function lo(e, t) {
762
+ function Co(e, t) {
617
763
  return !e && !t ? !0 : !e || !t ? !1 : Math.abs((e.zoom ?? 0) - (t.zoom ?? 0)) < 1e-6 && Math.abs((e.offsetX ?? 0) - (t.offsetX ?? 0)) < 1e-6 && Math.abs((e.offsetY ?? 0) - (t.offsetY ?? 0)) < 1e-6 && Math.abs((e.rotationDeg ?? 0) - (t.rotationDeg ?? 0)) < 1e-6;
618
764
  }
619
- function ho(e) {
765
+ function Io(e) {
620
766
  const t = String(e ?? "").trim();
621
767
  if (!t) return "";
622
768
  if (/^bearer\s+/i.test(t)) {
@@ -625,26 +771,26 @@ function ho(e) {
625
771
  }
626
772
  return `Bearer ${t}`;
627
773
  }
628
- function Ur(e) {
774
+ function Jr(e) {
629
775
  const n = String(e ?? "").trim().match(/^#?([0-9a-fA-F]{6})$/);
630
- if (!n) return [...Un];
776
+ if (!n) return [...Hn];
631
777
  const r = Number.parseInt(n[1], 16);
632
778
  return [r >> 16 & 255, r >> 8 & 255, r & 255, 255];
633
779
  }
634
- function fo(e) {
780
+ function _o(e) {
635
781
  const t = [
636
- [...Un]
782
+ [...Hn]
637
783
  ], n = /* @__PURE__ */ new Map();
638
784
  for (const i of e ?? []) {
639
785
  const o = String(i?.termId ?? "");
640
- !o || n.has(o) || (n.set(o, t.length), t.push(Ur(i?.termColor)));
786
+ !o || n.has(o) || (n.set(o, t.length), t.push(Jr(i?.termColor)));
641
787
  }
642
788
  const r = new Uint8Array(t.length * 4);
643
789
  for (let i = 0; i < t.length; i += 1)
644
790
  r[i * 4] = t[i][0], r[i * 4 + 1] = t[i][1], r[i * 4 + 2] = t[i][2], r[i * 4 + 3] = t[i][3];
645
791
  return { colors: r, termToPaletteIndex: n };
646
792
  }
647
- function pn(e, t, n) {
793
+ function Pn(e, t, n) {
648
794
  const r = e.createShader(e.VERTEX_SHADER), i = e.createShader(e.FRAGMENT_SHADER);
649
795
  if (!r || !i)
650
796
  throw new Error("Shader allocation failed");
@@ -659,7 +805,7 @@ function pn(e, t, n) {
659
805
  throw new Error(e.getProgramInfoLog(o) || "program link failed");
660
806
  return o;
661
807
  }
662
- const zr = "rgba(255, 77, 79, 0.16)", Lr = 3, Dr = 2, Ln = 96, Nr = 1, bn = [], Pe = [], wn = 1e3, Dn = 2, Nn = 2, kr = 4096, Xr = 0.2, Yr = 1.12, Wr = 0.89, Vr = 32, Or = "#000000", Gr = 0.1, qr = "#FFCF00", $r = "#FF0000", Hr = 1.5, yn = [2, 2], Zr = 1, Kr = 0.25, jr = 4, Jr = 1.5, Xt = {
808
+ const jr = "rgba(255, 77, 79, 0.16)", Qr = 3, ti = 2, Zn = 96, ei = 1, Rn = [], Ce = [], En = 1e3, Kn = 2, Jn = 2, ni = 4096, ri = 0.2, ii = 1.12, oi = 0.89, si = 32, ai = "#000000", ui = 0.1, ci = "#FFCF00", li = "#FF0000", hi = 1.5, vn = [2, 2], fi = 1, di = 0.25, mi = 4, gi = 1, pi = 0, bi = 4, wi = 0.05, yi = 256, Si = 1.5, Vt = {
663
809
  color: "#ff4d4f",
664
810
  width: 2,
665
811
  lineJoin: "round",
@@ -668,7 +814,7 @@ const zr = "rgba(255, 77, 79, 0.16)", Lr = 3, Dr = 2, Ln = 96, Nr = 1, bn = [],
668
814
  shadowBlur: 0,
669
815
  shadowOffsetX: 0,
670
816
  shadowOffsetY: 0
671
- }, Qr = {
817
+ }, xi = {
672
818
  color: "#4cc9f0",
673
819
  width: 2,
674
820
  lineDash: [10, 8],
@@ -691,92 +837,96 @@ const zr = "rgba(255, 77, 79, 0.16)", Lr = 3, Dr = 2, Ln = 96, Nr = 1, bn = [],
691
837
  offsetY: 10,
692
838
  borderRadius: 3
693
839
  };
694
- function ne(e, t, n) {
840
+ function Jt(e, t, n) {
695
841
  return Math.max(t, Math.min(n, e));
696
842
  }
697
- function we(e) {
843
+ function Se(e) {
698
844
  return e === "stamp-rectangle" || e === "stamp-circle" || e === "stamp-rectangle-4096px" || e === "stamp-rectangle-2mm2" || e === "stamp-circle-2mm2" || e === "stamp-circle-hpf-0.2mm2";
699
845
  }
700
- function se(e, t) {
846
+ function ue(e, t) {
701
847
  return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? t : e;
702
848
  }
703
- function ti(e) {
849
+ function Ti(e) {
704
850
  return {
705
- rectangleAreaMm2: se(e?.rectangleAreaMm2, Dn),
706
- circleAreaMm2: se(e?.circleAreaMm2, Nn),
707
- rectanglePixelSize: se(e?.rectanglePixelSize, kr)
851
+ rectangleAreaMm2: ue(e?.rectangleAreaMm2, Kn),
852
+ circleAreaMm2: ue(e?.circleAreaMm2, Jn),
853
+ rectanglePixelSize: ue(e?.rectanglePixelSize, ni)
708
854
  };
709
855
  }
710
- function ei(e, t) {
711
- return typeof e != "number" || !Number.isFinite(e) ? t : ne(e, 0, 1);
856
+ function Mi(e, t) {
857
+ return typeof e != "number" || !Number.isFinite(e) ? t : Jt(e, 0, 1);
712
858
  }
713
- function ni(e) {
714
- if (!Array.isArray(e)) return yn;
859
+ function Ai(e) {
860
+ if (!Array.isArray(e)) return vn;
715
861
  const t = e.filter((n) => Number.isFinite(n) && n >= 0);
716
- return t.length > 0 ? t : yn;
862
+ return t.length > 0 ? t : vn;
863
+ }
864
+ function Pi(e) {
865
+ return typeof e != "number" || !Number.isFinite(e) ? fi : Jt(e, di, mi);
717
866
  }
718
- function ri(e) {
719
- return typeof e != "number" || !Number.isFinite(e) ? Zr : ne(e, Kr, jr);
867
+ function Ri(e) {
868
+ return typeof e != "number" || !Number.isFinite(e) ? gi : Math.round(Jt(e, pi, bi));
720
869
  }
721
- function ii(e) {
722
- const t = se(e?.radius, Vr), n = se(e?.cursorLineWidth, Hr), r = ri(e?.edgeDetail);
870
+ function Ei(e) {
871
+ const t = ue(e?.radius, si), n = ue(e?.cursorLineWidth, hi), r = Pi(e?.edgeDetail), i = Ri(e?.edgeSmoothing);
723
872
  return {
724
873
  radius: t,
725
874
  edgeDetail: r,
875
+ edgeSmoothing: i,
726
876
  clickSelectRoi: e?.clickSelectRoi === !0,
727
- fillColor: e?.fillColor || Or,
728
- fillOpacity: ei(e?.fillOpacity, Gr),
729
- cursorColor: e?.cursorColor || qr,
730
- cursorActiveColor: e?.cursorActiveColor || $r,
877
+ fillColor: e?.fillColor || ai,
878
+ fillOpacity: Mi(e?.fillOpacity, ui),
879
+ cursorColor: e?.cursorColor || ci,
880
+ cursorActiveColor: e?.cursorActiveColor || li,
731
881
  cursorLineWidth: n,
732
- cursorLineDash: ni(e?.cursorLineDash)
882
+ cursorLineDash: Ai(e?.cursorLineDash)
733
883
  };
734
884
  }
735
- function oi(e) {
736
- return e * wn * wn;
885
+ function vi(e) {
886
+ return e * En * En;
737
887
  }
738
- function xn(e, t) {
739
- return !e || !Number.isFinite(t) || t <= 0 ? [] : Rt([
888
+ function Cn(e, t) {
889
+ return !e || !Number.isFinite(t) || t <= 0 ? [] : Ht([
740
890
  [e[0] - t, e[1] - t],
741
891
  [e[0] + t, e[1] - t],
742
892
  [e[0] + t, e[1] + t],
743
893
  [e[0] - t, e[1] + t]
744
894
  ]);
745
895
  }
746
- function si(e, t, n = Ln) {
896
+ function Ci(e, t, n = Zn) {
747
897
  if (!e || !Number.isFinite(t) || t <= 0) return [];
748
898
  const r = [];
749
899
  for (let i = 0; i <= n; i += 1) {
750
900
  const o = i / n * Math.PI * 2;
751
901
  r.push([e[0] + Math.cos(o) * t, e[1] + Math.sin(o) * t]);
752
902
  }
753
- return Rt(r);
903
+ return Ht(r);
754
904
  }
755
- function Rt(e) {
905
+ function Ht(e) {
756
906
  if (!Array.isArray(e) || e.length < 3) return [];
757
907
  const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
758
908
  return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
759
909
  }
760
- function Sn(e, t) {
761
- return !e || !t ? [] : Rt([
910
+ function In(e, t) {
911
+ return !e || !t ? [] : Ht([
762
912
  [e[0], e[1]],
763
913
  [t[0], e[1]],
764
914
  [t[0], t[1]],
765
915
  [e[0], t[1]]
766
916
  ]);
767
917
  }
768
- function Tn(e, t, n = Ln) {
918
+ function _n(e, t, n = Zn) {
769
919
  if (!e || !t) return [];
770
920
  const r = (e[0] + t[0]) * 0.5, i = (e[1] + t[1]) * 0.5, o = Math.hypot(t[0] - e[0], t[1] - e[1]) * 0.5;
771
921
  if (o < 1) return [];
772
922
  const s = [];
773
923
  for (let a = 0; a <= n; a += 1) {
774
- const u = a / n * Math.PI * 2;
775
- s.push([r + Math.cos(u) * o, i + Math.sin(u) * o]);
924
+ const c = a / n * Math.PI * 2;
925
+ s.push([r + Math.cos(c) * o, i + Math.sin(c) * o]);
776
926
  }
777
- return Rt(s);
927
+ return Ht(s);
778
928
  }
779
- function ke(e) {
929
+ function Ge(e) {
780
930
  if (!Array.isArray(e) || e.length < 4) return 0;
781
931
  let t = 0;
782
932
  for (let n = 0; n < e.length - 1; n += 1) {
@@ -785,17 +935,17 @@ function ke(e) {
785
935
  }
786
936
  return Math.abs(t * 0.5);
787
937
  }
788
- function Mn(e) {
938
+ function Bn(e) {
789
939
  if (!Array.isArray(e) || e.length === 0) return [0, 0, 0, 0];
790
940
  let t = 1 / 0, n = 1 / 0, r = -1 / 0, i = -1 / 0;
791
941
  for (const [o, s] of e)
792
942
  o < t && (t = o), o > r && (r = o), s < n && (n = s), s > i && (i = s);
793
943
  return [t, n, r, i];
794
944
  }
795
- function An(e) {
796
- return Array.isArray(e) && e.length >= 4 && ke(e) > Nr;
945
+ function Un(e) {
946
+ return Array.isArray(e) && e.length >= 4 && Ge(e) > ei;
797
947
  }
798
- function Xe(e, t, n = !1) {
948
+ function qe(e, t, n = !1) {
799
949
  if (t.length !== 0) {
800
950
  e.moveTo(t[0][0], t[0][1]);
801
951
  for (let r = 1; r < t.length; r += 1)
@@ -803,25 +953,25 @@ function Xe(e, t, n = !1) {
803
953
  n && e.closePath();
804
954
  }
805
955
  }
806
- function Qt(e, t, n, r = !1, i = !1) {
807
- t.length !== 0 && (e.beginPath(), Xe(e, t, r), i && r && (e.fillStyle = zr, e.fill()), e.strokeStyle = n.color, e.lineWidth = n.width, e.lineJoin = n.lineJoin, e.lineCap = n.lineCap, e.shadowColor = n.shadowColor, e.shadowBlur = n.shadowBlur, e.shadowOffsetX = n.shadowOffsetX, e.shadowOffsetY = n.shadowOffsetY, e.setLineDash(n.lineDash), e.stroke(), e.setLineDash(Pe), e.shadowColor = "rgba(0, 0, 0, 0)", e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0);
956
+ function Gt(e, t, n, r = !1, i = !1) {
957
+ t.length !== 0 && (e.beginPath(), qe(e, t, r), i && r && (e.fillStyle = jr, e.fill()), e.strokeStyle = n.color, e.lineWidth = n.width, e.lineJoin = n.lineJoin, e.lineCap = n.lineCap, e.shadowColor = n.shadowColor, e.shadowBlur = n.shadowBlur, e.shadowOffsetX = n.shadowOffsetX, e.shadowOffsetY = n.shadowOffsetY, e.setLineDash(n.lineDash), e.stroke(), e.setLineDash(Ce), e.shadowColor = "rgba(0, 0, 0, 0)", e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0);
808
958
  }
809
- function kn(e) {
810
- const t = Array.isArray(e?.lineDash) ? e.lineDash.filter((s) => Number.isFinite(s) && s >= 0) : Pe, n = typeof e?.width == "number" && Number.isFinite(e.width) ? Math.max(0, e.width) : Xt.width, r = typeof e?.shadowBlur == "number" && Number.isFinite(e.shadowBlur) ? Math.max(0, e.shadowBlur) : Xt.shadowBlur, i = typeof e?.shadowOffsetX == "number" && Number.isFinite(e.shadowOffsetX) ? e.shadowOffsetX : Xt.shadowOffsetX, o = typeof e?.shadowOffsetY == "number" && Number.isFinite(e.shadowOffsetY) ? e.shadowOffsetY : Xt.shadowOffsetY;
959
+ function jn(e) {
960
+ const t = Array.isArray(e?.lineDash) ? e.lineDash.filter((s) => Number.isFinite(s) && s >= 0) : Ce, n = typeof e?.width == "number" && Number.isFinite(e.width) ? Math.max(0, e.width) : Vt.width, r = typeof e?.shadowBlur == "number" && Number.isFinite(e.shadowBlur) ? Math.max(0, e.shadowBlur) : Vt.shadowBlur, i = typeof e?.shadowOffsetX == "number" && Number.isFinite(e.shadowOffsetX) ? e.shadowOffsetX : Vt.shadowOffsetX, o = typeof e?.shadowOffsetY == "number" && Number.isFinite(e.shadowOffsetY) ? e.shadowOffsetY : Vt.shadowOffsetY;
811
961
  return {
812
- color: e?.color || Xt.color,
962
+ color: e?.color || Vt.color,
813
963
  width: n,
814
- lineDash: t.length ? t : Pe,
815
- lineJoin: e?.lineJoin || Xt.lineJoin,
816
- lineCap: e?.lineCap || Xt.lineCap,
817
- shadowColor: e?.shadowColor || Xt.shadowColor,
964
+ lineDash: t.length ? t : Ce,
965
+ lineJoin: e?.lineJoin || Vt.lineJoin,
966
+ lineCap: e?.lineCap || Vt.lineCap,
967
+ shadowColor: e?.shadowColor || Vt.shadowColor,
818
968
  shadowBlur: r,
819
969
  shadowOffsetX: i,
820
970
  shadowOffsetY: o
821
971
  };
822
972
  }
823
- function oe(e, t) {
824
- return t ? kn({
973
+ function ae(e, t) {
974
+ return t ? jn({
825
975
  color: t.color ?? e.color,
826
976
  width: t.width ?? e.width,
827
977
  lineDash: t.lineDash ?? e.lineDash,
@@ -833,52 +983,52 @@ function oe(e, t) {
833
983
  shadowOffsetY: t.shadowOffsetY ?? e.shadowOffsetY
834
984
  }) : e;
835
985
  }
836
- function Pn(e, t) {
986
+ function Fn(e, t) {
837
987
  return e == null || t === null || t === void 0 ? !1 : String(e) === String(t);
838
988
  }
839
- function ai(e) {
989
+ function Ii(e) {
840
990
  const t = e[0];
841
991
  return Array.isArray(t) && Array.isArray(t[0]);
842
992
  }
843
- function En(e) {
993
+ function zn(e) {
844
994
  return typeof e == "number" && Number.isFinite(e);
845
995
  }
846
- function ui(e) {
847
- return Array.isArray(e) && e.length >= 2 && En(e[0]) && En(e[1]);
996
+ function _i(e) {
997
+ return Array.isArray(e) && e.length >= 2 && zn(e[0]) && zn(e[1]);
848
998
  }
849
- function ci(e) {
850
- return Array.isArray(e) && e.length >= 2 && e.every((t) => ui(t));
999
+ function Bi(e) {
1000
+ return Array.isArray(e) && e.length >= 2 && e.every((t) => _i(t));
851
1001
  }
852
- function Xn(e, t) {
1002
+ function Qn(e, t) {
853
1003
  if (!(!Array.isArray(e) || e.length === 0)) {
854
- if (ci(e)) {
1004
+ if (Bi(e)) {
855
1005
  t.push(e.map(([n, r]) => [n, r]));
856
1006
  return;
857
1007
  }
858
1008
  for (const n of e)
859
- Xn(n, t);
1009
+ Qn(n, t);
860
1010
  }
861
1011
  }
862
- function Rn(e, t) {
1012
+ function Ln(e, t) {
863
1013
  const n = [];
864
- Xn(e, n);
1014
+ Qn(e, n);
865
1015
  const r = [];
866
1016
  for (const i of n) {
867
1017
  if (i.length < 2) continue;
868
- const o = t ? Rt(i) : i;
1018
+ const o = t ? Ht(i) : i;
869
1019
  o.length >= (t ? 4 : 2) && r.push(o);
870
1020
  }
871
1021
  return r;
872
1022
  }
873
- function li(e, t, n, r) {
1023
+ function Ui(e, t, n, r) {
874
1024
  if (!(t.length < 4 || n.length === 0)) {
875
- e.save(), e.beginPath(), Xe(e, t, !0);
1025
+ e.save(), e.beginPath(), qe(e, t, !0);
876
1026
  for (const i of n)
877
- i.length < 4 || Xe(e, i, !0);
1027
+ i.length < 4 || qe(e, i, !0);
878
1028
  e.fillStyle = r, e.fill("evenodd"), e.restore();
879
1029
  }
880
1030
  }
881
- function hi(e) {
1031
+ function Fi(e) {
882
1032
  const t = typeof e?.paddingX == "number" && Number.isFinite(e.paddingX) ? Math.max(0, e.paddingX) : Et.paddingX, n = typeof e?.paddingY == "number" && Number.isFinite(e.paddingY) ? Math.max(0, e.paddingY) : Et.paddingY, r = typeof e?.fontSize == "number" && Number.isFinite(e.fontSize) ? Math.max(8, e.fontSize) : Et.fontSize, i = typeof e?.borderWidth == "number" && Number.isFinite(e.borderWidth) ? Math.max(0, e.borderWidth) : Et.borderWidth, o = typeof e?.offsetY == "number" && Number.isFinite(e.offsetY) ? e.offsetY : Et.offsetY, s = typeof e?.borderRadius == "number" && Number.isFinite(e.borderRadius) ? Math.max(0, e.borderRadius) : Et.borderRadius;
883
1033
  return {
884
1034
  fontFamily: e?.fontFamily || Et.fontFamily,
@@ -894,11 +1044,11 @@ function hi(e) {
894
1044
  borderRadius: s
895
1045
  };
896
1046
  }
897
- function fi(e, t, n, r, i, o) {
1047
+ function zi(e, t, n, r, i, o) {
898
1048
  const s = Math.max(0, Math.min(o, r * 0.5, i * 0.5));
899
1049
  e.beginPath(), e.moveTo(t + s, n), e.lineTo(t + r - s, n), e.quadraticCurveTo(t + r, n, t + r, n + s), e.lineTo(t + r, n + i - s), e.quadraticCurveTo(t + r, n + i, t + r - s, n + i), e.lineTo(t + s, n + i), e.quadraticCurveTo(t, n + i, t, n + i - s), e.lineTo(t, n + s), e.quadraticCurveTo(t, n, t + s, n), e.closePath();
900
1050
  }
901
- function di(e) {
1051
+ function Li(e) {
902
1052
  if (!e.length) return null;
903
1053
  let t = 1 / 0;
904
1054
  for (const i of e)
@@ -909,22 +1059,49 @@ function di(e) {
909
1059
  Math.abs(i[1] - t) > 0.5 || (i[0] < n && (n = i[0]), i[0] > r && (r = i[0]));
910
1060
  return !Number.isFinite(n) || !Number.isFinite(r) ? null : [(n + r) * 0.5, t];
911
1061
  }
912
- function mi(e, t, n, r, i, o) {
1062
+ function Di(e) {
1063
+ let t = null;
1064
+ for (const n of e) {
1065
+ const r = Li(n.outer);
1066
+ r && (!t || r[1] < t[1] || r[1] === t[1] && r[0] < t[0]) && (t = r);
1067
+ }
1068
+ return t;
1069
+ }
1070
+ function Dn(e) {
1071
+ const t = qn(e);
1072
+ if (t.length === 0) return [];
1073
+ const n = [];
1074
+ for (const r of t) {
1075
+ const i = r[0];
1076
+ if (!i || i.length < 4) continue;
1077
+ const o = i.map(([a, c]) => [a, c]), s = [];
1078
+ for (let a = 1; a < r.length; a += 1) {
1079
+ const c = r[a];
1080
+ !c || c.length < 4 || s.push(c.map(([h, l]) => [h, l]));
1081
+ }
1082
+ n.push({
1083
+ outer: o,
1084
+ holes: s
1085
+ });
1086
+ }
1087
+ return n;
1088
+ }
1089
+ function Ni(e, t, n, r, i, o) {
913
1090
  const s = t.trim();
914
1091
  if (!s) return;
915
1092
  e.save(), e.font = `${o.fontWeight} ${o.fontSize}px ${o.fontFamily}`, e.textAlign = "center", e.textBaseline = "middle";
916
- const u = e.measureText(s).width + o.paddingX * 2, c = o.fontSize + o.paddingY * 2, h = ne(n[0], u * 0.5 + 1, r - u * 0.5 - 1), g = ne(n[1] - o.offsetY, c * 0.5 + 1, i - c * 0.5 - 1), d = h - u * 0.5, p = g - c * 0.5;
917
- e.fillStyle = o.backgroundColor, e.strokeStyle = o.borderColor, e.lineWidth = o.borderWidth, fi(e, d, p, u, c, o.borderRadius), e.fill(), o.borderWidth > 0 && e.stroke(), e.fillStyle = o.textColor, e.fillText(s, h, g + 0.5), e.restore();
1093
+ const c = e.measureText(s).width + o.paddingX * 2, h = o.fontSize + o.paddingY * 2, l = Jt(n[0], c * 0.5 + 1, r - c * 0.5 - 1), m = Jt(n[1] - o.offsetY, h * 0.5 + 1, i - h * 0.5 - 1), d = l - c * 0.5, w = m - h * 0.5;
1094
+ e.fillStyle = o.backgroundColor, e.strokeStyle = o.borderColor, e.lineWidth = o.borderWidth, zi(e, d, w, c, h, o.borderRadius), e.fill(), o.borderWidth > 0 && e.stroke(), e.fillStyle = o.textColor, e.fillText(s, l, m + 0.5), e.restore();
918
1095
  }
919
- function Fe(e, t, n) {
920
- return [ne(e[0], 0, t), ne(e[1], 0, n)];
1096
+ function ke(e, t, n) {
1097
+ return [Jt(e[0], 0, t), Jt(e[1], 0, n)];
921
1098
  }
922
- function te(e) {
1099
+ function ee(e) {
923
1100
  if (!Array.isArray(e) || e.length < 2) return null;
924
1101
  const t = Number(e[0]), n = Number(e[1]);
925
1102
  return !Number.isFinite(t) || !Number.isFinite(n) ? null : [t, n];
926
1103
  }
927
- function gi({
1104
+ function ki({
928
1105
  tool: e,
929
1106
  imageWidth: t,
930
1107
  imageHeight: n,
@@ -933,28 +1110,28 @@ function gi({
933
1110
  stampOptions: o,
934
1111
  brushOptions: s,
935
1112
  projectorRef: a,
936
- onBrushTap: u,
937
- onDrawComplete: c,
938
- onPatchComplete: h,
939
- enabled: g,
1113
+ onBrushTap: c,
1114
+ onDrawComplete: h,
1115
+ onPatchComplete: l,
1116
+ enabled: m,
940
1117
  viewStateSignal: d,
941
- persistedRegions: p,
942
- patchRegions: x,
943
- persistedPolygons: S,
944
- regionStrokeStyle: P,
945
- regionStrokeHoverStyle: k,
946
- regionStrokeActiveStyle: C,
947
- patchStrokeStyle: E,
948
- resolveRegionStrokeStyle: D,
949
- overlayShapes: J,
950
- hoveredRegionId: ft = null,
951
- activeRegionId: at = null,
952
- regionLabelStyle: $,
953
- invalidateRef: ht,
954
- className: vt,
955
- style: Ot
1118
+ persistedRegions: w,
1119
+ patchRegions: S,
1120
+ persistedPolygons: x,
1121
+ regionStrokeStyle: T,
1122
+ regionStrokeHoverStyle: L,
1123
+ regionStrokeActiveStyle: v,
1124
+ patchStrokeStyle: P,
1125
+ resolveRegionStrokeStyle: F,
1126
+ overlayShapes: H,
1127
+ hoveredRegionId: dt = null,
1128
+ activeRegionId: wt = null,
1129
+ regionLabelStyle: mt,
1130
+ invalidateRef: X,
1131
+ className: Nt,
1132
+ style: zt
956
1133
  }) {
957
- const K = j(null), Ct = j(!1), zt = j(/* @__PURE__ */ new Map()), Kt = j(e), dt = j({
1134
+ const Z = j(null), vt = j(!1), Lt = j(/* @__PURE__ */ new Map()), jt = j(e), pt = j({
958
1135
  isDrawing: !1,
959
1136
  pointerId: null,
960
1137
  start: null,
@@ -962,10 +1139,34 @@ function gi({
962
1139
  cursor: null,
963
1140
  points: [],
964
1141
  stampCenter: null
965
- }), Q = g ?? e !== "cursor", M = tt(() => p && p.length > 0 ? p : !S || S.length === 0 ? bn : S.map((l, f) => ({
1142
+ }), nt = m ?? e !== "cursor", A = q(() => w && w.length > 0 ? w : !x || x.length === 0 ? Rn : x.map((u, f) => ({
966
1143
  id: f,
967
- coordinates: l
968
- })), [p, S]), I = tt(() => x ?? bn, [x]), A = tt(() => kn(P), [P]), L = tt(() => oe(A, k), [A, k]), Z = tt(() => oe(A, C), [A, C]), et = tt(() => oe(Qr, E), [E]), mt = tt(() => hi($), [$]), yt = tt(() => ti(o), [o]), U = tt(() => ii(s), [s]), At = tt(
1144
+ coordinates: u
1145
+ })), [w, x]), E = q(() => S ?? Rn, [S]), C = q(() => {
1146
+ const u = [];
1147
+ for (let f = 0; f < A.length; f += 1) {
1148
+ const p = A[f], y = Dn(p.coordinates);
1149
+ y.length !== 0 && u.push({
1150
+ region: p,
1151
+ regionIndex: f,
1152
+ regionKey: p.id ?? f,
1153
+ polygons: y
1154
+ });
1155
+ }
1156
+ return u;
1157
+ }, [A]), W = q(() => {
1158
+ const u = [];
1159
+ for (let f = 0; f < E.length; f += 1) {
1160
+ const p = E[f], y = Dn(p.coordinates);
1161
+ y.length !== 0 && u.push({
1162
+ region: p,
1163
+ regionIndex: f,
1164
+ regionKey: p.id ?? f,
1165
+ polygons: y
1166
+ });
1167
+ }
1168
+ return u;
1169
+ }, [E]), z = q(() => jn(T), [T]), ot = q(() => ae(z, L), [z, L]), rt = q(() => ae(z, v), [z, v]), St = q(() => ae(xi, P), [P]), ht = q(() => Fi(mt), [mt]), st = q(() => Ti(o), [o]), O = q(() => Ei(s), [s]), Q = q(
969
1170
  () => ({
970
1171
  position: "absolute",
971
1172
  inset: 0,
@@ -974,432 +1175,439 @@ function gi({
974
1175
  height: "100%",
975
1176
  display: "block",
976
1177
  touchAction: "none",
977
- pointerEvents: Q ? "auto" : "none",
978
- cursor: Q ? e === "brush" ? "none" : "crosshair" : "default",
979
- ...Ot
1178
+ pointerEvents: nt ? "auto" : "none",
1179
+ cursor: nt ? e === "brush" ? "none" : "crosshair" : "default",
1180
+ ...zt
980
1181
  }),
981
- [Q, e, Ot]
982
- ), gt = B(() => {
983
- const l = K.current;
984
- if (!l) return;
985
- const f = l.getBoundingClientRect(), w = Math.max(1, window.devicePixelRatio || 1), y = Math.max(1, Math.round(f.width * w)), R = Math.max(1, Math.round(f.height * w));
986
- (l.width !== y || l.height !== R) && (l.width = y, l.height = R);
1182
+ [nt, e, zt]
1183
+ ), K = B(() => {
1184
+ const u = Z.current;
1185
+ if (!u) return;
1186
+ const f = u.getBoundingClientRect(), p = Math.max(1, window.devicePixelRatio || 1), y = Math.max(1, Math.round(f.width * p)), R = Math.max(1, Math.round(f.height * p));
1187
+ (u.width !== y || u.height !== R) && (u.width = y, u.height = R);
987
1188
  }, []), N = B(
988
- (l) => {
1189
+ (u) => {
989
1190
  const f = a.current;
990
- if (!f || l.length === 0) return [];
991
- const w = new Array(l.length);
992
- for (let y = 0; y < l.length; y += 1) {
993
- const R = te(f.worldToScreen(l[y][0], l[y][1]));
1191
+ if (!f || u.length === 0) return [];
1192
+ const p = new Array(u.length);
1193
+ for (let y = 0; y < u.length; y += 1) {
1194
+ const R = ee(f.worldToScreen(u[y][0], u[y][1]));
994
1195
  if (!R) return [];
995
- w[y] = R;
1196
+ p[y] = R;
996
1197
  }
997
- return w;
1198
+ return p;
998
1199
  },
999
1200
  [a]
1000
- ), G = B(
1001
- (l, f) => {
1201
+ ), it = B(
1202
+ (u, f) => {
1002
1203
  if (!Number.isFinite(f) || f <= 0) return 0;
1003
- const w = a.current;
1004
- if (!w) return 0;
1005
- const y = te(w.worldToScreen(l[0], l[1])), R = te(w.worldToScreen(l[0] + f, l[1]));
1204
+ const p = a.current;
1205
+ if (!p) return 0;
1206
+ const y = ee(p.worldToScreen(u[0], u[1])), R = ee(p.worldToScreen(u[0] + f, u[1]));
1006
1207
  return !y || !R ? 0 : Math.hypot(R[0] - y[0], R[1] - y[1]);
1007
1208
  },
1008
1209
  [a]
1009
- ), ut = B(
1010
- (l) => {
1011
- if (!Number.isFinite(l) || l <= 0) return 0;
1012
- const f = typeof r == "number" && Number.isFinite(r) && r > 0 ? r : 1, w = typeof i == "number" && Number.isFinite(i) ? i : 0, y = a.current?.getViewState?.().zoom, R = typeof y == "number" && Number.isFinite(y) && y > 0 ? y : 1, v = w + Math.log2(R), Y = Math.max(1e-9, zn(f, w, v));
1013
- return l / Y / R;
1210
+ ), at = B(
1211
+ (u) => {
1212
+ if (!Number.isFinite(u) || u <= 0) return 0;
1213
+ const f = typeof r == "number" && Number.isFinite(r) && r > 0 ? r : 1, p = typeof i == "number" && Number.isFinite(i) ? i : 0, y = a.current?.getViewState?.().zoom, R = typeof y == "number" && Number.isFinite(y) && y > 0 ? y : 1, U = p + Math.log2(R), Y = Math.max(1e-9, $n(f, p, U));
1214
+ return u / Y / R;
1014
1215
  },
1015
1216
  [r, i, a]
1016
- ), nt = B(
1017
- (l, f) => {
1217
+ ), ut = B(
1218
+ (u, f) => {
1018
1219
  if (!f) return [];
1019
- let w = 0;
1020
- if (l === "stamp-rectangle-4096px") {
1021
- const v = yt.rectanglePixelSize * 0.5;
1022
- return xn(f, v).map((V) => Fe(V, t, n));
1220
+ let p = 0;
1221
+ if (u === "stamp-rectangle-4096px") {
1222
+ const U = st.rectanglePixelSize * 0.5;
1223
+ return Cn(f, U).map(($) => ke($, t, n));
1023
1224
  }
1024
- if (l === "stamp-rectangle" || l === "stamp-rectangle-2mm2" ? w = l === "stamp-rectangle-2mm2" ? Dn : yt.rectangleAreaMm2 : (l === "stamp-circle" || l === "stamp-circle-2mm2" || l === "stamp-circle-hpf-0.2mm2") && (w = l === "stamp-circle-hpf-0.2mm2" ? Xr : l === "stamp-circle-2mm2" ? Nn : yt.circleAreaMm2), !Number.isFinite(w) || w <= 0) return [];
1025
- const y = oi(w);
1225
+ if (u === "stamp-rectangle" || u === "stamp-rectangle-2mm2" ? p = u === "stamp-rectangle-2mm2" ? Kn : st.rectangleAreaMm2 : (u === "stamp-circle" || u === "stamp-circle-2mm2" || u === "stamp-circle-hpf-0.2mm2") && (p = u === "stamp-circle-hpf-0.2mm2" ? ri : u === "stamp-circle-2mm2" ? Jn : st.circleAreaMm2), !Number.isFinite(p) || p <= 0) return [];
1226
+ const y = vi(p);
1026
1227
  let R = [];
1027
- if (l === "stamp-rectangle" || l === "stamp-rectangle-2mm2") {
1028
- const v = ut(Math.sqrt(y) * 0.5);
1029
- R = xn(f, v);
1030
- } else if (l === "stamp-circle" || l === "stamp-circle-2mm2" || l === "stamp-circle-hpf-0.2mm2") {
1031
- const v = ut(Math.sqrt(y / Math.PI));
1032
- R = si(f, v);
1228
+ if (u === "stamp-rectangle" || u === "stamp-rectangle-2mm2") {
1229
+ const U = at(Math.sqrt(y) * 0.5);
1230
+ R = Cn(f, U);
1231
+ } else if (u === "stamp-circle" || u === "stamp-circle-2mm2" || u === "stamp-circle-hpf-0.2mm2") {
1232
+ const U = at(Math.sqrt(y / Math.PI));
1233
+ R = Ci(f, U);
1033
1234
  }
1034
- return R.length ? R.map((v) => Fe(v, t, n)) : [];
1235
+ return R.length ? R.map((U) => ke(U, t, n)) : [];
1035
1236
  },
1036
- [ut, t, n, yt]
1037
- ), rt = B(() => {
1038
- const l = dt.current;
1039
- return we(e) ? nt(e, l.stampCenter) : e === "brush" ? [] : l.isDrawing ? e === "freehand" ? l.points : e === "rectangle" ? Sn(l.start, l.current) : e === "circular" ? Tn(l.start, l.current) : [] : [];
1040
- }, [e, nt]), q = B(
1041
- (l) => {
1042
- const f = dt.current;
1237
+ [at, t, n, st]
1238
+ ), J = B(() => {
1239
+ const u = pt.current;
1240
+ return Se(e) ? ut(e, u.stampCenter) : e === "brush" ? [] : u.isDrawing ? e === "freehand" ? u.points : e === "rectangle" ? In(u.start, u.current) : e === "circular" ? _n(u.start, u.current) : [] : [];
1241
+ }, [e, ut]), Ct = B(
1242
+ (u) => {
1243
+ const f = pt.current;
1043
1244
  if (!f.isDrawing || f.points.length === 0) return;
1044
- const w = N(f.points);
1045
- if (w.length === 0) return;
1046
- const y = f.points[f.points.length - 1] ?? f.points[0], R = G(y, U.radius);
1245
+ const p = N(f.points);
1246
+ if (p.length === 0) return;
1247
+ const y = f.points[f.points.length - 1] ?? f.points[0], R = it(y, O.radius);
1047
1248
  if (!(!Number.isFinite(R) || R <= 0)) {
1048
- if (l.save(), l.globalAlpha = U.fillOpacity, l.fillStyle = U.fillColor, l.strokeStyle = U.fillColor, l.lineCap = "round", l.lineJoin = "round", l.lineWidth = R * 2, w.length === 1)
1049
- l.beginPath(), l.arc(w[0][0], w[0][1], R, 0, Math.PI * 2), l.fill();
1249
+ if (u.save(), u.globalAlpha = O.fillOpacity, u.fillStyle = O.fillColor, u.strokeStyle = O.fillColor, u.lineCap = "round", u.lineJoin = "round", u.lineWidth = R * 2, p.length === 1)
1250
+ u.beginPath(), u.arc(p[0][0], p[0][1], R, 0, Math.PI * 2), u.fill();
1050
1251
  else {
1051
- l.beginPath(), l.moveTo(w[0][0], w[0][1]);
1052
- for (let v = 1; v < w.length; v += 1)
1053
- l.lineTo(w[v][0], w[v][1]);
1054
- l.stroke();
1252
+ u.beginPath(), u.moveTo(p[0][0], p[0][1]);
1253
+ for (let U = 1; U < p.length; U += 1)
1254
+ u.lineTo(p[U][0], p[U][1]);
1255
+ u.stroke();
1055
1256
  }
1056
- l.restore();
1257
+ u.restore();
1057
1258
  }
1058
1259
  },
1059
- [N, G, U]
1060
- ), It = B(
1061
- (l) => {
1062
- const f = dt.current, w = f.cursor;
1063
- if (!w) return;
1064
- const y = te(a.current?.worldToScreen(w[0], w[1]) ?? []);
1260
+ [N, it, O]
1261
+ ), Pt = B(
1262
+ (u) => {
1263
+ const f = pt.current, p = f.cursor;
1264
+ if (!p) return;
1265
+ const y = ee(a.current?.worldToScreen(p[0], p[1]) ?? []);
1065
1266
  if (!y) return;
1066
- const R = G(w, U.radius);
1067
- !Number.isFinite(R) || R <= 0 || (l.save(), l.beginPath(), l.arc(y[0], y[1], R, 0, Math.PI * 2), l.strokeStyle = f.isDrawing ? U.cursorActiveColor : U.cursorColor, l.lineWidth = U.cursorLineWidth, l.setLineDash(U.cursorLineDash), l.stroke(), l.setLineDash(Pe), l.restore());
1267
+ const R = it(p, O.radius);
1268
+ !Number.isFinite(R) || R <= 0 || (u.save(), u.beginPath(), u.arc(y[0], y[1], R, 0, Math.PI * 2), u.strokeStyle = f.isDrawing ? O.cursorActiveColor : O.cursorColor, u.lineWidth = O.cursorLineWidth, u.setLineDash(O.cursorLineDash), u.stroke(), u.setLineDash(Ce), u.restore());
1068
1269
  },
1069
- [a, G, U]
1070
- ), _t = B(() => {
1071
- gt();
1072
- const l = K.current;
1073
- if (!l) return;
1074
- const f = l.getContext("2d");
1270
+ [a, it, O]
1271
+ ), It = B(() => {
1272
+ K();
1273
+ const u = Z.current;
1274
+ if (!u) return;
1275
+ const f = u.getContext("2d");
1075
1276
  if (!f) return;
1076
- const w = Math.max(1, window.devicePixelRatio || 1), y = l.width / w, R = l.height / w;
1077
- if (f.setTransform(1, 0, 0, 1, 0, 0), f.clearRect(0, 0, l.width, l.height), f.setTransform(w, 0, 0, w, 0, 0), M.length > 0)
1078
- for (let v = 0; v < M.length; v += 1) {
1079
- const Y = M[v], V = Y?.coordinates;
1080
- if (!V || V.length < 3) continue;
1081
- const W = Rt(V), lt = N(W);
1082
- if (lt.length >= 4) {
1083
- const Pt = Y.id ?? v, $t = Pn(at, Pt) ? "active" : Pn(ft, Pt) ? "hover" : "default";
1084
- let xt = $t === "active" ? Z : $t === "hover" ? L : A;
1085
- if (D) {
1086
- const H = D({
1087
- region: Y,
1088
- regionId: Pt,
1089
- regionIndex: v,
1090
- state: $t
1091
- });
1092
- xt = oe(xt, H || void 0);
1277
+ const p = Math.max(1, window.devicePixelRatio || 1), y = u.width / p, R = u.height / p;
1278
+ if (f.setTransform(1, 0, 0, 1, 0, 0), f.clearRect(0, 0, u.width, u.height), f.setTransform(p, 0, 0, p, 0, 0), C.length > 0)
1279
+ for (const U of C) {
1280
+ const { region: Y, polygons: $, regionIndex: V, regionKey: ft } = U, kt = Fn(wt, ft) ? "active" : Fn(dt, ft) ? "hover" : "default";
1281
+ let Xt = kt === "active" ? rt : kt === "hover" ? ot : z;
1282
+ if (F) {
1283
+ const tt = F({
1284
+ region: Y,
1285
+ regionId: ft,
1286
+ regionIndex: V,
1287
+ state: kt
1288
+ });
1289
+ Xt = ae(Xt, tt || void 0);
1290
+ }
1291
+ for (const tt of $) {
1292
+ const ct = N(tt.outer);
1293
+ ct.length >= 4 && Gt(f, ct, Xt, !0, !1);
1294
+ for (const yt of tt.holes) {
1295
+ const bt = N(yt);
1296
+ bt.length >= 4 && Gt(f, bt, Xt, !0, !1);
1093
1297
  }
1094
- Qt(f, lt, xt, !0, !1);
1095
1298
  }
1096
1299
  }
1097
- if (I.length > 0)
1098
- for (let v = 0; v < I.length; v += 1) {
1099
- const V = I[v]?.coordinates;
1100
- if (!V || V.length < 3) continue;
1101
- const W = Rt(V), lt = N(W);
1102
- lt.length < 4 || Qt(f, lt, et, !0, !1);
1103
- }
1104
- if (Array.isArray(J) && J.length > 0) {
1105
- const v = !!globalThis.__OPEN_PLANT_DEBUG_OVERLAY__, Y = N(
1106
- Rt([
1300
+ if (W.length > 0)
1301
+ for (const U of W)
1302
+ for (const Y of U.polygons) {
1303
+ const $ = N(Y.outer);
1304
+ $.length >= 4 && Gt(f, $, St, !0, !1);
1305
+ for (const V of Y.holes) {
1306
+ const ft = N(V);
1307
+ ft.length >= 4 && Gt(f, ft, St, !0, !1);
1308
+ }
1309
+ }
1310
+ if (Array.isArray(H) && H.length > 0) {
1311
+ const U = !!globalThis.__OPEN_PLANT_DEBUG_OVERLAY__, Y = N(
1312
+ Ht([
1107
1313
  [0, 0],
1108
1314
  [t, 0],
1109
1315
  [t, n],
1110
1316
  [0, n]
1111
1317
  ])
1112
1318
  );
1113
- for (let V = 0; V < J.length; V += 1) {
1114
- const W = J[V];
1115
- if (!W?.coordinates?.length || W.visible === !1) continue;
1116
- const lt = W.closed ?? ai(W.coordinates), Pt = Rn(W.coordinates, lt);
1117
- if (W.invertedFill?.fillColor) {
1118
- const xt = [], H = Rn(W.coordinates, !0);
1119
- for (const St of H) {
1120
- const Tt = N(St);
1121
- Tt.length >= 4 && xt.push(Tt);
1319
+ for (let $ = 0; $ < H.length; $ += 1) {
1320
+ const V = H[$];
1321
+ if (!V?.coordinates?.length || V.visible === !1) continue;
1322
+ const ft = V.closed ?? Ii(V.coordinates), kt = Ln(V.coordinates, ft);
1323
+ if (V.invertedFill?.fillColor) {
1324
+ const tt = [], ct = Ln(V.coordinates, !0);
1325
+ for (const yt of ct) {
1326
+ const bt = N(yt);
1327
+ bt.length >= 4 && tt.push(bt);
1122
1328
  }
1123
- if (v) {
1124
- const St = String(W.id ?? V), Tt = `${Y.length}|${H.length}|${xt.length}|${W.invertedFill.fillColor}`;
1125
- zt.current.get(St) !== Tt && (zt.current.set(St, Tt), console.debug("[open-plant] invertedFill", {
1126
- id: W.id ?? V,
1329
+ if (U) {
1330
+ const yt = String(V.id ?? $), bt = `${Y.length}|${ct.length}|${tt.length}|${V.invertedFill.fillColor}`;
1331
+ Lt.current.get(yt) !== bt && (Lt.current.set(yt, bt), console.debug("[open-plant] invertedFill", {
1332
+ id: V.id ?? $,
1127
1333
  outerRingPoints: Y.length,
1128
- sourceRingCount: H.length,
1129
- holeRingCount: xt.length,
1130
- fillColor: W.invertedFill.fillColor
1334
+ sourceRingCount: ct.length,
1335
+ holeRingCount: tt.length,
1336
+ fillColor: V.invertedFill.fillColor
1131
1337
  }));
1132
1338
  }
1133
- li(f, Y, xt, W.invertedFill.fillColor);
1339
+ Ui(f, Y, tt, V.invertedFill.fillColor);
1134
1340
  }
1135
- if (Pt.length === 0) continue;
1136
- const $t = oe(A, W.stroke ?? W.strokeStyle);
1137
- for (const xt of Pt) {
1138
- const H = N(xt);
1139
- H.length < 2 || Qt(f, H, $t, lt, W.fill ?? !1);
1341
+ if (kt.length === 0) continue;
1342
+ const Xt = ae(z, V.stroke ?? V.strokeStyle);
1343
+ for (const tt of kt) {
1344
+ const ct = N(tt);
1345
+ ct.length < 2 || Gt(f, ct, Xt, ft, V.fill ?? !1);
1140
1346
  }
1141
1347
  }
1142
1348
  }
1143
- if (Q)
1349
+ if (nt)
1144
1350
  if (e === "brush")
1145
- q(f), It(f);
1351
+ Ct(f), Pt(f);
1146
1352
  else {
1147
- const v = rt();
1148
- if (v.length > 0)
1353
+ const U = J();
1354
+ if (U.length > 0)
1149
1355
  if (e === "freehand") {
1150
- const Y = N(v);
1151
- Y.length >= 2 && Qt(f, Y, A, !1, !1), Y.length >= 3 && Qt(f, N(Rt(v)), A, !0, !0);
1356
+ const Y = N(U);
1357
+ Y.length >= 2 && Gt(f, Y, z, !1, !1), Y.length >= 3 && Gt(f, N(Ht(U)), z, !0, !0);
1152
1358
  } else {
1153
- const Y = N(v);
1154
- Y.length >= 4 && Qt(f, Y, A, !0, !0);
1359
+ const Y = N(U);
1360
+ Y.length >= 4 && Gt(f, Y, z, !0, !0);
1155
1361
  }
1156
1362
  }
1157
- if (M.length > 0)
1158
- for (const v of M) {
1159
- if (!v.label) continue;
1160
- const Y = v?.coordinates;
1161
- if (!Y || Y.length < 3) continue;
1162
- const V = Rt(Y), W = di(V);
1163
- if (!W) continue;
1164
- const lt = te(a.current?.worldToScreen(W[0], W[1]) ?? []);
1165
- lt && mi(f, v.label, lt, y, R, mt);
1363
+ if (C.length > 0)
1364
+ for (const U of C) {
1365
+ if (!U.region.label) continue;
1366
+ const Y = Di(U.polygons);
1367
+ if (!Y) continue;
1368
+ const $ = ee(a.current?.worldToScreen(Y[0], Y[1]) ?? []);
1369
+ $ && Ni(f, U.region.label, $, y, R, ht);
1166
1370
  }
1167
1371
  }, [
1168
- Q,
1372
+ nt,
1169
1373
  e,
1170
- rt,
1171
- q,
1172
- It,
1173
- gt,
1374
+ J,
1375
+ Ct,
1376
+ Pt,
1377
+ K,
1174
1378
  N,
1175
1379
  t,
1176
1380
  n,
1177
1381
  a,
1178
- M,
1179
- J,
1180
- ft,
1181
- at,
1182
- A,
1183
- L,
1184
- Z,
1185
- I,
1186
- et,
1187
- D,
1188
- mt
1189
- ]), F = B(() => {
1190
- Ct.current || (Ct.current = !0, requestAnimationFrame(() => {
1191
- Ct.current = !1, _t();
1382
+ C,
1383
+ H,
1384
+ dt,
1385
+ wt,
1386
+ z,
1387
+ ot,
1388
+ rt,
1389
+ W,
1390
+ St,
1391
+ F,
1392
+ ht
1393
+ ]), _ = B(() => {
1394
+ vt.current || (vt.current = !0, requestAnimationFrame(() => {
1395
+ vt.current = !1, It();
1192
1396
  }));
1193
- }, [_t]), ct = B((l = !1) => {
1194
- const f = dt.current, w = K.current;
1195
- if (w && f.pointerId !== null && w.hasPointerCapture(f.pointerId))
1397
+ }, [It]), gt = B((u = !1) => {
1398
+ const f = pt.current, p = Z.current;
1399
+ if (p && f.pointerId !== null && p.hasPointerCapture(f.pointerId))
1196
1400
  try {
1197
- w.releasePointerCapture(f.pointerId);
1401
+ p.releasePointerCapture(f.pointerId);
1198
1402
  } catch {
1199
1403
  }
1200
- f.isDrawing = !1, f.pointerId = null, f.start = null, f.current = null, f.points = [], f.stampCenter = null, l || (f.cursor = null);
1201
- }, []), ot = B(
1202
- (l) => {
1404
+ f.isDrawing = !1, f.pointerId = null, f.start = null, f.current = null, f.points = [], f.stampCenter = null, u || (f.cursor = null);
1405
+ }, []), Rt = B(
1406
+ (u) => {
1203
1407
  const f = a.current;
1204
1408
  if (!f || t <= 0 || n <= 0) return null;
1205
- const w = te(f.screenToWorld(l.clientX, l.clientY));
1206
- return w ? Fe(w, t, n) : null;
1409
+ const p = ee(f.screenToWorld(u.clientX, u.clientY));
1410
+ return p ? ke(p, t, n) : null;
1207
1411
  },
1208
1412
  [a, t, n]
1209
- ), Gt = B(() => {
1210
- const l = dt.current;
1211
- if (!l.isDrawing) {
1212
- ct(!0), F();
1413
+ ), _t = B(() => {
1414
+ const u = pt.current;
1415
+ if (!u.isDrawing) {
1416
+ gt(!0), _();
1213
1417
  return;
1214
1418
  }
1215
1419
  let f = [];
1216
1420
  if (e === "freehand")
1217
- l.points.length >= Lr && (f = Rt(l.points));
1421
+ u.points.length >= Qr && (f = Ht(u.points));
1218
1422
  else if (e === "rectangle")
1219
- f = Sn(l.start, l.current);
1423
+ f = In(u.start, u.current);
1220
1424
  else if (e === "circular")
1221
- f = Tn(l.start, l.current);
1425
+ f = _n(u.start, u.current);
1222
1426
  else if (e === "brush") {
1223
- const w = l.points[l.points.length - 1] ?? l.current ?? l.start;
1224
- if (U.clickSelectRoi && w && l.points.length <= 1 && u?.(w)) {
1225
- ct(!0), F();
1427
+ const p = u.points[u.points.length - 1] ?? u.current ?? u.start;
1428
+ if (O.clickSelectRoi && p && u.points.length <= 1 && c?.(p)) {
1429
+ gt(!0), _();
1226
1430
  return;
1227
1431
  }
1228
- const y = Math.max(1e-6, a.current?.getViewState?.().zoom ?? 1), R = U.edgeDetail, v = 0.75 / (y * R);
1229
- f = Fr(l.points, {
1230
- radius: U.radius,
1432
+ const y = O.edgeDetail, R = Math.max(
1433
+ wi,
1434
+ O.radius * 2 / (yi * y)
1435
+ );
1436
+ f = Hr(u.points, {
1437
+ radius: O.radius,
1231
1438
  clipBounds: [0, 0, t, n],
1232
- minRasterStep: v,
1233
- circleSides: Math.max(24, Math.round(64 * R)),
1234
- simplifyTolerance: v * 0.4
1439
+ minRasterStep: R,
1440
+ circleSides: Math.max(24, Math.round(64 * y)),
1441
+ simplifyTolerance: R * 0.25,
1442
+ smoothingPasses: O.edgeSmoothing
1235
1443
  });
1236
1444
  }
1237
- (e === "freehand" || e === "rectangle" || e === "circular" || e === "brush") && An(f) && c && c({
1445
+ (e === "freehand" || e === "rectangle" || e === "circular" || e === "brush") && Un(f) && h && h({
1238
1446
  tool: e,
1239
1447
  intent: e === "brush" ? "brush" : "roi",
1240
1448
  coordinates: f,
1241
- bbox: Mn(f),
1242
- areaPx: ke(f)
1243
- }), ct(!0), F();
1244
- }, [e, c, ct, F, U.radius, U.edgeDetail, U.clickSelectRoi, t, n, a, u]), Bt = B(
1245
- (l, f) => {
1246
- const w = nt(l, f);
1247
- if (!An(w)) return;
1248
- const y = l === "stamp-rectangle-4096px" ? "patch" : "roi", R = {
1249
- tool: l,
1449
+ bbox: Bn(f),
1450
+ areaPx: Ge(f)
1451
+ }), gt(!0), _();
1452
+ }, [e, h, gt, _, O.radius, O.edgeDetail, O.edgeSmoothing, O.clickSelectRoi, t, n, c]), re = B(
1453
+ (u, f) => {
1454
+ const p = ut(u, f);
1455
+ if (!Un(p)) return;
1456
+ const y = u === "stamp-rectangle-4096px" ? "patch" : "roi", R = {
1457
+ tool: u,
1250
1458
  intent: y,
1251
- coordinates: w,
1252
- bbox: Mn(w),
1253
- areaPx: ke(w)
1459
+ coordinates: p,
1460
+ bbox: Bn(p),
1461
+ areaPx: Ge(p)
1254
1462
  };
1255
- c?.(R), y === "patch" && h && h(R);
1463
+ h?.(R), y === "patch" && l && l(R);
1256
1464
  },
1257
- [nt, c, h]
1258
- ), Ft = B(
1259
- (l, f) => {
1260
- const w = a.current, y = Math.max(1e-6, w?.getViewState?.().zoom ?? 1), R = Jr / y, v = R * R, Y = l.points[l.points.length - 1];
1465
+ [ut, h, l]
1466
+ ), Bt = B(
1467
+ (u, f) => {
1468
+ const p = a.current, y = Math.max(1e-6, p?.getViewState?.().zoom ?? 1), R = Si / y, U = R * R, Y = u.points[u.points.length - 1];
1261
1469
  if (!Y) {
1262
- l.points.push(f), l.current = f;
1470
+ u.points.push(f), u.current = f;
1263
1471
  return;
1264
1472
  }
1265
- const V = f[0] - Y[0], W = f[1] - Y[1];
1266
- V * V + W * W >= v ? l.points.push(f) : l.points[l.points.length - 1] = f, l.current = f;
1473
+ const $ = f[0] - Y[0], V = f[1] - Y[1];
1474
+ $ * $ + V * V >= U ? u.points.push(f) : u.points[u.points.length - 1] = f, u.current = f;
1267
1475
  },
1268
1476
  [a]
1269
- ), qt = B(
1270
- (l) => {
1271
- if (!Q || e === "cursor" || l.button !== 0) return;
1272
- const f = ot(l);
1477
+ ), xt = B(
1478
+ (u) => {
1479
+ if (!nt || e === "cursor" || u.button !== 0) return;
1480
+ const f = Rt(u);
1273
1481
  if (!f) return;
1274
- if (l.preventDefault(), l.stopPropagation(), we(e)) {
1275
- const R = dt.current;
1276
- R.stampCenter = f, Bt(e, f), F();
1482
+ if (u.preventDefault(), u.stopPropagation(), Se(e)) {
1483
+ const R = pt.current;
1484
+ R.stampCenter = f, re(e, f), _();
1277
1485
  return;
1278
1486
  }
1279
- const w = K.current;
1280
- w && w.setPointerCapture(l.pointerId);
1281
- const y = dt.current;
1282
- y.isDrawing = !0, y.pointerId = l.pointerId, y.start = f, y.current = f, y.cursor = f, y.points = e === "freehand" || e === "brush" ? [f] : [], F();
1487
+ const p = Z.current;
1488
+ p && p.setPointerCapture(u.pointerId);
1489
+ const y = pt.current;
1490
+ y.isDrawing = !0, y.pointerId = u.pointerId, y.start = f, y.current = f, y.cursor = f, y.points = e === "freehand" || e === "brush" ? [f] : [], _();
1283
1491
  },
1284
- [Q, e, ot, Bt, F]
1285
- ), pt = B(
1286
- (l) => {
1287
- if (!Q || e === "cursor") return;
1288
- const f = ot(l);
1492
+ [nt, e, Rt, re, _]
1493
+ ), _e = B(
1494
+ (u) => {
1495
+ if (!nt || e === "cursor") return;
1496
+ const f = Rt(u);
1289
1497
  if (!f) return;
1290
- if (we(e)) {
1291
- const y = dt.current;
1292
- y.stampCenter = f, l.preventDefault(), l.stopPropagation(), F();
1498
+ if (Se(e)) {
1499
+ const y = pt.current;
1500
+ y.stampCenter = f, u.preventDefault(), u.stopPropagation(), _();
1293
1501
  return;
1294
1502
  }
1295
- const w = dt.current;
1503
+ const p = pt.current;
1296
1504
  if (e === "brush") {
1297
- if (w.cursor = f, !w.isDrawing || w.pointerId !== l.pointerId) {
1298
- F();
1505
+ if (p.cursor = f, !p.isDrawing || p.pointerId !== u.pointerId) {
1506
+ _();
1299
1507
  return;
1300
1508
  }
1301
- l.preventDefault(), l.stopPropagation(), Ft(w, f), F();
1509
+ u.preventDefault(), u.stopPropagation(), Bt(p, f), _();
1302
1510
  return;
1303
1511
  }
1304
- if (!(!w.isDrawing || w.pointerId !== l.pointerId)) {
1305
- if (l.preventDefault(), l.stopPropagation(), e === "freehand") {
1306
- const y = a.current, R = Math.max(1e-6, y?.getViewState?.().zoom ?? 1), v = Dr / R, Y = v * v, V = w.points[w.points.length - 1];
1307
- if (!V)
1308
- w.points.push(f);
1512
+ if (!(!p.isDrawing || p.pointerId !== u.pointerId)) {
1513
+ if (u.preventDefault(), u.stopPropagation(), e === "freehand") {
1514
+ const y = a.current, R = Math.max(1e-6, y?.getViewState?.().zoom ?? 1), U = ti / R, Y = U * U, $ = p.points[p.points.length - 1];
1515
+ if (!$)
1516
+ p.points.push(f);
1309
1517
  else {
1310
- const W = f[0] - V[0], lt = f[1] - V[1];
1311
- W * W + lt * lt >= Y && w.points.push(f);
1518
+ const V = f[0] - $[0], ft = f[1] - $[1];
1519
+ V * V + ft * ft >= Y && p.points.push(f);
1312
1520
  }
1313
1521
  } else
1314
- w.current = f;
1315
- F();
1522
+ p.current = f;
1523
+ _();
1316
1524
  }
1317
1525
  },
1318
- [Q, e, ot, F, a, Ft]
1319
- ), ue = B(
1320
- (l) => {
1321
- const f = dt.current;
1322
- if (!f.isDrawing || f.pointerId !== l.pointerId) return;
1323
- l.preventDefault(), l.stopPropagation();
1324
- const w = ot(l);
1325
- w && (f.cursor = w, e === "brush" ? Ft(f, w) : f.current = w);
1326
- const y = K.current;
1327
- if (y && y.hasPointerCapture(l.pointerId))
1526
+ [nt, e, Rt, _, a, Bt]
1527
+ ), ie = B(
1528
+ (u) => {
1529
+ const f = pt.current;
1530
+ if (!f.isDrawing || f.pointerId !== u.pointerId) return;
1531
+ u.preventDefault(), u.stopPropagation();
1532
+ const p = Rt(u);
1533
+ p && (f.cursor = p, e === "brush" ? Bt(f, p) : f.current = p);
1534
+ const y = Z.current;
1535
+ if (y && y.hasPointerCapture(u.pointerId))
1328
1536
  try {
1329
- y.releasePointerCapture(l.pointerId);
1537
+ y.releasePointerCapture(u.pointerId);
1330
1538
  } catch {
1331
1539
  }
1332
- Gt();
1540
+ _t();
1333
1541
  },
1334
- [Gt, ot, e, Ft]
1335
- ), ce = B(() => {
1336
- const l = dt.current;
1542
+ [_t, Rt, e, Bt]
1543
+ ), he = B(() => {
1544
+ const u = pt.current;
1337
1545
  let f = !1;
1338
- e === "brush" && !l.isDrawing && l.cursor && (l.cursor = null, f = !0), we(e) && l.stampCenter && (l.stampCenter = null, f = !0), f && F();
1339
- }, [e, F]);
1340
- return X(() => {
1341
- gt(), F();
1342
- const l = K.current;
1343
- if (!l) return;
1546
+ e === "brush" && !u.isDrawing && u.cursor && (u.cursor = null, f = !0), Se(e) && u.stampCenter && (u.stampCenter = null, f = !0), f && _();
1547
+ }, [e, _]);
1548
+ return k(() => {
1549
+ K(), _();
1550
+ const u = Z.current;
1551
+ if (!u) return;
1344
1552
  const f = new ResizeObserver(() => {
1345
- gt(), F();
1553
+ K(), _();
1346
1554
  });
1347
- return f.observe(l), () => {
1555
+ return f.observe(u), () => {
1348
1556
  f.disconnect();
1349
1557
  };
1350
- }, [gt, F]), X(() => {
1351
- Q || ct(), F();
1352
- }, [Q, F, ct]), X(() => {
1353
- Kt.current !== e && (Kt.current = e, ct(), F());
1354
- }, [e, ct, F]), X(() => {
1355
- F();
1356
- }, [d, M, J, F]), X(() => {
1357
- if (ht)
1358
- return ht.current = F, () => {
1359
- ht.current === F && (ht.current = null);
1558
+ }, [K, _]), k(() => {
1559
+ nt || gt(), _();
1560
+ }, [nt, _, gt]), k(() => {
1561
+ jt.current !== e && (jt.current = e, gt(), _());
1562
+ }, [e, gt, _]), k(() => {
1563
+ _();
1564
+ }, [d, A, H, _]), k(() => {
1565
+ if (X)
1566
+ return X.current = _, () => {
1567
+ X.current === _ && (X.current = null);
1360
1568
  };
1361
- }, [ht, F]), X(() => {
1362
- if (!Q) return;
1363
- const l = (f) => {
1364
- f.key === "Escape" && (ct(), F());
1569
+ }, [X, _]), k(() => {
1570
+ if (!nt) return;
1571
+ const u = (f) => {
1572
+ f.key === "Escape" && (gt(), _());
1365
1573
  };
1366
- return window.addEventListener("keydown", l), () => {
1367
- window.removeEventListener("keydown", l);
1574
+ return window.addEventListener("keydown", u), () => {
1575
+ window.removeEventListener("keydown", u);
1368
1576
  };
1369
- }, [Q, ct, F]), /* @__PURE__ */ Ut(
1577
+ }, [nt, gt, _]), /* @__PURE__ */ Ut(
1370
1578
  "canvas",
1371
1579
  {
1372
- ref: K,
1373
- className: vt,
1374
- style: At,
1375
- onPointerDown: qt,
1376
- onPointerMove: pt,
1377
- onPointerUp: ue,
1378
- onPointerCancel: ue,
1379
- onPointerLeave: ce,
1380
- onContextMenu: (l) => {
1381
- Q && l.preventDefault();
1580
+ ref: Z,
1581
+ className: Nt,
1582
+ style: Q,
1583
+ onPointerDown: xt,
1584
+ onPointerMove: _e,
1585
+ onPointerUp: ie,
1586
+ onPointerCancel: ie,
1587
+ onPointerLeave: he,
1588
+ onContextMenu: (u) => {
1589
+ nt && u.preventDefault();
1382
1590
  },
1383
- onWheel: (l) => {
1384
- if (!Q) return;
1385
- const f = K.current, w = a.current;
1386
- if (!f || typeof w?.zoomBy != "function") return;
1387
- l.preventDefault(), l.stopPropagation();
1388
- const y = f.getBoundingClientRect(), R = l.clientX - y.left, v = l.clientY - y.top;
1389
- w.zoomBy(l.deltaY < 0 ? Yr : Wr, R, v), F();
1591
+ onWheel: (u) => {
1592
+ if (!nt) return;
1593
+ const f = Z.current, p = a.current;
1594
+ if (!f || typeof p?.zoomBy != "function") return;
1595
+ u.preventDefault(), u.stopPropagation();
1596
+ const y = f.getBoundingClientRect(), R = u.clientX - y.left, U = u.clientY - y.top;
1597
+ p.zoomBy(u.deltaY < 0 ? ii : oi, R, U), _();
1390
1598
  }
1391
1599
  }
1392
1600
  );
1393
1601
  }
1394
- function vn(e) {
1602
+ function Nn(e) {
1395
1603
  return String(e ?? "").replace(/\/+$/, "");
1396
1604
  }
1397
- function Yn(e) {
1605
+ function tr(e) {
1398
1606
  const t = String(e ?? "");
1399
1607
  return t.startsWith("/") ? t : `/${t}`;
1400
1608
  }
1401
- function pi(e) {
1402
- const t = vn(e);
1609
+ function Xi(e) {
1610
+ const t = Nn(e);
1403
1611
  if (!t) return "";
1404
1612
  if (/\/TileGroup\d+$/i.test(t)) return t;
1405
1613
  let n = null;
@@ -1409,41 +1617,41 @@ function pi(e) {
1409
1617
  n = null;
1410
1618
  }
1411
1619
  if (n) {
1412
- const r = `${n.protocol}//${n.host}`, i = vn(n.pathname || "");
1620
+ const r = `${n.protocol}//${n.host}`, i = Nn(n.pathname || "");
1413
1621
  return /\/ims$/i.test(i) ? `${r}${i}` : /\/tiles$/i.test(i) ? `${r}${i}` : `${r}${i}/tiles`;
1414
1622
  }
1415
1623
  return /\/ims$/i.test(t) ? "/ims" : /\/tiles$/i.test(t) ? `${t}` : `${t}/tiles`;
1416
1624
  }
1417
- function mo(e, t) {
1418
- const n = e?.imsInfo || {}, r = !!e?.imsInfo, i = Number(n.width ?? e?.width ?? 0), o = Number(n.height ?? e?.height ?? 0), s = Number(n.tileSize ?? e?.tileSize ?? 0), a = Number(n.zoom ?? e?.zoom ?? 0), u = String(n.path ?? e?.path ?? ""), c = Number(n.mpp ?? e?.mpp ?? 0);
1419
- if (!i || !o || !s || !u)
1625
+ function Bo(e, t) {
1626
+ const n = e?.imsInfo || {}, r = !!e?.imsInfo, i = Number(n.width ?? e?.width ?? 0), o = Number(n.height ?? e?.height ?? 0), s = Number(n.tileSize ?? e?.tileSize ?? 0), a = Number(n.zoom ?? e?.zoom ?? 0), c = String(n.path ?? e?.path ?? ""), h = Number(n.mpp ?? e?.mpp ?? 0);
1627
+ if (!i || !o || !s || !c)
1420
1628
  throw new Error("이미지 메타데이터가 불완전합니다. width/height/tileSize/path 확인 필요");
1421
- const h = Array.isArray(e?.terms) ? e.terms.map((x) => ({
1422
- termId: String(x?.termId ?? ""),
1423
- termName: String(x?.termName ?? ""),
1424
- termColor: String(x?.termColor ?? "")
1425
- })) : [], g = Yn(u), d = pi(t), p = r ? (x, S, P) => `${d}${g}/${x}/${P}_${S}.webp` : void 0;
1629
+ const l = Array.isArray(e?.terms) ? e.terms.map((S) => ({
1630
+ termId: String(S?.termId ?? ""),
1631
+ termName: String(S?.termName ?? ""),
1632
+ termColor: String(S?.termColor ?? "")
1633
+ })) : [], m = tr(c), d = Xi(t), w = r ? (S, x, T) => `${d}${m}/${S}/${T}_${x}.webp` : void 0;
1426
1634
  return {
1427
1635
  id: e?._id || "unknown",
1428
1636
  name: e?.name || "unknown",
1429
1637
  width: i,
1430
1638
  height: o,
1431
- mpp: Number.isFinite(c) && c > 0 ? c : void 0,
1639
+ mpp: Number.isFinite(h) && h > 0 ? h : void 0,
1432
1640
  tileSize: s,
1433
1641
  maxTierZoom: Number.isFinite(a) ? Math.max(0, Math.floor(a)) : 0,
1434
- tilePath: u,
1642
+ tilePath: c,
1435
1643
  tileBaseUrl: t,
1436
- terms: h,
1437
- tileUrlBuilder: p
1644
+ terms: l,
1645
+ tileUrlBuilder: w
1438
1646
  };
1439
1647
  }
1440
- function Wn(e, t, n, r) {
1648
+ function er(e, t, n, r) {
1441
1649
  if (e.tileUrlBuilder)
1442
1650
  return e.tileUrlBuilder(t, n, r);
1443
- const i = Yn(e.tilePath);
1651
+ const i = tr(e.tilePath);
1444
1652
  return `${e.tileBaseUrl}${i}/${t}/${r}_${n}.webp`;
1445
1653
  }
1446
- const bt = {
1654
+ const Tt = {
1447
1655
  width: 220,
1448
1656
  height: 140,
1449
1657
  margin: 16,
@@ -1458,13 +1666,13 @@ const bt = {
1458
1666
  showThumbnail: !0,
1459
1667
  maxThumbnailTiles: 16
1460
1668
  };
1461
- function ee(e, t, n = 1) {
1669
+ function ne(e, t, n = 1) {
1462
1670
  return typeof e != "number" || !Number.isFinite(e) ? t : Math.max(n, e);
1463
1671
  }
1464
- function ye(e) {
1672
+ function xe(e) {
1465
1673
  return Array.isArray(e) && e.length === 4 && Number.isFinite(e[0]) && Number.isFinite(e[1]) && Number.isFinite(e[2]) && Number.isFinite(e[3]);
1466
1674
  }
1467
- function bi({
1675
+ function Yi({
1468
1676
  source: e,
1469
1677
  projectorRef: t,
1470
1678
  authToken: n = "",
@@ -1473,231 +1681,231 @@ function bi({
1473
1681
  className: o,
1474
1682
  style: s
1475
1683
  }) {
1476
- const a = j(null), u = j(null), c = j(null), h = j({
1684
+ const a = j(null), c = j(null), h = j(null), l = j({
1477
1685
  active: !1,
1478
1686
  pointerId: null
1479
- }), g = j(null), d = j(!1), p = ee(
1687
+ }), m = j(null), d = j(!1), w = ne(
1480
1688
  r?.width,
1481
- bt.width,
1689
+ Tt.width,
1482
1690
  64
1483
- ), x = ee(
1691
+ ), S = ne(
1484
1692
  r?.height,
1485
- bt.height,
1693
+ Tt.height,
1486
1694
  48
1487
- ), S = ee(
1695
+ ), x = ne(
1488
1696
  r?.margin,
1489
- bt.margin,
1697
+ Tt.margin,
1490
1698
  0
1491
- ), P = ee(
1699
+ ), T = ne(
1492
1700
  r?.borderRadius,
1493
- bt.borderRadius,
1701
+ Tt.borderRadius,
1494
1702
  0
1495
- ), k = ee(
1703
+ ), L = ne(
1496
1704
  r?.borderWidth,
1497
- bt.borderWidth,
1705
+ Tt.borderWidth,
1498
1706
  0
1499
- ), C = Math.max(
1707
+ ), v = Math.max(
1500
1708
  1,
1501
1709
  Math.round(
1502
- ee(
1710
+ ne(
1503
1711
  r?.maxThumbnailTiles,
1504
- bt.maxThumbnailTiles,
1712
+ Tt.maxThumbnailTiles,
1505
1713
  1
1506
1714
  )
1507
1715
  )
1508
- ), E = r?.backgroundColor || bt.backgroundColor, D = r?.borderColor || bt.borderColor, J = r?.viewportStrokeColor || bt.viewportStrokeColor, ft = r?.viewportFillColor || bt.viewportFillColor, at = r?.interactive ?? bt.interactive, $ = r?.showThumbnail ?? bt.showThumbnail, ht = r?.position || bt.position, vt = tt(() => {
1509
- const M = {};
1510
- return ht === "top-left" || ht === "bottom-left" ? M.left = S : M.right = S, ht === "top-left" || ht === "top-right" ? M.top = S : M.bottom = S, {
1716
+ ), P = r?.backgroundColor || Tt.backgroundColor, F = r?.borderColor || Tt.borderColor, H = r?.viewportStrokeColor || Tt.viewportStrokeColor, dt = r?.viewportFillColor || Tt.viewportFillColor, wt = r?.interactive ?? Tt.interactive, mt = r?.showThumbnail ?? Tt.showThumbnail, X = r?.position || Tt.position, Nt = q(() => {
1717
+ const A = {};
1718
+ return X === "top-left" || X === "bottom-left" ? A.left = x : A.right = x, X === "top-left" || X === "top-right" ? A.top = x : A.bottom = x, {
1511
1719
  position: "absolute",
1512
- ...M,
1513
- width: p,
1514
- height: x,
1515
- borderRadius: P,
1720
+ ...A,
1721
+ width: w,
1722
+ height: S,
1723
+ borderRadius: T,
1516
1724
  overflow: "hidden",
1517
1725
  zIndex: 4,
1518
- pointerEvents: at ? "auto" : "none",
1726
+ pointerEvents: wt ? "auto" : "none",
1519
1727
  touchAction: "none",
1520
1728
  boxShadow: "0 10px 22px rgba(0, 0, 0, 0.3)",
1521
1729
  ...s
1522
1730
  };
1523
- }, [S, ht, p, x, P, at, s]), Ot = B(() => {
1524
- const M = a.current;
1525
- if (!M) return;
1526
- const I = M.getContext("2d");
1527
- if (!I) return;
1528
- const A = p, L = x, Z = Math.max(1, window.devicePixelRatio || 1), et = Math.max(1, Math.round(A * Z)), mt = Math.max(1, Math.round(L * Z));
1529
- (M.width !== et || M.height !== mt) && (M.width = et, M.height = mt), I.setTransform(1, 0, 0, 1, 0, 0), I.clearRect(0, 0, M.width, M.height), I.setTransform(Z, 0, 0, Z, 0, 0), I.fillStyle = E, I.fillRect(0, 0, A, L);
1530
- const yt = u.current;
1531
- yt && I.drawImage(yt, 0, 0, A, L), I.strokeStyle = D, I.lineWidth = k, I.strokeRect(
1532
- k * 0.5,
1533
- k * 0.5,
1534
- A - k,
1535
- L - k
1731
+ }, [x, X, w, S, T, wt, s]), zt = B(() => {
1732
+ const A = a.current;
1733
+ if (!A) return;
1734
+ const E = A.getContext("2d");
1735
+ if (!E) return;
1736
+ const C = w, W = S, z = Math.max(1, window.devicePixelRatio || 1), ot = Math.max(1, Math.round(C * z)), rt = Math.max(1, Math.round(W * z));
1737
+ (A.width !== ot || A.height !== rt) && (A.width = ot, A.height = rt), E.setTransform(1, 0, 0, 1, 0, 0), E.clearRect(0, 0, A.width, A.height), E.setTransform(z, 0, 0, z, 0, 0), E.fillStyle = P, E.fillRect(0, 0, C, W);
1738
+ const St = c.current;
1739
+ St && E.drawImage(St, 0, 0, C, W), E.strokeStyle = F, E.lineWidth = L, E.strokeRect(
1740
+ L * 0.5,
1741
+ L * 0.5,
1742
+ C - L,
1743
+ W - L
1536
1744
  );
1537
- const U = t.current, At = U?.getViewBounds?.(), gt = U?.getViewCorners?.(), N = ye(At) ? At : ye(c.current) ? c.current : null;
1538
- if (!N) return;
1539
- c.current = N;
1540
- const G = A / Math.max(1, e.width), ut = L / Math.max(1, e.height), nt = Array.isArray(gt) && gt.length >= 4 && gt.every(
1541
- (ot) => Array.isArray(ot) && ot.length >= 2 && Number.isFinite(ot[0]) && Number.isFinite(ot[1])
1542
- ) ? gt : null;
1543
- if (nt) {
1544
- I.beginPath();
1545
- for (let ot = 0; ot < nt.length; ot += 1) {
1546
- const Gt = nt[ot], Bt = it(Gt[0] * G, 0, A), Ft = it(Gt[1] * ut, 0, L);
1547
- ot === 0 ? I.moveTo(Bt, Ft) : I.lineTo(Bt, Ft);
1745
+ const ht = t.current, st = ht?.getViewBounds?.(), O = ht?.getViewCorners?.(), Q = xe(st) ? st : xe(h.current) ? h.current : null;
1746
+ if (!Q) return;
1747
+ h.current = Q;
1748
+ const K = C / Math.max(1, e.width), N = W / Math.max(1, e.height), it = Array.isArray(O) && O.length >= 4 && O.every(
1749
+ (_) => Array.isArray(_) && _.length >= 2 && Number.isFinite(_[0]) && Number.isFinite(_[1])
1750
+ ) ? O : null;
1751
+ if (it) {
1752
+ E.beginPath();
1753
+ for (let _ = 0; _ < it.length; _ += 1) {
1754
+ const gt = it[_], Rt = et(gt[0] * K, 0, C), _t = et(gt[1] * N, 0, W);
1755
+ _ === 0 ? E.moveTo(Rt, _t) : E.lineTo(Rt, _t);
1548
1756
  }
1549
- I.closePath(), I.fillStyle = ft, I.fill(), I.strokeStyle = J, I.lineWidth = 1.5, I.stroke();
1757
+ E.closePath(), E.fillStyle = dt, E.fill(), E.strokeStyle = H, E.lineWidth = 1.5, E.stroke();
1550
1758
  return;
1551
1759
  }
1552
- const rt = it(N[0] * G, 0, A), q = it(N[1] * ut, 0, L), It = it(N[2] * G, 0, A), _t = it(N[3] * ut, 0, L), F = Math.max(1, It - rt), ct = Math.max(1, _t - q);
1553
- I.fillStyle = ft, I.fillRect(rt, q, F, ct), I.strokeStyle = J, I.lineWidth = 1.5, I.strokeRect(
1554
- rt + 0.5,
1555
- q + 0.5,
1556
- Math.max(1, F - 1),
1557
- Math.max(1, ct - 1)
1760
+ const at = et(Q[0] * K, 0, C), ut = et(Q[1] * N, 0, W), J = et(Q[2] * K, 0, C), Ct = et(Q[3] * N, 0, W), Pt = Math.max(1, J - at), It = Math.max(1, Ct - ut);
1761
+ E.fillStyle = dt, E.fillRect(at, ut, Pt, It), E.strokeStyle = H, E.lineWidth = 1.5, E.strokeRect(
1762
+ at + 0.5,
1763
+ ut + 0.5,
1764
+ Math.max(1, Pt - 1),
1765
+ Math.max(1, It - 1)
1558
1766
  );
1559
1767
  }, [
1560
- p,
1561
- x,
1562
- E,
1563
- D,
1564
- k,
1768
+ w,
1769
+ S,
1770
+ P,
1771
+ F,
1772
+ L,
1565
1773
  t,
1566
1774
  e.width,
1567
1775
  e.height,
1568
- ft,
1569
- J
1570
- ]), K = B(() => {
1571
- d.current || (d.current = !0, g.current = requestAnimationFrame(() => {
1572
- d.current = !1, g.current = null, Ot();
1776
+ dt,
1777
+ H
1778
+ ]), Z = B(() => {
1779
+ d.current || (d.current = !0, m.current = requestAnimationFrame(() => {
1780
+ d.current = !1, m.current = null, zt();
1573
1781
  }));
1574
- }, [Ot]), Ct = B(
1575
- (M, I) => {
1576
- const A = a.current;
1577
- if (!A) return null;
1578
- const L = A.getBoundingClientRect();
1579
- if (!L.width || !L.height) return null;
1580
- const Z = it((M - L.left) / L.width, 0, 1), et = it((I - L.top) / L.height, 0, 1);
1581
- return [Z * e.width, et * e.height];
1782
+ }, [zt]), vt = B(
1783
+ (A, E) => {
1784
+ const C = a.current;
1785
+ if (!C) return null;
1786
+ const W = C.getBoundingClientRect();
1787
+ if (!W.width || !W.height) return null;
1788
+ const z = et((A - W.left) / W.width, 0, 1), ot = et((E - W.top) / W.height, 0, 1);
1789
+ return [z * e.width, ot * e.height];
1582
1790
  },
1583
1791
  [e.width, e.height]
1584
- ), zt = B(
1585
- (M, I) => {
1586
- const A = t.current;
1587
- if (!A) return;
1588
- if (A.setViewCenter) {
1589
- A.setViewCenter(M, I), K();
1792
+ ), Lt = B(
1793
+ (A, E) => {
1794
+ const C = t.current;
1795
+ if (!C) return;
1796
+ if (C.setViewCenter) {
1797
+ C.setViewCenter(A, E), Z();
1590
1798
  return;
1591
1799
  }
1592
- const L = A.getViewBounds?.(), Z = ye(L) ? L : ye(c.current) ? c.current : null;
1593
- if (!Z) return;
1594
- const et = Math.max(1e-6, Z[2] - Z[0]), mt = Math.max(1e-6, Z[3] - Z[1]);
1595
- A.setViewState({
1596
- offsetX: M - et * 0.5,
1597
- offsetY: I - mt * 0.5
1598
- }), K();
1800
+ const W = C.getViewBounds?.(), z = xe(W) ? W : xe(h.current) ? h.current : null;
1801
+ if (!z) return;
1802
+ const ot = Math.max(1e-6, z[2] - z[0]), rt = Math.max(1e-6, z[3] - z[1]);
1803
+ C.setViewState({
1804
+ offsetX: A - ot * 0.5,
1805
+ offsetY: E - rt * 0.5
1806
+ }), Z();
1599
1807
  },
1600
- [t, K]
1601
- ), Kt = B(
1602
- (M) => {
1603
- if (!at || M.button !== 0) return;
1604
- const I = a.current;
1605
- if (!I) return;
1606
- const A = Ct(M.clientX, M.clientY);
1607
- A && (M.preventDefault(), M.stopPropagation(), I.setPointerCapture(M.pointerId), h.current = { active: !0, pointerId: M.pointerId }, zt(A[0], A[1]));
1808
+ [t, Z]
1809
+ ), jt = B(
1810
+ (A) => {
1811
+ if (!wt || A.button !== 0) return;
1812
+ const E = a.current;
1813
+ if (!E) return;
1814
+ const C = vt(A.clientX, A.clientY);
1815
+ C && (A.preventDefault(), A.stopPropagation(), E.setPointerCapture(A.pointerId), l.current = { active: !0, pointerId: A.pointerId }, Lt(C[0], C[1]));
1608
1816
  },
1609
- [at, Ct, zt]
1610
- ), dt = B(
1611
- (M) => {
1612
- const I = h.current;
1613
- if (!I.active || I.pointerId !== M.pointerId) return;
1614
- const A = Ct(M.clientX, M.clientY);
1615
- A && (M.preventDefault(), M.stopPropagation(), zt(A[0], A[1]));
1817
+ [wt, vt, Lt]
1818
+ ), pt = B(
1819
+ (A) => {
1820
+ const E = l.current;
1821
+ if (!E.active || E.pointerId !== A.pointerId) return;
1822
+ const C = vt(A.clientX, A.clientY);
1823
+ C && (A.preventDefault(), A.stopPropagation(), Lt(C[0], C[1]));
1616
1824
  },
1617
- [Ct, zt]
1618
- ), Q = B(
1619
- (M) => {
1620
- const I = h.current;
1621
- if (!I.active || I.pointerId !== M.pointerId) return;
1622
- const A = a.current;
1623
- if (A && A.hasPointerCapture(M.pointerId))
1825
+ [vt, Lt]
1826
+ ), nt = B(
1827
+ (A) => {
1828
+ const E = l.current;
1829
+ if (!E.active || E.pointerId !== A.pointerId) return;
1830
+ const C = a.current;
1831
+ if (C && C.hasPointerCapture(A.pointerId))
1624
1832
  try {
1625
- A.releasePointerCapture(M.pointerId);
1833
+ C.releasePointerCapture(A.pointerId);
1626
1834
  } catch {
1627
1835
  }
1628
- h.current = { active: !1, pointerId: null }, K();
1836
+ l.current = { active: !1, pointerId: null }, Z();
1629
1837
  },
1630
- [K]
1838
+ [Z]
1631
1839
  );
1632
- return X(() => {
1633
- let M = !1;
1634
- u.current = null, K();
1635
- const I = 0, A = 2 ** (e.maxTierZoom - I), L = Math.ceil(e.width / A), Z = Math.ceil(e.height / A), et = Math.max(1, Math.ceil(L / e.tileSize)), mt = Math.max(1, Math.ceil(Z / e.tileSize)), yt = et * mt;
1636
- if (!$ || yt > C)
1840
+ return k(() => {
1841
+ let A = !1;
1842
+ c.current = null, Z();
1843
+ const E = 0, C = 2 ** (e.maxTierZoom - E), W = Math.ceil(e.width / C), z = Math.ceil(e.height / C), ot = Math.max(1, Math.ceil(W / e.tileSize)), rt = Math.max(1, Math.ceil(z / e.tileSize)), St = ot * rt;
1844
+ if (!mt || St > v)
1637
1845
  return;
1638
- const U = document.createElement("canvas");
1639
- U.width = Math.max(1, Math.round(p)), U.height = Math.max(1, Math.round(x));
1640
- const At = U.getContext("2d");
1641
- if (!At)
1846
+ const ht = document.createElement("canvas");
1847
+ ht.width = Math.max(1, Math.round(w)), ht.height = Math.max(1, Math.round(S));
1848
+ const st = ht.getContext("2d");
1849
+ if (!st)
1642
1850
  return;
1643
- At.fillStyle = E, At.fillRect(0, 0, U.width, U.height);
1644
- const gt = [];
1645
- for (let N = 0; N < mt; N += 1)
1646
- for (let G = 0; G < et; G += 1) {
1647
- const ut = G * e.tileSize * A, nt = N * e.tileSize * A, rt = Math.min((G + 1) * e.tileSize, L) * A, q = Math.min((N + 1) * e.tileSize, Z) * A;
1648
- gt.push({
1649
- url: Wn(e, I, G, N),
1650
- bounds: [ut, nt, rt, q]
1851
+ st.fillStyle = P, st.fillRect(0, 0, ht.width, ht.height);
1852
+ const O = [];
1853
+ for (let Q = 0; Q < rt; Q += 1)
1854
+ for (let K = 0; K < ot; K += 1) {
1855
+ const N = K * e.tileSize * C, it = Q * e.tileSize * C, at = Math.min((K + 1) * e.tileSize, W) * C, ut = Math.min((Q + 1) * e.tileSize, z) * C;
1856
+ O.push({
1857
+ url: er(e, E, K, Q),
1858
+ bounds: [N, it, at, ut]
1651
1859
  });
1652
1860
  }
1653
1861
  return Promise.allSettled(
1654
- gt.map(async (N) => {
1655
- const G = !!n, ut = await fetch(N.url, {
1656
- headers: G ? { Authorization: n } : void 0
1862
+ O.map(async (Q) => {
1863
+ const K = !!n, N = await fetch(Q.url, {
1864
+ headers: K ? { Authorization: n } : void 0
1657
1865
  });
1658
- if (!ut.ok)
1659
- throw new Error(`HTTP ${ut.status}`);
1660
- const nt = await createImageBitmap(await ut.blob());
1661
- return { tile: N, bitmap: nt };
1866
+ if (!N.ok)
1867
+ throw new Error(`HTTP ${N.status}`);
1868
+ const it = await createImageBitmap(await N.blob());
1869
+ return { tile: Q, bitmap: it };
1662
1870
  })
1663
- ).then((N) => {
1664
- if (M) {
1665
- for (const nt of N)
1666
- nt.status === "fulfilled" && nt.value.bitmap.close();
1871
+ ).then((Q) => {
1872
+ if (A) {
1873
+ for (const it of Q)
1874
+ it.status === "fulfilled" && it.value.bitmap.close();
1667
1875
  return;
1668
1876
  }
1669
- const G = U.width / Math.max(1, e.width), ut = U.height / Math.max(1, e.height);
1670
- for (const nt of N) {
1671
- if (nt.status !== "fulfilled") continue;
1877
+ const K = ht.width / Math.max(1, e.width), N = ht.height / Math.max(1, e.height);
1878
+ for (const it of Q) {
1879
+ if (it.status !== "fulfilled") continue;
1672
1880
  const {
1673
- tile: { bounds: rt },
1674
- bitmap: q
1675
- } = nt.value, It = rt[0] * G, _t = rt[1] * ut, F = Math.max(1, (rt[2] - rt[0]) * G), ct = Math.max(1, (rt[3] - rt[1]) * ut);
1676
- At.drawImage(q, It, _t, F, ct), q.close();
1881
+ tile: { bounds: at },
1882
+ bitmap: ut
1883
+ } = it.value, J = at[0] * K, Ct = at[1] * N, Pt = Math.max(1, (at[2] - at[0]) * K), It = Math.max(1, (at[3] - at[1]) * N);
1884
+ st.drawImage(ut, J, Ct, Pt, It), ut.close();
1677
1885
  }
1678
- u.current = U, K();
1886
+ c.current = ht, Z();
1679
1887
  }), () => {
1680
- M = !0;
1888
+ A = !0;
1681
1889
  };
1682
1890
  }, [
1683
1891
  e,
1684
1892
  n,
1685
- p,
1686
- x,
1687
- E,
1688
- $,
1689
- C,
1690
- K
1691
- ]), X(() => {
1692
- K();
1693
- }, [K]), X(() => {
1893
+ w,
1894
+ S,
1895
+ P,
1896
+ mt,
1897
+ v,
1898
+ Z
1899
+ ]), k(() => {
1900
+ Z();
1901
+ }, [Z]), k(() => {
1694
1902
  if (i)
1695
- return i.current = K, () => {
1696
- i.current === K && (i.current = null);
1903
+ return i.current = Z, () => {
1904
+ i.current === Z && (i.current = null);
1697
1905
  };
1698
- }, [i, K]), X(
1906
+ }, [i, Z]), k(
1699
1907
  () => () => {
1700
- h.current = { active: !1, pointerId: null }, g.current !== null && (cancelAnimationFrame(g.current), g.current = null), d.current = !1;
1908
+ l.current = { active: !1, pointerId: null }, m.current !== null && (cancelAnimationFrame(m.current), m.current = null), d.current = !1;
1701
1909
  },
1702
1910
  []
1703
1911
  ), /* @__PURE__ */ Ut(
@@ -1705,21 +1913,21 @@ function bi({
1705
1913
  {
1706
1914
  ref: a,
1707
1915
  className: o,
1708
- style: vt,
1709
- onPointerDown: Kt,
1710
- onPointerMove: dt,
1711
- onPointerUp: Q,
1712
- onPointerCancel: Q,
1713
- onContextMenu: (M) => {
1714
- M.preventDefault();
1916
+ style: Nt,
1917
+ onPointerDown: jt,
1918
+ onPointerMove: pt,
1919
+ onPointerUp: nt,
1920
+ onPointerCancel: nt,
1921
+ onContextMenu: (A) => {
1922
+ A.preventDefault();
1715
1923
  },
1716
- onWheel: (M) => {
1717
- M.preventDefault(), M.stopPropagation();
1924
+ onWheel: (A) => {
1925
+ A.preventDefault(), A.stopPropagation();
1718
1926
  }
1719
1927
  }
1720
1928
  );
1721
1929
  }
1722
- function go({
1930
+ function Uo({
1723
1931
  imageWidth: e,
1724
1932
  imageHeight: t,
1725
1933
  tiles: n,
@@ -1727,32 +1935,32 @@ function go({
1727
1935
  className: i,
1728
1936
  style: o
1729
1937
  }) {
1730
- const s = j(null), a = j(null), u = tt(
1938
+ const s = j(null), a = j(null), c = q(
1731
1939
  () => ({ width: "100%", height: "100%", display: "block", ...o }),
1732
1940
  [o]
1733
1941
  );
1734
- return X(() => {
1735
- const c = s.current;
1736
- if (!c)
1942
+ return k(() => {
1943
+ const h = s.current;
1944
+ if (!h)
1737
1945
  return;
1738
- const h = new hr({
1739
- canvas: c,
1946
+ const l = new Tr({
1947
+ canvas: h,
1740
1948
  imageWidth: e,
1741
1949
  imageHeight: t,
1742
1950
  initialViewState: r
1743
1951
  });
1744
- return a.current = h, h.setTiles(n), () => {
1745
- h.destroy(), a.current = null;
1952
+ return a.current = l, l.setTiles(n), () => {
1953
+ l.destroy(), a.current = null;
1746
1954
  };
1747
- }, [e, t]), X(() => {
1748
- const c = a.current;
1749
- c && c.setTiles(n);
1750
- }, [n]), X(() => {
1751
- const c = a.current;
1752
- !c || !r || c.setViewState(r);
1753
- }, [r]), /* @__PURE__ */ Ut("canvas", { ref: s, className: i, style: u });
1754
- }
1755
- function Vn(e) {
1955
+ }, [e, t]), k(() => {
1956
+ const h = a.current;
1957
+ h && h.setTiles(n);
1958
+ }, [n]), k(() => {
1959
+ const h = a.current;
1960
+ !h || !r || h.setViewState(r);
1961
+ }, [r]), /* @__PURE__ */ Ut("canvas", { ref: s, className: i, style: c });
1962
+ }
1963
+ function nr(e) {
1756
1964
  return Math.max(
1757
1965
  0,
1758
1966
  Math.min(
@@ -1762,79 +1970,48 @@ function Vn(e) {
1762
1970
  )
1763
1971
  );
1764
1972
  }
1765
- function wi(e) {
1766
- if (!Array.isArray(e) || e.length < 3) return [];
1767
- const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
1768
- return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
1769
- }
1770
- function On(e) {
1771
- const t = [];
1772
- for (const n of e ?? []) {
1773
- const r = wi(n);
1774
- if (r.length < 4) continue;
1775
- let i = 1 / 0, o = 1 / 0, s = -1 / 0, a = -1 / 0;
1776
- for (const [u, c] of r)
1777
- u < i && (i = u), u > s && (s = u), c < o && (o = c), c > a && (a = c);
1778
- !Number.isFinite(i) || !Number.isFinite(o) || t.push({ ring: r, minX: i, minY: o, maxX: s, maxY: a });
1779
- }
1780
- return t;
1781
- }
1782
- function yi(e, t, n) {
1783
- let r = !1;
1784
- for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
1785
- const s = n[i][0], a = n[i][1], u = n[o][0], c = n[o][1];
1786
- a > t != c > t && e < (u - s) * (t - a) / (c - a || Number.EPSILON) + s && (r = !r);
1787
- }
1788
- return r;
1789
- }
1790
- function Gn(e, t, n) {
1791
- for (const r of n)
1792
- if (!(e < r.minX || e > r.maxX || t < r.minY || t > r.maxY) && yi(e, t, r.ring))
1793
- return !0;
1794
- return !1;
1795
- }
1796
- function Ee(e, t) {
1973
+ function Ie(e, t) {
1797
1974
  if (!e || !e.count || !e.positions || !e.paletteIndices)
1798
1975
  return null;
1799
- const n = On(t ?? []);
1976
+ const n = le(t ?? []);
1800
1977
  if (n.length === 0)
1801
1978
  return {
1802
1979
  count: 0,
1803
1980
  positions: new Float32Array(0),
1804
1981
  paletteIndices: new Uint16Array(0)
1805
1982
  };
1806
- const r = Vn(e), i = e.positions, o = e.paletteIndices, s = e.ids instanceof Uint32Array && e.ids.length >= r ? e.ids : null, a = new Float32Array(r * 2), u = new Uint16Array(r), c = s ? new Uint32Array(r) : null;
1807
- let h = 0;
1983
+ const r = nr(e), i = e.positions, o = e.paletteIndices, s = e.ids instanceof Uint32Array && e.ids.length >= r ? e.ids : null, a = new Float32Array(r * 2), c = new Uint16Array(r), h = s ? new Uint32Array(r) : null;
1984
+ let l = 0;
1808
1985
  for (let d = 0; d < r; d += 1) {
1809
- const p = i[d * 2], x = i[d * 2 + 1];
1810
- Gn(p, x, n) && (a[h * 2] = p, a[h * 2 + 1] = x, u[h] = o[d], c && (c[h] = s[d]), h += 1);
1986
+ const w = i[d * 2], S = i[d * 2 + 1];
1987
+ ve(w, S, n) && (a[l * 2] = w, a[l * 2 + 1] = S, c[l] = o[d], h && (h[l] = s[d]), l += 1);
1811
1988
  }
1812
- const g = {
1813
- count: h,
1814
- positions: a.subarray(0, h * 2),
1815
- paletteIndices: u.subarray(0, h)
1989
+ const m = {
1990
+ count: l,
1991
+ positions: a.subarray(0, l * 2),
1992
+ paletteIndices: c.subarray(0, l)
1816
1993
  };
1817
- return c && (g.ids = c.subarray(0, h)), g;
1994
+ return h && (m.ids = h.subarray(0, l)), m;
1818
1995
  }
1819
- function xi(e, t) {
1996
+ function Wi(e, t) {
1820
1997
  if (!e || !e.count || !e.positions || !e.paletteIndices)
1821
1998
  return new Uint32Array(0);
1822
- const n = On(t ?? []);
1999
+ const n = le(t ?? []);
1823
2000
  if (n.length === 0)
1824
2001
  return new Uint32Array(0);
1825
- const r = Vn(e);
2002
+ const r = nr(e);
1826
2003
  if (r === 0)
1827
2004
  return new Uint32Array(0);
1828
2005
  const i = e.positions, o = new Uint32Array(r);
1829
2006
  let s = 0;
1830
2007
  for (let a = 0; a < r; a += 1) {
1831
- const u = i[a * 2], c = i[a * 2 + 1];
1832
- Gn(u, c, n) && (o[s] = a, s += 1);
2008
+ const c = i[a * 2], h = i[a * 2 + 1];
2009
+ ve(c, h, n) && (o[s] = a, s += 1);
1833
2010
  }
1834
2011
  return o.subarray(0, s);
1835
2012
  }
1836
- let xe = null;
1837
- const Si = `
2013
+ let Te = null;
2014
+ const Oi = `
1838
2015
  struct Params {
1839
2016
  pointCount: u32,
1840
2017
  boundsCount: u32,
@@ -1866,21 +2043,21 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
1866
2043
  outputMask[i] = inside;
1867
2044
  }
1868
2045
  `;
1869
- function Ti() {
2046
+ function Vi() {
1870
2047
  if (typeof navigator > "u") return !1;
1871
2048
  const e = navigator;
1872
2049
  return typeof e.gpu == "object" && e.gpu !== null;
1873
2050
  }
1874
- function qn() {
1875
- if (!Ti()) return null;
2051
+ function rr() {
2052
+ if (!Vi()) return null;
1876
2053
  const t = navigator.gpu;
1877
2054
  if (!t || typeof t != "object") return null;
1878
2055
  const n = t;
1879
2056
  return typeof n.requestAdapter != "function" ? null : n;
1880
2057
  }
1881
- const Se = globalThis.GPUShaderStage?.COMPUTE ?? 4, Ue = globalThis.GPUBufferUsage?.STORAGE ?? 128, Te = globalThis.GPUBufferUsage?.COPY_DST ?? 8, Mi = globalThis.GPUBufferUsage?.COPY_SRC ?? 4, Ai = globalThis.GPUBufferUsage?.UNIFORM ?? 64, Pi = globalThis.GPUBufferUsage?.MAP_READ ?? 1, Ei = globalThis.GPUMapMode?.READ ?? 1;
1882
- async function po() {
1883
- const e = qn();
2058
+ const Me = globalThis.GPUShaderStage?.COMPUTE ?? 4, Xe = globalThis.GPUBufferUsage?.STORAGE ?? 128, Ae = globalThis.GPUBufferUsage?.COPY_DST ?? 8, Gi = globalThis.GPUBufferUsage?.COPY_SRC ?? 4, qi = globalThis.GPUBufferUsage?.UNIFORM ?? 64, Hi = globalThis.GPUBufferUsage?.MAP_READ ?? 1, $i = globalThis.GPUMapMode?.READ ?? 1;
2059
+ async function Fo() {
2060
+ const e = rr();
1884
2061
  if (!e)
1885
2062
  return { supported: !1, features: [] };
1886
2063
  const t = await e.requestAdapter();
@@ -1899,9 +2076,9 @@ async function po() {
1899
2076
  }
1900
2077
  } : { supported: !1, features: [] };
1901
2078
  }
1902
- async function Ri() {
1903
- return xe || (xe = (async () => {
1904
- const e = qn();
2079
+ async function Zi() {
2080
+ return Te || (Te = (async () => {
2081
+ const e = rr();
1905
2082
  if (!e) return null;
1906
2083
  const t = await e.requestAdapter();
1907
2084
  if (!t) return null;
@@ -1909,40 +2086,40 @@ async function Ri() {
1909
2086
  entries: [
1910
2087
  {
1911
2088
  binding: 0,
1912
- visibility: Se,
2089
+ visibility: Me,
1913
2090
  buffer: { type: "read-only-storage" }
1914
2091
  },
1915
2092
  {
1916
2093
  binding: 1,
1917
- visibility: Se,
2094
+ visibility: Me,
1918
2095
  buffer: { type: "read-only-storage" }
1919
2096
  },
1920
2097
  {
1921
2098
  binding: 2,
1922
- visibility: Se,
2099
+ visibility: Me,
1923
2100
  buffer: { type: "storage" }
1924
2101
  },
1925
2102
  {
1926
2103
  binding: 3,
1927
- visibility: Se,
2104
+ visibility: Me,
1928
2105
  buffer: { type: "uniform" }
1929
2106
  }
1930
2107
  ]
1931
2108
  }), i = n.createComputePipeline({
1932
2109
  layout: n.createPipelineLayout({ bindGroupLayouts: [r] }),
1933
2110
  compute: {
1934
- module: n.createShaderModule({ code: Si }),
2111
+ module: n.createShaderModule({ code: Oi }),
1935
2112
  entryPoint: "main"
1936
2113
  }
1937
2114
  });
1938
2115
  return { device: n, pipeline: i, bindGroupLayout: r };
1939
- })(), xe);
2116
+ })(), Te);
1940
2117
  }
1941
- function Me(e, t) {
2118
+ function Pe(e, t) {
1942
2119
  return Math.ceil(e / t) * t;
1943
2120
  }
1944
- async function vi(e, t, n) {
1945
- const r = await Ri();
2121
+ async function Ki(e, t, n) {
2122
+ const r = await Zi();
1946
2123
  if (!r) return null;
1947
2124
  const i = Math.max(0, Math.floor(t)), o = Math.max(0, Math.floor(n.length / 4));
1948
2125
  if (i === 0 || o === 0)
@@ -1950,27 +2127,27 @@ async function vi(e, t, n) {
1950
2127
  const s = Math.min(i, Math.floor(e.length / 2));
1951
2128
  if (s === 0)
1952
2129
  return new Uint32Array(0);
1953
- const a = s * 2 * Float32Array.BYTES_PER_ELEMENT, u = o * 4 * Float32Array.BYTES_PER_ELEMENT, c = s * Uint32Array.BYTES_PER_ELEMENT, h = Number(r.device.limits.maxStorageBufferBindingSize);
1954
- if (a > h || u > h || c > h)
2130
+ const a = s * 2 * Float32Array.BYTES_PER_ELEMENT, c = o * 4 * Float32Array.BYTES_PER_ELEMENT, h = s * Uint32Array.BYTES_PER_ELEMENT, l = Number(r.device.limits.maxStorageBufferBindingSize);
2131
+ if (a > l || c > l || h > l)
1955
2132
  return null;
1956
- const g = r.device.createBuffer({
1957
- size: Me(a, 4),
1958
- usage: Ue | Te
2133
+ const m = r.device.createBuffer({
2134
+ size: Pe(a, 4),
2135
+ usage: Xe | Ae
1959
2136
  }), d = r.device.createBuffer({
1960
- size: Me(u, 4),
1961
- usage: Ue | Te
1962
- }), p = r.device.createBuffer({
1963
- size: Me(c, 4),
1964
- usage: Ue | Mi
1965
- }), x = r.device.createBuffer({
1966
- size: 16,
1967
- usage: Ai | Te
2137
+ size: Pe(c, 4),
2138
+ usage: Xe | Ae
2139
+ }), w = r.device.createBuffer({
2140
+ size: Pe(h, 4),
2141
+ usage: Xe | Gi
1968
2142
  }), S = r.device.createBuffer({
1969
- size: Me(c, 4),
1970
- usage: Te | Pi
2143
+ size: 16,
2144
+ usage: qi | Ae
2145
+ }), x = r.device.createBuffer({
2146
+ size: Pe(h, 4),
2147
+ usage: Ae | Hi
1971
2148
  });
1972
2149
  r.device.queue.writeBuffer(
1973
- g,
2150
+ m,
1974
2151
  0,
1975
2152
  e.buffer,
1976
2153
  e.byteOffset,
@@ -1980,73 +2157,42 @@ async function vi(e, t, n) {
1980
2157
  0,
1981
2158
  n.buffer,
1982
2159
  n.byteOffset,
1983
- u
2160
+ c
1984
2161
  ), r.device.queue.writeBuffer(
1985
- x,
2162
+ S,
1986
2163
  0,
1987
2164
  new Uint32Array([s, o, 0, 0])
1988
2165
  );
1989
- const P = r.device.createBindGroup({
2166
+ const T = r.device.createBindGroup({
1990
2167
  layout: r.bindGroupLayout,
1991
2168
  entries: [
1992
- { binding: 0, resource: { buffer: g } },
2169
+ { binding: 0, resource: { buffer: m } },
1993
2170
  { binding: 1, resource: { buffer: d } },
1994
- { binding: 2, resource: { buffer: p } },
1995
- { binding: 3, resource: { buffer: x } }
2171
+ { binding: 2, resource: { buffer: w } },
2172
+ { binding: 3, resource: { buffer: S } }
1996
2173
  ]
1997
- }), k = r.device.createCommandEncoder(), C = k.beginComputePass();
1998
- C.setPipeline(r.pipeline), C.setBindGroup(0, P), C.dispatchWorkgroups(Math.ceil(s / 256)), C.end(), k.copyBufferToBuffer(p, 0, S, 0, c), r.device.queue.submit([k.finish()]), await S.mapAsync(Ei);
1999
- const E = S.getMappedRange(), D = new Uint32Array(E.slice(0));
2000
- return S.unmap(), g.destroy(), d.destroy(), p.destroy(), x.destroy(), S.destroy(), D;
2174
+ }), L = r.device.createCommandEncoder(), v = L.beginComputePass();
2175
+ v.setPipeline(r.pipeline), v.setBindGroup(0, T), v.dispatchWorkgroups(Math.ceil(s / 256)), v.end(), L.copyBufferToBuffer(w, 0, x, 0, h), r.device.queue.submit([L.finish()]), await x.mapAsync($i);
2176
+ const P = x.getMappedRange(), F = new Uint32Array(P.slice(0));
2177
+ return x.unmap(), m.destroy(), d.destroy(), w.destroy(), S.destroy(), x.destroy(), F;
2001
2178
  }
2002
- function Lt() {
2179
+ function Dt() {
2003
2180
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2004
2181
  }
2005
- function Ci(e) {
2006
- if (!Array.isArray(e) || e.length < 3) return [];
2007
- const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
2008
- return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
2009
- }
2010
- function Ii(e) {
2011
- const t = [];
2012
- for (const n of e ?? []) {
2013
- const r = Ci(n);
2014
- if (r.length < 4) continue;
2015
- let i = 1 / 0, o = 1 / 0, s = -1 / 0, a = -1 / 0;
2016
- for (const [u, c] of r)
2017
- u < i && (i = u), u > s && (s = u), c < o && (o = c), c > a && (a = c);
2018
- !Number.isFinite(i) || !Number.isFinite(o) || t.push({ ring: r, minX: i, minY: o, maxX: s, maxY: a });
2019
- }
2020
- return t;
2021
- }
2022
- function _i(e, t, n) {
2023
- let r = !1;
2024
- for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
2025
- const s = n[i][0], a = n[i][1], u = n[o][0], c = n[o][1];
2026
- a > t != c > t && e < (u - s) * (t - a) / (c - a || Number.EPSILON) + s && (r = !r);
2027
- }
2028
- return r;
2029
- }
2030
- function Cn(e, t, n) {
2031
- for (const r of n)
2032
- if (!(e < r.minX || e > r.maxX || t < r.minY || t > r.maxY) && _i(e, t, r.ring))
2033
- return !0;
2034
- return !1;
2035
- }
2036
- async function Bi(e, t, n = {}) {
2037
- const r = Lt(), i = n.bridgeToDraw === !0;
2182
+ async function Ji(e, t, n = {}) {
2183
+ const r = Dt(), i = n.bridgeToDraw === !0;
2038
2184
  if (!e || !e.count || !e.positions || !e.paletteIndices)
2039
2185
  return {
2040
2186
  data: null,
2041
2187
  meta: {
2042
2188
  mode: "hybrid-webgpu",
2043
- durationMs: Lt() - r,
2189
+ durationMs: Dt() - r,
2044
2190
  usedWebGpu: !1,
2045
2191
  candidateCount: 0,
2046
2192
  bridgedToDraw: !1
2047
2193
  }
2048
2194
  };
2049
- const o = Ii(t ?? []);
2195
+ const o = le(t ?? []);
2050
2196
  if (o.length === 0)
2051
2197
  return {
2052
2198
  data: {
@@ -2056,7 +2202,7 @@ async function Bi(e, t, n = {}) {
2056
2202
  },
2057
2203
  meta: {
2058
2204
  mode: "hybrid-webgpu",
2059
- durationMs: Lt() - r,
2205
+ durationMs: Dt() - r,
2060
2206
  usedWebGpu: !1,
2061
2207
  candidateCount: 0,
2062
2208
  bridgedToDraw: !1
@@ -2072,56 +2218,56 @@ async function Bi(e, t, n = {}) {
2072
2218
  },
2073
2219
  meta: {
2074
2220
  mode: "hybrid-webgpu",
2075
- durationMs: Lt() - r,
2221
+ durationMs: Dt() - r,
2076
2222
  usedWebGpu: !1,
2077
2223
  candidateCount: 0,
2078
2224
  bridgedToDraw: !1
2079
2225
  }
2080
2226
  };
2081
- const u = new Float32Array(o.length * 4);
2082
- for (let C = 0; C < o.length; C += 1) {
2083
- const E = C * 4, D = o[C];
2084
- u[E] = D.minX, u[E + 1] = D.minY, u[E + 2] = D.maxX, u[E + 3] = D.maxY;
2227
+ const c = new Float32Array(o.length * 4);
2228
+ for (let v = 0; v < o.length; v += 1) {
2229
+ const P = v * 4, F = o[v];
2230
+ c[P] = F.minX, c[P + 1] = F.minY, c[P + 2] = F.maxX, c[P + 3] = F.maxY;
2085
2231
  }
2086
- let c = null, h = !1;
2232
+ let h = null, l = !1;
2087
2233
  try {
2088
- c = await vi(e.positions, s, u), h = !!c;
2234
+ h = await Ki(e.positions, s, c), l = !!h;
2089
2235
  } catch {
2090
- c = null, h = !1;
2236
+ h = null, l = !1;
2091
2237
  }
2092
- if (!c)
2238
+ if (!h)
2093
2239
  return {
2094
- data: Ee(e, t),
2240
+ data: Ie(e, t),
2095
2241
  meta: {
2096
2242
  mode: "hybrid-webgpu",
2097
- durationMs: Lt() - r,
2243
+ durationMs: Dt() - r,
2098
2244
  usedWebGpu: !1,
2099
2245
  candidateCount: s,
2100
2246
  bridgedToDraw: !1
2101
2247
  }
2102
2248
  };
2103
- let g = 0;
2104
- for (let C = 0; C < s; C += 1)
2105
- c[C] === 1 && (g += 1);
2106
- const d = new Uint32Array(g);
2107
- if (g > 0) {
2108
- let C = 0;
2109
- for (let E = 0; E < s; E += 1)
2110
- c[E] === 1 && (d[C] = E, C += 1);
2111
- }
2112
- if (g === 0) {
2249
+ let m = 0;
2250
+ for (let v = 0; v < s; v += 1)
2251
+ h[v] === 1 && (m += 1);
2252
+ const d = new Uint32Array(m);
2253
+ if (m > 0) {
2254
+ let v = 0;
2255
+ for (let P = 0; P < s; P += 1)
2256
+ h[P] === 1 && (d[v] = P, v += 1);
2257
+ }
2258
+ if (m === 0) {
2113
2259
  if (i) {
2114
- const C = {
2260
+ const v = {
2115
2261
  count: s,
2116
2262
  positions: e.positions.subarray(0, s * 2),
2117
2263
  paletteIndices: e.paletteIndices.subarray(0, s),
2118
2264
  drawIndices: new Uint32Array(0)
2119
2265
  };
2120
- return a && (C.ids = a.subarray(0, s)), {
2121
- data: C,
2266
+ return a && (v.ids = a.subarray(0, s)), {
2267
+ data: v,
2122
2268
  meta: {
2123
2269
  mode: "hybrid-webgpu",
2124
- durationMs: Lt() - r,
2270
+ durationMs: Dt() - r,
2125
2271
  usedWebGpu: !0,
2126
2272
  candidateCount: 0,
2127
2273
  bridgedToDraw: !0
@@ -2137,7 +2283,7 @@ async function Bi(e, t, n = {}) {
2137
2283
  },
2138
2284
  meta: {
2139
2285
  mode: "hybrid-webgpu",
2140
- durationMs: Lt() - r,
2286
+ durationMs: Dt() - r,
2141
2287
  usedWebGpu: !0,
2142
2288
  candidateCount: 0,
2143
2289
  bridgedToDraw: !1
@@ -2145,76 +2291,76 @@ async function Bi(e, t, n = {}) {
2145
2291
  };
2146
2292
  }
2147
2293
  if (i) {
2148
- const C = new Uint32Array(g);
2149
- let E = 0;
2150
- for (let J = 0; J < g; J += 1) {
2151
- const ft = d[J] ?? 0, at = e.positions[ft * 2], $ = e.positions[ft * 2 + 1];
2152
- Cn(at, $, o) && (C[E] = ft, E += 1);
2294
+ const v = new Uint32Array(m);
2295
+ let P = 0;
2296
+ for (let H = 0; H < m; H += 1) {
2297
+ const dt = d[H] ?? 0, wt = e.positions[dt * 2], mt = e.positions[dt * 2 + 1];
2298
+ ve(wt, mt, o) && (v[P] = dt, P += 1);
2153
2299
  }
2154
- const D = {
2300
+ const F = {
2155
2301
  count: s,
2156
2302
  positions: e.positions.subarray(0, s * 2),
2157
2303
  paletteIndices: e.paletteIndices.subarray(0, s),
2158
- drawIndices: C.subarray(0, E)
2304
+ drawIndices: v.subarray(0, P)
2159
2305
  };
2160
- return a && (D.ids = a.subarray(0, s)), {
2161
- data: D,
2306
+ return a && (F.ids = a.subarray(0, s)), {
2307
+ data: F,
2162
2308
  meta: {
2163
2309
  mode: "hybrid-webgpu",
2164
- durationMs: Lt() - r,
2310
+ durationMs: Dt() - r,
2165
2311
  usedWebGpu: !0,
2166
- candidateCount: g,
2312
+ candidateCount: m,
2167
2313
  bridgedToDraw: !0
2168
2314
  }
2169
2315
  };
2170
2316
  }
2171
- const p = new Float32Array(g * 2), x = new Uint16Array(g), S = a ? new Uint32Array(g) : null;
2172
- let P = 0;
2173
- for (let C = 0; C < g; C += 1) {
2174
- const E = d[C] ?? 0, D = e.positions[E * 2], J = e.positions[E * 2 + 1];
2175
- Cn(D, J, o) && (p[P * 2] = D, p[P * 2 + 1] = J, x[P] = e.paletteIndices[E], S && (S[P] = a[E]), P += 1);
2317
+ const w = new Float32Array(m * 2), S = new Uint16Array(m), x = a ? new Uint32Array(m) : null;
2318
+ let T = 0;
2319
+ for (let v = 0; v < m; v += 1) {
2320
+ const P = d[v] ?? 0, F = e.positions[P * 2], H = e.positions[P * 2 + 1];
2321
+ ve(F, H, o) && (w[T * 2] = F, w[T * 2 + 1] = H, S[T] = e.paletteIndices[P], x && (x[T] = a[P]), T += 1);
2176
2322
  }
2177
- const k = {
2178
- count: P,
2179
- positions: p.subarray(0, P * 2),
2180
- paletteIndices: x.subarray(0, P)
2323
+ const L = {
2324
+ count: T,
2325
+ positions: w.subarray(0, T * 2),
2326
+ paletteIndices: S.subarray(0, T)
2181
2327
  };
2182
- return S && (k.ids = S.subarray(0, P)), {
2183
- data: k,
2328
+ return x && (L.ids = x.subarray(0, T)), {
2329
+ data: L,
2184
2330
  meta: {
2185
2331
  mode: "hybrid-webgpu",
2186
- durationMs: Lt() - r,
2332
+ durationMs: Dt() - r,
2187
2333
  usedWebGpu: !0,
2188
- candidateCount: g,
2334
+ candidateCount: m,
2189
2335
  bridgedToDraw: !1
2190
2336
  }
2191
2337
  };
2192
2338
  }
2193
- let wt = null, Ye = !0, $n = 1;
2194
- const Vt = /* @__PURE__ */ new Map();
2195
- function Yt() {
2339
+ let Mt = null, He = !0, ir = 1;
2340
+ const Zt = /* @__PURE__ */ new Map();
2341
+ function $t() {
2196
2342
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2197
2343
  }
2198
- function Hn() {
2199
- if (!Ye) return null;
2200
- if (wt) return wt;
2344
+ function or() {
2345
+ if (!He) return null;
2346
+ if (Mt) return Mt;
2201
2347
  try {
2202
2348
  const e = new Worker(new URL(
2203
2349
  /* @vite-ignore */
2204
- "" + new URL("assets/roi-clip-worker-D3hALtsJ.js", import.meta.url).href,
2350
+ "" + new URL("assets/roi-clip-worker-BRaTL8Jd.js", import.meta.url).href,
2205
2351
  import.meta.url
2206
2352
  ), { type: "module" });
2207
- return e.addEventListener("message", qe), e.addEventListener("error", $e), wt = e, e;
2353
+ return e.addEventListener("message", Qe), e.addEventListener("error", tn), Mt = e, e;
2208
2354
  } catch {
2209
- return Ye = !1, null;
2355
+ return He = !1, null;
2210
2356
  }
2211
2357
  }
2212
- function qe(e) {
2358
+ function Qe(e) {
2213
2359
  const t = e.data;
2214
2360
  if (!t) return;
2215
- const n = Vt.get(t.id);
2361
+ const n = Zt.get(t.id);
2216
2362
  if (!n) return;
2217
- if (Vt.delete(t.id), t.type === "roi-clip-failure") {
2363
+ if (Zt.delete(t.id), t.type === "roi-clip-failure") {
2218
2364
  n.reject(new Error(t.error || "worker clip failed"));
2219
2365
  return;
2220
2366
  }
@@ -2223,12 +2369,12 @@ function qe(e) {
2223
2369
  n.reject(new Error("worker response mismatch: expected point data result"));
2224
2370
  return;
2225
2371
  }
2226
- const u = Math.max(0, Math.floor(t.count)), c = new Uint32Array(t.indices).subarray(0, u);
2372
+ const c = Math.max(0, Math.floor(t.count)), h = new Uint32Array(t.indices).subarray(0, c);
2227
2373
  n.resolve({
2228
- indices: c,
2374
+ indices: h,
2229
2375
  meta: {
2230
2376
  mode: "worker",
2231
- durationMs: Number.isFinite(t.durationMs) ? t.durationMs : Yt() - n.startMs
2377
+ durationMs: Number.isFinite(t.durationMs) ? t.durationMs : $t() - n.startMs
2232
2378
  }
2233
2379
  });
2234
2380
  return;
@@ -2246,42 +2392,42 @@ function qe(e) {
2246
2392
  data: a,
2247
2393
  meta: {
2248
2394
  mode: "worker",
2249
- durationMs: Number.isFinite(t.durationMs) ? t.durationMs : Yt() - n.startMs
2395
+ durationMs: Number.isFinite(t.durationMs) ? t.durationMs : $t() - n.startMs
2250
2396
  }
2251
2397
  });
2252
2398
  }
2253
- function $e() {
2254
- Ye = !1, wt && (wt.removeEventListener("message", qe), wt.removeEventListener("error", $e), wt.terminate(), wt = null);
2255
- for (const [, e] of Vt)
2399
+ function tn() {
2400
+ He = !1, Mt && (Mt.removeEventListener("message", Qe), Mt.removeEventListener("error", tn), Mt.terminate(), Mt = null);
2401
+ for (const [, e] of Zt)
2256
2402
  e.reject(new Error("worker crashed"));
2257
- Vt.clear();
2403
+ Zt.clear();
2258
2404
  }
2259
- function bo() {
2260
- if (wt) {
2261
- wt.removeEventListener("message", qe), wt.removeEventListener("error", $e), wt.terminate(), wt = null;
2262
- for (const [, e] of Vt)
2405
+ function zo() {
2406
+ if (Mt) {
2407
+ Mt.removeEventListener("message", Qe), Mt.removeEventListener("error", tn), Mt.terminate(), Mt = null;
2408
+ for (const [, e] of Zt)
2263
2409
  e.reject(new Error("worker terminated"));
2264
- Vt.clear();
2410
+ Zt.clear();
2265
2411
  }
2266
2412
  }
2267
- async function Fi(e, t) {
2413
+ async function ji(e, t) {
2268
2414
  if (!e || !e.count || !e.positions || !e.paletteIndices)
2269
2415
  return {
2270
2416
  data: null,
2271
2417
  meta: { mode: "worker", durationMs: 0 }
2272
2418
  };
2273
- const n = Hn();
2419
+ const n = or();
2274
2420
  if (!n) {
2275
- const c = Yt();
2421
+ const h = $t();
2276
2422
  return {
2277
- data: Ee(e, t),
2278
- meta: { mode: "sync", durationMs: Yt() - c }
2423
+ data: Ie(e, t),
2424
+ meta: { mode: "sync", durationMs: $t() - h }
2279
2425
  };
2280
2426
  }
2281
- const r = Math.max(0, Math.min(e.count, Math.floor(e.positions.length / 2), e.paletteIndices.length)), i = e.positions.slice(0, r * 2), o = e.paletteIndices.slice(0, r), s = e.ids instanceof Uint32Array && e.ids.length >= r ? e.ids.slice(0, r) : null, a = $n++, u = Yt();
2282
- return new Promise((c, h) => {
2283
- Vt.set(a, { kind: "data", resolve: c, reject: h, startMs: u });
2284
- const g = {
2427
+ const r = Math.max(0, Math.min(e.count, Math.floor(e.positions.length / 2), e.paletteIndices.length)), i = e.positions.slice(0, r * 2), o = e.paletteIndices.slice(0, r), s = e.ids instanceof Uint32Array && e.ids.length >= r ? e.ids.slice(0, r) : null, a = ir++, c = $t();
2428
+ return new Promise((h, l) => {
2429
+ Zt.set(a, { kind: "data", resolve: h, reject: l, startMs: c });
2430
+ const m = {
2285
2431
  type: "roi-clip-request",
2286
2432
  id: a,
2287
2433
  count: r,
@@ -2290,83 +2436,54 @@ async function Fi(e, t) {
2290
2436
  ids: s?.buffer,
2291
2437
  polygons: t ?? []
2292
2438
  }, d = [i.buffer, o.buffer];
2293
- s && d.push(s.buffer), n.postMessage(g, d);
2439
+ s && d.push(s.buffer), n.postMessage(m, d);
2294
2440
  });
2295
2441
  }
2296
- async function wo(e, t) {
2442
+ async function Lo(e, t) {
2297
2443
  if (!e || !e.count || !e.positions || !e.paletteIndices)
2298
2444
  return {
2299
2445
  indices: new Uint32Array(0),
2300
2446
  meta: { mode: "worker", durationMs: 0 }
2301
2447
  };
2302
- const n = Hn();
2448
+ const n = or();
2303
2449
  if (!n) {
2304
- const a = Yt();
2450
+ const a = $t();
2305
2451
  return {
2306
- indices: xi(e, t),
2307
- meta: { mode: "sync", durationMs: Yt() - a }
2452
+ indices: Wi(e, t),
2453
+ meta: { mode: "sync", durationMs: $t() - a }
2308
2454
  };
2309
2455
  }
2310
- const r = Math.max(0, Math.min(e.count, Math.floor(e.positions.length / 2), e.paletteIndices.length)), i = e.positions.slice(0, r * 2), o = $n++, s = Yt();
2311
- return new Promise((a, u) => {
2312
- Vt.set(o, { kind: "index", resolve: a, reject: u, startMs: s });
2313
- const c = {
2456
+ const r = Math.max(0, Math.min(e.count, Math.floor(e.positions.length / 2), e.paletteIndices.length)), i = e.positions.slice(0, r * 2), o = ir++, s = $t();
2457
+ return new Promise((a, c) => {
2458
+ Zt.set(o, { kind: "index", resolve: a, reject: c, startMs: s });
2459
+ const h = {
2314
2460
  type: "roi-clip-index-request",
2315
2461
  id: o,
2316
2462
  count: r,
2317
2463
  positions: i.buffer,
2318
2464
  polygons: t ?? []
2319
2465
  };
2320
- n.postMessage(c, [i.buffer]);
2466
+ n.postMessage(h, [i.buffer]);
2321
2467
  });
2322
2468
  }
2323
- function Ui(e) {
2324
- if (!Array.isArray(e) || e.length < 3) return [];
2325
- const t = e.map(
2326
- (i) => [Number(i[0]), Number(i[1])]
2327
- ), n = t[0], r = t[t.length - 1];
2328
- return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
2329
- }
2330
- function zi(e) {
2331
- let t = 0;
2332
- for (let n = 0; n < e.length - 1; n += 1) {
2333
- const [r, i] = e[n], [o, s] = e[n + 1];
2334
- t += r * s - o * i;
2335
- }
2336
- return Math.abs(t * 0.5);
2337
- }
2338
- function Li(e) {
2469
+ function Qi(e) {
2339
2470
  const t = [];
2340
2471
  for (let n = 0; n < e.length; n += 1) {
2341
- const r = e[n];
2342
- if (!r?.coordinates?.length) continue;
2343
- const i = Ui(r.coordinates);
2344
- if (i.length < 4) continue;
2345
- let o = 1 / 0, s = 1 / 0, a = -1 / 0, u = -1 / 0;
2346
- for (const [c, h] of i)
2347
- c < o && (o = c), c > a && (a = c), h < s && (s = h), h > u && (u = h);
2348
- !Number.isFinite(o) || !Number.isFinite(s) || !Number.isFinite(a) || !Number.isFinite(u) || t.push({
2472
+ const r = e[n], i = le([r?.coordinates]);
2473
+ if (i.length === 0) continue;
2474
+ let o = 0;
2475
+ for (const s of i)
2476
+ o += s.area;
2477
+ t.push({
2349
2478
  regionId: r.id ?? n,
2350
2479
  regionIndex: n,
2351
- ring: i,
2352
- minX: o,
2353
- minY: s,
2354
- maxX: a,
2355
- maxY: u,
2356
- area: Math.max(1e-6, zi(i))
2480
+ polygons: i,
2481
+ area: Math.max(1e-6, o)
2357
2482
  });
2358
2483
  }
2359
2484
  return t;
2360
2485
  }
2361
- function Di(e, t, n) {
2362
- let r = !1;
2363
- for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
2364
- const s = n[i][0], a = n[i][1], u = n[o][0], c = n[o][1];
2365
- a > t != c > t && e < (u - s) * (t - a) / (c - a || Number.EPSILON) + s && (r = !r);
2366
- }
2367
- return r;
2368
- }
2369
- function Ni(e, t) {
2486
+ function to(e, t) {
2370
2487
  if (Array.isArray(t)) {
2371
2488
  const n = t[e];
2372
2489
  if (typeof n == "string" && n.length > 0) return n;
@@ -2377,7 +2494,7 @@ function Ni(e, t) {
2377
2494
  }
2378
2495
  return String(e);
2379
2496
  }
2380
- function ki(e, t, n = {}) {
2497
+ function eo(e, t, n = {}) {
2381
2498
  const r = Math.max(
2382
2499
  0,
2383
2500
  Math.min(
@@ -2389,23 +2506,23 @@ function ki(e, t, n = {}) {
2389
2506
  let i = null;
2390
2507
  if (e?.drawIndices instanceof Uint32Array) {
2391
2508
  const d = e.drawIndices;
2392
- let p = d.length;
2393
- for (let x = 0; x < d.length; x += 1)
2394
- d[x] < r || (p -= 1);
2395
- if (p === d.length)
2509
+ let w = d.length;
2510
+ for (let S = 0; S < d.length; S += 1)
2511
+ d[S] < r || (w -= 1);
2512
+ if (w === d.length)
2396
2513
  i = d;
2397
- else if (p > 0) {
2398
- const x = new Uint32Array(p);
2399
- let S = 0;
2400
- for (let P = 0; P < d.length; P += 1) {
2401
- const k = d[P];
2402
- k >= r || (x[S] = k, S += 1);
2514
+ else if (w > 0) {
2515
+ const S = new Uint32Array(w);
2516
+ let x = 0;
2517
+ for (let T = 0; T < d.length; T += 1) {
2518
+ const L = d[T];
2519
+ L >= r || (S[x] = L, x += 1);
2403
2520
  }
2404
- i = x;
2521
+ i = S;
2405
2522
  } else
2406
2523
  i = new Uint32Array(0);
2407
2524
  }
2408
- const o = i ? i.length : r, s = Li(t ?? []);
2525
+ const o = i ? i.length : r, s = Qi(t ?? []);
2409
2526
  if (!e || o === 0 || s.length === 0)
2410
2527
  return {
2411
2528
  groups: [],
@@ -2413,48 +2530,55 @@ function ki(e, t, n = {}) {
2413
2530
  pointsInsideAnyRegion: 0,
2414
2531
  unmatchedPointCount: o
2415
2532
  };
2416
- const a = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
2417
- let c = 0;
2533
+ const a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
2534
+ let h = 0;
2418
2535
  for (let d = 0; d < o; d += 1) {
2419
- const p = i ? i[d] : d, x = e.positions[p * 2], S = e.positions[p * 2 + 1];
2420
- let P = null;
2421
- for (const E of s)
2422
- x < E.minX || x > E.maxX || S < E.minY || S > E.maxY || Di(x, S, E.ring) && (!P || E.area < P.area) && (P = E);
2423
- if (!P) continue;
2424
- c += 1;
2425
- const k = e.paletteIndices[p] ?? 0, C = a.get(P.regionIndex) ?? /* @__PURE__ */ new Map();
2426
- C.set(k, (C.get(k) ?? 0) + 1), a.set(P.regionIndex, C), u.set(
2427
- P.regionIndex,
2428
- (u.get(P.regionIndex) ?? 0) + 1
2536
+ const w = i ? i[d] : d, S = e.positions[w * 2], x = e.positions[w * 2 + 1];
2537
+ let T = null;
2538
+ for (const P of s) {
2539
+ let F = !1;
2540
+ for (const H of P.polygons)
2541
+ if (je(S, x, H)) {
2542
+ F = !0;
2543
+ break;
2544
+ }
2545
+ F && (!T || P.area < T.area) && (T = P);
2546
+ }
2547
+ if (!T) continue;
2548
+ h += 1;
2549
+ const L = e.paletteIndices[w] ?? 0, v = a.get(T.regionIndex) ?? /* @__PURE__ */ new Map();
2550
+ v.set(L, (v.get(L) ?? 0) + 1), a.set(T.regionIndex, v), c.set(
2551
+ T.regionIndex,
2552
+ (c.get(T.regionIndex) ?? 0) + 1
2429
2553
  );
2430
2554
  }
2431
- const h = n.includeEmptyRegions ?? !1, g = [];
2555
+ const l = n.includeEmptyRegions ?? !1, m = [];
2432
2556
  for (const d of s) {
2433
- const p = u.get(d.regionIndex) ?? 0;
2434
- if (!h && p <= 0) continue;
2435
- const x = a.get(d.regionIndex) ?? /* @__PURE__ */ new Map(), S = Array.from(x.entries()).map(([P, k]) => ({
2436
- termId: Ni(P, n.paletteIndexToTermId),
2437
- paletteIndex: P,
2438
- count: k
2439
- })).sort((P, k) => k.count - P.count || P.paletteIndex - k.paletteIndex);
2440
- g.push({
2557
+ const w = c.get(d.regionIndex) ?? 0;
2558
+ if (!l && w <= 0) continue;
2559
+ const S = a.get(d.regionIndex) ?? /* @__PURE__ */ new Map(), x = Array.from(S.entries()).map(([T, L]) => ({
2560
+ termId: to(T, n.paletteIndexToTermId),
2561
+ paletteIndex: T,
2562
+ count: L
2563
+ })).sort((T, L) => L.count - T.count || T.paletteIndex - L.paletteIndex);
2564
+ m.push({
2441
2565
  regionId: d.regionId,
2442
2566
  regionIndex: d.regionIndex,
2443
- totalCount: p,
2444
- termCounts: S
2567
+ totalCount: w,
2568
+ termCounts: x
2445
2569
  });
2446
2570
  }
2447
2571
  return {
2448
- groups: g,
2572
+ groups: m,
2449
2573
  inputPointCount: o,
2450
- pointsInsideAnyRegion: c,
2451
- unmatchedPointCount: Math.max(0, o - c)
2574
+ pointsInsideAnyRegion: h,
2575
+ unmatchedPointCount: Math.max(0, o - h)
2452
2576
  };
2453
2577
  }
2454
- function Ae() {
2578
+ function Re() {
2455
2579
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2456
2580
  }
2457
- function Xi(e, t) {
2581
+ function no(e, t) {
2458
2582
  if (!t) return !1;
2459
2583
  try {
2460
2584
  const r = new URL(e, typeof window < "u" ? window.location.href : void 0).hostname.toLowerCase();
@@ -2463,7 +2587,7 @@ function Xi(e, t) {
2463
2587
  }
2464
2588
  return !0;
2465
2589
  }
2466
- class Yi {
2590
+ class ro {
2467
2591
  constructor(t) {
2468
2592
  b(this, "maxConcurrency");
2469
2593
  b(this, "maxRetries");
@@ -2513,7 +2637,7 @@ class Yi {
2513
2637
  const o = {
2514
2638
  tile: r,
2515
2639
  attempt: 0,
2516
- readyAt: Ae()
2640
+ readyAt: Re()
2517
2641
  };
2518
2642
  this.queue.push(o), this.queuedByKey.set(r.key, o);
2519
2643
  }
@@ -2569,14 +2693,14 @@ class Yi {
2569
2693
  if (this.inflight.size >= this.maxConcurrency || this.queue.length === 0) return;
2570
2694
  const t = this.queue[0]?.readyAt;
2571
2695
  if (typeof t != "number") return;
2572
- const n = Math.max(0, t - Ae());
2696
+ const n = Math.max(0, t - Re());
2573
2697
  this.timerId = window.setTimeout(() => {
2574
2698
  this.timerId = null, this.pump();
2575
2699
  }, n);
2576
2700
  }
2577
2701
  takeNextReadyQueueItem() {
2578
2702
  if (this.queue.length === 0) return null;
2579
- const t = Ae(), n = this.queue[0];
2703
+ const t = Re(), n = this.queue[0];
2580
2704
  return !n || n.readyAt > t ? null : (this.queue.shift(), this.queuedByKey.delete(n.tile.key), n);
2581
2705
  }
2582
2706
  startFetch(t) {
@@ -2586,7 +2710,7 @@ class Yi {
2586
2710
  controller: n
2587
2711
  };
2588
2712
  this.inflight.set(t.tile.key, r), this.emitStateChange();
2589
- const i = Xi(t.tile.url, this.authToken);
2713
+ const i = no(t.tile.url, this.authToken);
2590
2714
  fetch(t.tile.url, {
2591
2715
  signal: n.signal,
2592
2716
  headers: i ? { Authorization: this.authToken } : void 0
@@ -2609,12 +2733,12 @@ class Yi {
2609
2733
  return;
2610
2734
  if (t.attempt < this.maxRetries && this.visibleKeys.has(t.tile.key)) {
2611
2735
  this.retryCount += 1;
2612
- const a = t.attempt + 1, u = this.getRetryDelay(a), c = {
2736
+ const a = t.attempt + 1, c = this.getRetryDelay(a), h = {
2613
2737
  tile: t.tile,
2614
2738
  attempt: a,
2615
- readyAt: Ae() + u
2616
- }, h = this.queuedByKey.get(t.tile.key);
2617
- h ? (h.tile = c.tile, h.readyAt = Math.min(h.readyAt, c.readyAt), h.attempt = Math.max(h.attempt, c.attempt)) : (this.queue.push(c), this.queuedByKey.set(c.tile.key, c)), this.sortQueue();
2739
+ readyAt: Re() + c
2740
+ }, l = this.queuedByKey.get(t.tile.key);
2741
+ l ? (l.tile = h.tile, l.readyAt = Math.min(l.readyAt, h.readyAt), l.attempt = Math.max(l.attempt, h.attempt)) : (this.queue.push(h), this.queuedByKey.set(h.tile.key, h)), this.sortQueue();
2618
2742
  return;
2619
2743
  }
2620
2744
  this.failedCount += 1, this.onTileError?.(t.tile, o, t.attempt + 1);
@@ -2636,7 +2760,7 @@ class Yi {
2636
2760
  this.onStateChange?.(this.getSnapshot());
2637
2761
  }
2638
2762
  }
2639
- const In = 0.35, We = 0.5, Wi = 256, Ve = [
2763
+ const kn = 0.35, $e = 0.5, io = 256, Ze = [
2640
2764
  { zoom: 1, size: 2.8 },
2641
2765
  { zoom: 2, size: 3.4 },
2642
2766
  { zoom: 3, size: 4.2 },
@@ -2650,7 +2774,7 @@ const In = 0.35, We = 0.5, Wi = 256, Ve = [
2650
2774
  { zoom: 11, size: 22 },
2651
2775
  { zoom: 12, size: 28 }
2652
2776
  ];
2653
- class Vi {
2777
+ class oo {
2654
2778
  constructor() {
2655
2779
  b(this, "viewportWidth", 1);
2656
2780
  b(this, "viewportHeight", 1);
@@ -2685,14 +2809,14 @@ class Vi {
2685
2809
  this.viewState.offsetX = t - this.viewportWidth / (2 * r), this.viewState.offsetY = n - this.viewportHeight / (2 * r);
2686
2810
  }
2687
2811
  screenToWorld(t, n) {
2688
- const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = (t - this.viewportWidth * 0.5) / i, u = (n - this.viewportHeight * 0.5) / i, c = ae(r.rotationDeg), h = Math.cos(c), g = Math.sin(c);
2689
- return [o + a * h - u * g, s + a * g + u * h];
2812
+ const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = (t - this.viewportWidth * 0.5) / i, c = (n - this.viewportHeight * 0.5) / i, h = ce(r.rotationDeg), l = Math.cos(h), m = Math.sin(h);
2813
+ return [o + a * l - c * m, s + a * m + c * l];
2690
2814
  }
2691
2815
  worldToScreen(t, n) {
2692
- const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = t - o, u = n - s, c = ae(r.rotationDeg), h = Math.cos(c), g = Math.sin(c), d = a * h + u * g, p = -a * g + u * h;
2816
+ const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = t - o, c = n - s, h = ce(r.rotationDeg), l = Math.cos(h), m = Math.sin(h), d = a * l + c * m, w = -a * m + c * l;
2693
2817
  return [
2694
2818
  this.viewportWidth * 0.5 + d * i,
2695
- this.viewportHeight * 0.5 + p * i
2819
+ this.viewportHeight * 0.5 + w * i
2696
2820
  ];
2697
2821
  }
2698
2822
  getViewCorners() {
@@ -2705,38 +2829,38 @@ class Vi {
2705
2829
  ];
2706
2830
  }
2707
2831
  getMatrix() {
2708
- const t = Math.max(1e-6, this.viewState.zoom), [n, r] = this.getCenter(), i = ae(this.viewState.rotationDeg), o = Math.cos(i), s = Math.sin(i), a = 2 * t * o / this.viewportWidth, u = 2 * t * s / this.viewportWidth, c = 2 * t * s / this.viewportHeight, h = -2 * t * o / this.viewportHeight, g = -(a * n + u * r), d = -(c * n + h * r);
2709
- return new Float32Array([a, c, 0, u, h, 0, g, d, 1]);
2832
+ const t = Math.max(1e-6, this.viewState.zoom), [n, r] = this.getCenter(), i = ce(this.viewState.rotationDeg), o = Math.cos(i), s = Math.sin(i), a = 2 * t * o / this.viewportWidth, c = 2 * t * s / this.viewportWidth, h = 2 * t * s / this.viewportHeight, l = -2 * t * o / this.viewportHeight, m = -(a * n + c * r), d = -(h * n + l * r);
2833
+ return new Float32Array([a, h, 0, c, l, 0, m, d, 1]);
2710
2834
  }
2711
2835
  }
2712
- function ae(e) {
2836
+ function ce(e) {
2713
2837
  return e * Math.PI / 180;
2714
2838
  }
2715
- function _n() {
2839
+ function Xn() {
2716
2840
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2717
2841
  }
2718
- function Zt(e, t, n) {
2842
+ function qt(e, t, n) {
2719
2843
  const r = e.getUniformLocation(t, n);
2720
2844
  if (!r)
2721
2845
  throw new Error(`uniform location lookup failed: ${n}`);
2722
2846
  return r;
2723
2847
  }
2724
- function ze(e, t) {
2848
+ function Ye(e, t) {
2725
2849
  return !e || !t ? e === t : e.buffer === t.buffer && e.byteOffset === t.byteOffset && e.byteLength === t.byteLength;
2726
2850
  }
2727
- function Oe(e) {
2851
+ function Ke(e) {
2728
2852
  return e.map((t) => ({ zoom: t.zoom, size: t.size }));
2729
2853
  }
2730
- function Bn(e) {
2731
- if (!e) return Oe(Ve);
2854
+ function Yn(e) {
2855
+ if (!e) return Ke(Ze);
2732
2856
  const t = /* @__PURE__ */ new Map();
2733
2857
  for (const [n, r] of Object.entries(e)) {
2734
2858
  const i = Number(n), o = Number(r);
2735
2859
  !Number.isFinite(i) || !Number.isFinite(o) || o <= 0 || t.set(i, o);
2736
2860
  }
2737
- return t.size === 0 ? Oe(Ve) : Array.from(t.entries()).sort((n, r) => n[0] - r[0]).map(([n, r]) => ({ zoom: n, size: r }));
2861
+ return t.size === 0 ? Ke(Ze) : Array.from(t.entries()).sort((n, r) => n[0] - r[0]).map(([n, r]) => ({ zoom: n, size: r }));
2738
2862
  }
2739
- function Oi(e, t) {
2863
+ function so(e, t) {
2740
2864
  if (e === t) return !0;
2741
2865
  if (e.length !== t.length) return !1;
2742
2866
  for (let n = 0; n < e.length; n += 1)
@@ -2744,25 +2868,29 @@ function Oi(e, t) {
2744
2868
  return !1;
2745
2869
  return !0;
2746
2870
  }
2747
- function Gi(e, t) {
2748
- if (!Number.isFinite(e)) return t[0]?.size ?? We;
2749
- if (t.length === 0) return We;
2871
+ function ao(e, t) {
2872
+ if (!Number.isFinite(e)) return t[0]?.size ?? $e;
2873
+ if (t.length === 0) return $e;
2750
2874
  if (t.length === 1 || e <= t[0].zoom) return t[0].size;
2751
2875
  for (let s = 1; s < t.length; s += 1) {
2752
- const a = t[s - 1], u = t[s];
2753
- if (e > u.zoom) continue;
2754
- const c = Math.max(1e-6, u.zoom - a.zoom), h = it((e - a.zoom) / c, 0, 1);
2755
- return a.size + (u.size - a.size) * h;
2876
+ const a = t[s - 1], c = t[s];
2877
+ if (e > c.zoom) continue;
2878
+ const h = Math.max(1e-6, c.zoom - a.zoom), l = et((e - a.zoom) / h, 0, 1);
2879
+ return a.size + (c.size - a.size) * l;
2756
2880
  }
2757
2881
  const n = t[t.length - 1], r = t[t.length - 2], i = Math.max(1e-6, n.zoom - r.zoom), o = (n.size - r.size) / i;
2758
2882
  return n.size + (e - n.zoom) * o;
2759
2883
  }
2760
- class qi {
2884
+ const uo = 0.1, co = 5;
2885
+ function Wn(e) {
2886
+ return typeof e != "number" || !Number.isFinite(e) ? 1 : et(e, uo, co);
2887
+ }
2888
+ class lo {
2761
2889
  constructor(t, n, r = {}) {
2762
2890
  b(this, "canvas");
2763
2891
  b(this, "source");
2764
2892
  b(this, "gl");
2765
- b(this, "camera", new Vi());
2893
+ b(this, "camera", new oo());
2766
2894
  b(this, "onViewStateChange");
2767
2895
  b(this, "onStats");
2768
2896
  b(this, "onTileError");
@@ -2795,7 +2923,8 @@ class qi {
2795
2923
  b(this, "usePointIndices", !1);
2796
2924
  b(this, "pointBuffersDirty", !0);
2797
2925
  b(this, "pointPaletteSize", 1);
2798
- b(this, "pointSizeStops", Oe(Ve));
2926
+ b(this, "pointSizeStops", Ke(Ze));
2927
+ b(this, "pointStrokeScale", 1);
2799
2928
  b(this, "lastPointData", null);
2800
2929
  b(this, "lastPointPalette", null);
2801
2930
  b(this, "cache", /* @__PURE__ */ new Map());
@@ -2807,7 +2936,7 @@ class qi {
2807
2936
  b(this, "boundContextMenu");
2808
2937
  b(this, "boundContextLost");
2809
2938
  b(this, "boundContextRestored");
2810
- this.canvas = t, this.source = n, this.onViewStateChange = r.onViewStateChange, this.onStats = r.onStats, this.onTileError = r.onTileError, this.onContextLost = r.onContextLost, this.onContextRestored = r.onContextRestored, this.authToken = r.authToken ?? "", this.maxCacheTiles = Math.max(32, Math.floor(r.maxCacheTiles ?? 320)), this.ctrlDragRotate = r.ctrlDragRotate ?? !0, this.rotationDragSensitivityDegPerPixel = typeof r.rotationDragSensitivityDegPerPixel == "number" && Number.isFinite(r.rotationDragSensitivityDegPerPixel) ? Math.max(0, r.rotationDragSensitivityDegPerPixel) : In, this.pointSizeStops = Bn(r.pointSizeByZoom);
2939
+ this.canvas = t, this.source = n, this.onViewStateChange = r.onViewStateChange, this.onStats = r.onStats, this.onTileError = r.onTileError, this.onContextLost = r.onContextLost, this.onContextRestored = r.onContextRestored, this.authToken = r.authToken ?? "", this.maxCacheTiles = Math.max(32, Math.floor(r.maxCacheTiles ?? 320)), this.ctrlDragRotate = r.ctrlDragRotate ?? !0, this.rotationDragSensitivityDegPerPixel = typeof r.rotationDragSensitivityDegPerPixel == "number" && Number.isFinite(r.rotationDragSensitivityDegPerPixel) ? Math.max(0, r.rotationDragSensitivityDegPerPixel) : kn, this.pointSizeStops = Yn(r.pointSizeByZoom), this.pointStrokeScale = Wn(r.pointStrokeScale);
2811
2940
  const i = t.getContext("webgl2", {
2812
2941
  alpha: !1,
2813
2942
  antialias: !1,
@@ -2817,7 +2946,7 @@ class qi {
2817
2946
  });
2818
2947
  if (!i)
2819
2948
  throw new Error("WebGL2 not supported");
2820
- this.gl = i, this.tileProgram = this.initTileProgram(), this.pointProgram = this.initPointProgram(), this.tileScheduler = new Yi({
2949
+ this.gl = i, this.tileProgram = this.initTileProgram(), this.pointProgram = this.initPointProgram(), this.tileScheduler = new ro({
2821
2950
  authToken: this.authToken,
2822
2951
  maxConcurrency: r.tileScheduler?.maxConcurrency ?? 12,
2823
2952
  maxRetries: r.tileScheduler?.maxRetries ?? 2,
@@ -2834,7 +2963,7 @@ class qi {
2834
2963
  }
2835
2964
  setViewState(t) {
2836
2965
  const n = { ...t };
2837
- typeof n.zoom == "number" && (n.zoom = it(n.zoom, this.minZoom, this.maxZoom)), this.camera.setViewState(n), this.clampViewState(), this.emitViewState(), this.requestRender();
2966
+ typeof n.zoom == "number" && (n.zoom = et(n.zoom, this.minZoom, this.maxZoom)), this.camera.setViewState(n), this.clampViewState(), this.emitViewState(), this.requestRender();
2838
2967
  }
2839
2968
  getViewState() {
2840
2969
  return this.camera.getViewState();
@@ -2871,23 +3000,23 @@ class qi {
2871
3000
  t.paletteIndices.length
2872
3001
  )
2873
3002
  ), r = t.positions.subarray(0, n * 2), i = t.paletteIndices.subarray(0, n), o = t.drawIndices instanceof Uint32Array, s = o ? this.sanitizeDrawIndices(t.drawIndices, n) : null, a = this.lastPointData;
2874
- let u = this.pointBuffersDirty || !a || a.count !== n || !ze(a.positions, r) || !ze(a.paletteIndices, i), c = this.pointBuffersDirty || o && (!a?.drawIndices || !ze(a.drawIndices, s)) || !o && !!a?.drawIndices;
3003
+ let c = this.pointBuffersDirty || !a || a.count !== n || !Ye(a.positions, r) || !Ye(a.paletteIndices, i), h = this.pointBuffersDirty || o && (!a?.drawIndices || !Ye(a.drawIndices, s)) || !o && !!a?.drawIndices;
2875
3004
  if (this.lastPointData = {
2876
3005
  count: n,
2877
3006
  positions: r,
2878
3007
  paletteIndices: i,
2879
3008
  drawIndices: o ? s ?? void 0 : void 0
2880
3009
  }, this.contextLost || this.gl.isContextLost()) return;
2881
- const h = this.gl;
2882
- u && (h.bindBuffer(h.ARRAY_BUFFER, this.pointProgram.posBuffer), h.bufferData(h.ARRAY_BUFFER, this.lastPointData.positions, h.STATIC_DRAW), h.bindBuffer(h.ARRAY_BUFFER, this.pointProgram.termBuffer), h.bufferData(
2883
- h.ARRAY_BUFFER,
3010
+ const l = this.gl;
3011
+ c && (l.bindBuffer(l.ARRAY_BUFFER, this.pointProgram.posBuffer), l.bufferData(l.ARRAY_BUFFER, this.lastPointData.positions, l.STATIC_DRAW), l.bindBuffer(l.ARRAY_BUFFER, this.pointProgram.termBuffer), l.bufferData(
3012
+ l.ARRAY_BUFFER,
2884
3013
  this.lastPointData.paletteIndices,
2885
- h.STATIC_DRAW
2886
- ), h.bindBuffer(h.ARRAY_BUFFER, null)), o && c && (h.bindBuffer(h.ELEMENT_ARRAY_BUFFER, this.pointProgram.indexBuffer), h.bufferData(
2887
- h.ELEMENT_ARRAY_BUFFER,
3014
+ l.STATIC_DRAW
3015
+ ), l.bindBuffer(l.ARRAY_BUFFER, null)), o && h && (l.bindBuffer(l.ELEMENT_ARRAY_BUFFER, this.pointProgram.indexBuffer), l.bufferData(
3016
+ l.ELEMENT_ARRAY_BUFFER,
2888
3017
  s ?? new Uint32Array(0),
2889
- h.DYNAMIC_DRAW
2890
- ), h.bindBuffer(h.ELEMENT_ARRAY_BUFFER, null)), this.usePointIndices = o, this.pointCount = o ? s?.length ?? 0 : this.lastPointData.count, (u || c) && (this.pointBuffersDirty = !1), this.requestRender();
3018
+ l.DYNAMIC_DRAW
3019
+ ), l.bindBuffer(l.ELEMENT_ARRAY_BUFFER, null)), this.usePointIndices = o, this.pointCount = o ? s?.length ?? 0 : this.lastPointData.count, (c || h) && (this.pointBuffersDirty = !1), this.requestRender();
2891
3020
  }
2892
3021
  sanitizeDrawIndices(t, n) {
2893
3022
  if (n <= 0 || t.length === 0)
@@ -2912,8 +3041,12 @@ class qi {
2912
3041
  this.interactionLocked !== n && (this.interactionLocked = n, n && this.cancelDrag());
2913
3042
  }
2914
3043
  setPointSizeByZoom(t) {
2915
- const n = Bn(t);
2916
- Oi(this.pointSizeStops, n) || (this.pointSizeStops = n, this.requestRender());
3044
+ const n = Yn(t);
3045
+ so(this.pointSizeStops, n) || (this.pointSizeStops = n, this.requestRender());
3046
+ }
3047
+ setPointStrokeScale(t) {
3048
+ const n = Wn(t);
3049
+ this.pointStrokeScale !== n && (this.pointStrokeScale = n, this.requestRender());
2917
3050
  }
2918
3051
  cancelDrag() {
2919
3052
  if (this.pointerId !== null && this.canvas.hasPointerCapture(this.pointerId))
@@ -2945,38 +3078,38 @@ class qi {
2945
3078
  Math.abs(t.rotationDeg) < 1e-6 || (this.camera.setViewState({ rotationDeg: 0 }), this.clampViewState(), this.emitViewState(), this.requestRender());
2946
3079
  }
2947
3080
  getPointSizeByZoom() {
2948
- const t = Math.max(1e-6, this.camera.getViewState().zoom), n = this.source.maxTierZoom + Math.log2(t), r = Gi(n, this.pointSizeStops);
2949
- return it(r, We, Wi);
3081
+ const t = Math.max(1e-6, this.camera.getViewState().zoom), n = this.source.maxTierZoom + Math.log2(t), r = ao(n, this.pointSizeStops);
3082
+ return et(r, $e, io);
2950
3083
  }
2951
3084
  fitToImage() {
2952
3085
  const t = this.canvas.getBoundingClientRect(), n = Math.max(1, t.width || 1), r = Math.max(1, t.height || 1), i = Math.min(n / this.source.width, r / this.source.height), o = Number.isFinite(i) && i > 0 ? i : 1;
2953
3086
  this.fitZoom = o, this.minZoom = Math.max(this.fitZoom * 0.5, 1e-6), this.maxZoom = Math.max(1, this.fitZoom * 8), this.minZoom > this.maxZoom && (this.minZoom = this.maxZoom);
2954
3087
  const s = n / o, a = r / o;
2955
3088
  this.camera.setViewState({
2956
- zoom: it(o, this.minZoom, this.maxZoom),
3089
+ zoom: et(o, this.minZoom, this.maxZoom),
2957
3090
  offsetX: (this.source.width - s) * 0.5,
2958
3091
  offsetY: (this.source.height - a) * 0.5,
2959
3092
  rotationDeg: 0
2960
3093
  }), this.clampViewState(), this.emitViewState(), this.requestRender();
2961
3094
  }
2962
3095
  zoomBy(t, n, r) {
2963
- const i = this.camera.getViewState(), o = it(i.zoom * t, this.minZoom, this.maxZoom);
3096
+ const i = this.camera.getViewState(), o = et(i.zoom * t, this.minZoom, this.maxZoom);
2964
3097
  if (o === i.zoom) return;
2965
3098
  const [s, a] = this.camera.screenToWorld(n, r);
2966
3099
  this.camera.setViewState({ zoom: o });
2967
- const u = this.camera.getViewport(), c = n - u.width * 0.5, h = r - u.height * 0.5, g = ae(this.camera.getViewState().rotationDeg), d = Math.cos(g), p = Math.sin(g), x = c / o * d - h / o * p, S = c / o * p + h / o * d;
2968
- this.camera.setCenter(s - x, a - S), this.clampViewState(), this.emitViewState(), this.requestRender();
3100
+ const c = this.camera.getViewport(), h = n - c.width * 0.5, l = r - c.height * 0.5, m = ce(this.camera.getViewState().rotationDeg), d = Math.cos(m), w = Math.sin(m), S = h / o * d - l / o * w, x = h / o * w + l / o * d;
3101
+ this.camera.setCenter(s - S, a - x), this.clampViewState(), this.emitViewState(), this.requestRender();
2969
3102
  }
2970
3103
  clampViewState() {
2971
- const t = this.getViewBounds(), n = Math.max(1e-6, t[2] - t[0]), r = Math.max(1e-6, t[3] - t[1]), i = n * 0.2, o = r * 0.2, [s, a] = this.camera.getCenter(), u = n * 0.5, c = r * 0.5, h = u - i, g = this.source.width - u + i, d = c - o, p = this.source.height - c + o, x = h <= g ? it(s, h, g) : this.source.width * 0.5, S = d <= p ? it(a, d, p) : this.source.height * 0.5;
2972
- this.camera.setCenter(x, S);
3104
+ const t = this.getViewBounds(), n = Math.max(1e-6, t[2] - t[0]), r = Math.max(1e-6, t[3] - t[1]), i = n * 0.2, o = r * 0.2, [s, a] = this.camera.getCenter(), c = n * 0.5, h = r * 0.5, l = c - i, m = this.source.width - c + i, d = h - o, w = this.source.height - h + o, S = l <= m ? et(s, l, m) : this.source.width * 0.5, x = d <= w ? et(a, d, w) : this.source.height * 0.5;
3105
+ this.camera.setCenter(S, x);
2973
3106
  }
2974
3107
  emitViewState() {
2975
3108
  this.onViewStateChange?.(this.camera.getViewState());
2976
3109
  }
2977
3110
  selectTier() {
2978
3111
  const t = Math.max(1e-6, this.camera.getViewState().zoom), n = this.source.maxTierZoom + Math.log2(t);
2979
- return it(Math.floor(n), 0, this.source.maxTierZoom);
3112
+ return et(Math.floor(n), 0, this.source.maxTierZoom);
2980
3113
  }
2981
3114
  getViewBounds() {
2982
3115
  const t = this.camera.getViewCorners();
@@ -2991,40 +3124,40 @@ class qi {
2991
3124
  getVisibleTiles() {
2992
3125
  const t = this.selectTier();
2993
3126
  this.currentTier = t;
2994
- const n = this.getViewBounds(), r = Math.pow(2, this.source.maxTierZoom - t), i = Math.ceil(this.source.width / r), o = Math.ceil(this.source.height / r), s = Math.max(1, Math.ceil(i / this.source.tileSize)), a = Math.max(1, Math.ceil(o / this.source.tileSize)), u = n[0], c = n[1], h = n[2], g = n[3], d = it(
2995
- Math.floor(u / r / this.source.tileSize),
3127
+ const n = this.getViewBounds(), r = Math.pow(2, this.source.maxTierZoom - t), i = Math.ceil(this.source.width / r), o = Math.ceil(this.source.height / r), s = Math.max(1, Math.ceil(i / this.source.tileSize)), a = Math.max(1, Math.ceil(o / this.source.tileSize)), c = n[0], h = n[1], l = n[2], m = n[3], d = et(
3128
+ Math.floor(c / r / this.source.tileSize),
2996
3129
  0,
2997
3130
  s - 1
2998
- ), p = it(
2999
- Math.floor((h - 1) / r / this.source.tileSize),
3131
+ ), w = et(
3132
+ Math.floor((l - 1) / r / this.source.tileSize),
3000
3133
  0,
3001
3134
  s - 1
3002
- ), x = it(
3003
- Math.floor(c / r / this.source.tileSize),
3135
+ ), S = et(
3136
+ Math.floor(h / r / this.source.tileSize),
3004
3137
  0,
3005
3138
  a - 1
3006
- ), S = it(
3007
- Math.floor((g - 1) / r / this.source.tileSize),
3139
+ ), x = et(
3140
+ Math.floor((m - 1) / r / this.source.tileSize),
3008
3141
  0,
3009
3142
  a - 1
3010
3143
  );
3011
- if (d > p || x > S)
3144
+ if (d > w || S > x)
3012
3145
  return [];
3013
- const P = (u + h) * 0.5 / r / this.source.tileSize, k = (c + g) * 0.5 / r / this.source.tileSize, C = [];
3014
- for (let E = x; E <= S; E += 1)
3015
- for (let D = d; D <= p; D += 1) {
3016
- const J = D * this.source.tileSize * r, ft = E * this.source.tileSize * r, at = Math.min((D + 1) * this.source.tileSize, i) * r, $ = Math.min((E + 1) * this.source.tileSize, o) * r, ht = D - P, vt = E - k;
3017
- C.push({
3018
- key: `${t}/${D}/${E}`,
3146
+ const T = (c + l) * 0.5 / r / this.source.tileSize, L = (h + m) * 0.5 / r / this.source.tileSize, v = [];
3147
+ for (let P = S; P <= x; P += 1)
3148
+ for (let F = d; F <= w; F += 1) {
3149
+ const H = F * this.source.tileSize * r, dt = P * this.source.tileSize * r, wt = Math.min((F + 1) * this.source.tileSize, i) * r, mt = Math.min((P + 1) * this.source.tileSize, o) * r, X = F - T, Nt = P - L;
3150
+ v.push({
3151
+ key: `${t}/${F}/${P}`,
3019
3152
  tier: t,
3020
- x: D,
3021
- y: E,
3022
- bounds: [J, ft, at, $],
3023
- distance2: ht * ht + vt * vt,
3024
- url: Wn(this.source, t, D, E)
3153
+ x: F,
3154
+ y: P,
3155
+ bounds: [H, dt, wt, mt],
3156
+ distance2: X * X + Nt * Nt,
3157
+ url: er(this.source, t, F, P)
3025
3158
  });
3026
3159
  }
3027
- return C.sort((E, D) => E.distance2 - D.distance2), C;
3160
+ return v.sort((P, F) => P.distance2 - F.distance2), v;
3028
3161
  }
3029
3162
  trimCache() {
3030
3163
  if (this.cache.size <= this.maxCacheTiles) return;
@@ -3038,17 +3171,17 @@ class qi {
3038
3171
  }
3039
3172
  render() {
3040
3173
  if (this.destroyed || this.contextLost || this.gl.isContextLost()) return;
3041
- const t = _n();
3174
+ const t = Xn();
3042
3175
  this.frameSerial += 1;
3043
3176
  const n = this.gl, r = this.tileProgram, i = this.pointProgram;
3044
3177
  n.clearColor(0.03, 0.06, 0.1, 1), n.clear(n.COLOR_BUFFER_BIT);
3045
3178
  const o = this.getVisibleTiles(), s = this.getViewBounds(), a = new Set(o.map((d) => d.key));
3046
3179
  n.useProgram(r.program), n.bindVertexArray(r.vao), n.uniformMatrix3fv(r.uCamera, !1, this.camera.getMatrix()), n.uniform1i(r.uTexture, 0);
3047
- const u = [];
3180
+ const c = [];
3048
3181
  for (const [, d] of this.cache)
3049
- a.has(d.key) || this.intersectsBounds(d.bounds, s) && u.push(d);
3050
- u.sort((d, p) => d.tier - p.tier);
3051
- for (const d of u)
3182
+ a.has(d.key) || this.intersectsBounds(d.bounds, s) && c.push(d);
3183
+ c.sort((d, w) => d.tier - w.tier);
3184
+ for (const d of c)
3052
3185
  d.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, d.texture), n.uniform4f(
3053
3186
  r.uBounds,
3054
3187
  d.bounds[0],
@@ -3056,42 +3189,42 @@ class qi {
3056
3189
  d.bounds[2],
3057
3190
  d.bounds[3]
3058
3191
  ), n.drawArrays(n.TRIANGLE_STRIP, 0, 4);
3059
- let c = 0;
3060
- const h = [];
3192
+ let h = 0;
3193
+ const l = [];
3061
3194
  for (const d of o) {
3062
- const p = this.cache.get(d.key);
3063
- if (!p) {
3064
- h.push(d);
3195
+ const w = this.cache.get(d.key);
3196
+ if (!w) {
3197
+ l.push(d);
3065
3198
  continue;
3066
3199
  }
3067
- p.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, p.texture), n.uniform4f(
3200
+ w.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, w.texture), n.uniform4f(
3068
3201
  r.uBounds,
3069
- p.bounds[0],
3070
- p.bounds[1],
3071
- p.bounds[2],
3072
- p.bounds[3]
3073
- ), n.drawArrays(n.TRIANGLE_STRIP, 0, 4), c += 1;
3202
+ w.bounds[0],
3203
+ w.bounds[1],
3204
+ w.bounds[2],
3205
+ w.bounds[3]
3206
+ ), n.drawArrays(n.TRIANGLE_STRIP, 0, 4), h += 1;
3074
3207
  }
3075
- this.tileScheduler.schedule(h), n.bindTexture(n.TEXTURE_2D, null), n.bindVertexArray(null);
3076
- let g = 0;
3077
- if (this.pointCount > 0 && (n.enable(n.BLEND), n.blendFunc(n.ONE, n.ONE_MINUS_SRC_ALPHA), n.useProgram(i.program), n.bindVertexArray(i.vao), n.uniformMatrix3fv(i.uCamera, !1, this.camera.getMatrix()), n.uniform1f(i.uPointSize, this.getPointSizeByZoom()), n.uniform1f(i.uPaletteSize, this.pointPaletteSize), n.uniform1i(i.uPalette, 1), n.activeTexture(n.TEXTURE1), n.bindTexture(n.TEXTURE_2D, i.paletteTexture), this.usePointIndices ? n.drawElements(n.POINTS, this.pointCount, n.UNSIGNED_INT, 0) : n.drawArrays(n.POINTS, 0, this.pointCount), n.bindTexture(n.TEXTURE_2D, null), n.bindVertexArray(null), g = this.pointCount), this.onStats) {
3078
- const d = this.tileScheduler.getSnapshot(), p = c, x = h.length, S = u.length + c + (g > 0 ? 1 : 0);
3208
+ this.tileScheduler.schedule(l), n.bindTexture(n.TEXTURE_2D, null), n.bindVertexArray(null);
3209
+ let m = 0;
3210
+ if (this.pointCount > 0 && (n.enable(n.BLEND), n.blendFunc(n.ONE, n.ONE_MINUS_SRC_ALPHA), n.useProgram(i.program), n.bindVertexArray(i.vao), n.uniformMatrix3fv(i.uCamera, !1, this.camera.getMatrix()), n.uniform1f(i.uPointSize, this.getPointSizeByZoom()), n.uniform1f(i.uPointStrokeScale, this.pointStrokeScale), n.uniform1f(i.uPaletteSize, this.pointPaletteSize), n.uniform1i(i.uPalette, 1), n.activeTexture(n.TEXTURE1), n.bindTexture(n.TEXTURE_2D, i.paletteTexture), this.usePointIndices ? n.drawElements(n.POINTS, this.pointCount, n.UNSIGNED_INT, 0) : n.drawArrays(n.POINTS, 0, this.pointCount), n.bindTexture(n.TEXTURE_2D, null), n.bindVertexArray(null), m = this.pointCount), this.onStats) {
3211
+ const d = this.tileScheduler.getSnapshot(), w = h, S = l.length, x = c.length + h + (m > 0 ? 1 : 0);
3079
3212
  this.onStats({
3080
3213
  tier: this.currentTier,
3081
3214
  visible: o.length,
3082
- rendered: c,
3083
- points: g,
3084
- fallback: u.length,
3215
+ rendered: h,
3216
+ points: m,
3217
+ fallback: c.length,
3085
3218
  cache: this.cache.size,
3086
3219
  inflight: d.inflight,
3087
3220
  queued: d.queued,
3088
3221
  retries: d.retries,
3089
3222
  failed: d.failed,
3090
3223
  aborted: d.aborted,
3091
- cacheHits: p,
3092
- cacheMisses: x,
3093
- drawCalls: S,
3094
- frameMs: _n() - t
3224
+ cacheHits: w,
3225
+ cacheMisses: S,
3226
+ drawCalls: x,
3227
+ frameMs: Xn() - t
3095
3228
  });
3096
3229
  }
3097
3230
  }
@@ -3115,16 +3248,16 @@ class qi {
3115
3248
  if (this.lastPointerX = t.clientX, this.lastPointerY = t.clientY, this.interactionMode === "rotate") {
3116
3249
  const i = this.getPointerAngleRad(t.clientX, t.clientY), o = this.rotateLastAngleRad;
3117
3250
  if (this.rotateLastAngleRad = i, o !== null) {
3118
- const s = i - o, a = Math.atan2(Math.sin(s), Math.cos(s)), u = this.rotationDragSensitivityDegPerPixel / In, c = this.camera.getViewState();
3251
+ const s = i - o, a = Math.atan2(Math.sin(s), Math.cos(s)), c = this.rotationDragSensitivityDegPerPixel / kn, h = this.camera.getViewState();
3119
3252
  this.camera.setViewState({
3120
- rotationDeg: c.rotationDeg - a * 180 / Math.PI * u
3253
+ rotationDeg: h.rotationDeg - a * 180 / Math.PI * c
3121
3254
  });
3122
3255
  }
3123
3256
  } else {
3124
- const i = this.camera.getViewState(), o = Math.max(1e-6, i.zoom), s = ae(i.rotationDeg), a = Math.cos(s), u = Math.sin(s), c = (n * a - r * u) / o, h = (n * u + r * a) / o;
3257
+ const i = this.camera.getViewState(), o = Math.max(1e-6, i.zoom), s = ce(i.rotationDeg), a = Math.cos(s), c = Math.sin(s), h = (n * a - r * c) / o, l = (n * c + r * a) / o;
3125
3258
  this.camera.setViewState({
3126
- offsetX: i.offsetX - c,
3127
- offsetY: i.offsetY - h
3259
+ offsetX: i.offsetX - h,
3260
+ offsetY: i.offsetY - l
3128
3261
  });
3129
3262
  }
3130
3263
  this.clampViewState(), this.emitViewState(), this.requestRender();
@@ -3169,7 +3302,7 @@ class qi {
3169
3302
  }
3170
3303
  }
3171
3304
  initTileProgram() {
3172
- const t = this.gl, i = pn(t, `#version 300 es
3305
+ const t = this.gl, i = Pn(t, `#version 300 es
3173
3306
  precision highp float;
3174
3307
  in vec2 aUnit;
3175
3308
  in vec2 aUv;
@@ -3191,21 +3324,21 @@ class qi {
3191
3324
  out vec4 outColor;
3192
3325
  void main() {
3193
3326
  outColor = texture(uTexture, vUv);
3194
- }`), o = Zt(t, i, "uCamera"), s = Zt(t, i, "uBounds"), a = Zt(t, i, "uTexture"), u = t.createVertexArray(), c = t.createBuffer();
3195
- if (!u || !c)
3327
+ }`), o = qt(t, i, "uCamera"), s = qt(t, i, "uBounds"), a = qt(t, i, "uTexture"), c = t.createVertexArray(), h = t.createBuffer();
3328
+ if (!c || !h)
3196
3329
  throw new Error("buffer allocation failed");
3197
- t.bindVertexArray(u), t.bindBuffer(t.ARRAY_BUFFER, c), t.bufferData(
3330
+ t.bindVertexArray(c), t.bindBuffer(t.ARRAY_BUFFER, h), t.bufferData(
3198
3331
  t.ARRAY_BUFFER,
3199
3332
  new Float32Array([0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1]),
3200
3333
  t.STATIC_DRAW
3201
3334
  );
3202
- const h = t.getAttribLocation(i, "aUnit"), g = t.getAttribLocation(i, "aUv");
3203
- if (h < 0 || g < 0)
3335
+ const l = t.getAttribLocation(i, "aUnit"), m = t.getAttribLocation(i, "aUv");
3336
+ if (l < 0 || m < 0)
3204
3337
  throw new Error("tile attribute lookup failed");
3205
- return t.enableVertexAttribArray(h), t.enableVertexAttribArray(g), t.vertexAttribPointer(h, 2, t.FLOAT, !1, 16, 0), t.vertexAttribPointer(g, 2, t.FLOAT, !1, 16, 8), t.bindVertexArray(null), t.bindBuffer(t.ARRAY_BUFFER, null), { program: i, vao: u, vbo: c, uCamera: o, uBounds: s, uTexture: a };
3338
+ return t.enableVertexAttribArray(l), t.enableVertexAttribArray(m), t.vertexAttribPointer(l, 2, t.FLOAT, !1, 16, 0), t.vertexAttribPointer(m, 2, t.FLOAT, !1, 16, 8), t.bindVertexArray(null), t.bindBuffer(t.ARRAY_BUFFER, null), { program: i, vao: c, vbo: h, uCamera: o, uBounds: s, uTexture: a };
3206
3339
  }
3207
3340
  initPointProgram() {
3208
- const t = this.gl, i = pn(t, `#version 300 es
3341
+ const t = this.gl, i = Pn(t, `#version 300 es
3209
3342
  precision highp float;
3210
3343
  in vec2 aPosition;
3211
3344
  in uint aTerm;
@@ -3223,6 +3356,7 @@ class qi {
3223
3356
  uniform sampler2D uPalette;
3224
3357
  uniform float uPaletteSize;
3225
3358
  uniform float uPointSize;
3359
+ uniform float uPointStrokeScale;
3226
3360
  out vec4 outColor;
3227
3361
  void main() {
3228
3362
  vec2 pc = gl_PointCoord * 2.0 - 1.0;
@@ -3234,7 +3368,8 @@ class qi {
3234
3368
  vec4 color = texture(uPalette, uv);
3235
3369
  if (color.a <= 0.0) discard;
3236
3370
 
3237
- float ringWidth = clamp(3.0 / max(1.0, uPointSize), 0.12, 0.62);
3371
+ float s = uPointStrokeScale;
3372
+ float ringWidth = clamp(3.0 * s / max(1.0, uPointSize), 0.12 * s, 0.62 * s);
3238
3373
  float innerRadius = 1.0 - ringWidth;
3239
3374
  float aa = 1.5 / max(1.0, uPointSize);
3240
3375
 
@@ -3244,18 +3379,18 @@ class qi {
3244
3379
  if (alpha <= 0.001) discard;
3245
3380
 
3246
3381
  outColor = vec4(color.rgb * alpha, alpha);
3247
- }`), o = Zt(t, i, "uCamera"), s = Zt(t, i, "uPointSize"), a = Zt(t, i, "uPalette"), u = Zt(t, i, "uPaletteSize"), c = t.createVertexArray(), h = t.createBuffer(), g = t.createBuffer(), d = t.createBuffer(), p = t.createTexture();
3248
- if (!c || !h || !g || !d || !p)
3382
+ }`), o = qt(t, i, "uCamera"), s = qt(t, i, "uPointSize"), a = qt(t, i, "uPointStrokeScale"), c = qt(t, i, "uPalette"), h = qt(t, i, "uPaletteSize"), l = t.createVertexArray(), m = t.createBuffer(), d = t.createBuffer(), w = t.createBuffer(), S = t.createTexture();
3383
+ if (!l || !m || !d || !w || !S)
3249
3384
  throw new Error("point buffer allocation failed");
3250
- t.bindVertexArray(c), t.bindBuffer(t.ARRAY_BUFFER, h), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
3385
+ t.bindVertexArray(l), t.bindBuffer(t.ARRAY_BUFFER, m), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
3251
3386
  const x = t.getAttribLocation(i, "aPosition");
3252
3387
  if (x < 0)
3253
3388
  throw new Error("point position attribute not found");
3254
- t.enableVertexAttribArray(x), t.vertexAttribPointer(x, 2, t.FLOAT, !1, 0, 0), t.bindBuffer(t.ARRAY_BUFFER, g), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
3255
- const S = t.getAttribLocation(i, "aTerm");
3256
- if (S < 0)
3389
+ t.enableVertexAttribArray(x), t.vertexAttribPointer(x, 2, t.FLOAT, !1, 0, 0), t.bindBuffer(t.ARRAY_BUFFER, d), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
3390
+ const T = t.getAttribLocation(i, "aTerm");
3391
+ if (T < 0)
3257
3392
  throw new Error("point term attribute not found");
3258
- return t.enableVertexAttribArray(S), t.vertexAttribIPointer(S, 1, t.UNSIGNED_SHORT, 0, 0), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, d), t.bufferData(t.ELEMENT_ARRAY_BUFFER, 0, t.DYNAMIC_DRAW), t.bindVertexArray(null), t.bindBuffer(t.ARRAY_BUFFER, null), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, null), t.bindTexture(t.TEXTURE_2D, p), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.NEAREST), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.NEAREST), t.texImage2D(
3393
+ return t.enableVertexAttribArray(T), t.vertexAttribIPointer(T, 1, t.UNSIGNED_SHORT, 0, 0), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, w), t.bufferData(t.ELEMENT_ARRAY_BUFFER, 0, t.DYNAMIC_DRAW), t.bindVertexArray(null), t.bindBuffer(t.ARRAY_BUFFER, null), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, null), t.bindTexture(t.TEXTURE_2D, S), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.NEAREST), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.NEAREST), t.texImage2D(
3259
3394
  t.TEXTURE_2D,
3260
3395
  0,
3261
3396
  t.RGBA,
@@ -3267,15 +3402,16 @@ class qi {
3267
3402
  new Uint8Array([160, 160, 160, 255])
3268
3403
  ), t.bindTexture(t.TEXTURE_2D, null), {
3269
3404
  program: i,
3270
- vao: c,
3271
- posBuffer: h,
3272
- termBuffer: g,
3273
- indexBuffer: d,
3274
- paletteTexture: p,
3405
+ vao: l,
3406
+ posBuffer: m,
3407
+ termBuffer: d,
3408
+ indexBuffer: w,
3409
+ paletteTexture: S,
3275
3410
  uCamera: o,
3276
3411
  uPointSize: s,
3277
- uPalette: a,
3278
- uPaletteSize: u
3412
+ uPointStrokeScale: a,
3413
+ uPalette: c,
3414
+ uPaletteSize: h
3279
3415
  };
3280
3416
  }
3281
3417
  handleTileLoaded(t, n) {
@@ -3302,15 +3438,15 @@ class qi {
3302
3438
  return r ? (n.bindTexture(n.TEXTURE_2D, r), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, 1), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, n.RGBA, n.UNSIGNED_BYTE, t), n.bindTexture(n.TEXTURE_2D, null), r) : null;
3303
3439
  }
3304
3440
  }
3305
- const Le = [], $i = [], Hi = {
3441
+ const We = [], ho = [], fo = {
3306
3442
  count: 0,
3307
3443
  positions: new Float32Array(0),
3308
3444
  paletteIndices: new Uint16Array(0)
3309
- }, Zi = 0.65, Ki = 4, ji = 24, Ji = 1024, Qi = 4;
3310
- function to(e) {
3445
+ }, mo = 0.65, go = 4, po = 24, bo = 1024, wo = 4;
3446
+ function yo(e) {
3311
3447
  return Math.max(0, Math.min(Math.floor(e.count ?? 0), Math.floor((e.positions?.length ?? 0) / 2), e.paletteIndices?.length ?? 0));
3312
3448
  }
3313
- function eo(e, t) {
3449
+ function So(e, t) {
3314
3450
  if (!(e instanceof Uint32Array) || t <= 0 || e.length === 0)
3315
3451
  return null;
3316
3452
  let n = !1;
@@ -3329,69 +3465,74 @@ function eo(e, t) {
3329
3465
  }
3330
3466
  return r.subarray(0, i);
3331
3467
  }
3332
- function no(e, t) {
3468
+ function xo(e, t) {
3333
3469
  if (!e || t <= 0) return 256;
3334
- const n = Math.max(1, e.width * e.height), i = Math.sqrt(n / Math.max(1, t)) * Qi;
3335
- return Math.max(ji, Math.min(Ji, i));
3470
+ const n = Math.max(1, e.width * e.height), i = Math.sqrt(n / Math.max(1, t)) * wo;
3471
+ return Math.max(po, Math.min(bo, i));
3336
3472
  }
3337
- function ro(e, t) {
3473
+ function To(e, t) {
3338
3474
  if (!e || !e.positions || !e.paletteIndices)
3339
3475
  return null;
3340
- const n = to(e);
3476
+ const n = yo(e);
3341
3477
  if (n <= 0)
3342
3478
  return null;
3343
- const r = e.positions.subarray(0, n * 2), i = e.ids instanceof Uint32Array && e.ids.length >= n ? e.ids.subarray(0, n) : null, o = eo(e.drawIndices, n), s = o ? o.length : n;
3479
+ const r = e.positions.subarray(0, n * 2), i = e.ids instanceof Uint32Array && e.ids.length >= n ? e.ids.subarray(0, n) : null, o = So(e.drawIndices, n), s = o ? o.length : n;
3344
3480
  if (s === 0)
3345
3481
  return null;
3346
- const a = no(t, s), u = /* @__PURE__ */ new Map(), c = (h) => {
3347
- const g = r[h * 2], d = r[h * 2 + 1];
3348
- if (!Number.isFinite(g) || !Number.isFinite(d)) return;
3349
- const p = Math.floor(g / a), x = Math.floor(d / a);
3350
- let S = u.get(p);
3351
- S || (S = /* @__PURE__ */ new Map(), u.set(p, S));
3352
- const P = S.get(x);
3353
- P ? P.push(h) : S.set(x, [h]);
3482
+ const a = xo(t, s), c = /* @__PURE__ */ new Map(), h = (l) => {
3483
+ const m = r[l * 2], d = r[l * 2 + 1];
3484
+ if (!Number.isFinite(m) || !Number.isFinite(d)) return;
3485
+ const w = Math.floor(m / a), S = Math.floor(d / a);
3486
+ let x = c.get(w);
3487
+ x || (x = /* @__PURE__ */ new Map(), c.set(w, x));
3488
+ const T = x.get(S);
3489
+ T ? T.push(l) : x.set(S, [l]);
3354
3490
  };
3355
3491
  if (o)
3356
- for (let h = 0; h < o.length; h += 1)
3357
- c(o[h] ?? 0);
3492
+ for (let l = 0; l < o.length; l += 1)
3493
+ h(o[l] ?? 0);
3358
3494
  else
3359
- for (let h = 0; h < n; h += 1)
3360
- c(h);
3361
- return u.size === 0 ? null : {
3495
+ for (let l = 0; l < n; l += 1)
3496
+ h(l);
3497
+ return c.size === 0 ? null : {
3362
3498
  cellSize: a,
3363
3499
  safeCount: n,
3364
3500
  positions: r,
3365
3501
  ids: i,
3366
- buckets: u
3502
+ buckets: c
3367
3503
  };
3368
3504
  }
3369
- function Ge(e, t) {
3505
+ function Je(e, t) {
3370
3506
  return e.id ?? t;
3371
3507
  }
3372
- function io(e, t) {
3373
- if (!Array.isArray(t) || t.length < 3) return !1;
3374
- const [n, r] = e;
3375
- let i = !1;
3376
- for (let o = 0, s = t.length - 1; o < t.length; s = o++) {
3377
- const [a, u] = t[o], [c, h] = t[s];
3378
- u > r != h > r && n < (c - a) * (r - u) / Math.max(1e-12, h - u) + a && (i = !i);
3508
+ function Mo(e) {
3509
+ const t = [];
3510
+ for (let n = 0; n < e.length; n += 1) {
3511
+ const r = e[n], i = le([r?.coordinates]);
3512
+ i.length !== 0 && t.push({
3513
+ region: r,
3514
+ regionIndex: n,
3515
+ regionId: Je(r, n),
3516
+ polygons: i
3517
+ });
3379
3518
  }
3380
- return i;
3519
+ return t;
3381
3520
  }
3382
- function De(e, t) {
3383
- for (let n = t.length - 1; n >= 0; n -= 1) {
3384
- const r = t[n];
3385
- if (r?.coordinates?.length && io(e, r.coordinates))
3386
- return {
3387
- region: r,
3388
- regionIndex: n,
3389
- regionId: Ge(r, n)
3390
- };
3521
+ function Oe(e, t) {
3522
+ const n = e[0], r = e[1];
3523
+ for (let i = t.length - 1; i >= 0; i -= 1) {
3524
+ const o = t[i];
3525
+ for (const s of o.polygons)
3526
+ if (je(n, r, s))
3527
+ return {
3528
+ region: o.region,
3529
+ regionIndex: o.regionIndex,
3530
+ regionId: o.regionId
3531
+ };
3391
3532
  }
3392
3533
  return null;
3393
3534
  }
3394
- function yo({
3535
+ function Do({
3395
3536
  source: e,
3396
3537
  viewState: t,
3397
3538
  onViewStateChange: n,
@@ -3400,49 +3541,50 @@ function yo({
3400
3541
  onContextLost: o,
3401
3542
  onContextRestored: s,
3402
3543
  debugOverlay: a = !1,
3403
- debugOverlayStyle: u,
3404
- fitNonce: c = 0,
3405
- rotationResetNonce: h = 0,
3406
- authToken: g = "",
3544
+ debugOverlayStyle: c,
3545
+ fitNonce: h = 0,
3546
+ rotationResetNonce: l = 0,
3547
+ authToken: m = "",
3407
3548
  ctrlDragRotate: d = !0,
3408
- pointData: p = null,
3409
- pointPalette: x = null,
3410
- pointSizeByZoom: S,
3411
- roiRegions: P,
3412
- roiPolygons: k,
3413
- clipPointsToRois: C = !1,
3414
- clipMode: E = "worker",
3415
- onClipStats: D,
3416
- onRoiPointGroups: J,
3417
- roiPaletteIndexToTermId: ft,
3418
- interactionLock: at = !1,
3419
- drawTool: $ = "cursor",
3420
- stampOptions: ht,
3421
- brushOptions: vt,
3422
- regionStrokeStyle: Ot,
3423
- regionStrokeHoverStyle: K,
3424
- regionStrokeActiveStyle: Ct,
3425
- patchStrokeStyle: zt,
3426
- resolveRegionStrokeStyle: Kt,
3427
- overlayShapes: dt,
3428
- customLayers: Q,
3429
- patchRegions: M,
3430
- regionLabelStyle: I,
3431
- onPointerWorldMove: A,
3432
- onPointHover: L,
3433
- onPointClick: Z,
3434
- onRegionHover: et,
3435
- onRegionClick: mt,
3436
- onActiveRegionChange: yt,
3437
- getCellByCoordinatesRef: U,
3438
- onDrawComplete: At,
3439
- onPatchComplete: gt,
3440
- showOverviewMap: N = !1,
3441
- overviewMapOptions: G,
3442
- className: ut,
3443
- style: nt
3549
+ pointData: w = null,
3550
+ pointPalette: S = null,
3551
+ pointSizeByZoom: x,
3552
+ pointStrokeScale: T,
3553
+ roiRegions: L,
3554
+ roiPolygons: v,
3555
+ clipPointsToRois: P = !1,
3556
+ clipMode: F = "worker",
3557
+ onClipStats: H,
3558
+ onRoiPointGroups: dt,
3559
+ roiPaletteIndexToTermId: wt,
3560
+ interactionLock: mt = !1,
3561
+ drawTool: X = "cursor",
3562
+ stampOptions: Nt,
3563
+ brushOptions: zt,
3564
+ regionStrokeStyle: Z,
3565
+ regionStrokeHoverStyle: vt,
3566
+ regionStrokeActiveStyle: Lt,
3567
+ patchStrokeStyle: jt,
3568
+ resolveRegionStrokeStyle: pt,
3569
+ overlayShapes: nt,
3570
+ customLayers: A,
3571
+ patchRegions: E,
3572
+ regionLabelStyle: C,
3573
+ onPointerWorldMove: W,
3574
+ onPointHover: z,
3575
+ onPointClick: ot,
3576
+ onRegionHover: rt,
3577
+ onRegionClick: St,
3578
+ onActiveRegionChange: ht,
3579
+ getCellByCoordinatesRef: st,
3580
+ onDrawComplete: O,
3581
+ onPatchComplete: Q,
3582
+ showOverviewMap: K = !1,
3583
+ overviewMapOptions: N,
3584
+ className: it,
3585
+ style: at
3444
3586
  }) {
3445
- const rt = j(null), q = j(null), It = j(null), _t = j(null), F = j(n), ct = j(r), ot = j(a), [Gt, Bt] = Jt(!0), [Ft, qt] = Jt(null), [pt, ue] = Jt(null), [ce, l] = Jt(null), [f, w] = Jt(null), y = j(null), R = j(null), v = j(null), Y = j(0), V = P ?? Le, W = M ?? Le, lt = k ?? $i, Pt = (Q?.length ?? 0) > 0, $t = tt(() => ({ position: "relative", width: "100%", height: "100%", ...nt }), [nt]), xt = tt(
3587
+ const ut = j(null), J = j(null), Ct = j(null), Pt = j(null), It = j(n), _ = j(r), gt = j(a), [Rt, _t] = te(!0), [re, Bt] = te(null), [xt, _e] = te(null), [ie, he] = te(null), [u, f] = te(null), p = j(null), y = j(null), R = j(null), U = j(0), Y = L ?? We, $ = E ?? We, V = v ?? ho, ft = (A?.length ?? 0) > 0, kt = q(() => ({ position: "relative", width: "100%", height: "100%", ...at }), [at]), Xt = q(
3446
3588
  () => ({
3447
3589
  position: "absolute",
3448
3590
  top: 8,
@@ -3461,272 +3603,275 @@ function yo({
3461
3603
  border: "1px solid rgba(173, 216, 255, 0.28)",
3462
3604
  borderRadius: 8,
3463
3605
  boxShadow: "0 8px 22px rgba(0,0,0,0.35)",
3464
- ...u
3606
+ ...c
3465
3607
  }),
3466
- [u]
3467
- ), H = tt(() => V.length > 0 ? V : lt.length === 0 ? Le : lt.map((m, T) => ({
3468
- id: T,
3469
- coordinates: m
3470
- })), [V, lt]), St = tt(() => H.map((m) => m.coordinates), [H]), [Tt, le] = Jt(p);
3471
- X(() => {
3472
- const m = ++Y.current;
3473
- let T = !1;
3474
- if (!C)
3475
- return le(p), () => {
3476
- T = !0;
3608
+ [c]
3609
+ ), tt = q(() => Y.length > 0 ? Y : V.length === 0 ? We : V.map((g, M) => ({
3610
+ id: M,
3611
+ coordinates: g
3612
+ })), [Y, V]), ct = q(() => Mo(tt), [tt]), yt = q(
3613
+ () => tt.map((g) => g.coordinates),
3614
+ [tt]
3615
+ ), [bt, fe] = te(w);
3616
+ k(() => {
3617
+ const g = ++U.current;
3618
+ let M = !1;
3619
+ if (!P)
3620
+ return fe(w), () => {
3621
+ M = !0;
3477
3622
  };
3478
- if (!p || !p.count || !p.positions || !p.paletteIndices)
3479
- return le(null), () => {
3480
- T = !0;
3623
+ if (!w || !w.count || !w.positions || !w.paletteIndices)
3624
+ return fe(null), () => {
3625
+ M = !0;
3481
3626
  };
3482
- if (St.length === 0)
3483
- return le(Hi), D?.({
3484
- mode: E,
3627
+ if (yt.length === 0)
3628
+ return fe(fo), H?.({
3629
+ mode: F,
3485
3630
  durationMs: 0,
3486
- inputCount: p.count,
3631
+ inputCount: w.count,
3487
3632
  outputCount: 0,
3488
3633
  polygonCount: 0
3489
3634
  }), () => {
3490
- T = !0;
3635
+ M = !0;
3491
3636
  };
3492
- const _ = (z, st) => {
3493
- if (T || m !== Y.current) return;
3494
- const de = z?.drawIndices ? z.drawIndices.length : z?.count ?? 0;
3495
- le(z), D?.({
3496
- mode: st.mode,
3497
- durationMs: st.durationMs,
3498
- inputCount: p.count,
3499
- outputCount: de,
3500
- polygonCount: St.length,
3501
- usedWebGpu: st.usedWebGpu,
3502
- candidateCount: st.candidateCount,
3503
- bridgedToDraw: st.bridgedToDraw
3637
+ const I = (D, lt) => {
3638
+ if (M || g !== U.current) return;
3639
+ const ge = D?.drawIndices ? D.drawIndices.length : D?.count ?? 0;
3640
+ fe(D), H?.({
3641
+ mode: lt.mode,
3642
+ durationMs: lt.durationMs,
3643
+ inputCount: w.count,
3644
+ outputCount: ge,
3645
+ polygonCount: yt.length,
3646
+ usedWebGpu: lt.usedWebGpu,
3647
+ candidateCount: lt.candidateCount,
3648
+ bridgedToDraw: lt.bridgedToDraw
3504
3649
  });
3505
3650
  };
3506
3651
  return (async () => {
3507
- if (E === "sync") {
3508
- const z = performance.now(), st = Ee(p, St);
3509
- _(st, {
3652
+ if (F === "sync") {
3653
+ const D = performance.now(), lt = Ie(w, yt);
3654
+ I(lt, {
3510
3655
  mode: "sync",
3511
- durationMs: performance.now() - z
3656
+ durationMs: performance.now() - D
3512
3657
  });
3513
3658
  return;
3514
3659
  }
3515
- if (E === "hybrid-webgpu") {
3516
- const z = await Bi(p, St, { bridgeToDraw: !0 });
3517
- _(z.data, {
3518
- mode: z.meta.mode,
3519
- durationMs: z.meta.durationMs,
3520
- usedWebGpu: z.meta.usedWebGpu,
3521
- candidateCount: z.meta.candidateCount,
3522
- bridgedToDraw: z.meta.bridgedToDraw
3660
+ if (F === "hybrid-webgpu") {
3661
+ const D = await Ji(w, yt, { bridgeToDraw: !0 });
3662
+ I(D.data, {
3663
+ mode: D.meta.mode,
3664
+ durationMs: D.meta.durationMs,
3665
+ usedWebGpu: D.meta.usedWebGpu,
3666
+ candidateCount: D.meta.candidateCount,
3667
+ bridgedToDraw: D.meta.bridgedToDraw
3523
3668
  });
3524
3669
  return;
3525
3670
  }
3526
3671
  try {
3527
- const z = await Fi(p, St);
3528
- _(z.data, {
3529
- mode: z.meta.mode,
3530
- durationMs: z.meta.durationMs
3672
+ const D = await ji(w, yt);
3673
+ I(D.data, {
3674
+ mode: D.meta.mode,
3675
+ durationMs: D.meta.durationMs
3531
3676
  });
3532
3677
  } catch {
3533
- const z = performance.now(), st = Ee(p, St);
3534
- _(st, {
3678
+ const D = performance.now(), lt = Ie(w, yt);
3679
+ I(lt, {
3535
3680
  mode: "sync",
3536
- durationMs: performance.now() - z
3681
+ durationMs: performance.now() - D
3537
3682
  });
3538
3683
  }
3539
3684
  })(), () => {
3540
- T = !0;
3685
+ M = !0;
3541
3686
  };
3542
- }, [C, E, p, St, D]);
3543
- const He = !!(L || Z || U), Mt = tt(() => He ? ro(Tt, e) : null, [He, Tt, e]), Ht = B(
3544
- (m) => {
3545
- const T = q.current;
3546
- if (!T || !Mt) return null;
3547
- const _ = Number(m[0]), O = Number(m[1]);
3548
- if (!Number.isFinite(_) || !Number.isFinite(O)) return null;
3549
- const z = Math.max(1e-6, T.getViewState().zoom), st = T.getPointSizeByZoom(), re = Math.max(Ki, st * Zi) / z;
3550
- if (!Number.isFinite(re) || re <= 0) return null;
3551
- const Re = Mt.cellSize, nn = Math.floor(_ / Re), rn = Math.floor(O / Re), me = Math.max(1, Math.ceil(re / Re)), er = re * re;
3552
- let ge = -1, on = er, sn = 0, an = 0;
3553
- for (let ve = nn - me; ve <= nn + me; ve += 1) {
3554
- const un = Mt.buckets.get(ve);
3555
- if (un)
3556
- for (let Ce = rn - me; Ce <= rn + me; Ce += 1) {
3557
- const pe = un.get(Ce);
3558
- if (!(!pe || pe.length === 0))
3559
- for (let Ie = 0; Ie < pe.length; Ie += 1) {
3560
- const be = pe[Ie];
3561
- if (be >= Mt.safeCount) continue;
3562
- const cn = Mt.positions[be * 2], ln = Mt.positions[be * 2 + 1], hn = cn - _, fn = ln - O, dn = hn * hn + fn * fn;
3563
- dn > on || (on = dn, ge = be, sn = cn, an = ln);
3687
+ }, [P, F, w, yt, H]);
3688
+ const en = !!(z || ot || st), At = q(() => en ? To(bt, e) : null, [en, bt, e]), Kt = B(
3689
+ (g) => {
3690
+ const M = J.current;
3691
+ if (!M || !At) return null;
3692
+ const I = Number(g[0]), G = Number(g[1]);
3693
+ if (!Number.isFinite(I) || !Number.isFinite(G)) return null;
3694
+ const D = Math.max(1e-6, M.getViewState().zoom), lt = M.getPointSizeByZoom(), oe = Math.max(go, lt * mo) / D;
3695
+ if (!Number.isFinite(oe) || oe <= 0) return null;
3696
+ const Be = At.cellSize, ln = Math.floor(I / Be), hn = Math.floor(G / Be), pe = Math.max(1, Math.ceil(oe / Be)), fr = oe * oe;
3697
+ let be = -1, fn = fr, dn = 0, mn = 0;
3698
+ for (let Ue = ln - pe; Ue <= ln + pe; Ue += 1) {
3699
+ const gn = At.buckets.get(Ue);
3700
+ if (gn)
3701
+ for (let Fe = hn - pe; Fe <= hn + pe; Fe += 1) {
3702
+ const we = gn.get(Fe);
3703
+ if (!(!we || we.length === 0))
3704
+ for (let ze = 0; ze < we.length; ze += 1) {
3705
+ const ye = we[ze];
3706
+ if (ye >= At.safeCount) continue;
3707
+ const pn = At.positions[ye * 2], bn = At.positions[ye * 2 + 1], wn = pn - I, yn = bn - G, Sn = wn * wn + yn * yn;
3708
+ Sn > fn || (fn = Sn, be = ye, dn = pn, mn = bn);
3564
3709
  }
3565
3710
  }
3566
3711
  }
3567
- if (ge < 0) return null;
3568
- const nr = Mt.ids ? Number(Mt.ids[ge]) : null;
3712
+ if (be < 0) return null;
3713
+ const dr = At.ids ? Number(At.ids[be]) : null;
3569
3714
  return {
3570
- index: ge,
3571
- id: nr,
3572
- coordinate: [_, O],
3573
- pointCoordinate: [sn, an]
3715
+ index: be,
3716
+ id: dr,
3717
+ coordinate: [I, G],
3718
+ pointCoordinate: [dn, mn]
3574
3719
  };
3575
3720
  },
3576
- [Mt]
3577
- ), jt = B(
3578
- (m, T) => {
3579
- if (!L) return;
3580
- const _ = m?.index ?? null, O = m?.id ?? null;
3581
- R.current === _ && v.current === O || (R.current = _, v.current = O, L({
3582
- index: _,
3583
- id: O,
3584
- coordinate: T,
3585
- pointCoordinate: m?.pointCoordinate ?? null
3721
+ [At]
3722
+ ), Qt = B(
3723
+ (g, M) => {
3724
+ if (!z) return;
3725
+ const I = g?.index ?? null, G = g?.id ?? null;
3726
+ y.current === I && R.current === G || (y.current = I, R.current = G, z({
3727
+ index: I,
3728
+ id: G,
3729
+ coordinate: M,
3730
+ pointCoordinate: g?.pointCoordinate ?? null
3586
3731
  }));
3587
3732
  },
3588
- [L]
3589
- ), he = B(
3590
- (m, T) => {
3591
- if (!Z) return;
3592
- const _ = Ht(m);
3593
- _ && Z({
3594
- ..._,
3595
- button: T
3733
+ [z]
3734
+ ), de = B(
3735
+ (g, M) => {
3736
+ if (!ot) return;
3737
+ const I = Kt(g);
3738
+ I && ot({
3739
+ ...I,
3740
+ button: M
3596
3741
  });
3597
3742
  },
3598
- [Z, Ht]
3743
+ [ot, Kt]
3599
3744
  );
3600
- tt(() => {
3601
- const m = Number(G?.width ?? 220);
3602
- return Number.isFinite(m) ? Math.max(64, m) : 220;
3603
- }, [G?.width]);
3604
- const Ze = tt(() => {
3605
- const m = Number(G?.height ?? 140);
3606
- return Number.isFinite(m) ? Math.max(48, m) : 140;
3607
- }, [G?.height]), Dt = tt(() => {
3608
- const m = Number(G?.margin ?? 16);
3609
- return Number.isFinite(m) ? Math.max(0, m) : 16;
3610
- }, [G?.margin]), fe = G?.position || "bottom-right";
3611
- X(() => {
3612
- if (U)
3613
- return U.current = Ht, () => {
3614
- U.current === Ht && (U.current = null);
3745
+ q(() => {
3746
+ const g = Number(N?.width ?? 220);
3747
+ return Number.isFinite(g) ? Math.max(64, g) : 220;
3748
+ }, [N?.width]);
3749
+ const nn = q(() => {
3750
+ const g = Number(N?.height ?? 140);
3751
+ return Number.isFinite(g) ? Math.max(48, g) : 140;
3752
+ }, [N?.height]), Yt = q(() => {
3753
+ const g = Number(N?.margin ?? 16);
3754
+ return Number.isFinite(g) ? Math.max(0, g) : 16;
3755
+ }, [N?.margin]), me = N?.position || "bottom-right";
3756
+ k(() => {
3757
+ if (st)
3758
+ return st.current = Kt, () => {
3759
+ st.current === Kt && (st.current = null);
3615
3760
  };
3616
- }, [U, Ht]);
3617
- const Nt = B(
3618
- (m) => {
3619
- ue((T) => String(T) === String(m) ? T : (yt?.(m), m));
3761
+ }, [st, Kt]);
3762
+ const Wt = B(
3763
+ (g) => {
3764
+ _e((M) => String(M) === String(g) ? M : (ht?.(g), g));
3620
3765
  },
3621
- [yt]
3766
+ [ht]
3622
3767
  );
3623
- X(() => {
3624
- F.current = n;
3625
- }, [n]), X(() => {
3626
- ct.current = r;
3627
- }, [r]), X(() => {
3628
- ot.current = a, a || w(null);
3768
+ k(() => {
3769
+ It.current = n;
3770
+ }, [n]), k(() => {
3771
+ _.current = r;
3772
+ }, [r]), k(() => {
3773
+ gt.current = a, a || f(null);
3629
3774
  }, [a]);
3630
- const Ke = B((m) => {
3631
- ct.current?.(m), ot.current && w(m);
3632
- }, []), Zn = tt(() => f ? [
3633
- `tier ${f.tier} | frame ${f.frameMs?.toFixed(2) ?? "-"} ms | drawCalls ${f.drawCalls ?? "-"}`,
3634
- `tiles visible ${f.visible} | rendered ${f.rendered} | fallback ${f.fallback}`,
3635
- `cache size ${f.cache} | hit ${f.cacheHits ?? "-"} | miss ${f.cacheMisses ?? "-"}`,
3636
- `queue inflight ${f.inflight} | queued ${f.queued ?? "-"} | retries ${f.retries ?? "-"} | failed ${f.failed ?? "-"} | aborted ${f.aborted ?? "-"}`,
3637
- `points ${f.points}`
3775
+ const rn = B((g) => {
3776
+ _.current?.(g), gt.current && f(g);
3777
+ }, []), sr = q(() => u ? [
3778
+ `tier ${u.tier} | frame ${u.frameMs?.toFixed(2) ?? "-"} ms | drawCalls ${u.drawCalls ?? "-"}`,
3779
+ `tiles visible ${u.visible} | rendered ${u.rendered} | fallback ${u.fallback}`,
3780
+ `cache size ${u.cache} | hit ${u.cacheHits ?? "-"} | miss ${u.cacheMisses ?? "-"}`,
3781
+ `queue inflight ${u.inflight} | queued ${u.queued ?? "-"} | retries ${u.retries ?? "-"} | failed ${u.failed ?? "-"} | aborted ${u.aborted ?? "-"}`,
3782
+ `points ${u.points}`
3638
3783
  ].join(`
3639
- `) : "stats: waiting for first frame...", [f]);
3640
- X(() => {
3641
- !(pt === null ? !0 : H.some((O, z) => String(Ge(O, z)) === String(pt))) && pt !== null && Nt(null);
3642
- const T = y.current;
3643
- !(T === null ? !0 : H.some((O, z) => String(Ge(O, z)) === String(T))) && T !== null && (y.current = null, qt(null), et?.({
3784
+ `) : "stats: waiting for first frame...", [u]);
3785
+ k(() => {
3786
+ !(xt === null ? !0 : tt.some((G, D) => String(Je(G, D)) === String(xt))) && xt !== null && Wt(null);
3787
+ const M = p.current;
3788
+ !(M === null ? !0 : tt.some((G, D) => String(Je(G, D)) === String(M))) && M !== null && (p.current = null, Bt(null), rt?.({
3644
3789
  region: null,
3645
3790
  regionId: null,
3646
3791
  regionIndex: -1,
3647
3792
  coordinate: null
3648
3793
  }));
3649
- }, [H, pt, et, Nt]), X(() => {
3650
- const m = R.current;
3651
- m !== null && (Mt && m < Mt.safeCount || (R.current = null, v.current = null, L?.({
3794
+ }, [tt, xt, rt, Wt]), k(() => {
3795
+ const g = y.current;
3796
+ g !== null && (At && g < At.safeCount || (y.current = null, R.current = null, z?.({
3652
3797
  index: null,
3653
3798
  id: null,
3654
3799
  coordinate: null,
3655
3800
  pointCoordinate: null
3656
3801
  })));
3657
- }, [Mt, L]);
3658
- const je = B(
3659
- (m) => {
3660
- Pt && l(m);
3661
- const T = F.current;
3662
- T && T(m), It.current?.(), _t.current?.();
3802
+ }, [At, z]);
3803
+ const on = B(
3804
+ (g) => {
3805
+ ft && he(g);
3806
+ const M = It.current;
3807
+ M && M(g), Ct.current?.(), Pt.current?.();
3663
3808
  },
3664
- [Pt]
3809
+ [ft]
3665
3810
  );
3666
- X(() => {
3667
- if (!N) {
3668
- Bt(!1);
3811
+ k(() => {
3812
+ if (!K) {
3813
+ _t(!1);
3669
3814
  return;
3670
3815
  }
3671
- Bt(!0);
3672
- }, [N, e?.id]), X(() => {
3673
- $ !== "cursor" && y.current !== null && (y.current = null, qt(null), et?.({
3816
+ _t(!0);
3817
+ }, [K, e?.id]), k(() => {
3818
+ X !== "cursor" && p.current !== null && (p.current = null, Bt(null), rt?.({
3674
3819
  region: null,
3675
3820
  regionId: null,
3676
3821
  regionIndex: -1,
3677
3822
  coordinate: null
3678
3823
  }));
3679
- }, [$, et]), X(() => {
3680
- $ !== "cursor" && R.current !== null && (R.current = null, v.current = null, L?.({
3824
+ }, [X, rt]), k(() => {
3825
+ X !== "cursor" && y.current !== null && (y.current = null, R.current = null, z?.({
3681
3826
  index: null,
3682
3827
  id: null,
3683
3828
  coordinate: null,
3684
3829
  pointCoordinate: null
3685
3830
  }));
3686
- }, [$, L]);
3687
- const kt = B((m, T) => {
3688
- const _ = q.current;
3689
- if (!_) return null;
3690
- const O = _.screenToWorld(m, T);
3691
- if (!Array.isArray(O) || O.length < 2) return null;
3692
- const z = Number(O[0]), st = Number(O[1]);
3693
- return !Number.isFinite(z) || !Number.isFinite(st) ? null : [z, st];
3694
- }, []), Je = B((m, T) => {
3695
- const _ = q.current;
3696
- if (!_) return null;
3697
- const O = _.worldToScreen(m, T);
3698
- if (!Array.isArray(O) || O.length < 2) return null;
3699
- const z = Number(O[0]), st = Number(O[1]);
3700
- return !Number.isFinite(z) || !Number.isFinite(st) ? null : [z, st];
3701
- }, []), Qe = B(() => {
3702
- q.current?.requestRender(), It.current?.(), _t.current?.();
3703
- }, []), tn = tt(() => ce ?? q.current?.getViewState() ?? null, [ce]), en = tt(() => {
3831
+ }, [X, z]);
3832
+ const Ot = B((g, M) => {
3833
+ const I = J.current;
3834
+ if (!I) return null;
3835
+ const G = I.screenToWorld(g, M);
3836
+ if (!Array.isArray(G) || G.length < 2) return null;
3837
+ const D = Number(G[0]), lt = Number(G[1]);
3838
+ return !Number.isFinite(D) || !Number.isFinite(lt) ? null : [D, lt];
3839
+ }, []), sn = B((g, M) => {
3840
+ const I = J.current;
3841
+ if (!I) return null;
3842
+ const G = I.worldToScreen(g, M);
3843
+ if (!Array.isArray(G) || G.length < 2) return null;
3844
+ const D = Number(G[0]), lt = Number(G[1]);
3845
+ return !Number.isFinite(D) || !Number.isFinite(lt) ? null : [D, lt];
3846
+ }, []), an = B(() => {
3847
+ J.current?.requestRender(), Ct.current?.(), Pt.current?.();
3848
+ }, []), un = q(() => ie ?? J.current?.getViewState() ?? null, [ie]), cn = q(() => {
3704
3849
  if (!e) return null;
3705
- const m = tn;
3706
- return m ? {
3850
+ const g = un;
3851
+ return g ? {
3707
3852
  source: e,
3708
- viewState: m,
3709
- drawTool: $,
3710
- interactionLock: at,
3711
- worldToScreen: Je,
3712
- screenToWorld: kt,
3713
- requestRedraw: Qe
3853
+ viewState: g,
3854
+ drawTool: X,
3855
+ interactionLock: mt,
3856
+ worldToScreen: sn,
3857
+ screenToWorld: Ot,
3858
+ requestRedraw: an
3714
3859
  } : null;
3715
- }, [e, tn, $, at, Je, kt, Qe]), Kn = B(
3716
- (m) => {
3717
- const T = m.target === rt.current, _ = kt(m.clientX, m.clientY);
3718
- if (A) {
3719
- const de = !!_ && _[0] >= 0 && _[1] >= 0 && !!e && _[0] <= e.width && _[1] <= e.height;
3720
- A({
3721
- coordinate: _,
3722
- clientX: m.clientX,
3723
- clientY: m.clientY,
3724
- insideImage: de
3860
+ }, [e, un, X, mt, sn, Ot, an]), ar = B(
3861
+ (g) => {
3862
+ const M = g.target === ut.current, I = Ot(g.clientX, g.clientY);
3863
+ if (W) {
3864
+ const ge = !!I && I[0] >= 0 && I[1] >= 0 && !!e && I[0] <= e.width && I[1] <= e.height;
3865
+ W({
3866
+ coordinate: I,
3867
+ clientX: g.clientX,
3868
+ clientY: g.clientY,
3869
+ insideImage: ge
3725
3870
  });
3726
3871
  }
3727
- if ($ !== "cursor") return;
3728
- if (!T) {
3729
- jt(null, null), y.current !== null && (y.current = null, qt(null), et?.({
3872
+ if (X !== "cursor") return;
3873
+ if (!M) {
3874
+ Qt(null, null), p.current !== null && (p.current = null, Bt(null), rt?.({
3730
3875
  region: null,
3731
3876
  regionId: null,
3732
3877
  regionIndex: -1,
@@ -3734,128 +3879,132 @@ function yo({
3734
3879
  }));
3735
3880
  return;
3736
3881
  }
3737
- if (!_) {
3738
- jt(null, null);
3882
+ if (!I) {
3883
+ Qt(null, null);
3739
3884
  return;
3740
3885
  }
3741
- if (L && jt(Ht(_), _), !H.length) return;
3742
- const O = De(_, H), z = O?.regionId ?? null, st = y.current;
3743
- String(st) !== String(z) && (y.current = z, qt(z), et?.({
3744
- region: O?.region ?? null,
3745
- regionId: z,
3746
- regionIndex: O?.regionIndex ?? -1,
3747
- coordinate: _
3886
+ if (z && Qt(Kt(I), I), !ct.length) return;
3887
+ const G = Oe(I, ct), D = G?.regionId ?? null, lt = p.current;
3888
+ String(lt) !== String(D) && (p.current = D, Bt(D), rt?.({
3889
+ region: G?.region ?? null,
3890
+ regionId: D,
3891
+ regionIndex: G?.regionIndex ?? -1,
3892
+ coordinate: I
3748
3893
  }));
3749
3894
  },
3750
- [$, H, kt, et, A, e, jt, Ht, L]
3751
- ), jn = B(() => {
3752
- A?.({
3895
+ [X, ct, Ot, rt, W, e, Qt, Kt, z]
3896
+ ), ur = B(() => {
3897
+ W?.({
3753
3898
  coordinate: null,
3754
3899
  clientX: -1,
3755
3900
  clientY: -1,
3756
3901
  insideImage: !1
3757
- }), jt(null, null), y.current !== null && (y.current = null, qt(null), et?.({
3902
+ }), Qt(null, null), p.current !== null && (p.current = null, Bt(null), rt?.({
3758
3903
  region: null,
3759
3904
  regionId: null,
3760
3905
  regionIndex: -1,
3761
3906
  coordinate: null
3762
3907
  }));
3763
- }, [et, A, jt]), Jn = B(
3764
- (m) => {
3765
- if ($ !== "cursor" || m.target !== rt.current) return;
3766
- const T = kt(m.clientX, m.clientY);
3767
- if (!T) return;
3768
- if (he(T, m.button), !H.length) {
3769
- Nt(null);
3908
+ }, [rt, W, Qt]), cr = B(
3909
+ (g) => {
3910
+ if (X !== "cursor" || g.target !== ut.current) return;
3911
+ const M = Ot(g.clientX, g.clientY);
3912
+ if (!M) return;
3913
+ if (de(M, g.button), !ct.length) {
3914
+ Wt(null);
3770
3915
  return;
3771
3916
  }
3772
- const _ = De(T, H);
3773
- if (!_) {
3774
- Nt(null);
3917
+ const I = Oe(M, ct);
3918
+ if (!I) {
3919
+ Wt(null);
3775
3920
  return;
3776
3921
  }
3777
- const O = pt !== null && String(pt) === String(_.regionId) ? null : _.regionId;
3778
- Nt(O), mt?.({
3779
- region: _.region,
3780
- regionId: _.regionId,
3781
- regionIndex: _.regionIndex,
3782
- coordinate: T
3922
+ const G = xt !== null && String(xt) === String(I.regionId) ? null : I.regionId;
3923
+ Wt(G), St?.({
3924
+ region: I.region,
3925
+ regionId: I.regionId,
3926
+ regionIndex: I.regionIndex,
3927
+ coordinate: M
3783
3928
  });
3784
3929
  },
3785
- [$, H, kt, mt, pt, Nt, he]
3786
- ), Qn = B(
3787
- (m) => {
3788
- if ($ !== "brush" || vt?.clickSelectRoi !== !0 || !H.length) return !1;
3789
- const T = De(m, H);
3790
- if (!T) return !1;
3791
- const _ = pt !== null && String(pt) === String(T.regionId) ? null : T.regionId;
3792
- return Nt(_), mt?.({
3793
- region: T.region,
3794
- regionId: T.regionId,
3795
- regionIndex: T.regionIndex,
3796
- coordinate: m
3930
+ [X, ct, Ot, St, xt, Wt, de]
3931
+ ), lr = B(
3932
+ (g) => {
3933
+ if (X !== "brush" || zt?.clickSelectRoi !== !0 || !ct.length) return !1;
3934
+ const M = Oe(g, ct);
3935
+ if (!M) return !1;
3936
+ const I = xt !== null && String(xt) === String(M.regionId) ? null : M.regionId;
3937
+ return Wt(I), St?.({
3938
+ region: M.region,
3939
+ regionId: M.regionId,
3940
+ regionIndex: M.regionIndex,
3941
+ coordinate: g
3797
3942
  }), !0;
3798
3943
  },
3799
- [$, vt?.clickSelectRoi, H, pt, Nt, mt]
3800
- ), tr = B(
3801
- (m) => {
3802
- if (!Z || $ !== "cursor" || m.target !== rt.current) return;
3803
- m.preventDefault();
3804
- const T = kt(m.clientX, m.clientY);
3805
- T && he(T, m.button);
3944
+ [X, zt?.clickSelectRoi, ct, xt, Wt, St]
3945
+ ), hr = B(
3946
+ (g) => {
3947
+ if (!ot || X !== "cursor" || g.target !== ut.current) return;
3948
+ g.preventDefault();
3949
+ const M = Ot(g.clientX, g.clientY);
3950
+ M && de(M, g.button);
3806
3951
  },
3807
- [$, kt, he, Z]
3952
+ [X, Ot, de, ot]
3808
3953
  );
3809
- return X(() => {
3810
- const m = rt.current;
3811
- if (!m || !e)
3954
+ return k(() => {
3955
+ const g = ut.current;
3956
+ if (!g || !e)
3812
3957
  return;
3813
- const T = new qi(m, e, {
3814
- onViewStateChange: je,
3815
- onStats: Ke,
3958
+ const M = new lo(g, e, {
3959
+ onViewStateChange: on,
3960
+ onStats: rn,
3816
3961
  onTileError: i,
3817
3962
  onContextLost: o,
3818
3963
  onContextRestored: s,
3819
- authToken: g,
3964
+ authToken: m,
3820
3965
  ctrlDragRotate: d,
3821
- pointSizeByZoom: S
3966
+ pointSizeByZoom: x,
3967
+ pointStrokeScale: T
3822
3968
  });
3823
- return q.current = T, t && T.setViewState(t), T.setInteractionLock(at), Pt && l(T.getViewState()), () => {
3824
- T.destroy(), q.current = null;
3969
+ return J.current = M, t && M.setViewState(t), M.setInteractionLock(mt), ft && he(M.getViewState()), () => {
3970
+ M.destroy(), J.current = null;
3825
3971
  };
3826
- }, [e, Ke, i, o, s, g, d, S, je, Pt]), X(() => {
3827
- const m = q.current;
3828
- !m || !t || m.setViewState(t);
3829
- }, [t]), X(() => {
3830
- const m = q.current;
3831
- m && m.fitToImage();
3832
- }, [c]), X(() => {
3833
- const m = q.current;
3834
- m && m.resetRotation();
3835
- }, [h]), X(() => {
3836
- const m = q.current;
3837
- !m || !x || m.setPointPalette(x);
3838
- }, [x]), X(() => {
3839
- const m = q.current;
3840
- m && m.setPointSizeByZoom(S);
3841
- }, [S]), X(() => {
3842
- const m = q.current;
3843
- m && m.setPointData(Tt);
3844
- }, [Tt]), X(() => {
3845
- if (!J) return;
3846
- const T = ki(C ? Tt : p, H, {
3847
- paletteIndexToTermId: ft,
3972
+ }, [e, rn, i, o, s, m, d, x, T, on, ft]), k(() => {
3973
+ const g = J.current;
3974
+ !g || !t || g.setViewState(t);
3975
+ }, [t]), k(() => {
3976
+ const g = J.current;
3977
+ g && g.fitToImage();
3978
+ }, [h]), k(() => {
3979
+ const g = J.current;
3980
+ g && g.resetRotation();
3981
+ }, [l]), k(() => {
3982
+ const g = J.current;
3983
+ !g || !S || g.setPointPalette(S);
3984
+ }, [S]), k(() => {
3985
+ const g = J.current;
3986
+ g && g.setPointSizeByZoom(x);
3987
+ }, [x]), k(() => {
3988
+ const g = J.current;
3989
+ g && g.setPointStrokeScale(T);
3990
+ }, [T]), k(() => {
3991
+ const g = J.current;
3992
+ g && g.setPointData(bt);
3993
+ }, [bt]), k(() => {
3994
+ if (!dt) return;
3995
+ const M = eo(P ? bt : w, tt, {
3996
+ paletteIndexToTermId: wt,
3848
3997
  includeEmptyRegions: !0
3849
3998
  });
3850
- J(T);
3851
- }, [J, C, p, Tt, H, ft]), X(() => {
3852
- const m = q.current;
3853
- m && m.setInteractionLock(at);
3854
- }, [at]), /* @__PURE__ */ mn("div", { className: ut, style: $t, onPointerMove: Kn, onPointerLeave: jn, onClick: Jn, onContextMenu: tr, children: [
3999
+ dt(M);
4000
+ }, [dt, P, w, bt, tt, wt]), k(() => {
4001
+ const g = J.current;
4002
+ g && g.setInteractionLock(mt);
4003
+ }, [mt]), /* @__PURE__ */ xn("div", { className: it, style: kt, onPointerMove: ar, onPointerLeave: ur, onClick: cr, onContextMenu: hr, children: [
3855
4004
  /* @__PURE__ */ Ut(
3856
4005
  "canvas",
3857
4006
  {
3858
- ref: rt,
4007
+ ref: ut,
3859
4008
  className: "wsi-render-canvas",
3860
4009
  style: {
3861
4010
  position: "absolute",
@@ -3865,69 +4014,69 @@ function yo({
3865
4014
  height: "100%",
3866
4015
  display: "block",
3867
4016
  touchAction: "none",
3868
- cursor: $ === "cursor" && Ft !== null ? "pointer" : at ? "crosshair" : "grab"
4017
+ cursor: X === "cursor" && re !== null ? "pointer" : mt ? "crosshair" : "grab"
3869
4018
  }
3870
4019
  }
3871
4020
  ),
3872
- e && en && Array.isArray(Q) && Q.length > 0 ? Q.map((m, T) => /* @__PURE__ */ Ut(
4021
+ e && cn && Array.isArray(A) && A.length > 0 ? A.map((g, M) => /* @__PURE__ */ Ut(
3873
4022
  "div",
3874
4023
  {
3875
- className: m.className,
4024
+ className: g.className,
3876
4025
  style: {
3877
4026
  position: "absolute",
3878
4027
  inset: 0,
3879
- zIndex: m.zIndex ?? 3,
3880
- pointerEvents: m.pointerEvents ?? "none",
3881
- ...m.style
4028
+ zIndex: g.zIndex ?? 3,
4029
+ pointerEvents: g.pointerEvents ?? "none",
4030
+ ...g.style
3882
4031
  },
3883
- children: m.render(en)
4032
+ children: g.render(cn)
3884
4033
  },
3885
- m.id ?? T
4034
+ g.id ?? M
3886
4035
  )) : null,
3887
4036
  e ? /* @__PURE__ */ Ut(
3888
- gi,
4037
+ ki,
3889
4038
  {
3890
- tool: $,
3891
- enabled: $ !== "cursor",
4039
+ tool: X,
4040
+ enabled: X !== "cursor",
3892
4041
  imageWidth: e.width,
3893
4042
  imageHeight: e.height,
3894
4043
  imageMpp: e.mpp,
3895
4044
  imageZoom: e.maxTierZoom,
3896
- stampOptions: ht,
3897
- brushOptions: vt,
3898
- projectorRef: q,
3899
- onBrushTap: Qn,
4045
+ stampOptions: Nt,
4046
+ brushOptions: zt,
4047
+ projectorRef: J,
4048
+ onBrushTap: lr,
3900
4049
  viewStateSignal: t,
3901
- persistedRegions: H,
3902
- patchRegions: W,
3903
- regionStrokeStyle: Ot,
3904
- regionStrokeHoverStyle: K,
3905
- regionStrokeActiveStyle: Ct,
3906
- patchStrokeStyle: zt,
3907
- resolveRegionStrokeStyle: Kt,
3908
- overlayShapes: dt,
3909
- hoveredRegionId: Ft,
3910
- activeRegionId: pt,
3911
- regionLabelStyle: I,
3912
- invalidateRef: It,
3913
- onDrawComplete: At,
3914
- onPatchComplete: gt
4050
+ persistedRegions: tt,
4051
+ patchRegions: $,
4052
+ regionStrokeStyle: Z,
4053
+ regionStrokeHoverStyle: vt,
4054
+ regionStrokeActiveStyle: Lt,
4055
+ patchStrokeStyle: jt,
4056
+ resolveRegionStrokeStyle: pt,
4057
+ overlayShapes: nt,
4058
+ hoveredRegionId: re,
4059
+ activeRegionId: xt,
4060
+ regionLabelStyle: C,
4061
+ invalidateRef: Ct,
4062
+ onDrawComplete: O,
4063
+ onPatchComplete: Q
3915
4064
  }
3916
4065
  ) : null,
3917
- a ? /* @__PURE__ */ Ut("pre", { "data-open-plant-debug-overlay": !0, style: xt, children: Zn }) : null,
3918
- e && N ? Gt ? /* @__PURE__ */ mn(or, { children: [
3919
- /* @__PURE__ */ Ut(bi, { source: e, projectorRef: q, authToken: g, options: G, invalidateRef: _t }),
4066
+ a ? /* @__PURE__ */ Ut("pre", { "data-open-plant-debug-overlay": !0, style: Xt, children: sr }) : null,
4067
+ e && K ? Rt ? /* @__PURE__ */ xn(pr, { children: [
4068
+ /* @__PURE__ */ Ut(Yi, { source: e, projectorRef: J, authToken: m, options: N, invalidateRef: Pt }),
3920
4069
  /* @__PURE__ */ Ut(
3921
4070
  "button",
3922
4071
  {
3923
4072
  type: "button",
3924
4073
  "aria-label": "Hide overview map",
3925
- onClick: () => Bt(!1),
4074
+ onClick: () => _t(!1),
3926
4075
  style: {
3927
4076
  position: "absolute",
3928
4077
  zIndex: 6,
3929
- ...fe.includes("left") ? { left: Dt } : { right: Dt },
3930
- ...fe.includes("top") ? { top: Dt + Ze + 8 } : { bottom: Dt + Ze + 8 },
4078
+ ...me.includes("left") ? { left: Yt } : { right: Yt },
4079
+ ...me.includes("top") ? { top: Yt + nn + 8 } : { bottom: Yt + nn + 8 },
3931
4080
  width: 20,
3932
4081
  height: 20,
3933
4082
  borderRadius: 999,
@@ -3947,12 +4096,12 @@ function yo({
3947
4096
  {
3948
4097
  type: "button",
3949
4098
  "aria-label": "Show overview map",
3950
- onClick: () => Bt(!0),
4099
+ onClick: () => _t(!0),
3951
4100
  style: {
3952
4101
  position: "absolute",
3953
4102
  zIndex: 6,
3954
- ...fe.includes("left") ? { left: Dt } : { right: Dt },
3955
- ...fe.includes("top") ? { top: Dt } : { bottom: Dt },
4103
+ ...me.includes("left") ? { left: Yt } : { right: Yt },
4104
+ ...me.includes("top") ? { top: Yt } : { bottom: Yt },
3956
4105
  height: 24,
3957
4106
  minWidth: 40,
3958
4107
  borderRadius: 999,
@@ -3970,34 +4119,34 @@ function yo({
3970
4119
  ] });
3971
4120
  }
3972
4121
  export {
3973
- Un as DEFAULT_POINT_COLOR,
3974
- gi as DrawLayer,
3975
- hr as M1TileRenderer,
3976
- bi as OverviewMap,
3977
- Yi as TileScheduler,
3978
- go as TileViewerCanvas,
3979
- qi as WsiTileRenderer,
3980
- yo as WsiViewerCanvas,
3981
- fo as buildTermPalette,
3982
- co as calcScaleLength,
3983
- zn as calcScaleResolution,
3984
- it as clamp,
3985
- Rt as closeRing,
3986
- ki as computeRoiPointGroups,
3987
- Tn as createCircle,
3988
- Sn as createRectangle,
3989
- Ee as filterPointDataByPolygons,
3990
- Bi as filterPointDataByPolygonsHybrid,
3991
- Fi as filterPointDataByPolygonsInWorker,
3992
- xi as filterPointIndicesByPolygons,
3993
- wo as filterPointIndicesByPolygonsInWorker,
3994
- po as getWebGpuCapabilities,
3995
- Ur as hexToRgba,
3996
- lo as isSameViewState,
3997
- mo as normalizeImageInfo,
3998
- vi as prefilterPointsByBoundsWebGpu,
3999
- bo as terminateRoiClipWorker,
4000
- ho as toBearerToken,
4001
- Wn as toTileUrl
4122
+ Hn as DEFAULT_POINT_COLOR,
4123
+ ki as DrawLayer,
4124
+ Tr as M1TileRenderer,
4125
+ Yi as OverviewMap,
4126
+ ro as TileScheduler,
4127
+ Uo as TileViewerCanvas,
4128
+ lo as WsiTileRenderer,
4129
+ Do as WsiViewerCanvas,
4130
+ _o as buildTermPalette,
4131
+ vo as calcScaleLength,
4132
+ $n as calcScaleResolution,
4133
+ et as clamp,
4134
+ Ht as closeRing,
4135
+ eo as computeRoiPointGroups,
4136
+ _n as createCircle,
4137
+ In as createRectangle,
4138
+ Ie as filterPointDataByPolygons,
4139
+ Ji as filterPointDataByPolygonsHybrid,
4140
+ ji as filterPointDataByPolygonsInWorker,
4141
+ Wi as filterPointIndicesByPolygons,
4142
+ Lo as filterPointIndicesByPolygonsInWorker,
4143
+ Fo as getWebGpuCapabilities,
4144
+ Jr as hexToRgba,
4145
+ Co as isSameViewState,
4146
+ Bo as normalizeImageInfo,
4147
+ Ki as prefilterPointsByBoundsWebGpu,
4148
+ zo as terminateRoiClipWorker,
4149
+ Io as toBearerToken,
4150
+ er as toTileUrl
4002
4151
  };
4003
4152
  //# sourceMappingURL=index.js.map