@mintplayer/web-components 2.10.0 → 2.11.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.
Files changed (50) hide show
  1. package/accordion/index.mjs +4 -4
  2. package/charts/core/index.d.ts +1 -0
  3. package/charts/core/index.mjs +19 -0
  4. package/charts/core/src/arc.d.ts +28 -0
  5. package/charts/core/src/color.d.ts +11 -0
  6. package/charts/core/src/hierarchy-layout.d.ts +68 -0
  7. package/charts/core/src/index.d.ts +5 -0
  8. package/charts/core/src/scale.d.ts +21 -0
  9. package/charts/core/src/types.d.ts +52 -0
  10. package/charts/hierarchy/index.d.ts +1 -0
  11. package/charts/hierarchy/index.mjs +816 -0
  12. package/charts/hierarchy/src/components/index.d.ts +1 -0
  13. package/charts/hierarchy/src/components/mp-hierarchy-chart.d.ts +188 -0
  14. package/charts/hierarchy/src/index.d.ts +2 -0
  15. package/charts/hierarchy/src/styles/hierarchy-chart.styles.d.ts +2 -0
  16. package/charts/hierarchy/src/styles/index.d.ts +1 -0
  17. package/charts/sparkline/index.d.ts +1 -0
  18. package/charts/sparkline/index.mjs +162 -0
  19. package/charts/sparkline/src/components/index.d.ts +1 -0
  20. package/charts/sparkline/src/components/mp-sparkline.d.ts +51 -0
  21. package/charts/sparkline/src/index.d.ts +1 -0
  22. package/charts/sparkline/src/styles/index.d.ts +1 -0
  23. package/charts/sparkline/src/styles/sparkline.styles.d.ts +2 -0
  24. package/charts/trend/index.d.ts +1 -0
  25. package/charts/trend/index.mjs +432 -0
  26. package/charts/trend/src/components/index.d.ts +1 -0
  27. package/charts/trend/src/components/mp-trend-chart.d.ts +104 -0
  28. package/charts/trend/src/index.d.ts +2 -0
  29. package/charts/trend/src/styles/index.d.ts +1 -0
  30. package/charts/trend/src/styles/trend-chart.styles.d.ts +2 -0
  31. package/checkbox/index.mjs +1 -1
  32. package/chunks/color-5yPBn70k.mjs +179 -0
  33. package/chunks/{form-check.styles-jBlHetYX.mjs → form-check.styles-B0pxJ6YC.mjs} +2 -2
  34. package/chunks/{form-control.styles-BOTBdmvg.mjs → form-control.styles-C3j87Sn3.mjs} +1 -1
  35. package/chunks/{mp-checkbox-6EJwdUIn.mjs → mp-checkbox-CzwS7Y_t.mjs} +2 -2
  36. package/chunks/{mp-datatable-25O1GtvU.mjs → mp-datatable-GmKqaN8y.mjs} +1 -1
  37. package/chunks/{mp-radio-DvKgrTFL.mjs → mp-radio-cL46sUA0.mjs} +2 -2
  38. package/chunks/{mp-select-lHP00OBH.mjs → mp-select-BNrbPwN4.mjs} +1 -1
  39. package/chunks/{mp-toggle-button-C4Loq_p4.mjs → mp-toggle-button-eo_aTQtu.mjs} +32 -32
  40. package/chunks/scale-B0bRUdc7.mjs +91 -0
  41. package/datatable/index.mjs +1 -1
  42. package/file-manager/index.mjs +1 -1
  43. package/package.json +17 -1
  44. package/phone-input/index.mjs +2 -2
  45. package/query-builder/index.mjs +101 -101
  46. package/radio/index.mjs +1 -1
  47. package/radio-group/index.mjs +1 -1
  48. package/scheduler/index.mjs +3 -3
  49. package/select/index.mjs +1 -1
  50. package/toggle-button/index.mjs +1 -1
@@ -0,0 +1,816 @@
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";
7
+ :host {
8
+ display: block;
9
+ width: 100%;
10
+ aspect-ratio: 1;
11
+ /* Two-level fallbacks: Bootstrap 5.3 reassigns --bs-* per data-bs-theme and
12
+ custom properties inherit through the shadow boundary, so dark mode needs
13
+ 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);
16
+ --mp-hierarchy-chart-center-color: var(--bs-body-color, #212529);
17
+ --mp-hierarchy-chart-center-bg: var(--bs-body-bg, #ffffff);
18
+ --mp-hierarchy-chart-node-fill: var(--bs-secondary-bg, #e9ecef);
19
+ --mp-hierarchy-chart-gap: var(--bs-body-bg, #ffffff);
20
+ --mp-hierarchy-chart-branch-border: var(--bs-border-color, #dee2e6);
21
+ --mp-hierarchy-chart-tooltip-bg: var(--bs-dark, #212529);
22
+ --mp-hierarchy-chart-tooltip-color: var(--bs-light, #f8f9fa);
23
+ --mp-hierarchy-chart-focus-ring-color: var(--bs-primary, #0d6efd);
24
+ }
25
+
26
+ * {
27
+ box-sizing: border-box;
28
+ }
29
+
30
+ .chart {
31
+ position: relative;
32
+ width: 100%;
33
+ height: 100%;
34
+ }
35
+
36
+ svg {
37
+ display: block;
38
+ width: 100%;
39
+ height: 100%;
40
+ }
41
+
42
+ /* ---------- sunburst ---------- */
43
+ .ring {
44
+ stroke: none;
45
+ cursor: pointer;
46
+ }
47
+
48
+ .ring[data-leaf] {
49
+ fill-opacity: 0.6;
50
+ cursor: default;
51
+ }
52
+
53
+ .arc-label {
54
+ fill: var(--mp-hierarchy-chart-arc-label-color);
55
+ font-size: 26px; /* logical viewBox units (1000x1000) */
56
+ text-anchor: middle;
57
+ dominant-baseline: middle;
58
+ pointer-events: none;
59
+ user-select: none;
60
+ }
61
+
62
+ /* HTML overlay button in the sunburst hole (a role=tree svg cannot own a button). */
63
+ .center-control {
64
+ position: absolute;
65
+ top: 50%;
66
+ left: 50%;
67
+ transform: translate(-50%, -50%);
68
+ border-radius: 50%;
69
+ min-width: 24px;
70
+ min-height: 24px;
71
+ overflow: hidden;
72
+ padding: 0.25rem;
73
+ background: var(--mp-hierarchy-chart-center-bg);
74
+ color: var(--mp-hierarchy-chart-center-color);
75
+ border: 1px solid var(--mp-hierarchy-chart-branch-border);
76
+ font: inherit;
77
+ font-size: 0.875rem;
78
+ cursor: pointer;
79
+ }
80
+
81
+ /* At the root there is nothing to zoom out to, and a disabled button still
82
+ swallows clicks — which would make the hole a dead zone over the chart. */
83
+ .center-control:disabled {
84
+ cursor: default;
85
+ pointer-events: none;
86
+ }
87
+
88
+ /* ---------- icicle / treemap (positioned divs) ---------- */
89
+ .cell {
90
+ position: absolute;
91
+ overflow: hidden;
92
+ background: var(--mp-hierarchy-chart-node-fill);
93
+ border: 1px solid var(--mp-hierarchy-chart-gap);
94
+ border-radius: 2px;
95
+ color: var(--mp-hierarchy-chart-label-color);
96
+ font-size: 0.8125rem;
97
+ line-height: 1.25;
98
+ padding: 1px 4px;
99
+ cursor: pointer;
100
+ transition: left var(--mp-hierarchy-chart-transition-duration, 300ms) ease-out, top var(--mp-hierarchy-chart-transition-duration, 300ms) ease-out, width var(--mp-hierarchy-chart-transition-duration, 300ms) ease-out, height var(--mp-hierarchy-chart-transition-duration, 300ms) ease-out;
101
+ }
102
+
103
+ .icicle,
104
+ .treemap,
105
+ .treemap-body {
106
+ position: relative;
107
+ width: 100%;
108
+ height: 100%;
109
+ }
110
+
111
+ .treemap-header {
112
+ height: 1.75rem;
113
+ padding: 0.25rem 0.5rem;
114
+ overflow: hidden;
115
+ white-space: nowrap;
116
+ text-overflow: ellipsis;
117
+ color: var(--mp-hierarchy-chart-center-color);
118
+ background: var(--mp-hierarchy-chart-center-bg);
119
+ border: 1px solid var(--mp-hierarchy-chart-branch-border);
120
+ border-radius: 2px;
121
+ font-size: 0.8125rem;
122
+ cursor: pointer;
123
+ }
124
+
125
+ .treemap .treemap-body {
126
+ height: calc(100% - 1.75rem - 2px);
127
+ margin-top: 2px;
128
+ }
129
+
130
+ .chart-tooltip {
131
+ position: absolute;
132
+ display: none;
133
+ max-width: 60%;
134
+ padding: 0.25rem 0.5rem;
135
+ background: var(--mp-hierarchy-chart-tooltip-bg);
136
+ color: var(--mp-hierarchy-chart-tooltip-color);
137
+ border-radius: 0.25rem;
138
+ font-size: 0.8125rem;
139
+ pointer-events: none;
140
+ z-index: 1;
141
+ }
142
+
143
+ .chart-tooltip[data-visible] {
144
+ display: block;
145
+ }
146
+
147
+ .cell[data-leaf] {
148
+ cursor: default;
149
+ }
150
+
151
+ .cell .cell-label {
152
+ display: block;
153
+ overflow: hidden;
154
+ text-overflow: ellipsis;
155
+ white-space: nowrap;
156
+ }
157
+
158
+ /* A treemap branch tile is a frame: children render inside its header inset,
159
+ its own strip shows the label. */
160
+ .treemap .cell[data-branch] {
161
+ background: transparent;
162
+ border-color: var(--mp-hierarchy-chart-branch-border);
163
+ }
164
+
165
+ .focus-cell {
166
+ background: var(--mp-hierarchy-chart-center-bg);
167
+ border-color: var(--mp-hierarchy-chart-branch-border);
168
+ }
169
+
170
+ /* Focus indication: a drawn stroke on SVG arcs (outline on SVG is historically
171
+ unreliable), a normal inset outline on HTML cells/buttons. */
172
+ .ring:focus {
173
+ outline: none;
174
+ }
175
+
176
+ .ring:focus-visible {
177
+ stroke: var(--mp-hierarchy-chart-focus-ring-color);
178
+ stroke-width: 6px;
179
+ stroke-linejoin: round;
180
+ }
181
+
182
+ .cell:focus-visible {
183
+ outline: 3px solid var(--mp-hierarchy-chart-focus-ring-color);
184
+ outline-offset: -3px;
185
+ }
186
+
187
+ .center-control:focus-visible,
188
+ .treemap-header:focus-visible {
189
+ outline: 3px solid var(--mp-hierarchy-chart-focus-ring-color);
190
+ outline-offset: 2px;
191
+ }
192
+
193
+ .ring[data-loading],
194
+ .cell[data-loading] {
195
+ animation: mp-hierarchy-chart-pulse 1.2s ease-in-out infinite;
196
+ }
197
+
198
+ .ring[data-load-error],
199
+ .cell[data-load-error] {
200
+ opacity: 0.5;
201
+ }
202
+
203
+ @keyframes mp-hierarchy-chart-pulse {
204
+ 50% {
205
+ opacity: 0.4;
206
+ }
207
+ }
208
+ @media (prefers-reduced-motion: reduce) {
209
+ .ring,
210
+ .cell {
211
+ transition: none !important;
212
+ animation: none !important;
213
+ }
214
+ }`), c = 1e3, m = 2 * Math.PI;
215
+ function T() {
216
+ return typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches;
217
+ }
218
+ class q extends w {
219
+ 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 });
221
+ }
222
+ static {
223
+ this.styles = [C];
224
+ }
225
+ static get observedAttributes() {
226
+ return [
227
+ ...super.observedAttributes ?? [],
228
+ "layout",
229
+ "root-id",
230
+ "max-depth",
231
+ "min-angle",
232
+ "min-size",
233
+ "show-labels",
234
+ "label-min-area",
235
+ "color-min",
236
+ "color-max",
237
+ "color-start",
238
+ "color-end",
239
+ "transition-duration",
240
+ "locale",
241
+ "zoom-out-label",
242
+ "metric-unit-label",
243
+ "value-unit-label",
244
+ "loading-label",
245
+ // Copied onto the in-shadow role=tree node — the host stays generic.
246
+ "aria-label",
247
+ "input-label"
248
+ ];
249
+ }
250
+ /** The whole tree, rolled up once per write. */
251
+ get data() {
252
+ return this._data;
253
+ }
254
+ set data(e) {
255
+ this._data = e, this._index = e ? y(e) : void 0, this.requestUpdate();
256
+ }
257
+ get layout() {
258
+ return this._layout;
259
+ }
260
+ set layout(e) {
261
+ this._layout = e === "icicle" || e === "treemap" ? e : "sunburst", this.requestUpdate();
262
+ }
263
+ get rootId() {
264
+ return this._rootId;
265
+ }
266
+ 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());
269
+ }
270
+ /**
271
+ * 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.
275
+ */
276
+ get maxDepth() {
277
+ return this._maxDepth;
278
+ }
279
+ set maxDepth(e) {
280
+ this._maxDepth = e === "auto" ? "auto" : Math.max(1, Math.floor(Number(e) || 2)), this.requestUpdate();
281
+ }
282
+ /**
283
+ * `maxDepth` resolved against the current data. Never 0: a chart showing no
284
+ * ring at all is not a rendering anyone asked for, so a leaf focus still
285
+ * draws its (empty) first ring.
286
+ */
287
+ get renderedDepth() {
288
+ return this._maxDepth !== "auto" ? this._maxDepth : this._index ? Math.max(1, z(this._index, this._rootId)) : 1;
289
+ }
290
+ get minAngle() {
291
+ return this._minAngle;
292
+ }
293
+ set minAngle(e) {
294
+ this._minAngle = Math.max(0, Number(e) || 0), this.requestUpdate();
295
+ }
296
+ get minSize() {
297
+ return this._minSize;
298
+ }
299
+ set minSize(e) {
300
+ this._minSize = Math.max(0, Number(e) || 0), this.requestUpdate();
301
+ }
302
+ get showLabels() {
303
+ return this._showLabels;
304
+ }
305
+ set showLabels(e) {
306
+ this._showLabels = !!e, this.requestUpdate();
307
+ }
308
+ get labelMinArea() {
309
+ return this._labelMinArea;
310
+ }
311
+ set labelMinArea(e) {
312
+ this._labelMinArea = Math.max(0, Number(e) || 0), this.requestUpdate();
313
+ }
314
+ get colorMin() {
315
+ return this._colorMin;
316
+ }
317
+ set colorMin(e) {
318
+ this._colorMin = Number(e) || 0, this.rebuildScale();
319
+ }
320
+ get colorMax() {
321
+ return this._colorMax;
322
+ }
323
+ set colorMax(e) {
324
+ this._colorMax = Number(e) || 0, this.rebuildScale();
325
+ }
326
+ get colorStart() {
327
+ return this._colorStart;
328
+ }
329
+ set colorStart(e) {
330
+ this._colorStart = e || "#fe0000", this.rebuildScale();
331
+ }
332
+ get colorEnd() {
333
+ return this._colorEnd;
334
+ }
335
+ set colorEnd(e) {
336
+ this._colorEnd = e || "#21b577", this.rebuildScale();
337
+ }
338
+ get inputLabel() {
339
+ return this._inputLabel;
340
+ }
341
+ set inputLabel(e) {
342
+ this._inputLabel = e ?? null, this.requestUpdate();
343
+ }
344
+ get transitionDuration() {
345
+ return this._transitionDuration;
346
+ }
347
+ set transitionDuration(e) {
348
+ this._transitionDuration = Math.max(0, Number(e) || 0), this.style.setProperty("--mp-hierarchy-chart-transition-duration", `${this._transitionDuration}ms`);
349
+ }
350
+ get locale() {
351
+ return this._locale;
352
+ }
353
+ set locale(e) {
354
+ this._locale = e || void 0, this.requestUpdate();
355
+ }
356
+ get tooltipFormatter() {
357
+ return this._tooltipFormatter;
358
+ }
359
+ set tooltipFormatter(e) {
360
+ this._tooltipFormatter = e;
361
+ }
362
+ get labelFormatter() {
363
+ return this._labelFormatter;
364
+ }
365
+ set labelFormatter(e) {
366
+ this._labelFormatter = e, this.requestUpdate();
367
+ }
368
+ get loadChildren() {
369
+ return this._loadChildren;
370
+ }
371
+ set loadChildren(e) {
372
+ this._loadChildren = e, this.requestUpdate();
373
+ }
374
+ get loadingLabel() {
375
+ return this._loadingLabel;
376
+ }
377
+ set loadingLabel(e) {
378
+ this._loadingLabel = e ?? "Loading";
379
+ }
380
+ rebuildScale() {
381
+ this._fill = v(this._colorMin, this._colorMax, this._colorStart, this._colorEnd), this.requestUpdate();
382
+ }
383
+ attributeChangedCallback(e, i, t) {
384
+ switch (super.attributeChangedCallback(e, i, t), e) {
385
+ case "layout":
386
+ this.layout = t ?? "sunburst";
387
+ break;
388
+ case "root-id":
389
+ this.rootId = t ?? void 0;
390
+ break;
391
+ case "max-depth":
392
+ this.maxDepth = t === "auto" ? "auto" : Number(t ?? 2);
393
+ break;
394
+ case "min-angle":
395
+ this.minAngle = Number(t ?? 0.2);
396
+ break;
397
+ case "min-size":
398
+ this.minSize = Number(t ?? 4);
399
+ break;
400
+ case "show-labels":
401
+ this.showLabels = t !== "false" && t !== null;
402
+ break;
403
+ case "label-min-area":
404
+ this.labelMinArea = Number(t ?? 0.03);
405
+ break;
406
+ case "color-min":
407
+ this.colorMin = Number(t ?? 0);
408
+ break;
409
+ case "color-max":
410
+ this.colorMax = Number(t ?? 100);
411
+ break;
412
+ case "color-start":
413
+ this.colorStart = t ?? "#fe0000";
414
+ break;
415
+ case "color-end":
416
+ this.colorEnd = t ?? "#21b577";
417
+ break;
418
+ case "transition-duration":
419
+ this.transitionDuration = Number(t ?? 300);
420
+ break;
421
+ case "locale":
422
+ this.locale = t ?? void 0;
423
+ break;
424
+ case "zoom-out-label":
425
+ this._zoomOutLabel = t ?? "Zoom out one level", this.requestUpdate();
426
+ break;
427
+ case "loading-label":
428
+ this._loadingLabel = t ?? "Loading";
429
+ break;
430
+ case "metric-unit-label":
431
+ this._metricUnitLabel = t ?? "%", this.requestUpdate();
432
+ break;
433
+ case "value-unit-label":
434
+ this._valueUnitLabel = t ?? "", this.requestUpdate();
435
+ break;
436
+ case "aria-label":
437
+ this.requestUpdate();
438
+ break;
439
+ case "input-label":
440
+ this.inputLabel = t;
441
+ break;
442
+ }
443
+ }
444
+ get zoomOutLabel() {
445
+ return this._zoomOutLabel;
446
+ }
447
+ set zoomOutLabel(e) {
448
+ this._zoomOutLabel = e || "Zoom out one level", this.requestUpdate();
449
+ }
450
+ get metricUnitLabel() {
451
+ return this._metricUnitLabel;
452
+ }
453
+ set metricUnitLabel(e) {
454
+ this._metricUnitLabel = e ?? "%", this.requestUpdate();
455
+ }
456
+ get valueUnitLabel() {
457
+ return this._valueUnitLabel;
458
+ }
459
+ set valueUnitLabel(e) {
460
+ this._valueUnitLabel = e ?? "", this.requestUpdate();
461
+ }
462
+ /** The node the chart is rooted on right now (tree root when root-id is unset). */
463
+ get focusedRoot() {
464
+ return this._index ? x(this._index, this._rootId) : void 0;
465
+ }
466
+ /* ---------- zoom ---------- */
467
+ /** Re-root on a node id (undefined = tree root) and emit `hierarchy-zoom`. */
468
+ 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) }));
473
+ }
474
+ /** Move the roving tabindex (and DOM focus) to a rendered node. */
475
+ focusNode(e) {
476
+ this._rendered.some((i) => i.id === e) && (this._focusedId = e, this._restoreFocus = !0, this.requestUpdate());
477
+ }
478
+ zoomOut() {
479
+ const e = this._index, i = this.focusedRoot;
480
+ !e || !i || i === e.root || this.zoomTo(e.parents.get(i.id)?.id);
481
+ }
482
+ /* ---------- sunburst tween ---------- */
483
+ beginTween() {
484
+ if (this._transitionDuration <= 0 || T() || this._layout !== "sunburst" || !this._prevSpans.size) return;
485
+ 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));
488
+ };
489
+ this._tween = 0, this._tweenFrame = requestAnimationFrame(i);
490
+ }
491
+ tweenedSpan(e) {
492
+ 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 };
494
+ return {
495
+ x0: t.x0 + (e.x0 - t.x0) * i,
496
+ x1: t.x1 + (e.x1 - t.x1) * i
497
+ };
498
+ }
499
+ /* ---------- pointer interaction ---------- */
500
+ nodeFromEvent(e) {
501
+ const t = e.composedPath()[0]?.closest?.("[data-id]")?.getAttribute("data-id");
502
+ return t ? this._index?.byId.get(t) : void 0;
503
+ }
504
+ onClick(e) {
505
+ const i = this._index, t = this.nodeFromEvent(e);
506
+ if (!(!i || !t)) {
507
+ if (t === this.focusedRoot) {
508
+ this.zoomOut();
509
+ return;
510
+ }
511
+ if (this._failedIds.delete(t.id), this._loadedIds.delete(t.id), t.children?.length || t.hasChildren && this._loadChildren) {
512
+ this.zoomTo(t.id);
513
+ return;
514
+ }
515
+ this.emit("hierarchy-node-select", { node: t, path: p(i, t) });
516
+ }
517
+ }
518
+ 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) {
523
+ this.clearHover();
524
+ return;
525
+ }
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", "");
529
+ }
530
+ this._hoveredId !== t.id && (this._hoveredId = t.id, this.emit("hierarchy-node-hover", { node: t, path: p(i, t) }));
531
+ }
532
+ clearHover() {
533
+ this.shadowRoot?.querySelector(".chart-tooltip")?.removeAttribute("data-visible"), this._hoveredId !== null && (this._hoveredId = null, this.emit("hierarchy-node-hover", { node: null, path: [] }));
534
+ }
535
+ 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);
539
+ return [
540
+ 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(" — ");
544
+ }
545
+ labelText(e) {
546
+ return this._labelFormatter?.(e) ?? e.name;
547
+ }
548
+ /** Localized per-node accessible name: "components, 82%, 1,234 lines". */
549
+ 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);
551
+ return [
552
+ 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
555
+ ].filter((s) => s !== void 0).join(", ");
556
+ }
557
+ emit(e, i) {
558
+ this.dispatchEvent(new CustomEvent(e, { detail: i, bubbles: !0, composed: !0 }));
559
+ }
560
+ /* ---------- keyboard (APG tree, adapted: siblings wrap, Down = outward) ---------- */
561
+ 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);
567
+ switch (e.key) {
568
+ case "ArrowRight":
569
+ s(r[(n + 1) % r.length]?.id);
570
+ break;
571
+ case "ArrowLeft":
572
+ s(r[(n - 1 + r.length) % r.length]?.id);
573
+ break;
574
+ case "ArrowDown":
575
+ s(this._rendered.find((o) => o.parentId === a)?.id);
576
+ break;
577
+ case "ArrowUp":
578
+ s(this._rendered.some((o) => o.id === h?.parentId) ? h?.parentId ?? void 0 : void 0);
579
+ break;
580
+ case "Home":
581
+ s(r[0]?.id);
582
+ break;
583
+ case "End":
584
+ s(r[r.length - 1]?.id);
585
+ break;
586
+ 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) });
590
+ break;
591
+ }
592
+ case "Escape":
593
+ case "Backspace":
594
+ if (this.focusedRoot === this._index?.root) return;
595
+ this.zoomOut();
596
+ break;
597
+ default:
598
+ this.handleTypeahead(e, a);
599
+ return;
600
+ }
601
+ e.preventDefault(), e.stopPropagation();
602
+ }
603
+ handleTypeahead(e, i) {
604
+ if (e.key.length !== 1 || e.ctrlKey || e.metaKey || e.altKey) return;
605
+ 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;
611
+ });
612
+ r && (this._focusedId = r.id, this._restoreFocus = !0, this.requestUpdate(), e.preventDefault());
613
+ }
614
+ /**
615
+ * Roving tabindex target for this render: the focused node while it is
616
+ * still rendered, else the first rendered node (announcement rides the
617
+ * zoom announce that caused the window to change).
618
+ */
619
+ 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);
623
+ }
624
+ return this._focusedId ?? void 0;
625
+ }
626
+ 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();
628
+ }
629
+ /* ---------- lazy children ---------- */
630
+ isLazy(e) {
631
+ return !!e && !!e.hasChildren && !e.children?.length && !this._loadedIds.has(e.id);
632
+ }
633
+ /** Kick a load for every lazy node whose CHILD ring is inside the rendered window. */
634
+ 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(
642
+ (n) => {
643
+ r.children = n, this._loadingIds.delete(r.id), this._loadedIds.add(r.id), this._data && (this._index = y(this._data)), this.requestUpdate();
644
+ },
645
+ (n) => {
646
+ this._loadingIds.delete(r.id), this._failedIds.add(r.id), this.emit("hierarchy-node-load-error", { node: r, error: n }), this.requestUpdate();
647
+ }
648
+ ), r)), h.length && this.requestUpdate();
649
+ }
650
+ fillOf(e) {
651
+ 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;
654
+ }
655
+ treeLabel() {
656
+ return this.getAttribute("aria-label") ?? this._inputLabel;
657
+ }
658
+ render() {
659
+ const e = this._index, i = this.focusedRoot;
660
+ return !e || !i ? u`<div class="chart"></div>` : u`<div
661
+ class="chart"
662
+ @click=${this.onClick}
663
+ @keydown=${this.onKeyDown}
664
+ @pointermove=${this.onPointerMove}
665
+ @pointerleave=${this.clearHover}
666
+ >
667
+ ${this._layout === "sunburst" ? this.renderSunburst(e) : this._layout === "icicle" ? this.renderIcicle(e, i) : this.renderTreemap(e, i)}
668
+ <div class="chart-tooltip" aria-hidden="true"></div>
669
+ ${this.liveAnnouncer.template()}
670
+ </div>`;
671
+ }
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
677
+ })), this._tabFocusId = this.resolveTabFocus();
678
+ }
679
+ /* ---------- sunburst ---------- */
680
+ 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)]));
685
+ 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}>
690
+ <!-- role=none: this group only centres the geometry, and an unroled node
691
+ 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>`
698
+ ) : d}
699
+ </g>
700
+ </svg>
701
+ <button
702
+ class="center-control"
703
+ aria-label=${this._zoomOutLabel}
704
+ title=${n ? d : this._zoomOutLabel}
705
+ ?disabled=${n}
706
+ style=${f({ width: `${o}%`, height: `${o}%` })}
707
+ @click=${this.zoomOut}
708
+ >${i ? this.labelText(i) : ""}</button>`;
709
+ }
710
+ renderArc(e, i, t) {
711
+ const a = M(0, 0, e.depth * t, (e.depth + 1) * t, i.x0 * m, i.x1 * m, {
712
+ padAngle: 5e-3
713
+ }), s = this.fillOf(e.node);
714
+ return g`<path
715
+ class="ring"
716
+ data-id=${e.node.id}
717
+ ?data-leaf=${!e.hasChildren}
718
+ ?data-loading=${this._loadingIds.has(e.node.id)}
719
+ ?data-load-error=${this._failedIds.has(e.node.id)}
720
+ d=${a}
721
+ fill=${s ?? "var(--mp-hierarchy-chart-node-fill)"}
722
+ role="treeitem"
723
+ tabindex=${e.node.id === this._tabFocusId ? "0" : "-1"}
724
+ aria-label=${this.accessibleName(e.node)}
725
+ aria-level=${e.level}
726
+ aria-setsize=${e.setsize}
727
+ aria-posinset=${e.posinset}
728
+ aria-expanded=${e.hasChildren ? String(e.depth < this.renderedDepth && !!e.node.children?.length) : d}
729
+ aria-busy=${this._loadingIds.has(e.node.id) ? "true" : d}
730
+ ></path>`;
731
+ }
732
+ arcLabelFits(e) {
733
+ return U(e.x0 * m, e.x1 * m, 1, this._labelMinArea);
734
+ }
735
+ /* ---------- 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}>
742
+ <div
743
+ class="cell focus-cell"
744
+ data-id=${i.id}
745
+ role="treeitem"
746
+ tabindex="-1"
747
+ aria-label=${this.accessibleName(i)}
748
+ aria-level=${A(e, i)}
749
+ aria-setsize="1"
750
+ aria-posinset="1"
751
+ 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))}
761
+ </div>`;
762
+ }
763
+ /* ---------- treemap ---------- */
764
+ renderTreemap(e, i) {
765
+ const t = this.renderedDepth, a = F(e, this._rootId, {
766
+ maxDepth: t,
767
+ minArea: (this._minSize / c) ** 2,
768
+ childPadding: 4e-3,
769
+ 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">
772
+ <button
773
+ class="treemap-header"
774
+ aria-label=${this._zoomOutLabel}
775
+ title=${h}
776
+ ?disabled=${i === e.root}
777
+ @click=${this.zoomOut}
778
+ >${h}</button>
779
+ <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))}
786
+ </div>
787
+ </div>`;
788
+ }
789
+ renderCell(e, i, t) {
790
+ const a = this._layout === "treemap" && t, s = a ? void 0 : this.fillOf(e.node);
791
+ return u`<div
792
+ class="cell"
793
+ data-id=${e.node.id}
794
+ ?data-leaf=${!e.hasChildren}
795
+ ?data-branch=${a}
796
+ ?data-loading=${this._loadingIds.has(e.node.id)}
797
+ ?data-load-error=${this._failedIds.has(e.node.id)}
798
+ role="treeitem"
799
+ tabindex=${e.node.id === this._tabFocusId ? "0" : "-1"}
800
+ aria-label=${this.accessibleName(e.node)}
801
+ aria-level=${e.level}
802
+ aria-setsize=${e.setsize}
803
+ aria-posinset=${e.posinset}
804
+ aria-expanded=${e.hasChildren ? String(t) : d}
805
+ 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>`;
808
+ }
809
+ }
810
+ function D(_) {
811
+ return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(_) : _.replace(/["\\]/g, "\\$&");
812
+ }
813
+ typeof customElements < "u" && !customElements.get("mp-hierarchy-chart") && customElements.define("mp-hierarchy-chart", q);
814
+ export {
815
+ q as MpHierarchyChart
816
+ };