basalt-ui 2.25.0 → 2.27.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 (81) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/MIGRATING.md +227 -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 +37 -1
  8. package/dist/charts/ChartCard.d.ts +13 -5
  9. package/dist/charts/ChartCard.d.ts.map +1 -1
  10. package/dist/charts/ChartCard.js +12 -2
  11. package/dist/charts/Sparkline.d.ts.map +1 -1
  12. package/dist/charts/Sparkline.js +106 -10
  13. package/dist/charts/chart-box.module.css +123 -5
  14. package/dist/charts/chart-box.module.css.d.ts +3 -0
  15. package/dist/charts/chart-card.module.css +34 -0
  16. package/dist/charts/chart-card.module.css.d.ts +2 -0
  17. package/dist/charts/chart-legend.module.css +1 -16
  18. package/dist/charts/compile.d.ts +20 -0
  19. package/dist/charts/compile.d.ts.map +1 -1
  20. package/dist/charts/compile.js +99 -3
  21. package/dist/charts/legend.d.ts.map +1 -1
  22. package/dist/charts/legend.js +54 -71
  23. package/dist/charts/sparkline.module.css +13 -9
  24. package/dist/charts/state.d.ts +7 -0
  25. package/dist/charts/state.d.ts.map +1 -1
  26. package/dist/charts/state.js +17 -1
  27. package/dist/cli/shot/capture.d.ts +32 -3
  28. package/dist/cli/shot/capture.d.ts.map +1 -1
  29. package/dist/cli/shot/capture.js +17 -7
  30. package/dist/dashboard/meter-model.d.ts +19 -3
  31. package/dist/dashboard/meter-model.d.ts.map +1 -1
  32. package/dist/dashboard/meter-model.js +155 -13
  33. package/dist/dashboard/meter-parts.d.ts +4 -7
  34. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  35. package/dist/dashboard/meter-parts.js +130 -90
  36. package/dist/dashboard/meter.d.ts +1 -1
  37. package/dist/dashboard/meter.d.ts.map +1 -1
  38. package/dist/dashboard/meter.js +10 -7
  39. package/dist/dashboard/meter.module.css +55 -13
  40. package/dist/dashboard/meter.module.css.d.ts +1 -2
  41. package/dist/dashboard/section.d.ts +1 -2
  42. package/dist/dashboard/section.d.ts.map +1 -1
  43. package/dist/dashboard/section.module.css +8 -7
  44. package/dist/dashboard/stat-card.module.css +17 -0
  45. package/dist/dashboard/stat-strip.d.ts +9 -1
  46. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  47. package/dist/dashboard/stat-strip.js +121 -27
  48. package/dist/dashboard/stat-strip.module.css +51 -3
  49. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  50. package/dist/dashboard/visual-slot.d.ts +4 -0
  51. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  52. package/dist/dashboard/visual-slot.js +2 -0
  53. package/dist/dashboard/widget-header.module.css +9 -0
  54. package/llms.txt +3 -2
  55. package/package.json +1 -1
  56. package/src/charts/Bars.tsx +50 -2
  57. package/src/charts/ChartCard.tsx +32 -5
  58. package/src/charts/Sparkline.tsx +166 -13
  59. package/src/charts/chart-box.module.css +123 -5
  60. package/src/charts/chart-box.module.css.d.ts +3 -0
  61. package/src/charts/chart-card.module.css +34 -0
  62. package/src/charts/chart-card.module.css.d.ts +2 -0
  63. package/src/charts/chart-legend.module.css +1 -16
  64. package/src/charts/compile.ts +153 -3
  65. package/src/charts/legend.tsx +33 -49
  66. package/src/charts/sparkline.module.css +13 -9
  67. package/src/charts/state.tsx +43 -1
  68. package/src/cli/shot/capture.ts +25 -9
  69. package/src/dashboard/meter-model.ts +248 -22
  70. package/src/dashboard/meter-parts.tsx +124 -69
  71. package/src/dashboard/meter.module.css +55 -13
  72. package/src/dashboard/meter.module.css.d.ts +1 -2
  73. package/src/dashboard/meter.tsx +22 -9
  74. package/src/dashboard/section.module.css +8 -7
  75. package/src/dashboard/section.tsx +1 -2
  76. package/src/dashboard/stat-card.module.css +17 -0
  77. package/src/dashboard/stat-strip.module.css +51 -3
  78. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  79. package/src/dashboard/stat-strip.tsx +162 -33
  80. package/src/dashboard/visual-slot.ts +5 -0
  81. package/src/dashboard/widget-header.module.css +9 -0
@@ -251,6 +251,11 @@ export type RowLabel = {
251
251
  holding?: boolean
252
252
  /** A tick at the track's start or end: it keeps its place over every zone name it would touch. */
253
253
  end?: boolean
254
+ /**
255
+ * The scale's own start figure (not a consumer tick): D38's caption order drops it before anything
256
+ * wraps, so it never takes the second row; it hides when the first row cannot hold it.
257
+ */
258
+ figure?: boolean
254
259
  short?: LabelBox
255
260
  }
256
261
 
@@ -261,6 +266,8 @@ export type RowPlacement = {
261
266
  short: boolean[]
262
267
  /** Pixels a shown label moves along the row's physical x axis to stay inside it (0 unless clamped). */
263
268
  shift: number[]
269
+ /** Index-aligned: the row a shown label stands on, 0 the first, 1 the second (staggered under it). */
270
+ row: (0 | 1)[]
264
271
  }
265
272
 
266
273
  /**
@@ -268,43 +275,141 @@ export type RowPlacement = {
268
275
  * is the reading's verdict, so it never hides for width: it may spill past its span, shifted inside
269
276
  * the row); the other ticks go next, then the end ticks (at the track's start or end: a scale's
270
277
  * figures); every other zone name then shows only when it lies inside the row and its own span and
271
- * clears every label already kept, trying its full name, then its `short` box, then hiding. An end
278
+ * clears every label already kept, trying its full name, then its `short` box, then hiding. A name
279
+ * that does not fit its span borrows room: its neighbours (the holding name too) slide away, each
280
+ * keeping its CENTRE inside its own span (it may overhang a span edge by up to half its width).
281
+ * Order per name: full on row one, full on row two, `short` on row one, `short` on row two, hidden;
282
+ * on an equal count of shown labels the full-name layout wins over the `short` one. An end
272
283
  * figure hides only when it cannot clear the holding name, an interior tick or the other end. A tick
273
- * keeps at least `gap` px (one gap step of the host's spacing) from every other label; zone names
274
- * among themselves only must not touch. A hidden name is still named in the described-by text.
284
+ * keeps at least `gap` px (one gap step of the host's spacing) from every other label, and so does
285
+ * a zone name from its neighbour. No zone name and no tick label is lost for width: one that cannot
286
+ * hold its place on the first row stands on a second row directly under it (centred on its span or
287
+ * mark, clamped inside the row, keeping the same gap), and only hides when neither row can hold it.
288
+ * A hidden label is still named in the described-by text.
275
289
  */
276
290
  export function placeRowLabels(
277
291
  labels: readonly RowLabel[],
278
292
  rowWidth: number,
279
293
  gap = 0,
280
294
  ): RowPlacement {
295
+ // A name's order: full on row one (borrowing included), full on row two, then its `short` on row
296
+ // one, `short` on row two, then hidden. So the full names are tried alone first and the `short`
297
+ // fallback only runs when some label would otherwise be lost.
298
+ const full = layOut(
299
+ labels.map(({ short: _short, ...l }) => l),
300
+ rowWidth,
301
+ gap,
302
+ )
303
+ if (full.shown.every(Boolean) || labels.every((l) => l.short === undefined)) return full
304
+ const withShort = layOut(labels, rowWidth, gap)
305
+ return withShort.shown.filter(Boolean).length > full.shown.filter(Boolean).length
306
+ ? withShort
307
+ : full
308
+ }
309
+
310
+ function layOut(labels: readonly RowLabel[], rowWidth: number, gap: number): RowPlacement {
311
+ const first = placeOnce(labels, rowWidth, gap, false)
312
+ // One register: once any name falls back to its `short`, every other name that has one follows
313
+ // (the holding name, which never shortens, is the one exception). The row is placed again with
314
+ // those names in their `short` box, so every shift is computed against the box that renders.
315
+ const registerShort = first.short.some(Boolean)
316
+ const one = registerShort ? placeOnce(labels, rowWidth, gap, true) : first
317
+ return stagger(labels, one, rowWidth, gap, registerShort)
318
+ }
319
+
320
+ /**
321
+ * The second row: every label the first row could not hold, ticks before names, each centred on its
322
+ * own box (a tick keeps its anchoring) and clamped inside the row like the holding name, keeping `gap`
323
+ * px from the labels already on that row. The register follows the first row; a label that fits
324
+ * neither row stays hidden.
325
+ */
326
+ function stagger(
327
+ labels: readonly RowLabel[],
328
+ one: Omit<RowPlacement, 'row'>,
329
+ rowWidth: number,
330
+ gap: number,
331
+ registerShort: boolean,
332
+ ): RowPlacement {
333
+ const row = labels.map((): 0 | 1 => 0)
334
+ const { shown, short, shift } = one
335
+ const kept: LabelBox[] = []
336
+ const rank = (l: RowLabel) => (l.end ? 0 : l.span ? 2 : 1)
337
+ const pending = labels
338
+ .map((_, i) => i)
339
+ .filter((i) => !shown[i] && labels[i]?.figure !== true)
340
+ .toSorted((a, b) => rank(labels[a] as RowLabel) - rank(labels[b] as RowLabel))
341
+ const clamped = (b: LabelBox): LabelBox => {
342
+ const width = b.right - b.left
343
+ const left = Math.max(0, Math.min(b.left, rowWidth - width))
344
+ return { left, right: left + width }
345
+ }
346
+ const clears = (b: LabelBox) =>
347
+ !kept.some(
348
+ (k) => b.left < k.right + gap - LABEL_SUBPIXEL && k.left < b.right + gap - LABEL_SUBPIXEL,
349
+ )
350
+ for (const i of pending) {
351
+ const label = labels[i] as RowLabel
352
+ const useShort = registerShort && label.short !== undefined
353
+ const candidates = useShort
354
+ ? [label.short as LabelBox]
355
+ : label.short !== undefined
356
+ ? [label.box, label.short]
357
+ : [label.box]
358
+ for (const base of candidates) {
359
+ const box = clamped(base)
360
+ if (box.right - box.left > rowWidth + LABEL_SUBPIXEL || !clears(box)) continue
361
+ kept.push(box)
362
+ shown[i] = true
363
+ short[i] = base !== label.box
364
+ shift[i] = box.left - base.left
365
+ row[i] = 1
366
+ break
367
+ }
368
+ }
369
+ return { shown, short, shift, row }
370
+ }
371
+
372
+ function placeOnce(
373
+ labels: readonly RowLabel[],
374
+ rowWidth: number,
375
+ gap: number,
376
+ registerShort: boolean,
377
+ ): Omit<RowPlacement, 'row'> {
281
378
  const shown = labels.map(() => false)
282
379
  const short = labels.map(() => false)
283
380
  const shift = labels.map(() => 0)
284
- const kept: { box: LabelBox; tick: boolean }[] = []
381
+ const kept: { box: LabelBox; tick: boolean; i: number }[] = []
285
382
  const rank = (l: RowLabel) => (l.holding ? 0 : l.span ? 3 : l.end ? 2 : 1)
286
383
  const order = labels
287
384
  .map((_, i) => i)
288
385
  .toSorted((a, b) => rank(labels[a] as RowLabel) - rank(labels[b] as RowLabel))
289
- // 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 }) => {
292
- const pad = tick || kTick ? gap : 0
293
- return b.left < k.right + pad - LABEL_SUBPIXEL && k.left < b.right + pad - LABEL_SUBPIXEL
294
- })
386
+ // Every pair of labels keeps the gap step apart, a zone name from its neighbour as a tick does.
387
+ const clears = (b: LabelBox) =>
388
+ !kept.some(
389
+ ({ box: k }) =>
390
+ b.left < k.right + gap - LABEL_SUBPIXEL && k.left < b.right + gap - LABEL_SUBPIXEL,
391
+ )
295
392
  for (const i of order) {
296
393
  const label = labels[i] as RowLabel
297
394
  const { span } = label
298
395
  const tick = span === undefined && !label.holding
299
396
  let box = label.box
397
+ if (tick) {
398
+ // A tick may sit past the row's end (a wide label hugging a mark in the near half): it is
399
+ // shifted inside the row, as the holding name is, rather than lost.
400
+ const width = box.right - box.left
401
+ const left = Math.max(0, Math.min(box.left, rowWidth - width))
402
+ shift[i] = left - box.left
403
+ box = { left, right: left + width }
404
+ }
300
405
  if (label.holding) {
301
406
  const width = box.right - box.left
302
407
  const left = Math.max(0, Math.min(box.left, rowWidth - width))
303
408
  shift[i] = left - box.left
304
409
  box = { left, right: left + width }
305
- if (!clears(box, false)) continue
410
+ if (!clears(box)) continue
306
411
  shown[i] = true
307
- kept.push({ box, tick: false })
412
+ kept.push({ box, tick: false, i })
308
413
  continue
309
414
  }
310
415
  const fits = (b: LabelBox) =>
@@ -312,20 +417,133 @@ export function placeRowLabels(
312
417
  b.right <= rowWidth + LABEL_SUBPIXEL &&
313
418
  (span === undefined ||
314
419
  (b.left >= span.left - LABEL_SUBPIXEL && b.right <= span.right + LABEL_SUBPIXEL)) &&
315
- clears(b, tick)
316
- const useShort = !fits(box) && label.short !== undefined && fits(label.short)
420
+ clears(b)
421
+ const useShort =
422
+ label.short !== undefined && (registerShort ? true : !fits(box)) && fits(label.short)
423
+ if (registerShort && label.short !== undefined && !useShort) continue
317
424
  if (useShort) box = label.short as LabelBox
318
- else if (!fits(box)) continue
425
+ else if (!fits(box)) {
426
+ shift[i] = 0
427
+ continue
428
+ }
319
429
  shown[i] = true
320
430
  short[i] = useShort
321
- kept.push({ box, tick })
431
+ kept.push({ box, tick, i })
322
432
  }
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
433
+ // A name that did not fit inside its own span borrows room from the row: the zone names beside it
434
+ // (the holding one included) slide away from it and it takes the gap. The rule is D38's: a name's
435
+ // CENTRE stays inside its own span, so a slid name may overhang a span edge by up to half its width,
436
+ // never past its centre. Full name first, then `short`; ticks never move.
437
+ for (const [i, label] of labels.entries()) {
438
+ if (label.span === undefined || label.holding || (shown[i] && !short[i])) continue
439
+ const { span } = label
440
+ const centre = (b: LabelBox) => (b.left + b.right) / 2
441
+ const others = kept.filter((k) => k.i !== i)
442
+ const movable = (k: (typeof kept)[number]) => !k.tick
443
+ const fixed = others.filter((k) => !movable(k))
444
+ const slidable = others.filter(movable)
445
+ const base = registerShort && label.short ? label.short : label.box
446
+ const mid = centre(base)
447
+ // Only a name that sits in the row and clears every tick: a tick keeps its place over a name.
448
+ const touches = (a: LabelBox, b: LabelBox) =>
449
+ a.left < b.right + gap - LABEL_SUBPIXEL && b.left < a.right + gap - LABEL_SUBPIXEL
450
+ if (
451
+ base.left < -LABEL_SUBPIXEL ||
452
+ base.right > rowWidth + LABEL_SUBPIXEL ||
453
+ others.some((k) => k.tick && touches(base, k.box)) ||
454
+ fixed.some((f) => f.box.left < mid && f.box.right > mid)
455
+ )
456
+ continue
457
+ const rightOf = slidable
458
+ .filter((k) => centre(k.box) >= mid)
459
+ .toSorted((a, b) => b.box.left - a.box.left)
460
+ const leftOf = slidable
461
+ .filter((k) => centre(k.box) < mid)
462
+ .toSorted((a, b) => a.box.left - b.box.left)
463
+ const place = (b: LabelBox, lo: number, hi: number): LabelBox => {
464
+ const left = Math.max(lo, Math.min(b.left, hi - (b.right - b.left)))
465
+ return { left, right: left + (b.right - b.left) }
466
+ }
467
+ // Slide only the sides the name needs: none, then the right, the left, both.
468
+ const attempt = (right: boolean, left: boolean) => {
469
+ const slides = new Map<number, number>()
470
+ let hi = rowWidth
471
+ for (const k of rightOf) {
472
+ const w = k.box.right - k.box.left
473
+ const stop = right
474
+ ? Math.min(
475
+ (labels[k.i]?.span?.right ?? rowWidth) + w / 2 + LABEL_SUBPIXEL,
476
+ hi,
477
+ ...fixed.filter((f) => f.box.left >= k.box.left).map((f) => f.box.left - gap),
478
+ )
479
+ : k.box.left + w
480
+ const at = Math.max(k.box.left, stop - w)
481
+ slides.set(k.i, at - k.box.left)
482
+ hi = at - gap
483
+ }
484
+ let lo = 0
485
+ for (const k of leftOf) {
486
+ const w = k.box.right - k.box.left
487
+ const stop = left
488
+ ? Math.max(
489
+ (labels[k.i]?.span?.left ?? 0) - w / 2 - LABEL_SUBPIXEL,
490
+ lo,
491
+ ...fixed.filter((f) => f.box.right <= k.box.right).map((f) => f.box.right + gap),
492
+ )
493
+ : k.box.left
494
+ const at = Math.min(k.box.left, stop)
495
+ slides.set(k.i, at - k.box.left)
496
+ lo = at + w + gap
497
+ }
498
+ // The gap this name may take: after the nearest left neighbour and fixed label, before the right.
499
+ const gapLo = Math.max(
500
+ lo,
501
+ ...fixed.filter((f) => f.box.right <= mid).map((f) => f.box.right + gap),
502
+ 0,
503
+ )
504
+ const gapHi = Math.min(
505
+ hi,
506
+ ...fixed.filter((f) => f.box.left >= mid).map((f) => f.box.left - gap),
507
+ rowWidth,
508
+ )
509
+ return { slides, gapLo, gapHi }
510
+ }
511
+ const tries = [
512
+ attempt(false, false),
513
+ attempt(true, false),
514
+ attempt(false, true),
515
+ attempt(true, true),
516
+ ]
517
+ const names =
518
+ registerShort && label.short
519
+ ? [label.short]
520
+ : shown[i]
521
+ ? [label.box]
522
+ : label.short
523
+ ? [label.box, label.short]
524
+ : [label.box]
525
+ for (const box of names) {
526
+ const w = box.right - box.left
527
+ const fit = tries.find(({ gapLo, gapHi }) => {
528
+ if (gapHi - gapLo + LABEL_SUBPIXEL < w) return false
529
+ const c = centre(place(box, gapLo, gapHi))
530
+ return c >= span.left && c <= span.right
531
+ })
532
+ if (fit === undefined) continue
533
+ const placed = place(box, fit.gapLo, fit.gapHi)
534
+ for (const k of kept) {
535
+ const by = fit.slides.get(k.i) ?? 0
536
+ if (by === 0) continue
537
+ k.box = { left: k.box.left + by, right: k.box.right + by }
538
+ shift[k.i] = (shift[k.i] ?? 0) + by
539
+ }
540
+ const own = kept.findIndex((k) => k.i === i)
541
+ if (own >= 0) kept.splice(own, 1)
542
+ kept.push({ box: placed, tick: false, i })
543
+ shift[i] = placed.left - box.left
544
+ shown[i] = true
545
+ short[i] = box !== label.box
546
+ break
329
547
  }
330
548
  }
331
549
  return { shown, short, shift }
@@ -361,6 +579,8 @@ export type BarModel = {
361
579
  parts: readonly Part[]
362
580
  /** Percent where the first forecast part starts; absent when the forecast opens the track. */
363
581
  boundaryPct: number | undefined
582
+ /** Where the forecast part ends (clamped to the track): the forecast caption ends here. */
583
+ forecastEndPct: number | undefined
364
584
  forecastText: string | null
365
585
  captionMode: CaptionMode
366
586
  /** Only in `parts` mode: one caption per part, in order. Empty otherwise. */
@@ -463,6 +683,12 @@ export function modelBar(input: BarInput): BarModel {
463
683
  span,
464
684
  parts,
465
685
  boundaryPct: firstForecast > 0 ? toPct(parts[firstForecast]?.start ?? 0) : undefined,
686
+ forecastEndPct:
687
+ firstForecast > 0
688
+ ? toPct(
689
+ parts.filter((p) => p.forecast).reduce((end, p) => Math.max(end, p.start + p.size), 0),
690
+ )
691
+ : undefined,
466
692
  forecastText:
467
693
  forecastLabels.length === 0
468
694
  ? null