@jcsoftdev/ui 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.2 (2026-10-13)
4
+
5
+ ### Fixes
6
+
7
+ - **`ui-theme build --no-kotlin` no longer builds Kotlin.** It used to generate `Theme.kt` and discard it, so `var(...)` and `oklch(...)` colors still threw "Unsupported color for Kotlin". Without the flag, the error now names the token and suggests `--no-kotlin`.
8
+
9
+ ### Added
10
+
11
+ - **`@jcsoftdev/ui/theme-builder`** exports `buildTheme`, `buildTokensCss`, `buildThemeCss`, `buildFontsCss` and `buildThemeKt`, typed. `buildTheme` takes `kotlin: false` to skip `Theme.kt`.
12
+
13
+ ## 0.2.1 (2026-10-13)
14
+
15
+ ### Fixes
16
+
17
+ - **DonutChart / PieChart no longer flicker on hover.** The hovered slice steps out by `explode`
18
+ and was also the pointer target, so a still pointer near its edge ended up outside the moved
19
+ slice, the hover dropped, the slice slid back under the pointer and the loop repeated (tooltip,
20
+ dimming and centre total blinking). Pointer events now go to fixed, invisible hit arcs that leave
21
+ no gap between slices and also cover the stepped-out ring.
22
+ - `ChartTooltip` takes an optional `containerHeight` and keeps the card inside it vertically
23
+ (DonutChart passes it), so a slice near the top no longer pushes the card past the chart edge.
24
+
3
25
  ## 0.2.0 (2026-10-11)
4
26
 
5
27
  Zero runtime dependencies, a published headless layer, per-part customization and a configurable
package/bin/ui-theme.mjs CHANGED
@@ -7,7 +7,8 @@ import { buildTheme } from "../scripts/build-theme.mjs";
7
7
  const USAGE = `Usage: ui-theme build [tokens.json] --out <dir> [--kotlin-package <pkg>] [--no-kotlin]
8
8
 
9
9
  Generates tokens.css, theme.css, fonts.css and Theme.kt from a tokens file.
10
- Without a tokens file the bundled default theme is used.`;
10
+ Without a tokens file the bundled default theme is used.
11
+ --no-kotlin skips Theme.kt, so tokens with var() or oklch() colors build.`;
11
12
 
12
13
  const args = process.argv.slice(2);
13
14
  const flag = (name) => {
@@ -35,11 +36,13 @@ if (command !== "build" || !out) {
35
36
 
36
37
  const here = dirname(fileURLToPath(import.meta.url));
37
38
  const file = resolve(tokensFlag ?? positional ?? join(here, "../tokens/default.json"));
38
- const files = buildTheme(JSON.parse(readFileSync(file, "utf8")), { kotlinPackage });
39
+ const files = buildTheme(JSON.parse(readFileSync(file, "utf8")), {
40
+ kotlinPackage,
41
+ kotlin: !noKotlin,
42
+ });
39
43
 
40
44
  mkdirSync(resolve(out), { recursive: true });
41
45
  for (const [name, content] of Object.entries(files)) {
42
- if (noKotlin && name.endsWith(".kt")) continue;
43
46
  writeFileSync(join(resolve(out), name), content);
44
47
  console.log(`wrote ${join(out, name)}`);
45
48
  }
@@ -17,6 +17,8 @@ export interface ChartTooltipProps {
17
17
  y: number;
18
18
  /** Width of the container; the tooltip prefers the left of the anchor past 60% and never leaves it. */
19
19
  containerWidth: number;
20
+ /** Height of the container; when given, the card is kept inside it vertically too. */
21
+ containerHeight?: number;
20
22
  title?: ReactNode;
21
23
  rows: readonly TooltipRow[];
22
24
  /** Wrapped sentence under the title, for notes that are not series values. */
@@ -33,6 +35,8 @@ export interface ChartTooltipProps {
33
35
  * always stays inside the container: it takes the side of the anchor with
34
36
  * room, and is clamped to the edges when neither side fits (narrow charts).
35
37
  */
36
- export declare function ChartTooltip({ x, y, containerWidth, title, rows, body, side, className, }: ChartTooltipProps): import("react").JSX.Element;
38
+ export declare function ChartTooltip({ x, y, containerWidth, containerHeight, title, rows, body, side, className, }: ChartTooltipProps): import("react").JSX.Element;
37
39
  /** Left edge of a tooltip `width` wide next to anchor `x`, kept inside `containerWidth`. */
38
40
  export declare function tooltipLeft(x: number, width: number, containerWidth: number, side?: "left" | "right"): number;
41
+ /** Vertical centre of a card `height` tall at anchor `y`, kept inside `containerHeight` when it fits. */
42
+ export declare function tooltipCenterY(y: number, height: number, containerHeight: number): number;
@@ -9,6 +9,7 @@ function ChartTooltip({
9
9
  x,
10
10
  y,
11
11
  containerWidth,
12
+ containerHeight,
12
13
  title,
13
14
  rows,
14
15
  body,
@@ -16,12 +17,15 @@ function ChartTooltip({
16
17
  className
17
18
  }) {
18
19
  const ref = useRef(null);
19
- const [size, setSize] = useState(0);
20
+ const [size, setSize] = useState({ width: 0, height: 0 });
20
21
  useIsomorphicLayoutEffect(() => {
21
- const next = ref.current?.offsetWidth ?? 0;
22
- if (Math.abs(next - size) > 0.5) setSize(next);
22
+ const width = ref.current?.offsetWidth ?? 0;
23
+ const height = ref.current?.offsetHeight ?? 0;
24
+ if (Math.abs(width - size.width) > 0.5 || Math.abs(height - size.height) > 0.5)
25
+ setSize({ width, height });
23
26
  });
24
- const left = tooltipLeft(x, size, containerWidth, side);
27
+ const left = tooltipLeft(x, size.width, containerWidth, side);
28
+ const top = containerHeight == null ? y : tooltipCenterY(y, size.height, containerHeight);
25
29
  return /* @__PURE__ */ jsxs(
26
30
  "div",
27
31
  {
@@ -34,7 +38,7 @@ function ChartTooltip({
34
38
  ),
35
39
  style: {
36
40
  maxWidth: Math.max(120, Math.min(260, containerWidth - EDGE * 2)),
37
- transform: `translate3d(${Math.round(left)}px, ${Math.round(y)}px, 0) translateY(-50%)`
41
+ transform: `translate3d(${Math.round(left)}px, ${Math.round(top)}px, 0) translateY(-50%)`
38
42
  },
39
43
  children: [
40
44
  title ? /* @__PURE__ */ jsx("div", { className: "mb-1.5 font-bold text-fs-120 text-ink", children: title }) : null,
@@ -77,7 +81,13 @@ function tooltipLeft(x, width, containerWidth, side) {
77
81
  const chosen = preferLeft && fitsLeft ? leftSide : fitsRight ? right : fitsLeft ? leftSide : right;
78
82
  return Math.max(EDGE, Math.min(chosen, containerWidth - width - EDGE));
79
83
  }
84
+ function tooltipCenterY(y, height, containerHeight) {
85
+ const min = height / 2 + EDGE;
86
+ const max = containerHeight - height / 2 - EDGE;
87
+ return max < min ? containerHeight / 2 : Math.max(min, Math.min(y, max));
88
+ }
80
89
  export {
81
90
  ChartTooltip,
91
+ tooltipCenterY,
82
92
  tooltipLeft
83
93
  };
@@ -236,13 +236,21 @@ function DonutPlot({
236
236
  const from = semi ? -Math.PI / 2 : degToRad(startAngle);
237
237
  const to = semi ? Math.PI / 2 : from + TAU;
238
238
  const pad = gap / Math.max(1, (inner2 + radius2) / (variant === "pie" ? 1.6 : 2));
239
- const slices2 = sliceAngles(
240
- items.map(
241
- (_, index) => visible2.some((entry) => entry.index === index) ? shown[index] ?? 0 : 0
242
- ),
243
- { startAngle: from, endAngle: to, padAngle: pad }
239
+ const values = items.map(
240
+ (_, index) => visible2.some((entry) => entry.index === index) ? shown[index] ?? 0 : 0
244
241
  );
245
- return { visible: visible2.map((entry) => entry.index), sum: sum2, radius: radius2, inner: inner2, cx: cx2, cy: cy2, slices: slices2 };
242
+ const slices2 = sliceAngles(values, { startAngle: from, endAngle: to, padAngle: pad });
243
+ const hits2 = sliceAngles(values, { startAngle: from, endAngle: to });
244
+ return {
245
+ visible: visible2.map((entry) => entry.index),
246
+ sum: sum2,
247
+ radius: radius2,
248
+ inner: inner2,
249
+ cx: cx2,
250
+ cy: cy2,
251
+ slices: slices2,
252
+ hits: hits2
253
+ };
246
254
  }, [
247
255
  items,
248
256
  shown,
@@ -257,7 +265,7 @@ function DonutPlot({
257
265
  gap,
258
266
  startAngle
259
267
  ]);
260
- const { visible, sum, radius, inner, cx, cy, slices } = geometry;
268
+ const { visible, sum, radius, inner, cx, cy, slices, hits } = geometry;
261
269
  const nav = useIndexNavigation(visible.length, { wrap: true });
262
270
  const activeIndex = nav.active != null ? visible[nav.active] ?? null : null;
263
271
  const legendIndex = state.highlighted ? items.findIndex((item) => item.datum.id === state.highlighted) : -1;
@@ -276,6 +284,19 @@ function DonutPlot({
276
284
  ),
277
285
  [slices, cx, cy, inner, radius, cornerRadius]
278
286
  );
287
+ const hitPaths = useMemo(
288
+ () => hits.map(
289
+ (hit) => hit.fraction > 0 ? arcPath({
290
+ cx,
291
+ cy,
292
+ innerRadius: inner,
293
+ outerRadius: radius + Math.max(0, explode),
294
+ startAngle: hit.start,
295
+ endAngle: hit.end
296
+ }) : ""
297
+ ),
298
+ [hits, cx, cy, inner, radius, explode]
299
+ );
279
300
  const outsideLabels = useMemo(() => {
280
301
  if (!outside) return [];
281
302
  const lines = outside === "both" ? 2 : 1;
@@ -405,7 +426,6 @@ function DonutPlot({
405
426
  const item = items[index];
406
427
  const path = paths[index];
407
428
  if (!item || !path) return null;
408
- const position = visible.indexOf(index);
409
429
  const focused = focusIndex === index;
410
430
  const dimmed = focusIndex != null && !focused;
411
431
  const shift = focused ? polarPoint(0, 0, explode, slice.mid) : { x: 0, y: 0 };
@@ -418,11 +438,7 @@ function DonutPlot({
418
438
  dx: shift.x,
419
439
  dy: shift.y,
420
440
  originX: cx,
421
- originY: cy,
422
- clickable: onSliceClick != null,
423
- onEnter: (event) => nav.hover(position, event),
424
- onLeave: nav.leave,
425
- onClick: onSliceClick ? () => onSliceClick(item.datum) : void 0
441
+ originY: cy
426
442
  },
427
443
  item.datum.id
428
444
  );
@@ -478,6 +494,22 @@ function DonutPlot({
478
494
  label.id
479
495
  );
480
496
  }),
497
+ hitPaths.map((d, index) => {
498
+ const item = items[index];
499
+ if (!item || !d) return null;
500
+ const position = visible.indexOf(index);
501
+ return /* @__PURE__ */ jsx(
502
+ SliceHitArea,
503
+ {
504
+ d,
505
+ clickable: onSliceClick != null,
506
+ onEnter: (event) => nav.hover(position, event),
507
+ onLeave: nav.leave,
508
+ onClick: onSliceClick ? () => onSliceClick(item.datum) : void 0
509
+ },
510
+ item.datum.id
511
+ );
512
+ }),
481
513
  showCenter ? /* @__PURE__ */ jsxs("g", { "data-fade": "", ...DECORATIVE, textAnchor: "middle", className: "pointer-events-none", children: [
482
514
  /* @__PURE__ */ jsx(
483
515
  "text",
@@ -528,7 +560,17 @@ function DonutPlot({
528
560
  className: "pointer-events-none absolute inset-0 rounded-xs outline-none focus-visible:outline-2 focus-visible:outline-accent-ink focus-visible:outline-offset-2"
529
561
  }
530
562
  ),
531
- tooltip && anchor && rows.length ? /* @__PURE__ */ jsx(ChartTooltip, { x: anchor.x, y: anchor.y, containerWidth: width, rows, side: tipSide }) : null
563
+ tooltip && anchor && rows.length ? /* @__PURE__ */ jsx(
564
+ ChartTooltip,
565
+ {
566
+ x: anchor.x,
567
+ y: anchor.y,
568
+ containerWidth: width,
569
+ containerHeight: height,
570
+ rows,
571
+ side: tipSide
572
+ }
573
+ ) : null
532
574
  ] });
533
575
  }
534
576
  const SliceMark = memo(function SliceMark2({
@@ -538,19 +580,32 @@ const SliceMark = memo(function SliceMark2({
538
580
  dx,
539
581
  dy,
540
582
  originX,
541
- originY,
542
- clickable,
543
- onEnter,
544
- onLeave,
545
- onClick
583
+ originY
546
584
  }) {
585
+ return /* @__PURE__ */ jsx(
586
+ "path",
587
+ {
588
+ "data-slice": "",
589
+ d,
590
+ className: "pointer-events-none motion-safe:transition-[transform,opacity] motion-safe:duration-200 motion-safe:ease-out",
591
+ style: {
592
+ fill: paint,
593
+ opacity: dimmed ? 0.4 : 1,
594
+ transform: `translate(${Math.round(dx * 100) / 100}px, ${Math.round(dy * 100) / 100}px)`,
595
+ transformOrigin: `${originX}px ${originY}px`
596
+ }
597
+ }
598
+ );
599
+ });
600
+ function SliceHitArea({ d, clickable, onEnter, onLeave, onClick }) {
547
601
  return (
548
602
  // biome-ignore lint/a11y/noStaticElementInteractions: pointer hover only; keyboard goes through the chart slider.
549
603
  /* @__PURE__ */ jsx(
550
604
  "path",
551
605
  {
552
- "data-slice": "",
606
+ "data-slice-hit": "",
553
607
  d,
608
+ fill: "transparent",
554
609
  onPointerEnter: onEnter,
555
610
  onPointerMove: onEnter,
556
611
  onPointerLeave: onLeave,
@@ -558,20 +613,11 @@ const SliceMark = memo(function SliceMark2({
558
613
  onClick: (event) => {
559
614
  if (event.detail === 0) onClick?.();
560
615
  },
561
- className: cn(
562
- "motion-safe:transition-[transform,opacity] motion-safe:duration-200 motion-safe:ease-out",
563
- clickable && "cursor-pointer"
564
- ),
565
- style: {
566
- fill: paint,
567
- opacity: dimmed ? 0.4 : 1,
568
- transform: `translate(${Math.round(dx * 100) / 100}px, ${Math.round(dy * 100) / 100}px)`,
569
- transformOrigin: `${originX}px ${originY}px`
570
- }
616
+ className: cn(clickable && "cursor-pointer")
571
617
  }
572
618
  )
573
619
  );
574
- });
620
+ }
575
621
  const PATTERN_KINDS = 5;
576
622
  function SlicePattern({ id, kind, color }) {
577
623
  const motif = { fill: "var(--surface)", fillOpacity: 0.5 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcsoftdev/ui",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Token-driven React component library: React 19, Tailwind v4.",
5
5
  "author": "jcsoftdev",
6
6
  "license": "MIT",
@@ -45,6 +45,7 @@
45
45
  "bin",
46
46
  "icons",
47
47
  "scripts/build-theme.mjs",
48
+ "scripts/build-theme.d.ts",
48
49
  "README.md",
49
50
  "CHANGELOG.md",
50
51
  "THIRD_PARTY_NOTICES.md",
@@ -54,6 +55,10 @@
54
55
  "./styles/*": "./styles/*",
55
56
  "./tokens/*": "./tokens/*",
56
57
  "./package.json": "./package.json",
58
+ "./theme-builder": {
59
+ "types": "./scripts/build-theme.d.ts",
60
+ "import": "./scripts/build-theme.mjs"
61
+ },
57
62
  "./rich-text": {
58
63
  "types": "./dist/rich-text/index.d.ts",
59
64
  "source": "./src/rich-text/index.ts",
@@ -0,0 +1,18 @@
1
+ export interface ThemeTokens {
2
+ name: string;
3
+ [group: string]: unknown;
4
+ }
5
+
6
+ export interface BuildThemeOptions {
7
+ kotlin?: boolean;
8
+ kotlinPackage?: string;
9
+ }
10
+
11
+ export function buildTokensCss(tokens: ThemeTokens): string;
12
+ export function buildThemeCss(tokens: ThemeTokens): string;
13
+ export function buildFontsCss(tokens: ThemeTokens): string;
14
+ export function buildThemeKt(tokens: ThemeTokens, pkg?: string): string;
15
+ export function buildTheme(
16
+ tokens: ThemeTokens,
17
+ options?: BuildThemeOptions,
18
+ ): Record<string, string>;
@@ -341,6 +341,17 @@ export function toKotlinColor(css) {
341
341
  throw new Error(`Unsupported color for Kotlin: ${css}`);
342
342
  }
343
343
 
344
+ const kotlinColorOf = (token, theme, base) => {
345
+ const value = valueFor(token, theme, base);
346
+ try {
347
+ return toKotlinColor(value);
348
+ } catch {
349
+ throw new Error(
350
+ `Token "${token.name}" (${theme}) has a color Kotlin cannot represent: ${value}. Use hex or rgb(a) values, or pass --no-kotlin.`,
351
+ );
352
+ }
353
+ };
354
+
344
355
  const px = (value) => `${Number.parseFloat(value)}.dp`;
345
356
 
346
357
  export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
@@ -368,7 +379,7 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
368
379
  for (const theme of themes) {
369
380
  out.push(` val ${pascal(theme)} = ThemeColors(`);
370
381
  for (const t of colors) {
371
- out.push(` ${camel(t.name)} = ${toKotlinColor(valueFor(t, theme, base))},`);
382
+ out.push(` ${camel(t.name)} = ${kotlinColorOf(t, theme, base)},`);
372
383
  }
373
384
  out.push(" )");
374
385
  }
@@ -387,7 +398,7 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
387
398
  const byName = new Map(tokens.color.tokens.map((t) => [t.name, t]));
388
399
  const args = Object.entries(PALETTE_ROLES).map(([role]) => {
389
400
  const tok = byName.get(roles[role]);
390
- return tok ? toKotlinColor(valueFor(tok, theme, base)) : "Color.Unspecified";
401
+ return tok ? kotlinColorOf(tok, theme, base) : "Color.Unspecified";
391
402
  });
392
403
  out.push(` "${id}" to AccentPalette(${args.join(", ")}),`);
393
404
  }
@@ -427,11 +438,12 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
427
438
  return out.join("\n");
428
439
  }
429
440
 
430
- export function buildTheme(tokens, { kotlinPackage } = {}) {
431
- return {
441
+ export function buildTheme(tokens, { kotlinPackage, kotlin = true } = {}) {
442
+ const css = {
432
443
  "tokens.css": buildTokensCss(tokens),
433
444
  "theme.css": buildThemeCss(tokens),
434
445
  "fonts.css": buildFontsCss(tokens),
435
- "Theme.kt": buildThemeKt(tokens, kotlinPackage),
436
446
  };
447
+ if (!kotlin) return css;
448
+ return { ...css, "Theme.kt": buildThemeKt(tokens, kotlinPackage) };
437
449
  }
@@ -26,6 +26,8 @@ export interface ChartTooltipProps {
26
26
  y: number;
27
27
  /** Width of the container; the tooltip prefers the left of the anchor past 60% and never leaves it. */
28
28
  containerWidth: number;
29
+ /** Height of the container; when given, the card is kept inside it vertically too. */
30
+ containerHeight?: number;
29
31
  title?: ReactNode;
30
32
  rows: readonly TooltipRow[];
31
33
  /** Wrapped sentence under the title, for notes that are not series values. */
@@ -47,6 +49,7 @@ export function ChartTooltip({
47
49
  x,
48
50
  y,
49
51
  containerWidth,
52
+ containerHeight,
50
53
  title,
51
54
  rows,
52
55
  body,
@@ -54,12 +57,15 @@ export function ChartTooltip({
54
57
  className,
55
58
  }: ChartTooltipProps) {
56
59
  const ref = useRef<HTMLDivElement>(null);
57
- const [size, setSize] = useState(0);
60
+ const [size, setSize] = useState({ width: 0, height: 0 });
58
61
  useIsomorphicLayoutEffect(() => {
59
- const next = ref.current?.offsetWidth ?? 0;
60
- if (Math.abs(next - size) > 0.5) setSize(next);
62
+ const width = ref.current?.offsetWidth ?? 0;
63
+ const height = ref.current?.offsetHeight ?? 0;
64
+ if (Math.abs(width - size.width) > 0.5 || Math.abs(height - size.height) > 0.5)
65
+ setSize({ width, height });
61
66
  });
62
- const left = tooltipLeft(x, size, containerWidth, side);
67
+ const left = tooltipLeft(x, size.width, containerWidth, side);
68
+ const top = containerHeight == null ? y : tooltipCenterY(y, size.height, containerHeight);
63
69
  return (
64
70
  <div
65
71
  ref={ref}
@@ -71,7 +77,7 @@ export function ChartTooltip({
71
77
  )}
72
78
  style={{
73
79
  maxWidth: Math.max(120, Math.min(260, containerWidth - EDGE * 2)),
74
- transform: `translate3d(${Math.round(left)}px, ${Math.round(y)}px, 0) translateY(-50%)`,
80
+ transform: `translate3d(${Math.round(left)}px, ${Math.round(top)}px, 0) translateY(-50%)`,
75
81
  }}
76
82
  >
77
83
  {title ? <div className="mb-1.5 font-bold text-fs-120 text-ink">{title}</div> : null}
@@ -124,3 +130,10 @@ export function tooltipLeft(
124
130
  preferLeft && fitsLeft ? leftSide : fitsRight ? right : fitsLeft ? leftSide : right;
125
131
  return Math.max(EDGE, Math.min(chosen, containerWidth - width - EDGE));
126
132
  }
133
+
134
+ /** Vertical centre of a card `height` tall at anchor `y`, kept inside `containerHeight` when it fits. */
135
+ export function tooltipCenterY(y: number, height: number, containerHeight: number): number {
136
+ const min = height / 2 + EDGE;
137
+ const max = containerHeight - height / 2 - EDGE;
138
+ return max < min ? containerHeight / 2 : Math.max(min, Math.min(y, max));
139
+ }
@@ -374,13 +374,22 @@ function DonutPlot({
374
374
  const from = semi ? -Math.PI / 2 : degToRad(startAngle);
375
375
  const to = semi ? Math.PI / 2 : from + TAU;
376
376
  const pad = gap / Math.max(1, (inner + radius) / (variant === "pie" ? 1.6 : 2));
377
- const slices = sliceAngles(
378
- items.map((_, index) =>
379
- visible.some((entry) => entry.index === index) ? (shown[index] ?? 0) : 0,
380
- ),
381
- { startAngle: from, endAngle: to, padAngle: pad },
377
+ const values = items.map((_, index) =>
378
+ visible.some((entry) => entry.index === index) ? (shown[index] ?? 0) : 0,
382
379
  );
383
- return { visible: visible.map((entry) => entry.index), sum, radius, inner, cx, cy, slices };
380
+ const slices = sliceAngles(values, { startAngle: from, endAngle: to, padAngle: pad });
381
+ // Hit areas leave no gap between neighbours, so moving across slices never drops the hover.
382
+ const hits = sliceAngles(values, { startAngle: from, endAngle: to });
383
+ return {
384
+ visible: visible.map((entry) => entry.index),
385
+ sum,
386
+ radius,
387
+ inner,
388
+ cx,
389
+ cy,
390
+ slices,
391
+ hits,
392
+ };
384
393
  }, [
385
394
  items,
386
395
  shown,
@@ -396,7 +405,7 @@ function DonutPlot({
396
405
  startAngle,
397
406
  ]);
398
407
 
399
- const { visible, sum, radius, inner, cx, cy, slices } = geometry;
408
+ const { visible, sum, radius, inner, cx, cy, slices, hits } = geometry;
400
409
  const nav = useIndexNavigation(visible.length, { wrap: true });
401
410
  const activeIndex = nav.active != null ? (visible[nav.active] ?? null) : null;
402
411
  const legendIndex = state.highlighted
@@ -421,6 +430,25 @@ function DonutPlot({
421
430
  ),
422
431
  [slices, cx, cy, inner, radius, cornerRadius],
423
432
  );
433
+ // The hovered slice steps out by `explode`. Pointer events go to these resting arcs, which
434
+ // also cover the stepped-out ring, never to the moving slice: a slice that moved away from a
435
+ // still pointer fired pointerleave, dropped the hover, slid back under the pointer and looped.
436
+ const hitPaths = useMemo(
437
+ () =>
438
+ hits.map((hit) =>
439
+ hit.fraction > 0
440
+ ? arcPath({
441
+ cx,
442
+ cy,
443
+ innerRadius: inner,
444
+ outerRadius: radius + Math.max(0, explode),
445
+ startAngle: hit.start,
446
+ endAngle: hit.end,
447
+ })
448
+ : "",
449
+ ),
450
+ [hits, cx, cy, inner, radius, explode],
451
+ );
424
452
 
425
453
  // Outside labels -----------------------------------------------------------
426
454
  const outsideLabels = useMemo<OutsideLabel[]>(() => {
@@ -570,7 +598,6 @@ function DonutPlot({
570
598
  const item = items[index];
571
599
  const path = paths[index];
572
600
  if (!item || !path) return null;
573
- const position = visible.indexOf(index);
574
601
  const focused = focusIndex === index;
575
602
  const dimmed = focusIndex != null && !focused;
576
603
  const shift = focused ? polarPoint(0, 0, explode, slice.mid) : { x: 0, y: 0 };
@@ -584,10 +611,6 @@ function DonutPlot({
584
611
  dy={shift.y}
585
612
  originX={cx}
586
613
  originY={cy}
587
- clickable={onSliceClick != null}
588
- onEnter={(event) => nav.hover(position, event)}
589
- onLeave={nav.leave}
590
- onClick={onSliceClick ? () => onSliceClick(item.datum) : undefined}
591
614
  />
592
615
  );
593
616
  })}
@@ -643,6 +666,22 @@ function DonutPlot({
643
666
  );
644
667
  })}
645
668
 
669
+ {hitPaths.map((d, index) => {
670
+ const item = items[index];
671
+ if (!item || !d) return null;
672
+ const position = visible.indexOf(index);
673
+ return (
674
+ <SliceHitArea
675
+ key={item.datum.id}
676
+ d={d}
677
+ clickable={onSliceClick != null}
678
+ onEnter={(event) => nav.hover(position, event)}
679
+ onLeave={nav.leave}
680
+ onClick={onSliceClick ? () => onSliceClick(item.datum) : undefined}
681
+ />
682
+ );
683
+ })}
684
+
646
685
  {showCenter ? (
647
686
  <g data-fade="" {...DECORATIVE} textAnchor="middle" className="pointer-events-none">
648
687
  <text
@@ -691,7 +730,14 @@ function DonutPlot({
691
730
  />
692
731
 
693
732
  {tooltip && anchor && rows.length ? (
694
- <ChartTooltip x={anchor.x} y={anchor.y} containerWidth={width} rows={rows} side={tipSide} />
733
+ <ChartTooltip
734
+ x={anchor.x}
735
+ y={anchor.y}
736
+ containerWidth={width}
737
+ containerHeight={height}
738
+ rows={rows}
739
+ side={tipSide}
740
+ />
695
741
  ) : null}
696
742
  </div>
697
743
  );
@@ -706,10 +752,6 @@ interface SliceMarkProps {
706
752
  dy: number;
707
753
  originX: number;
708
754
  originY: number;
709
- clickable: boolean;
710
- onEnter: (event: { clientX: number; clientY: number }) => void;
711
- onLeave: () => void;
712
- onClick?: () => void;
713
755
  }
714
756
 
715
757
  const SliceMark = memo(function SliceMark({
@@ -720,29 +762,12 @@ const SliceMark = memo(function SliceMark({
720
762
  dy,
721
763
  originX,
722
764
  originY,
723
- clickable,
724
- onEnter,
725
- onLeave,
726
- onClick,
727
765
  }: SliceMarkProps) {
728
766
  return (
729
- // biome-ignore lint/a11y/noStaticElementInteractions: pointer hover only; keyboard goes through the chart slider.
730
767
  <path
731
768
  data-slice=""
732
769
  d={d}
733
- onPointerEnter={onEnter}
734
- onPointerMove={onEnter}
735
- onPointerLeave={onLeave}
736
- onPointerUp={onClick}
737
- onClick={(event) => {
738
- // A mouse or touch press opens on pointer-up (a hover shift can move the slice
739
- // between press and release and swallow the click); click is for keyboard and AT.
740
- if (event.detail === 0) onClick?.();
741
- }}
742
- className={cn(
743
- "motion-safe:transition-[transform,opacity] motion-safe:duration-200 motion-safe:ease-out",
744
- clickable && "cursor-pointer",
745
- )}
770
+ className="pointer-events-none motion-safe:transition-[transform,opacity] motion-safe:duration-200 motion-safe:ease-out"
746
771
  style={{
747
772
  fill: paint,
748
773
  opacity: dimmed ? 0.4 : 1,
@@ -753,6 +778,35 @@ const SliceMark = memo(function SliceMark({
753
778
  );
754
779
  });
755
780
 
781
+ interface SliceHitAreaProps {
782
+ d: string;
783
+ clickable: boolean;
784
+ onEnter: (event: { clientX: number; clientY: number }) => void;
785
+ onLeave: () => void;
786
+ onClick?: () => void;
787
+ }
788
+
789
+ /** Invisible, never-moving pointer target for one slice. */
790
+ function SliceHitArea({ d, clickable, onEnter, onLeave, onClick }: SliceHitAreaProps) {
791
+ return (
792
+ // biome-ignore lint/a11y/noStaticElementInteractions: pointer hover only; keyboard goes through the chart slider.
793
+ <path
794
+ data-slice-hit=""
795
+ d={d}
796
+ fill="transparent"
797
+ onPointerEnter={onEnter}
798
+ onPointerMove={onEnter}
799
+ onPointerLeave={onLeave}
800
+ onPointerUp={onClick}
801
+ onClick={(event) => {
802
+ // A mouse or touch press opens on pointer-up; click is for keyboard and AT.
803
+ if (event.detail === 0) onClick?.();
804
+ }}
805
+ className={cn(clickable && "cursor-pointer")}
806
+ />
807
+ );
808
+ }
809
+
756
810
  const PATTERN_KINDS = 5;
757
811
 
758
812
  /** Texture swatch for one slice: the slice color with a surface-colored motif on top. */