basalt-ui 2.27.2 → 2.29.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 (343) hide show
  1. package/CHANGELOG.md +466 -307
  2. package/MIGRATING.md +358 -12
  3. package/agent/rules/basalt-batteries.md +1 -1
  4. package/agent/rules/basalt-mantine.md +1 -1
  5. package/agent/rules/basalt-tokens.md +2 -2
  6. package/agent/skills/basalt-app/SKILL.md +3 -3
  7. package/agent/skills/basalt-charts/SKILL.md +1 -1
  8. package/agent/skills/basalt-design/SKILL.md +12 -6
  9. package/agent/skills/basalt-design/references/catalogue.md +42 -36
  10. package/agent/skills/basalt-design/references/recipes.md +47 -0
  11. package/agent/skills/basalt-design/references/states.md +1 -1
  12. package/configs/oxlint-basalt.json +2 -1
  13. package/configs/oxlint-plugin.js +112 -3
  14. package/configs/oxlint-plugin.test.ts +99 -4
  15. package/configs/oxlint.json +1 -0
  16. package/dist/agent/chat/thread-message.d.ts +1 -160
  17. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  18. package/dist/agent/chat/thread-message.js +7 -162
  19. package/dist/agent/chat/virtualize.d.ts +5 -5
  20. package/dist/charts/ChartCard.d.ts +14 -7
  21. package/dist/charts/ChartCard.d.ts.map +1 -1
  22. package/dist/charts/ChartCard.js +112 -23
  23. package/dist/charts/Lines.d.ts.map +1 -1
  24. package/dist/charts/Lines.js +11 -4
  25. package/dist/charts/Sparkline.d.ts +14 -2
  26. package/dist/charts/Sparkline.d.ts.map +1 -1
  27. package/dist/charts/Sparkline.js +155 -44
  28. package/dist/charts/chart-box.module.css +59 -2
  29. package/dist/charts/chart-box.module.css.d.ts +5 -0
  30. package/dist/charts/chart-card.module.css +28 -17
  31. package/dist/charts/chart-card.module.css.d.ts +3 -0
  32. package/dist/charts/compile.d.ts +1 -1
  33. package/dist/charts/compile.d.ts.map +1 -1
  34. package/dist/charts/compile.js +38 -27
  35. package/dist/charts/labels.d.ts +13 -3
  36. package/dist/charts/labels.d.ts.map +1 -1
  37. package/dist/charts/labels.js +131 -20
  38. package/dist/charts/legend.d.ts.map +1 -1
  39. package/dist/charts/legend.js +1 -1
  40. package/dist/charts/ref-label.d.ts +37 -8
  41. package/dist/charts/ref-label.d.ts.map +1 -1
  42. package/dist/charts/ref-label.js +55 -10
  43. package/dist/charts/sparkline.module.css +50 -0
  44. package/dist/charts/sparkline.module.css.d.ts +3 -0
  45. package/dist/charts/state.d.ts +4 -4
  46. package/dist/charts/state.d.ts.map +1 -1
  47. package/dist/charts/state.js +23 -5
  48. package/dist/cli/doctor-upgrade.d.ts +11 -0
  49. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  50. package/dist/cli/doctor-upgrade.js +54 -0
  51. package/dist/cli/doctor.d.ts.map +1 -1
  52. package/dist/cli/doctor.js +32 -0
  53. package/dist/cli/help.d.ts.map +1 -1
  54. package/dist/cli/help.js +8 -3
  55. package/dist/cli/index.d.ts +13 -13
  56. package/dist/cli/index.d.ts.map +1 -1
  57. package/dist/cli/index.js +36 -2
  58. package/dist/cli/init.d.ts +6 -0
  59. package/dist/cli/init.d.ts.map +1 -1
  60. package/dist/cli/init.js +118 -27
  61. package/dist/cli/router-wiring.d.ts +3 -0
  62. package/dist/cli/router-wiring.d.ts.map +1 -1
  63. package/dist/cli/router-wiring.js +2 -0
  64. package/dist/cli/shot/capture.d.ts +34 -2
  65. package/dist/cli/shot/capture.d.ts.map +1 -1
  66. package/dist/cli/shot/capture.js +95 -12
  67. package/dist/cli/shot/detect.d.ts +4 -1
  68. package/dist/cli/shot/detect.d.ts.map +1 -1
  69. package/dist/cli/shot/detect.js +38 -16
  70. package/dist/cli/shot/index.d.ts.map +1 -1
  71. package/dist/cli/shot/index.js +9 -2
  72. package/dist/cli/shot/measure.d.ts.map +1 -1
  73. package/dist/cli/shot/measure.js +11 -2
  74. package/dist/cli/shot/types.d.ts +4 -1
  75. package/dist/cli/shot/types.d.ts.map +1 -1
  76. package/dist/cli/sync.d.ts.map +1 -1
  77. package/dist/cli/sync.js +10 -2
  78. package/dist/common/could-not-load.d.ts +13 -0
  79. package/dist/common/could-not-load.d.ts.map +1 -0
  80. package/dist/common/could-not-load.js +14 -0
  81. package/dist/common/empty-copy.d.ts +16 -0
  82. package/dist/common/empty-copy.d.ts.map +1 -0
  83. package/dist/common/empty-copy.js +9 -0
  84. package/dist/common/index.d.ts +1 -0
  85. package/dist/common/index.d.ts.map +1 -1
  86. package/dist/common/index.js +3 -0
  87. package/dist/common/props.d.ts +20 -0
  88. package/dist/common/props.d.ts.map +1 -1
  89. package/dist/common/props.js +13 -1
  90. package/dist/common/retry-button.module.css +7 -3
  91. package/dist/common/virtual-rows.d.ts +196 -0
  92. package/dist/common/virtual-rows.d.ts.map +1 -0
  93. package/dist/common/virtual-rows.js +290 -0
  94. package/dist/controls/controls.module.css +33 -1
  95. package/dist/controls/controls.module.css.d.ts +2 -0
  96. package/dist/controls/enum-filter.d.ts.map +1 -1
  97. package/dist/controls/enum-filter.js +8 -2
  98. package/dist/controls/filter-pill.d.ts +27 -3
  99. package/dist/controls/filter-pill.d.ts.map +1 -1
  100. package/dist/controls/filter-pill.js +15 -4
  101. package/dist/controls/form-layout.d.ts +9 -3
  102. package/dist/controls/form-layout.d.ts.map +1 -1
  103. package/dist/controls/form-layout.js +74 -12
  104. package/dist/controls/form-layout.module.css +112 -7
  105. package/dist/controls/form-layout.module.css.d.ts +1 -0
  106. package/dist/controls/multi-select-filter.d.ts +2 -2
  107. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  108. package/dist/controls/multi-select-filter.js +12 -6
  109. package/dist/controls/range-filter.d.ts +1 -1
  110. package/dist/controls/range-filter.d.ts.map +1 -1
  111. package/dist/controls/range-filter.js +8 -2
  112. package/dist/dashboard/bar-list.d.ts +5 -5
  113. package/dist/dashboard/bar-list.d.ts.map +1 -1
  114. package/dist/dashboard/bar-list.js +15 -8
  115. package/dist/dashboard/bar-list.module.css +21 -5
  116. package/dist/dashboard/board-nav.d.ts +22 -0
  117. package/dist/dashboard/board-nav.d.ts.map +1 -0
  118. package/dist/dashboard/board-nav.js +49 -0
  119. package/dist/dashboard/board.d.ts +52 -0
  120. package/dist/dashboard/board.d.ts.map +1 -0
  121. package/dist/dashboard/board.js +247 -0
  122. package/dist/dashboard/board.module.css +179 -0
  123. package/dist/dashboard/board.module.css.d.ts +28 -0
  124. package/dist/dashboard/empty-state.d.ts +6 -6
  125. package/dist/dashboard/empty-state.d.ts.map +1 -1
  126. package/dist/dashboard/empty-state.js +17 -8
  127. package/dist/dashboard/event-list-model.d.ts +54 -0
  128. package/dist/dashboard/event-list-model.d.ts.map +1 -0
  129. package/dist/dashboard/event-list-model.js +76 -0
  130. package/dist/dashboard/event-list-rows.d.ts +23 -0
  131. package/dist/dashboard/event-list-rows.d.ts.map +1 -0
  132. package/dist/dashboard/event-list-rows.js +89 -0
  133. package/dist/dashboard/event-list-scroll.d.ts +55 -0
  134. package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
  135. package/dist/dashboard/event-list-scroll.js +216 -0
  136. package/dist/dashboard/event-list-skeleton.d.ts +10 -0
  137. package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
  138. package/dist/dashboard/event-list-skeleton.js +34 -0
  139. package/dist/dashboard/event-list.d.ts +65 -0
  140. package/dist/dashboard/event-list.d.ts.map +1 -0
  141. package/dist/dashboard/event-list.js +208 -0
  142. package/dist/dashboard/event-list.module.css +336 -0
  143. package/dist/dashboard/event-list.module.css.d.ts +34 -0
  144. package/dist/dashboard/index.d.ts +2 -0
  145. package/dist/dashboard/index.d.ts.map +1 -1
  146. package/dist/dashboard/index.js +4 -0
  147. package/dist/dashboard/meter-model.d.ts +6 -3
  148. package/dist/dashboard/meter-model.d.ts.map +1 -1
  149. package/dist/dashboard/meter-model.js +9 -4
  150. package/dist/dashboard/meter-parts.d.ts +3 -0
  151. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  152. package/dist/dashboard/meter-parts.js +36 -6
  153. package/dist/dashboard/meter.d.ts +3 -3
  154. package/dist/dashboard/meter.d.ts.map +1 -1
  155. package/dist/dashboard/meter.js +10 -2
  156. package/dist/dashboard/meter.module.css +20 -12
  157. package/dist/dashboard/meter.module.css.d.ts +0 -1
  158. package/dist/dashboard/page-summary.d.ts +3 -3
  159. package/dist/dashboard/page-summary.d.ts.map +1 -1
  160. package/dist/dashboard/page-summary.js +7 -2
  161. package/dist/dashboard/page-summary.module.css +5 -2
  162. package/dist/dashboard/query-state.d.ts +9 -8
  163. package/dist/dashboard/query-state.d.ts.map +1 -1
  164. package/dist/dashboard/query-state.js +29 -11
  165. package/dist/dashboard/section.d.ts +11 -3
  166. package/dist/dashboard/section.d.ts.map +1 -1
  167. package/dist/dashboard/section.js +34 -7
  168. package/dist/dashboard/settings-section.d.ts +8 -5
  169. package/dist/dashboard/settings-section.d.ts.map +1 -1
  170. package/dist/dashboard/settings-section.js +12 -8
  171. package/dist/dashboard/settings-section.module.css +25 -4
  172. package/dist/dashboard/settings-section.module.css.d.ts +1 -0
  173. package/dist/dashboard/stat-card-parts.d.ts +5 -1
  174. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  175. package/dist/dashboard/stat-card-parts.js +8 -3
  176. package/dist/dashboard/stat-card.d.ts +3 -3
  177. package/dist/dashboard/stat-card.d.ts.map +1 -1
  178. package/dist/dashboard/stat-card.js +47 -12
  179. package/dist/dashboard/stat-card.module.css +42 -7
  180. package/dist/dashboard/stat-card.module.css.d.ts +3 -0
  181. package/dist/dashboard/stat-group.d.ts +2 -2
  182. package/dist/dashboard/stat-group.d.ts.map +1 -1
  183. package/dist/dashboard/stat-group.js +10 -3
  184. package/dist/dashboard/stat-strip.d.ts +5 -4
  185. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  186. package/dist/dashboard/stat-strip.js +41 -31
  187. package/dist/dashboard/stat-strip.module.css +8 -6
  188. package/dist/dashboard/visual-slot.d.ts +4 -0
  189. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  190. package/dist/dashboard/visual-slot.js +2 -0
  191. package/dist/dashboard/widget-header.d.ts +6 -6
  192. package/dist/dashboard/widget-header.d.ts.map +1 -1
  193. package/dist/dashboard/widget-header.js +4 -2
  194. package/dist/dashboard/widget-header.module.css +12 -15
  195. package/dist/format/shared.d.ts.map +1 -1
  196. package/dist/format/shared.js +24 -1
  197. package/dist/guard/index.d.ts +1 -1
  198. package/dist/guard/index.d.ts.map +1 -1
  199. package/dist/guard/index.js +4 -1
  200. package/dist/index.d.ts +1 -1
  201. package/dist/index.d.ts.map +1 -1
  202. package/dist/index.js +4 -0
  203. package/dist/shell/app-main.module.css +18 -0
  204. package/dist/styles.css +69 -0
  205. package/dist/surfaces.d.ts +2 -2
  206. package/dist/surfaces.d.ts.map +1 -1
  207. package/dist/surfaces.js +8 -2
  208. package/dist/table/cell-kinds.d.ts +47 -0
  209. package/dist/table/cell-kinds.d.ts.map +1 -0
  210. package/dist/table/cell-kinds.js +180 -0
  211. package/dist/table/cell-kinds.module.css +55 -0
  212. package/dist/table/cell-kinds.module.css.d.ts +15 -0
  213. package/dist/table/data-table-fold.d.ts +155 -0
  214. package/dist/table/data-table-fold.d.ts.map +1 -0
  215. package/dist/table/data-table-fold.js +320 -0
  216. package/dist/table/data-table-state.d.ts +10 -3
  217. package/dist/table/data-table-state.d.ts.map +1 -1
  218. package/dist/table/data-table-state.js +11 -6
  219. package/dist/table/data-table.d.ts +13 -28
  220. package/dist/table/data-table.d.ts.map +1 -1
  221. package/dist/table/data-table.js +362 -255
  222. package/dist/table/data-table.module.css +282 -3
  223. package/dist/table/data-table.module.css.d.ts +16 -0
  224. package/dist/table/table-features.d.ts +34 -4
  225. package/dist/table/table-features.d.ts.map +1 -1
  226. package/dist/table/table-features.js +10 -0
  227. package/dist/theme/card-inset.module.css +35 -0
  228. package/dist/theme/controls.module.css +55 -2
  229. package/dist/theme/ctl-theme.d.ts.map +1 -1
  230. package/dist/theme/ctl-theme.js +5 -0
  231. package/dist/theme/index.d.ts.map +1 -1
  232. package/dist/theme/index.js +14 -10
  233. package/dist/tokens/core.d.ts +1 -0
  234. package/dist/tokens/core.d.ts.map +1 -1
  235. package/dist/tokens/core.js +1 -0
  236. package/dist/tokens/derive.js +1 -1
  237. package/dist/tokens/palette.d.ts +2 -1
  238. package/dist/tokens/palette.d.ts.map +1 -1
  239. package/llms.txt +295 -5
  240. package/package.json +1 -1
  241. package/src/agent/chat/thread-message.tsx +10 -403
  242. package/src/agent/chat/virtualize.ts +5 -5
  243. package/src/charts/ChartCard.tsx +175 -31
  244. package/src/charts/Lines.tsx +13 -4
  245. package/src/charts/Sparkline.tsx +213 -48
  246. package/src/charts/chart-box.module.css +59 -2
  247. package/src/charts/chart-box.module.css.d.ts +5 -0
  248. package/src/charts/chart-card.module.css +28 -17
  249. package/src/charts/chart-card.module.css.d.ts +3 -0
  250. package/src/charts/compile.ts +59 -33
  251. package/src/charts/labels.ts +175 -24
  252. package/src/charts/legend.tsx +3 -2
  253. package/src/charts/ref-label.ts +114 -18
  254. package/src/charts/sparkline.module.css +50 -0
  255. package/src/charts/sparkline.module.css.d.ts +3 -0
  256. package/src/charts/state.tsx +40 -10
  257. package/src/cli/doctor-upgrade.ts +75 -0
  258. package/src/cli/doctor.ts +36 -0
  259. package/src/cli/help.ts +16 -6
  260. package/src/cli/index.ts +73 -67
  261. package/src/cli/init.ts +157 -36
  262. package/src/cli/router-wiring.ts +2 -2
  263. package/src/cli/shot/capture.ts +138 -16
  264. package/src/cli/shot/detect.ts +46 -22
  265. package/src/cli/shot/index.ts +8 -2
  266. package/src/cli/shot/measure.ts +11 -2
  267. package/src/cli/shot/types.ts +4 -1
  268. package/src/cli/sync.ts +12 -2
  269. package/src/common/could-not-load.ts +22 -0
  270. package/src/common/empty-copy.ts +17 -0
  271. package/src/common/index.ts +1 -0
  272. package/src/common/props.ts +30 -0
  273. package/src/common/retry-button.module.css +7 -3
  274. package/src/common/virtual-rows.tsx +682 -0
  275. package/src/controls/controls.module.css +33 -1
  276. package/src/controls/controls.module.css.d.ts +2 -0
  277. package/src/controls/enum-filter.tsx +8 -2
  278. package/src/controls/filter-pill.tsx +80 -27
  279. package/src/controls/form-layout.module.css +112 -7
  280. package/src/controls/form-layout.module.css.d.ts +1 -0
  281. package/src/controls/form-layout.tsx +115 -22
  282. package/src/controls/multi-select-filter.tsx +22 -11
  283. package/src/controls/range-filter.tsx +9 -3
  284. package/src/dashboard/bar-list.module.css +21 -5
  285. package/src/dashboard/bar-list.tsx +53 -45
  286. package/src/dashboard/board-nav.ts +67 -0
  287. package/src/dashboard/board.module.css +179 -0
  288. package/src/dashboard/board.module.css.d.ts +28 -0
  289. package/src/dashboard/board.tsx +415 -0
  290. package/src/dashboard/empty-state.tsx +21 -11
  291. package/src/dashboard/event-list-model.ts +125 -0
  292. package/src/dashboard/event-list-rows.tsx +117 -0
  293. package/src/dashboard/event-list-scroll.ts +291 -0
  294. package/src/dashboard/event-list-skeleton.tsx +62 -0
  295. package/src/dashboard/event-list.module.css +336 -0
  296. package/src/dashboard/event-list.module.css.d.ts +34 -0
  297. package/src/dashboard/event-list.tsx +336 -0
  298. package/src/dashboard/index.ts +2 -0
  299. package/src/dashboard/meter-model.ts +16 -7
  300. package/src/dashboard/meter-parts.tsx +53 -14
  301. package/src/dashboard/meter.module.css +20 -12
  302. package/src/dashboard/meter.module.css.d.ts +0 -1
  303. package/src/dashboard/meter.tsx +36 -18
  304. package/src/dashboard/page-summary.module.css +5 -2
  305. package/src/dashboard/page-summary.tsx +13 -6
  306. package/src/dashboard/query-state.tsx +55 -30
  307. package/src/dashboard/section.tsx +83 -41
  308. package/src/dashboard/settings-section.module.css +25 -4
  309. package/src/dashboard/settings-section.module.css.d.ts +1 -0
  310. package/src/dashboard/settings-section.tsx +18 -8
  311. package/src/dashboard/stat-card-parts.tsx +20 -3
  312. package/src/dashboard/stat-card.module.css +42 -7
  313. package/src/dashboard/stat-card.module.css.d.ts +3 -0
  314. package/src/dashboard/stat-card.tsx +55 -13
  315. package/src/dashboard/stat-group.tsx +22 -14
  316. package/src/dashboard/stat-strip.module.css +8 -6
  317. package/src/dashboard/stat-strip.tsx +29 -20
  318. package/src/dashboard/visual-slot.ts +5 -0
  319. package/src/dashboard/widget-header.module.css +12 -15
  320. package/src/dashboard/widget-header.tsx +8 -5
  321. package/src/format/shared.ts +30 -1
  322. package/src/guard/index.ts +7 -1
  323. package/src/index.ts +4 -0
  324. package/src/shell/app-main.module.css +18 -0
  325. package/src/styles.css +69 -0
  326. package/src/surfaces.ts +7 -1
  327. package/src/table/cell-kinds.module.css +55 -0
  328. package/src/table/cell-kinds.module.css.d.ts +15 -0
  329. package/src/table/cell-kinds.tsx +263 -0
  330. package/src/table/data-table-fold.tsx +567 -0
  331. package/src/table/data-table-state.ts +24 -13
  332. package/src/table/data-table.module.css +282 -3
  333. package/src/table/data-table.module.css.d.ts +16 -0
  334. package/src/table/data-table.tsx +430 -362
  335. package/src/table/table-features.ts +44 -4
  336. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
  337. package/src/theme/card-inset.module.css +35 -0
  338. package/src/theme/controls.module.css +55 -2
  339. package/src/theme/ctl-theme.tsx +8 -0
  340. package/src/theme/index.ts +12 -8
  341. package/src/tokens/core.ts +1 -0
  342. package/src/tokens/derive.ts +1 -1
  343. package/src/tokens/palette.ts +4 -1
@@ -1,15 +1,23 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useRef, useState } from "react";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { Children, isValidElement, useRef, useState } from "react";
3
3
  import { useIsomorphicLayoutEffect } from "../common/isomorphic-layout-effect.js";
4
- import { cx } from "../common/props.js";
4
+ import { HostTitleContext } from "../common/could-not-load.js";
5
+ import { cx, splitDataAttributes } from "../common/props.js";
6
+ import { DeltaBadge } from "../dashboard/delta-badge.js";
5
7
  import { WidgetHeader } from "../dashboard/widget-header.js";
6
8
  import { VX } from "../tokens/index.js";
7
9
  import { ChartCardContext } from "./card-context.js";
10
+ import { BandStrip } from "./BandStrip.js";
11
+ import { Lines } from "./Lines.js";
12
+ import { StackedArea } from "./StackedArea.js";
8
13
  import classes from "./chart-card.module.css";
9
14
  import { ChartPlaceholder, resolveChartState } from "./state.js";
10
15
  const cardStyle = {
11
16
  display: "flex",
12
17
  flexDirection: "column",
18
+ // Fills its grid cell (or a `h="100%"` anchor wrapper): two cards in one row end together, with
19
+ // no wrapper background under the shorter one. In an auto-height parent it resolves to auto.
20
+ height: "100%",
13
21
  minHeight: 0,
14
22
  containerType: "inline-size",
15
23
  containerName: "basalt-card",
@@ -62,6 +70,33 @@ function periodText(period, afterUnit) {
62
70
  const text = period.join(" \xB7 ");
63
71
  return afterUnit && !text.startsWith(PERIOD_SEPARATOR.trim()) ? PERIOD_SEPARATOR + text : text;
64
72
  }
73
+ const hasComparison = (node) => node !== void 0 && node !== null && node !== false && node !== "";
74
+ function Comparison({ node }) {
75
+ if (typeof node !== "string") return node;
76
+ const sign = /^\s*([+\-−])\s*(.+)$/.exec(node);
77
+ if (sign === null) return node;
78
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
79
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: classes.factGlyph, children: sign[1] === "+" ? "\u25B2" : "\u25BC" }),
80
+ sign[2]
81
+ ] });
82
+ }
83
+ function legacyFact(header) {
84
+ const { value, delta, deltaPeriod, deltaPolarity } = header;
85
+ if (value === void 0 && delta === void 0) return void 0;
86
+ return {
87
+ value: value ?? null,
88
+ ...delta !== void 0 && {
89
+ comparison: /* @__PURE__ */ jsx(
90
+ DeltaBadge,
91
+ {
92
+ value: delta,
93
+ period: deltaPeriod,
94
+ ...deltaPolarity !== void 0 && { polarity: deltaPolarity }
95
+ }
96
+ )
97
+ }
98
+ };
99
+ }
65
100
  const definedOnly = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
66
101
  const HEADER_TRIGGERS = ["title", "info", "value", "icon", "count"];
67
102
  function Facts({
@@ -86,9 +121,28 @@ function Facts({
86
121
  ...f.tone !== void 0 && { "data-tone": f.tone },
87
122
  className: classes.fact,
88
123
  children: [
89
- /* @__PURE__ */ jsx("span", { "data-basalt-fact-value": "", className: classes.factValue, children: f.value }),
124
+ f.value !== null && f.value !== void 0 && f.value !== "" && /* @__PURE__ */ jsx(
125
+ "span",
126
+ {
127
+ "data-basalt-fact-value": "",
128
+ ...!hasComparison(f.comparison) && { "data-basalt-fact-tone": "" },
129
+ className: cx(
130
+ classes.factValue,
131
+ !hasComparison(f.comparison) && classes.factTone
132
+ ),
133
+ children: f.value
134
+ }
135
+ ),
90
136
  f.unit !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.factUnit, children: f.unit }),
91
- f.comparison,
137
+ hasComparison(f.comparison) && /* @__PURE__ */ jsx(
138
+ "span",
139
+ {
140
+ "data-basalt-fact-delta": "",
141
+ "data-basalt-fact-tone": "",
142
+ className: classes.factTone,
143
+ children: /* @__PURE__ */ jsx(Comparison, { node: f.comparison })
144
+ }
145
+ ),
92
146
  period !== "" && /* @__PURE__ */ jsx("span", { className: classes.factPeriod, children: period })
93
147
  ]
94
148
  },
@@ -106,6 +160,30 @@ function FactsSkeleton({ basis }) {
106
160
  basis && /* @__PURE__ */ jsx("p", { className: cx(classes.factsBasis, classes.skeletonBasis) })
107
161
  ] });
108
162
  }
163
+ function isChartHeight(value) {
164
+ return typeof value === "number" || typeof value === "object" && value !== null && typeof value.base === "number";
165
+ }
166
+ function bodyKindOf(node) {
167
+ for (const child of Children.toArray(node)) {
168
+ if (!isValidElement(child)) continue;
169
+ if (child.type === Lines || child.type === StackedArea) return { ghost: "line" };
170
+ if (child.type === BandStrip) {
171
+ const { height, states, legend } = child.props;
172
+ return {
173
+ ghost: "band",
174
+ ...isChartHeight(height) && { height },
175
+ // The loaded strip's legend row sits under the box: the ghost keeps its room.
176
+ ...legend !== false && (states?.length ?? 0) > 1 && { legend: true }
177
+ };
178
+ }
179
+ const inner = bodyKindOf(child.props.children);
180
+ if (inner !== void 0) return inner;
181
+ }
182
+ return void 0;
183
+ }
184
+ function reserveLegend(reserve, placeholder) {
185
+ return reserve ? /* @__PURE__ */ jsx("div", { className: classes.legendReserve, "data-basalt-legend-reserve": "", children: placeholder }) : placeholder;
186
+ }
109
187
  function ChartCard({
110
188
  actions,
111
189
  state,
@@ -121,26 +199,34 @@ function ChartCard({
121
199
  style,
122
200
  children,
123
201
  facts,
124
- ...header
202
+ ...headerAndData
125
203
  }) {
204
+ const { data, rest: header } = splitDataAttributes(headerAndData);
126
205
  const { ref, short } = useShortCard();
127
206
  const resolved = resolveChartState(state);
128
- const showFacts = facts !== void 0 && resolved === null;
129
- const skeletonFacts = facts !== void 0 && resolved === "pending";
207
+ const noun = stateNoun ?? header.title;
208
+ const kind = resolved === "pending" ? bodyKindOf(children) : void 0;
209
+ const plotGhost = ghost ?? kind?.ghost;
210
+ const pendingHeight = placeholderHeight ?? kind?.height;
211
+ const headline = facts ?? legacyFact(header);
212
+ const showFacts = headline !== void 0 && resolved === null;
213
+ const skeletonFacts = headline !== void 0 && resolved === "pending";
130
214
  const hasHeader = actions !== void 0 || showFacts || skeletonFacts || HEADER_TRIGGERS.some((k) => header[k] !== void 0);
131
- const { subtitle, ...rest } = header;
132
- const headerProps = facts === void 0 ? header : rest;
215
+ const { subtitle, value: _v, delta: _d, deltaPeriod: _p, deltaPolarity: _pol, ...rest } = header;
216
+ const headerProps = headline === void 0 ? header : rest;
217
+ const hostBody = /* @__PURE__ */ jsx(HostTitleContext, { value: header.title, children });
133
218
  return /* @__PURE__ */ jsx(ChartCardContext.Provider, { value: true, children: /* @__PURE__ */ jsxs(
134
219
  "div",
135
220
  {
136
221
  ref,
222
+ ...data,
137
223
  "data-basalt-chart-card": "",
138
224
  className: cx(classNames?.root, className),
139
225
  style: { ...cardStyle, ...style },
140
226
  ...resolved === "pending" && { "aria-busy": "true" },
141
227
  ...short && { "data-basalt-card-short": "" },
142
228
  children: [
143
- hasHeader && /* @__PURE__ */ jsxs("div", { className: cx(classes.header, classNames?.header), children: [
229
+ hasHeader && /* @__PURE__ */ jsxs("div", { "data-basalt-chart-header": "", className: cx(classes.header, classNames?.header), children: [
144
230
  /* @__PURE__ */ jsx(
145
231
  WidgetHeader,
146
232
  {
@@ -152,7 +238,7 @@ function ChartCard({
152
238
  }
153
239
  }
154
240
  ),
155
- showFacts && /* @__PURE__ */ jsx(Facts, { facts, basis: subtitle, stale }),
241
+ showFacts && /* @__PURE__ */ jsx(Facts, { facts: headline, basis: subtitle, stale }),
156
242
  skeletonFacts && /* @__PURE__ */ jsx(FactsSkeleton, { basis: subtitle !== void 0 })
157
243
  ] }),
158
244
  /* @__PURE__ */ jsx(
@@ -160,17 +246,20 @@ function ChartCard({
160
246
  {
161
247
  ...classNames?.body !== void 0 && { className: classNames.body },
162
248
  style: bodyClipStyle,
163
- children: resolved === null || resolved === "pending" && placeholderHeight === "content" ? children : /* @__PURE__ */ jsx(
164
- ChartPlaceholder,
165
- {
166
- state,
167
- ...placeholderHeight !== void 0 && { height: placeholderHeight },
168
- ...stateNoun !== void 0 && { noun: stateNoun },
169
- ...ghost !== void 0 && { ghost },
170
- ...onRetry !== void 0 && { onRetry },
171
- ...retrying !== void 0 && { retrying },
172
- action: stateAction
173
- }
249
+ children: resolved === null || resolved === "pending" && placeholderHeight === "content" ? hostBody : reserveLegend(
250
+ kind?.legend === true,
251
+ /* @__PURE__ */ jsx(
252
+ ChartPlaceholder,
253
+ {
254
+ state,
255
+ ...pendingHeight !== void 0 && { height: pendingHeight },
256
+ ...noun !== void 0 && { noun },
257
+ ...plotGhost !== void 0 && { ghost: plotGhost },
258
+ ...onRetry !== void 0 && { onRetry },
259
+ ...retrying !== void 0 && { retrying },
260
+ action: stateAction
261
+ }
262
+ )
174
263
  )
175
264
  }
176
265
  )
@@ -1 +1 @@
1
- {"version":3,"file":"Lines.d.ts","sourceRoot":"","sources":["../../src/charts/Lines.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,YAAY,EAAE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C,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CA6FzF"}
@@ -6,7 +6,7 @@ import { useCallback } from "react";
6
6
  import { CartesianRung } from "./CartesianChart.js";
7
7
  import { areaGradientId } from "./compile.js";
8
8
  import { chartCurve } from "./curves.js";
9
- import { endLabelMarks, endLabelPlan } from "./labels.js";
9
+ import { claimLabelBoxes, endLabelMarks, endLabelPlan } from "./labels.js";
10
10
  import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from "./marks.js";
11
11
  import { rowX } from "./types.js";
12
12
  const hasValue = (r) => r.y !== null;
@@ -20,7 +20,7 @@ function lastIsPlaceable(props, s) {
20
20
  }
21
21
  const AUTO_END_LABELS = 3;
22
22
  function Lines(props) {
23
- const { thresholds, naming = "auto", ...rest } = props;
23
+ const { thresholds, naming = "auto", refLines, ...rest } = props;
24
24
  const { series } = props;
25
25
  const labelled = series.filter((s) => s.role !== "reference");
26
26
  const namedByLabels = props.y2 === void 0 && series.every((s) => s.legend === false || s.role !== "reference") && !(props.refLines ?? []).some((r) => r.legend !== void 0);
@@ -79,15 +79,22 @@ function Lines(props) {
79
79
  out.push(...markersOf(s, plot.rows(s.key), yScale));
80
80
  }
81
81
  const labelled2 = plotted.filter((s) => s.role !== "reference");
82
- out.push(...endLabelMarks(endLabelPlan(plot, labelled2, effective)));
82
+ const rules = (refLines ?? []).flatMap((r) => r.axis === "right" ? [] : [r.value]);
83
+ const plan = endLabelPlan(plot, labelled2, effective, rules);
84
+ claimLabelBoxes(
85
+ plot,
86
+ plan.map((p) => p.box)
87
+ );
88
+ out.push(...endLabelMarks(plan));
83
89
  return out;
84
90
  },
85
- [series, thresholds, effective]
91
+ [series, thresholds, effective, refLines]
86
92
  );
87
93
  return /* @__PURE__ */ jsx(
88
94
  CartesianRung,
89
95
  {
90
96
  ...rest,
97
+ ...refLines !== void 0 && { refLines },
91
98
  marks,
92
99
  ...labelsOnly && { legend: false },
93
100
  ...hideAtWide && { hideLegendAtWide: true }
@@ -32,15 +32,27 @@ export type SparklineProps = BasaltProps & {
32
32
  /** A quiet dashed hairline at a value, or at the mean of the plotted values (`'mean'`). The y
33
33
  * domain widens to include it. Not a legend item, never a status colour. */
34
34
  reference?: number | 'mean' | undefined;
35
- /** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot start just
36
- * above the line. */
35
+ /** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot end the line
36
+ * is not near, just above the reference (below when there is no room above). */
37
37
  referenceLabel?: string | undefined;
38
+ /** A productive range (`{ from: 0.6, to: 1 }`) drawn as a quiet band behind the line. The y
39
+ * domain widens to include it. Not a series: no legend item, no tooltip row. A non-finite bound or
40
+ * an empty range (`from === to`) draws nothing and leaves the domain alone. */
41
+ band?: {
42
+ from: number;
43
+ to: number;
44
+ } | undefined;
38
45
  /** Formats the readout's value. Default: the compact number format. */
39
46
  format?: ((value: number) => string) | undefined;
40
47
  /** The readout's x label per point, index-aligned with `data`: pass the point's day ("12 Oct"),
41
48
  * and the readout reads `3 items · 12 Oct` beside the point. Omitted: the moment of an `{ at }`
42
49
  * point, else the value alone. */
43
50
  labels?: readonly string[] | undefined;
51
+ /** The span the series covers, stated quietly under the plot (`12 wk`). Default inside a `StatCard`
52
+ * or strip cell: the first and last of `labels`, or of an `{ at }` series' days (`3 Aug – 19 Oct`; an hourly series states none);
53
+ * plain values state none. `false` or a blank string states none. With a `referenceLabel`, a stated window also takes
54
+ * that label out of the plot into the same row, where no line can run through it. */
55
+ window?: string | false | undefined;
44
56
  };
45
57
  type Point = {
46
58
  i: number;
@@ -1 +1 @@
1
- {"version":3,"file":"Sparkline.d.ts","sourceRoot":"","sources":["../../src/charts/Sparkline.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAA0D,YAAY,EAAE,MAAM,OAAO,CAAA;AAEjG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAi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,SAAS,CAAA;IAC9B;gFAC4E;IAC5E,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACvC;oFACgF;IAChF,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC;;mFAE+E;IAC/E,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAA;IAC/C,uEAAuE;IACvE,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IAChD;;sCAEkC;IAClC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;IACtC;;;yFAGqF;IACrF,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAA;CACpC,CAAA;AAED,KAAK,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AA+L5C;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,KAAK,EAAE,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GAAG,KAAK,GACnB,SAAS,KAAK,EAAE,CAIlB;AAwXD,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,CAoS7D"}
@@ -2,6 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { dot } from "@tanstack/charts/dot";
3
3
  import { decorative } from "@tanstack/charts/mark/decorative";
4
4
  import { lineY } from "@tanstack/charts/line";
5
+ import { rect } from "@tanstack/charts/rect";
5
6
  import { ruleY } from "@tanstack/charts/rule";
6
7
  import { scaleBand } from "@tanstack/charts/scales/band";
7
8
  import { scaleLinear } from "@tanstack/charts/scales/linear";
@@ -27,6 +28,10 @@ const READOUT_GAP = 8;
27
28
  const LINE_INSET = 3;
28
29
  const SHORT_BOX = 36;
29
30
  const MUTED_LINE = alpha(VX.muted, 0.35);
31
+ const ZONE_X = {
32
+ zx: { channel: "x", scale: scaleLinear().domain([0, 1]), axis: false }
33
+ };
34
+ const BAND_FILL = alpha(VX.neutral, 0.2);
30
35
  const REFERENCE_LABEL_DX = 3;
31
36
  const LINE_PX_PER_POINT = 1;
32
37
  const BAR_PX_PER_BAR = 2;
@@ -56,6 +61,26 @@ function momentsOf(data) {
56
61
  return clockOnly ? readoutClock(d) : `${readoutDay(d)} ${readoutClock(d)}`;
57
62
  });
58
63
  }
64
+ function isDayWindow(data) {
65
+ const known = [];
66
+ for (const d of data) {
67
+ const at = typeof d === "object" && d !== null ? toDate(d.at) : null;
68
+ if (at !== null) known.push(at);
69
+ }
70
+ return known.length > 0 && dayGranular(known);
71
+ }
72
+ function spanOf(names) {
73
+ const first = names?.find((n) => n !== void 0);
74
+ const last = names?.findLast((n) => n !== void 0);
75
+ return first === void 0 || last === void 0 || first === last ? void 0 : `${first} \u2013 ${last}`;
76
+ }
77
+ function windowCaption(opts) {
78
+ const { prop, slot, data, labels, moments } = opts;
79
+ if (prop === false) return void 0;
80
+ if (prop !== void 0) return prop.trim() === "" ? void 0 : prop.trim();
81
+ if (slot === null || slot.compact === true) return void 0;
82
+ return spanOf(labels ?? (isDayWindow(data) ? moments : void 0));
83
+ }
59
84
  function extent(rows) {
60
85
  let lo = Number.POSITIVE_INFINITY;
61
86
  let hi = Number.NEGATIVE_INFINITY;
@@ -124,44 +149,67 @@ function poolSparkline(rows, width, mark) {
124
149
  if (width <= 0 || rows.length <= Math.max(cap, mark === "bar" ? 1 : 2)) return rows;
125
150
  return mark === "bar" ? poolBar(rows, cap) : poolLine(rows, cap);
126
151
  }
127
- function frameOf([lo, hi], mark, count, hasEnd) {
152
+ function frameOf([lo, hi], mark, count, hasEnd, banded = false) {
128
153
  if (mark === "bar") return { x: [0, count], y: [Math.min(lo, 0), Math.max(hi, 0) || 1] };
129
- const pad = (hi - lo) * 0.1 || 1;
154
+ const pad = (hi - lo) * (banded ? 0.25 : 0.1) || 1;
130
155
  const xPad = hasEnd ? (count - 1) * 0.04 || 0.5 : 0;
131
156
  return { x: [-xPad, Math.max(count - 1, 1) + xPad], y: [lo - pad, hi + pad] };
132
157
  }
133
- function compileSparkline(source, extentOf, mark, color, emphasisColor, reference, referenceLabel) {
134
- const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null);
135
- const referenceMark = (height) => reference === null ? [] : [
136
- ruleY([reference], {
137
- id: "reference",
138
- stroke: VX.line,
139
- strokeOpacity: 1,
140
- strokeWidth: 1,
141
- strokeDasharray: DASH
142
- }),
143
- ...referenceLabel === void 0 ? [] : [
144
- decorative(
145
- text([reference], {
146
- id: "reference-label",
147
- x: () => mark === "bar" ? 0 : frame.x[0],
148
- y: (v) => v,
149
- text: () => referenceLabel,
150
- fill: VX.ink2,
151
- fontSize: VX.text.micro,
152
- anchor: "start",
153
- dx: REFERENCE_LABEL_DX,
154
- dy: referenceLabelPlacement({
155
- value: reference,
156
- domain: frame.y,
157
- height,
158
- inset: mark === "bar" ? 0 : LINE_INSET,
159
- fontSize: VX.text.micro
160
- }).dy
161
- })
162
- )
163
- ]
158
+ function compileSparkline(source, extentOf, mark, color, emphasisColor, reference, referenceLabel, band, bandEdges) {
159
+ const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null, bandEdges);
160
+ const bandMark = () => band === null ? [] : [
161
+ decorative(
162
+ rect([band], {
163
+ id: "band",
164
+ x1: () => 0,
165
+ x2: () => 1,
166
+ xScale: "zx",
167
+ y1: "from",
168
+ y2: "to",
169
+ fill: BAND_FILL,
170
+ inset: 0
171
+ })
172
+ )
164
173
  ];
174
+ const referenceMark = (height, width, rows) => {
175
+ if (reference === null) return [];
176
+ const place = referenceLabel === void 0 ? null : referenceLabelPlacement({
177
+ value: reference,
178
+ domain: frame.y,
179
+ height,
180
+ width,
181
+ inset: mark === "bar" ? 0 : LINE_INSET,
182
+ fontSize: VX.text.micro,
183
+ label: referenceLabel,
184
+ line: mark === "bar" ? void 0 : rows.flatMap(
185
+ (r) => r.v === null ? [] : [{ fx: (r.i - frame.x[0]) / (frame.x[1] - frame.x[0]), y: r.v }]
186
+ )
187
+ });
188
+ return [
189
+ ruleY([reference], {
190
+ id: "reference",
191
+ stroke: VX.line,
192
+ strokeOpacity: 1,
193
+ strokeWidth: 1,
194
+ strokeDasharray: DASH
195
+ }),
196
+ ...referenceLabel === void 0 || place === null ? [] : [
197
+ decorative(
198
+ text([reference], {
199
+ id: "reference-label",
200
+ x: () => place.end === "end" ? frame.x[1] : mark === "bar" ? 0 : frame.x[0],
201
+ y: (v) => v,
202
+ text: () => referenceLabel,
203
+ fill: VX.ink2,
204
+ fontSize: VX.text.micro,
205
+ anchor: place.end,
206
+ dx: place.end === "end" ? -REFERENCE_LABEL_DX : REFERENCE_LABEL_DX,
207
+ dy: place.dy
208
+ })
209
+ )
210
+ ]
211
+ ];
212
+ };
165
213
  return {
166
214
  // A bar's hover is the bar and the readout chip: no engine point marker (bar chrome only, as
167
215
  // `Bars`).
@@ -172,7 +220,8 @@ function compileSparkline(source, extentOf, mark, color, emphasisColor, referenc
172
220
  if (mark === "bar") {
173
221
  return {
174
222
  marks: [
175
- ...referenceMark(height),
223
+ ...bandMark(),
224
+ ...referenceMark(height, width, rows),
176
225
  barMark(rows, {
177
226
  id: "bars",
178
227
  x: "i",
@@ -185,6 +234,8 @@ function compileSparkline(source, extentOf, mark, color, emphasisColor, referenc
185
234
  scale: scaleBand().domain(rows.map((r) => r.i)).padding(BAR_GAP),
186
235
  axis: false
187
236
  },
237
+ // The band spans the whole plot, outer half-bars included: a unit scale, not the band x.
238
+ ...ZONE_X,
188
239
  y: {
189
240
  scale: scaleLinear().domain(frame.y),
190
241
  axis: false
@@ -197,7 +248,8 @@ function compileSparkline(source, extentOf, mark, color, emphasisColor, referenc
197
248
  }
198
249
  return {
199
250
  marks: [
200
- ...referenceMark(height),
251
+ ...bandMark(),
252
+ ...referenceMark(height, width, rows),
201
253
  lineY(rows, {
202
254
  id: "line",
203
255
  x: "i",
@@ -217,6 +269,7 @@ function compileSparkline(source, extentOf, mark, color, emphasisColor, referenc
217
269
  scale: scaleLinear().domain(frame.x),
218
270
  axis: false
219
271
  },
272
+ ...ZONE_X,
220
273
  y: { scale: scaleLinear().domain(frame.y), axis: false }
221
274
  },
222
275
  theme: CHART_THEME,
@@ -369,17 +422,29 @@ function Sparkline(props) {
369
422
  state,
370
423
  reference,
371
424
  referenceLabel,
425
+ band,
372
426
  format = defaultNumberFormat,
373
427
  labels,
428
+ window: windowProp,
374
429
  className,
375
430
  style
376
431
  } = props;
377
432
  const id = useId();
378
- const hosted = useContext(VisualSlotContext) !== null;
433
+ const slot = useContext(VisualSlotContext);
434
+ const hosted = slot !== null;
435
+ const moments = useMemo(() => momentsOf(data), [data]);
436
+ const windowText = useMemo(
437
+ () => windowCaption({ prop: windowProp, slot, data, labels, moments }),
438
+ [windowProp, slot, data, labels, moments]
439
+ );
440
+ const labelInRow = windowText !== void 0 && referenceLabel !== void 0;
441
+ const plotLabel = labelInRow ? void 0 : referenceLabel;
379
442
  const [hover, setHover] = useState(null);
380
443
  const [keyed, setKeyed] = useState(null);
381
444
  const active = hover ?? keyed;
382
445
  const readoutRef = useRef(null);
446
+ const bandFrom = band?.from;
447
+ const bandTo = band?.to;
383
448
  const model = useMemo(() => {
384
449
  const rows2 = data.map((d, i) => ({
385
450
  i,
@@ -389,15 +454,44 @@ function Sparkline(props) {
389
454
  if (range === null) return null;
390
455
  const at2 = reference === "mean" ? meanOf(rows2) : reference ?? null;
391
456
  const ref = at2 !== null && Number.isFinite(at2) ? at2 : null;
392
- const full = ref === null ? range : [Math.min(range[0], ref), Math.max(range[1], ref)];
457
+ const bandSpan = bandFrom !== void 0 && bandTo !== void 0 && Number.isFinite(bandFrom + bandTo) && bandFrom !== bandTo ? { from: Math.min(bandFrom, bandTo), to: Math.max(bandFrom, bandTo) } : null;
458
+ const edges = [ref, bandSpan?.from, bandSpan?.to].filter(
459
+ (v) => typeof v === "number"
460
+ );
461
+ const full = [
462
+ Math.min(range[0], ...edges),
463
+ Math.max(range[1], ...edges)
464
+ ];
393
465
  const end = emphasizeLast ? emphasisColor : null;
466
+ const bandEdges = full[0] < range[0] || full[1] > range[1];
394
467
  return {
395
468
  rows: rows2,
396
- moments: momentsOf(data),
397
- frame: frameOf(full, mark, rows2.length, end !== null),
398
- definition: compileSparkline(rows2, full, mark, color, end, ref, referenceLabel)
469
+ moments,
470
+ frame: frameOf(full, mark, rows2.length, end !== null, bandSpan !== null && bandEdges),
471
+ definition: compileSparkline(
472
+ rows2,
473
+ full,
474
+ mark,
475
+ color,
476
+ end,
477
+ ref,
478
+ plotLabel,
479
+ bandSpan,
480
+ bandSpan !== null && bandEdges
481
+ )
399
482
  };
400
- }, [data, mark, color, emphasizeLast, emphasisColor, reference, referenceLabel]);
483
+ }, [
484
+ data,
485
+ moments,
486
+ mark,
487
+ color,
488
+ emphasizeLast,
489
+ emphasisColor,
490
+ reference,
491
+ plotLabel,
492
+ bandFrom,
493
+ bandTo
494
+ ]);
401
495
  const resolved = resolveChartState(state);
402
496
  const rows = model?.rows;
403
497
  const interactive = resolved === null && model !== null;
@@ -473,11 +567,12 @@ function Sparkline(props) {
473
567
  },
474
568
  ...at.fy > 0.5 ? { top: 0 } : { bottom: 0 }
475
569
  };
476
- return /* @__PURE__ */ jsxs(
570
+ const plot = /* @__PURE__ */ jsxs(
477
571
  "div",
478
572
  {
479
573
  "data-basalt-sparkline": "",
480
574
  ...hosted && { "data-basalt-hosted": "" },
575
+ ...shown && { "data-basalt-readout": "" },
481
576
  role: "presentation",
482
577
  className: cx(classes.root, className),
483
578
  style: { width: width ?? "100%", height, minWidth: 0, ...style },
@@ -490,7 +585,15 @@ function Sparkline(props) {
490
585
  setKeyed(null);
491
586
  },
492
587
  children: [
493
- resolved !== null && /* @__PURE__ */ jsx(ChartPlaceholder, { state, height, compact: true }),
588
+ resolved !== null && /* @__PURE__ */ jsx(
589
+ ChartPlaceholder,
590
+ {
591
+ state,
592
+ height,
593
+ compact: true,
594
+ ghost: mark === "bar" ? "bars" : "line"
595
+ }
596
+ ),
494
597
  resolved === null && model !== null && /* @__PURE__ */ jsx(
495
598
  ChartEngine,
496
599
  {
@@ -501,7 +604,7 @@ function Sparkline(props) {
501
604
  coarse: false
502
605
  }
503
606
  ),
504
- at !== null && // One layer on the plot rect (inside a line's margin): the dot and the readout take their
607
+ shown && at !== null && // One layer on the plot rect (inside a line's margin): the dot and the readout take their
505
608
  // fractions of the same box, so both land where the mark did. A bar has no dot: the bar
506
609
  // is the marker.
507
610
  /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", className: classes.layer, style: layerStyle, children: [
@@ -534,6 +637,14 @@ function Sparkline(props) {
534
637
  ]
535
638
  }
536
639
  );
640
+ if (windowText === void 0) return plot;
641
+ return /* @__PURE__ */ jsxs("div", { className: classes.frame, style: { width: width ?? "100%" }, children: [
642
+ plot,
643
+ /* @__PURE__ */ jsxs("div", { className: classes.caption, "data-basalt-sparkline-caption": "", children: [
644
+ /* @__PURE__ */ jsx("span", { "data-basalt-sparkline-window": "", children: windowText }),
645
+ labelInRow && /* @__PURE__ */ jsx("span", { className: classes.key, "data-basalt-sparkline-key": "", children: referenceLabel })
646
+ ] })
647
+ ] });
537
648
  }
538
649
  export {
539
650
  Sparkline,