basalt-ui 2.24.0 → 2.26.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 (90) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/MIGRATING.md +191 -19
  3. package/configs/oxlint-basalt.json +1 -1
  4. package/configs/oxlint-plugin.js +3 -9
  5. package/configs/oxlint-plugin.test.ts +6 -0
  6. package/dist/charts/Bars.d.ts.map +1 -1
  7. package/dist/charts/Bars.js +4 -1
  8. package/dist/charts/CartesianChart.d.ts +2 -0
  9. package/dist/charts/CartesianChart.d.ts.map +1 -1
  10. package/dist/charts/ChartCard.d.ts +11 -5
  11. package/dist/charts/ChartCard.d.ts.map +1 -1
  12. package/dist/charts/ChartCard.js +11 -3
  13. package/dist/charts/Sparkline.d.ts.map +1 -1
  14. package/dist/charts/Sparkline.js +65 -7
  15. package/dist/charts/chart-box.module.css +50 -7
  16. package/dist/charts/chart-box.module.css.d.ts +2 -0
  17. package/dist/charts/chart-card.module.css +34 -0
  18. package/dist/charts/chart-card.module.css.d.ts +2 -0
  19. package/dist/charts/chart-legend.module.css +5 -6
  20. package/dist/charts/compile.d.ts +2 -0
  21. package/dist/charts/compile.d.ts.map +1 -1
  22. package/dist/charts/compile.js +45 -1
  23. package/dist/charts/legend.d.ts.map +1 -1
  24. package/dist/charts/legend.js +42 -9
  25. package/dist/charts/sparkline.module.css +13 -9
  26. package/dist/charts/state.d.ts +3 -1
  27. package/dist/charts/state.d.ts.map +1 -1
  28. package/dist/charts/state.js +15 -2
  29. package/dist/cli/shot/detect.d.ts.map +1 -1
  30. package/dist/cli/shot/detect.js +25 -36
  31. package/dist/dashboard/bar-list.d.ts.map +1 -1
  32. package/dist/dashboard/bar-list.js +16 -2
  33. package/dist/dashboard/bar-list.module.css +7 -2
  34. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  35. package/dist/dashboard/meter-model.d.ts +2 -0
  36. package/dist/dashboard/meter-model.d.ts.map +1 -1
  37. package/dist/dashboard/meter-model.js +99 -7
  38. package/dist/dashboard/meter-parts.d.ts +4 -7
  39. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  40. package/dist/dashboard/meter-parts.js +102 -78
  41. package/dist/dashboard/meter.d.ts +1 -1
  42. package/dist/dashboard/meter.d.ts.map +1 -1
  43. package/dist/dashboard/meter.js +10 -7
  44. package/dist/dashboard/meter.module.css +43 -12
  45. package/dist/dashboard/meter.module.css.d.ts +1 -2
  46. package/dist/dashboard/section.d.ts +1 -2
  47. package/dist/dashboard/section.d.ts.map +1 -1
  48. package/dist/dashboard/section.module.css +8 -7
  49. package/dist/dashboard/stat-card.module.css +19 -2
  50. package/dist/dashboard/stat-strip.d.ts +9 -1
  51. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  52. package/dist/dashboard/stat-strip.js +32 -6
  53. package/dist/dashboard/stat-strip.module.css +40 -1
  54. package/dist/dashboard/stat-strip.module.css.d.ts +3 -0
  55. package/dist/dashboard/visual-slot.d.ts +4 -0
  56. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  57. package/dist/dashboard/visual-slot.js +2 -0
  58. package/dist/dashboard/widget-header.module.css +9 -0
  59. package/llms.txt +3 -3
  60. package/package.json +1 -1
  61. package/src/charts/Bars.tsx +7 -2
  62. package/src/charts/CartesianChart.tsx +2 -0
  63. package/src/charts/ChartCard.tsx +30 -7
  64. package/src/charts/Sparkline.tsx +105 -10
  65. package/src/charts/chart-box.module.css +50 -7
  66. package/src/charts/chart-box.module.css.d.ts +2 -0
  67. package/src/charts/chart-card.module.css +34 -0
  68. package/src/charts/chart-card.module.css.d.ts +2 -0
  69. package/src/charts/chart-legend.module.css +5 -6
  70. package/src/charts/compile.ts +60 -1
  71. package/src/charts/legend.tsx +64 -16
  72. package/src/charts/sparkline.module.css +13 -9
  73. package/src/charts/state.tsx +33 -7
  74. package/src/cli/shot/detect.ts +26 -40
  75. package/src/dashboard/bar-list.module.css +7 -2
  76. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  77. package/src/dashboard/bar-list.tsx +14 -2
  78. package/src/dashboard/meter-model.ts +147 -12
  79. package/src/dashboard/meter-parts.tsx +71 -50
  80. package/src/dashboard/meter.module.css +43 -12
  81. package/src/dashboard/meter.module.css.d.ts +1 -2
  82. package/src/dashboard/meter.tsx +22 -9
  83. package/src/dashboard/section.module.css +8 -7
  84. package/src/dashboard/section.tsx +1 -2
  85. package/src/dashboard/stat-card.module.css +19 -2
  86. package/src/dashboard/stat-strip.module.css +40 -1
  87. package/src/dashboard/stat-strip.module.css.d.ts +3 -0
  88. package/src/dashboard/stat-strip.tsx +49 -8
  89. package/src/dashboard/visual-slot.ts +5 -0
  90. package/src/dashboard/widget-header.module.css +9 -0
@@ -15,7 +15,7 @@
15
15
  * | craft-1/scale-error, -missing| layout | P1 |
16
16
  * | craft-1/off-scale-inset, -gap| layout | P1; P3 when every off value is within 1 px of a step |
17
17
  * | craft-3/empty-region | layout | P1 |
18
- * | craft-1/off-scale-radius | style | P1; P3 when every off value is within 1 px of a step |
18
+ * | craft-1/off-scale-radius | style | P1; P3 within 1 px of a step (never a nested one) |
19
19
  * | craft-1/nested-radius-step | style | P1 |
20
20
  * | craft-2/font-sizes | style | P1 |
21
21
  * | lint/basalt/<rule> | style | P1 for an error, P2 for a warning |
@@ -121,48 +121,34 @@ function craftOne(a: AnchorMetrics, scale: Scale | undefined): Draft[] {
121
121
  if (!scale) return []
122
122
  const base = { anchor: a.name, route: a.route, where: where(a) }
123
123
  const out: Draft[] = []
124
- const spacing = Object.values(scale.spacing)
125
- const radii = Object.values(scale.radius)
126
-
127
- const inset = SIDE_NAMES.map((side) => ({ side, v: a.padding[side] })).flatMap(({ side, v }) => {
128
- const d = offScale(v, spacing)
129
- return d === null ? [] : [{ side, v, d }]
130
- })
131
- if (inset.length > 0) {
132
- out.push({
133
- ...base,
134
- rule: 'craft-1/off-scale-inset',
135
- severity: sizing(inset.map((i) => i.d)),
136
- layer: 'layout',
137
- cite: `metrics.json anchors[${a.name} ${where(a)}].padding`,
138
- defect: `Padding ${inset.map((i) => `${i.side} ${i.v}px`).join(', ')} is not a spacing step (${stepsText(scale.spacing)}).`,
124
+ const sides = SIDE_NAMES.map((side) => ({ at: side, v: a.padding[side], nested: false }))
125
+ const gaps = (['row', 'column'] as const).map((axis) => ({
126
+ at: axis,
127
+ v: a.gap[axis],
128
+ nested: false,
129
+ }))
130
+ const radii = [
131
+ { at: '', v: a.radius, nested: false },
132
+ ...a.nested.map((n) => ({ at: `nested ${n.path}`, v: n.radius, nested: true })),
133
+ ]
134
+ const groups = [
135
+ ['inset', 'layout', 'Padding', 'padding', scale.spacing, sides],
136
+ ['gap', 'layout', 'Gap', 'gap', scale.spacing, gaps],
137
+ ['radius', 'style', 'Radius', 'radius', scale.radius, radii],
138
+ ] as const
139
+ for (const [rule, layer, label, field, steps, items] of groups) {
140
+ const off = items.flatMap(({ at, v, nested }) => {
141
+ const d = offScale(v, Object.values(steps))
142
+ return d === null ? [] : [{ at, v, d, nested }]
139
143
  })
140
- }
141
-
142
- const gap = (['row', 'column'] as const).flatMap((axis) => {
143
- const d = offScale(a.gap[axis], spacing)
144
- return d === null ? [] : [{ axis, v: a.gap[axis], d }]
145
- })
146
- if (gap.length > 0) {
144
+ if (off.length === 0) continue
147
145
  out.push({
148
146
  ...base,
149
- rule: 'craft-1/off-scale-gap',
150
- severity: sizing(gap.map((g) => g.d)),
151
- layer: 'layout',
152
- cite: `metrics.json anchors[${a.name} ${where(a)}].gap`,
153
- defect: `Gap ${gap.map((g) => `${g.axis} ${g.v}px`).join(', ')} is not a spacing step (${stepsText(scale.spacing)}).`,
154
- })
155
- }
156
-
157
- const radius = offScale(a.radius, radii)
158
- if (radius !== null) {
159
- out.push({
160
- ...base,
161
- rule: 'craft-1/off-scale-radius',
162
- severity: sizing([radius]),
163
- layer: 'style',
164
- cite: `metrics.json anchors[${a.name} ${where(a)}].radius`,
165
- defect: `Radius ${String(a.radius)}px is not a radius step (${stepsText(scale.radius)}).`,
147
+ rule: `craft-1/off-scale-${rule}`,
148
+ severity: off.some((o) => o.nested) ? 'P1' : sizing(off.map((o) => o.d)),
149
+ layer,
150
+ cite: `metrics.json anchors[${a.name} ${where(a)}].${field}`,
151
+ defect: `${label} ${off.map((o) => `${o.at} ${o.v}px`.trim()).join(', ')} is not a ${steps === scale.radius ? 'radius' : 'spacing'} step (${stepsText(steps)}).`,
166
152
  })
167
153
  }
168
154
  return out
@@ -100,9 +100,14 @@
100
100
  color: var(--vx-muted);
101
101
  }
102
102
 
103
+ /* A real row with a skeleton laid over it: the row sets the height, the skeleton paints it. */
103
104
  .skeletonRow {
104
- grid-column: 1 / -1;
105
- height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
105
+ position: relative;
106
+ }
107
+
108
+ .skeletonFill {
109
+ position: absolute;
110
+ inset: 0;
106
111
  }
107
112
 
108
113
  /* A row's threshold: a hairline across the bar at a position on the row's own scale. */
@@ -15,5 +15,6 @@ declare const classes: {
15
15
  readonly secondary: string
16
16
  readonly empty: string
17
17
  readonly skeletonRow: string
18
+ readonly skeletonFill: string
18
19
  }
19
20
  export default classes
@@ -132,12 +132,24 @@ export function BarList({
132
132
  style,
133
133
  }: BarListProps) {
134
134
  if (loading) {
135
+ // Each row is a real, empty row with a skeleton laid over it, so the list takes the height of
136
+ // the rows it will become in every layout instead of a fixed guess.
135
137
  return (
136
138
  <div className={cx(classes.frame, className)} style={style}>
137
- <div className={classes.root} aria-busy="true">
139
+ <div className={classes.root} aria-busy="true" data-variant={variant}>
138
140
  <VisuallyHidden>{`Loading ${label}`}</VisuallyHidden>
139
141
  {Array.from({ length: loadingRows }, (_, i) => (
140
- <Skeleton key={i} className={classes.skeletonRow} data-bar-skeleton />
142
+ <div
143
+ key={i}
144
+ className={cx(classes.row, classes.skeletonRow)}
145
+ data-bar-skeleton
146
+ aria-hidden
147
+ >
148
+ <span className={classes.label}>{'\u00a0'}</span>
149
+ <span className={classes.value} />
150
+ <span className={classes.track} />
151
+ <Skeleton className={classes.skeletonFill} />
152
+ </div>
141
153
  ))}
142
154
  </div>
143
155
  </div>
@@ -277,18 +277,32 @@ export function placeRowLabels(
277
277
  labels: readonly RowLabel[],
278
278
  rowWidth: number,
279
279
  gap = 0,
280
+ ): RowPlacement {
281
+ const first = placeOnce(labels, rowWidth, gap, false)
282
+ // One register: once any name falls back to its `short`, every other name that has one follows
283
+ // (the holding name, which never shortens, is the one exception). The row is placed again with
284
+ // those names in their `short` box, so every shift is computed against the box that renders.
285
+ return first.short.some(Boolean) ? placeOnce(labels, rowWidth, gap, true) : first
286
+ }
287
+
288
+ function placeOnce(
289
+ labels: readonly RowLabel[],
290
+ rowWidth: number,
291
+ gap: number,
292
+ registerShort: boolean,
280
293
  ): RowPlacement {
281
294
  const shown = labels.map(() => false)
282
295
  const short = labels.map(() => false)
283
296
  const shift = labels.map(() => 0)
284
- const kept: { box: LabelBox; tick: boolean }[] = []
297
+ const kept: { box: LabelBox; tick: boolean; i: number }[] = []
285
298
  const rank = (l: RowLabel) => (l.holding ? 0 : l.span ? 3 : l.end ? 2 : 1)
286
299
  const order = labels
287
300
  .map((_, i) => i)
288
301
  .toSorted((a, b) => rank(labels[a] as RowLabel) - rank(labels[b] as RowLabel))
289
302
  // The gap step applies when either label of a pair is a tick; zone names keep to "not touching".
290
- const clears = (b: LabelBox, tick: boolean) =>
291
- !kept.some(({ box: k, tick: kTick }) => {
303
+ const clears = (b: LabelBox, tick: boolean, self = -1) =>
304
+ !kept.some(({ box: k, tick: kTick, i: ki }) => {
305
+ if (ki === self) return false
292
306
  const pad = tick || kTick ? gap : 0
293
307
  return b.left < k.right + pad - LABEL_SUBPIXEL && k.left < b.right + pad - LABEL_SUBPIXEL
294
308
  })
@@ -304,7 +318,7 @@ export function placeRowLabels(
304
318
  box = { left, right: left + width }
305
319
  if (!clears(box, false)) continue
306
320
  shown[i] = true
307
- kept.push({ box, tick: false })
321
+ kept.push({ box, tick: false, i })
308
322
  continue
309
323
  }
310
324
  const fits = (b: LabelBox) =>
@@ -313,19 +327,132 @@ export function placeRowLabels(
313
327
  (span === undefined ||
314
328
  (b.left >= span.left - LABEL_SUBPIXEL && b.right <= span.right + LABEL_SUBPIXEL)) &&
315
329
  clears(b, tick)
316
- const useShort = !fits(box) && label.short !== undefined && fits(label.short)
330
+ const useShort =
331
+ label.short !== undefined && (registerShort ? true : !fits(box)) && fits(label.short)
332
+ if (registerShort && label.short !== undefined && !useShort) continue
317
333
  if (useShort) box = label.short as LabelBox
318
334
  else if (!fits(box)) continue
319
335
  shown[i] = true
320
336
  short[i] = useShort
321
- kept.push({ box, tick })
337
+ kept.push({ box, tick, i })
322
338
  }
323
- // One register: once any name falls back to its `short`, every other shown name that has one
324
- // follows (the holding name, which never shortens, is the one exception). A shorter box only
325
- // clears more, so the placement above stays valid.
326
- if (short.some(Boolean)) {
327
- for (const [i, label] of labels.entries()) {
328
- if (shown[i] && !label.holding && label.short !== undefined) short[i] = true
339
+ // A name that did not fit inside its own span borrows room from the row: the zone names beside it
340
+ // slide inside THEIR spans, away from it, and it takes the gap, staying centred in its span. Full
341
+ // name first, then `short`; holding names and ticks never move.
342
+ for (const [i, label] of labels.entries()) {
343
+ if (label.span === undefined || label.holding || (shown[i] && !short[i])) continue
344
+ const { span } = label
345
+ const centre = (b: LabelBox) => (b.left + b.right) / 2
346
+ const others = kept.filter((k) => k.i !== i)
347
+ const movable = (k: (typeof kept)[number]) => !k.tick && !labels[k.i]?.holding
348
+ const fixed = others.filter((k) => !movable(k))
349
+ const slidable = others.filter(movable)
350
+ const base = registerShort && label.short ? label.short : label.box
351
+ const mid = centre(base)
352
+ // Only a name that sits in the row and clears every tick: a tick keeps its place over a name.
353
+ const touches = (a: LabelBox, b: LabelBox) =>
354
+ a.left < b.right + gap - LABEL_SUBPIXEL && b.left < a.right + gap - LABEL_SUBPIXEL
355
+ if (
356
+ base.left < -LABEL_SUBPIXEL ||
357
+ base.right > rowWidth + LABEL_SUBPIXEL ||
358
+ others.some((k) => k.tick && touches(base, k.box)) ||
359
+ fixed.some((f) => f.box.left < mid && f.box.right > mid)
360
+ )
361
+ continue
362
+ const rightOf = slidable
363
+ .filter((k) => centre(k.box) > mid)
364
+ .toSorted((a, b) => b.box.left - a.box.left)
365
+ const leftOf = slidable
366
+ .filter((k) => centre(k.box) < mid)
367
+ .toSorted((a, b) => a.box.left - b.box.left)
368
+ const place = (b: LabelBox, lo: number, hi: number): LabelBox => {
369
+ const left = Math.max(lo, Math.min(b.left, hi - (b.right - b.left)))
370
+ return { left, right: left + (b.right - b.left) }
371
+ }
372
+ // Slide only the sides the name needs: none, then the right, the left, both.
373
+ const attempt = (right: boolean, left: boolean) => {
374
+ const slides = new Map<number, number>()
375
+ let hi = rowWidth
376
+ for (const k of rightOf) {
377
+ const w = k.box.right - k.box.left
378
+ const stop = right
379
+ ? Math.min(
380
+ (labels[k.i]?.span?.right ?? rowWidth) + LABEL_SUBPIXEL,
381
+ hi,
382
+ ...fixed
383
+ .filter((f) => f.box.left >= k.box.left)
384
+ .map((f) => f.box.left - (f.tick ? gap : 0)),
385
+ )
386
+ : k.box.left + w
387
+ const at = Math.max(k.box.left, stop - w)
388
+ slides.set(k.i, at - k.box.left)
389
+ hi = at
390
+ }
391
+ let lo = 0
392
+ for (const k of leftOf) {
393
+ const w = k.box.right - k.box.left
394
+ const stop = left
395
+ ? Math.max(
396
+ (labels[k.i]?.span?.left ?? 0) - LABEL_SUBPIXEL,
397
+ lo,
398
+ ...fixed
399
+ .filter((f) => f.box.right <= k.box.right)
400
+ .map((f) => f.box.right + (f.tick ? gap : 0)),
401
+ )
402
+ : k.box.left
403
+ const at = Math.min(k.box.left, stop)
404
+ slides.set(k.i, at - k.box.left)
405
+ lo = at + w
406
+ }
407
+ // The gap this name may take: after the nearest left neighbour and fixed label, before the right.
408
+ const gapLo = Math.max(
409
+ lo,
410
+ ...fixed.filter((f) => f.box.right <= mid).map((f) => f.box.right + (f.tick ? gap : 0)),
411
+ 0,
412
+ )
413
+ const gapHi = Math.min(
414
+ hi,
415
+ ...fixed.filter((f) => f.box.left >= mid).map((f) => f.box.left - (f.tick ? gap : 0)),
416
+ rowWidth,
417
+ )
418
+ return { slides, gapLo, gapHi }
419
+ }
420
+ const tries = [
421
+ attempt(false, false),
422
+ attempt(true, false),
423
+ attempt(false, true),
424
+ attempt(true, true),
425
+ ]
426
+ const names =
427
+ registerShort && label.short
428
+ ? [label.short]
429
+ : shown[i]
430
+ ? [label.box]
431
+ : label.short
432
+ ? [label.box, label.short]
433
+ : [label.box]
434
+ for (const box of names) {
435
+ const w = box.right - box.left
436
+ const fit = tries.find(({ gapLo, gapHi }) => {
437
+ if (gapHi - gapLo + LABEL_SUBPIXEL < w) return false
438
+ const c = centre(place(box, gapLo, gapHi))
439
+ return c >= span.left && c <= span.right
440
+ })
441
+ if (fit === undefined) continue
442
+ const placed = place(box, fit.gapLo, fit.gapHi)
443
+ for (const k of kept) {
444
+ const by = fit.slides.get(k.i) ?? 0
445
+ if (by === 0) continue
446
+ k.box = { left: k.box.left + by, right: k.box.right + by }
447
+ shift[k.i] = (shift[k.i] ?? 0) + by
448
+ }
449
+ const own = kept.findIndex((k) => k.i === i)
450
+ if (own >= 0) kept.splice(own, 1)
451
+ kept.push({ box: placed, tick: false, i })
452
+ shift[i] = placed.left - box.left
453
+ shown[i] = true
454
+ short[i] = box !== label.box
455
+ break
329
456
  }
330
457
  }
331
458
  return { shown, short, shift }
@@ -361,6 +488,8 @@ export type BarModel = {
361
488
  parts: readonly Part[]
362
489
  /** Percent where the first forecast part starts; absent when the forecast opens the track. */
363
490
  boundaryPct: number | undefined
491
+ /** Where the forecast part ends (clamped to the track): the forecast caption ends here. */
492
+ forecastEndPct: number | undefined
364
493
  forecastText: string | null
365
494
  captionMode: CaptionMode
366
495
  /** Only in `parts` mode: one caption per part, in order. Empty otherwise. */
@@ -463,6 +592,12 @@ export function modelBar(input: BarInput): BarModel {
463
592
  span,
464
593
  parts,
465
594
  boundaryPct: firstForecast > 0 ? toPct(parts[firstForecast]?.start ?? 0) : undefined,
595
+ forecastEndPct:
596
+ firstForecast > 0
597
+ ? toPct(
598
+ parts.filter((p) => p.forecast).reduce((end, p) => Math.max(end, p.start + p.size), 0),
599
+ )
600
+ : undefined,
466
601
  forecastText:
467
602
  forecastLabels.length === 0
468
603
  ? null
@@ -139,39 +139,12 @@ function Line({ zoned, children }: { zoned: boolean; children?: ReactNode }) {
139
139
  )
140
140
  }
141
141
 
142
- /**
143
- * The loaded Meter's footprint at its loaded height: a zoned track keeps the figure row above and the
144
- * zone-name row below, a plain bar the caption row below, so the card does not jump when data lands.
145
- */
146
- export function MeterLoading({
147
- label,
148
- ring,
149
- zoned,
150
- shell,
151
- }: {
152
- label: string
153
- ring: boolean
154
- zoned: boolean
155
- shell: Shell
156
- }) {
142
+ /** The ring's loading state: one skeleton disc at the ring's size. A bar loads through `MeterBar`. */
143
+ export function MeterRingLoading({ label, shell }: { label: string; shell: Shell }) {
157
144
  return (
158
145
  <div {...rootProps(shell)} aria-busy="true">
159
146
  <VisuallyHidden className={classes.summary}>{`Loading ${label}`}</VisuallyHidden>
160
- {ring ? (
161
- <Skeleton className={classes.skeletonRing} circle />
162
- ) : (
163
- <>
164
- {zoned && (
165
- <Line zoned={zoned}>
166
- <Skeleton className={classes.skeletonCaption} radius="sm" />
167
- </Line>
168
- )}
169
- <Skeleton className={classes.skeletonTrack} />
170
- <Line zoned={zoned}>
171
- <Skeleton className={classes.skeletonCaption} radius="sm" />
172
- </Line>
173
- </>
174
- )}
147
+ <Skeleton className={classes.skeletonRing} circle />
175
148
  </div>
176
149
  )
177
150
  }
@@ -499,6 +472,8 @@ type CaptionItem = {
499
472
  align?: 'start' | 'center' | 'end'
500
473
  /** Drop rank when the row is too narrow (lowest first); none never drops. */
501
474
  drop?: number
475
+ /** Tried when the primary anchor drops the caption; the caption drops only if this fails too. */
476
+ alt?: { pct: number; align?: 'start' | 'center' | 'end' }
502
477
  }
503
478
 
504
479
  /** The measurement shared by the marks row and the part list: natural widths, row width, gap step. */
@@ -583,13 +558,23 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
583
558
  ...(item.align !== undefined && { align: item.align }),
584
559
  ...(item.drop !== undefined && { drop: item.drop }),
585
560
  }))
586
- const next = placeCaptionRow(marks, rowWidth, gap)
561
+ let next = placeCaptionRow(marks, rowWidth, gap)
562
+ // A caption that dropped at its preferred anchor gets its fallback before it is given up.
563
+ items.forEach((item, i) => {
564
+ if (item.alt === undefined || !next?.dropped[i]) return
565
+ const retry = placeCaptionRow(
566
+ marks.map((m, j) => (j === i ? { ...m, ...item.alt } : m)),
567
+ rowWidth,
568
+ gap,
569
+ )
570
+ if (retry !== null && !retry.dropped[i]) next = retry
571
+ })
587
572
  setPlaced((prev) => (samePlacement(prev, next) ? prev : next))
588
573
  },
589
574
  items
590
575
  .map(
591
576
  (i) =>
592
- `${i.key}@${i.pct ?? i.edge ?? ''}${i.align ?? ''}${i.drop ?? ''}:${typeof i.node === 'string' ? i.node : ''}`,
577
+ `${i.key}@${i.pct ?? i.edge ?? ''}${i.align ?? ''}${i.drop ?? ''}${i.alt?.pct ?? ''}:${typeof i.node === 'string' ? i.node : ''}`,
593
578
  )
594
579
  .join('\u0000'),
595
580
  )
@@ -700,9 +685,12 @@ export function MeterBar(props: {
700
685
  startCaption: ReactNode
701
686
  endCaption: ReactNode
702
687
  readingAt: 'fill' | 'start' | undefined
688
+ /** The loaded structure with its text painted as skeleton: the footprint IS the loaded one. */
689
+ loading?: boolean
703
690
  shell: Shell
704
691
  }) {
705
692
  const { label, min, max, format, zones, shell } = props
693
+ const loading = props.loading === true
706
694
  const describedId = useId()
707
695
  const model = modelBar(props)
708
696
  const compact = shell.row
@@ -788,9 +776,20 @@ export function MeterBar(props: {
788
776
  key: 'forecast',
789
777
  node: glue(model.forecastText),
790
778
  drop: 2,
791
- // The reading ends at the boundary, the forecast begins there.
792
- ...(props.readingAt !== 'start' && start !== null && { align: 'start' as const }),
793
- ...(model.boundaryPct !== undefined && { pct: model.boundaryPct }),
779
+ // The reading ends at the boundary, the forecast ends where its fill does.
780
+ // If that collides, it falls back to starting at the boundary before it drops.
781
+ ...(props.readingAt !== 'start' && model.forecastEndPct !== undefined
782
+ ? {
783
+ pct: model.forecastEndPct,
784
+ align: 'end' as const,
785
+ ...(model.boundaryPct !== undefined && {
786
+ alt: {
787
+ pct: model.boundaryPct,
788
+ ...(start !== null && { align: 'start' as const }),
789
+ },
790
+ }),
791
+ }
792
+ : model.boundaryPct !== undefined && { pct: model.boundaryPct }),
794
793
  } satisfies CaptionItem,
795
794
  ]
796
795
  : []),
@@ -824,15 +823,32 @@ export function MeterBar(props: {
824
823
  ]
825
824
 
826
825
  const root = rootProps(shell)
826
+ // Loading is the loaded tree: every caption row stands where it will, its text is painted as
827
+ // skeleton (CSS) and hidden from assistive tech; the root announces the state once.
828
+ const quiet = (node: ReactNode) =>
829
+ loading ? (
830
+ <div className={classes.hold} aria-hidden>
831
+ {node}
832
+ </div>
833
+ ) : (
834
+ node
835
+ )
827
836
  return (
828
- <div {...root} className={root.className}>
837
+ <div
838
+ {...root}
839
+ className={root.className}
840
+ {...(loading && { 'aria-busy': 'true', 'data-meter-loading': '' })}
841
+ >
842
+ {loading && <VisuallyHidden className={classes.summary}>{`Loading ${label}`}</VisuallyHidden>}
829
843
  {aboveTicks.length > 0 && <LabelRow zones={[]} ticks={aboveTicks} />}
830
844
  <div
831
845
  className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
832
846
  data-meter-track-hidden={trackHidden ? '' : undefined}
833
- aria-label={label}
834
- {...ariaValues(props.reading, min, max, format)}
835
- {...describedBy}
847
+ {...(!loading && {
848
+ 'aria-label': label,
849
+ ...ariaValues(props.reading, min, max, format),
850
+ ...describedBy,
851
+ })}
836
852
  >
837
853
  <div
838
854
  className={classes.track}
@@ -845,6 +861,7 @@ export function MeterBar(props: {
845
861
  >
846
862
  {zones?.map(
847
863
  (z, i) =>
864
+ !loading &&
848
865
  model.markerPct !== undefined && (
849
866
  <div
850
867
  key={i}
@@ -857,7 +874,7 @@ export function MeterBar(props: {
857
874
  />
858
875
  ),
859
876
  )}
860
- {model.parts.map((p, i) => (
877
+ {(loading ? [] : model.parts).map((p, i) => (
861
878
  <div
862
879
  key={i}
863
880
  className={cx(classes.fill, p.forecast && classes.forecastFill)}
@@ -870,22 +887,26 @@ export function MeterBar(props: {
870
887
  />
871
888
  ))}
872
889
  </div>
873
- <Tick kind="marker" className={classes.marker} pct={model.markerPct} />
874
- <Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
875
- {model.ticks.map((t) => (
876
- <Tick key={t.key} kind="tick" className={classes.tick} pct={t.pct} />
877
- ))}
878
- <Tick kind="target" className={classes.tick} pct={model.targetPct} />
890
+ {!loading && (
891
+ <>
892
+ <Tick kind="marker" className={classes.marker} pct={model.markerPct} />
893
+ <Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
894
+ {model.ticks.map((t) => (
895
+ <Tick key={t.key} kind="tick" className={classes.tick} pct={t.pct} />
896
+ ))}
897
+ <Tick kind="target" className={classes.tick} pct={model.targetPct} />
898
+ </>
899
+ )}
879
900
  </div>
880
901
  {zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={belowTicks} />}
881
- {anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
882
- {model.describedByText !== null && (
902
+ {anchored && quiet(<ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>)}
903
+ {!loading && model.describedByText !== null && (
883
904
  <VisuallyHidden id={describedId} className={classes.summary}>
884
905
  {model.describedByText}
885
906
  </VisuallyHidden>
886
907
  )}
887
- {hasParts && <PartCaptions captions={model.partCaptions} />}
888
- {items.length > 0 && <CaptionRow items={items} />}
908
+ {hasParts && quiet(<PartCaptions captions={model.partCaptions} />)}
909
+ {items.length > 0 && quiet(<CaptionRow items={items} />)}
889
910
  </div>
890
911
  )
891
912
  }
@@ -312,8 +312,7 @@
312
312
  color: var(--vx-muted);
313
313
  }
314
314
 
315
- /* One caption-height line: a blank caption row (empty) or the home of a skeleton line (loading), so
316
- * both stand at the loaded Meter's height. */
315
+ /* One caption-height line: a blank caption row of an empty Meter, so it stands at the loaded height. */
317
316
  .line {
318
317
  display: flex;
319
318
  align-items: center;
@@ -325,14 +324,50 @@
325
324
  height: 1.25em;
326
325
  }
327
326
 
328
- /* The skeleton holds the loaded footprint: figure row (zoned), track, caption / zone-name row. */
329
- .skeletonTrack {
330
- height: 0.375rem;
327
+ /* Loading is the loaded tree (`MeterBar` with `loading`): every row stands where it will and the
328
+ * height is the loaded one. Text is painted as skeleton in place: transparent ink on a pulsing pill
329
+ * the width of the caption, the track a pulsing bar. A caption the layout dropped stays hidden. */
330
+ .hold {
331
+ display: contents;
332
+ }
333
+
334
+ [data-meter-loading] {
335
+ --basalt-meter-skeleton: color-mix(in srgb, var(--vx-muted) 28%, transparent);
336
+ }
337
+
338
+ [data-meter-loading]
339
+ :is(.rowLabel, .caption, .captionEnd, .captionTarget, .zoneReading, .partCaption) {
340
+ color: transparent;
341
+ background: var(--basalt-meter-skeleton);
342
+ border-radius: var(--vx-radius-fine);
343
+ animation: meterPulse 1500ms linear infinite;
344
+ }
345
+
346
+ [data-meter-loading] .swatch {
347
+ visibility: hidden;
331
348
  }
332
349
 
333
- .skeletonCaption {
334
- width: 40%;
335
- height: 0.75rem;
350
+ [data-meter-loading] .track {
351
+ background: var(--basalt-meter-skeleton);
352
+ animation: meterPulse 1500ms linear infinite;
353
+ }
354
+
355
+ @keyframes meterPulse {
356
+ 0%,
357
+ 100% {
358
+ opacity: 0.4;
359
+ }
360
+
361
+ 50% {
362
+ opacity: 1;
363
+ }
364
+ }
365
+
366
+ @media (prefers-reduced-motion: reduce) {
367
+ [data-meter-loading]
368
+ :is(.rowLabel, .caption, .captionEnd, .captionTarget, .zoneReading, .partCaption, .track) {
369
+ animation: none;
370
+ }
336
371
  }
337
372
 
338
373
  /* ── ring ────────────────────────────────────────────────────────────────────────────────────── */
@@ -406,10 +441,6 @@
406
441
  height: 1lh;
407
442
  }
408
443
 
409
- .row .skeletonTrack {
410
- height: 1lh;
411
- }
412
-
413
444
  .row .line {
414
445
  display: none;
415
446
  }
@@ -34,8 +34,7 @@ declare const classes: {
34
34
  readonly empty: string
35
35
  readonly line: string
36
36
  readonly lineZoned: string
37
- readonly skeletonTrack: string
38
- readonly skeletonCaption: string
37
+ readonly hold: string
39
38
  readonly ringBox: string
40
39
  readonly ring: string
41
40
  readonly ringTrack: string