basalt-ui 2.13.0 → 2.13.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/MIGRATING.md +32 -12
  3. package/README.md +1 -1
  4. package/dist/charts/compile.d.ts.map +1 -1
  5. package/dist/charts/compile.js +6 -5
  6. package/dist/charts/cursor.d.ts +33 -7
  7. package/dist/charts/cursor.d.ts.map +1 -1
  8. package/dist/charts/cursor.js +31 -10
  9. package/dist/charts/legend.d.ts +19 -3
  10. package/dist/charts/legend.d.ts.map +1 -1
  11. package/dist/charts/legend.js +33 -15
  12. package/dist/charts/marks.d.ts.map +1 -1
  13. package/dist/charts/marks.js +24 -28
  14. package/dist/charts/panel.d.ts.map +1 -1
  15. package/dist/charts/panel.js +4 -4
  16. package/dist/charts/types.d.ts +3 -2
  17. package/dist/charts/types.d.ts.map +1 -1
  18. package/dist/router-tanstack/nav.d.ts +5 -0
  19. package/dist/router-tanstack/nav.d.ts.map +1 -1
  20. package/dist/router-tanstack/use-nav.d.ts +4 -2
  21. package/dist/router-tanstack/use-nav.d.ts.map +1 -1
  22. package/dist/router-tanstack/use-nav.js +55 -18
  23. package/dist/shell/app-breadcrumbs.d.ts +1 -3
  24. package/dist/shell/app-breadcrumbs.d.ts.map +1 -1
  25. package/dist/shell/app-breadcrumbs.js +1 -6
  26. package/dist/shell/index.d.ts +14 -5
  27. package/dist/shell/index.d.ts.map +1 -1
  28. package/dist/shell/index.js +6 -29
  29. package/dist/shell/nav-types.d.ts +7 -0
  30. package/dist/shell/nav-types.d.ts.map +1 -1
  31. package/dist/shell/page-aside.d.ts +4 -2
  32. package/dist/shell/page-aside.d.ts.map +1 -1
  33. package/dist/shell/page-aside.js +41 -23
  34. package/dist/shell/page-bar.d.ts +1 -1
  35. package/dist/shell/page-bar.d.ts.map +1 -1
  36. package/dist/shell/page-bar.js +39 -33
  37. package/dist/theme/index.d.ts.map +1 -1
  38. package/dist/theme/index.js +4 -1
  39. package/llms.txt +2 -2
  40. package/package.json +1 -1
  41. package/src/charts/compile.ts +8 -10
  42. package/src/charts/cursor.ts +69 -19
  43. package/src/charts/legend.tsx +40 -19
  44. package/src/charts/marks.ts +28 -29
  45. package/src/charts/panel.tsx +4 -4
  46. package/src/charts/types.ts +3 -2
  47. package/src/router-tanstack/nav.ts +5 -0
  48. package/src/router-tanstack/use-nav.ts +116 -76
  49. package/src/shell/app-breadcrumbs.tsx +1 -12
  50. package/src/shell/index.tsx +22 -55
  51. package/src/shell/nav-types.ts +8 -0
  52. package/src/shell/page-aside.tsx +59 -26
  53. package/src/shell/page-bar.tsx +63 -59
  54. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -0
  55. package/src/theme/index.ts +4 -1
@@ -1,5 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import { cx } from "../common/props.js";
5
5
  import { CtlSlot } from "../theme/index.js";
@@ -16,18 +16,15 @@ import { useIsomorphicLayoutEffect } from "../common/isomorphic-layout-effect.js
16
16
  import classes from "./page-bar.module.css";
17
17
  import asideClasses from "./page-aside.module.css";
18
18
  const PAGE_BAR_HEIGHT_VAR = "--basalt-page-bar-h";
19
- const NO_SLOTS = {
19
+ const NO_TARGETS = {
20
20
  target: null,
21
21
  setTarget: () => {
22
22
  },
23
23
  bandTarget: null,
24
24
  setBandTarget: () => {
25
- },
26
- inShell: false,
27
- mobileMoreActions: [],
28
- kebabClaims: 0,
29
- claimKebab: () => () => {
30
- },
25
+ }
26
+ };
27
+ const NO_PANEL_SLOT = {
31
28
  panelHost: false,
32
29
  claimPanelHost: () => () => {
33
30
  },
@@ -38,7 +35,10 @@ const NO_SLOTS = {
38
35
  setPanelTarget: () => {
39
36
  }
40
37
  };
41
- const PageBarContext = createContext(NO_SLOTS);
38
+ const PortalTargetsContext = createContext(NO_TARGETS);
39
+ const AsidePanelContext = createContext(NO_PANEL_SLOT);
40
+ const InShellContext = createContext(false);
41
+ const KebabClaimedContext = createContext(false);
42
42
  function PageBarProvider({
43
43
  globalActions,
44
44
  children
@@ -63,41 +63,45 @@ function PageBarProvider({
63
63
  setPanel((current) => current === next ? null : current);
64
64
  };
65
65
  }, []);
66
- const mobileMoreActions = globalActions.filter((action, index) => (action.mobile ?? (index < 2 ? "bar" : "more")) === "more").map(globalActionAsBarAction);
67
- const value = {
68
- target,
69
- setTarget,
70
- bandTarget,
71
- setBandTarget,
72
- inShell: true,
73
- mobileMoreActions,
74
- kebabClaims,
75
- claimKebab,
76
- panelHost: panelHostClaims > 0,
77
- claimPanelHost,
78
- panel,
79
- claimPanel,
80
- panelTarget,
81
- setPanelTarget
82
- };
83
- return /* @__PURE__ */ jsx(PageBarContext.Provider, { value, children: /* @__PURE__ */ jsx(BarExtrasProvider, { value: { mobileMoreActions, claimKebab }, children }) });
66
+ const mobileMoreActions = useMemo(
67
+ () => globalActions.filter((action, index) => (action.mobile ?? (index < 2 ? "bar" : "more")) === "more").map(globalActionAsBarAction),
68
+ [globalActions]
69
+ );
70
+ const targets = useMemo(
71
+ () => ({ target, setTarget, bandTarget, setBandTarget }),
72
+ [target, bandTarget]
73
+ );
74
+ const panelSlot = useMemo(
75
+ () => ({
76
+ panelHost: panelHostClaims > 0,
77
+ claimPanelHost,
78
+ panel,
79
+ claimPanel,
80
+ panelTarget,
81
+ setPanelTarget
82
+ }),
83
+ [panelHostClaims, claimPanelHost, panel, claimPanel, panelTarget]
84
+ );
85
+ const extras = useMemo(() => ({ mobileMoreActions, claimKebab }), [mobileMoreActions, claimKebab]);
86
+ return /* @__PURE__ */ jsx(InShellContext.Provider, { value: true, children: /* @__PURE__ */ jsx(PortalTargetsContext.Provider, { value: targets, children: /* @__PURE__ */ jsx(KebabClaimedContext.Provider, { value: kebabClaims > 0, children: /* @__PURE__ */ jsx(AsidePanelContext.Provider, { value: panelSlot, children: /* @__PURE__ */ jsx(BarExtrasProvider, { value: extras, children }) }) }) }) });
84
87
  }
85
88
  function PageBarOutlet({ className }) {
86
- const { setTarget } = useContext(PageBarContext);
89
+ const { setTarget } = useContext(PortalTargetsContext);
87
90
  return /* @__PURE__ */ jsx("div", { ref: setTarget, className });
88
91
  }
89
92
  function PageBarBandOutlet({ className }) {
90
- const { setBandTarget } = useContext(PageBarContext);
93
+ const { setBandTarget } = useContext(PortalTargetsContext);
91
94
  return /* @__PURE__ */ jsx("div", { ref: setBandTarget, className });
92
95
  }
93
96
  function useInPageBarShell() {
94
- return useContext(PageBarContext).inShell;
97
+ return useContext(InShellContext);
95
98
  }
96
99
  function usePageKebabClaimed() {
97
- return useContext(PageBarContext).kebabClaims > 0;
100
+ return useContext(KebabClaimedContext);
98
101
  }
99
102
  function useAsidePanelSlot() {
100
- const { panelHost, claimPanel, panelTarget, inShell } = useContext(PageBarContext);
103
+ const { panelHost, claimPanel, panelTarget } = useContext(AsidePanelContext);
104
+ const inShell = useContext(InShellContext);
101
105
  const [settled, setSettled] = useState(false);
102
106
  useIsomorphicLayoutEffect(() => {
103
107
  setSettled(true);
@@ -158,7 +162,9 @@ function PageBar({
158
162
  style,
159
163
  classNames
160
164
  }) {
161
- const { target, bandTarget, inShell, panel, claimPanelHost, setPanelTarget } = useContext(PageBarContext);
165
+ const { target, bandTarget } = useContext(PortalTargetsContext);
166
+ const { panel, claimPanelHost, setPanelTarget } = useContext(AsidePanelContext);
167
+ const inShell = useContext(InShellContext);
162
168
  const [panelOpened, setPanelOpened] = useState(false);
163
169
  const seenPanel = useRef(panel);
164
170
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EA0CV,oBAAoB,EAGpB,oBAAoB,EAErB,MAAM,eAAe,CAAA;AAStB,OA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AAM,iBAAiB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE9E,8FAA8F;AAC9F,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAsF7D;;8FAE8F;AAC9F,eAAO,MAAM,oBAAoB,EAAE,oBACc,CAAA;AAEjD,kEAAkE;AAClE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IAE9B;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAA;IAEzB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAE1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAC7B,CAAA;AAYD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,aAAa,CAAC,EACrD,OAAO,CAAC,EAAE,wBAAwB,GACjC,oBAAoB,CAiCtB"}
@@ -693,7 +693,10 @@ function buildTheme(data, options = {}) {
693
693
  // behind it. Title = head font; close button = the ghost idiom (floating.module.css). Below the
694
694
  // `medium` size class the Modal is a bottom sheet (floating.module.css `sheet*`).
695
695
  Modal: ext({
696
- defaultProps: { radius: radius.floating, closeButtonProps: { ...HIT_ATTR } },
696
+ defaultProps: {
697
+ radius: radius.floating,
698
+ closeButtonProps: { ...HIT_ATTR, "aria-label": "Close" }
699
+ },
697
700
  classNames: {
698
701
  close: floatingClasses.closeButton,
699
702
  inner: floatingClasses.sheetInner,
package/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # basalt-ui v2.13.0
1
+ # basalt-ui v2.13.2
2
2
  # Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
3
3
  #
4
4
  # Entry points: use the exact import specifier below; do not guess.
@@ -13,7 +13,7 @@
13
13
  # A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
14
14
 
15
15
  Package: basalt-ui
16
- Version: 2.13.0
16
+ Version: 2.13.2
17
17
 
18
18
  ## basalt-ui
19
19
  Import: import { ... } from 'basalt-ui'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basalt-ui",
3
- "version": "2.13.0",
3
+ "version": "2.13.2",
4
4
  "description": "Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets",
5
5
  "keywords": [
6
6
  "charts",
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * `compileCartesian` — basalt's chart spec in, a TanStack definition out (`docs/V2-SPEC.md` § 9.2).
3
3
  * Pure and React-free: the host memoizes it, the tests call it directly. It owns the scales and
4
- * domains, the theme bridge, zones / x-zones / reference lines, the crosshair, grouped source-only
5
- * focus, the shared cursor binding, the tooltip content, and the container-class guide ladder.
4
+ * domains, the theme bridge, zones / x-zones / reference lines, the crosshair, the shared cursor
5
+ * binding, the tooltip content, and the container-class guide ladder.
6
6
  * TanStack owns margins (measured), layout, focus and keyboard, the tooltip surface and SSR.
7
7
  */
8
8
  import { crosshair } from '@tanstack/charts/crosshair'
@@ -11,7 +11,6 @@ import { rect } from '@tanstack/charts/rect'
11
11
  import { ruleX, ruleY } from '@tanstack/charts/rule'
12
12
  import { scaleLinear } from '@tanstack/charts/scales/linear'
13
13
  import { scaleUtc } from 'd3-scale'
14
- import { tooltip as tooltipHost } from '@tanstack/charts/tooltip'
15
14
  import { portal } from '@tanstack/charts/tooltip/portal'
16
15
  import type {
17
16
  ChartBuildContext,
@@ -27,7 +26,7 @@ import { SHORT_CHART_HEIGHT } from './box'
27
26
  import { fmtCompact } from '../format/number'
28
27
  import { VX } from '../tokens'
29
28
  import type { ContainerClass } from '../tokens/size-classes'
30
- import { cursorBinding, sourceOnlyFocus } from './cursor'
29
+ import { cursorBinding, followerOptions, quietWhileFollowing } from './cursor'
31
30
  import { cursorDots } from './marks'
32
31
  import { bucketTicks, strideEvery } from './ticks'
33
32
  import { MAIN_PANE, plotAccess, plotContext } from './plot-context'
@@ -805,7 +804,8 @@ function tooltipSpec<T, X extends ChartX>(opts: {
805
804
  (s) => s.tooltip !== false,
806
805
  )
807
806
  return {
808
- use: tooltipHost,
807
+ use: quietWhileFollowing,
808
+ ...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
809
809
  portal,
810
810
  anchor: 'group-center',
811
811
  content: (points: readonly ChartPoint[]) => {
@@ -909,11 +909,9 @@ export function compileCartesian<T, X extends ChartX>(
909
909
  ...(labelsInside(cls, height) && { margin: { left: 0, ...(axes.right && { right: 0 }) } }),
910
910
  }
911
911
  },
912
- // Followers paint the crosshair only, unless the chart opts into following tooltips.
913
- focus:
914
- typeof input.tooltip === 'object' && input.tooltip.onFollow
915
- ? 'group-x'
916
- : sourceOnlyFocus(input.cursorGroup, input.chartId),
912
+ // Followers resolve the leader's group, so they draw its dots; `quietWhileFollowing` mutes the
913
+ // tooltip unless the chart opts into following tooltips.
914
+ focus: 'group-x',
917
915
  maxFocusDistance: Number.POSITIVE_INFINITY,
918
916
  cursor: cursorBinding({
919
917
  group: input.cursorGroup,
@@ -15,12 +15,9 @@
15
15
  */
16
16
  import { createChartCursor, cursorHost } from '@tanstack/charts/cursor'
17
17
  import type { ChartCursorController } from '@tanstack/charts/cursor'
18
- import { resolveChartFocusStrategy } from '@tanstack/charts/cursor/host'
19
- import type {
20
- ChartCursorBinding,
21
- ChartFocusStrategy,
22
- ChartValue,
23
- } from '@tanstack/charts/types/core'
18
+ import { tooltip } from '@tanstack/charts/tooltip'
19
+ import type { ChartTooltipExtension } from '@tanstack/charts/tooltip'
20
+ import type { ChartCursorBinding, ChartValue } from '@tanstack/charts/types/core'
24
21
  import type { ChartX, CursorResolution } from './types'
25
22
 
26
23
  type CursorState = ReturnType<ChartCursorController['getState']>
@@ -244,20 +241,73 @@ export function chartCursorView(
244
241
  }
245
242
 
246
243
  /**
247
- * Source-only tooltips. A 1.1.0 host shows a tooltip (and its `role="status"` live region) exactly
248
- * when it resolves a focus point, and it resolves a shared cursor's point through the definition's
249
- * focus strategy. Wrapping `group-x` so it groups nothing while a FOREIGN state is current leaves a
250
- * follower with the crosshair (painted from the cursor presentation, not from focus) and nothing
251
- * else.
244
+ * The extra key a chart puts on its tooltip options to name itself to {@link quietWhileFollowing}.
245
+ * Absent, the tooltip paints for followers too.
252
246
  */
253
- export function sourceOnlyFocus(group: string | undefined, chartId: string): ChartFocusStrategy {
254
- const base = resolveChartFocusStrategy<unknown, ChartValue, ChartValue>('group-x')
255
- if (!base) throw new Error('[basalt] charts: the group-x focus strategy is missing')
256
- return {
257
- resolve: (points, context) => base.resolve(points, context),
258
- navigation: (points) => base.navigation(points),
259
- group: (points, context) => (isForeign(group, chartId) ? [] : base.group(points, context)),
260
- }
247
+ export type TooltipFollowerOptions = {
248
+ readonly follower?: { readonly group: string | undefined; readonly chartId: string } | undefined
249
+ }
250
+
251
+ const isFollowerOptions = (options: unknown): options is TooltipFollowerOptions => {
252
+ if (typeof options !== 'object' || options === null || !('follower' in options)) return false
253
+ const { follower } = options
254
+ return (
255
+ follower === undefined ||
256
+ (typeof follower === 'object' &&
257
+ follower !== null &&
258
+ 'group' in follower &&
259
+ 'chartId' in follower &&
260
+ typeof follower.chartId === 'string')
261
+ )
262
+ }
263
+
264
+ /**
265
+ * The tooltip options a chart spreads next to `use: quietWhileFollowing`: its identity, unless the
266
+ * chart opted into following tooltips (`tooltip.onFollow`). The one place `onFollow` is read for
267
+ * this, shared by `compileCartesian` and the panel rung.
268
+ */
269
+ export function followerOptions(
270
+ tooltip: { onFollow?: boolean | undefined } | false | null | undefined,
271
+ group: string | undefined,
272
+ chartId: string,
273
+ ): TooltipFollowerOptions {
274
+ const onFollow = typeof tooltip === 'object' && tooltip !== null && tooltip.onFollow === true
275
+ return onFollow ? {} : ({ follower: { group, chartId } } satisfies TooltipFollowerOptions)
276
+ }
277
+
278
+ /**
279
+ * The engine's DOM tooltip host, silent while this chart FOLLOWS another's cursor. A follower
280
+ * resolves the leader's focus group (so the engine draws the same dots at the shared x); the host
281
+ * would then paint a tooltip and fill its `role="status"` live region. Whenever `isForeign` holds,
282
+ * this wrapper calls the host's `hide()` instead of `paint()`: a follower that has never led never
283
+ * creates the element, and one that has led keeps it in the DOM, hidden. Otherwise (leader, no
284
+ * `follower` option, or after the leader clears) it defers to the host.
285
+ *
286
+ * The chart's identity arrives only through `update` (the engine calls it before every `paint`);
287
+ * a `paint` before the first `update` has nothing to tell it who is leading, so it hides.
288
+ *
289
+ * It wraps `create`/`update`/`paint` of the engine's tooltip host, whose lifecycle is undocumented:
290
+ * re-check this wrapper, the live region included, on every `@tanstack/charts` upgrade.
291
+ */
292
+ export const quietWhileFollowing: ChartTooltipExtension = {
293
+ ...tooltip,
294
+ create: (context) => {
295
+ const host = tooltip.create(context)
296
+ let configured = false
297
+ let follower: TooltipFollowerOptions['follower']
298
+ return {
299
+ ...host,
300
+ update: (options) => {
301
+ configured = true
302
+ follower = isFollowerOptions(options) ? options.follower : undefined
303
+ host.update(options)
304
+ },
305
+ paint: (paint) => {
306
+ if (!configured || (follower && isForeign(follower.group, follower.chartId))) host.hide()
307
+ else host.paint(paint)
308
+ },
309
+ }
310
+ },
261
311
  }
262
312
 
263
313
  export function cursorBinding(opts: {
@@ -11,9 +11,10 @@ import type { ChartSeries } from './types'
11
11
 
12
12
  /**
13
13
  * `auto` renders both swatches and lets the container decide: none, dots or chips (CSS). The
14
- * swatch SHAPE follows the mode, signed split included: below 480px a dot (8px circle), from 480px
15
- * a chip (10px square) — so one `DualPanel` bar legend is a split circle on a narrow card and a
16
- * split square on a wide one. By design (friction row 58), not a per-chart prop.
14
+ * swatch SHAPE follows the mode for a filled mark, signed split included: below 480px a dot (8px
15
+ * circle), from 480px a chip (10px square) — so one `DualPanel` bar legend is a split circle on a
16
+ * narrow card and a split square on a wide one. A LINE series swaps a short stroke for a shorter
17
+ * one instead, dash included, so it is never a dot. Not a per-chart prop.
17
18
  */
18
19
  export type LegendMode = 'dots' | 'chips' | 'auto'
19
20
 
@@ -105,6 +106,41 @@ type SwatchStyle = Pick<
105
106
  const swatchFill = (s: SwatchStyle): string =>
106
107
  s.colorNegative ? `linear-gradient(90deg, ${s.color} 50%, ${s.colorNegative} 50%)` : s.color
107
108
 
109
+ /**
110
+ * A line series' key: a short stroke with its dash, compact below 480px and wide from 480px. A
111
+ * dashed swatch has BUTT caps: a round cap grows each dash by half the stroke width per end and
112
+ * would close the gap.
113
+ */
114
+ export const LINE_SWATCH = {
115
+ compact: { width: 8, dash: '2.5 2' },
116
+ wide: { width: 12, dash: '4 3' },
117
+ } as const
118
+
119
+ function LineSwatch({ s, compact }: { s: SwatchStyle; compact: boolean }): ReactElement {
120
+ const { width, dash } = compact ? LINE_SWATCH.compact : LINE_SWATCH.wide
121
+ return (
122
+ <svg
123
+ aria-hidden
124
+ className={compact ? classes.dot : classes.chip}
125
+ width={width}
126
+ height={8}
127
+ style={{ flex: 'none' }}
128
+ >
129
+ <line
130
+ x1={1}
131
+ x2={width - 1}
132
+ y1={4}
133
+ y2={4}
134
+ stroke={s.color}
135
+ strokeWidth={2}
136
+ strokeLinecap={s.dash === 'dashed' ? 'butt' : 'round'}
137
+ strokeOpacity={s.strokeOpacity ?? 1}
138
+ {...(s.dash === 'dashed' && { strokeDasharray: dash })}
139
+ />
140
+ </svg>
141
+ )
142
+ }
143
+
108
144
  function Swatch({ s, mode }: { s: SwatchStyle; mode: LegendMode }): ReactElement {
109
145
  if (mode === 'auto')
110
146
  return (
@@ -113,6 +149,7 @@ function Swatch({ s, mode }: { s: SwatchStyle; mode: LegendMode }): ReactElement
113
149
  <Swatch s={s} mode="chips" />
114
150
  </>
115
151
  )
152
+ if ((s.mark ?? 'line') === 'line') return <LineSwatch s={s} compact={mode === 'dots'} />
116
153
  if (mode === 'dots')
117
154
  return (
118
155
  <span
@@ -129,22 +166,6 @@ function Swatch({ s, mode }: { s: SwatchStyle; mode: LegendMode }): ReactElement
129
166
  }}
130
167
  />
131
168
  )
132
- if ((s.mark ?? 'line') === 'line')
133
- return (
134
- <svg aria-hidden className={classes.chip} width={16} height={8} style={{ flex: 'none' }}>
135
- <line
136
- x1={1}
137
- x2={15}
138
- y1={4}
139
- y2={4}
140
- stroke={s.color}
141
- strokeWidth={2}
142
- strokeLinecap="round"
143
- strokeOpacity={s.strokeOpacity ?? 1}
144
- {...(s.dash === 'dashed' && { strokeDasharray: '4 3' })}
145
- />
146
- </svg>
147
- )
148
169
  return (
149
170
  <span
150
171
  aria-hidden
@@ -156,38 +156,37 @@ export function cursorDots<T, X extends ChartX>(
156
156
  rows: readonly PlotRow<T, X>[],
157
157
  yScale: 'y2' | undefined,
158
158
  ): ChartMarks {
159
- // `dot.fill` is constant, so a series with `getMarker` gets one mark per distinct datum colour.
160
- const byColor = new Map<string, PlotRow<T, X>[]>([[s.color, []]])
161
- for (const row of rows) {
162
- const color = s.getMarker?.(row.datum)?.color ?? s.color
163
- const group = byColor.get(color)
164
- if (group) group.push(row)
165
- else byColor.set(color, [row])
159
+ const { getMarker } = s
160
+ // `dot.fill` is constant but a state style's is not: one mark whose focused fill is the datum's
161
+ // own `getMarker` colour, resolved once per row here rather than on every focus repaint. The map
162
+ // is keyed by the row OBJECT: the engine hands the same objects back as the state context's datum.
163
+ const colors = getMarker
164
+ ? new Map(rows.map((r) => [r, getMarker(r.datum)?.color ?? s.color]))
165
+ : undefined
166
+ const focused = {
167
+ fillOpacity: 1,
168
+ strokeOpacity: 1,
169
+ ...(colors && {
170
+ fill: ({ datum }: { datum: PlotRow<T, X> }): string => colors.get(datum) ?? s.color,
171
+ }),
166
172
  }
167
- return [...byColor].flatMap(([color, group]) =>
168
- // The series colour keeps `<key>-cursor` even when no datum uses it; others are keyed by colour.
169
- group.length === 0 && color !== s.color
170
- ? []
171
- : [
172
- dot(group, {
173
- id: color === s.color ? `${s.key}-cursor` : `${s.key}-cursor-${colorSlug(color)}`,
174
- x: rowX,
175
- y: 'y',
176
- r: VX.dotR,
177
- fill: color,
178
- fillOpacity: 0,
179
- stroke: VX.surface.panel,
180
- strokeWidth: 1.5,
181
- strokeOpacity: 0,
182
- states: [{ when: { focus: 'x' }, style: { fillOpacity: 1, strokeOpacity: 1 } }],
183
- ...(yScale !== undefined && { yScale }),
184
- }),
185
- ],
186
- )
173
+ return [
174
+ dot(rows, {
175
+ id: `${s.key}-cursor`,
176
+ x: rowX,
177
+ y: 'y',
178
+ r: VX.dotR,
179
+ fill: s.color,
180
+ fillOpacity: 0,
181
+ stroke: VX.surface.panel,
182
+ strokeWidth: 1.5,
183
+ strokeOpacity: 0,
184
+ states: [{ when: { focus: 'x' }, style: focused }],
185
+ ...(yScale !== undefined && { yScale }),
186
+ }),
187
+ ]
187
188
  }
188
189
 
189
- const colorSlug = (color: string): string => color.replaceAll(/[^\w-]+/g, '_')
190
-
191
190
  /**
192
191
  * A single-series `barY`. The engine stacks every `barY` that has no explicit extent, and a row with
193
192
  * no `z`/`color` channel is its own series: an N-by-N matrix (a 5k-row `DualPanel` took 10 s). So
@@ -6,7 +6,6 @@
6
6
  * `state`, cursor binding, tooltip surface, guides — is the rung's or lives here once.
7
7
  */
8
8
  import { crosshair } from '@tanstack/charts/crosshair'
9
- import { tooltip as tooltipHost } from '@tanstack/charts/tooltip'
10
9
  import { portal } from '@tanstack/charts/tooltip/portal'
11
10
  import type {
12
11
  ChartBuildContext,
@@ -23,7 +22,7 @@ import { ChartShell } from './CartesianChart'
23
22
  import type { ChartShellProps, ShellContext } from './CartesianChart'
24
23
  import { defaultFormatX, engineRow, utcHeaderDate, visibleSeries, xGuide, yGuide } from './compile'
25
24
  import type { CartesianDefinition } from './compile'
26
- import { cursorBinding, sourceOnlyFocus } from './cursor'
25
+ import { cursorBinding, followerOptions, quietWhileFollowing } from './cursor'
27
26
  import { plotAccess } from './plot-context'
28
27
  import type { PlotAccess } from './plot-context'
29
28
  import type { XScaleModel } from './scales'
@@ -210,7 +209,7 @@ function panelDefinition<T, X extends ChartX>(
210
209
  }
211
210
  const definition: CartesianDefinition = {
212
211
  chart: () => composed,
213
- focus: tooltip?.onFollow ? 'group-x' : sourceOnlyFocus(cursorGroup, chartId),
212
+ focus: 'group-x',
214
213
  maxFocusDistance: Number.POSITIVE_INFINITY,
215
214
  cursor: cursorBinding({
216
215
  group: cursorGroup,
@@ -223,7 +222,8 @@ function panelDefinition<T, X extends ChartX>(
223
222
  props.tooltip === false
224
223
  ? false
225
224
  : {
226
- use: tooltipHost,
225
+ use: quietWhileFollowing,
226
+ ...followerOptions(tooltip, cursorGroup, chartId),
227
227
  portal,
228
228
  anchor: 'group-center',
229
229
  content: (points: readonly ChartPoint[]) => {
@@ -70,8 +70,9 @@ export type ChartSeries<T> = {
70
70
  /** A marker at a point (a PR star, a status dot); `null` for none. Always-on markers are `Lines`'
71
71
  * alone. On a `CartesianChart` with consumer `marks` only the CURSOR dot of a `cursorValue`
72
72
  * series reads `getMarker` (its `color`): without `cursorValue` it is ignored there, so draw a
73
- * persistent dot in `marks` yourself. Each distinct color is one extra mark: keep colors a small
74
- * categorical set (statuses, buckets), never a continuous scale. */
73
+ * persistent dot in `marks` yourself. Each distinct color of an always-on marker is one extra mark:
74
+ * keep those a small categorical set (statuses, buckets), never a continuous scale. Only the
75
+ * `cursorValue` cursor dot is ONE mark whatever its colors. */
75
76
  getMarker?:
76
77
  | ((d: T) => {
77
78
  color?: string | undefined
@@ -121,6 +121,11 @@ export type NavItemId<G> = Extract<keyof NavIndex<G>, string>
121
121
  export type NavGroupId<G> = G extends ReadonlyArray<{ id: infer I }> ? I : never
122
122
  export type NavTabId<G> = NavItemId<G> | NavGroupId<G>
123
123
 
124
+ /**
125
+ * The resolved definition `defineNav` returns. Call `defineNav` at module scope: the shell caches
126
+ * each destination's anchor per config object, so one built inside a component remounts the links
127
+ * on every render.
128
+ */
124
129
  export type NavConfig<
125
130
  G extends ReadonlyArray<AnyNavGroup>,
126
131
  T extends ReadonlyArray<NavTabId<G>>,