@mintplayer/web-components 2.12.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,24 @@
1
- import { unsafeCSS as I, LitElement as w, html as u, nothing as d, svg as g } from "lit";
2
- import { repeat as b } from "lit/directives/repeat.js";
3
- import { styleMap as f } from "lit/directives/style-map.js";
4
- import { L as k } from "../../chunks/live-announcer-Bi0orG4n.mjs";
5
- import { e as v, d as y, g as z, r as x, f as p, p as $, a as S, c as M, b as U, l as A, s as F } from "../../chunks/color-5yPBn70k.mjs";
6
- const C = I(`@charset "UTF-8";
1
+ import { unsafeCSS as T, LitElement as F, html as c, nothing as d, svg as k } from "lit";
2
+ import { repeat as f } from "lit/directives/repeat.js";
3
+ import { styleMap as v } from "lit/directives/style-map.js";
4
+ import { L as C } from "../../chunks/live-announcer-Bi0orG4n.mjs";
5
+ import { d as z, c as $, k as U, j as L, e as q, f as S, i as m, p as I, a as R, b as O, g as A, l as D, s as Z, h as E } from "../../chunks/color-DIeST-IS.mjs";
6
+ const P = T(`@charset "UTF-8";
7
7
  :host {
8
- display: block;
8
+ /* Flex column so the optional breadcrumb takes its own row; without it the
9
+ chart is the only child and fills the host exactly as before. */
10
+ display: flex;
11
+ flex-direction: column;
9
12
  width: 100%;
10
13
  aspect-ratio: 1;
11
14
  /* Two-level fallbacks: Bootstrap 5.3 reassigns --bs-* per data-bs-theme and
12
15
  custom properties inherit through the shadow boundary, so dark mode needs
13
16
  no media query here. */
14
- --mp-hierarchy-chart-label-color: var(--bs-body-color, #212529);
15
- --mp-hierarchy-chart-arc-label-color: var(--bs-light, #f8f9fa);
17
+ /* Node labels contrast against the DATA-COLORED surface under them, not the
18
+ page theme — the element picks one of this pair per node from the fill
19
+ composited over the resolved backdrop. Deliberately NOT --bs-* driven. */
20
+ --mp-hierarchy-chart-label-on-light: #1c1f23;
21
+ --mp-hierarchy-chart-label-on-dark: #f8f9fa;
16
22
  --mp-hierarchy-chart-center-color: var(--bs-body-color, #212529);
17
23
  --mp-hierarchy-chart-center-bg: var(--bs-body-bg, #ffffff);
18
24
  --mp-hierarchy-chart-node-fill: var(--bs-secondary-bg, #e9ecef);
@@ -30,7 +36,53 @@ const C = I(`@charset "UTF-8";
30
36
  .chart {
31
37
  position: relative;
32
38
  width: 100%;
33
- height: 100%;
39
+ flex: 1 1 auto;
40
+ min-height: 0;
41
+ /* The geometric zoom window: content outside it must clip, not spill. */
42
+ overflow: hidden;
43
+ }
44
+
45
+ .breadcrumb {
46
+ display: flex;
47
+ flex-wrap: wrap;
48
+ align-items: center;
49
+ flex: 0 0 auto;
50
+ gap: 0.125rem;
51
+ margin: 0;
52
+ padding: 0 0 0.25rem;
53
+ font-size: 0.875rem;
54
+ }
55
+
56
+ .crumb {
57
+ min-width: 24px;
58
+ min-height: 24px;
59
+ padding: 0.125rem 0.375rem;
60
+ background: transparent;
61
+ border: 0;
62
+ border-radius: 0.25rem;
63
+ color: var(--mp-hierarchy-chart-center-color);
64
+ font: inherit;
65
+ cursor: pointer;
66
+ text-decoration: underline;
67
+ }
68
+
69
+ .crumb-current {
70
+ padding: 0.125rem 0.375rem;
71
+ color: var(--mp-hierarchy-chart-center-color);
72
+ font-weight: 600;
73
+ }
74
+
75
+ .crumb-sep {
76
+ opacity: 0.5;
77
+ user-select: none;
78
+ }
79
+
80
+ /* Only when pinch is enabled: removing pinch-zoom from touch-action is what
81
+ hands two-finger gestures to JS (S4-measured) while one-finger pan stays
82
+ native. Never applied with zoom-gestures="none"/"wheel", so browser page
83
+ pinch-zoom over the chart keeps working there. */
84
+ .chart.pinch {
85
+ touch-action: pan-x pan-y;
34
86
  }
35
87
 
36
88
  svg {
@@ -50,15 +102,24 @@ svg {
50
102
  cursor: default;
51
103
  }
52
104
 
105
+ /* font-size comes per-element from the component (device px converted to
106
+ viewBox units against the measured host scale — labels never scale with
107
+ host size or zoom). */
53
108
  .arc-label {
54
- fill: var(--mp-hierarchy-chart-arc-label-color);
55
- font-size: 26px; /* logical viewBox units (1000x1000) */
56
109
  text-anchor: middle;
57
110
  dominant-baseline: middle;
58
111
  pointer-events: none;
59
112
  user-select: none;
60
113
  }
61
114
 
115
+ .arc-label[data-surface=light] {
116
+ fill: var(--mp-hierarchy-chart-label-on-light);
117
+ }
118
+
119
+ .arc-label[data-surface=dark] {
120
+ fill: var(--mp-hierarchy-chart-label-on-dark);
121
+ }
122
+
62
123
  /* HTML overlay button in the sunburst hole (a role=tree svg cannot own a button). */
63
124
  .center-control {
64
125
  position: absolute;
@@ -92,8 +153,7 @@ svg {
92
153
  background: var(--mp-hierarchy-chart-node-fill);
93
154
  border: 1px solid var(--mp-hierarchy-chart-gap);
94
155
  border-radius: 2px;
95
- color: var(--mp-hierarchy-chart-label-color);
96
- font-size: 0.8125rem;
156
+ /* font-size is set inline by the component (constant device px). */
97
157
  line-height: 1.25;
98
158
  padding: 1px 4px;
99
159
  cursor: pointer;
@@ -144,6 +204,40 @@ svg {
144
204
  display: block;
145
205
  }
146
206
 
207
+ /* Transient "how to zoom" overlay shown on an uncaptured plain wheel — the
208
+ embedded-maps convention. Purely visual: aria-hidden, no pointer events. */
209
+ .zoom-hint {
210
+ position: absolute;
211
+ top: 50%;
212
+ left: 50%;
213
+ transform: translate(-50%, -50%);
214
+ max-width: 90%;
215
+ padding: 0.375rem 0.75rem;
216
+ background: var(--mp-hierarchy-chart-tooltip-bg);
217
+ color: var(--mp-hierarchy-chart-tooltip-color);
218
+ border-radius: 0.25rem;
219
+ font-size: 0.875rem;
220
+ text-align: center;
221
+ pointer-events: none;
222
+ user-select: none;
223
+ z-index: 2;
224
+ animation: mp-hierarchy-chart-hint 1.5s ease-out forwards;
225
+ }
226
+
227
+ @keyframes mp-hierarchy-chart-hint {
228
+ 0% {
229
+ opacity: 0;
230
+ }
231
+ 15% {
232
+ opacity: 1;
233
+ }
234
+ 80% {
235
+ opacity: 1;
236
+ }
237
+ 100% {
238
+ opacity: 0;
239
+ }
240
+ }
147
241
  .cell[data-leaf] {
148
242
  cursor: default;
149
243
  }
@@ -155,6 +249,14 @@ svg {
155
249
  white-space: nowrap;
156
250
  }
157
251
 
252
+ .cell[data-surface=light] {
253
+ color: var(--mp-hierarchy-chart-label-on-light);
254
+ }
255
+
256
+ .cell[data-surface=dark] {
257
+ color: var(--mp-hierarchy-chart-label-on-dark);
258
+ }
259
+
158
260
  /* A treemap branch tile is a frame: children render inside its header inset,
159
261
  its own strip shows the label. */
160
262
  .treemap .cell[data-branch] {
@@ -185,7 +287,8 @@ svg {
185
287
  }
186
288
 
187
289
  .center-control:focus-visible,
188
- .treemap-header:focus-visible {
290
+ .treemap-header:focus-visible,
291
+ .crumb:focus-visible {
189
292
  outline: 3px solid var(--mp-hierarchy-chart-focus-ring-color);
190
293
  outline-offset: 2px;
191
294
  }
@@ -207,20 +310,21 @@ svg {
207
310
  }
208
311
  @media (prefers-reduced-motion: reduce) {
209
312
  .ring,
210
- .cell {
313
+ .cell,
314
+ .zoom-hint {
211
315
  transition: none !important;
212
316
  animation: none !important;
213
317
  }
214
- }`), c = 1e3, m = 2 * Math.PI;
215
- function T() {
318
+ }`), u = 1e3, y = 2 * Math.PI;
319
+ function N() {
216
320
  return typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches;
217
321
  }
218
- class q extends w {
322
+ class x extends F {
219
323
  constructor() {
220
- super(...arguments), this._layout = "sunburst", this._maxDepth = 2, this._minAngle = 0.2, this._minSize = 4, this._showLabels = !0, this._labelMinArea = 0.03, this._colorMin = 0, this._colorMax = 100, this._colorStart = "#fe0000", this._colorEnd = "#21b577", this._inputLabel = null, this._transitionDuration = 300, this._loadingIds = /* @__PURE__ */ new Set(), this._failedIds = /* @__PURE__ */ new Set(), this._loadedIds = /* @__PURE__ */ new Set(), this._loadingLabel = "Loading", this._fill = v(this._colorMin, this._colorMax, this._colorStart, this._colorEnd), this._prevSpans = /* @__PURE__ */ new Map(), this._tween = 1, this._tweenFrame = 0, this._hoveredId = null, this._focusedId = null, this._restoreFocus = !1, this._rendered = [], this._typeahead = "", this._typeaheadTimer = 0, this._zoomOutLabel = "Zoom out one level", this._metricUnitLabel = "%", this._valueUnitLabel = "", this.liveAnnouncer = new k(this, { omitRole: !0 });
324
+ super(...arguments), this._layout = "sunburst", this._maxDepth = void 0, this._minAngle = 0.2, this._minSize = 4, this._showLabels = !0, this._labelFontSize = 12, this._backdrop = "#ffffff", this._hostScale = 0.42, this._colorMin = 0, this._colorMax = 100, this._colorStart = "#fe0000", this._colorEnd = "#21b577", this._inputLabel = null, this._transitionDuration = 300, this._loadingIds = /* @__PURE__ */ new Set(), this._failedIds = /* @__PURE__ */ new Set(), this._loadedIds = /* @__PURE__ */ new Set(), this._loadingLabel = "Loading", this._fill = z(this._colorMin, this._colorMax, this._colorStart, this._colorEnd), this._prevSpans = /* @__PURE__ */ new Map(), this._tween = 1, this._tweenFrame = 0, this._hoveredId = null, this._focusedId = null, this._restoreFocus = !1, this._rendered = [], this._typeahead = "", this._typeaheadTimer = 0, this._zoomOutLabel = "Zoom out one level", this._metricUnitLabel = "%", this._valueUnitLabel = "", this.liveAnnouncer = new C(this, { omitRole: !0 }), this._showBreadcrumb = !1, this._breadcrumbLabel = "Chart path", this._gestures = /* @__PURE__ */ new Set(["wheel", "pinch"]), this._hintVisible = !1, this._hintTimer = 0, this._wheelListener = (e) => this.onWheel(e), this._viewZoom = 1, this._viewX = 0, this._viewY = 0, this._pinchPointers = /* @__PURE__ */ new Map(), this._dragPointer = null, this._dragLast = { x: 0, y: 0 }, this._dragTotal = 0, this._dragMoved = !1, this._dismissedForId = null;
221
325
  }
222
326
  static {
223
- this.styles = [C];
327
+ this.styles = [P];
224
328
  }
225
329
  static get observedAttributes() {
226
330
  return [
@@ -231,13 +335,18 @@ class q extends w {
231
335
  "min-angle",
232
336
  "min-size",
233
337
  "show-labels",
234
- "label-min-area",
338
+ "label-font-size",
339
+ "backdrop",
235
340
  "color-min",
236
341
  "color-max",
237
342
  "color-start",
238
343
  "color-end",
239
344
  "transition-duration",
240
345
  "locale",
346
+ "zoom-gestures",
347
+ "zoom-hint-label",
348
+ "show-breadcrumb",
349
+ "breadcrumb-label",
241
350
  "zoom-out-label",
242
351
  "metric-unit-label",
243
352
  "value-unit-label",
@@ -252,29 +361,35 @@ class q extends w {
252
361
  return this._data;
253
362
  }
254
363
  set data(e) {
255
- this._data = e, this._index = e ? y(e) : void 0, this.requestUpdate();
364
+ this._data = e, this._index = e ? $(e) : void 0, this.resetZoom();
256
365
  }
257
366
  get layout() {
258
367
  return this._layout;
259
368
  }
260
369
  set layout(e) {
261
- this._layout = e === "icicle" || e === "treemap" ? e : "sunburst", this.requestUpdate();
370
+ this._layout = e === "icicle" || e === "treemap" ? e : "sunburst", this.resetZoom();
262
371
  }
263
372
  get rootId() {
264
373
  return this._rootId;
265
374
  }
266
375
  set rootId(e) {
267
- const i = e || void 0;
268
- i !== this._rootId && (this.beginTween(), this._rootId = i, i === void 0 ? this.removeAttribute("root-id") : this.setAttribute("root-id", i), this.requestUpdate());
376
+ const t = e || void 0;
377
+ t !== this._rootId && (this.beginTween(), this._rootId = t, t === void 0 ? this.removeAttribute("root-id") : this.setAttribute("root-id", t), this.requestUpdate());
269
378
  }
270
379
  /**
271
380
  * Levels rendered outward from the focus node, or `'auto'` for every loaded
272
- * level. Default 2 (codecov's window), which keeps the DOM small on a big
273
- * tree; any positive number is valid, and `'auto'` follows the data — with
274
- * lazy loading that means each arriving level reveals the next.
381
+ * level. Any positive number is valid.
382
+ *
383
+ * Left unset it resolves to `'auto'` — a chart given a whole tree should draw
384
+ * the tree it was given — EXCEPT when a `loadChildren` loader is present:
385
+ * `'auto'` treats the deepest rendered ring as a load candidate, so an
386
+ * unbounded lazy chart walks the entire remote tree one level per render (see
387
+ * `loadLazyCandidates`). Lazy charts therefore keep the bounded 2-level
388
+ * window (codecov's) unless the consumer asks for `'auto'` explicitly and
389
+ * means it.
275
390
  */
276
391
  get maxDepth() {
277
- return this._maxDepth;
392
+ return this._maxDepth ?? (this._loadChildren ? 2 : "auto");
278
393
  }
279
394
  set maxDepth(e) {
280
395
  this._maxDepth = e === "auto" ? "auto" : Math.max(1, Math.floor(Number(e) || 2)), this.requestUpdate();
@@ -285,7 +400,8 @@ class q extends w {
285
400
  * draws its (empty) first ring.
286
401
  */
287
402
  get renderedDepth() {
288
- return this._maxDepth !== "auto" ? this._maxDepth : this._index ? Math.max(1, z(this._index, this._rootId)) : 1;
403
+ const e = this.maxDepth;
404
+ return e !== "auto" ? e : this._index ? Math.max(1, U(this._index, this._rootId)) : 1;
289
405
  }
290
406
  get minAngle() {
291
407
  return this._minAngle;
@@ -305,11 +421,24 @@ class q extends w {
305
421
  set showLabels(e) {
306
422
  this._showLabels = !!e, this.requestUpdate();
307
423
  }
308
- get labelMinArea() {
309
- return this._labelMinArea;
424
+ /** Label font size in DEVICE px — held constant across host size and zoom state. */
425
+ get labelFontSize() {
426
+ return this._labelFontSize;
427
+ }
428
+ set labelFontSize(e) {
429
+ this._labelFontSize = Math.max(1, Number(e) || 12), this.requestUpdate();
430
+ }
431
+ /**
432
+ * Opaque CSS color behind the chart, used to composite translucent fills
433
+ * before picking a contrasting label color. Unset = auto-detected from the
434
+ * nearest opaque ancestor background (set it when the walk cannot see the
435
+ * real backdrop: images, gradients, cross-document embedding).
436
+ */
437
+ get backdrop() {
438
+ return this._backdropOverride;
310
439
  }
311
- set labelMinArea(e) {
312
- this._labelMinArea = Math.max(0, Number(e) || 0), this.requestUpdate();
440
+ set backdrop(e) {
441
+ this._backdropOverride = e || void 0, this.requestUpdate();
313
442
  }
314
443
  get colorMin() {
315
444
  return this._colorMin;
@@ -378,69 +507,101 @@ class q extends w {
378
507
  this._loadingLabel = e ?? "Loading";
379
508
  }
380
509
  rebuildScale() {
381
- this._fill = v(this._colorMin, this._colorMax, this._colorStart, this._colorEnd), this.requestUpdate();
510
+ this._fill = z(this._colorMin, this._colorMax, this._colorStart, this._colorEnd), this.requestUpdate();
382
511
  }
383
- attributeChangedCallback(e, i, t) {
384
- switch (super.attributeChangedCallback(e, i, t), e) {
512
+ attributeChangedCallback(e, t, i) {
513
+ switch (super.attributeChangedCallback(e, t, i), e) {
385
514
  case "layout":
386
- this.layout = t ?? "sunburst";
515
+ this.layout = i ?? "sunburst";
387
516
  break;
388
517
  case "root-id":
389
- this.rootId = t ?? void 0;
518
+ this.rootId = i ?? void 0;
390
519
  break;
391
520
  case "max-depth":
392
- this.maxDepth = t === "auto" ? "auto" : Number(t ?? 2);
521
+ i === null ? (this._maxDepth = void 0, this.requestUpdate()) : this.maxDepth = i === "auto" ? "auto" : Number(i);
393
522
  break;
394
523
  case "min-angle":
395
- this.minAngle = Number(t ?? 0.2);
524
+ this.minAngle = Number(i ?? 0.2);
396
525
  break;
397
526
  case "min-size":
398
- this.minSize = Number(t ?? 4);
527
+ this.minSize = Number(i ?? 4);
399
528
  break;
400
529
  case "show-labels":
401
- this.showLabels = t !== "false" && t !== null;
530
+ this.showLabels = i !== "false" && i !== null;
531
+ break;
532
+ case "label-font-size":
533
+ this.labelFontSize = Number(i ?? 12);
402
534
  break;
403
- case "label-min-area":
404
- this.labelMinArea = Number(t ?? 0.03);
535
+ case "backdrop":
536
+ this.backdrop = i ?? void 0;
405
537
  break;
406
538
  case "color-min":
407
- this.colorMin = Number(t ?? 0);
539
+ this.colorMin = Number(i ?? 0);
408
540
  break;
409
541
  case "color-max":
410
- this.colorMax = Number(t ?? 100);
542
+ this.colorMax = Number(i ?? 100);
411
543
  break;
412
544
  case "color-start":
413
- this.colorStart = t ?? "#fe0000";
545
+ this.colorStart = i ?? "#fe0000";
414
546
  break;
415
547
  case "color-end":
416
- this.colorEnd = t ?? "#21b577";
548
+ this.colorEnd = i ?? "#21b577";
417
549
  break;
418
550
  case "transition-duration":
419
- this.transitionDuration = Number(t ?? 300);
551
+ this.transitionDuration = Number(i ?? 300);
420
552
  break;
421
553
  case "locale":
422
- this.locale = t ?? void 0;
554
+ this.locale = i ?? void 0;
555
+ break;
556
+ case "zoom-gestures":
557
+ this.zoomGestures = i ?? "wheel pinch";
558
+ break;
559
+ case "zoom-hint-label":
560
+ this._zoomHintLabel = i ?? void 0;
561
+ break;
562
+ case "show-breadcrumb":
563
+ this.showBreadcrumb = i !== "false" && i !== null;
564
+ break;
565
+ case "breadcrumb-label":
566
+ this._breadcrumbLabel = i ?? "Chart path", this.requestUpdate();
423
567
  break;
424
568
  case "zoom-out-label":
425
- this._zoomOutLabel = t ?? "Zoom out one level", this.requestUpdate();
569
+ this._zoomOutLabel = i ?? "Zoom out one level", this.requestUpdate();
426
570
  break;
427
571
  case "loading-label":
428
- this._loadingLabel = t ?? "Loading";
572
+ this._loadingLabel = i ?? "Loading";
429
573
  break;
430
574
  case "metric-unit-label":
431
- this._metricUnitLabel = t ?? "%", this.requestUpdate();
575
+ this._metricUnitLabel = i ?? "%", this.requestUpdate();
432
576
  break;
433
577
  case "value-unit-label":
434
- this._valueUnitLabel = t ?? "", this.requestUpdate();
578
+ this._valueUnitLabel = i ?? "", this.requestUpdate();
435
579
  break;
436
580
  case "aria-label":
437
581
  this.requestUpdate();
438
582
  break;
439
583
  case "input-label":
440
- this.inputLabel = t;
584
+ this.inputLabel = i;
441
585
  break;
442
586
  }
443
587
  }
588
+ /**
589
+ * Renders the focus path as real buttons above the chart: a single-pointer,
590
+ * keyboard-operable way back up, and the visible statement of zoom state
591
+ * (PRD hierarchy-chart-zoom-labels B1). Off by default.
592
+ */
593
+ get showBreadcrumb() {
594
+ return this._showBreadcrumb;
595
+ }
596
+ set showBreadcrumb(e) {
597
+ this._showBreadcrumb = !!e, this.requestUpdate();
598
+ }
599
+ get breadcrumbLabel() {
600
+ return this._breadcrumbLabel;
601
+ }
602
+ set breadcrumbLabel(e) {
603
+ this._breadcrumbLabel = e || "Chart path", this.requestUpdate();
604
+ }
444
605
  get zoomOutLabel() {
445
606
  return this._zoomOutLabel;
446
607
  }
@@ -461,155 +622,380 @@ class q extends w {
461
622
  }
462
623
  /** The node the chart is rooted on right now (tree root when root-id is unset). */
463
624
  get focusedRoot() {
464
- return this._index ? x(this._index, this._rootId) : void 0;
625
+ return this._index ? L(this._index, this._rootId) : void 0;
626
+ }
627
+ /* ---------- rendered size + backdrop (label contrast inputs) ---------- */
628
+ connectedCallback() {
629
+ super.connectedCallback(), this.addEventListener("wheel", this._wheelListener, { passive: !1 }), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver((e) => {
630
+ const t = e[e.length - 1]?.contentRect.width;
631
+ if (!t) return;
632
+ const i = t / u;
633
+ Math.abs(i - this._hostScale) > 1e-3 && (this._hostScale = i, this.requestUpdate());
634
+ }), this._resizeObserver.observe(this));
635
+ }
636
+ disconnectedCallback() {
637
+ this.removeEventListener("wheel", this._wheelListener), clearTimeout(this._hintTimer), this._resizeObserver?.disconnect(), this._resizeObserver = void 0, super.disconnectedCallback();
638
+ }
639
+ willUpdate(e) {
640
+ super.willUpdate(e), this._tween >= 1 && this.resolveBackdrop();
641
+ }
642
+ /**
643
+ * The first opaque computed background-color above the host (shadow roots
644
+ * crossed via .host). A live theme flip is picked up on the next render —
645
+ * one frame of suboptimal-but-legible contrast, self-correcting.
646
+ */
647
+ resolveBackdrop() {
648
+ if (this._backdropOverride) {
649
+ this._backdrop = this._backdropOverride;
650
+ return;
651
+ }
652
+ if (typeof getComputedStyle != "function") return;
653
+ let e = this;
654
+ for (; e; ) {
655
+ const t = getComputedStyle(e).backgroundColor;
656
+ if (B(t)) {
657
+ this._backdrop = t;
658
+ return;
659
+ }
660
+ const i = e.getRootNode();
661
+ e = e.parentElement ?? (i instanceof ShadowRoot ? i.host : null);
662
+ }
663
+ }
664
+ /** Which token bucket a label over this node should use: the surface's tone. */
665
+ surfaceToneOf(e, t) {
666
+ const i = this.fillOf(e), r = i ? q(i, this._backdrop, t) : void 0;
667
+ return this.toneOfSurface(r);
668
+ }
669
+ toneOfSurface(e) {
670
+ return ((e !== void 0 ? S(e) : void 0) ?? S(this._backdrop) ?? "dark") === "dark" ? "light" : "dark";
671
+ }
672
+ /** Space-separated gesture allowlist: 'wheel pinch' (default) | 'wheel' | 'pinch' | 'none'. */
673
+ get zoomGestures() {
674
+ return this._gestures.size ? [...this._gestures].join(" ") : "none";
675
+ }
676
+ set zoomGestures(e) {
677
+ const t = (e ?? "").toLowerCase().split(/\s+/);
678
+ this._gestures = new Set(
679
+ t.filter((i) => i === "wheel" || i === "pinch")
680
+ );
681
+ }
682
+ get zoomHintLabel() {
683
+ return this._zoomHintLabel !== void 0 ? this._zoomHintLabel : typeof navigator < "u" && /Mac|iPhone|iPad/.test(navigator.platform ?? "") ? "Use ⌘ + scroll to zoom the chart" : "Use Ctrl + scroll to zoom the chart";
684
+ }
685
+ set zoomHintLabel(e) {
686
+ this._zoomHintLabel = e || void 0;
687
+ }
688
+ static {
689
+ this.MAX_ZOOM = 32;
690
+ }
691
+ /** Current geometric magnification (1 = fitted). Read-only state for consumers/tests. */
692
+ get zoomLevel() {
693
+ return this._viewZoom;
694
+ }
695
+ /** Programmatic geometric zoom, anchored at chart fractions (default: center). */
696
+ setZoomLevel(e, t = 0.5, i = 0.5) {
697
+ const r = Math.min(x.MAX_ZOOM, Math.max(1, Number(e) || 1)), s = this._viewX + t / this._viewZoom, a = this._viewY + i / this._viewZoom;
698
+ this._viewZoom = r, this._viewX = g(s - t / r, r), this._viewY = g(a - i / r, r), this.requestUpdate();
699
+ }
700
+ resetZoom() {
701
+ this._viewZoom = 1, this._viewX = 0, this._viewY = 0, this.requestUpdate();
702
+ }
703
+ /** Pan by chart-screen fractions (drag / two-finger move). */
704
+ panBy(e, t) {
705
+ this._viewZoom <= 1 || (this._viewX = g(this._viewX - e / this._viewZoom, this._viewZoom), this._viewY = g(this._viewY - t / this._viewZoom, this._viewZoom), this.requestUpdate());
706
+ }
707
+ /** Map a normalized content rect through the view window to chart fractions. */
708
+ viewRect(e, t, i, r) {
709
+ const s = this._viewZoom;
710
+ return {
711
+ x0: (e - this._viewX) * s,
712
+ y0: (t - this._viewY) * s,
713
+ x1: (i - this._viewX) * s,
714
+ y1: (r - this._viewY) * s
715
+ };
716
+ }
717
+ /** Pointer position as chart fractions, for anchor-at-cursor zooming. */
718
+ chartAnchor(e) {
719
+ const t = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect();
720
+ return !t || !t.width || !t.height ? { x: 0.5, y: 0.5 } : {
721
+ x: Math.min(1, Math.max(0, (e.clientX - t.left) / t.width)),
722
+ y: Math.min(1, Math.max(0, (e.clientY - t.top) / t.height))
723
+ };
724
+ }
725
+ /** Device px per normalized content unit — the label fit tests' scale. */
726
+ get effectiveScale() {
727
+ return this._hostScale * this._viewZoom;
728
+ }
729
+ onWheel(e) {
730
+ if (!this._gestures.has("wheel") || !this._index) return;
731
+ if (!e.ctrlKey && !e.metaKey) {
732
+ this.showZoomHint();
733
+ return;
734
+ }
735
+ e.preventDefault();
736
+ const t = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? this.clientHeight || 400 : 1, i = Math.max(-100, Math.min(100, e.deltaY * t)), r = this.chartAnchor(e);
737
+ this.setZoomLevel(this._viewZoom * Math.exp(-i * 5e-3), r.x, r.y);
738
+ }
739
+ pinchDistance() {
740
+ const [e, t] = [...this._pinchPointers.values()];
741
+ return Math.hypot(t.x - e.x, t.y - e.y);
742
+ }
743
+ pinchMidpoint() {
744
+ const [e, t] = [...this._pinchPointers.values()];
745
+ return { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 };
746
+ }
747
+ onPointerDown(e) {
748
+ if (e.pointerType === "touch") {
749
+ if (!this._gestures.has("pinch")) return;
750
+ this._pinchPointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
751
+ return;
752
+ }
753
+ this._viewZoom > 1 && e.button === 0 && (this._dragPointer = e.pointerId, this._dragLast = { x: e.clientX, y: e.clientY }, this._dragTotal = 0, this._dragMoved = !1);
754
+ }
755
+ /** @returns true when the move belonged to a pinch or drag (skip hover handling). */
756
+ trackViewGesture(e) {
757
+ if (e.pointerType === "touch" && this._pinchPointers.has(e.pointerId)) {
758
+ if (this._pinchPointers.size !== 2)
759
+ return this._pinchPointers.set(e.pointerId, { x: e.clientX, y: e.clientY }), !1;
760
+ const t = this.pinchDistance(), i = this.pinchMidpoint();
761
+ if (this._pinchPointers.set(e.pointerId, { x: e.clientX, y: e.clientY }), t > 0) {
762
+ const r = this.pinchMidpoint(), s = this.chartAnchor({ clientX: r.x, clientY: r.y });
763
+ this.setZoomLevel(this._viewZoom * (this.pinchDistance() / t), s.x, s.y);
764
+ const a = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect();
765
+ a?.width && a.height && this.panBy((r.x - i.x) / a.width, (r.y - i.y) / a.height);
766
+ }
767
+ return !0;
768
+ }
769
+ if (this._dragPointer === e.pointerId) {
770
+ const t = e.clientX - this._dragLast.x, i = e.clientY - this._dragLast.y;
771
+ this._dragLast = { x: e.clientX, y: e.clientY }, this._dragTotal += Math.abs(t) + Math.abs(i), this._dragTotal > 3 && (this._dragMoved = !0);
772
+ const r = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect();
773
+ return r?.width && r.height && this.panBy(t / r.width, i / r.height), !0;
774
+ }
775
+ return !1;
776
+ }
777
+ /** pointerup ends the gesture; pointercancel abandons it (divergent engines degrade to tap). */
778
+ endViewGesture(e) {
779
+ this._pinchPointers.delete(e.pointerId), this._dragPointer === e.pointerId && (this._dragPointer = null);
780
+ }
781
+ showZoomHint() {
782
+ this._hintVisible = !0, clearTimeout(this._hintTimer), this._hintTimer = setTimeout(() => {
783
+ this._hintVisible = !1, this.requestUpdate();
784
+ }, 1500), this.requestUpdate();
465
785
  }
466
786
  /* ---------- zoom ---------- */
467
787
  /** Re-root on a node id (undefined = tree root) and emit `hierarchy-zoom`. */
468
788
  zoomTo(e) {
469
- const i = this._index;
470
- if (!i) return;
471
- const t = x(i, e);
472
- t !== this.focusedRoot && (this.rootId = t === i.root ? void 0 : t.id, this.liveAnnouncer.announce(this.labelText(t)), this.emit("hierarchy-zoom", { node: t, path: p(i, t) }));
789
+ const t = this._index;
790
+ if (!t) return;
791
+ const i = L(t, e);
792
+ i !== this.focusedRoot && (this.resetZoom(), this.rootId = i === t.root ? void 0 : i.id, this.liveAnnouncer.announce(this.labelText(i)), this.emit("hierarchy-zoom", { node: i, path: m(t, i) }));
473
793
  }
474
794
  /** Move the roving tabindex (and DOM focus) to a rendered node. */
475
795
  focusNode(e) {
476
- this._rendered.some((i) => i.id === e) && (this._focusedId = e, this._restoreFocus = !0, this.requestUpdate());
796
+ this._rendered.some((t) => t.id === e) && (this._focusedId = e, this._restoreFocus = !0, this.requestUpdate());
477
797
  }
478
798
  zoomOut() {
479
- const e = this._index, i = this.focusedRoot;
480
- !e || !i || i === e.root || this.zoomTo(e.parents.get(i.id)?.id);
799
+ const e = this._index, t = this.focusedRoot;
800
+ !e || !t || t === e.root || this.zoomTo(e.parents.get(t.id)?.id);
481
801
  }
482
802
  /* ---------- sunburst tween ---------- */
483
803
  beginTween() {
484
- if (this._transitionDuration <= 0 || T() || this._layout !== "sunburst" || !this._prevSpans.size) return;
804
+ if (this._transitionDuration <= 0 || N() || this._layout !== "sunburst" || !this._prevSpans.size) return;
485
805
  cancelAnimationFrame(this._tweenFrame);
486
- const e = performance.now(), i = (t) => {
487
- this._tween = Math.min(1, (t - e) / this._transitionDuration), this.requestUpdate(), this._tween < 1 && (this._tweenFrame = requestAnimationFrame(i));
806
+ const e = performance.now(), t = (i) => {
807
+ this._tween = Math.min(1, (i - e) / this._transitionDuration), this.requestUpdate(), this._tween < 1 && (this._tweenFrame = requestAnimationFrame(t));
488
808
  };
489
- this._tween = 0, this._tweenFrame = requestAnimationFrame(i);
809
+ this._tween = 0, this._tweenFrame = requestAnimationFrame(t);
490
810
  }
491
811
  tweenedSpan(e) {
492
812
  if (this._tween >= 1) return e;
493
- const i = 1 - (1 - this._tween) * (1 - this._tween), t = this._prevSpans.get(e.node.id) ?? { x0: e.x0, x1: e.x0 };
813
+ const t = 1 - (1 - this._tween) * (1 - this._tween), i = this._prevSpans.get(e.node.id) ?? { x0: e.x0, x1: e.x0 };
494
814
  return {
495
- x0: t.x0 + (e.x0 - t.x0) * i,
496
- x1: t.x1 + (e.x1 - t.x1) * i
815
+ x0: i.x0 + (e.x0 - i.x0) * t,
816
+ x1: i.x1 + (e.x1 - i.x1) * t
497
817
  };
498
818
  }
499
819
  /* ---------- pointer interaction ---------- */
500
820
  nodeFromEvent(e) {
501
- const t = e.composedPath()[0]?.closest?.("[data-id]")?.getAttribute("data-id");
502
- return t ? this._index?.byId.get(t) : void 0;
821
+ const i = e.composedPath()[0]?.closest?.("[data-id]")?.getAttribute("data-id");
822
+ return i ? this._index?.byId.get(i) : void 0;
503
823
  }
504
824
  onClick(e) {
505
- const i = this._index, t = this.nodeFromEvent(e);
506
- if (!(!i || !t)) {
507
- if (t === this.focusedRoot) {
825
+ if (this._dragMoved) {
826
+ this._dragMoved = !1;
827
+ return;
828
+ }
829
+ const t = this._index, i = this.nodeFromEvent(e);
830
+ if (!(!t || !i)) {
831
+ if (i === this.focusedRoot) {
508
832
  this.zoomOut();
509
833
  return;
510
834
  }
511
- if (this._failedIds.delete(t.id), this._loadedIds.delete(t.id), t.children?.length || t.hasChildren && this._loadChildren) {
512
- this.zoomTo(t.id);
835
+ if (this._failedIds.delete(i.id), this._loadedIds.delete(i.id), i.children?.length || i.hasChildren && this._loadChildren) {
836
+ this.zoomTo(i.id);
513
837
  return;
514
838
  }
515
- this.emit("hierarchy-node-select", { node: t, path: p(i, t) });
839
+ this.emit("hierarchy-node-select", { node: i, path: m(t, i) });
516
840
  }
517
841
  }
842
+ get tooltipEl() {
843
+ return this.shadowRoot?.querySelector(".chart-tooltip") ?? null;
844
+ }
845
+ isTooltipVisible() {
846
+ return this.tooltipEl?.hasAttribute("data-visible") ?? !1;
847
+ }
848
+ /** Show the tooltip for a node at chart-relative coordinates, clamped inside the chart. */
849
+ showTooltip(e, t, i) {
850
+ const r = this.tooltipEl, s = this.shadowRoot?.querySelector(".chart");
851
+ if (!r || !s) return;
852
+ r.textContent = this.tooltipText(e), r.setAttribute("data-visible", "");
853
+ const a = r.offsetWidth, o = r.offsetHeight;
854
+ r.style.left = `${Math.max(0, Math.min(t + 12, s.clientWidth - a))}px`, r.style.top = `${Math.max(0, Math.min(i + 12, s.clientHeight - o))}px`;
855
+ }
856
+ hideTooltip() {
857
+ this.tooltipEl?.removeAttribute("data-visible");
858
+ }
518
859
  onPointerMove(e) {
519
- const i = this._index;
520
- if (!i) return;
521
- const t = this.nodeFromEvent(e), a = this.shadowRoot?.querySelector(".chart-tooltip");
522
- if (!t || t === this.focusedRoot) {
860
+ const t = this._index;
861
+ if (!t || this.trackViewGesture(e)) return;
862
+ const i = this.nodeFromEvent(e);
863
+ if (!i || i === this.focusedRoot) {
523
864
  this.clearHover();
524
865
  return;
525
866
  }
526
- if (a) {
527
- const h = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect();
528
- h && (a.style.left = `${e.clientX - h.left + 12}px`, a.style.top = `${e.clientY - h.top + 12}px`), a.textContent = this.tooltipText(t), a.setAttribute("data-visible", "");
867
+ if (i.id !== this._dismissedForId) {
868
+ this._dismissedForId = null;
869
+ const r = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect();
870
+ r && this.showTooltip(i, e.clientX - r.left, e.clientY - r.top);
529
871
  }
530
- this._hoveredId !== t.id && (this._hoveredId = t.id, this.emit("hierarchy-node-hover", { node: t, path: p(i, t) }));
872
+ this._hoveredId !== i.id && (this._hoveredId = i.id, this.emit("hierarchy-node-hover", { node: i, path: m(t, i) }));
531
873
  }
532
874
  clearHover() {
533
- this.shadowRoot?.querySelector(".chart-tooltip")?.removeAttribute("data-visible"), this._hoveredId !== null && (this._hoveredId = null, this.emit("hierarchy-node-hover", { node: null, path: [] }));
875
+ this.hideTooltip(), this._dismissedForId = null, this._hoveredId !== null && (this._hoveredId = null, this.emit("hierarchy-node-hover", { node: null, path: [] }));
876
+ }
877
+ /** Keyboard parity for the hover tooltip (1.4.13): show on focus, hide on blur. */
878
+ onFocusIn(e) {
879
+ const t = e.composedPath()[0]?.closest?.('[role="treeitem"][data-id]'), i = t?.getAttribute("data-id"), r = i ? this._index?.byId.get(i) : void 0;
880
+ if (!r || r === this.focusedRoot || r.id === this._dismissedForId) return;
881
+ this._dismissedForId = null;
882
+ const s = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect(), a = t?.getBoundingClientRect();
883
+ !s || !a || this.showTooltip(
884
+ r,
885
+ a.left - s.left + a.width / 2,
886
+ a.top - s.top + a.height / 2
887
+ );
888
+ }
889
+ onFocusOut() {
890
+ this.hideTooltip();
534
891
  }
535
892
  tooltipText(e) {
536
- const i = this._tooltipFormatter?.(e);
537
- if (i !== void 0) return i;
538
- const t = new Intl.NumberFormat(this._locale || this.closest("[lang]")?.getAttribute("lang") || void 0), a = this._index?.colorValues.get(e.id), s = this._index?.values.get(e.id);
893
+ const t = this._tooltipFormatter?.(e);
894
+ if (t !== void 0) return t;
895
+ const i = new Intl.NumberFormat(this._locale || this.closest("[lang]")?.getAttribute("lang") || void 0), r = this._index?.colorValues.get(e.id), s = this._index?.values.get(e.id);
539
896
  return [
540
897
  e.name,
541
- a !== void 0 ? `${t.format(Math.round(a * 10) / 10)}%` : void 0,
542
- s !== void 0 && s > 0 ? t.format(s) : void 0
543
- ].filter((h) => h !== void 0).join(" — ");
898
+ r !== void 0 ? `${i.format(Math.round(r * 10) / 10)}%` : void 0,
899
+ s !== void 0 && s > 0 ? i.format(s) : void 0
900
+ ].filter((a) => a !== void 0).join(" — ");
544
901
  }
545
902
  labelText(e) {
546
903
  return this._labelFormatter?.(e) ?? e.name;
547
904
  }
548
905
  /** Localized per-node accessible name: "components, 82%, 1,234 lines". */
549
906
  accessibleName(e) {
550
- const i = new Intl.NumberFormat(this._locale || this.closest("[lang]")?.getAttribute("lang") || void 0), t = this._index?.colorValues.get(e.id), a = this._index?.values.get(e.id);
907
+ const t = new Intl.NumberFormat(this._locale || this.closest("[lang]")?.getAttribute("lang") || void 0), i = this._index?.colorValues.get(e.id), r = this._index?.values.get(e.id);
551
908
  return [
552
909
  this.labelText(e),
553
- t !== void 0 ? `${i.format(Math.round(t * 10) / 10)}${this._metricUnitLabel}` : void 0,
554
- a !== void 0 && a > 0 ? `${i.format(a)}${this._valueUnitLabel ? ` ${this._valueUnitLabel}` : ""}` : void 0
910
+ i !== void 0 ? `${t.format(Math.round(i * 10) / 10)}${this._metricUnitLabel}` : void 0,
911
+ r !== void 0 && r > 0 ? `${t.format(r)}${this._valueUnitLabel ? ` ${this._valueUnitLabel}` : ""}` : void 0
555
912
  ].filter((s) => s !== void 0).join(", ");
556
913
  }
557
- emit(e, i) {
558
- this.dispatchEvent(new CustomEvent(e, { detail: i, bubbles: !0, composed: !0 }));
914
+ emit(e, t) {
915
+ this.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, composed: !0 }));
559
916
  }
560
917
  /* ---------- keyboard (APG tree, adapted: siblings wrap, Down = outward) ---------- */
561
918
  onKeyDown(e) {
562
- const i = this._index, a = e.composedPath()[0]?.closest?.('[role="treeitem"][data-id]')?.getAttribute("data-id");
563
- if (!i || !a) return;
564
- const s = (o) => {
565
- o !== void 0 && (this._focusedId = o, this._restoreFocus = !0, this.requestUpdate());
566
- }, h = this._rendered.find((o) => o.id === a), r = this._rendered.filter((o) => o.parentId === h?.parentId), n = r.findIndex((o) => o.id === a);
919
+ const t = this._index, r = e.composedPath()[0]?.closest?.('[role="treeitem"][data-id]')?.getAttribute("data-id");
920
+ if (!t || !r) return;
921
+ const s = (h) => {
922
+ h !== void 0 && (this._focusedId = h, this._restoreFocus = !0, this.requestUpdate());
923
+ }, a = this._rendered.find((h) => h.id === r), o = this._rendered.filter((h) => h.parentId === a?.parentId), n = o.findIndex((h) => h.id === r);
567
924
  switch (e.key) {
568
925
  case "ArrowRight":
569
- s(r[(n + 1) % r.length]?.id);
926
+ s(o[(n + 1) % o.length]?.id);
570
927
  break;
571
928
  case "ArrowLeft":
572
- s(r[(n - 1 + r.length) % r.length]?.id);
929
+ s(o[(n - 1 + o.length) % o.length]?.id);
573
930
  break;
574
931
  case "ArrowDown":
575
- s(this._rendered.find((o) => o.parentId === a)?.id);
932
+ s(this._rendered.find((h) => h.parentId === r)?.id);
576
933
  break;
577
934
  case "ArrowUp":
578
- s(this._rendered.some((o) => o.id === h?.parentId) ? h?.parentId ?? void 0 : void 0);
935
+ s(this._rendered.some((h) => h.id === a?.parentId) ? a?.parentId ?? void 0 : void 0);
579
936
  break;
580
937
  case "Home":
581
- s(r[0]?.id);
938
+ s(o[0]?.id);
582
939
  break;
583
940
  case "End":
584
- s(r[r.length - 1]?.id);
941
+ s(o[o.length - 1]?.id);
585
942
  break;
586
943
  case "Enter": {
587
- const o = i.byId.get(a);
588
- if (!o) return;
589
- this._failedIds.delete(o.id), this._loadedIds.delete(o.id), o === this.focusedRoot ? this.zoomOut() : o.children?.length || o.hasChildren && this._loadChildren ? this.zoomTo(o.id) : this.emit("hierarchy-node-select", { node: o, path: p(i, o) });
944
+ const h = t.byId.get(r);
945
+ if (!h) return;
946
+ this._failedIds.delete(h.id), this._loadedIds.delete(h.id), h === this.focusedRoot ? this.zoomOut() : h.children?.length || h.hasChildren && this._loadChildren ? this.zoomTo(h.id) : this.emit("hierarchy-node-select", { node: h, path: m(t, h) });
590
947
  break;
591
948
  }
592
949
  case "Escape":
950
+ if (this.isTooltipVisible()) {
951
+ this.hideTooltip(), this._dismissedForId = r;
952
+ break;
953
+ }
954
+ if (this._viewZoom > 1) {
955
+ this.resetZoom();
956
+ break;
957
+ }
958
+ if (this.focusedRoot === this._index?.root) return;
959
+ this.zoomOut();
960
+ break;
593
961
  case "Backspace":
594
962
  if (this.focusedRoot === this._index?.root) return;
595
963
  this.zoomOut();
596
964
  break;
965
+ // Keyboard equivalent of the wheel/pinch magnification (2.1.1),
966
+ // anchored on the focused node so it stays in view.
967
+ case "+":
968
+ case "=":
969
+ this.zoomKeyboard(r, this._viewZoom * 1.5);
970
+ break;
971
+ case "-":
972
+ case "_":
973
+ this.zoomKeyboard(r, this._viewZoom / 1.5);
974
+ break;
975
+ case "0":
976
+ this.resetZoom();
977
+ break;
597
978
  default:
598
- this.handleTypeahead(e, a);
979
+ this.handleTypeahead(e, r);
599
980
  return;
600
981
  }
601
982
  e.preventDefault(), e.stopPropagation();
602
983
  }
603
- handleTypeahead(e, i) {
984
+ /** Zoom anchored on a node's on-screen center (falls back to the chart center). */
985
+ zoomKeyboard(e, t) {
986
+ const i = this.shadowRoot?.querySelector(`[role="treeitem"][data-id="${M(e)}"]`), r = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect(), s = i?.getBoundingClientRect(), a = r?.width && s?.width ? this.chartAnchor({ clientX: s.left + s.width / 2, clientY: s.top + s.height / 2 }) : { x: 0.5, y: 0.5 };
987
+ this.setZoomLevel(t, a.x, a.y);
988
+ }
989
+ handleTypeahead(e, t) {
604
990
  if (e.key.length !== 1 || e.ctrlKey || e.metaKey || e.altKey) return;
605
991
  clearTimeout(this._typeaheadTimer), this._typeahead += e.key.toLowerCase(), this._typeaheadTimer = setTimeout(() => this._typeahead = "", 500);
606
- const t = this._index;
607
- if (!t) return;
608
- const a = this._rendered, s = a.findIndex((n) => n.id === i), r = [...a.slice(s + 1), ...a.slice(0, s + 1)].find((n) => {
609
- const o = t.byId.get(n.id);
610
- return o ? this.labelText(o).toLowerCase().startsWith(this._typeahead) : !1;
992
+ const i = this._index;
993
+ if (!i) return;
994
+ const r = this._rendered, s = r.findIndex((n) => n.id === t), o = [...r.slice(s + 1), ...r.slice(0, s + 1)].find((n) => {
995
+ const h = i.byId.get(n.id);
996
+ return h ? this.labelText(h).toLowerCase().startsWith(this._typeahead) : !1;
611
997
  });
612
- r && (this._focusedId = r.id, this._restoreFocus = !0, this.requestUpdate(), e.preventDefault());
998
+ o && (this._focusedId = o.id, this._restoreFocus = !0, this.requestUpdate(), e.preventDefault());
613
999
  }
614
1000
  /**
615
1001
  * Roving tabindex target for this render: the focused node while it is
@@ -617,14 +1003,14 @@ class q extends w {
617
1003
  * zoom announce that caused the window to change).
618
1004
  */
619
1005
  resolveTabFocus() {
620
- if (!(this._focusedId && this._rendered.some((i) => i.id === this._focusedId))) {
621
- const i = this._rendered[0]?.id, t = !!this.shadowRoot?.activeElement;
622
- this._focusedId = i ?? null, t && i && (this._restoreFocus = !0);
1006
+ if (!(this._focusedId && this._rendered.some((t) => t.id === this._focusedId))) {
1007
+ const t = this._rendered[0]?.id, i = !!this.shadowRoot?.activeElement;
1008
+ this._focusedId = t ?? null, i && t && (this._restoreFocus = !0);
623
1009
  }
624
1010
  return this._focusedId ?? void 0;
625
1011
  }
626
1012
  updated(e) {
627
- super.updated(e), this._restoreFocus && this._focusedId && (this._restoreFocus = !1, this.shadowRoot?.querySelector(`[role="treeitem"][data-id="${D(this._focusedId)}"]`)?.focus({ preventScroll: !0 })), this.loadLazyCandidates();
1013
+ super.updated(e), this._restoreFocus && this._focusedId && (this._restoreFocus = !1, this.shadowRoot?.querySelector(`[role="treeitem"][data-id="${M(this._focusedId)}"]`)?.focus({ preventScroll: !0 })), this.loadLazyCandidates();
628
1014
  }
629
1015
  /* ---------- lazy children ---------- */
630
1016
  isLazy(e) {
@@ -632,69 +1018,98 @@ class q extends w {
632
1018
  }
633
1019
  /** Kick a load for every lazy node whose CHILD ring is inside the rendered window. */
634
1020
  loadLazyCandidates() {
635
- const e = this._loadChildren, i = this._index;
636
- if (!e || !i) return;
637
- const t = this.focusedRoot, a = this._maxDepth === "auto", s = this.renderedDepth, h = [
638
- ...this.isLazy(t) ? [t] : [],
639
- ...this._rendered.filter((r) => a || r.depth < s).map((r) => i.byId.get(r.id)).filter((r) => this.isLazy(r))
640
- ].filter((r) => !this._loadingIds.has(r.id) && !this._failedIds.has(r.id));
641
- h.map((r) => (this._loadingIds.add(r.id), r === t && this.liveAnnouncer.announce(`${this._loadingLabel} ${this.labelText(r)}`), e(r).then(
1021
+ const e = this._loadChildren, t = this._index;
1022
+ if (!e || !t) return;
1023
+ const i = this.focusedRoot, r = this.maxDepth === "auto", s = this.renderedDepth, a = [
1024
+ ...this.isLazy(i) ? [i] : [],
1025
+ ...this._rendered.filter((o) => r || o.depth < s).map((o) => t.byId.get(o.id)).filter((o) => this.isLazy(o))
1026
+ ].filter((o) => !this._loadingIds.has(o.id) && !this._failedIds.has(o.id));
1027
+ a.map((o) => (this._loadingIds.add(o.id), o === i && this.liveAnnouncer.announce(`${this._loadingLabel} ${this.labelText(o)}`), e(o).then(
642
1028
  (n) => {
643
- r.children = n, this._loadingIds.delete(r.id), this._loadedIds.add(r.id), this._data && (this._index = y(this._data)), this.requestUpdate();
1029
+ o.children = n, this._loadingIds.delete(o.id), this._loadedIds.add(o.id), this._data && (this._index = $(this._data)), this.requestUpdate();
644
1030
  },
645
1031
  (n) => {
646
- this._loadingIds.delete(r.id), this._failedIds.add(r.id), this.emit("hierarchy-node-load-error", { node: r, error: n }), this.requestUpdate();
1032
+ this._loadingIds.delete(o.id), this._failedIds.add(o.id), this.emit("hierarchy-node-load-error", { node: o, error: n }), this.requestUpdate();
647
1033
  }
648
- ), r)), h.length && this.requestUpdate();
1034
+ ), o)), a.length && this.requestUpdate();
649
1035
  }
650
1036
  fillOf(e) {
651
1037
  if (e.color) return e.color;
652
- const i = this._index?.colorValues.get(e.id);
653
- return i !== void 0 ? this._fill(i) : void 0;
1038
+ const t = this._index?.colorValues.get(e.id);
1039
+ return t !== void 0 ? this._fill(t) : void 0;
654
1040
  }
655
1041
  treeLabel() {
656
1042
  return this.getAttribute("aria-label") ?? this._inputLabel;
657
1043
  }
1044
+ /** The focus path as buttons, OUTSIDE any role=tree container (trees own only treeitems). */
1045
+ renderBreadcrumb(e, t) {
1046
+ const i = m(e, t);
1047
+ return c`<nav class="breadcrumb" aria-label=${this._breadcrumbLabel}>
1048
+ ${i.map((r, s) => s === i.length - 1 ? c`<span class="crumb-current" aria-current="location">${this.labelText(r)}</span>` : c`<button
1049
+ type="button"
1050
+ class="crumb"
1051
+ @click=${() => this.zoomTo(r === e.root ? void 0 : r.id)}
1052
+ >${this.labelText(r)}</button><span class="crumb-sep" aria-hidden="true">/</span>`)}
1053
+ </nav>`;
1054
+ }
658
1055
  render() {
659
- const e = this._index, i = this.focusedRoot;
660
- return !e || !i ? u`<div class="chart"></div>` : u`<div
661
- class="chart"
1056
+ const e = this._index, t = this.focusedRoot;
1057
+ return !e || !t ? c`<div class="chart"></div>` : c`${this._showBreadcrumb ? this.renderBreadcrumb(e, t) : d}<div
1058
+ class="chart ${this._gestures.has("pinch") ? "pinch" : ""}"
662
1059
  @click=${this.onClick}
663
1060
  @keydown=${this.onKeyDown}
1061
+ @pointerdown=${this.onPointerDown}
664
1062
  @pointermove=${this.onPointerMove}
1063
+ @pointerup=${this.endViewGesture}
1064
+ @pointercancel=${this.endViewGesture}
665
1065
  @pointerleave=${this.clearHover}
1066
+ @focusin=${this.onFocusIn}
1067
+ @focusout=${this.onFocusOut}
666
1068
  >
667
- ${this._layout === "sunburst" ? this.renderSunburst(e) : this._layout === "icicle" ? this.renderIcicle(e, i) : this.renderTreemap(e, i)}
1069
+ ${this._layout === "sunburst" ? this.renderSunburst(e) : this._layout === "icicle" ? this.renderIcicle(e, t) : this.renderTreemap(e, t)}
668
1070
  <div class="chart-tooltip" aria-hidden="true"></div>
1071
+ ${this._hintVisible && this._gestures.has("wheel") ? c`<div class="zoom-hint" aria-hidden="true">${this.zoomHintLabel}</div>` : d}
669
1072
  ${this.liveAnnouncer.template()}
670
1073
  </div>`;
671
1074
  }
672
- captureRendered(e, i) {
673
- this._rendered = e.map((t) => ({
674
- id: t.node.id,
675
- parentId: this._index?.parents.get(t.node.id)?.id ?? i,
676
- depth: t.depth
1075
+ captureRendered(e, t) {
1076
+ this._rendered = e.map((i) => ({
1077
+ id: i.node.id,
1078
+ parentId: this._index?.parents.get(i.node.id)?.id ?? t,
1079
+ depth: i.depth
677
1080
  })), this._tabFocusId = this.resolveTabFocus();
678
1081
  }
679
1082
  /* ---------- sunburst ---------- */
680
1083
  renderSunburst(e) {
681
- const i = this.focusedRoot, t = this.renderedDepth, a = $(e, this._rootId, {
682
- maxDepth: t,
683
- minFraction: this._minAngle / 360
684
- }), s = c / 2 / (t + 1), h = this.treeLabel(), r = new Map(a.map((l) => [l.node.id, this.tweenedSpan(l)]));
1084
+ const t = this.focusedRoot, i = this.renderedDepth, r = I(e, this._rootId, {
1085
+ maxDepth: i,
1086
+ // The cull relaxes with magnification: a sliver you zoomed into is no
1087
+ // longer a sliver on screen.
1088
+ minFraction: this._minAngle / 360 / this._viewZoom
1089
+ }), s = u / 2 / (i + 1), a = this.treeLabel(), o = new Map(r.map((l) => [l.node.id, this.tweenedSpan(l)]));
685
1090
  this._prevSpans = new Map(
686
- [...r.entries()].map(([l, L]) => [l, { ...L, depth: 0 }])
687
- ), this.captureRendered(a, i?.id ?? "");
688
- const n = i === e.root, o = 100 / (t + 1) * 0.9;
689
- return u`<svg viewBox="0 0 ${c} ${c}" role="tree" aria-label=${h ?? d}>
1091
+ [...o.entries()].map(([l, _]) => [l, { ..._, depth: 0 }])
1092
+ ), this.captureRendered(r, t?.id ?? "");
1093
+ const n = t === e.root, h = 100 / (i + 1) * 0.9, b = this._viewZoom, w = this.viewRect(0.5, 0.5, 0.5, 0.5);
1094
+ return c`<svg
1095
+ viewBox="${this._viewX * u} ${this._viewY * u} ${u / b} ${u / b}"
1096
+ role="tree"
1097
+ aria-label=${a ?? d}
1098
+ >
690
1099
  <!-- role=none: this group only centres the geometry, and an unroled node
691
1100
  between role=tree and its treeitems is an aria-required-parent risk. -->
692
- <g role="none" transform="translate(${c / 2},${c / 2})">
693
- ${b(a, (l) => l.node.id, (l) => this.renderArc(l, r.get(l.node.id) ?? l, s))}
694
- ${this._showLabels && this._tween >= 1 ? b(
695
- a.filter((l) => this.arcLabelFits(l)),
696
- (l) => `label-${l.node.id}`,
697
- (l) => g`<text class="arc-label" transform=${S(l.x0, l.x1, (l.depth + 0.5) * s)}>${this.labelText(l.node)}</text>`
1101
+ <g role="none" transform="translate(${u / 2},${u / 2})">
1102
+ ${f(r, (l) => l.node.id, (l) => this.renderArc(l, o.get(l.node.id) ?? l, s))}
1103
+ ${this._showLabels && this._tween >= 1 ? f(
1104
+ r.map((l) => ({ n: l, fit: this.arcLabelFit(l, s) })).filter(({ fit: l }) => l.visible),
1105
+ ({ n: l }) => `label-${l.node.id}`,
1106
+ ({ n: l, fit: _ }) => k`<text
1107
+ class="arc-label"
1108
+ aria-hidden="true"
1109
+ font-size=${Math.round(this._labelFontSize / this.effectiveScale * 100) / 100}
1110
+ data-surface=${this.surfaceToneOf(l.node, l.hasChildren ? 1 : 0.6)}
1111
+ transform=${R(l.x0, l.x1, (l.depth + 0.5) * s, _.orientation)}
1112
+ >${_.text}</text>`
698
1113
  ) : d}
699
1114
  </g>
700
1115
  </svg>
@@ -703,21 +1118,26 @@ class q extends w {
703
1118
  aria-label=${this._zoomOutLabel}
704
1119
  title=${n ? d : this._zoomOutLabel}
705
1120
  ?disabled=${n}
706
- style=${f({ width: `${o}%`, height: `${o}%` })}
1121
+ style=${v({
1122
+ left: `${w.x0 * 100}%`,
1123
+ top: `${w.y0 * 100}%`,
1124
+ width: `${h * b}%`,
1125
+ height: `${h * b}%`
1126
+ })}
707
1127
  @click=${this.zoomOut}
708
- >${i ? this.labelText(i) : ""}</button>`;
1128
+ >${t ? this.labelText(t) : ""}</button>`;
709
1129
  }
710
- renderArc(e, i, t) {
711
- const a = M(0, 0, e.depth * t, (e.depth + 1) * t, i.x0 * m, i.x1 * m, {
1130
+ renderArc(e, t, i) {
1131
+ const r = O(0, 0, e.depth * i, (e.depth + 1) * i, t.x0 * y, t.x1 * y, {
712
1132
  padAngle: 5e-3
713
1133
  }), s = this.fillOf(e.node);
714
- return g`<path
1134
+ return k`<path
715
1135
  class="ring"
716
1136
  data-id=${e.node.id}
717
1137
  ?data-leaf=${!e.hasChildren}
718
1138
  ?data-loading=${this._loadingIds.has(e.node.id)}
719
1139
  ?data-load-error=${this._failedIds.has(e.node.id)}
720
- d=${a}
1140
+ d=${r}
721
1141
  fill=${s ?? "var(--mp-hierarchy-chart-node-fill)"}
722
1142
  role="treeitem"
723
1143
  tabindex=${e.node.id === this._tabFocusId ? "0" : "-1"}
@@ -729,88 +1149,133 @@ class q extends w {
729
1149
  aria-busy=${this._loadingIds.has(e.node.id) ? "true" : d}
730
1150
  ></path>`;
731
1151
  }
732
- arcLabelFits(e) {
733
- return U(e.x0 * m, e.x1 * m, 1, this._labelMinArea);
1152
+ /**
1153
+ * Fit the (formatted) name into the arc IN DEVICE PX — the same 12px label
1154
+ * needs a bigger arc on a small host, and re-rooting is what makes arcs big
1155
+ * enough, so labels appear as you zoom in.
1156
+ */
1157
+ arcLabelFit(e, t) {
1158
+ return A(
1159
+ this.labelText(e.node),
1160
+ (e.x1 - e.x0) * y,
1161
+ e.depth * t * this.effectiveScale,
1162
+ (e.depth + 1) * t * this.effectiveScale,
1163
+ this._labelFontSize
1164
+ );
734
1165
  }
735
1166
  /* ---------- icicle ---------- */
736
- renderIcicle(e, i) {
737
- const t = this.renderedDepth, a = $(e, this._rootId, {
738
- maxDepth: t,
739
- minFraction: this._minSize / c
740
- }), s = t + 1, h = this.treeLabel();
741
- return this.captureRendered(a, i.id), u`<div class="icicle" role="tree" aria-label=${h ?? d}>
1167
+ renderIcicle(e, t) {
1168
+ const i = this.renderedDepth, r = I(e, this._rootId, {
1169
+ maxDepth: i,
1170
+ minFraction: this._minSize / u / this._viewZoom
1171
+ }), s = i + 1, a = this.treeLabel();
1172
+ this.captureRendered(r, t.id);
1173
+ const o = this.viewRect(0, 0, 1 / s, 1);
1174
+ return c`<div class="icicle" role="tree" aria-label=${a ?? d}>
742
1175
  <div
743
1176
  class="cell focus-cell"
744
- data-id=${i.id}
1177
+ data-id=${t.id}
1178
+ data-surface=${this.toneOfSurface(void 0)}
745
1179
  role="treeitem"
746
1180
  tabindex="-1"
747
- aria-label=${this.accessibleName(i)}
748
- aria-level=${A(e, i)}
1181
+ aria-label=${this.accessibleName(t)}
1182
+ aria-level=${D(e, t)}
749
1183
  aria-setsize="1"
750
1184
  aria-posinset="1"
751
1185
  aria-expanded="true"
752
- title=${i === e.root ? d : this._zoomOutLabel}
753
- style=${f({ left: "0%", top: "0%", width: `${100 / s}%`, height: "100%" })}
754
- ><span class="cell-label">${this.labelText(i)}</span></div>
755
- ${b(a, (r) => r.node.id, (r) => this.renderCell(r, {
756
- left: `${r.depth / s * 100}%`,
757
- top: `${r.x0 * 100}%`,
758
- width: `${1 / s * 100}%`,
759
- height: `${(r.x1 - r.x0) * 100}%`
760
- }, r.hasChildren && r.depth < this.renderedDepth && !!r.node.children?.length))}
1186
+ title=${t === e.root ? d : this._zoomOutLabel}
1187
+ style=${v({ ...this.cellGeometry(o), fontSize: `${this._labelFontSize}px` })}
1188
+ >${this._showLabels && this.cellLabelFits(o) ? c`<span class="cell-label">${this.labelText(t)}</span>` : d}</div>
1189
+ ${f(
1190
+ r,
1191
+ (n) => n.node.id,
1192
+ (n) => this.renderCell(
1193
+ n,
1194
+ this.viewRect(n.depth / s, n.x0, (n.depth + 1) / s, n.x1),
1195
+ n.hasChildren && n.depth < this.renderedDepth && !!n.node.children?.length
1196
+ )
1197
+ )}
761
1198
  </div>`;
762
1199
  }
763
1200
  /* ---------- treemap ---------- */
764
- renderTreemap(e, i) {
765
- const t = this.renderedDepth, a = F(e, this._rootId, {
766
- maxDepth: t,
767
- minArea: (this._minSize / c) ** 2,
1201
+ renderTreemap(e, t) {
1202
+ const i = this.renderedDepth, r = Z(e, this._rootId, {
1203
+ maxDepth: i,
1204
+ minArea: (this._minSize / u) ** 2 / (this._viewZoom * this._viewZoom),
768
1205
  childPadding: 4e-3,
769
1206
  childHeaderSpace: 0.028
770
- }), s = this.treeLabel(), h = p(e, i).map((r) => this.labelText(r)).join(" / ");
771
- return this.captureRendered(a, i.id), u`<div class="treemap">
1207
+ }), s = this.treeLabel(), a = m(e, t).map((o) => this.labelText(o)).join(" / ");
1208
+ return this.captureRendered(r, t.id), c`<div class="treemap">
772
1209
  <button
773
1210
  class="treemap-header"
774
1211
  aria-label=${this._zoomOutLabel}
775
- title=${h}
776
- ?disabled=${i === e.root}
1212
+ title=${a}
1213
+ ?disabled=${t === e.root}
777
1214
  @click=${this.zoomOut}
778
- >${h}</button>
1215
+ >${a}</button>
779
1216
  <div class="treemap-body" role="tree" aria-label=${s ?? d}>
780
- ${b(a, (r) => r.node.id, (r) => this.renderCell(r, {
781
- left: `${r.x0 * 100}%`,
782
- top: `${r.y0 * 100}%`,
783
- width: `${(r.x1 - r.x0) * 100}%`,
784
- height: `${(r.y1 - r.y0) * 100}%`
785
- }, r.hasChildren && r.depth < this.renderedDepth && !!r.node.children?.length))}
1217
+ ${f(
1218
+ r,
1219
+ (o) => o.node.id,
1220
+ (o) => this.renderCell(
1221
+ o,
1222
+ this.viewRect(o.x0, o.y0, o.x1, o.y1),
1223
+ o.hasChildren && o.depth < this.renderedDepth && !!o.node.children?.length
1224
+ )
1225
+ )}
786
1226
  </div>
787
1227
  </div>`;
788
1228
  }
789
- renderCell(e, i, t) {
790
- const a = this._layout === "treemap" && t, s = a ? void 0 : this.fillOf(e.node);
791
- return u`<div
1229
+ cellGeometry(e) {
1230
+ return {
1231
+ left: `${e.x0 * 100}%`,
1232
+ top: `${e.y0 * 100}%`,
1233
+ width: `${(e.x1 - e.x0) * 100}%`,
1234
+ height: `${(e.y1 - e.y0) * 100}%`
1235
+ };
1236
+ }
1237
+ cellLabelFits(e) {
1238
+ const t = u * this._hostScale;
1239
+ return E((e.x1 - e.x0) * t, (e.y1 - e.y0) * t, this._labelFontSize);
1240
+ }
1241
+ renderCell(e, t, i) {
1242
+ const r = this._layout === "treemap" && i, s = r ? void 0 : this.fillOf(e.node), a = this._showLabels && this.cellLabelFits(t);
1243
+ return c`<div
792
1244
  class="cell"
793
1245
  data-id=${e.node.id}
794
1246
  ?data-leaf=${!e.hasChildren}
795
- ?data-branch=${a}
1247
+ ?data-branch=${r}
796
1248
  ?data-loading=${this._loadingIds.has(e.node.id)}
797
1249
  ?data-load-error=${this._failedIds.has(e.node.id)}
1250
+ data-surface=${s ? this.surfaceToneOf(e.node, 1) : this.toneOfSurface(void 0)}
798
1251
  role="treeitem"
799
1252
  tabindex=${e.node.id === this._tabFocusId ? "0" : "-1"}
800
1253
  aria-label=${this.accessibleName(e.node)}
801
1254
  aria-level=${e.level}
802
1255
  aria-setsize=${e.setsize}
803
1256
  aria-posinset=${e.posinset}
804
- aria-expanded=${e.hasChildren ? String(t) : d}
1257
+ aria-expanded=${e.hasChildren ? String(i) : d}
805
1258
  aria-busy=${this._loadingIds.has(e.node.id) ? "true" : d}
806
- style=${f({ ...i, ...s ? { background: s } : {} })}
807
- ><span class="cell-label">${this.labelText(e.node)}</span></div>`;
1259
+ style=${v({
1260
+ ...this.cellGeometry(t),
1261
+ fontSize: `${this._labelFontSize}px`,
1262
+ ...s ? { background: s } : {}
1263
+ })}
1264
+ >${a ? c`<span class="cell-label">${this.labelText(e.node)}</span>` : d}</div>`;
808
1265
  }
809
1266
  }
810
- function D(_) {
811
- return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(_) : _.replace(/["\\]/g, "\\$&");
1267
+ function g(p, e) {
1268
+ return Math.min(1 - 1 / e, Math.max(0, p));
1269
+ }
1270
+ function B(p) {
1271
+ if (!p || p === "transparent") return !1;
1272
+ const e = p.match(/^rgba\([^)]+,\s*([\d.]+)\s*\)$/i)?.[1];
1273
+ return e !== void 0 ? Number(e) >= 1 : /^(rgb\(|#|hsl\()/i.test(p);
1274
+ }
1275
+ function M(p) {
1276
+ return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(p) : p.replace(/["\\]/g, "\\$&");
812
1277
  }
813
- typeof customElements < "u" && !customElements.get("mp-hierarchy-chart") && customElements.define("mp-hierarchy-chart", q);
1278
+ typeof customElements < "u" && !customElements.get("mp-hierarchy-chart") && customElements.define("mp-hierarchy-chart", x);
814
1279
  export {
815
- q as MpHierarchyChart
1280
+ x as MpHierarchyChart
816
1281
  };