open-plant 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- var Xe = Object.defineProperty;
2
- var Ve = (e, t, n) => t in e ? Xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var f = (e, t, n) => Ve(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as Et, jsxs as de, Fragment as Oe } from "react/jsx-runtime";
5
- import { useRef as $, useMemo as et, useCallback as D, useEffect as L, useState as Ft } from "react";
6
- function me(e, t, n) {
1
+ var an = Object.defineProperty;
2
+ var cn = (e, t, n) => t in e ? an(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var d = (e, t, n) => cn(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as Mt, jsxs as Ee, Fragment as un } from "react/jsx-runtime";
5
+ import { useRef as Z, useMemo as H, useCallback as D, useEffect as z, useState as Yt } from "react";
6
+ function Ae(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 me(e, t, n) {
13
13
  }
14
14
  return r;
15
15
  }
16
- function Ge(e, t, n) {
17
- const r = me(e, e.VERTEX_SHADER, t), i = me(e, e.FRAGMENT_SHADER, n), o = e.createProgram();
16
+ function ln(e, t, n) {
17
+ const r = Ae(e, e.VERTEX_SHADER, t), i = Ae(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 Ge(e, t, n) {
23
23
  }
24
24
  return o;
25
25
  }
26
- function Jt(e, t, n) {
26
+ function se(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 qe(e) {
32
+ function hn(e) {
33
33
  const t = e.getContext("webgl2", {
34
34
  alpha: !1,
35
35
  antialias: !1,
@@ -42,11 +42,11 @@ function qe(e) {
42
42
  throw new Error("WebGL2 is not available.");
43
43
  return t;
44
44
  }
45
- let $e = class {
45
+ let dn = class {
46
46
  constructor() {
47
- f(this, "viewportWidth", 1);
48
- f(this, "viewportHeight", 1);
49
- f(this, "viewState", {
47
+ d(this, "viewportWidth", 1);
48
+ d(this, "viewportHeight", 1);
49
+ d(this, "viewState", {
50
50
  offsetX: 0,
51
51
  offsetY: 0,
52
52
  zoom: 1
@@ -82,7 +82,7 @@ let $e = class {
82
82
  ]);
83
83
  }
84
84
  };
85
- const He = `#version 300 es
85
+ const fn = `#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
- `, Ze = `#version 300 es
105
+ `, mn = `#version 300 es
106
106
  precision highp float;
107
107
 
108
108
  in vec2 vUv;
@@ -114,28 +114,28 @@ void main() {
114
114
  outColor = texture(uTexture, vUv);
115
115
  }
116
116
  `;
117
- class Ke {
117
+ class gn {
118
118
  constructor(t) {
119
- f(this, "canvas");
120
- f(this, "gl");
121
- f(this, "camera", new $e());
122
- f(this, "imageWidth");
123
- f(this, "imageHeight");
124
- f(this, "clearColor");
125
- f(this, "program");
126
- f(this, "vao");
127
- f(this, "quadBuffer");
128
- f(this, "uCameraLocation");
129
- f(this, "uBoundsLocation");
130
- f(this, "uTextureLocation");
131
- f(this, "resizeObserver");
132
- f(this, "tiles", []);
133
- f(this, "frameId", null);
134
- f(this, "loadVersion", 0);
135
- f(this, "destroyed", !1);
136
- f(this, "fitted", !1);
137
- f(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 = qe(this.canvas), this.program = Ge(this.gl, He, Ze);
119
+ d(this, "canvas");
120
+ d(this, "gl");
121
+ d(this, "camera", new dn());
122
+ d(this, "imageWidth");
123
+ d(this, "imageHeight");
124
+ d(this, "clearColor");
125
+ d(this, "program");
126
+ d(this, "vao");
127
+ d(this, "quadBuffer");
128
+ d(this, "uCameraLocation");
129
+ d(this, "uBoundsLocation");
130
+ d(this, "uTextureLocation");
131
+ d(this, "resizeObserver");
132
+ d(this, "tiles", []);
133
+ d(this, "frameId", null);
134
+ d(this, "loadVersion", 0);
135
+ d(this, "destroyed", !1);
136
+ d(this, "fitted", !1);
137
+ d(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 = hn(this.canvas), this.program = ln(this.gl, fn, mn);
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 Ke {
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 = Jt(
180
+ ), this.gl.bindVertexArray(null), this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null), this.uCameraLocation = se(
181
181
  this.gl,
182
182
  this.program,
183
183
  "uCamera"
184
- ), this.uBoundsLocation = Jt(
184
+ ), this.uBoundsLocation = se(
185
185
  this.gl,
186
186
  this.program,
187
187
  "uBounds"
188
- ), this.uTextureLocation = Jt(
188
+ ), this.uTextureLocation = se(
189
189
  this.gl,
190
190
  this.program,
191
191
  "uTexture"
@@ -310,31 +310,31 @@ class Ke {
310
310
  this.gl.deleteTexture(n.texture);
311
311
  }
312
312
  }
313
- const Ce = [
313
+ const Xe = [
314
314
  160,
315
315
  160,
316
316
  160,
317
317
  255
318
318
  ];
319
- function Z(e, t, n) {
319
+ function j(e, t, n) {
320
320
  return Math.max(t, Math.min(n, e));
321
321
  }
322
- function Ie(e, t, n) {
322
+ function Ve(e, t, n) {
323
323
  const r = Number(e), i = Number(t), o = Number(n);
324
324
  return !Number.isFinite(r) || r <= 0 ? 1 : !Number.isFinite(i) || !Number.isFinite(o) ? r : Math.pow(2, i - o) * r;
325
325
  }
326
- function Jn(e, t, n) {
327
- let i = 100 * Ie(e, t, n);
326
+ function fr(e, t, n) {
327
+ let i = 100 * Ve(e, t, n);
328
328
  if (Number(e)) {
329
329
  let o = "μm";
330
330
  return i > 1e3 && (i /= 1e3, o = "mm"), `${i.toPrecision(3)} ${o}`;
331
331
  }
332
332
  return `${Math.round(i * 1e3) / 1e3} pixels`;
333
333
  }
334
- function Qn(e, t) {
334
+ function mr(e, t) {
335
335
  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;
336
336
  }
337
- function tr(e) {
337
+ function gr(e) {
338
338
  const t = String(e ?? "").trim();
339
339
  if (!t) return "";
340
340
  if (/^bearer\s+/i.test(t)) {
@@ -343,26 +343,26 @@ function tr(e) {
343
343
  }
344
344
  return `Bearer ${t}`;
345
345
  }
346
- function je(e) {
346
+ function pn(e) {
347
347
  const n = String(e ?? "").trim().match(/^#?([0-9a-fA-F]{6})$/);
348
- if (!n) return [...Ce];
348
+ if (!n) return [...Xe];
349
349
  const r = Number.parseInt(n[1], 16);
350
350
  return [r >> 16 & 255, r >> 8 & 255, r & 255, 255];
351
351
  }
352
- function er(e) {
352
+ function pr(e) {
353
353
  const t = [
354
- [...Ce]
354
+ [...Xe]
355
355
  ], n = /* @__PURE__ */ new Map();
356
356
  for (const i of e ?? []) {
357
357
  const o = String(i?.termId ?? "");
358
- !o || n.has(o) || (n.set(o, t.length), t.push(je(i?.termColor)));
358
+ !o || n.has(o) || (n.set(o, t.length), t.push(pn(i?.termColor)));
359
359
  }
360
360
  const r = new Uint8Array(t.length * 4);
361
361
  for (let i = 0; i < t.length; i += 1)
362
362
  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];
363
363
  return { colors: r, termToPaletteIndex: n };
364
364
  }
365
- function ge(e, t, n) {
365
+ function Re(e, t, n) {
366
366
  const r = e.createShader(e.VERTEX_SHADER), i = e.createShader(e.FRAGMENT_SHADER);
367
367
  if (!r || !i)
368
368
  throw new Error("Shader allocation failed");
@@ -377,7 +377,7 @@ function ge(e, t, n) {
377
377
  throw new Error(e.getProgramInfoLog(o) || "program link failed");
378
378
  return o;
379
379
  }
380
- const Je = "rgba(255, 77, 79, 0.16)", Qe = 3, tn = 2, _e = 96, en = 1, nn = [], ie = [], pe = 1e3, Be = 2, Ue = 2, rn = 4096, on = 0.2, At = {
380
+ const wn = "rgba(255, 77, 79, 0.16)", bn = 3, yn = 2, Oe = 96, xn = 1, Ce = [], fe = [], Ie = 1e3, Ge = 2, qe = 2, Tn = 4096, vn = 0.2, Bt = {
381
381
  color: "#ff4d4f",
382
382
  width: 2,
383
383
  lineJoin: "round",
@@ -386,7 +386,17 @@ const Je = "rgba(255, 77, 79, 0.16)", Qe = 3, tn = 2, _e = 96, en = 1, nn = [],
386
386
  shadowBlur: 0,
387
387
  shadowOffsetX: 0,
388
388
  shadowOffsetY: 0
389
- }, bt = {
389
+ }, Mn = {
390
+ color: "#4cc9f0",
391
+ width: 2,
392
+ lineDash: [10, 8],
393
+ lineJoin: "round",
394
+ lineCap: "round",
395
+ shadowColor: "rgba(0, 0, 0, 0)",
396
+ shadowBlur: 0,
397
+ shadowOffsetX: 0,
398
+ shadowOffsetY: 0
399
+ }, xt = {
390
400
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
391
401
  fontSize: 12,
392
402
  fontWeight: 500,
@@ -399,82 +409,67 @@ const Je = "rgba(255, 77, 79, 0.16)", Qe = 3, tn = 2, _e = 96, en = 1, nn = [],
399
409
  offsetY: 10,
400
410
  borderRadius: 3
401
411
  };
402
- function Zt(e, t, n) {
412
+ function ne(e, t, n) {
403
413
  return Math.max(t, Math.min(n, e));
404
414
  }
405
- function Yt(e) {
415
+ function Zt(e) {
406
416
  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";
407
417
  }
408
- function Qt(e, t) {
418
+ function ae(e, t) {
409
419
  return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? t : e;
410
420
  }
411
- function sn(e) {
421
+ function Pn(e) {
412
422
  return {
413
- rectangleAreaMm2: Qt(
414
- e?.rectangleAreaMm2,
415
- Be
416
- ),
417
- circleAreaMm2: Qt(
418
- e?.circleAreaMm2,
419
- Ue
420
- ),
421
- rectanglePixelSize: Qt(
422
- e?.rectanglePixelSize,
423
- rn
424
- )
423
+ rectangleAreaMm2: ae(e?.rectangleAreaMm2, Ge),
424
+ circleAreaMm2: ae(e?.circleAreaMm2, qe),
425
+ rectanglePixelSize: ae(e?.rectanglePixelSize, Tn)
425
426
  };
426
427
  }
427
- function an(e) {
428
- return e * pe * pe;
428
+ function Sn(e) {
429
+ return e * Ie * Ie;
429
430
  }
430
- function be(e, t) {
431
- return !e || !Number.isFinite(t) || t <= 0 ? [] : St([
431
+ function _e(e, t) {
432
+ return !e || !Number.isFinite(t) || t <= 0 ? [] : Pt([
432
433
  [e[0] - t, e[1] - t],
433
434
  [e[0] + t, e[1] - t],
434
435
  [e[0] + t, e[1] + t],
435
436
  [e[0] - t, e[1] + t]
436
437
  ]);
437
438
  }
438
- function un(e, t, n = _e) {
439
+ function En(e, t, n = Oe) {
439
440
  if (!e || !Number.isFinite(t) || t <= 0) return [];
440
441
  const r = [];
441
442
  for (let i = 0; i <= n; i += 1) {
442
443
  const o = i / n * Math.PI * 2;
443
- r.push([
444
- e[0] + Math.cos(o) * t,
445
- e[1] + Math.sin(o) * t
446
- ]);
444
+ r.push([e[0] + Math.cos(o) * t, e[1] + Math.sin(o) * t]);
447
445
  }
448
- return St(r);
446
+ return Pt(r);
449
447
  }
450
- function St(e) {
448
+ function Pt(e) {
451
449
  if (!Array.isArray(e) || e.length < 3) return [];
452
450
  const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
453
451
  return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
454
452
  }
455
- function we(e, t) {
456
- return !e || !t ? [] : St([
453
+ function Be(e, t) {
454
+ return !e || !t ? [] : Pt([
457
455
  [e[0], e[1]],
458
456
  [t[0], e[1]],
459
457
  [t[0], t[1]],
460
458
  [e[0], t[1]]
461
459
  ]);
462
460
  }
463
- function ye(e, t, n = _e) {
461
+ function Ue(e, t, n = Oe) {
464
462
  if (!e || !t) return [];
465
463
  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;
466
464
  if (o < 1) return [];
467
465
  const s = [];
468
466
  for (let a = 0; a <= n; a += 1) {
469
- const l = a / n * Math.PI * 2;
470
- s.push([
471
- r + Math.cos(l) * o,
472
- i + Math.sin(l) * o
473
- ]);
467
+ const c = a / n * Math.PI * 2;
468
+ s.push([r + Math.cos(c) * o, i + Math.sin(c) * o]);
474
469
  }
475
- return St(s);
470
+ return Pt(s);
476
471
  }
477
- function oe(e) {
472
+ function me(e) {
478
473
  if (!Array.isArray(e) || e.length < 4) return 0;
479
474
  let t = 0;
480
475
  for (let n = 0; n < e.length - 1; n += 1) {
@@ -483,40 +478,40 @@ function oe(e) {
483
478
  }
484
479
  return Math.abs(t * 0.5);
485
480
  }
486
- function xe(e) {
481
+ function Fe(e) {
487
482
  if (!Array.isArray(e) || e.length === 0) return [0, 0, 0, 0];
488
483
  let t = 1 / 0, n = 1 / 0, r = -1 / 0, i = -1 / 0;
489
484
  for (const [o, s] of e)
490
485
  o < t && (t = o), o > r && (r = o), s < n && (n = s), s > i && (i = s);
491
486
  return [t, n, r, i];
492
487
  }
493
- function Te(e) {
494
- return Array.isArray(e) && e.length >= 4 && oe(e) > en;
488
+ function Le(e) {
489
+ return Array.isArray(e) && e.length >= 4 && me(e) > xn;
495
490
  }
496
- function Dt(e, t, n, r = !1, i = !1) {
491
+ function Wt(e, t, n, r = !1, i = !1) {
497
492
  if (t.length !== 0) {
498
493
  e.beginPath(), e.moveTo(t[0][0], t[0][1]);
499
494
  for (let o = 1; o < t.length; o += 1)
500
495
  e.lineTo(t[o][0], t[o][1]);
501
- r && e.closePath(), i && r && (e.fillStyle = Je, 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(ie), e.shadowColor = "rgba(0, 0, 0, 0)", e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0;
496
+ r && e.closePath(), i && r && (e.fillStyle = wn, 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(fe), e.shadowColor = "rgba(0, 0, 0, 0)", e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0;
502
497
  }
503
498
  }
504
- function Fe(e) {
505
- const t = Array.isArray(e?.lineDash) ? e.lineDash.filter((s) => Number.isFinite(s) && s >= 0) : ie, n = typeof e?.width == "number" && Number.isFinite(e.width) ? Math.max(0, e.width) : At.width, r = typeof e?.shadowBlur == "number" && Number.isFinite(e.shadowBlur) ? Math.max(0, e.shadowBlur) : At.shadowBlur, i = typeof e?.shadowOffsetX == "number" && Number.isFinite(e.shadowOffsetX) ? e.shadowOffsetX : At.shadowOffsetX, o = typeof e?.shadowOffsetY == "number" && Number.isFinite(e.shadowOffsetY) ? e.shadowOffsetY : At.shadowOffsetY;
499
+ function $e(e) {
500
+ const t = Array.isArray(e?.lineDash) ? e.lineDash.filter((s) => Number.isFinite(s) && s >= 0) : fe, n = typeof e?.width == "number" && Number.isFinite(e.width) ? Math.max(0, e.width) : Bt.width, r = typeof e?.shadowBlur == "number" && Number.isFinite(e.shadowBlur) ? Math.max(0, e.shadowBlur) : Bt.shadowBlur, i = typeof e?.shadowOffsetX == "number" && Number.isFinite(e.shadowOffsetX) ? e.shadowOffsetX : Bt.shadowOffsetX, o = typeof e?.shadowOffsetY == "number" && Number.isFinite(e.shadowOffsetY) ? e.shadowOffsetY : Bt.shadowOffsetY;
506
501
  return {
507
- color: e?.color || At.color,
502
+ color: e?.color || Bt.color,
508
503
  width: n,
509
- lineDash: t.length ? t : ie,
510
- lineJoin: e?.lineJoin || At.lineJoin,
511
- lineCap: e?.lineCap || At.lineCap,
512
- shadowColor: e?.shadowColor || At.shadowColor,
504
+ lineDash: t.length ? t : fe,
505
+ lineJoin: e?.lineJoin || Bt.lineJoin,
506
+ lineCap: e?.lineCap || Bt.lineCap,
507
+ shadowColor: e?.shadowColor || Bt.shadowColor,
513
508
  shadowBlur: r,
514
509
  shadowOffsetX: i,
515
510
  shadowOffsetY: o
516
511
  };
517
512
  }
518
- function Wt(e, t) {
519
- return t ? Fe({
513
+ function Ot(e, t) {
514
+ return t ? $e({
520
515
  color: t.color ?? e.color,
521
516
  width: t.width ?? e.width,
522
517
  lineDash: t.lineDash ?? e.lineDash,
@@ -528,18 +523,18 @@ function Wt(e, t) {
528
523
  shadowOffsetY: t.shadowOffsetY ?? e.shadowOffsetY
529
524
  }) : e;
530
525
  }
531
- function ve(e, t) {
526
+ function De(e, t) {
532
527
  return e == null || t === null || t === void 0 ? !1 : String(e) === String(t);
533
528
  }
534
- function cn(e) {
535
- const t = typeof e?.paddingX == "number" && Number.isFinite(e.paddingX) ? Math.max(0, e.paddingX) : bt.paddingX, n = typeof e?.paddingY == "number" && Number.isFinite(e.paddingY) ? Math.max(0, e.paddingY) : bt.paddingY, r = typeof e?.fontSize == "number" && Number.isFinite(e.fontSize) ? Math.max(8, e.fontSize) : bt.fontSize, i = typeof e?.borderWidth == "number" && Number.isFinite(e.borderWidth) ? Math.max(0, e.borderWidth) : bt.borderWidth, o = typeof e?.offsetY == "number" && Number.isFinite(e.offsetY) ? e.offsetY : bt.offsetY, s = typeof e?.borderRadius == "number" && Number.isFinite(e.borderRadius) ? Math.max(0, e.borderRadius) : bt.borderRadius;
529
+ function An(e) {
530
+ const t = typeof e?.paddingX == "number" && Number.isFinite(e.paddingX) ? Math.max(0, e.paddingX) : xt.paddingX, n = typeof e?.paddingY == "number" && Number.isFinite(e.paddingY) ? Math.max(0, e.paddingY) : xt.paddingY, r = typeof e?.fontSize == "number" && Number.isFinite(e.fontSize) ? Math.max(8, e.fontSize) : xt.fontSize, i = typeof e?.borderWidth == "number" && Number.isFinite(e.borderWidth) ? Math.max(0, e.borderWidth) : xt.borderWidth, o = typeof e?.offsetY == "number" && Number.isFinite(e.offsetY) ? e.offsetY : xt.offsetY, s = typeof e?.borderRadius == "number" && Number.isFinite(e.borderRadius) ? Math.max(0, e.borderRadius) : xt.borderRadius;
536
531
  return {
537
- fontFamily: e?.fontFamily || bt.fontFamily,
532
+ fontFamily: e?.fontFamily || xt.fontFamily,
538
533
  fontSize: r,
539
- fontWeight: e?.fontWeight || bt.fontWeight,
540
- textColor: e?.textColor || bt.textColor,
541
- backgroundColor: e?.backgroundColor || bt.backgroundColor,
542
- borderColor: e?.borderColor || bt.borderColor,
534
+ fontWeight: e?.fontWeight || xt.fontWeight,
535
+ textColor: e?.textColor || xt.textColor,
536
+ backgroundColor: e?.backgroundColor || xt.backgroundColor,
537
+ borderColor: e?.borderColor || xt.borderColor,
543
538
  borderWidth: i,
544
539
  paddingX: t,
545
540
  paddingY: n,
@@ -547,11 +542,11 @@ function cn(e) {
547
542
  borderRadius: s
548
543
  };
549
544
  }
550
- function ln(e, t, n, r, i, o) {
545
+ function Rn(e, t, n, r, i, o) {
551
546
  const s = Math.max(0, Math.min(o, r * 0.5, i * 0.5));
552
547
  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();
553
548
  }
554
- function hn(e) {
549
+ function Cn(e) {
555
550
  if (!e.length) return null;
556
551
  let t = 1 / 0;
557
552
  for (const i of e)
@@ -562,37 +557,22 @@ function hn(e) {
562
557
  Math.abs(i[1] - t) > 0.5 || (i[0] < n && (n = i[0]), i[0] > r && (r = i[0]));
563
558
  return !Number.isFinite(n) || !Number.isFinite(r) ? null : [(n + r) * 0.5, t];
564
559
  }
565
- function fn(e, t, n, r, i, o) {
560
+ function In(e, t, n, r, i, o) {
566
561
  const s = t.trim();
567
562
  if (!s) return;
568
563
  e.save(), e.font = `${o.fontWeight} ${o.fontSize}px ${o.fontFamily}`, e.textAlign = "center", e.textBaseline = "middle";
569
- const l = e.measureText(s).width + o.paddingX * 2, u = o.fontSize + o.paddingY * 2, h = Zt(
570
- n[0],
571
- l * 0.5 + 1,
572
- r - l * 0.5 - 1
573
- ), p = Zt(
574
- n[1] - o.offsetY,
575
- u * 0.5 + 1,
576
- i - u * 0.5 - 1
577
- ), d = h - l * 0.5, g = p - u * 0.5;
578
- e.fillStyle = o.backgroundColor, e.strokeStyle = o.borderColor, e.lineWidth = o.borderWidth, ln(
579
- e,
580
- d,
581
- g,
582
- l,
583
- u,
584
- o.borderRadius
585
- ), e.fill(), o.borderWidth > 0 && e.stroke(), e.fillStyle = o.textColor, e.fillText(s, h, p + 0.5), e.restore();
564
+ const c = e.measureText(s).width + o.paddingX * 2, l = o.fontSize + o.paddingY * 2, h = ne(n[0], c * 0.5 + 1, r - c * 0.5 - 1), w = ne(n[1] - o.offsetY, l * 0.5 + 1, i - l * 0.5 - 1), f = h - c * 0.5, m = w - l * 0.5;
565
+ e.fillStyle = o.backgroundColor, e.strokeStyle = o.borderColor, e.lineWidth = o.borderWidth, Rn(e, f, m, c, l, o.borderRadius), e.fill(), o.borderWidth > 0 && e.stroke(), e.fillStyle = o.textColor, e.fillText(s, h, w + 0.5), e.restore();
586
566
  }
587
- function te(e, t, n) {
588
- return [Zt(e[0], 0, t), Zt(e[1], 0, n)];
567
+ function ce(e, t, n) {
568
+ return [ne(e[0], 0, t), ne(e[1], 0, n)];
589
569
  }
590
- function ee(e) {
570
+ function ue(e) {
591
571
  if (!Array.isArray(e) || e.length < 2) return null;
592
572
  const t = Number(e[0]), n = Number(e[1]);
593
573
  return !Number.isFinite(t) || !Number.isFinite(n) ? null : [t, n];
594
574
  }
595
- function dn({
575
+ function _n({
596
576
  tool: e,
597
577
  imageWidth: t,
598
578
  imageHeight: n,
@@ -601,48 +581,36 @@ function dn({
601
581
  stampOptions: o,
602
582
  projectorRef: s,
603
583
  onDrawComplete: a,
584
+ onPatchComplete: c,
604
585
  enabled: l,
605
- viewStateSignal: u,
606
- persistedRegions: h,
607
- persistedPolygons: p,
608
- regionStrokeStyle: d,
609
- regionStrokeHoverStyle: g,
610
- regionStrokeActiveStyle: y,
611
- resolveRegionStrokeStyle: b,
612
- overlayShapes: x,
613
- hoveredRegionId: A = null,
614
- activeRegionId: F = null,
615
- regionLabelStyle: C,
616
- invalidateRef: z,
617
- className: wt,
618
- style: lt
586
+ viewStateSignal: h,
587
+ persistedRegions: w,
588
+ patchRegions: f,
589
+ persistedPolygons: m,
590
+ regionStrokeStyle: y,
591
+ regionStrokeHoverStyle: b,
592
+ regionStrokeActiveStyle: v,
593
+ patchStrokeStyle: S,
594
+ resolveRegionStrokeStyle: L,
595
+ overlayShapes: R,
596
+ hoveredRegionId: W = null,
597
+ activeRegionId: yt = null,
598
+ regionLabelStyle: st,
599
+ invalidateRef: X,
600
+ className: At,
601
+ style: mt
619
602
  }) {
620
- const Y = $(null), yt = $(!1), ht = $(e), nt = $({
603
+ const lt = Z(null), Rt = Z(!1), J = Z(e), rt = Z({
621
604
  isDrawing: !1,
622
605
  pointerId: null,
623
606
  start: null,
624
607
  current: null,
625
608
  points: [],
626
609
  stampCenter: null
627
- }), H = l ?? e !== "cursor", V = et(() => h && h.length > 0 ? h : !p || p.length === 0 ? nn : p.map((c, m) => ({
628
- id: m,
629
- coordinates: c
630
- })), [h, p]), J = et(
631
- () => Fe(d),
632
- [d]
633
- ), vt = et(
634
- () => Wt(J, g),
635
- [J, g]
636
- ), xt = et(
637
- () => Wt(J, y),
638
- [J, y]
639
- ), ut = et(
640
- () => cn(C),
641
- [C]
642
- ), Tt = et(
643
- () => sn(o),
644
- [o]
645
- ), P = et(
610
+ }), V = l ?? e !== "cursor", ht = H(() => w && w.length > 0 ? w : !m || m.length === 0 ? Ce : m.map((u, g) => ({
611
+ id: g,
612
+ coordinates: u
613
+ })), [w, m]), Ct = H(() => f ?? Ce, [f]), at = H(() => $e(y), [y]), x = H(() => Ot(at, b), [at, b]), T = H(() => Ot(at, v), [at, v]), E = H(() => Ot(Mn, S), [S]), k = H(() => An(st), [st]), O = H(() => Pn(o), [o]), gt = H(
646
614
  () => ({
647
615
  position: "absolute",
648
616
  inset: 0,
@@ -651,324 +619,309 @@ function dn({
651
619
  height: "100%",
652
620
  display: "block",
653
621
  touchAction: "none",
654
- pointerEvents: H ? "auto" : "none",
655
- cursor: H ? "crosshair" : "default",
656
- ...lt
622
+ pointerEvents: V ? "auto" : "none",
623
+ cursor: V ? "crosshair" : "default",
624
+ ...mt
657
625
  }),
658
- [H, lt]
659
- ), E = D(() => {
660
- const c = Y.current;
661
- if (!c) return;
662
- const m = c.getBoundingClientRect(), S = Math.max(1, window.devicePixelRatio || 1), v = Math.max(1, Math.round(m.width * S)), N = Math.max(1, Math.round(m.height * S));
663
- (c.width !== v || c.height !== N) && (c.width = v, c.height = N);
664
- }, []), M = D(
665
- (c) => {
666
- const m = s.current;
667
- if (!m || c.length === 0) return [];
668
- const S = new Array(c.length);
669
- for (let v = 0; v < c.length; v += 1) {
670
- const N = ee(
671
- m.worldToScreen(c[v][0], c[v][1])
672
- );
673
- if (!N) return [];
674
- S[v] = N;
626
+ [V, mt]
627
+ ), tt = D(() => {
628
+ const u = lt.current;
629
+ if (!u) return;
630
+ const g = u.getBoundingClientRect(), M = Math.max(1, window.devicePixelRatio || 1), _ = Math.max(1, Math.round(g.width * M)), A = Math.max(1, Math.round(g.height * M));
631
+ (u.width !== _ || u.height !== A) && (u.width = _, u.height = A);
632
+ }, []), q = D(
633
+ (u) => {
634
+ const g = s.current;
635
+ if (!g || u.length === 0) return [];
636
+ const M = new Array(u.length);
637
+ for (let _ = 0; _ < u.length; _ += 1) {
638
+ const A = ue(g.worldToScreen(u[_][0], u[_][1]));
639
+ if (!A) return [];
640
+ M[_] = A;
675
641
  }
676
- return S;
642
+ return M;
677
643
  },
678
644
  [s]
679
- ), I = D(
680
- (c) => {
681
- if (!Number.isFinite(c) || c <= 0) return 0;
682
- const m = typeof r == "number" && Number.isFinite(r) && r > 0 ? r : 1, S = typeof i == "number" && Number.isFinite(i) ? i : 0, v = s.current?.getViewState?.().zoom, N = typeof v == "number" && Number.isFinite(v) && v > 0 ? v : 1, T = S + Math.log2(N), _ = Math.max(
683
- 1e-9,
684
- Ie(m, S, T)
685
- );
686
- return c / _ / N;
645
+ ), et = D(
646
+ (u) => {
647
+ if (!Number.isFinite(u) || u <= 0) return 0;
648
+ const g = typeof r == "number" && Number.isFinite(r) && r > 0 ? r : 1, M = typeof i == "number" && Number.isFinite(i) ? i : 0, _ = s.current?.getViewState?.().zoom, A = typeof _ == "number" && Number.isFinite(_) && _ > 0 ? _ : 1, C = M + Math.log2(A), I = Math.max(1e-9, Ve(g, M, C));
649
+ return u / I / A;
687
650
  },
688
651
  [r, i, s]
689
- ), O = D(
690
- (c, m) => {
691
- if (!m) return [];
692
- let S = 0;
693
- if (c === "stamp-rectangle-4096px") {
694
- const T = Tt.rectanglePixelSize * 0.5;
695
- return be(m, T).map((G) => te(G, t, n));
652
+ ), ct = D(
653
+ (u, g) => {
654
+ if (!g) return [];
655
+ let M = 0;
656
+ if (u === "stamp-rectangle-4096px") {
657
+ const C = O.rectanglePixelSize * 0.5;
658
+ return _e(g, C).map((G) => ce(G, t, n));
696
659
  }
697
- if (c === "stamp-rectangle" || c === "stamp-rectangle-2mm2" ? S = c === "stamp-rectangle-2mm2" ? Be : Tt.rectangleAreaMm2 : (c === "stamp-circle" || c === "stamp-circle-2mm2" || c === "stamp-circle-hpf-0.2mm2") && (S = c === "stamp-circle-hpf-0.2mm2" ? on : c === "stamp-circle-2mm2" ? Ue : Tt.circleAreaMm2), !Number.isFinite(S) || S <= 0) return [];
698
- const v = an(S);
699
- let N = [];
700
- if (c === "stamp-rectangle" || c === "stamp-rectangle-2mm2") {
701
- const T = I(Math.sqrt(v) * 0.5);
702
- N = be(m, T);
703
- } else if (c === "stamp-circle" || c === "stamp-circle-2mm2" || c === "stamp-circle-hpf-0.2mm2") {
704
- const T = I(Math.sqrt(v / Math.PI));
705
- N = un(m, T);
660
+ if (u === "stamp-rectangle" || u === "stamp-rectangle-2mm2" ? M = u === "stamp-rectangle-2mm2" ? Ge : O.rectangleAreaMm2 : (u === "stamp-circle" || u === "stamp-circle-2mm2" || u === "stamp-circle-hpf-0.2mm2") && (M = u === "stamp-circle-hpf-0.2mm2" ? vn : u === "stamp-circle-2mm2" ? qe : O.circleAreaMm2), !Number.isFinite(M) || M <= 0) return [];
661
+ const _ = Sn(M);
662
+ let A = [];
663
+ if (u === "stamp-rectangle" || u === "stamp-rectangle-2mm2") {
664
+ const C = et(Math.sqrt(_) * 0.5);
665
+ A = _e(g, C);
666
+ } else if (u === "stamp-circle" || u === "stamp-circle-2mm2" || u === "stamp-circle-hpf-0.2mm2") {
667
+ const C = et(Math.sqrt(_ / Math.PI));
668
+ A = En(g, C);
706
669
  }
707
- return N.length ? N.map((T) => te(T, t, n)) : [];
670
+ return A.length ? A.map((C) => ce(C, t, n)) : [];
708
671
  },
709
- [I, t, n, Tt]
710
- ), it = D(() => {
711
- const c = nt.current;
712
- return Yt(e) ? O(e, c.stampCenter) : c.isDrawing ? e === "freehand" ? c.points : e === "rectangle" ? we(c.start, c.current) : e === "circular" ? ye(c.start, c.current) : [] : [];
713
- }, [e, O]), ot = D(() => {
714
- E();
715
- const c = Y.current;
716
- if (!c) return;
717
- const m = c.getContext("2d");
718
- if (!m) return;
719
- const S = Math.max(1, window.devicePixelRatio || 1), v = c.width / S, N = c.height / S;
720
- if (m.setTransform(1, 0, 0, 1, 0, 0), m.clearRect(0, 0, c.width, c.height), m.setTransform(S, 0, 0, S, 0, 0), V.length > 0)
721
- for (let T = 0; T < V.length; T += 1) {
722
- const _ = V[T], G = _?.coordinates;
672
+ [et, t, n, O]
673
+ ), ut = D(() => {
674
+ const u = rt.current;
675
+ return Zt(e) ? ct(e, u.stampCenter) : u.isDrawing ? e === "freehand" ? u.points : e === "rectangle" ? Be(u.start, u.current) : e === "circular" ? Ue(u.start, u.current) : [] : [];
676
+ }, [e, ct]), U = D(() => {
677
+ tt();
678
+ const u = lt.current;
679
+ if (!u) return;
680
+ const g = u.getContext("2d");
681
+ if (!g) return;
682
+ const M = Math.max(1, window.devicePixelRatio || 1), _ = u.width / M, A = u.height / M;
683
+ if (g.setTransform(1, 0, 0, 1, 0, 0), g.clearRect(0, 0, u.width, u.height), g.setTransform(M, 0, 0, M, 0, 0), ht.length > 0)
684
+ for (let C = 0; C < ht.length; C += 1) {
685
+ const I = ht[C], G = I?.coordinates;
723
686
  if (!G || G.length < 3) continue;
724
- const tt = St(G), dt = M(tt);
725
- if (dt.length >= 4) {
726
- const Rt = _.id ?? T, j = ve(
727
- F,
728
- Rt
729
- ) ? "active" : ve(A, Rt) ? "hover" : "default";
730
- let pt = j === "active" ? xt : j === "hover" ? vt : J;
731
- if (b) {
732
- const _t = b({
733
- region: _,
734
- regionId: Rt,
735
- regionIndex: T,
736
- state: j
687
+ const it = Pt(G), ot = q(it);
688
+ if (ot.length >= 4) {
689
+ const St = I.id ?? C, It = De(yt, St) ? "active" : De(W, St) ? "hover" : "default";
690
+ let Vt = It === "active" ? T : It === "hover" ? x : at;
691
+ if (L) {
692
+ const ie = L({
693
+ region: I,
694
+ regionId: St,
695
+ regionIndex: C,
696
+ state: It
737
697
  });
738
- pt = Wt(pt, _t || void 0);
698
+ Vt = Ot(Vt, ie || void 0);
739
699
  }
740
- Dt(m, dt, pt, !0, !1);
700
+ Wt(g, ot, Vt, !0, !1);
741
701
  }
742
702
  }
743
- if (Array.isArray(x) && x.length > 0)
744
- for (let T = 0; T < x.length; T += 1) {
745
- const _ = x[T];
746
- if (!_?.coordinates?.length) continue;
747
- const G = _.closed ?? !1, tt = G ? St(_.coordinates) : _.coordinates, dt = M(tt);
748
- if (dt.length < 2) continue;
749
- const Rt = Wt(
750
- J,
751
- _.strokeStyle
752
- );
753
- Dt(m, dt, Rt, G, _.fill ?? !1);
703
+ if (Ct.length > 0)
704
+ for (let C = 0; C < Ct.length; C += 1) {
705
+ const G = Ct[C]?.coordinates;
706
+ if (!G || G.length < 3) continue;
707
+ const it = Pt(G), ot = q(it);
708
+ ot.length < 4 || Wt(g, ot, E, !0, !1);
754
709
  }
755
- if (H) {
756
- const T = it();
757
- if (T.length > 0)
710
+ if (Array.isArray(R) && R.length > 0)
711
+ for (let C = 0; C < R.length; C += 1) {
712
+ const I = R[C];
713
+ if (!I?.coordinates?.length) continue;
714
+ const G = I.closed ?? !1, it = G ? Pt(I.coordinates) : I.coordinates, ot = q(it);
715
+ if (ot.length < 2) continue;
716
+ const St = Ot(at, I.strokeStyle);
717
+ Wt(g, ot, St, G, I.fill ?? !1);
718
+ }
719
+ if (V) {
720
+ const C = ut();
721
+ if (C.length > 0)
758
722
  if (e === "freehand") {
759
- const _ = M(T);
760
- _.length >= 2 && Dt(m, _, J, !1, !1), _.length >= 3 && Dt(
761
- m,
762
- M(St(T)),
763
- J,
764
- !0,
765
- !0
766
- );
723
+ const I = q(C);
724
+ I.length >= 2 && Wt(g, I, at, !1, !1), I.length >= 3 && Wt(g, q(Pt(C)), at, !0, !0);
767
725
  } else {
768
- const _ = M(T);
769
- _.length >= 4 && Dt(m, _, J, !0, !0);
726
+ const I = q(C);
727
+ I.length >= 4 && Wt(g, I, at, !0, !0);
770
728
  }
771
729
  }
772
- if (V.length > 0)
773
- for (const T of V) {
774
- if (!T.label) continue;
775
- const _ = T?.coordinates;
776
- if (!_ || _.length < 3) continue;
777
- const G = St(_), tt = hn(G);
778
- if (!tt) continue;
779
- const dt = ee(
780
- s.current?.worldToScreen(tt[0], tt[1]) ?? []
781
- );
782
- dt && fn(
783
- m,
784
- T.label,
785
- dt,
786
- v,
787
- N,
788
- ut
789
- );
730
+ if (ht.length > 0)
731
+ for (const C of ht) {
732
+ if (!C.label) continue;
733
+ const I = C?.coordinates;
734
+ if (!I || I.length < 3) continue;
735
+ const G = Pt(I), it = Cn(G);
736
+ if (!it) continue;
737
+ const ot = ue(s.current?.worldToScreen(it[0], it[1]) ?? []);
738
+ ot && In(g, C.label, ot, _, A, k);
790
739
  }
791
740
  }, [
792
- H,
741
+ V,
793
742
  e,
794
- it,
795
- E,
796
- M,
743
+ ut,
744
+ tt,
745
+ q,
797
746
  s,
798
- V,
747
+ ht,
748
+ R,
749
+ W,
750
+ yt,
751
+ at,
799
752
  x,
800
- A,
801
- F,
802
- J,
803
- vt,
804
- xt,
805
- b,
806
- ut
807
- ]), R = D(() => {
808
- yt.current || (yt.current = !0, requestAnimationFrame(() => {
809
- yt.current = !1, ot();
753
+ T,
754
+ Ct,
755
+ E,
756
+ L,
757
+ k
758
+ ]), P = D(() => {
759
+ Rt.current || (Rt.current = !0, requestAnimationFrame(() => {
760
+ Rt.current = !1, U();
810
761
  }));
811
- }, [ot]), W = D(() => {
812
- const c = nt.current, m = Y.current;
813
- if (m && c.pointerId !== null && m.hasPointerCapture(c.pointerId))
762
+ }, [U]), Y = D(() => {
763
+ const u = rt.current, g = lt.current;
764
+ if (g && u.pointerId !== null && g.hasPointerCapture(u.pointerId))
814
765
  try {
815
- m.releasePointerCapture(c.pointerId);
766
+ g.releasePointerCapture(u.pointerId);
816
767
  } catch {
817
768
  }
818
- c.isDrawing = !1, c.pointerId = null, c.start = null, c.current = null, c.points = [], c.stampCenter = null;
819
- }, []), st = D(
820
- (c) => {
821
- const m = s.current;
822
- if (!m || t <= 0 || n <= 0) return null;
823
- const S = ee(
824
- m.screenToWorld(c.clientX, c.clientY)
825
- );
826
- return S ? te(S, t, n) : null;
769
+ u.isDrawing = !1, u.pointerId = null, u.start = null, u.current = null, u.points = [], u.stampCenter = null;
770
+ }, []), $ = D(
771
+ (u) => {
772
+ const g = s.current;
773
+ if (!g || t <= 0 || n <= 0) return null;
774
+ const M = ue(g.screenToWorld(u.clientX, u.clientY));
775
+ return M ? ce(M, t, n) : null;
827
776
  },
828
777
  [s, t, n]
829
- ), ft = D(() => {
830
- const c = nt.current;
831
- if (!c.isDrawing) {
832
- W(), R();
778
+ ), Q = D(() => {
779
+ const u = rt.current;
780
+ if (!u.isDrawing) {
781
+ Y(), P();
833
782
  return;
834
783
  }
835
- let m = [];
836
- e === "freehand" ? c.points.length >= Qe && (m = St(c.points)) : e === "rectangle" ? m = we(c.start, c.current) : e === "circular" && (m = ye(c.start, c.current)), (e === "freehand" || e === "rectangle" || e === "circular") && Te(m) && a && a({
784
+ let g = [];
785
+ e === "freehand" ? u.points.length >= bn && (g = Pt(u.points)) : e === "rectangle" ? g = Be(u.start, u.current) : e === "circular" && (g = Ue(u.start, u.current)), (e === "freehand" || e === "rectangle" || e === "circular") && Le(g) && a && a({
837
786
  tool: e,
838
- coordinates: m,
839
- bbox: xe(m),
840
- areaPx: oe(m)
841
- }), W(), R();
842
- }, [e, a, W, R]), X = D(
843
- (c, m) => {
844
- const S = O(c, m);
845
- !Te(S) || !a || a({
846
- tool: c,
847
- coordinates: S,
848
- bbox: xe(S),
849
- areaPx: oe(S)
850
- });
787
+ intent: "roi",
788
+ coordinates: g,
789
+ bbox: Fe(g),
790
+ areaPx: me(g)
791
+ }), Y(), P();
792
+ }, [e, a, Y, P]), dt = D(
793
+ (u, g) => {
794
+ const M = ct(u, g);
795
+ if (!Le(M)) return;
796
+ const _ = u === "stamp-rectangle-4096px" ? "patch" : "roi", A = {
797
+ tool: u,
798
+ intent: _,
799
+ coordinates: M,
800
+ bbox: Fe(M),
801
+ areaPx: me(M)
802
+ };
803
+ a?.(A), _ === "patch" && c && c(A);
851
804
  },
852
- [O, a]
853
- ), K = D(
854
- (c) => {
855
- if (!H || e === "cursor" || c.button !== 0) return;
856
- const m = st(c);
857
- if (!m) return;
858
- if (c.preventDefault(), c.stopPropagation(), Yt(e)) {
859
- const N = nt.current;
860
- N.stampCenter = m, X(e, m), R();
805
+ [ct, a, c]
806
+ ), Lt = D(
807
+ (u) => {
808
+ if (!V || e === "cursor" || u.button !== 0) return;
809
+ const g = $(u);
810
+ if (!g) return;
811
+ if (u.preventDefault(), u.stopPropagation(), Zt(e)) {
812
+ const A = rt.current;
813
+ A.stampCenter = g, dt(e, g), P();
861
814
  return;
862
815
  }
863
- const S = Y.current;
864
- S && S.setPointerCapture(c.pointerId);
865
- const v = nt.current;
866
- v.isDrawing = !0, v.pointerId = c.pointerId, v.start = m, v.current = m, v.points = e === "freehand" ? [m] : [], R();
816
+ const M = lt.current;
817
+ M && M.setPointerCapture(u.pointerId);
818
+ const _ = rt.current;
819
+ _.isDrawing = !0, _.pointerId = u.pointerId, _.start = g, _.current = g, _.points = e === "freehand" ? [g] : [], P();
867
820
  },
868
- [H, e, st, X, R]
869
- ), rt = D(
870
- (c) => {
871
- if (!H || e === "cursor") return;
872
- const m = st(c);
873
- if (!m) return;
874
- if (Yt(e)) {
875
- const v = nt.current;
876
- v.stampCenter = m, c.preventDefault(), c.stopPropagation(), R();
821
+ [V, e, $, dt, P]
822
+ ), Tt = D(
823
+ (u) => {
824
+ if (!V || e === "cursor") return;
825
+ const g = $(u);
826
+ if (!g) return;
827
+ if (Zt(e)) {
828
+ const _ = rt.current;
829
+ _.stampCenter = g, u.preventDefault(), u.stopPropagation(), P();
877
830
  return;
878
831
  }
879
- const S = nt.current;
880
- if (!(!S.isDrawing || S.pointerId !== c.pointerId)) {
881
- if (c.preventDefault(), c.stopPropagation(), e === "freehand") {
882
- const v = s.current, N = Math.max(1e-6, v?.getViewState?.().zoom ?? 1), T = tn / N, _ = T * T, G = S.points[S.points.length - 1];
832
+ const M = rt.current;
833
+ if (!(!M.isDrawing || M.pointerId !== u.pointerId)) {
834
+ if (u.preventDefault(), u.stopPropagation(), e === "freehand") {
835
+ const _ = s.current, A = Math.max(1e-6, _?.getViewState?.().zoom ?? 1), C = yn / A, I = C * C, G = M.points[M.points.length - 1];
883
836
  if (!G)
884
- S.points.push(m);
837
+ M.points.push(g);
885
838
  else {
886
- const tt = m[0] - G[0], dt = m[1] - G[1];
887
- tt * tt + dt * dt >= _ && S.points.push(m);
839
+ const it = g[0] - G[0], ot = g[1] - G[1];
840
+ it * it + ot * ot >= I && M.points.push(g);
888
841
  }
889
842
  } else
890
- S.current = m;
891
- R();
843
+ M.current = g;
844
+ P();
892
845
  }
893
846
  },
894
- [H, e, st, R, s]
895
- ), q = D(
896
- (c) => {
897
- const m = nt.current;
898
- if (!m.isDrawing || m.pointerId !== c.pointerId) return;
899
- c.preventDefault(), c.stopPropagation();
900
- const S = Y.current;
901
- if (S && S.hasPointerCapture(c.pointerId))
847
+ [V, e, $, P, s]
848
+ ), vt = D(
849
+ (u) => {
850
+ const g = rt.current;
851
+ if (!g.isDrawing || g.pointerId !== u.pointerId) return;
852
+ u.preventDefault(), u.stopPropagation();
853
+ const M = lt.current;
854
+ if (M && M.hasPointerCapture(u.pointerId))
902
855
  try {
903
- S.releasePointerCapture(c.pointerId);
856
+ M.releasePointerCapture(u.pointerId);
904
857
  } catch {
905
858
  }
906
- ft();
859
+ Q();
907
860
  },
908
- [ft]
909
- ), Q = D(() => {
910
- if (!Yt(e)) return;
911
- const c = nt.current;
912
- c.stampCenter && (c.stampCenter = null, R());
913
- }, [e, R]);
914
- return L(() => {
915
- E(), R();
916
- const c = Y.current;
917
- if (!c) return;
918
- const m = new ResizeObserver(() => {
919
- E(), R();
861
+ [Q]
862
+ ), bt = D(() => {
863
+ if (!Zt(e)) return;
864
+ const u = rt.current;
865
+ u.stampCenter && (u.stampCenter = null, P());
866
+ }, [e, P]);
867
+ return z(() => {
868
+ tt(), P();
869
+ const u = lt.current;
870
+ if (!u) return;
871
+ const g = new ResizeObserver(() => {
872
+ tt(), P();
920
873
  });
921
- return m.observe(c), () => {
922
- m.disconnect();
874
+ return g.observe(u), () => {
875
+ g.disconnect();
923
876
  };
924
- }, [E, R]), L(() => {
925
- H || W(), R();
926
- }, [H, R, W]), L(() => {
927
- ht.current !== e && (ht.current = e, W(), R());
928
- }, [e, W, R]), L(() => {
929
- R();
930
- }, [u, V, x, R]), L(() => {
931
- if (z)
932
- return z.current = R, () => {
933
- z.current === R && (z.current = null);
877
+ }, [tt, P]), z(() => {
878
+ V || Y(), P();
879
+ }, [V, P, Y]), z(() => {
880
+ J.current !== e && (J.current = e, Y(), P());
881
+ }, [e, Y, P]), z(() => {
882
+ P();
883
+ }, [h, ht, R, P]), z(() => {
884
+ if (X)
885
+ return X.current = P, () => {
886
+ X.current === P && (X.current = null);
934
887
  };
935
- }, [z, R]), L(() => {
936
- if (!H) return;
937
- const c = (m) => {
938
- m.key === "Escape" && (W(), R());
888
+ }, [X, P]), z(() => {
889
+ if (!V) return;
890
+ const u = (g) => {
891
+ g.key === "Escape" && (Y(), P());
939
892
  };
940
- return window.addEventListener("keydown", c), () => {
941
- window.removeEventListener("keydown", c);
893
+ return window.addEventListener("keydown", u), () => {
894
+ window.removeEventListener("keydown", u);
942
895
  };
943
- }, [H, W, R]), /* @__PURE__ */ Et(
896
+ }, [V, Y, P]), /* @__PURE__ */ Mt(
944
897
  "canvas",
945
898
  {
946
- ref: Y,
947
- className: wt,
948
- style: P,
949
- onPointerDown: K,
950
- onPointerMove: rt,
951
- onPointerUp: q,
952
- onPointerCancel: q,
953
- onPointerLeave: Q,
954
- onContextMenu: (c) => {
955
- H && c.preventDefault();
899
+ ref: lt,
900
+ className: At,
901
+ style: gt,
902
+ onPointerDown: Lt,
903
+ onPointerMove: Tt,
904
+ onPointerUp: vt,
905
+ onPointerCancel: vt,
906
+ onPointerLeave: bt,
907
+ onContextMenu: (u) => {
908
+ V && u.preventDefault();
956
909
  },
957
- onWheel: (c) => {
958
- H && c.preventDefault();
910
+ onWheel: (u) => {
911
+ V && u.preventDefault();
959
912
  }
960
913
  }
961
914
  );
962
915
  }
963
- function Pe(e) {
916
+ function Ne(e) {
964
917
  return String(e ?? "").replace(/\/+$/, "");
965
918
  }
966
- function De(e) {
919
+ function He(e) {
967
920
  const t = String(e ?? "");
968
921
  return t.startsWith("/") ? t : `/${t}`;
969
922
  }
970
- function mn(e) {
971
- const t = Pe(e);
923
+ function Bn(e) {
924
+ const t = Ne(e);
972
925
  if (!t) return "";
973
926
  if (/\/TileGroup\d+$/i.test(t)) return t;
974
927
  let n = null;
@@ -978,41 +931,41 @@ function mn(e) {
978
931
  n = null;
979
932
  }
980
933
  if (n) {
981
- const r = `${n.protocol}//${n.host}`, i = Pe(n.pathname || "");
934
+ const r = `${n.protocol}//${n.host}`, i = Ne(n.pathname || "");
982
935
  return /\/ims$/i.test(i) ? `${r}${i}` : /\/tiles$/i.test(i) ? `${r}${i}` : `${r}${i}/tiles`;
983
936
  }
984
937
  return /\/ims$/i.test(t) ? "/ims" : /\/tiles$/i.test(t) ? `${t}` : `${t}/tiles`;
985
938
  }
986
- function nr(e, t) {
987
- 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), l = String(n.path ?? e?.path ?? ""), u = Number(n.mpp ?? e?.mpp ?? 0);
988
- if (!i || !o || !s || !l)
939
+ function wr(e, t) {
940
+ 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 ?? ""), l = Number(n.mpp ?? e?.mpp ?? 0);
941
+ if (!i || !o || !s || !c)
989
942
  throw new Error("이미지 메타데이터가 불완전합니다. width/height/tileSize/path 확인 필요");
990
943
  const h = Array.isArray(e?.terms) ? e.terms.map((y) => ({
991
944
  termId: String(y?.termId ?? ""),
992
945
  termName: String(y?.termName ?? ""),
993
946
  termColor: String(y?.termColor ?? "")
994
- })) : [], p = De(l), d = mn(t), g = r ? (y, b, x) => `${d}${p}/${y}/${x}_${b}.webp` : void 0;
947
+ })) : [], w = He(c), f = Bn(t), m = r ? (y, b, v) => `${f}${w}/${y}/${v}_${b}.webp` : void 0;
995
948
  return {
996
949
  id: e?._id || "unknown",
997
950
  name: e?.name || "unknown",
998
951
  width: i,
999
952
  height: o,
1000
- mpp: Number.isFinite(u) && u > 0 ? u : void 0,
953
+ mpp: Number.isFinite(l) && l > 0 ? l : void 0,
1001
954
  tileSize: s,
1002
955
  maxTierZoom: Number.isFinite(a) ? Math.max(0, Math.floor(a)) : 0,
1003
- tilePath: l,
956
+ tilePath: c,
1004
957
  tileBaseUrl: t,
1005
958
  terms: h,
1006
- tileUrlBuilder: g
959
+ tileUrlBuilder: m
1007
960
  };
1008
961
  }
1009
- function Le(e, t, n, r) {
962
+ function Ze(e, t, n, r) {
1010
963
  if (e.tileUrlBuilder)
1011
964
  return e.tileUrlBuilder(t, n, r);
1012
- const i = De(e.tilePath);
965
+ const i = He(e.tilePath);
1013
966
  return `${e.tileBaseUrl}${i}/${t}/${r}_${n}.webp`;
1014
967
  }
1015
- const mt = {
968
+ const pt = {
1016
969
  width: 220,
1017
970
  height: 140,
1018
971
  margin: 16,
@@ -1027,13 +980,13 @@ const mt = {
1027
980
  showThumbnail: !0,
1028
981
  maxThumbnailTiles: 16
1029
982
  };
1030
- function Ut(e, t, n = 1) {
983
+ function Xt(e, t, n = 1) {
1031
984
  return typeof e != "number" || !Number.isFinite(e) ? t : Math.max(n, e);
1032
985
  }
1033
- function Xt(e) {
986
+ function Kt(e) {
1034
987
  return Array.isArray(e) && e.length === 4 && Number.isFinite(e[0]) && Number.isFinite(e[1]) && Number.isFinite(e[2]) && Number.isFinite(e[3]);
1035
988
  }
1036
- function gn({
989
+ function Un({
1037
990
  source: e,
1038
991
  projectorRef: t,
1039
992
  authToken: n = "",
@@ -1042,253 +995,253 @@ function gn({
1042
995
  className: o,
1043
996
  style: s
1044
997
  }) {
1045
- const a = $(null), l = $(null), u = $(null), h = $({
998
+ const a = Z(null), c = Z(null), l = Z(null), h = Z({
1046
999
  active: !1,
1047
1000
  pointerId: null
1048
- }), p = $(null), d = $(!1), g = Ut(
1001
+ }), w = Z(null), f = Z(!1), m = Xt(
1049
1002
  r?.width,
1050
- mt.width,
1003
+ pt.width,
1051
1004
  64
1052
- ), y = Ut(
1005
+ ), y = Xt(
1053
1006
  r?.height,
1054
- mt.height,
1007
+ pt.height,
1055
1008
  48
1056
- ), b = Ut(
1009
+ ), b = Xt(
1057
1010
  r?.margin,
1058
- mt.margin,
1011
+ pt.margin,
1059
1012
  0
1060
- ), x = Ut(
1013
+ ), v = Xt(
1061
1014
  r?.borderRadius,
1062
- mt.borderRadius,
1015
+ pt.borderRadius,
1063
1016
  0
1064
- ), A = Ut(
1017
+ ), S = Xt(
1065
1018
  r?.borderWidth,
1066
- mt.borderWidth,
1019
+ pt.borderWidth,
1067
1020
  0
1068
- ), F = Math.max(
1021
+ ), L = Math.max(
1069
1022
  1,
1070
1023
  Math.round(
1071
- Ut(
1024
+ Xt(
1072
1025
  r?.maxThumbnailTiles,
1073
- mt.maxThumbnailTiles,
1026
+ pt.maxThumbnailTiles,
1074
1027
  1
1075
1028
  )
1076
1029
  )
1077
- ), C = r?.backgroundColor || mt.backgroundColor, z = r?.borderColor || mt.borderColor, wt = r?.viewportStrokeColor || mt.viewportStrokeColor, lt = r?.viewportFillColor || mt.viewportFillColor, Y = r?.interactive ?? mt.interactive, yt = r?.showThumbnail ?? mt.showThumbnail, ht = r?.position || mt.position, nt = et(() => {
1078
- const P = {};
1079
- return ht === "top-left" || ht === "bottom-left" ? P.left = b : P.right = b, ht === "top-left" || ht === "top-right" ? P.top = b : P.bottom = b, {
1030
+ ), R = r?.backgroundColor || pt.backgroundColor, W = r?.borderColor || pt.borderColor, yt = r?.viewportStrokeColor || pt.viewportStrokeColor, st = r?.viewportFillColor || pt.viewportFillColor, X = r?.interactive ?? pt.interactive, At = r?.showThumbnail ?? pt.showThumbnail, mt = r?.position || pt.position, lt = H(() => {
1031
+ const x = {};
1032
+ return mt === "top-left" || mt === "bottom-left" ? x.left = b : x.right = b, mt === "top-left" || mt === "top-right" ? x.top = b : x.bottom = b, {
1080
1033
  position: "absolute",
1081
- ...P,
1082
- width: g,
1034
+ ...x,
1035
+ width: m,
1083
1036
  height: y,
1084
- borderRadius: x,
1037
+ borderRadius: v,
1085
1038
  overflow: "hidden",
1086
1039
  zIndex: 4,
1087
- pointerEvents: Y ? "auto" : "none",
1040
+ pointerEvents: X ? "auto" : "none",
1088
1041
  touchAction: "none",
1089
1042
  boxShadow: "0 10px 22px rgba(0, 0, 0, 0.3)",
1090
1043
  ...s
1091
1044
  };
1092
- }, [b, ht, g, y, x, Y, s]), H = D(() => {
1093
- const P = a.current;
1094
- if (!P) return;
1095
- const E = P.getContext("2d");
1096
- if (!E) return;
1097
- const M = g, I = y, O = Math.max(1, window.devicePixelRatio || 1), it = Math.max(1, Math.round(M * O)), ot = Math.max(1, Math.round(I * O));
1098
- (P.width !== it || P.height !== ot) && (P.width = it, P.height = ot), E.setTransform(1, 0, 0, 1, 0, 0), E.clearRect(0, 0, P.width, P.height), E.setTransform(O, 0, 0, O, 0, 0), E.fillStyle = C, E.fillRect(0, 0, M, I);
1099
- const R = l.current;
1100
- R && E.drawImage(R, 0, 0, M, I), E.strokeStyle = z, E.lineWidth = A, E.strokeRect(
1101
- A * 0.5,
1102
- A * 0.5,
1103
- M - A,
1104
- I - A
1045
+ }, [b, mt, m, y, v, X, s]), Rt = D(() => {
1046
+ const x = a.current;
1047
+ if (!x) return;
1048
+ const T = x.getContext("2d");
1049
+ if (!T) return;
1050
+ const E = m, k = y, O = Math.max(1, window.devicePixelRatio || 1), gt = Math.max(1, Math.round(E * O)), tt = Math.max(1, Math.round(k * O));
1051
+ (x.width !== gt || x.height !== tt) && (x.width = gt, x.height = tt), T.setTransform(1, 0, 0, 1, 0, 0), T.clearRect(0, 0, x.width, x.height), T.setTransform(O, 0, 0, O, 0, 0), T.fillStyle = R, T.fillRect(0, 0, E, k);
1052
+ const q = c.current;
1053
+ q && T.drawImage(q, 0, 0, E, k), T.strokeStyle = W, T.lineWidth = S, T.strokeRect(
1054
+ S * 0.5,
1055
+ S * 0.5,
1056
+ E - S,
1057
+ k - S
1105
1058
  );
1106
- const W = t.current, st = W?.getViewBounds?.(), ft = W?.getViewCorners?.(), X = Xt(st) ? st : Xt(u.current) ? u.current : null;
1107
- if (!X) return;
1108
- u.current = X;
1109
- const K = M / Math.max(1, e.width), rt = I / Math.max(1, e.height), q = Array.isArray(ft) && ft.length >= 4 && ft.every(
1110
- (T) => Array.isArray(T) && T.length >= 2 && Number.isFinite(T[0]) && Number.isFinite(T[1])
1111
- ) ? ft : null;
1112
- if (q) {
1113
- E.beginPath();
1114
- for (let T = 0; T < q.length; T += 1) {
1115
- const _ = q[T], G = Z(_[0] * K, 0, M), tt = Z(_[1] * rt, 0, I);
1116
- T === 0 ? E.moveTo(G, tt) : E.lineTo(G, tt);
1059
+ const et = t.current, ct = et?.getViewBounds?.(), ut = et?.getViewCorners?.(), U = Kt(ct) ? ct : Kt(l.current) ? l.current : null;
1060
+ if (!U) return;
1061
+ l.current = U;
1062
+ const P = E / Math.max(1, e.width), Y = k / Math.max(1, e.height), $ = Array.isArray(ut) && ut.length >= 4 && ut.every(
1063
+ (u) => Array.isArray(u) && u.length >= 2 && Number.isFinite(u[0]) && Number.isFinite(u[1])
1064
+ ) ? ut : null;
1065
+ if ($) {
1066
+ T.beginPath();
1067
+ for (let u = 0; u < $.length; u += 1) {
1068
+ const g = $[u], M = j(g[0] * P, 0, E), _ = j(g[1] * Y, 0, k);
1069
+ u === 0 ? T.moveTo(M, _) : T.lineTo(M, _);
1117
1070
  }
1118
- E.closePath(), E.fillStyle = lt, E.fill(), E.strokeStyle = wt, E.lineWidth = 1.5, E.stroke();
1071
+ T.closePath(), T.fillStyle = st, T.fill(), T.strokeStyle = yt, T.lineWidth = 1.5, T.stroke();
1119
1072
  return;
1120
1073
  }
1121
- const Q = Z(X[0] * K, 0, M), c = Z(X[1] * rt, 0, I), m = Z(X[2] * K, 0, M), S = Z(X[3] * rt, 0, I), v = Math.max(1, m - Q), N = Math.max(1, S - c);
1122
- E.fillStyle = lt, E.fillRect(Q, c, v, N), E.strokeStyle = wt, E.lineWidth = 1.5, E.strokeRect(
1074
+ const Q = j(U[0] * P, 0, E), dt = j(U[1] * Y, 0, k), Lt = j(U[2] * P, 0, E), Tt = j(U[3] * Y, 0, k), vt = Math.max(1, Lt - Q), bt = Math.max(1, Tt - dt);
1075
+ T.fillStyle = st, T.fillRect(Q, dt, vt, bt), T.strokeStyle = yt, T.lineWidth = 1.5, T.strokeRect(
1123
1076
  Q + 0.5,
1124
- c + 0.5,
1125
- Math.max(1, v - 1),
1126
- Math.max(1, N - 1)
1077
+ dt + 0.5,
1078
+ Math.max(1, vt - 1),
1079
+ Math.max(1, bt - 1)
1127
1080
  );
1128
1081
  }, [
1129
- g,
1082
+ m,
1130
1083
  y,
1131
- C,
1132
- z,
1133
- A,
1084
+ R,
1085
+ W,
1086
+ S,
1134
1087
  t,
1135
1088
  e.width,
1136
1089
  e.height,
1137
- lt,
1138
- wt
1139
- ]), V = D(() => {
1140
- d.current || (d.current = !0, p.current = requestAnimationFrame(() => {
1141
- d.current = !1, p.current = null, H();
1090
+ st,
1091
+ yt
1092
+ ]), J = D(() => {
1093
+ f.current || (f.current = !0, w.current = requestAnimationFrame(() => {
1094
+ f.current = !1, w.current = null, Rt();
1142
1095
  }));
1143
- }, [H]), J = D(
1144
- (P, E) => {
1145
- const M = a.current;
1146
- if (!M) return null;
1147
- const I = M.getBoundingClientRect();
1148
- if (!I.width || !I.height) return null;
1149
- const O = Z((P - I.left) / I.width, 0, 1), it = Z((E - I.top) / I.height, 0, 1);
1150
- return [O * e.width, it * e.height];
1096
+ }, [Rt]), rt = D(
1097
+ (x, T) => {
1098
+ const E = a.current;
1099
+ if (!E) return null;
1100
+ const k = E.getBoundingClientRect();
1101
+ if (!k.width || !k.height) return null;
1102
+ const O = j((x - k.left) / k.width, 0, 1), gt = j((T - k.top) / k.height, 0, 1);
1103
+ return [O * e.width, gt * e.height];
1151
1104
  },
1152
1105
  [e.width, e.height]
1153
- ), vt = D(
1154
- (P, E) => {
1155
- const M = t.current;
1156
- if (!M) return;
1157
- if (M.setViewCenter) {
1158
- M.setViewCenter(P, E), V();
1106
+ ), V = D(
1107
+ (x, T) => {
1108
+ const E = t.current;
1109
+ if (!E) return;
1110
+ if (E.setViewCenter) {
1111
+ E.setViewCenter(x, T), J();
1159
1112
  return;
1160
1113
  }
1161
- const I = M.getViewBounds?.(), O = Xt(I) ? I : Xt(u.current) ? u.current : null;
1114
+ const k = E.getViewBounds?.(), O = Kt(k) ? k : Kt(l.current) ? l.current : null;
1162
1115
  if (!O) return;
1163
- const it = Math.max(1e-6, O[2] - O[0]), ot = Math.max(1e-6, O[3] - O[1]);
1164
- M.setViewState({
1165
- offsetX: P - it * 0.5,
1166
- offsetY: E - ot * 0.5
1167
- }), V();
1116
+ const gt = Math.max(1e-6, O[2] - O[0]), tt = Math.max(1e-6, O[3] - O[1]);
1117
+ E.setViewState({
1118
+ offsetX: x - gt * 0.5,
1119
+ offsetY: T - tt * 0.5
1120
+ }), J();
1168
1121
  },
1169
- [t, V]
1170
- ), xt = D(
1171
- (P) => {
1172
- if (!Y || P.button !== 0) return;
1173
- const E = a.current;
1174
- if (!E) return;
1175
- const M = J(P.clientX, P.clientY);
1176
- M && (P.preventDefault(), P.stopPropagation(), E.setPointerCapture(P.pointerId), h.current = { active: !0, pointerId: P.pointerId }, vt(M[0], M[1]));
1122
+ [t, J]
1123
+ ), ht = D(
1124
+ (x) => {
1125
+ if (!X || x.button !== 0) return;
1126
+ const T = a.current;
1127
+ if (!T) return;
1128
+ const E = rt(x.clientX, x.clientY);
1129
+ E && (x.preventDefault(), x.stopPropagation(), T.setPointerCapture(x.pointerId), h.current = { active: !0, pointerId: x.pointerId }, V(E[0], E[1]));
1177
1130
  },
1178
- [Y, J, vt]
1179
- ), ut = D(
1180
- (P) => {
1181
- const E = h.current;
1182
- if (!E.active || E.pointerId !== P.pointerId) return;
1183
- const M = J(P.clientX, P.clientY);
1184
- M && (P.preventDefault(), P.stopPropagation(), vt(M[0], M[1]));
1131
+ [X, rt, V]
1132
+ ), Ct = D(
1133
+ (x) => {
1134
+ const T = h.current;
1135
+ if (!T.active || T.pointerId !== x.pointerId) return;
1136
+ const E = rt(x.clientX, x.clientY);
1137
+ E && (x.preventDefault(), x.stopPropagation(), V(E[0], E[1]));
1185
1138
  },
1186
- [J, vt]
1187
- ), Tt = D(
1188
- (P) => {
1189
- const E = h.current;
1190
- if (!E.active || E.pointerId !== P.pointerId) return;
1191
- const M = a.current;
1192
- if (M && M.hasPointerCapture(P.pointerId))
1139
+ [rt, V]
1140
+ ), at = D(
1141
+ (x) => {
1142
+ const T = h.current;
1143
+ if (!T.active || T.pointerId !== x.pointerId) return;
1144
+ const E = a.current;
1145
+ if (E && E.hasPointerCapture(x.pointerId))
1193
1146
  try {
1194
- M.releasePointerCapture(P.pointerId);
1147
+ E.releasePointerCapture(x.pointerId);
1195
1148
  } catch {
1196
1149
  }
1197
- h.current = { active: !1, pointerId: null }, V();
1150
+ h.current = { active: !1, pointerId: null }, J();
1198
1151
  },
1199
- [V]
1152
+ [J]
1200
1153
  );
1201
- return L(() => {
1202
- let P = !1;
1203
- l.current = null, V();
1204
- const E = 0, M = 2 ** (e.maxTierZoom - E), I = Math.ceil(e.width / M), O = Math.ceil(e.height / M), it = Math.max(1, Math.ceil(I / e.tileSize)), ot = Math.max(1, Math.ceil(O / e.tileSize)), R = it * ot;
1205
- if (!yt || R > F)
1154
+ return z(() => {
1155
+ let x = !1;
1156
+ c.current = null, J();
1157
+ const T = 0, E = 2 ** (e.maxTierZoom - T), k = Math.ceil(e.width / E), O = Math.ceil(e.height / E), gt = Math.max(1, Math.ceil(k / e.tileSize)), tt = Math.max(1, Math.ceil(O / e.tileSize)), q = gt * tt;
1158
+ if (!At || q > L)
1206
1159
  return;
1207
- const W = document.createElement("canvas");
1208
- W.width = Math.max(1, Math.round(g)), W.height = Math.max(1, Math.round(y));
1209
- const st = W.getContext("2d");
1210
- if (!st)
1160
+ const et = document.createElement("canvas");
1161
+ et.width = Math.max(1, Math.round(m)), et.height = Math.max(1, Math.round(y));
1162
+ const ct = et.getContext("2d");
1163
+ if (!ct)
1211
1164
  return;
1212
- st.fillStyle = C, st.fillRect(0, 0, W.width, W.height);
1213
- const ft = [];
1214
- for (let X = 0; X < ot; X += 1)
1215
- for (let K = 0; K < it; K += 1) {
1216
- const rt = K * e.tileSize * M, q = X * e.tileSize * M, Q = Math.min((K + 1) * e.tileSize, I) * M, c = Math.min((X + 1) * e.tileSize, O) * M;
1217
- ft.push({
1218
- url: Le(e, E, K, X),
1219
- bounds: [rt, q, Q, c]
1165
+ ct.fillStyle = R, ct.fillRect(0, 0, et.width, et.height);
1166
+ const ut = [];
1167
+ for (let U = 0; U < tt; U += 1)
1168
+ for (let P = 0; P < gt; P += 1) {
1169
+ const Y = P * e.tileSize * E, $ = U * e.tileSize * E, Q = Math.min((P + 1) * e.tileSize, k) * E, dt = Math.min((U + 1) * e.tileSize, O) * E;
1170
+ ut.push({
1171
+ url: Ze(e, T, P, U),
1172
+ bounds: [Y, $, Q, dt]
1220
1173
  });
1221
1174
  }
1222
1175
  return Promise.allSettled(
1223
- ft.map(async (X) => {
1224
- const K = !!n, rt = await fetch(X.url, {
1225
- headers: K ? { Authorization: n } : void 0
1176
+ ut.map(async (U) => {
1177
+ const P = !!n, Y = await fetch(U.url, {
1178
+ headers: P ? { Authorization: n } : void 0
1226
1179
  });
1227
- if (!rt.ok)
1228
- throw new Error(`HTTP ${rt.status}`);
1229
- const q = await createImageBitmap(await rt.blob());
1230
- return { tile: X, bitmap: q };
1180
+ if (!Y.ok)
1181
+ throw new Error(`HTTP ${Y.status}`);
1182
+ const $ = await createImageBitmap(await Y.blob());
1183
+ return { tile: U, bitmap: $ };
1231
1184
  })
1232
- ).then((X) => {
1233
- if (P) {
1234
- for (const q of X)
1235
- q.status === "fulfilled" && q.value.bitmap.close();
1185
+ ).then((U) => {
1186
+ if (x) {
1187
+ for (const $ of U)
1188
+ $.status === "fulfilled" && $.value.bitmap.close();
1236
1189
  return;
1237
1190
  }
1238
- const K = W.width / Math.max(1, e.width), rt = W.height / Math.max(1, e.height);
1239
- for (const q of X) {
1240
- if (q.status !== "fulfilled") continue;
1191
+ const P = et.width / Math.max(1, e.width), Y = et.height / Math.max(1, e.height);
1192
+ for (const $ of U) {
1193
+ if ($.status !== "fulfilled") continue;
1241
1194
  const {
1242
1195
  tile: { bounds: Q },
1243
- bitmap: c
1244
- } = q.value, m = Q[0] * K, S = Q[1] * rt, v = Math.max(1, (Q[2] - Q[0]) * K), N = Math.max(1, (Q[3] - Q[1]) * rt);
1245
- st.drawImage(c, m, S, v, N), c.close();
1196
+ bitmap: dt
1197
+ } = $.value, Lt = Q[0] * P, Tt = Q[1] * Y, vt = Math.max(1, (Q[2] - Q[0]) * P), bt = Math.max(1, (Q[3] - Q[1]) * Y);
1198
+ ct.drawImage(dt, Lt, Tt, vt, bt), dt.close();
1246
1199
  }
1247
- l.current = W, V();
1200
+ c.current = et, J();
1248
1201
  }), () => {
1249
- P = !0;
1202
+ x = !0;
1250
1203
  };
1251
1204
  }, [
1252
1205
  e,
1253
1206
  n,
1254
- g,
1207
+ m,
1255
1208
  y,
1256
- C,
1257
- yt,
1258
- F,
1259
- V
1260
- ]), L(() => {
1261
- V();
1262
- }, [V]), L(() => {
1209
+ R,
1210
+ At,
1211
+ L,
1212
+ J
1213
+ ]), z(() => {
1214
+ J();
1215
+ }, [J]), z(() => {
1263
1216
  if (i)
1264
- return i.current = V, () => {
1265
- i.current === V && (i.current = null);
1217
+ return i.current = J, () => {
1218
+ i.current === J && (i.current = null);
1266
1219
  };
1267
- }, [i, V]), L(
1220
+ }, [i, J]), z(
1268
1221
  () => () => {
1269
- h.current = { active: !1, pointerId: null }, p.current !== null && (cancelAnimationFrame(p.current), p.current = null), d.current = !1;
1222
+ h.current = { active: !1, pointerId: null }, w.current !== null && (cancelAnimationFrame(w.current), w.current = null), f.current = !1;
1270
1223
  },
1271
1224
  []
1272
- ), /* @__PURE__ */ Et(
1225
+ ), /* @__PURE__ */ Mt(
1273
1226
  "canvas",
1274
1227
  {
1275
1228
  ref: a,
1276
1229
  className: o,
1277
- style: nt,
1278
- onPointerDown: xt,
1279
- onPointerMove: ut,
1280
- onPointerUp: Tt,
1281
- onPointerCancel: Tt,
1282
- onContextMenu: (P) => {
1283
- P.preventDefault();
1230
+ style: lt,
1231
+ onPointerDown: ht,
1232
+ onPointerMove: Ct,
1233
+ onPointerUp: at,
1234
+ onPointerCancel: at,
1235
+ onContextMenu: (x) => {
1236
+ x.preventDefault();
1284
1237
  },
1285
- onWheel: (P) => {
1286
- P.preventDefault(), P.stopPropagation();
1238
+ onWheel: (x) => {
1239
+ x.preventDefault(), x.stopPropagation();
1287
1240
  }
1288
1241
  }
1289
1242
  );
1290
1243
  }
1291
- function rr({
1244
+ function br({
1292
1245
  imageWidth: e,
1293
1246
  imageHeight: t,
1294
1247
  tiles: n,
@@ -1296,16 +1249,16 @@ function rr({
1296
1249
  className: i,
1297
1250
  style: o
1298
1251
  }) {
1299
- const s = $(null), a = $(null), l = et(
1252
+ const s = Z(null), a = Z(null), c = H(
1300
1253
  () => ({ width: "100%", height: "100%", display: "block", ...o }),
1301
1254
  [o]
1302
1255
  );
1303
- return L(() => {
1304
- const u = s.current;
1305
- if (!u)
1256
+ return z(() => {
1257
+ const l = s.current;
1258
+ if (!l)
1306
1259
  return;
1307
- const h = new Ke({
1308
- canvas: u,
1260
+ const h = new gn({
1261
+ canvas: l,
1309
1262
  imageWidth: e,
1310
1263
  imageHeight: t,
1311
1264
  initialViewState: r
@@ -1313,69 +1266,96 @@ function rr({
1313
1266
  return a.current = h, h.setTiles(n), () => {
1314
1267
  h.destroy(), a.current = null;
1315
1268
  };
1316
- }, [e, t]), L(() => {
1317
- const u = a.current;
1318
- u && u.setTiles(n);
1319
- }, [n]), L(() => {
1320
- const u = a.current;
1321
- !u || !r || u.setViewState(r);
1322
- }, [r]), /* @__PURE__ */ Et("canvas", { ref: s, className: i, style: l });
1269
+ }, [e, t]), z(() => {
1270
+ const l = a.current;
1271
+ l && l.setTiles(n);
1272
+ }, [n]), z(() => {
1273
+ const l = a.current;
1274
+ !l || !r || l.setViewState(r);
1275
+ }, [r]), /* @__PURE__ */ Mt("canvas", { ref: s, className: i, style: c });
1276
+ }
1277
+ function Ke(e) {
1278
+ return Math.max(
1279
+ 0,
1280
+ Math.min(
1281
+ Math.floor(e.count ?? 0),
1282
+ Math.floor((e.positions?.length ?? 0) / 2),
1283
+ e.paletteIndices?.length ?? 0
1284
+ )
1285
+ );
1323
1286
  }
1324
- function pn(e) {
1287
+ function Fn(e) {
1325
1288
  if (!Array.isArray(e) || e.length < 3) return [];
1326
1289
  const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
1327
1290
  return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
1328
1291
  }
1329
- function bn(e) {
1292
+ function je(e) {
1330
1293
  const t = [];
1331
1294
  for (const n of e ?? []) {
1332
- const r = pn(n);
1295
+ const r = Fn(n);
1333
1296
  if (r.length < 4) continue;
1334
1297
  let i = 1 / 0, o = 1 / 0, s = -1 / 0, a = -1 / 0;
1335
- for (const [l, u] of r)
1336
- l < i && (i = l), l > s && (s = l), u < o && (o = u), u > a && (a = u);
1298
+ for (const [c, l] of r)
1299
+ c < i && (i = c), c > s && (s = c), l < o && (o = l), l > a && (a = l);
1337
1300
  !Number.isFinite(i) || !Number.isFinite(o) || t.push({ ring: r, minX: i, minY: o, maxX: s, maxY: a });
1338
1301
  }
1339
1302
  return t;
1340
1303
  }
1341
- function wn(e, t, n) {
1304
+ function Ln(e, t, n) {
1342
1305
  let r = !1;
1343
1306
  for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
1344
- const s = n[i][0], a = n[i][1], l = n[o][0], u = n[o][1];
1345
- a > t != u > t && e < (l - s) * (t - a) / (u - a || Number.EPSILON) + s && (r = !r);
1307
+ const s = n[i][0], a = n[i][1], c = n[o][0], l = n[o][1];
1308
+ a > t != l > t && e < (c - s) * (t - a) / (l - a || Number.EPSILON) + s && (r = !r);
1346
1309
  }
1347
1310
  return r;
1348
1311
  }
1349
- function yn(e, t, n) {
1312
+ function Je(e, t, n) {
1350
1313
  for (const r of n)
1351
- if (!(e < r.minX || e > r.maxX || t < r.minY || t > r.maxY) && wn(e, t, r.ring))
1314
+ if (!(e < r.minX || e > r.maxX || t < r.minY || t > r.maxY) && Ln(e, t, r.ring))
1352
1315
  return !0;
1353
1316
  return !1;
1354
1317
  }
1355
- function Kt(e, t) {
1318
+ function re(e, t) {
1356
1319
  if (!e || !e.count || !e.positions || !e.paletteIndices)
1357
1320
  return null;
1358
- const n = bn(t ?? []);
1321
+ const n = je(t ?? []);
1359
1322
  if (n.length === 0)
1360
1323
  return {
1361
1324
  count: 0,
1362
1325
  positions: new Float32Array(0),
1363
1326
  paletteIndices: new Uint16Array(0)
1364
1327
  };
1365
- const r = e.count, i = e.positions, o = e.paletteIndices, s = new Float32Array(r * 2), a = new Uint16Array(r);
1366
- let l = 0;
1367
- for (let u = 0; u < r; u += 1) {
1368
- const h = i[u * 2], p = i[u * 2 + 1];
1369
- yn(h, p, n) && (s[l * 2] = h, s[l * 2 + 1] = p, a[l] = o[u], l += 1);
1328
+ const r = Ke(e), i = e.positions, o = e.paletteIndices, s = new Float32Array(r * 2), a = new Uint16Array(r);
1329
+ let c = 0;
1330
+ for (let l = 0; l < r; l += 1) {
1331
+ const h = i[l * 2], w = i[l * 2 + 1];
1332
+ Je(h, w, n) && (s[c * 2] = h, s[c * 2 + 1] = w, a[c] = o[l], c += 1);
1370
1333
  }
1371
1334
  return {
1372
- count: l,
1373
- positions: s.subarray(0, l * 2),
1374
- paletteIndices: a.subarray(0, l)
1335
+ count: c,
1336
+ positions: s.subarray(0, c * 2),
1337
+ paletteIndices: a.subarray(0, c)
1375
1338
  };
1376
1339
  }
1377
- let Vt = null;
1378
- const xn = `
1340
+ function Dn(e, t) {
1341
+ if (!e || !e.count || !e.positions || !e.paletteIndices)
1342
+ return new Uint32Array(0);
1343
+ const n = je(t ?? []);
1344
+ if (n.length === 0)
1345
+ return new Uint32Array(0);
1346
+ const r = Ke(e);
1347
+ if (r === 0)
1348
+ return new Uint32Array(0);
1349
+ const i = e.positions, o = new Uint32Array(r);
1350
+ let s = 0;
1351
+ for (let a = 0; a < r; a += 1) {
1352
+ const c = i[a * 2], l = i[a * 2 + 1];
1353
+ Je(c, l, n) && (o[s] = a, s += 1);
1354
+ }
1355
+ return o.subarray(0, s);
1356
+ }
1357
+ let jt = null;
1358
+ const Nn = `
1379
1359
  struct Params {
1380
1360
  pointCount: u32,
1381
1361
  boundsCount: u32,
@@ -1407,21 +1387,21 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
1407
1387
  outputMask[i] = inside;
1408
1388
  }
1409
1389
  `;
1410
- function Tn() {
1390
+ function zn() {
1411
1391
  if (typeof navigator > "u") return !1;
1412
1392
  const e = navigator;
1413
1393
  return typeof e.gpu == "object" && e.gpu !== null;
1414
1394
  }
1415
- function ze() {
1416
- if (!Tn()) return null;
1395
+ function Qe() {
1396
+ if (!zn()) return null;
1417
1397
  const t = navigator.gpu;
1418
1398
  if (!t || typeof t != "object") return null;
1419
1399
  const n = t;
1420
1400
  return typeof n.requestAdapter != "function" ? null : n;
1421
1401
  }
1422
- const Ot = globalThis.GPUShaderStage?.COMPUTE ?? 4, ne = globalThis.GPUBufferUsage?.STORAGE ?? 128, Gt = globalThis.GPUBufferUsage?.COPY_DST ?? 8, vn = globalThis.GPUBufferUsage?.COPY_SRC ?? 4, Pn = globalThis.GPUBufferUsage?.UNIFORM ?? 64, En = globalThis.GPUBufferUsage?.MAP_READ ?? 1, Sn = globalThis.GPUMapMode?.READ ?? 1;
1423
- async function ir() {
1424
- const e = ze();
1402
+ const Jt = globalThis.GPUShaderStage?.COMPUTE ?? 4, le = globalThis.GPUBufferUsage?.STORAGE ?? 128, Qt = globalThis.GPUBufferUsage?.COPY_DST ?? 8, kn = globalThis.GPUBufferUsage?.COPY_SRC ?? 4, Yn = globalThis.GPUBufferUsage?.UNIFORM ?? 64, Wn = globalThis.GPUBufferUsage?.MAP_READ ?? 1, Xn = globalThis.GPUMapMode?.READ ?? 1;
1403
+ async function yr() {
1404
+ const e = Qe();
1425
1405
  if (!e)
1426
1406
  return { supported: !1, features: [] };
1427
1407
  const t = await e.requestAdapter();
@@ -1440,9 +1420,9 @@ async function ir() {
1440
1420
  }
1441
1421
  } : { supported: !1, features: [] };
1442
1422
  }
1443
- async function Mn() {
1444
- return Vt || (Vt = (async () => {
1445
- const e = ze();
1423
+ async function Vn() {
1424
+ return jt || (jt = (async () => {
1425
+ const e = Qe();
1446
1426
  if (!e) return null;
1447
1427
  const t = await e.requestAdapter();
1448
1428
  if (!t) return null;
@@ -1450,40 +1430,40 @@ async function Mn() {
1450
1430
  entries: [
1451
1431
  {
1452
1432
  binding: 0,
1453
- visibility: Ot,
1433
+ visibility: Jt,
1454
1434
  buffer: { type: "read-only-storage" }
1455
1435
  },
1456
1436
  {
1457
1437
  binding: 1,
1458
- visibility: Ot,
1438
+ visibility: Jt,
1459
1439
  buffer: { type: "read-only-storage" }
1460
1440
  },
1461
1441
  {
1462
1442
  binding: 2,
1463
- visibility: Ot,
1443
+ visibility: Jt,
1464
1444
  buffer: { type: "storage" }
1465
1445
  },
1466
1446
  {
1467
1447
  binding: 3,
1468
- visibility: Ot,
1448
+ visibility: Jt,
1469
1449
  buffer: { type: "uniform" }
1470
1450
  }
1471
1451
  ]
1472
1452
  }), i = n.createComputePipeline({
1473
1453
  layout: n.createPipelineLayout({ bindGroupLayouts: [r] }),
1474
1454
  compute: {
1475
- module: n.createShaderModule({ code: xn }),
1455
+ module: n.createShaderModule({ code: Nn }),
1476
1456
  entryPoint: "main"
1477
1457
  }
1478
1458
  });
1479
1459
  return { device: n, pipeline: i, bindGroupLayout: r };
1480
- })(), Vt);
1460
+ })(), jt);
1481
1461
  }
1482
- function qt(e, t) {
1462
+ function te(e, t) {
1483
1463
  return Math.ceil(e / t) * t;
1484
1464
  }
1485
- async function An(e, t, n) {
1486
- const r = await Mn();
1465
+ async function On(e, t, n) {
1466
+ const r = await Vn();
1487
1467
  if (!r) return null;
1488
1468
  const i = Math.max(0, Math.floor(t)), o = Math.max(0, Math.floor(n.length / 4));
1489
1469
  if (i === 0 || o === 0)
@@ -1491,103 +1471,103 @@ async function An(e, t, n) {
1491
1471
  const s = Math.min(i, Math.floor(e.length / 2));
1492
1472
  if (s === 0)
1493
1473
  return new Uint32Array(0);
1494
- const a = s * 2 * Float32Array.BYTES_PER_ELEMENT, l = o * 4 * Float32Array.BYTES_PER_ELEMENT, u = s * Uint32Array.BYTES_PER_ELEMENT, h = Number(r.device.limits.maxStorageBufferBindingSize);
1495
- if (a > h || l > h || u > h)
1474
+ const a = s * 2 * Float32Array.BYTES_PER_ELEMENT, c = o * 4 * Float32Array.BYTES_PER_ELEMENT, l = s * Uint32Array.BYTES_PER_ELEMENT, h = Number(r.device.limits.maxStorageBufferBindingSize);
1475
+ if (a > h || c > h || l > h)
1496
1476
  return null;
1497
- const p = r.device.createBuffer({
1498
- size: qt(a, 4),
1499
- usage: ne | Gt
1500
- }), d = r.device.createBuffer({
1501
- size: qt(l, 4),
1502
- usage: ne | Gt
1503
- }), g = r.device.createBuffer({
1504
- size: qt(u, 4),
1505
- usage: ne | vn
1477
+ const w = r.device.createBuffer({
1478
+ size: te(a, 4),
1479
+ usage: le | Qt
1480
+ }), f = r.device.createBuffer({
1481
+ size: te(c, 4),
1482
+ usage: le | Qt
1483
+ }), m = r.device.createBuffer({
1484
+ size: te(l, 4),
1485
+ usage: le | kn
1506
1486
  }), y = r.device.createBuffer({
1507
1487
  size: 16,
1508
- usage: Pn | Gt
1488
+ usage: Yn | Qt
1509
1489
  }), b = r.device.createBuffer({
1510
- size: qt(u, 4),
1511
- usage: Gt | En
1490
+ size: te(l, 4),
1491
+ usage: Qt | Wn
1512
1492
  });
1513
1493
  r.device.queue.writeBuffer(
1514
- p,
1494
+ w,
1515
1495
  0,
1516
1496
  e.buffer,
1517
1497
  e.byteOffset,
1518
1498
  a
1519
1499
  ), r.device.queue.writeBuffer(
1520
- d,
1500
+ f,
1521
1501
  0,
1522
1502
  n.buffer,
1523
1503
  n.byteOffset,
1524
- l
1504
+ c
1525
1505
  ), r.device.queue.writeBuffer(
1526
1506
  y,
1527
1507
  0,
1528
1508
  new Uint32Array([s, o, 0, 0])
1529
1509
  );
1530
- const x = r.device.createBindGroup({
1510
+ const v = r.device.createBindGroup({
1531
1511
  layout: r.bindGroupLayout,
1532
1512
  entries: [
1533
- { binding: 0, resource: { buffer: p } },
1534
- { binding: 1, resource: { buffer: d } },
1535
- { binding: 2, resource: { buffer: g } },
1513
+ { binding: 0, resource: { buffer: w } },
1514
+ { binding: 1, resource: { buffer: f } },
1515
+ { binding: 2, resource: { buffer: m } },
1536
1516
  { binding: 3, resource: { buffer: y } }
1537
1517
  ]
1538
- }), A = r.device.createCommandEncoder(), F = A.beginComputePass();
1539
- F.setPipeline(r.pipeline), F.setBindGroup(0, x), F.dispatchWorkgroups(Math.ceil(s / 256)), F.end(), A.copyBufferToBuffer(g, 0, b, 0, u), r.device.queue.submit([A.finish()]), await b.mapAsync(Sn);
1540
- const C = b.getMappedRange(), z = new Uint32Array(C.slice(0));
1541
- return b.unmap(), p.destroy(), d.destroy(), g.destroy(), y.destroy(), b.destroy(), z;
1518
+ }), S = r.device.createCommandEncoder(), L = S.beginComputePass();
1519
+ L.setPipeline(r.pipeline), L.setBindGroup(0, v), L.dispatchWorkgroups(Math.ceil(s / 256)), L.end(), S.copyBufferToBuffer(m, 0, b, 0, l), r.device.queue.submit([S.finish()]), await b.mapAsync(Xn);
1520
+ const R = b.getMappedRange(), W = new Uint32Array(R.slice(0));
1521
+ return b.unmap(), w.destroy(), f.destroy(), m.destroy(), y.destroy(), b.destroy(), W;
1542
1522
  }
1543
- function Pt() {
1523
+ function Et() {
1544
1524
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1545
1525
  }
1546
- function Rn(e) {
1526
+ function Gn(e) {
1547
1527
  if (!Array.isArray(e) || e.length < 3) return [];
1548
1528
  const t = e.map(([i, o]) => [i, o]), n = t[0], r = t[t.length - 1];
1549
1529
  return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
1550
1530
  }
1551
- function Cn(e) {
1531
+ function qn(e) {
1552
1532
  const t = [];
1553
1533
  for (const n of e ?? []) {
1554
- const r = Rn(n);
1534
+ const r = Gn(n);
1555
1535
  if (r.length < 4) continue;
1556
1536
  let i = 1 / 0, o = 1 / 0, s = -1 / 0, a = -1 / 0;
1557
- for (const [l, u] of r)
1558
- l < i && (i = l), l > s && (s = l), u < o && (o = u), u > a && (a = u);
1537
+ for (const [c, l] of r)
1538
+ c < i && (i = c), c > s && (s = c), l < o && (o = l), l > a && (a = l);
1559
1539
  !Number.isFinite(i) || !Number.isFinite(o) || t.push({ ring: r, minX: i, minY: o, maxX: s, maxY: a });
1560
1540
  }
1561
1541
  return t;
1562
1542
  }
1563
- function In(e, t, n) {
1543
+ function $n(e, t, n) {
1564
1544
  let r = !1;
1565
1545
  for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
1566
- const s = n[i][0], a = n[i][1], l = n[o][0], u = n[o][1];
1567
- a > t != u > t && e < (l - s) * (t - a) / (u - a || Number.EPSILON) + s && (r = !r);
1546
+ const s = n[i][0], a = n[i][1], c = n[o][0], l = n[o][1];
1547
+ a > t != l > t && e < (c - s) * (t - a) / (l - a || Number.EPSILON) + s && (r = !r);
1568
1548
  }
1569
1549
  return r;
1570
1550
  }
1571
- function Ee(e, t, n) {
1551
+ function ze(e, t, n) {
1572
1552
  for (const r of n)
1573
- if (!(e < r.minX || e > r.maxX || t < r.minY || t > r.maxY) && In(e, t, r.ring))
1553
+ if (!(e < r.minX || e > r.maxX || t < r.minY || t > r.maxY) && $n(e, t, r.ring))
1574
1554
  return !0;
1575
1555
  return !1;
1576
1556
  }
1577
- async function _n(e, t, n = {}) {
1578
- const r = Pt(), i = n.bridgeToDraw === !0;
1557
+ async function Hn(e, t, n = {}) {
1558
+ const r = Et(), i = n.bridgeToDraw === !0;
1579
1559
  if (!e || !e.count || !e.positions || !e.paletteIndices)
1580
1560
  return {
1581
1561
  data: null,
1582
1562
  meta: {
1583
1563
  mode: "hybrid-webgpu",
1584
- durationMs: Pt() - r,
1564
+ durationMs: Et() - r,
1585
1565
  usedWebGpu: !1,
1586
1566
  candidateCount: 0,
1587
1567
  bridgedToDraw: !1
1588
1568
  }
1589
1569
  };
1590
- const o = Cn(t ?? []);
1570
+ const o = qn(t ?? []);
1591
1571
  if (o.length === 0)
1592
1572
  return {
1593
1573
  data: {
@@ -1597,7 +1577,7 @@ async function _n(e, t, n = {}) {
1597
1577
  },
1598
1578
  meta: {
1599
1579
  mode: "hybrid-webgpu",
1600
- durationMs: Pt() - r,
1580
+ durationMs: Et() - r,
1601
1581
  usedWebGpu: !1,
1602
1582
  candidateCount: 0,
1603
1583
  bridgedToDraw: !1
@@ -1613,7 +1593,7 @@ async function _n(e, t, n = {}) {
1613
1593
  },
1614
1594
  meta: {
1615
1595
  mode: "hybrid-webgpu",
1616
- durationMs: Pt() - r,
1596
+ durationMs: Et() - r,
1617
1597
  usedWebGpu: !1,
1618
1598
  candidateCount: 0,
1619
1599
  bridgedToDraw: !1
@@ -1621,21 +1601,21 @@ async function _n(e, t, n = {}) {
1621
1601
  };
1622
1602
  const a = new Float32Array(o.length * 4);
1623
1603
  for (let b = 0; b < o.length; b += 1) {
1624
- const x = b * 4, A = o[b];
1625
- a[x] = A.minX, a[x + 1] = A.minY, a[x + 2] = A.maxX, a[x + 3] = A.maxY;
1604
+ const v = b * 4, S = o[b];
1605
+ a[v] = S.minX, a[v + 1] = S.minY, a[v + 2] = S.maxX, a[v + 3] = S.maxY;
1626
1606
  }
1627
- let l = null, u = !1;
1607
+ let c = null, l = !1;
1628
1608
  try {
1629
- l = await An(e.positions, s, a), u = !!l;
1609
+ c = await On(e.positions, s, a), l = !!c;
1630
1610
  } catch {
1631
- l = null, u = !1;
1611
+ c = null, l = !1;
1632
1612
  }
1633
- if (!l)
1613
+ if (!c)
1634
1614
  return {
1635
- data: Kt(e, t),
1615
+ data: re(e, t),
1636
1616
  meta: {
1637
1617
  mode: "hybrid-webgpu",
1638
- durationMs: Pt() - r,
1618
+ durationMs: Et() - r,
1639
1619
  usedWebGpu: !1,
1640
1620
  candidateCount: s,
1641
1621
  bridgedToDraw: !1
@@ -1643,12 +1623,12 @@ async function _n(e, t, n = {}) {
1643
1623
  };
1644
1624
  let h = 0;
1645
1625
  for (let b = 0; b < s; b += 1)
1646
- l[b] === 1 && (h += 1);
1647
- const p = new Uint32Array(h);
1626
+ c[b] === 1 && (h += 1);
1627
+ const w = new Uint32Array(h);
1648
1628
  if (h > 0) {
1649
1629
  let b = 0;
1650
- for (let x = 0; x < s; x += 1)
1651
- l[x] === 1 && (p[b] = x, b += 1);
1630
+ for (let v = 0; v < s; v += 1)
1631
+ c[v] === 1 && (w[b] = v, b += 1);
1652
1632
  }
1653
1633
  if (h === 0)
1654
1634
  return i ? {
@@ -1660,7 +1640,7 @@ async function _n(e, t, n = {}) {
1660
1640
  },
1661
1641
  meta: {
1662
1642
  mode: "hybrid-webgpu",
1663
- durationMs: Pt() - r,
1643
+ durationMs: Et() - r,
1664
1644
  usedWebGpu: !0,
1665
1645
  candidateCount: 0,
1666
1646
  bridgedToDraw: !0
@@ -1673,7 +1653,7 @@ async function _n(e, t, n = {}) {
1673
1653
  },
1674
1654
  meta: {
1675
1655
  mode: "hybrid-webgpu",
1676
- durationMs: Pt() - r,
1656
+ durationMs: Et() - r,
1677
1657
  usedWebGpu: !0,
1678
1658
  candidateCount: 0,
1679
1659
  bridgedToDraw: !1
@@ -1681,76 +1661,95 @@ async function _n(e, t, n = {}) {
1681
1661
  };
1682
1662
  if (i) {
1683
1663
  const b = new Uint32Array(h);
1684
- let x = 0;
1685
- for (let A = 0; A < h; A += 1) {
1686
- const F = p[A] ?? 0, C = e.positions[F * 2], z = e.positions[F * 2 + 1];
1687
- Ee(C, z, o) && (b[x] = F, x += 1);
1664
+ let v = 0;
1665
+ for (let S = 0; S < h; S += 1) {
1666
+ const L = w[S] ?? 0, R = e.positions[L * 2], W = e.positions[L * 2 + 1];
1667
+ ze(R, W, o) && (b[v] = L, v += 1);
1688
1668
  }
1689
1669
  return {
1690
1670
  data: {
1691
1671
  count: s,
1692
1672
  positions: e.positions.subarray(0, s * 2),
1693
1673
  paletteIndices: e.paletteIndices.subarray(0, s),
1694
- drawIndices: b.subarray(0, x)
1674
+ drawIndices: b.subarray(0, v)
1695
1675
  },
1696
1676
  meta: {
1697
1677
  mode: "hybrid-webgpu",
1698
- durationMs: Pt() - r,
1678
+ durationMs: Et() - r,
1699
1679
  usedWebGpu: !0,
1700
1680
  candidateCount: h,
1701
1681
  bridgedToDraw: !0
1702
1682
  }
1703
1683
  };
1704
1684
  }
1705
- const d = new Float32Array(h * 2), g = new Uint16Array(h);
1685
+ const f = new Float32Array(h * 2), m = new Uint16Array(h);
1706
1686
  let y = 0;
1707
1687
  for (let b = 0; b < h; b += 1) {
1708
- const x = p[b] ?? 0, A = e.positions[x * 2], F = e.positions[x * 2 + 1];
1709
- Ee(A, F, o) && (d[y * 2] = A, d[y * 2 + 1] = F, g[y] = e.paletteIndices[x], y += 1);
1688
+ const v = w[b] ?? 0, S = e.positions[v * 2], L = e.positions[v * 2 + 1];
1689
+ ze(S, L, o) && (f[y * 2] = S, f[y * 2 + 1] = L, m[y] = e.paletteIndices[v], y += 1);
1710
1690
  }
1711
1691
  return {
1712
1692
  data: {
1713
1693
  count: y,
1714
- positions: d.subarray(0, y * 2),
1715
- paletteIndices: g.subarray(0, y)
1694
+ positions: f.subarray(0, y * 2),
1695
+ paletteIndices: m.subarray(0, y)
1716
1696
  },
1717
1697
  meta: {
1718
1698
  mode: "hybrid-webgpu",
1719
- durationMs: Pt() - r,
1699
+ durationMs: Et() - r,
1720
1700
  usedWebGpu: !0,
1721
1701
  candidateCount: h,
1722
1702
  bridgedToDraw: !1
1723
1703
  }
1724
1704
  };
1725
1705
  }
1726
- let gt = null, se = !0, Bn = 1;
1727
- const It = /* @__PURE__ */ new Map();
1728
- function Ht() {
1706
+ let wt = null, ge = !0, tn = 1;
1707
+ const Ft = /* @__PURE__ */ new Map();
1708
+ function Ut() {
1729
1709
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1730
1710
  }
1731
- function Un() {
1732
- if (!se) return null;
1733
- if (gt) return gt;
1711
+ function en() {
1712
+ if (!ge) return null;
1713
+ if (wt) return wt;
1734
1714
  try {
1735
1715
  const e = new Worker(new URL(
1736
1716
  /* @vite-ignore */
1737
- "" + new URL("assets/roi-clip-worker-i1SE1Dpa.js", import.meta.url).href,
1717
+ "" + new URL("assets/roi-clip-worker-DdVYCepx.js", import.meta.url).href,
1738
1718
  import.meta.url
1739
1719
  ), { type: "module" });
1740
- return e.addEventListener("message", ue), e.addEventListener("error", ce), gt = e, e;
1720
+ return e.addEventListener("message", we), e.addEventListener("error", be), wt = e, e;
1741
1721
  } catch {
1742
- return se = !1, null;
1722
+ return ge = !1, null;
1743
1723
  }
1744
1724
  }
1745
- function ue(e) {
1725
+ function we(e) {
1746
1726
  const t = e.data;
1747
1727
  if (!t) return;
1748
- const n = It.get(t.id);
1728
+ const n = Ft.get(t.id);
1749
1729
  if (!n) return;
1750
- if (It.delete(t.id), t.type === "roi-clip-failure") {
1730
+ if (Ft.delete(t.id), t.type === "roi-clip-failure") {
1751
1731
  n.reject(new Error(t.error || "worker clip failed"));
1752
1732
  return;
1753
1733
  }
1734
+ if (t.type === "roi-clip-index-success") {
1735
+ if (n.kind !== "index") {
1736
+ n.reject(new Error("worker response mismatch: expected point data result"));
1737
+ return;
1738
+ }
1739
+ const a = Math.max(0, Math.floor(t.count)), c = new Uint32Array(t.indices).subarray(0, a);
1740
+ n.resolve({
1741
+ indices: c,
1742
+ meta: {
1743
+ mode: "worker",
1744
+ durationMs: Number.isFinite(t.durationMs) ? t.durationMs : Ut() - n.startMs
1745
+ }
1746
+ });
1747
+ return;
1748
+ }
1749
+ if (n.kind !== "data") {
1750
+ n.reject(new Error("worker response mismatch: expected index result"));
1751
+ return;
1752
+ }
1754
1753
  const r = Math.max(0, Math.floor(t.count)), i = new Float32Array(t.positions), o = new Uint16Array(t.paletteIndices), s = {
1755
1754
  count: r,
1756
1755
  positions: i.subarray(0, r * 2),
@@ -1760,41 +1759,41 @@ function ue(e) {
1760
1759
  data: s,
1761
1760
  meta: {
1762
1761
  mode: "worker",
1763
- durationMs: Number.isFinite(t.durationMs) ? t.durationMs : Ht() - n.startMs
1762
+ durationMs: Number.isFinite(t.durationMs) ? t.durationMs : Ut() - n.startMs
1764
1763
  }
1765
1764
  });
1766
1765
  }
1767
- function ce() {
1768
- se = !1, gt && (gt.removeEventListener("message", ue), gt.removeEventListener("error", ce), gt.terminate(), gt = null);
1769
- for (const [, e] of It)
1766
+ function be() {
1767
+ ge = !1, wt && (wt.removeEventListener("message", we), wt.removeEventListener("error", be), wt.terminate(), wt = null);
1768
+ for (const [, e] of Ft)
1770
1769
  e.reject(new Error("worker crashed"));
1771
- It.clear();
1770
+ Ft.clear();
1772
1771
  }
1773
- function or() {
1774
- if (gt) {
1775
- gt.removeEventListener("message", ue), gt.removeEventListener("error", ce), gt.terminate(), gt = null;
1776
- for (const [, e] of It)
1772
+ function xr() {
1773
+ if (wt) {
1774
+ wt.removeEventListener("message", we), wt.removeEventListener("error", be), wt.terminate(), wt = null;
1775
+ for (const [, e] of Ft)
1777
1776
  e.reject(new Error("worker terminated"));
1778
- It.clear();
1777
+ Ft.clear();
1779
1778
  }
1780
1779
  }
1781
- async function Fn(e, t) {
1780
+ async function Zn(e, t) {
1782
1781
  if (!e || !e.count || !e.positions || !e.paletteIndices)
1783
1782
  return {
1784
1783
  data: null,
1785
1784
  meta: { mode: "worker", durationMs: 0 }
1786
1785
  };
1787
- const n = Un();
1786
+ const n = en();
1788
1787
  if (!n) {
1789
- const l = Ht();
1788
+ const c = Ut();
1790
1789
  return {
1791
- data: Kt(e, t),
1792
- meta: { mode: "sync", durationMs: Ht() - l }
1790
+ data: re(e, t),
1791
+ meta: { mode: "sync", durationMs: Ut() - c }
1793
1792
  };
1794
1793
  }
1795
- 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 = Bn++, a = Ht();
1796
- return new Promise((l, u) => {
1797
- It.set(s, { resolve: l, reject: u, startMs: a });
1794
+ 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 = tn++, a = Ut();
1795
+ return new Promise((c, l) => {
1796
+ Ft.set(s, { kind: "data", resolve: c, reject: l, startMs: a });
1798
1797
  const h = {
1799
1798
  type: "roi-clip-request",
1800
1799
  id: s,
@@ -1806,14 +1805,41 @@ async function Fn(e, t) {
1806
1805
  n.postMessage(h, [i.buffer, o.buffer]);
1807
1806
  });
1808
1807
  }
1809
- function Dn(e) {
1808
+ async function Tr(e, t) {
1809
+ if (!e || !e.count || !e.positions || !e.paletteIndices)
1810
+ return {
1811
+ indices: new Uint32Array(0),
1812
+ meta: { mode: "worker", durationMs: 0 }
1813
+ };
1814
+ const n = en();
1815
+ if (!n) {
1816
+ const a = Ut();
1817
+ return {
1818
+ indices: Dn(e, t),
1819
+ meta: { mode: "sync", durationMs: Ut() - a }
1820
+ };
1821
+ }
1822
+ 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 = tn++, s = Ut();
1823
+ return new Promise((a, c) => {
1824
+ Ft.set(o, { kind: "index", resolve: a, reject: c, startMs: s });
1825
+ const l = {
1826
+ type: "roi-clip-index-request",
1827
+ id: o,
1828
+ count: r,
1829
+ positions: i.buffer,
1830
+ polygons: t ?? []
1831
+ };
1832
+ n.postMessage(l, [i.buffer]);
1833
+ });
1834
+ }
1835
+ function Kn(e) {
1810
1836
  if (!Array.isArray(e) || e.length < 3) return [];
1811
1837
  const t = e.map(
1812
1838
  (i) => [Number(i[0]), Number(i[1])]
1813
1839
  ), n = t[0], r = t[t.length - 1];
1814
1840
  return !n || !r ? [] : ((n[0] !== r[0] || n[1] !== r[1]) && t.push([n[0], n[1]]), t);
1815
1841
  }
1816
- function Ln(e) {
1842
+ function jn(e) {
1817
1843
  let t = 0;
1818
1844
  for (let n = 0; n < e.length - 1; n += 1) {
1819
1845
  const [r, i] = e[n], [o, s] = e[n + 1];
@@ -1821,38 +1847,38 @@ function Ln(e) {
1821
1847
  }
1822
1848
  return Math.abs(t * 0.5);
1823
1849
  }
1824
- function zn(e) {
1850
+ function Jn(e) {
1825
1851
  const t = [];
1826
1852
  for (let n = 0; n < e.length; n += 1) {
1827
1853
  const r = e[n];
1828
1854
  if (!r?.coordinates?.length) continue;
1829
- const i = Dn(r.coordinates);
1855
+ const i = Kn(r.coordinates);
1830
1856
  if (i.length < 4) continue;
1831
- let o = 1 / 0, s = 1 / 0, a = -1 / 0, l = -1 / 0;
1832
- for (const [u, h] of i)
1833
- u < o && (o = u), u > a && (a = u), h < s && (s = h), h > l && (l = h);
1834
- !Number.isFinite(o) || !Number.isFinite(s) || !Number.isFinite(a) || !Number.isFinite(l) || t.push({
1857
+ let o = 1 / 0, s = 1 / 0, a = -1 / 0, c = -1 / 0;
1858
+ for (const [l, h] of i)
1859
+ l < o && (o = l), l > a && (a = l), h < s && (s = h), h > c && (c = h);
1860
+ !Number.isFinite(o) || !Number.isFinite(s) || !Number.isFinite(a) || !Number.isFinite(c) || t.push({
1835
1861
  regionId: r.id ?? n,
1836
1862
  regionIndex: n,
1837
1863
  ring: i,
1838
1864
  minX: o,
1839
1865
  minY: s,
1840
1866
  maxX: a,
1841
- maxY: l,
1842
- area: Math.max(1e-6, Ln(i))
1867
+ maxY: c,
1868
+ area: Math.max(1e-6, jn(i))
1843
1869
  });
1844
1870
  }
1845
1871
  return t;
1846
1872
  }
1847
- function Nn(e, t, n) {
1873
+ function Qn(e, t, n) {
1848
1874
  let r = !1;
1849
1875
  for (let i = 0, o = n.length - 1; i < n.length; o = i, i += 1) {
1850
- const s = n[i][0], a = n[i][1], l = n[o][0], u = n[o][1];
1851
- a > t != u > t && e < (l - s) * (t - a) / (u - a || Number.EPSILON) + s && (r = !r);
1876
+ const s = n[i][0], a = n[i][1], c = n[o][0], l = n[o][1];
1877
+ a > t != l > t && e < (c - s) * (t - a) / (l - a || Number.EPSILON) + s && (r = !r);
1852
1878
  }
1853
1879
  return r;
1854
1880
  }
1855
- function kn(e, t) {
1881
+ function tr(e, t) {
1856
1882
  if (Array.isArray(t)) {
1857
1883
  const n = t[e];
1858
1884
  if (typeof n == "string" && n.length > 0) return n;
@@ -1863,7 +1889,7 @@ function kn(e, t) {
1863
1889
  }
1864
1890
  return String(e);
1865
1891
  }
1866
- function Yn(e, t, n = {}) {
1892
+ function er(e, t, n = {}) {
1867
1893
  const r = Math.max(
1868
1894
  0,
1869
1895
  Math.min(
@@ -1874,24 +1900,24 @@ function Yn(e, t, n = {}) {
1874
1900
  );
1875
1901
  let i = null;
1876
1902
  if (e?.drawIndices instanceof Uint32Array) {
1877
- const d = e.drawIndices;
1878
- let g = d.length;
1879
- for (let y = 0; y < d.length; y += 1)
1880
- d[y] < r || (g -= 1);
1881
- if (g === d.length)
1882
- i = d;
1883
- else if (g > 0) {
1884
- const y = new Uint32Array(g);
1903
+ const f = e.drawIndices;
1904
+ let m = f.length;
1905
+ for (let y = 0; y < f.length; y += 1)
1906
+ f[y] < r || (m -= 1);
1907
+ if (m === f.length)
1908
+ i = f;
1909
+ else if (m > 0) {
1910
+ const y = new Uint32Array(m);
1885
1911
  let b = 0;
1886
- for (let x = 0; x < d.length; x += 1) {
1887
- const A = d[x];
1888
- A >= r || (y[b] = A, b += 1);
1912
+ for (let v = 0; v < f.length; v += 1) {
1913
+ const S = f[v];
1914
+ S >= r || (y[b] = S, b += 1);
1889
1915
  }
1890
1916
  i = y;
1891
1917
  } else
1892
1918
  i = new Uint32Array(0);
1893
1919
  }
1894
- const o = i ? i.length : r, s = zn(t ?? []);
1920
+ const o = i ? i.length : r, s = Jn(t ?? []);
1895
1921
  if (!e || o === 0 || s.length === 0)
1896
1922
  return {
1897
1923
  groups: [],
@@ -1899,48 +1925,48 @@ function Yn(e, t, n = {}) {
1899
1925
  pointsInsideAnyRegion: 0,
1900
1926
  unmatchedPointCount: o
1901
1927
  };
1902
- const a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
1903
- let u = 0;
1904
- for (let d = 0; d < o; d += 1) {
1905
- const g = i ? i[d] : d, y = e.positions[g * 2], b = e.positions[g * 2 + 1];
1906
- let x = null;
1907
- for (const C of s)
1908
- y < C.minX || y > C.maxX || b < C.minY || b > C.maxY || Nn(y, b, C.ring) && (!x || C.area < x.area) && (x = C);
1909
- if (!x) continue;
1910
- u += 1;
1911
- const A = e.paletteIndices[g] ?? 0, F = a.get(x.regionIndex) ?? /* @__PURE__ */ new Map();
1912
- F.set(A, (F.get(A) ?? 0) + 1), a.set(x.regionIndex, F), l.set(
1913
- x.regionIndex,
1914
- (l.get(x.regionIndex) ?? 0) + 1
1928
+ const a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
1929
+ let l = 0;
1930
+ for (let f = 0; f < o; f += 1) {
1931
+ const m = i ? i[f] : f, y = e.positions[m * 2], b = e.positions[m * 2 + 1];
1932
+ let v = null;
1933
+ for (const R of s)
1934
+ y < R.minX || y > R.maxX || b < R.minY || b > R.maxY || Qn(y, b, R.ring) && (!v || R.area < v.area) && (v = R);
1935
+ if (!v) continue;
1936
+ l += 1;
1937
+ const S = e.paletteIndices[m] ?? 0, L = a.get(v.regionIndex) ?? /* @__PURE__ */ new Map();
1938
+ L.set(S, (L.get(S) ?? 0) + 1), a.set(v.regionIndex, L), c.set(
1939
+ v.regionIndex,
1940
+ (c.get(v.regionIndex) ?? 0) + 1
1915
1941
  );
1916
1942
  }
1917
- const h = n.includeEmptyRegions ?? !1, p = [];
1918
- for (const d of s) {
1919
- const g = l.get(d.regionIndex) ?? 0;
1920
- if (!h && g <= 0) continue;
1921
- const y = a.get(d.regionIndex) ?? /* @__PURE__ */ new Map(), b = Array.from(y.entries()).map(([x, A]) => ({
1922
- termId: kn(x, n.paletteIndexToTermId),
1923
- paletteIndex: x,
1924
- count: A
1925
- })).sort((x, A) => A.count - x.count || x.paletteIndex - A.paletteIndex);
1926
- p.push({
1927
- regionId: d.regionId,
1928
- regionIndex: d.regionIndex,
1929
- totalCount: g,
1943
+ const h = n.includeEmptyRegions ?? !1, w = [];
1944
+ for (const f of s) {
1945
+ const m = c.get(f.regionIndex) ?? 0;
1946
+ if (!h && m <= 0) continue;
1947
+ const y = a.get(f.regionIndex) ?? /* @__PURE__ */ new Map(), b = Array.from(y.entries()).map(([v, S]) => ({
1948
+ termId: tr(v, n.paletteIndexToTermId),
1949
+ paletteIndex: v,
1950
+ count: S
1951
+ })).sort((v, S) => S.count - v.count || v.paletteIndex - S.paletteIndex);
1952
+ w.push({
1953
+ regionId: f.regionId,
1954
+ regionIndex: f.regionIndex,
1955
+ totalCount: m,
1930
1956
  termCounts: b
1931
1957
  });
1932
1958
  }
1933
1959
  return {
1934
- groups: p,
1960
+ groups: w,
1935
1961
  inputPointCount: o,
1936
- pointsInsideAnyRegion: u,
1937
- unmatchedPointCount: Math.max(0, o - u)
1962
+ pointsInsideAnyRegion: l,
1963
+ unmatchedPointCount: Math.max(0, o - l)
1938
1964
  };
1939
1965
  }
1940
- function $t() {
1966
+ function ee() {
1941
1967
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1942
1968
  }
1943
- function Wn(e, t) {
1969
+ function nr(e, t) {
1944
1970
  if (!t) return !1;
1945
1971
  try {
1946
1972
  const r = new URL(e, typeof window < "u" ? window.location.href : void 0).hostname.toLowerCase();
@@ -1949,25 +1975,25 @@ function Wn(e, t) {
1949
1975
  }
1950
1976
  return !0;
1951
1977
  }
1952
- class Xn {
1978
+ class rr {
1953
1979
  constructor(t) {
1954
- f(this, "maxConcurrency");
1955
- f(this, "maxRetries");
1956
- f(this, "retryBaseDelayMs");
1957
- f(this, "retryMaxDelayMs");
1958
- f(this, "onTileLoad");
1959
- f(this, "onTileError");
1960
- f(this, "onStateChange");
1961
- f(this, "authToken");
1962
- f(this, "destroyed", !1);
1963
- f(this, "queue", []);
1964
- f(this, "queuedByKey", /* @__PURE__ */ new Map());
1965
- f(this, "inflight", /* @__PURE__ */ new Map());
1966
- f(this, "visibleKeys", /* @__PURE__ */ new Set());
1967
- f(this, "timerId", null);
1968
- f(this, "abortedCount", 0);
1969
- f(this, "retryCount", 0);
1970
- f(this, "failedCount", 0);
1980
+ d(this, "maxConcurrency");
1981
+ d(this, "maxRetries");
1982
+ d(this, "retryBaseDelayMs");
1983
+ d(this, "retryMaxDelayMs");
1984
+ d(this, "onTileLoad");
1985
+ d(this, "onTileError");
1986
+ d(this, "onStateChange");
1987
+ d(this, "authToken");
1988
+ d(this, "destroyed", !1);
1989
+ d(this, "queue", []);
1990
+ d(this, "queuedByKey", /* @__PURE__ */ new Map());
1991
+ d(this, "inflight", /* @__PURE__ */ new Map());
1992
+ d(this, "visibleKeys", /* @__PURE__ */ new Set());
1993
+ d(this, "timerId", null);
1994
+ d(this, "abortedCount", 0);
1995
+ d(this, "retryCount", 0);
1996
+ d(this, "failedCount", 0);
1971
1997
  this.maxConcurrency = Math.max(1, Math.floor(t.maxConcurrency ?? 12)), this.maxRetries = Math.max(0, Math.floor(t.maxRetries ?? 2)), this.retryBaseDelayMs = Math.max(
1972
1998
  10,
1973
1999
  Math.floor(t.retryBaseDelayMs ?? 120)
@@ -1999,7 +2025,7 @@ class Xn {
1999
2025
  const o = {
2000
2026
  tile: r,
2001
2027
  attempt: 0,
2002
- readyAt: $t()
2028
+ readyAt: ee()
2003
2029
  };
2004
2030
  this.queue.push(o), this.queuedByKey.set(r.key, o);
2005
2031
  }
@@ -2055,14 +2081,14 @@ class Xn {
2055
2081
  if (this.inflight.size >= this.maxConcurrency || this.queue.length === 0) return;
2056
2082
  const t = this.queue[0]?.readyAt;
2057
2083
  if (typeof t != "number") return;
2058
- const n = Math.max(0, t - $t());
2084
+ const n = Math.max(0, t - ee());
2059
2085
  this.timerId = window.setTimeout(() => {
2060
2086
  this.timerId = null, this.pump();
2061
2087
  }, n);
2062
2088
  }
2063
2089
  takeNextReadyQueueItem() {
2064
2090
  if (this.queue.length === 0) return null;
2065
- const t = $t(), n = this.queue[0];
2091
+ const t = ee(), n = this.queue[0];
2066
2092
  return !n || n.readyAt > t ? null : (this.queue.shift(), this.queuedByKey.delete(n.tile.key), n);
2067
2093
  }
2068
2094
  startFetch(t) {
@@ -2072,7 +2098,7 @@ class Xn {
2072
2098
  controller: n
2073
2099
  };
2074
2100
  this.inflight.set(t.tile.key, r), this.emitStateChange();
2075
- const i = Wn(t.tile.url, this.authToken);
2101
+ const i = nr(t.tile.url, this.authToken);
2076
2102
  fetch(t.tile.url, {
2077
2103
  signal: n.signal,
2078
2104
  headers: i ? { Authorization: this.authToken } : void 0
@@ -2095,12 +2121,12 @@ class Xn {
2095
2121
  return;
2096
2122
  if (t.attempt < this.maxRetries && this.visibleKeys.has(t.tile.key)) {
2097
2123
  this.retryCount += 1;
2098
- const a = t.attempt + 1, l = this.getRetryDelay(a), u = {
2124
+ const a = t.attempt + 1, c = this.getRetryDelay(a), l = {
2099
2125
  tile: t.tile,
2100
2126
  attempt: a,
2101
- readyAt: $t() + l
2127
+ readyAt: ee() + c
2102
2128
  }, h = this.queuedByKey.get(t.tile.key);
2103
- h ? (h.tile = u.tile, h.readyAt = Math.min(h.readyAt, u.readyAt), h.attempt = Math.max(h.attempt, u.attempt)) : (this.queue.push(u), this.queuedByKey.set(u.tile.key, u)), this.sortQueue();
2129
+ h ? (h.tile = l.tile, h.readyAt = Math.min(h.readyAt, l.readyAt), h.attempt = Math.max(h.attempt, l.attempt)) : (this.queue.push(l), this.queuedByKey.set(l.tile.key, l)), this.sortQueue();
2104
2130
  return;
2105
2131
  }
2106
2132
  this.failedCount += 1, this.onTileError?.(t.tile, o, t.attempt + 1);
@@ -2122,12 +2148,12 @@ class Xn {
2122
2148
  this.onStateChange?.(this.getSnapshot());
2123
2149
  }
2124
2150
  }
2125
- const Se = 0.35;
2126
- class Vn {
2151
+ const ke = 0.35;
2152
+ class ir {
2127
2153
  constructor() {
2128
- f(this, "viewportWidth", 1);
2129
- f(this, "viewportHeight", 1);
2130
- f(this, "viewState", {
2154
+ d(this, "viewportWidth", 1);
2155
+ d(this, "viewportHeight", 1);
2156
+ d(this, "viewState", {
2131
2157
  zoom: 1,
2132
2158
  offsetX: 0,
2133
2159
  offsetY: 0,
@@ -2158,14 +2184,14 @@ class Vn {
2158
2184
  this.viewState.offsetX = t - this.viewportWidth / (2 * r), this.viewState.offsetY = n - this.viewportHeight / (2 * r);
2159
2185
  }
2160
2186
  screenToWorld(t, n) {
2161
- const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = (t - this.viewportWidth * 0.5) / i, l = (n - this.viewportHeight * 0.5) / i, u = Lt(r.rotationDeg), h = Math.cos(u), p = Math.sin(u);
2162
- return [o + a * h - l * p, s + a * p + l * h];
2187
+ 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, l = Gt(r.rotationDeg), h = Math.cos(l), w = Math.sin(l);
2188
+ return [o + a * h - c * w, s + a * w + c * h];
2163
2189
  }
2164
2190
  worldToScreen(t, n) {
2165
- const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = t - o, l = n - s, u = Lt(r.rotationDeg), h = Math.cos(u), p = Math.sin(u), d = a * h + l * p, g = -a * p + l * h;
2191
+ const r = this.viewState, i = Math.max(1e-6, r.zoom), [o, s] = this.getCenter(), a = t - o, c = n - s, l = Gt(r.rotationDeg), h = Math.cos(l), w = Math.sin(l), f = a * h + c * w, m = -a * w + c * h;
2166
2192
  return [
2167
- this.viewportWidth * 0.5 + d * i,
2168
- this.viewportHeight * 0.5 + g * i
2193
+ this.viewportWidth * 0.5 + f * i,
2194
+ this.viewportHeight * 0.5 + m * i
2169
2195
  ];
2170
2196
  }
2171
2197
  getViewCorners() {
@@ -2178,75 +2204,75 @@ class Vn {
2178
2204
  ];
2179
2205
  }
2180
2206
  getMatrix() {
2181
- const t = Math.max(1e-6, this.viewState.zoom), [n, r] = this.getCenter(), i = Lt(this.viewState.rotationDeg), o = Math.cos(i), s = Math.sin(i), a = 2 * t * o / this.viewportWidth, l = 2 * t * s / this.viewportWidth, u = 2 * t * s / this.viewportHeight, h = -2 * t * o / this.viewportHeight, p = -(a * n + l * r), d = -(u * n + h * r);
2182
- return new Float32Array([a, u, 0, l, h, 0, p, d, 1]);
2207
+ const t = Math.max(1e-6, this.viewState.zoom), [n, r] = this.getCenter(), i = Gt(this.viewState.rotationDeg), o = Math.cos(i), s = Math.sin(i), a = 2 * t * o / this.viewportWidth, c = 2 * t * s / this.viewportWidth, l = 2 * t * s / this.viewportHeight, h = -2 * t * o / this.viewportHeight, w = -(a * n + c * r), f = -(l * n + h * r);
2208
+ return new Float32Array([a, l, 0, c, h, 0, w, f, 1]);
2183
2209
  }
2184
2210
  }
2185
- function Lt(e) {
2211
+ function Gt(e) {
2186
2212
  return e * Math.PI / 180;
2187
2213
  }
2188
- function Me() {
2214
+ function Ye() {
2189
2215
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2190
2216
  }
2191
- function Ct(e, t, n) {
2217
+ function Nt(e, t, n) {
2192
2218
  const r = e.getUniformLocation(t, n);
2193
2219
  if (!r)
2194
2220
  throw new Error(`uniform location lookup failed: ${n}`);
2195
2221
  return r;
2196
2222
  }
2197
- function re(e, t) {
2223
+ function he(e, t) {
2198
2224
  return !e || !t ? e === t : e.buffer === t.buffer && e.byteOffset === t.byteOffset && e.byteLength === t.byteLength;
2199
2225
  }
2200
- class On {
2226
+ class or {
2201
2227
  constructor(t, n, r = {}) {
2202
- f(this, "canvas");
2203
- f(this, "source");
2204
- f(this, "gl");
2205
- f(this, "camera", new Vn());
2206
- f(this, "onViewStateChange");
2207
- f(this, "onStats");
2208
- f(this, "onTileError");
2209
- f(this, "onContextLost");
2210
- f(this, "onContextRestored");
2211
- f(this, "resizeObserver");
2212
- f(this, "tileProgram");
2213
- f(this, "pointProgram");
2214
- f(this, "tileScheduler");
2215
- f(this, "authToken");
2216
- f(this, "destroyed", !1);
2217
- f(this, "contextLost", !1);
2218
- f(this, "frame", null);
2219
- f(this, "frameSerial", 0);
2220
- f(this, "dragging", !1);
2221
- f(this, "interactionMode", "none");
2222
- f(this, "rotateLastAngleRad", null);
2223
- f(this, "pointerId", null);
2224
- f(this, "lastPointerX", 0);
2225
- f(this, "lastPointerY", 0);
2226
- f(this, "interactionLocked", !1);
2227
- f(this, "ctrlDragRotate", !0);
2228
- f(this, "rotationDragSensitivityDegPerPixel", 0.35);
2229
- f(this, "maxCacheTiles");
2230
- f(this, "fitZoom", 1);
2231
- f(this, "minZoom", 1e-6);
2232
- f(this, "maxZoom", 1);
2233
- f(this, "currentTier", 0);
2234
- f(this, "pointCount", 0);
2235
- f(this, "usePointIndices", !1);
2236
- f(this, "pointBuffersDirty", !0);
2237
- f(this, "pointPaletteSize", 1);
2238
- f(this, "lastPointData", null);
2239
- f(this, "lastPointPalette", null);
2240
- f(this, "cache", /* @__PURE__ */ new Map());
2241
- f(this, "boundPointerDown");
2242
- f(this, "boundPointerMove");
2243
- f(this, "boundPointerUp");
2244
- f(this, "boundWheel");
2245
- f(this, "boundDoubleClick");
2246
- f(this, "boundContextMenu");
2247
- f(this, "boundContextLost");
2248
- f(this, "boundContextRestored");
2249
- 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) : Se;
2228
+ d(this, "canvas");
2229
+ d(this, "source");
2230
+ d(this, "gl");
2231
+ d(this, "camera", new ir());
2232
+ d(this, "onViewStateChange");
2233
+ d(this, "onStats");
2234
+ d(this, "onTileError");
2235
+ d(this, "onContextLost");
2236
+ d(this, "onContextRestored");
2237
+ d(this, "resizeObserver");
2238
+ d(this, "tileProgram");
2239
+ d(this, "pointProgram");
2240
+ d(this, "tileScheduler");
2241
+ d(this, "authToken");
2242
+ d(this, "destroyed", !1);
2243
+ d(this, "contextLost", !1);
2244
+ d(this, "frame", null);
2245
+ d(this, "frameSerial", 0);
2246
+ d(this, "dragging", !1);
2247
+ d(this, "interactionMode", "none");
2248
+ d(this, "rotateLastAngleRad", null);
2249
+ d(this, "pointerId", null);
2250
+ d(this, "lastPointerX", 0);
2251
+ d(this, "lastPointerY", 0);
2252
+ d(this, "interactionLocked", !1);
2253
+ d(this, "ctrlDragRotate", !0);
2254
+ d(this, "rotationDragSensitivityDegPerPixel", 0.35);
2255
+ d(this, "maxCacheTiles");
2256
+ d(this, "fitZoom", 1);
2257
+ d(this, "minZoom", 1e-6);
2258
+ d(this, "maxZoom", 1);
2259
+ d(this, "currentTier", 0);
2260
+ d(this, "pointCount", 0);
2261
+ d(this, "usePointIndices", !1);
2262
+ d(this, "pointBuffersDirty", !0);
2263
+ d(this, "pointPaletteSize", 1);
2264
+ d(this, "lastPointData", null);
2265
+ d(this, "lastPointPalette", null);
2266
+ d(this, "cache", /* @__PURE__ */ new Map());
2267
+ d(this, "boundPointerDown");
2268
+ d(this, "boundPointerMove");
2269
+ d(this, "boundPointerUp");
2270
+ d(this, "boundWheel");
2271
+ d(this, "boundDoubleClick");
2272
+ d(this, "boundContextMenu");
2273
+ d(this, "boundContextLost");
2274
+ d(this, "boundContextRestored");
2275
+ 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) : ke;
2250
2276
  const i = t.getContext("webgl2", {
2251
2277
  alpha: !1,
2252
2278
  antialias: !1,
@@ -2256,7 +2282,7 @@ class On {
2256
2282
  });
2257
2283
  if (!i)
2258
2284
  throw new Error("WebGL2 not supported");
2259
- this.gl = i, this.tileProgram = this.initTileProgram(), this.pointProgram = this.initPointProgram(), this.tileScheduler = new Xn({
2285
+ this.gl = i, this.tileProgram = this.initTileProgram(), this.pointProgram = this.initPointProgram(), this.tileScheduler = new rr({
2260
2286
  authToken: this.authToken,
2261
2287
  maxConcurrency: r.tileScheduler?.maxConcurrency ?? 12,
2262
2288
  maxRetries: r.tileScheduler?.maxRetries ?? 2,
@@ -2273,7 +2299,7 @@ class On {
2273
2299
  }
2274
2300
  setViewState(t) {
2275
2301
  const n = { ...t };
2276
- typeof n.zoom == "number" && (n.zoom = Z(n.zoom, this.minZoom, this.maxZoom)), this.camera.setViewState(n), this.clampViewState(), this.emitViewState(), this.requestRender();
2302
+ typeof n.zoom == "number" && (n.zoom = j(n.zoom, this.minZoom, this.maxZoom)), this.camera.setViewState(n), this.clampViewState(), this.emitViewState(), this.requestRender();
2277
2303
  }
2278
2304
  getViewState() {
2279
2305
  return this.camera.getViewState();
@@ -2310,7 +2336,7 @@ class On {
2310
2336
  t.paletteIndices.length
2311
2337
  )
2312
2338
  ), 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;
2313
- let l = this.pointBuffersDirty || !a || a.count !== n || !re(a.positions, r) || !re(a.paletteIndices, i), u = this.pointBuffersDirty || o && (!a?.drawIndices || !re(a.drawIndices, s)) || !o && !!a?.drawIndices;
2339
+ let c = this.pointBuffersDirty || !a || a.count !== n || !he(a.positions, r) || !he(a.paletteIndices, i), l = this.pointBuffersDirty || o && (!a?.drawIndices || !he(a.drawIndices, s)) || !o && !!a?.drawIndices;
2314
2340
  if (this.lastPointData = {
2315
2341
  count: n,
2316
2342
  positions: r,
@@ -2318,15 +2344,15 @@ class On {
2318
2344
  drawIndices: o ? s ?? void 0 : void 0
2319
2345
  }, this.contextLost || this.gl.isContextLost()) return;
2320
2346
  const h = this.gl;
2321
- l && (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(
2347
+ c && (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(
2322
2348
  h.ARRAY_BUFFER,
2323
2349
  this.lastPointData.paletteIndices,
2324
2350
  h.STATIC_DRAW
2325
- ), h.bindBuffer(h.ARRAY_BUFFER, null)), o && u && (h.bindBuffer(h.ELEMENT_ARRAY_BUFFER, this.pointProgram.indexBuffer), h.bufferData(
2351
+ ), h.bindBuffer(h.ARRAY_BUFFER, null)), o && l && (h.bindBuffer(h.ELEMENT_ARRAY_BUFFER, this.pointProgram.indexBuffer), h.bufferData(
2326
2352
  h.ELEMENT_ARRAY_BUFFER,
2327
2353
  s ?? new Uint32Array(0),
2328
2354
  h.DYNAMIC_DRAW
2329
- ), h.bindBuffer(h.ELEMENT_ARRAY_BUFFER, null)), this.usePointIndices = o, this.pointCount = o ? s?.length ?? 0 : this.lastPointData.count, (l || u) && (this.pointBuffersDirty = !1), this.requestRender();
2355
+ ), h.bindBuffer(h.ELEMENT_ARRAY_BUFFER, null)), this.usePointIndices = o, this.pointCount = o ? s?.length ?? 0 : this.lastPointData.count, (c || l) && (this.pointBuffersDirty = !1), this.requestRender();
2330
2356
  }
2331
2357
  sanitizeDrawIndices(t, n) {
2332
2358
  if (n <= 0 || t.length === 0)
@@ -2396,35 +2422,35 @@ class On {
2396
2422
  ];
2397
2423
  let i = r[0][1];
2398
2424
  for (let s = 1; s < r.length; s += 1) {
2399
- const [a, l] = r[s - 1], [u, h] = r[s];
2425
+ const [a, c] = r[s - 1], [l, h] = r[s];
2400
2426
  if (n <= a) break;
2401
- const p = Z((n - a) / Math.max(1e-6, u - a), 0, 1);
2402
- i = l + (h - l) * p;
2427
+ const w = j((n - a) / Math.max(1e-6, l - a), 0, 1);
2428
+ i = c + (h - c) * w;
2403
2429
  }
2404
2430
  const o = r[r.length - 1];
2405
- return n > o[0] && (i += (n - o[0]) * 4), Z(i, 2.2, 36);
2431
+ return n > o[0] && (i += (n - o[0]) * 4), j(i, 2.2, 36);
2406
2432
  }
2407
2433
  fitToImage() {
2408
2434
  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;
2409
2435
  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);
2410
2436
  const s = n / o, a = r / o;
2411
2437
  this.camera.setViewState({
2412
- zoom: Z(o, this.minZoom, this.maxZoom),
2438
+ zoom: j(o, this.minZoom, this.maxZoom),
2413
2439
  offsetX: (this.source.width - s) * 0.5,
2414
2440
  offsetY: (this.source.height - a) * 0.5,
2415
2441
  rotationDeg: 0
2416
2442
  }), this.clampViewState(), this.emitViewState(), this.requestRender();
2417
2443
  }
2418
2444
  zoomBy(t, n, r) {
2419
- const i = this.camera.getViewState(), o = Z(i.zoom * t, this.minZoom, this.maxZoom);
2445
+ const i = this.camera.getViewState(), o = j(i.zoom * t, this.minZoom, this.maxZoom);
2420
2446
  if (o === i.zoom) return;
2421
2447
  const [s, a] = this.camera.screenToWorld(n, r);
2422
2448
  this.camera.setViewState({ zoom: o });
2423
- const l = this.camera.getViewport(), u = n - l.width * 0.5, h = r - l.height * 0.5, p = Lt(this.camera.getViewState().rotationDeg), d = Math.cos(p), g = Math.sin(p), y = u / o * d - h / o * g, b = u / o * g + h / o * d;
2449
+ const c = this.camera.getViewport(), l = n - c.width * 0.5, h = r - c.height * 0.5, w = Gt(this.camera.getViewState().rotationDeg), f = Math.cos(w), m = Math.sin(w), y = l / o * f - h / o * m, b = l / o * m + h / o * f;
2424
2450
  this.camera.setCenter(s - y, a - b), this.clampViewState(), this.emitViewState(), this.requestRender();
2425
2451
  }
2426
2452
  clampViewState() {
2427
- 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(), l = n * 0.5, u = r * 0.5, h = l - i, p = this.source.width - l + i, d = u - o, g = this.source.height - u + o, y = h <= p ? Z(s, h, p) : this.source.width * 0.5, b = d <= g ? Z(a, d, g) : this.source.height * 0.5;
2453
+ 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, l = r * 0.5, h = c - i, w = this.source.width - c + i, f = l - o, m = this.source.height - l + o, y = h <= w ? j(s, h, w) : this.source.width * 0.5, b = f <= m ? j(a, f, m) : this.source.height * 0.5;
2428
2454
  this.camera.setCenter(y, b);
2429
2455
  }
2430
2456
  emitViewState() {
@@ -2432,7 +2458,7 @@ class On {
2432
2458
  }
2433
2459
  selectTier() {
2434
2460
  const t = Math.max(1e-6, this.camera.getViewState().zoom), n = this.source.maxTierZoom + Math.log2(t);
2435
- return Z(Math.floor(n), 0, this.source.maxTierZoom);
2461
+ return j(Math.floor(n), 0, this.source.maxTierZoom);
2436
2462
  }
2437
2463
  getViewBounds() {
2438
2464
  const t = this.camera.getViewCorners();
@@ -2447,40 +2473,40 @@ class On {
2447
2473
  getVisibleTiles() {
2448
2474
  const t = this.selectTier();
2449
2475
  this.currentTier = t;
2450
- 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)), l = n[0], u = n[1], h = n[2], p = n[3], d = Z(
2451
- Math.floor(l / r / this.source.tileSize),
2476
+ 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], l = n[1], h = n[2], w = n[3], f = j(
2477
+ Math.floor(c / r / this.source.tileSize),
2452
2478
  0,
2453
2479
  s - 1
2454
- ), g = Z(
2480
+ ), m = j(
2455
2481
  Math.floor((h - 1) / r / this.source.tileSize),
2456
2482
  0,
2457
2483
  s - 1
2458
- ), y = Z(
2459
- Math.floor(u / r / this.source.tileSize),
2484
+ ), y = j(
2485
+ Math.floor(l / r / this.source.tileSize),
2460
2486
  0,
2461
2487
  a - 1
2462
- ), b = Z(
2463
- Math.floor((p - 1) / r / this.source.tileSize),
2488
+ ), b = j(
2489
+ Math.floor((w - 1) / r / this.source.tileSize),
2464
2490
  0,
2465
2491
  a - 1
2466
2492
  );
2467
- if (d > g || y > b)
2493
+ if (f > m || y > b)
2468
2494
  return [];
2469
- const x = (l + h) * 0.5 / r / this.source.tileSize, A = (u + p) * 0.5 / r / this.source.tileSize, F = [];
2470
- for (let C = y; C <= b; C += 1)
2471
- for (let z = d; z <= g; z += 1) {
2472
- const wt = z * this.source.tileSize * r, lt = C * this.source.tileSize * r, Y = Math.min((z + 1) * this.source.tileSize, i) * r, yt = Math.min((C + 1) * this.source.tileSize, o) * r, ht = z - x, nt = C - A;
2473
- F.push({
2474
- key: `${t}/${z}/${C}`,
2495
+ const v = (c + h) * 0.5 / r / this.source.tileSize, S = (l + w) * 0.5 / r / this.source.tileSize, L = [];
2496
+ for (let R = y; R <= b; R += 1)
2497
+ for (let W = f; W <= m; W += 1) {
2498
+ const yt = W * this.source.tileSize * r, st = R * this.source.tileSize * r, X = Math.min((W + 1) * this.source.tileSize, i) * r, At = Math.min((R + 1) * this.source.tileSize, o) * r, mt = W - v, lt = R - S;
2499
+ L.push({
2500
+ key: `${t}/${W}/${R}`,
2475
2501
  tier: t,
2476
- x: z,
2477
- y: C,
2478
- bounds: [wt, lt, Y, yt],
2479
- distance2: ht * ht + nt * nt,
2480
- url: Le(this.source, t, z, C)
2502
+ x: W,
2503
+ y: R,
2504
+ bounds: [yt, st, X, At],
2505
+ distance2: mt * mt + lt * lt,
2506
+ url: Ze(this.source, t, W, R)
2481
2507
  });
2482
2508
  }
2483
- return F.sort((C, z) => C.distance2 - z.distance2), F;
2509
+ return L.sort((R, W) => R.distance2 - W.distance2), L;
2484
2510
  }
2485
2511
  trimCache() {
2486
2512
  if (this.cache.size <= this.maxCacheTiles) return;
@@ -2494,60 +2520,60 @@ class On {
2494
2520
  }
2495
2521
  render() {
2496
2522
  if (this.destroyed || this.contextLost || this.gl.isContextLost()) return;
2497
- const t = Me();
2523
+ const t = Ye();
2498
2524
  this.frameSerial += 1;
2499
2525
  const n = this.gl, r = this.tileProgram, i = this.pointProgram;
2500
2526
  n.clearColor(0.03, 0.06, 0.1, 1), n.clear(n.COLOR_BUFFER_BIT);
2501
- const o = this.getVisibleTiles(), s = this.getViewBounds(), a = new Set(o.map((d) => d.key));
2527
+ const o = this.getVisibleTiles(), s = this.getViewBounds(), a = new Set(o.map((f) => f.key));
2502
2528
  n.useProgram(r.program), n.bindVertexArray(r.vao), n.uniformMatrix3fv(r.uCamera, !1, this.camera.getMatrix()), n.uniform1i(r.uTexture, 0);
2503
- const l = [];
2504
- for (const [, d] of this.cache)
2505
- a.has(d.key) || this.intersectsBounds(d.bounds, s) && l.push(d);
2506
- l.sort((d, g) => d.tier - g.tier);
2507
- for (const d of l)
2508
- d.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, d.texture), n.uniform4f(
2529
+ const c = [];
2530
+ for (const [, f] of this.cache)
2531
+ a.has(f.key) || this.intersectsBounds(f.bounds, s) && c.push(f);
2532
+ c.sort((f, m) => f.tier - m.tier);
2533
+ for (const f of c)
2534
+ f.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, f.texture), n.uniform4f(
2509
2535
  r.uBounds,
2510
- d.bounds[0],
2511
- d.bounds[1],
2512
- d.bounds[2],
2513
- d.bounds[3]
2536
+ f.bounds[0],
2537
+ f.bounds[1],
2538
+ f.bounds[2],
2539
+ f.bounds[3]
2514
2540
  ), n.drawArrays(n.TRIANGLE_STRIP, 0, 4);
2515
- let u = 0;
2541
+ let l = 0;
2516
2542
  const h = [];
2517
- for (const d of o) {
2518
- const g = this.cache.get(d.key);
2519
- if (!g) {
2520
- h.push(d);
2543
+ for (const f of o) {
2544
+ const m = this.cache.get(f.key);
2545
+ if (!m) {
2546
+ h.push(f);
2521
2547
  continue;
2522
2548
  }
2523
- g.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, g.texture), n.uniform4f(
2549
+ m.lastUsed = this.frameSerial, n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, m.texture), n.uniform4f(
2524
2550
  r.uBounds,
2525
- g.bounds[0],
2526
- g.bounds[1],
2527
- g.bounds[2],
2528
- g.bounds[3]
2529
- ), n.drawArrays(n.TRIANGLE_STRIP, 0, 4), u += 1;
2551
+ m.bounds[0],
2552
+ m.bounds[1],
2553
+ m.bounds[2],
2554
+ m.bounds[3]
2555
+ ), n.drawArrays(n.TRIANGLE_STRIP, 0, 4), l += 1;
2530
2556
  }
2531
2557
  this.tileScheduler.schedule(h), n.bindTexture(n.TEXTURE_2D, null), n.bindVertexArray(null);
2532
- let p = 0;
2533
- 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), p = this.pointCount), this.onStats) {
2534
- const d = this.tileScheduler.getSnapshot(), g = u, y = h.length, b = l.length + u + (p > 0 ? 1 : 0);
2558
+ let w = 0;
2559
+ 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), w = this.pointCount), this.onStats) {
2560
+ const f = this.tileScheduler.getSnapshot(), m = l, y = h.length, b = c.length + l + (w > 0 ? 1 : 0);
2535
2561
  this.onStats({
2536
2562
  tier: this.currentTier,
2537
2563
  visible: o.length,
2538
- rendered: u,
2539
- points: p,
2540
- fallback: l.length,
2564
+ rendered: l,
2565
+ points: w,
2566
+ fallback: c.length,
2541
2567
  cache: this.cache.size,
2542
- inflight: d.inflight,
2543
- queued: d.queued,
2544
- retries: d.retries,
2545
- failed: d.failed,
2546
- aborted: d.aborted,
2547
- cacheHits: g,
2568
+ inflight: f.inflight,
2569
+ queued: f.queued,
2570
+ retries: f.retries,
2571
+ failed: f.failed,
2572
+ aborted: f.aborted,
2573
+ cacheHits: m,
2548
2574
  cacheMisses: y,
2549
2575
  drawCalls: b,
2550
- frameMs: Me() - t
2576
+ frameMs: Ye() - t
2551
2577
  });
2552
2578
  }
2553
2579
  }
@@ -2571,15 +2597,15 @@ class On {
2571
2597
  if (this.lastPointerX = t.clientX, this.lastPointerY = t.clientY, this.interactionMode === "rotate") {
2572
2598
  const i = this.getPointerAngleRad(t.clientX, t.clientY), o = this.rotateLastAngleRad;
2573
2599
  if (this.rotateLastAngleRad = i, o !== null) {
2574
- const s = i - o, a = Math.atan2(Math.sin(s), Math.cos(s)), l = this.rotationDragSensitivityDegPerPixel / Se, u = this.camera.getViewState();
2600
+ const s = i - o, a = Math.atan2(Math.sin(s), Math.cos(s)), c = this.rotationDragSensitivityDegPerPixel / ke, l = this.camera.getViewState();
2575
2601
  this.camera.setViewState({
2576
- rotationDeg: u.rotationDeg - a * 180 / Math.PI * l
2602
+ rotationDeg: l.rotationDeg - a * 180 / Math.PI * c
2577
2603
  });
2578
2604
  }
2579
2605
  } else {
2580
- const i = this.camera.getViewState(), o = Math.max(1e-6, i.zoom), s = Lt(i.rotationDeg), a = Math.cos(s), l = Math.sin(s), u = (n * a - r * l) / o, h = (n * l + r * a) / o;
2606
+ const i = this.camera.getViewState(), o = Math.max(1e-6, i.zoom), s = Gt(i.rotationDeg), a = Math.cos(s), c = Math.sin(s), l = (n * a - r * c) / o, h = (n * c + r * a) / o;
2581
2607
  this.camera.setViewState({
2582
- offsetX: i.offsetX - u,
2608
+ offsetX: i.offsetX - l,
2583
2609
  offsetY: i.offsetY - h
2584
2610
  });
2585
2611
  }
@@ -2625,7 +2651,7 @@ class On {
2625
2651
  }
2626
2652
  }
2627
2653
  initTileProgram() {
2628
- const t = this.gl, i = ge(t, `#version 300 es
2654
+ const t = this.gl, i = Re(t, `#version 300 es
2629
2655
  precision highp float;
2630
2656
  in vec2 aUnit;
2631
2657
  in vec2 aUv;
@@ -2647,21 +2673,21 @@ class On {
2647
2673
  out vec4 outColor;
2648
2674
  void main() {
2649
2675
  outColor = texture(uTexture, vUv);
2650
- }`), o = Ct(t, i, "uCamera"), s = Ct(t, i, "uBounds"), a = Ct(t, i, "uTexture"), l = t.createVertexArray(), u = t.createBuffer();
2651
- if (!l || !u)
2676
+ }`), o = Nt(t, i, "uCamera"), s = Nt(t, i, "uBounds"), a = Nt(t, i, "uTexture"), c = t.createVertexArray(), l = t.createBuffer();
2677
+ if (!c || !l)
2652
2678
  throw new Error("buffer allocation failed");
2653
- t.bindVertexArray(l), t.bindBuffer(t.ARRAY_BUFFER, u), t.bufferData(
2679
+ t.bindVertexArray(c), t.bindBuffer(t.ARRAY_BUFFER, l), t.bufferData(
2654
2680
  t.ARRAY_BUFFER,
2655
2681
  new Float32Array([0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1]),
2656
2682
  t.STATIC_DRAW
2657
2683
  );
2658
- const h = t.getAttribLocation(i, "aUnit"), p = t.getAttribLocation(i, "aUv");
2659
- if (h < 0 || p < 0)
2684
+ const h = t.getAttribLocation(i, "aUnit"), w = t.getAttribLocation(i, "aUv");
2685
+ if (h < 0 || w < 0)
2660
2686
  throw new Error("tile attribute lookup failed");
2661
- return t.enableVertexAttribArray(h), t.enableVertexAttribArray(p), t.vertexAttribPointer(h, 2, t.FLOAT, !1, 16, 0), t.vertexAttribPointer(p, 2, t.FLOAT, !1, 16, 8), t.bindVertexArray(null), t.bindBuffer(t.ARRAY_BUFFER, null), { program: i, vao: l, vbo: u, uCamera: o, uBounds: s, uTexture: a };
2687
+ return t.enableVertexAttribArray(h), t.enableVertexAttribArray(w), t.vertexAttribPointer(h, 2, t.FLOAT, !1, 16, 0), t.vertexAttribPointer(w, 2, t.FLOAT, !1, 16, 8), t.bindVertexArray(null), t.bindBuffer(t.ARRAY_BUFFER, null), { program: i, vao: c, vbo: l, uCamera: o, uBounds: s, uTexture: a };
2662
2688
  }
2663
2689
  initPointProgram() {
2664
- const t = this.gl, i = ge(t, `#version 300 es
2690
+ const t = this.gl, i = Re(t, `#version 300 es
2665
2691
  precision highp float;
2666
2692
  in vec2 aPosition;
2667
2693
  in uint aTerm;
@@ -2700,18 +2726,18 @@ class On {
2700
2726
  if (alpha <= 0.001) discard;
2701
2727
 
2702
2728
  outColor = vec4(color.rgb * alpha, alpha);
2703
- }`), o = Ct(t, i, "uCamera"), s = Ct(t, i, "uPointSize"), a = Ct(t, i, "uPalette"), l = Ct(t, i, "uPaletteSize"), u = t.createVertexArray(), h = t.createBuffer(), p = t.createBuffer(), d = t.createBuffer(), g = t.createTexture();
2704
- if (!u || !h || !p || !d || !g)
2729
+ }`), o = Nt(t, i, "uCamera"), s = Nt(t, i, "uPointSize"), a = Nt(t, i, "uPalette"), c = Nt(t, i, "uPaletteSize"), l = t.createVertexArray(), h = t.createBuffer(), w = t.createBuffer(), f = t.createBuffer(), m = t.createTexture();
2730
+ if (!l || !h || !w || !f || !m)
2705
2731
  throw new Error("point buffer allocation failed");
2706
- t.bindVertexArray(u), t.bindBuffer(t.ARRAY_BUFFER, h), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
2732
+ t.bindVertexArray(l), t.bindBuffer(t.ARRAY_BUFFER, h), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
2707
2733
  const y = t.getAttribLocation(i, "aPosition");
2708
2734
  if (y < 0)
2709
2735
  throw new Error("point position attribute not found");
2710
- t.enableVertexAttribArray(y), t.vertexAttribPointer(y, 2, t.FLOAT, !1, 0, 0), t.bindBuffer(t.ARRAY_BUFFER, p), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
2736
+ t.enableVertexAttribArray(y), t.vertexAttribPointer(y, 2, t.FLOAT, !1, 0, 0), t.bindBuffer(t.ARRAY_BUFFER, w), t.bufferData(t.ARRAY_BUFFER, 0, t.DYNAMIC_DRAW);
2711
2737
  const b = t.getAttribLocation(i, "aTerm");
2712
2738
  if (b < 0)
2713
2739
  throw new Error("point term attribute not found");
2714
- return t.enableVertexAttribArray(b), t.vertexAttribIPointer(b, 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, g), 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(
2740
+ return t.enableVertexAttribArray(b), t.vertexAttribIPointer(b, 1, t.UNSIGNED_SHORT, 0, 0), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, f), 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, m), 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(
2715
2741
  t.TEXTURE_2D,
2716
2742
  0,
2717
2743
  t.RGBA,
@@ -2723,15 +2749,15 @@ class On {
2723
2749
  new Uint8Array([160, 160, 160, 255])
2724
2750
  ), t.bindTexture(t.TEXTURE_2D, null), {
2725
2751
  program: i,
2726
- vao: u,
2752
+ vao: l,
2727
2753
  posBuffer: h,
2728
- termBuffer: p,
2729
- indexBuffer: d,
2730
- paletteTexture: g,
2754
+ termBuffer: w,
2755
+ indexBuffer: f,
2756
+ paletteTexture: m,
2731
2757
  uCamera: o,
2732
2758
  uPointSize: s,
2733
2759
  uPalette: a,
2734
- uPaletteSize: l
2760
+ uPaletteSize: c
2735
2761
  };
2736
2762
  }
2737
2763
  handleTileLoaded(t, n) {
@@ -2758,37 +2784,37 @@ class On {
2758
2784
  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;
2759
2785
  }
2760
2786
  }
2761
- const Ae = [], Gn = [], qn = {
2787
+ const de = [], sr = [], ar = {
2762
2788
  count: 0,
2763
2789
  positions: new Float32Array(0),
2764
2790
  paletteIndices: new Uint16Array(0)
2765
2791
  };
2766
- function ae(e, t) {
2792
+ function pe(e, t) {
2767
2793
  return e.id ?? t;
2768
2794
  }
2769
- function $n(e, t) {
2795
+ function cr(e, t) {
2770
2796
  if (!Array.isArray(t) || t.length < 3) return !1;
2771
2797
  const [n, r] = e;
2772
2798
  let i = !1;
2773
2799
  for (let o = 0, s = t.length - 1; o < t.length; s = o++) {
2774
- const [a, l] = t[o], [u, h] = t[s];
2775
- l > r != h > r && n < (u - a) * (r - l) / Math.max(1e-12, h - l) + a && (i = !i);
2800
+ const [a, c] = t[o], [l, h] = t[s];
2801
+ c > r != h > r && n < (l - a) * (r - c) / Math.max(1e-12, h - c) + a && (i = !i);
2776
2802
  }
2777
2803
  return i;
2778
2804
  }
2779
- function Re(e, t) {
2805
+ function We(e, t) {
2780
2806
  for (let n = t.length - 1; n >= 0; n -= 1) {
2781
2807
  const r = t[n];
2782
- if (r?.coordinates?.length && $n(e, r.coordinates))
2808
+ if (r?.coordinates?.length && cr(e, r.coordinates))
2783
2809
  return {
2784
2810
  region: r,
2785
2811
  regionIndex: n,
2786
- regionId: ae(r, n)
2812
+ regionId: pe(r, n)
2787
2813
  };
2788
2814
  }
2789
2815
  return null;
2790
2816
  }
2791
- function sr({
2817
+ function vr({
2792
2818
  source: e,
2793
2819
  viewState: t,
2794
2820
  onViewStateChange: n,
@@ -2797,40 +2823,44 @@ function sr({
2797
2823
  onContextLost: o,
2798
2824
  onContextRestored: s,
2799
2825
  debugOverlay: a = !1,
2800
- debugOverlayStyle: l,
2801
- fitNonce: u = 0,
2826
+ debugOverlayStyle: c,
2827
+ fitNonce: l = 0,
2802
2828
  rotationResetNonce: h = 0,
2803
- authToken: p = "",
2804
- ctrlDragRotate: d = !0,
2805
- pointData: g = null,
2829
+ authToken: w = "",
2830
+ ctrlDragRotate: f = !0,
2831
+ pointData: m = null,
2806
2832
  pointPalette: y = null,
2807
2833
  roiRegions: b,
2808
- roiPolygons: x,
2809
- clipPointsToRois: A = !1,
2810
- clipMode: F = "worker",
2811
- onClipStats: C,
2812
- onRoiPointGroups: z,
2813
- roiPaletteIndexToTermId: wt,
2814
- interactionLock: lt = !1,
2815
- drawTool: Y = "cursor",
2816
- stampOptions: yt,
2817
- regionStrokeStyle: ht,
2818
- regionStrokeHoverStyle: nt,
2819
- regionStrokeActiveStyle: H,
2820
- resolveRegionStrokeStyle: V,
2821
- overlayShapes: J,
2822
- regionLabelStyle: vt,
2823
- onPointerWorldMove: xt,
2824
- onRegionHover: ut,
2825
- onRegionClick: Tt,
2826
- onActiveRegionChange: P,
2827
- onDrawComplete: E,
2828
- showOverviewMap: M = !1,
2829
- overviewMapOptions: I,
2830
- className: O,
2831
- style: it
2834
+ roiPolygons: v,
2835
+ clipPointsToRois: S = !1,
2836
+ clipMode: L = "worker",
2837
+ onClipStats: R,
2838
+ onRoiPointGroups: W,
2839
+ roiPaletteIndexToTermId: yt,
2840
+ interactionLock: st = !1,
2841
+ drawTool: X = "cursor",
2842
+ stampOptions: At,
2843
+ regionStrokeStyle: mt,
2844
+ regionStrokeHoverStyle: lt,
2845
+ regionStrokeActiveStyle: Rt,
2846
+ patchStrokeStyle: J,
2847
+ resolveRegionStrokeStyle: rt,
2848
+ overlayShapes: V,
2849
+ customLayers: ht,
2850
+ patchRegions: Ct,
2851
+ regionLabelStyle: at,
2852
+ onPointerWorldMove: x,
2853
+ onRegionHover: T,
2854
+ onRegionClick: E,
2855
+ onActiveRegionChange: k,
2856
+ onDrawComplete: O,
2857
+ onPatchComplete: gt,
2858
+ showOverviewMap: tt = !1,
2859
+ overviewMapOptions: q,
2860
+ className: et,
2861
+ style: ct
2832
2862
  }) {
2833
- const ot = $(null), R = $(null), W = $(null), st = $(null), ft = $(n), X = $(r), K = $(a), [rt, q] = Ft(!0), [Q, c] = Ft(null), [m, S] = Ft(null), [v, N] = Ft(null), T = $(null), _ = $(0), G = b ?? Ae, tt = x ?? Gn, dt = et(() => ({ position: "relative", width: "100%", height: "100%", ...it }), [it]), Rt = et(
2863
+ const ut = Z(null), U = Z(null), P = Z(null), Y = Z(null), $ = Z(n), Q = Z(r), dt = Z(a), [Lt, Tt] = Yt(!0), [vt, bt] = Yt(null), [u, g] = Yt(null), [M, _] = Yt(null), [A, C] = Yt(null), I = Z(null), G = Z(0), it = b ?? de, ot = Ct ?? de, St = v ?? sr, It = (ht?.length ?? 0) > 0, Vt = H(() => ({ position: "relative", width: "100%", height: "100%", ...ct }), [ct]), ie = H(
2834
2864
  () => ({
2835
2865
  position: "absolute",
2836
2866
  top: 8,
@@ -2849,171 +2879,192 @@ function sr({
2849
2879
  border: "1px solid rgba(173, 216, 255, 0.28)",
2850
2880
  borderRadius: 8,
2851
2881
  boxShadow: "0 8px 22px rgba(0,0,0,0.35)",
2852
- ...l
2882
+ ...c
2853
2883
  }),
2854
- [l]
2855
- ), j = et(() => G.length > 0 ? G : tt.length === 0 ? Ae : tt.map((w, B) => ({
2884
+ [c]
2885
+ ), ft = H(() => it.length > 0 ? it : St.length === 0 ? de : St.map((p, B) => ({
2856
2886
  id: B,
2857
- coordinates: w
2858
- })), [G, tt]), pt = et(() => j.map((w) => w.coordinates), [j]), [_t, zt] = Ft(g);
2859
- L(() => {
2860
- const w = ++_.current;
2887
+ coordinates: p
2888
+ })), [it, St]), Dt = H(() => ft.map((p) => p.coordinates), [ft]), [qt, $t] = Yt(m);
2889
+ z(() => {
2890
+ const p = ++G.current;
2861
2891
  let B = !1;
2862
- if (!A)
2863
- return zt(g), () => {
2892
+ if (!S)
2893
+ return $t(m), () => {
2864
2894
  B = !0;
2865
2895
  };
2866
- if (!g || !g.count || !g.positions || !g.paletteIndices)
2867
- return zt(null), () => {
2896
+ if (!m || !m.count || !m.positions || !m.paletteIndices)
2897
+ return $t(null), () => {
2868
2898
  B = !0;
2869
2899
  };
2870
- if (pt.length === 0)
2871
- return zt(qn), C?.({
2872
- mode: F,
2900
+ if (Dt.length === 0)
2901
+ return $t(ar), R?.({
2902
+ mode: L,
2873
2903
  durationMs: 0,
2874
- inputCount: g.count,
2904
+ inputCount: m.count,
2875
2905
  outputCount: 0,
2876
2906
  polygonCount: 0
2877
2907
  }), () => {
2878
2908
  B = !0;
2879
2909
  };
2880
- const k = (U, ct) => {
2881
- if (B || w !== _.current) return;
2882
- const jt = U?.drawIndices ? U.drawIndices.length : U?.count ?? 0;
2883
- zt(U), C?.({
2884
- mode: ct.mode,
2885
- durationMs: ct.durationMs,
2886
- inputCount: g.count,
2887
- outputCount: jt,
2888
- polygonCount: pt.length,
2889
- usedWebGpu: ct.usedWebGpu,
2890
- candidateCount: ct.candidateCount,
2891
- bridgedToDraw: ct.bridgedToDraw
2910
+ const N = (F, nt) => {
2911
+ if (B || p !== G.current) return;
2912
+ const oe = F?.drawIndices ? F.drawIndices.length : F?.count ?? 0;
2913
+ $t(F), R?.({
2914
+ mode: nt.mode,
2915
+ durationMs: nt.durationMs,
2916
+ inputCount: m.count,
2917
+ outputCount: oe,
2918
+ polygonCount: Dt.length,
2919
+ usedWebGpu: nt.usedWebGpu,
2920
+ candidateCount: nt.candidateCount,
2921
+ bridgedToDraw: nt.bridgedToDraw
2892
2922
  });
2893
2923
  };
2894
2924
  return (async () => {
2895
- if (F === "sync") {
2896
- const U = performance.now(), ct = Kt(g, pt);
2897
- k(ct, {
2925
+ if (L === "sync") {
2926
+ const F = performance.now(), nt = re(m, Dt);
2927
+ N(nt, {
2898
2928
  mode: "sync",
2899
- durationMs: performance.now() - U
2929
+ durationMs: performance.now() - F
2900
2930
  });
2901
2931
  return;
2902
2932
  }
2903
- if (F === "hybrid-webgpu") {
2904
- const U = await _n(
2905
- g,
2906
- pt,
2907
- { bridgeToDraw: !0 }
2908
- );
2909
- k(U.data, {
2910
- mode: U.meta.mode,
2911
- durationMs: U.meta.durationMs,
2912
- usedWebGpu: U.meta.usedWebGpu,
2913
- candidateCount: U.meta.candidateCount,
2914
- bridgedToDraw: U.meta.bridgedToDraw
2933
+ if (L === "hybrid-webgpu") {
2934
+ const F = await Hn(m, Dt, { bridgeToDraw: !0 });
2935
+ N(F.data, {
2936
+ mode: F.meta.mode,
2937
+ durationMs: F.meta.durationMs,
2938
+ usedWebGpu: F.meta.usedWebGpu,
2939
+ candidateCount: F.meta.candidateCount,
2940
+ bridgedToDraw: F.meta.bridgedToDraw
2915
2941
  });
2916
2942
  return;
2917
2943
  }
2918
2944
  try {
2919
- const U = await Fn(g, pt);
2920
- k(U.data, {
2921
- mode: U.meta.mode,
2922
- durationMs: U.meta.durationMs
2945
+ const F = await Zn(m, Dt);
2946
+ N(F.data, {
2947
+ mode: F.meta.mode,
2948
+ durationMs: F.meta.durationMs
2923
2949
  });
2924
2950
  } catch {
2925
- const U = performance.now(), ct = Kt(g, pt);
2926
- k(ct, {
2951
+ const F = performance.now(), nt = re(m, Dt);
2952
+ N(nt, {
2927
2953
  mode: "sync",
2928
- durationMs: performance.now() - U
2954
+ durationMs: performance.now() - F
2929
2955
  });
2930
2956
  }
2931
2957
  })(), () => {
2932
2958
  B = !0;
2933
2959
  };
2934
- }, [A, F, g, pt, C]), et(() => {
2935
- const w = Number(I?.width ?? 220);
2936
- return Number.isFinite(w) ? Math.max(64, w) : 220;
2937
- }, [I?.width]);
2938
- const le = et(() => {
2939
- const w = Number(I?.height ?? 140);
2940
- return Number.isFinite(w) ? Math.max(48, w) : 140;
2941
- }, [I?.height]), Mt = et(() => {
2942
- const w = Number(I?.margin ?? 16);
2943
- return Number.isFinite(w) ? Math.max(0, w) : 16;
2944
- }, [I?.margin]), Nt = I?.position || "bottom-right", Bt = D(
2945
- (w) => {
2946
- S((B) => String(B) === String(w) ? B : (P?.(w), w));
2960
+ }, [S, L, m, Dt, R]), H(() => {
2961
+ const p = Number(q?.width ?? 220);
2962
+ return Number.isFinite(p) ? Math.max(64, p) : 220;
2963
+ }, [q?.width]);
2964
+ const ye = H(() => {
2965
+ const p = Number(q?.height ?? 140);
2966
+ return Number.isFinite(p) ? Math.max(48, p) : 140;
2967
+ }, [q?.height]), _t = H(() => {
2968
+ const p = Number(q?.margin ?? 16);
2969
+ return Number.isFinite(p) ? Math.max(0, p) : 16;
2970
+ }, [q?.margin]), Ht = q?.position || "bottom-right", zt = D(
2971
+ (p) => {
2972
+ g((B) => String(B) === String(p) ? B : (k?.(p), p));
2947
2973
  },
2948
- [P]
2974
+ [k]
2949
2975
  );
2950
- L(() => {
2951
- ft.current = n;
2952
- }, [n]), L(() => {
2953
- X.current = r;
2954
- }, [r]), L(() => {
2955
- K.current = a, a || N(null);
2976
+ z(() => {
2977
+ $.current = n;
2978
+ }, [n]), z(() => {
2979
+ Q.current = r;
2980
+ }, [r]), z(() => {
2981
+ dt.current = a, a || C(null);
2956
2982
  }, [a]);
2957
- const he = D((w) => {
2958
- X.current?.(w), K.current && N(w);
2959
- }, []), Ne = et(() => v ? [
2960
- `tier ${v.tier} | frame ${v.frameMs?.toFixed(2) ?? "-"} ms | drawCalls ${v.drawCalls ?? "-"}`,
2961
- `tiles visible ${v.visible} | rendered ${v.rendered} | fallback ${v.fallback}`,
2962
- `cache size ${v.cache} | hit ${v.cacheHits ?? "-"} | miss ${v.cacheMisses ?? "-"}`,
2963
- `queue inflight ${v.inflight} | queued ${v.queued ?? "-"} | retries ${v.retries ?? "-"} | failed ${v.failed ?? "-"} | aborted ${v.aborted ?? "-"}`,
2964
- `points ${v.points}`
2983
+ const xe = D((p) => {
2984
+ Q.current?.(p), dt.current && C(p);
2985
+ }, []), nn = H(() => A ? [
2986
+ `tier ${A.tier} | frame ${A.frameMs?.toFixed(2) ?? "-"} ms | drawCalls ${A.drawCalls ?? "-"}`,
2987
+ `tiles visible ${A.visible} | rendered ${A.rendered} | fallback ${A.fallback}`,
2988
+ `cache size ${A.cache} | hit ${A.cacheHits ?? "-"} | miss ${A.cacheMisses ?? "-"}`,
2989
+ `queue inflight ${A.inflight} | queued ${A.queued ?? "-"} | retries ${A.retries ?? "-"} | failed ${A.failed ?? "-"} | aborted ${A.aborted ?? "-"}`,
2990
+ `points ${A.points}`
2965
2991
  ].join(`
2966
- `) : "stats: waiting for first frame...", [v]);
2967
- L(() => {
2968
- !(m === null ? !0 : j.some((at, U) => String(ae(at, U)) === String(m))) && m !== null && Bt(null);
2969
- const B = T.current;
2970
- !(B === null ? !0 : j.some((at, U) => String(ae(at, U)) === String(B))) && B !== null && (T.current = null, c(null), ut?.({
2992
+ `) : "stats: waiting for first frame...", [A]);
2993
+ z(() => {
2994
+ !(u === null ? !0 : ft.some((K, F) => String(pe(K, F)) === String(u))) && u !== null && zt(null);
2995
+ const B = I.current;
2996
+ !(B === null ? !0 : ft.some((K, F) => String(pe(K, F)) === String(B))) && B !== null && (I.current = null, bt(null), T?.({
2971
2997
  region: null,
2972
2998
  regionId: null,
2973
2999
  regionIndex: -1,
2974
3000
  coordinate: null
2975
3001
  }));
2976
- }, [j, m, ut, Bt]);
2977
- const fe = D((w) => {
2978
- const B = ft.current;
2979
- B && B(w), W.current?.(), st.current?.();
2980
- }, []);
2981
- L(() => {
2982
- if (!M) {
2983
- q(!1);
3002
+ }, [ft, u, T, zt]);
3003
+ const Te = D(
3004
+ (p) => {
3005
+ It && _(p);
3006
+ const B = $.current;
3007
+ B && B(p), P.current?.(), Y.current?.();
3008
+ },
3009
+ [It]
3010
+ );
3011
+ z(() => {
3012
+ if (!tt) {
3013
+ Tt(!1);
2984
3014
  return;
2985
3015
  }
2986
- q(!0);
2987
- }, [M, e?.id]), L(() => {
2988
- Y !== "cursor" && T.current !== null && (T.current = null, c(null), ut?.({
3016
+ Tt(!0);
3017
+ }, [tt, e?.id]), z(() => {
3018
+ X !== "cursor" && I.current !== null && (I.current = null, bt(null), T?.({
2989
3019
  region: null,
2990
3020
  regionId: null,
2991
3021
  regionIndex: -1,
2992
3022
  coordinate: null
2993
3023
  }));
2994
- }, [Y, ut]);
2995
- const kt = D((w, B) => {
2996
- const k = R.current;
2997
- if (!k) return null;
2998
- const at = k.screenToWorld(w, B);
2999
- if (!Array.isArray(at) || at.length < 2) return null;
3000
- const U = Number(at[0]), ct = Number(at[1]);
3001
- return !Number.isFinite(U) || !Number.isFinite(ct) ? null : [U, ct];
3002
- }, []), ke = D(
3003
- (w) => {
3004
- const B = w.target === ot.current, k = kt(w.clientX, w.clientY);
3005
- if (xt) {
3006
- const jt = !!k && k[0] >= 0 && k[1] >= 0 && !!e && k[0] <= e.width && k[1] <= e.height;
3007
- xt({
3008
- coordinate: k,
3009
- clientX: w.clientX,
3010
- clientY: w.clientY,
3011
- insideImage: jt
3024
+ }, [X, T]);
3025
+ const kt = D((p, B) => {
3026
+ const N = U.current;
3027
+ if (!N) return null;
3028
+ const K = N.screenToWorld(p, B);
3029
+ if (!Array.isArray(K) || K.length < 2) return null;
3030
+ const F = Number(K[0]), nt = Number(K[1]);
3031
+ return !Number.isFinite(F) || !Number.isFinite(nt) ? null : [F, nt];
3032
+ }, []), ve = D((p, B) => {
3033
+ const N = U.current;
3034
+ if (!N) return null;
3035
+ const K = N.worldToScreen(p, B);
3036
+ if (!Array.isArray(K) || K.length < 2) return null;
3037
+ const F = Number(K[0]), nt = Number(K[1]);
3038
+ return !Number.isFinite(F) || !Number.isFinite(nt) ? null : [F, nt];
3039
+ }, []), Me = D(() => {
3040
+ U.current?.requestRender(), P.current?.(), Y.current?.();
3041
+ }, []), Pe = H(() => M ?? U.current?.getViewState() ?? null, [M]), Se = H(() => {
3042
+ if (!e) return null;
3043
+ const p = Pe;
3044
+ return p ? {
3045
+ source: e,
3046
+ viewState: p,
3047
+ drawTool: X,
3048
+ interactionLock: st,
3049
+ worldToScreen: ve,
3050
+ screenToWorld: kt,
3051
+ requestRedraw: Me
3052
+ } : null;
3053
+ }, [e, Pe, X, st, ve, kt, Me]), rn = D(
3054
+ (p) => {
3055
+ const B = p.target === ut.current, N = kt(p.clientX, p.clientY);
3056
+ if (x) {
3057
+ const oe = !!N && N[0] >= 0 && N[1] >= 0 && !!e && N[0] <= e.width && N[1] <= e.height;
3058
+ x({
3059
+ coordinate: N,
3060
+ clientX: p.clientX,
3061
+ clientY: p.clientY,
3062
+ insideImage: oe
3012
3063
  });
3013
3064
  }
3014
- if (Y !== "cursor") return;
3065
+ if (X !== "cursor") return;
3015
3066
  if (!B) {
3016
- T.current !== null && (T.current = null, c(null), ut?.({
3067
+ I.current !== null && (I.current = null, bt(null), T?.({
3017
3068
  region: null,
3018
3069
  regionId: null,
3019
3070
  regionIndex: -1,
@@ -3021,98 +3072,98 @@ function sr({
3021
3072
  }));
3022
3073
  return;
3023
3074
  }
3024
- if (!k || !j.length) return;
3025
- const at = Re(k, j), U = at?.regionId ?? null, ct = T.current;
3026
- String(ct) !== String(U) && (T.current = U, c(U), ut?.({
3027
- region: at?.region ?? null,
3028
- regionId: U,
3029
- regionIndex: at?.regionIndex ?? -1,
3030
- coordinate: k
3075
+ if (!N || !ft.length) return;
3076
+ const K = We(N, ft), F = K?.regionId ?? null, nt = I.current;
3077
+ String(nt) !== String(F) && (I.current = F, bt(F), T?.({
3078
+ region: K?.region ?? null,
3079
+ regionId: F,
3080
+ regionIndex: K?.regionIndex ?? -1,
3081
+ coordinate: N
3031
3082
  }));
3032
3083
  },
3033
- [Y, j, kt, ut, xt, e]
3034
- ), Ye = D(() => {
3035
- xt?.({
3084
+ [X, ft, kt, T, x, e]
3085
+ ), on = D(() => {
3086
+ x?.({
3036
3087
  coordinate: null,
3037
3088
  clientX: -1,
3038
3089
  clientY: -1,
3039
3090
  insideImage: !1
3040
- }), T.current !== null && (T.current = null, c(null), ut?.({
3091
+ }), I.current !== null && (I.current = null, bt(null), T?.({
3041
3092
  region: null,
3042
3093
  regionId: null,
3043
3094
  regionIndex: -1,
3044
3095
  coordinate: null
3045
3096
  }));
3046
- }, [ut, xt]), We = D(
3047
- (w) => {
3048
- if (Y !== "cursor" || w.target !== ot.current) return;
3049
- if (!j.length) {
3050
- Bt(null);
3097
+ }, [T, x]), sn = D(
3098
+ (p) => {
3099
+ if (X !== "cursor" || p.target !== ut.current) return;
3100
+ if (!ft.length) {
3101
+ zt(null);
3051
3102
  return;
3052
3103
  }
3053
- const B = kt(w.clientX, w.clientY);
3104
+ const B = kt(p.clientX, p.clientY);
3054
3105
  if (!B) return;
3055
- const k = Re(B, j);
3056
- if (!k) {
3057
- Bt(null);
3106
+ const N = We(B, ft);
3107
+ if (!N) {
3108
+ zt(null);
3058
3109
  return;
3059
3110
  }
3060
- const at = m !== null && String(m) === String(k.regionId) ? null : k.regionId;
3061
- Bt(at), Tt?.({
3062
- region: k.region,
3063
- regionId: k.regionId,
3064
- regionIndex: k.regionIndex,
3111
+ const K = u !== null && String(u) === String(N.regionId) ? null : N.regionId;
3112
+ zt(K), E?.({
3113
+ region: N.region,
3114
+ regionId: N.regionId,
3115
+ regionIndex: N.regionIndex,
3065
3116
  coordinate: B
3066
3117
  });
3067
3118
  },
3068
- [Y, j, kt, Tt, m, Bt]
3119
+ [X, ft, kt, E, u, zt]
3069
3120
  );
3070
- return L(() => {
3071
- const w = ot.current;
3072
- if (!w || !e)
3121
+ return z(() => {
3122
+ const p = ut.current;
3123
+ if (!p || !e)
3073
3124
  return;
3074
- const B = new On(w, e, {
3075
- onViewStateChange: fe,
3076
- onStats: he,
3125
+ const B = new or(p, e, {
3126
+ onViewStateChange: Te,
3127
+ onStats: xe,
3077
3128
  onTileError: i,
3078
3129
  onContextLost: o,
3079
3130
  onContextRestored: s,
3080
- authToken: p,
3081
- ctrlDragRotate: d
3131
+ authToken: w,
3132
+ ctrlDragRotate: f
3082
3133
  });
3083
- return R.current = B, t && B.setViewState(t), B.setInteractionLock(lt), () => {
3084
- B.destroy(), R.current = null;
3134
+ return U.current = B, t && B.setViewState(t), B.setInteractionLock(st), It && _(B.getViewState()), () => {
3135
+ B.destroy(), U.current = null;
3085
3136
  };
3086
- }, [e, he, i, o, s, p, d, fe]), L(() => {
3087
- const w = R.current;
3088
- !w || !t || w.setViewState(t);
3089
- }, [t]), L(() => {
3090
- const w = R.current;
3091
- w && w.fitToImage();
3092
- }, [u]), L(() => {
3093
- const w = R.current;
3094
- w && w.resetRotation();
3095
- }, [h]), L(() => {
3096
- const w = R.current;
3097
- !w || !y || w.setPointPalette(y);
3098
- }, [y]), L(() => {
3099
- const w = R.current;
3100
- w && w.setPointData(_t);
3101
- }, [_t]), L(() => {
3102
- if (!z) return;
3103
- const B = Yn(A ? _t : g, j, {
3104
- paletteIndexToTermId: wt,
3137
+ }, [e, xe, i, o, s, w, f, Te, It]), z(() => {
3138
+ const p = U.current;
3139
+ !p || !t || p.setViewState(t);
3140
+ }, [t]), z(() => {
3141
+ const p = U.current;
3142
+ p && p.fitToImage();
3143
+ }, [l]), z(() => {
3144
+ const p = U.current;
3145
+ p && p.resetRotation();
3146
+ }, [h]), z(() => {
3147
+ const p = U.current;
3148
+ !p || !y || p.setPointPalette(y);
3149
+ }, [y]), z(() => {
3150
+ const p = U.current;
3151
+ p && p.setPointData(qt);
3152
+ }, [qt]), z(() => {
3153
+ if (!W) return;
3154
+ const B = er(S ? qt : m, ft, {
3155
+ paletteIndexToTermId: yt,
3105
3156
  includeEmptyRegions: !0
3106
3157
  });
3107
- z(B);
3108
- }, [z, A, g, _t, j, wt]), L(() => {
3109
- const w = R.current;
3110
- w && w.setInteractionLock(lt);
3111
- }, [lt]), /* @__PURE__ */ de("div", { className: O, style: dt, onPointerMove: ke, onPointerLeave: Ye, onClick: We, children: [
3112
- /* @__PURE__ */ Et(
3158
+ W(B);
3159
+ }, [W, S, m, qt, ft, yt]), z(() => {
3160
+ const p = U.current;
3161
+ p && p.setInteractionLock(st);
3162
+ }, [st]), /* @__PURE__ */ Ee("div", { className: et, style: Vt, onPointerMove: rn, onPointerLeave: on, onClick: sn, children: [
3163
+ /* @__PURE__ */ Mt(
3113
3164
  "canvas",
3114
3165
  {
3115
- ref: ot,
3166
+ ref: ut,
3116
3167
  className: "wsi-render-canvas",
3117
3168
  style: {
3118
3169
  position: "absolute",
@@ -3122,49 +3173,67 @@ function sr({
3122
3173
  height: "100%",
3123
3174
  display: "block",
3124
3175
  touchAction: "none",
3125
- cursor: Y === "cursor" && Q !== null ? "pointer" : lt ? "crosshair" : "grab"
3176
+ cursor: X === "cursor" && vt !== null ? "pointer" : st ? "crosshair" : "grab"
3126
3177
  }
3127
3178
  }
3128
3179
  ),
3129
- e ? /* @__PURE__ */ Et(
3130
- dn,
3180
+ e && Se && Array.isArray(ht) && ht.length > 0 ? ht.map((p, B) => /* @__PURE__ */ Mt(
3181
+ "div",
3182
+ {
3183
+ className: p.className,
3184
+ style: {
3185
+ position: "absolute",
3186
+ inset: 0,
3187
+ zIndex: p.zIndex ?? 3,
3188
+ pointerEvents: p.pointerEvents ?? "none",
3189
+ ...p.style
3190
+ },
3191
+ children: p.render(Se)
3192
+ },
3193
+ p.id ?? B
3194
+ )) : null,
3195
+ e ? /* @__PURE__ */ Mt(
3196
+ _n,
3131
3197
  {
3132
- tool: Y,
3133
- enabled: Y !== "cursor",
3198
+ tool: X,
3199
+ enabled: X !== "cursor",
3134
3200
  imageWidth: e.width,
3135
3201
  imageHeight: e.height,
3136
3202
  imageMpp: e.mpp,
3137
3203
  imageZoom: e.maxTierZoom,
3138
- stampOptions: yt,
3139
- projectorRef: R,
3204
+ stampOptions: At,
3205
+ projectorRef: U,
3140
3206
  viewStateSignal: t,
3141
- persistedRegions: j,
3142
- regionStrokeStyle: ht,
3143
- regionStrokeHoverStyle: nt,
3144
- regionStrokeActiveStyle: H,
3145
- resolveRegionStrokeStyle: V,
3146
- overlayShapes: J,
3147
- hoveredRegionId: Q,
3148
- activeRegionId: m,
3149
- regionLabelStyle: vt,
3150
- invalidateRef: W,
3151
- onDrawComplete: E
3207
+ persistedRegions: ft,
3208
+ patchRegions: ot,
3209
+ regionStrokeStyle: mt,
3210
+ regionStrokeHoverStyle: lt,
3211
+ regionStrokeActiveStyle: Rt,
3212
+ patchStrokeStyle: J,
3213
+ resolveRegionStrokeStyle: rt,
3214
+ overlayShapes: V,
3215
+ hoveredRegionId: vt,
3216
+ activeRegionId: u,
3217
+ regionLabelStyle: at,
3218
+ invalidateRef: P,
3219
+ onDrawComplete: O,
3220
+ onPatchComplete: gt
3152
3221
  }
3153
3222
  ) : null,
3154
- a ? /* @__PURE__ */ Et("pre", { "data-open-plant-debug-overlay": !0, style: Rt, children: Ne }) : null,
3155
- e && M ? rt ? /* @__PURE__ */ de(Oe, { children: [
3156
- /* @__PURE__ */ Et(gn, { source: e, projectorRef: R, authToken: p, options: I, invalidateRef: st }),
3157
- /* @__PURE__ */ Et(
3223
+ a ? /* @__PURE__ */ Mt("pre", { "data-open-plant-debug-overlay": !0, style: ie, children: nn }) : null,
3224
+ e && tt ? Lt ? /* @__PURE__ */ Ee(un, { children: [
3225
+ /* @__PURE__ */ Mt(Un, { source: e, projectorRef: U, authToken: w, options: q, invalidateRef: Y }),
3226
+ /* @__PURE__ */ Mt(
3158
3227
  "button",
3159
3228
  {
3160
3229
  type: "button",
3161
3230
  "aria-label": "Hide overview map",
3162
- onClick: () => q(!1),
3231
+ onClick: () => Tt(!1),
3163
3232
  style: {
3164
3233
  position: "absolute",
3165
3234
  zIndex: 6,
3166
- ...Nt.includes("left") ? { left: Mt } : { right: Mt },
3167
- ...Nt.includes("top") ? { top: Mt + le + 8 } : { bottom: Mt + le + 8 },
3235
+ ...Ht.includes("left") ? { left: _t } : { right: _t },
3236
+ ...Ht.includes("top") ? { top: _t + ye + 8 } : { bottom: _t + ye + 8 },
3168
3237
  width: 20,
3169
3238
  height: 20,
3170
3239
  borderRadius: 999,
@@ -3179,17 +3248,17 @@ function sr({
3179
3248
  children: "×"
3180
3249
  }
3181
3250
  )
3182
- ] }) : /* @__PURE__ */ Et(
3251
+ ] }) : /* @__PURE__ */ Mt(
3183
3252
  "button",
3184
3253
  {
3185
3254
  type: "button",
3186
3255
  "aria-label": "Show overview map",
3187
- onClick: () => q(!0),
3256
+ onClick: () => Tt(!0),
3188
3257
  style: {
3189
3258
  position: "absolute",
3190
3259
  zIndex: 6,
3191
- ...Nt.includes("left") ? { left: Mt } : { right: Mt },
3192
- ...Nt.includes("top") ? { top: Mt } : { bottom: Mt },
3260
+ ...Ht.includes("left") ? { left: _t } : { right: _t },
3261
+ ...Ht.includes("top") ? { top: _t } : { bottom: _t },
3193
3262
  height: 24,
3194
3263
  minWidth: 40,
3195
3264
  borderRadius: 999,
@@ -3207,32 +3276,34 @@ function sr({
3207
3276
  ] });
3208
3277
  }
3209
3278
  export {
3210
- Ce as DEFAULT_POINT_COLOR,
3211
- dn as DrawLayer,
3212
- Ke as M1TileRenderer,
3213
- gn as OverviewMap,
3214
- Xn as TileScheduler,
3215
- rr as TileViewerCanvas,
3216
- On as WsiTileRenderer,
3217
- sr as WsiViewerCanvas,
3218
- er as buildTermPalette,
3219
- Jn as calcScaleLength,
3220
- Ie as calcScaleResolution,
3221
- Z as clamp,
3222
- St as closeRing,
3223
- Yn as computeRoiPointGroups,
3224
- ye as createCircle,
3225
- we as createRectangle,
3226
- Kt as filterPointDataByPolygons,
3227
- _n as filterPointDataByPolygonsHybrid,
3228
- Fn as filterPointDataByPolygonsInWorker,
3229
- ir as getWebGpuCapabilities,
3230
- je as hexToRgba,
3231
- Qn as isSameViewState,
3232
- nr as normalizeImageInfo,
3233
- An as prefilterPointsByBoundsWebGpu,
3234
- or as terminateRoiClipWorker,
3235
- tr as toBearerToken,
3236
- Le as toTileUrl
3279
+ Xe as DEFAULT_POINT_COLOR,
3280
+ _n as DrawLayer,
3281
+ gn as M1TileRenderer,
3282
+ Un as OverviewMap,
3283
+ rr as TileScheduler,
3284
+ br as TileViewerCanvas,
3285
+ or as WsiTileRenderer,
3286
+ vr as WsiViewerCanvas,
3287
+ pr as buildTermPalette,
3288
+ fr as calcScaleLength,
3289
+ Ve as calcScaleResolution,
3290
+ j as clamp,
3291
+ Pt as closeRing,
3292
+ er as computeRoiPointGroups,
3293
+ Ue as createCircle,
3294
+ Be as createRectangle,
3295
+ re as filterPointDataByPolygons,
3296
+ Hn as filterPointDataByPolygonsHybrid,
3297
+ Zn as filterPointDataByPolygonsInWorker,
3298
+ Dn as filterPointIndicesByPolygons,
3299
+ Tr as filterPointIndicesByPolygonsInWorker,
3300
+ yr as getWebGpuCapabilities,
3301
+ pn as hexToRgba,
3302
+ mr as isSameViewState,
3303
+ wr as normalizeImageInfo,
3304
+ On as prefilterPointsByBoundsWebGpu,
3305
+ xr as terminateRoiClipWorker,
3306
+ gr as toBearerToken,
3307
+ Ze as toTileUrl
3237
3308
  };
3238
3309
  //# sourceMappingURL=index.js.map