@sdxc/ui 0.0.0-pre.1

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 (399) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +812 -0
  3. package/dist/animations/index.d.ts +12 -0
  4. package/dist/animations/index.js +12 -0
  5. package/dist/animations/keyframes.d.ts +162 -0
  6. package/dist/animations/keyframes.js +297 -0
  7. package/dist/animations/scroll.d.ts +154 -0
  8. package/dist/animations/scroll.js +228 -0
  9. package/dist/animations/tokens.d.ts +47 -0
  10. package/dist/animations/tokens.js +47 -0
  11. package/dist/animations/transitions.d.ts +143 -0
  12. package/dist/animations/transitions.js +147 -0
  13. package/dist/behaviors/announcer.d.ts +90 -0
  14. package/dist/behaviors/announcer.js +93 -0
  15. package/dist/behaviors/calendar-model.d.ts +218 -0
  16. package/dist/behaviors/calendar-model.js +376 -0
  17. package/dist/behaviors/drag-session.d.ts +119 -0
  18. package/dist/behaviors/drag-session.js +110 -0
  19. package/dist/behaviors/filter-model.d.ts +117 -0
  20. package/dist/behaviors/filter-model.js +185 -0
  21. package/dist/behaviors/index.d.ts +16 -0
  22. package/dist/behaviors/index.js +16 -0
  23. package/dist/behaviors/resize-session.d.ts +115 -0
  24. package/dist/behaviors/resize-session.js +157 -0
  25. package/dist/behaviors/scroll-follow-model.d.ts +180 -0
  26. package/dist/behaviors/scroll-follow-model.js +197 -0
  27. package/dist/behaviors/selection-model.d.ts +129 -0
  28. package/dist/behaviors/selection-model.js +259 -0
  29. package/dist/behaviors/toaster.d.ts +144 -0
  30. package/dist/behaviors/toaster.js +228 -0
  31. package/dist/components/accordion.d.ts +93 -0
  32. package/dist/components/accordion.js +165 -0
  33. package/dist/components/alert-dialog.d.ts +110 -0
  34. package/dist/components/alert-dialog.js +169 -0
  35. package/dist/components/alert.d.ts +109 -0
  36. package/dist/components/alert.js +160 -0
  37. package/dist/components/aspect-ratio.d.ts +44 -0
  38. package/dist/components/aspect-ratio.js +35 -0
  39. package/dist/components/attachment.d.ts +146 -0
  40. package/dist/components/attachment.js +320 -0
  41. package/dist/components/avatar.d.ts +118 -0
  42. package/dist/components/avatar.js +89 -0
  43. package/dist/components/badge.d.ts +66 -0
  44. package/dist/components/badge.js +129 -0
  45. package/dist/components/breadcrumbs.d.ts +67 -0
  46. package/dist/components/breadcrumbs.js +121 -0
  47. package/dist/components/bubble.d.ts +91 -0
  48. package/dist/components/bubble.js +216 -0
  49. package/dist/components/button.d.ts +78 -0
  50. package/dist/components/button.js +207 -0
  51. package/dist/components/calendar.d.ts +166 -0
  52. package/dist/components/calendar.js +320 -0
  53. package/dist/components/card.d.ts +82 -0
  54. package/dist/components/card.js +126 -0
  55. package/dist/components/carousel.d.ts +96 -0
  56. package/dist/components/carousel.js +214 -0
  57. package/dist/components/chart.d.ts +485 -0
  58. package/dist/components/chart.js +563 -0
  59. package/dist/components/checkbox-group.d.ts +58 -0
  60. package/dist/components/checkbox-group.js +53 -0
  61. package/dist/components/checkbox.d.ts +61 -0
  62. package/dist/components/checkbox.js +81 -0
  63. package/dist/components/color-area.d.ts +83 -0
  64. package/dist/components/color-area.js +251 -0
  65. package/dist/components/color-field.d.ts +128 -0
  66. package/dist/components/color-field.js +73 -0
  67. package/dist/components/color-picker.d.ts +132 -0
  68. package/dist/components/color-picker.js +183 -0
  69. package/dist/components/color-slider.d.ts +103 -0
  70. package/dist/components/color-slider.js +198 -0
  71. package/dist/components/color-swatch-picker.d.ts +106 -0
  72. package/dist/components/color-swatch-picker.js +75 -0
  73. package/dist/components/color-swatch.d.ts +57 -0
  74. package/dist/components/color-swatch.js +82 -0
  75. package/dist/components/color-wheel.d.ts +58 -0
  76. package/dist/components/color-wheel.js +160 -0
  77. package/dist/components/combobox.d.ts +73 -0
  78. package/dist/components/combobox.js +108 -0
  79. package/dist/components/command.d.ts +80 -0
  80. package/dist/components/command.js +151 -0
  81. package/dist/components/confirm.d.ts +124 -0
  82. package/dist/components/confirm.js +56 -0
  83. package/dist/components/context-menu.d.ts +108 -0
  84. package/dist/components/context-menu.js +200 -0
  85. package/dist/components/date-field.d.ts +110 -0
  86. package/dist/components/date-field.js +49 -0
  87. package/dist/components/date-picker.d.ts +136 -0
  88. package/dist/components/date-picker.js +155 -0
  89. package/dist/components/date-range-picker.d.ts +152 -0
  90. package/dist/components/date-range-picker.js +106 -0
  91. package/dist/components/description.d.ts +36 -0
  92. package/dist/components/description.js +21 -0
  93. package/dist/components/dialog.d.ts +97 -0
  94. package/dist/components/dialog.js +203 -0
  95. package/dist/components/disclosure.d.ts +85 -0
  96. package/dist/components/disclosure.js +180 -0
  97. package/dist/components/drawer.d.ts +82 -0
  98. package/dist/components/drawer.js +162 -0
  99. package/dist/components/drop-indicator.d.ts +43 -0
  100. package/dist/components/drop-indicator.js +47 -0
  101. package/dist/components/drop-zone.d.ts +73 -0
  102. package/dist/components/drop-zone.js +54 -0
  103. package/dist/components/empty.d.ts +89 -0
  104. package/dist/components/empty.js +129 -0
  105. package/dist/components/field-error.d.ts +41 -0
  106. package/dist/components/field-error.js +36 -0
  107. package/dist/components/file-trigger.d.ts +84 -0
  108. package/dist/components/file-trigger.js +169 -0
  109. package/dist/components/form.d.ts +118 -0
  110. package/dist/components/form.js +113 -0
  111. package/dist/components/grid-list.d.ts +112 -0
  112. package/dist/components/grid-list.js +220 -0
  113. package/dist/components/group.d.ts +45 -0
  114. package/dist/components/group.js +44 -0
  115. package/dist/components/header.d.ts +33 -0
  116. package/dist/components/header.js +29 -0
  117. package/dist/components/heading-scope.d.ts +83 -0
  118. package/dist/components/heading-scope.js +82 -0
  119. package/dist/components/heading.d.ts +50 -0
  120. package/dist/components/heading.js +31 -0
  121. package/dist/components/hover-card.d.ts +77 -0
  122. package/dist/components/hover-card.js +151 -0
  123. package/dist/components/image-placeholder.d.ts +105 -0
  124. package/dist/components/image-placeholder.js +212 -0
  125. package/dist/components/index.d.ts +109 -0
  126. package/dist/components/index.js +109 -0
  127. package/dist/components/input.d.ts +53 -0
  128. package/dist/components/input.js +76 -0
  129. package/dist/components/item.d.ts +97 -0
  130. package/dist/components/item.js +185 -0
  131. package/dist/components/keyboard.d.ts +33 -0
  132. package/dist/components/keyboard.js +20 -0
  133. package/dist/components/label.d.ts +38 -0
  134. package/dist/components/label.js +24 -0
  135. package/dist/components/link-button.d.ts +59 -0
  136. package/dist/components/link-button.js +174 -0
  137. package/dist/components/link.d.ts +43 -0
  138. package/dist/components/link.js +85 -0
  139. package/dist/components/listbox.d.ts +119 -0
  140. package/dist/components/listbox.js +114 -0
  141. package/dist/components/logo.d.ts +117 -0
  142. package/dist/components/logo.js +89 -0
  143. package/dist/components/marker.d.ts +82 -0
  144. package/dist/components/marker.js +163 -0
  145. package/dist/components/menu.d.ts +90 -0
  146. package/dist/components/menu.js +146 -0
  147. package/dist/components/menubar.d.ts +54 -0
  148. package/dist/components/menubar.js +118 -0
  149. package/dist/components/message-scroller.d.ts +109 -0
  150. package/dist/components/message-scroller.js +180 -0
  151. package/dist/components/message.d.ts +104 -0
  152. package/dist/components/message.js +200 -0
  153. package/dist/components/meter.d.ts +60 -0
  154. package/dist/components/meter.js +110 -0
  155. package/dist/components/modal.d.ts +71 -0
  156. package/dist/components/modal.js +120 -0
  157. package/dist/components/nav-link.d.ts +53 -0
  158. package/dist/components/nav-link.js +83 -0
  159. package/dist/components/navigation-menu.d.ts +150 -0
  160. package/dist/components/navigation-menu.js +381 -0
  161. package/dist/components/number-field.d.ts +76 -0
  162. package/dist/components/number-field.js +190 -0
  163. package/dist/components/otp-field.d.ts +68 -0
  164. package/dist/components/otp-field.js +46 -0
  165. package/dist/components/overlay-arrow.d.ts +51 -0
  166. package/dist/components/overlay-arrow.js +77 -0
  167. package/dist/components/pagination.d.ts +67 -0
  168. package/dist/components/pagination.js +164 -0
  169. package/dist/components/popover.d.ts +69 -0
  170. package/dist/components/popover.js +68 -0
  171. package/dist/components/progress-bar.d.ts +53 -0
  172. package/dist/components/progress-bar.js +90 -0
  173. package/dist/components/radio-group.d.ts +102 -0
  174. package/dist/components/radio-group.js +114 -0
  175. package/dist/components/range-calendar.d.ts +169 -0
  176. package/dist/components/range-calendar.js +216 -0
  177. package/dist/components/resizable.d.ts +98 -0
  178. package/dist/components/resizable.js +151 -0
  179. package/dist/components/scroll-area.d.ts +54 -0
  180. package/dist/components/scroll-area.js +89 -0
  181. package/dist/components/search-field.d.ts +55 -0
  182. package/dist/components/search-field.js +49 -0
  183. package/dist/components/section.d.ts +37 -0
  184. package/dist/components/section.js +22 -0
  185. package/dist/components/select.d.ts +96 -0
  186. package/dist/components/select.js +285 -0
  187. package/dist/components/selection-indicator.d.ts +47 -0
  188. package/dist/components/selection-indicator.js +50 -0
  189. package/dist/components/sentinel-row.d.ts +22 -0
  190. package/dist/components/sentinel-row.js +29 -0
  191. package/dist/components/separator.d.ts +35 -0
  192. package/dist/components/separator.js +48 -0
  193. package/dist/components/shared-element.d.ts +45 -0
  194. package/dist/components/shared-element.js +48 -0
  195. package/dist/components/sheet.d.ts +78 -0
  196. package/dist/components/sheet.js +167 -0
  197. package/dist/components/sidebar.d.ts +288 -0
  198. package/dist/components/sidebar.js +1068 -0
  199. package/dist/components/skeleton.d.ts +36 -0
  200. package/dist/components/skeleton.js +38 -0
  201. package/dist/components/slider.d.ts +102 -0
  202. package/dist/components/slider.js +179 -0
  203. package/dist/components/spinner.d.ts +55 -0
  204. package/dist/components/spinner.js +51 -0
  205. package/dist/components/switch.d.ts +47 -0
  206. package/dist/components/switch.js +82 -0
  207. package/dist/components/table.d.ts +139 -0
  208. package/dist/components/table.js +216 -0
  209. package/dist/components/tabs.d.ts +124 -0
  210. package/dist/components/tabs.js +246 -0
  211. package/dist/components/tag-group.d.ts +83 -0
  212. package/dist/components/tag-group.js +157 -0
  213. package/dist/components/text-field.d.ts +119 -0
  214. package/dist/components/text-field.js +51 -0
  215. package/dist/components/text.d.ts +34 -0
  216. package/dist/components/text.js +19 -0
  217. package/dist/components/textarea.d.ts +52 -0
  218. package/dist/components/textarea.js +82 -0
  219. package/dist/components/time-field.d.ts +110 -0
  220. package/dist/components/time-field.js +48 -0
  221. package/dist/components/toast.d.ts +149 -0
  222. package/dist/components/toast.js +365 -0
  223. package/dist/components/toggle-button.d.ts +115 -0
  224. package/dist/components/toggle-button.js +237 -0
  225. package/dist/components/toolbar.d.ts +47 -0
  226. package/dist/components/toolbar.js +54 -0
  227. package/dist/components/tooltip.d.ts +52 -0
  228. package/dist/components/tooltip.js +92 -0
  229. package/dist/components/tree.d.ts +123 -0
  230. package/dist/components/tree.js +239 -0
  231. package/dist/components/typeset.d.ts +53 -0
  232. package/dist/components/typeset.js +271 -0
  233. package/dist/index.d.ts +8 -0
  234. package/dist/index.js +8 -0
  235. package/dist/mixins/aria-checked.d.ts +42 -0
  236. package/dist/mixins/aria-checked.js +127 -0
  237. package/dist/mixins/attachment-trigger.d.ts +64 -0
  238. package/dist/mixins/attachment-trigger.js +190 -0
  239. package/dist/mixins/calendar-keys.d.ts +27 -0
  240. package/dist/mixins/calendar-keys.js +113 -0
  241. package/dist/mixins/carousel-controls.d.ts +30 -0
  242. package/dist/mixins/carousel-controls.js +222 -0
  243. package/dist/mixins/chart-tooltip.d.ts +118 -0
  244. package/dist/mixins/chart-tooltip.js +323 -0
  245. package/dist/mixins/clear-field.d.ts +60 -0
  246. package/dist/mixins/clear-field.js +100 -0
  247. package/dist/mixins/color-area-drag.d.ts +58 -0
  248. package/dist/mixins/color-area-drag.js +162 -0
  249. package/dist/mixins/color-channel-sync.d.ts +73 -0
  250. package/dist/mixins/color-channel-sync.js +169 -0
  251. package/dist/mixins/color-preview.d.ts +28 -0
  252. package/dist/mixins/color-preview.js +77 -0
  253. package/dist/mixins/color-wheel-drag.d.ts +58 -0
  254. package/dist/mixins/color-wheel-drag.js +139 -0
  255. package/dist/mixins/combobox-filter.d.ts +59 -0
  256. package/dist/mixins/combobox-filter.js +81 -0
  257. package/dist/mixins/command-filter.d.ts +55 -0
  258. package/dist/mixins/command-filter.js +121 -0
  259. package/dist/mixins/command-keys.d.ts +31 -0
  260. package/dist/mixins/command-keys.js +116 -0
  261. package/dist/mixins/context-menu.d.ts +24 -0
  262. package/dist/mixins/context-menu.js +64 -0
  263. package/dist/mixins/copy-to-clipboard.d.ts +64 -0
  264. package/dist/mixins/copy-to-clipboard.js +109 -0
  265. package/dist/mixins/dismiss.d.ts +77 -0
  266. package/dist/mixins/dismiss.js +151 -0
  267. package/dist/mixins/drag-reorder.d.ts +88 -0
  268. package/dist/mixins/drag-reorder.js +214 -0
  269. package/dist/mixins/drop-zone.d.ts +52 -0
  270. package/dist/mixins/drop-zone.js +132 -0
  271. package/dist/mixins/dual-range.d.ts +60 -0
  272. package/dist/mixins/dual-range.js +100 -0
  273. package/dist/mixins/grid-list-keys.d.ts +34 -0
  274. package/dist/mixins/grid-list-keys.js +260 -0
  275. package/dist/mixins/heading-level-fallback.d.ts +81 -0
  276. package/dist/mixins/heading-level-fallback.js +112 -0
  277. package/dist/mixins/hotkey.d.ts +26 -0
  278. package/dist/mixins/hotkey.js +132 -0
  279. package/dist/mixins/image-fallback.d.ts +57 -0
  280. package/dist/mixins/image-fallback.js +86 -0
  281. package/dist/mixins/index.d.ts +48 -0
  282. package/dist/mixins/index.js +48 -0
  283. package/dist/mixins/listbox-keys.d.ts +52 -0
  284. package/dist/mixins/listbox-keys.js +63 -0
  285. package/dist/mixins/long-press.d.ts +76 -0
  286. package/dist/mixins/long-press.js +130 -0
  287. package/dist/mixins/menu-keys.d.ts +40 -0
  288. package/dist/mixins/menu-keys.js +117 -0
  289. package/dist/mixins/menubar-keys.d.ts +59 -0
  290. package/dist/mixins/menubar-keys.js +230 -0
  291. package/dist/mixins/message-follow.d.ts +56 -0
  292. package/dist/mixins/message-follow.js +368 -0
  293. package/dist/mixins/otp-slots.d.ts +53 -0
  294. package/dist/mixins/otp-slots.js +175 -0
  295. package/dist/mixins/persist.d.ts +36 -0
  296. package/dist/mixins/persist.js +78 -0
  297. package/dist/mixins/press-toggle.d.ts +43 -0
  298. package/dist/mixins/press-toggle.js +61 -0
  299. package/dist/mixins/range-preview.d.ts +26 -0
  300. package/dist/mixins/range-preview.js +120 -0
  301. package/dist/mixins/resize-handle.d.ts +101 -0
  302. package/dist/mixins/resize-handle.js +288 -0
  303. package/dist/mixins/stepper.d.ts +81 -0
  304. package/dist/mixins/stepper.js +194 -0
  305. package/dist/mixins/tab-keys.d.ts +30 -0
  306. package/dist/mixins/tab-keys.js +63 -0
  307. package/dist/mixins/theme-toggle.d.ts +82 -0
  308. package/dist/mixins/theme-toggle.js +158 -0
  309. package/dist/mixins/track-host-node.d.ts +34 -0
  310. package/dist/mixins/track-host-node.js +42 -0
  311. package/dist/mixins/treeKeys.d.ts +57 -0
  312. package/dist/mixins/treeKeys.js +266 -0
  313. package/dist/mixins/validate.d.ts +65 -0
  314. package/dist/mixins/validate.js +139 -0
  315. package/dist/mixins/view-transition.d.ts +56 -0
  316. package/dist/mixins/view-transition.js +111 -0
  317. package/dist/styles/chart-palette.d.ts +34 -0
  318. package/dist/styles/chart-palette.js +27 -0
  319. package/dist/styles/field-stack-layout.d.ts +27 -0
  320. package/dist/styles/field-stack-layout.js +16 -0
  321. package/dist/styles/floating-surface.d.ts +32 -0
  322. package/dist/styles/floating-surface.js +30 -0
  323. package/dist/styles/graphic-host.d.ts +25 -0
  324. package/dist/styles/graphic-host.js +18 -0
  325. package/dist/styles/index.d.ts +20 -0
  326. package/dist/styles/index.js +20 -0
  327. package/dist/styles/interactive-transition.d.ts +32 -0
  328. package/dist/styles/interactive-transition.js +32 -0
  329. package/dist/styles/legend-toggle.d.ts +29 -0
  330. package/dist/styles/legend-toggle.js +24 -0
  331. package/dist/styles/output-caption-text.d.ts +22 -0
  332. package/dist/styles/output-caption-text.js +15 -0
  333. package/dist/styles/panel-chrome.d.ts +34 -0
  334. package/dist/styles/panel-chrome.js +26 -0
  335. package/dist/styles/range-thumb-appearance.d.ts +36 -0
  336. package/dist/styles/range-thumb-appearance.js +76 -0
  337. package/dist/styles/rtl-aware-gradient-direction.d.ts +28 -0
  338. package/dist/styles/rtl-aware-gradient-direction.js +28 -0
  339. package/dist/styles/semantic-color-panel.d.ts +35 -0
  340. package/dist/styles/semantic-color-panel.js +41 -0
  341. package/dist/utils/chart-marker-indices.d.ts +22 -0
  342. package/dist/utils/chart-marker-indices.js +45 -0
  343. package/dist/utils/chart-path.d.ts +86 -0
  344. package/dist/utils/chart-path.js +122 -0
  345. package/dist/utils/chart-scale.d.ts +182 -0
  346. package/dist/utils/chart-scale.js +221 -0
  347. package/dist/utils/color-math.d.ts +252 -0
  348. package/dist/utils/color-math.js +480 -0
  349. package/dist/utils/command-event.d.ts +24 -0
  350. package/dist/utils/command-event.js +26 -0
  351. package/dist/utils/css-styles.d.ts +21 -0
  352. package/dist/utils/css-styles.js +11 -0
  353. package/dist/utils/decorative-icon.d.ts +15 -0
  354. package/dist/utils/decorative-icon.js +15 -0
  355. package/dist/utils/disabled-selector.d.ts +22 -0
  356. package/dist/utils/disabled-selector.js +22 -0
  357. package/dist/utils/dispatch-change.d.ts +17 -0
  358. package/dist/utils/dispatch-change.js +19 -0
  359. package/dist/utils/field-parts.d.ts +26 -0
  360. package/dist/utils/field-parts.js +12 -0
  361. package/dist/utils/full-turn-radians.d.ts +16 -0
  362. package/dist/utils/full-turn-radians.js +16 -0
  363. package/dist/utils/geometry.d.ts +14 -0
  364. package/dist/utils/geometry.js +9 -0
  365. package/dist/utils/has-accessible-text.d.ts +19 -0
  366. package/dist/utils/has-accessible-text.js +30 -0
  367. package/dist/utils/hue-spectrum.d.ts +19 -0
  368. package/dist/utils/hue-spectrum.js +19 -0
  369. package/dist/utils/index.d.ts +35 -0
  370. package/dist/utils/index.js +35 -0
  371. package/dist/utils/is-new-primary-press.d.ts +29 -0
  372. package/dist/utils/is-new-primary-press.js +31 -0
  373. package/dist/utils/keyboard-nav.d.ts +64 -0
  374. package/dist/utils/keyboard-nav.js +79 -0
  375. package/dist/utils/merge-style.d.ts +33 -0
  376. package/dist/utils/merge-style.js +30 -0
  377. package/dist/utils/paired-range-inputs.d.ts +26 -0
  378. package/dist/utils/paired-range-inputs.js +29 -0
  379. package/dist/utils/placement.d.ts +18 -0
  380. package/dist/utils/placement.js +12 -0
  381. package/dist/utils/prefers-reduced-motion.d.ts +17 -0
  382. package/dist/utils/prefers-reduced-motion.js +19 -0
  383. package/dist/utils/resolve-field-wiring.d.ts +83 -0
  384. package/dist/utils/resolve-field-wiring.js +53 -0
  385. package/dist/utils/resolve-fill-percent.d.ts +28 -0
  386. package/dist/utils/resolve-fill-percent.js +34 -0
  387. package/dist/utils/round-precision.d.ts +22 -0
  388. package/dist/utils/round-precision.js +25 -0
  389. package/dist/utils/semantic-color-panel.d.ts +35 -0
  390. package/dist/utils/semantic-color-panel.js +28 -0
  391. package/dist/utils/semantic-color.d.ts +17 -0
  392. package/dist/utils/semantic-color.js +11 -0
  393. package/dist/utils/warn-if-no-accessible-name.d.ts +52 -0
  394. package/dist/utils/warn-if-no-accessible-name.js +55 -0
  395. package/dist/utils/write-cookie.d.ts +35 -0
  396. package/dist/utils/write-cookie.js +37 -0
  397. package/package.json +32 -0
  398. package/src/reset.css +223 -0
  399. package/src/theme.css +146 -0
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Handles the `--ui-prev`, `--ui-next`, and `--ui-goto` commands a Carousel's
3
+ * invoker buttons dispatch at its viewport, turning each into an
4
+ * `Element.scrollBy()` call, and keeps every matching invoker's `disabled`
5
+ * state in sync with whichever scroll edge the viewport currently sits at.
6
+ *
7
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
8
+ * @copyright Sergio Xalambrí 2026
9
+ */
10
+ import { createElement, createMixin, on } from "remix/ui";
11
+ import { asCommandEvent } from "../utils/command-event.js";
12
+ /** Command a Previous-slide invoker button dispatches at the Carousel viewport. */
13
+ const PREV_COMMAND = "--ui-prev";
14
+ /** Command a Next-slide invoker button dispatches at the Carousel viewport. */
15
+ const NEXT_COMMAND = "--ui-next";
16
+ /**
17
+ * Command a pagination invoker button dispatches at the Carousel viewport,
18
+ * carrying the zero-based index of its target slide as `event.source.dataset.slide`.
19
+ */
20
+ const GOTO_COMMAND = "--ui-goto";
21
+ /**
22
+ * Attribute every Carousel slide exposes itself on. {@link carouselControls}
23
+ * queries every element carrying this attribute beneath the viewport, in
24
+ * document order, to resolve the slide a `--ui-goto` command targets.
25
+ */
26
+ export const CAROUSEL_SLIDE_ATTRIBUTE = "data-carousel-slide";
27
+ /**
28
+ * How many pixels of rounding error `scrollLeft` may still sit at from a true
29
+ * scroll edge and count as having reached it, so sub-pixel layout rounding
30
+ * never leaves both — or neither — of a pair of invoker buttons enabled.
31
+ */
32
+ const EDGE_TOLERANCE_PX = 1;
33
+ /**
34
+ * Resolves the animation to scroll a Carousel command with. `scrollBy()`'s
35
+ * smooth-scroll rides the platform's own animation, not a CSS transition, so
36
+ * it never picks up the reduced-motion override applied there.
37
+ *
38
+ * @returns `"instant"` when the user prefers reduced motion, `"smooth"` otherwise.
39
+ */
40
+ function resolveScrollBehavior() {
41
+ return window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth";
42
+ }
43
+ /**
44
+ * Reports whether `node` renders in a right-to-left writing direction, so
45
+ * scroll math can flip which physical direction counts as "previous" and
46
+ * "next" in reading order.
47
+ *
48
+ * @param node Element whose computed direction is read.
49
+ */
50
+ function isRightToLeft(node) {
51
+ return getComputedStyle(node).direction === "rtl";
52
+ }
53
+ /**
54
+ * Furthest a scroll container can move along its inline axis: the gap
55
+ * between its full content width and the width actually visible at once.
56
+ *
57
+ * @param node Scroll container to measure.
58
+ */
59
+ function getMaxScrollLeft(node) {
60
+ return Math.max(0, node.scrollWidth - node.clientWidth);
61
+ }
62
+ /**
63
+ * Classifies whether `node` has scrolled to the reading-order start (nothing
64
+ * left for `--ui-prev`) or end (nothing left for `--ui-next`), normalizing
65
+ * `scrollLeft`'s right-to-left sign flip into a 0-to-max reading position.
66
+ *
67
+ * @param node Scroll container to read the current position of.
68
+ */
69
+ function readScrollEdges(node) {
70
+ let maxScrollLeft = getMaxScrollLeft(node);
71
+ let readingPosition = isRightToLeft(node) ? -node.scrollLeft : node.scrollLeft;
72
+ return {
73
+ atStart: readingPosition <= EDGE_TOLERANCE_PX,
74
+ atEnd: readingPosition >= maxScrollLeft - EDGE_TOLERANCE_PX,
75
+ };
76
+ }
77
+ /**
78
+ * Scrolls `node` by one full viewport page in the given reading-order
79
+ * direction, flipping the physical sign under a right-to-left direction so
80
+ * "forward" always advances in reading order regardless of `dir`.
81
+ *
82
+ * @param node Carousel viewport to scroll.
83
+ * @param direction `-1` for a `--ui-prev` command, `1` for `--ui-next`.
84
+ */
85
+ function scrollByPage(node, direction) {
86
+ let sign = isRightToLeft(node) ? -direction : direction;
87
+ node.scrollBy({ left: sign * node.clientWidth, behavior: resolveScrollBehavior() });
88
+ }
89
+ /**
90
+ * Scrolls `node` so the slide at `index` among its
91
+ * {@link CAROUSEL_SLIDE_ATTRIBUTE} descendants moves to the viewport's start
92
+ * edge, accounting for `node`'s right-to-left direction.
93
+ *
94
+ * @param node Carousel viewport to scroll.
95
+ * @param index Zero-based position of the target slide, in document order.
96
+ */
97
+ function scrollToSlide(node, index) {
98
+ let slides = node.querySelectorAll(`[${CAROUSEL_SLIDE_ATTRIBUTE}]`);
99
+ let slide = slides[index];
100
+ if (slide === undefined)
101
+ return;
102
+ let targetScrollLeft = isRightToLeft(node)
103
+ ? slide.offsetLeft - getMaxScrollLeft(node)
104
+ : slide.offsetLeft;
105
+ node.scrollBy({
106
+ left: targetScrollLeft - node.scrollLeft,
107
+ behavior: resolveScrollBehavior(),
108
+ });
109
+ }
110
+ /**
111
+ * Parses a `--ui-goto` command's target slide index from its invoking
112
+ * button's `data-slide` attribute.
113
+ *
114
+ * @param source Invoking element the `command` event names as its `source`.
115
+ * @returns The parsed zero-based index, or `null` when `source` carries no valid one.
116
+ */
117
+ function readGotoSlideIndex(source) {
118
+ if (!(source instanceof HTMLElement))
119
+ return null;
120
+ let raw = source.dataset.slide;
121
+ if (raw === undefined)
122
+ return null;
123
+ let index = Number(raw);
124
+ return Number.isInteger(index) && index >= 0 ? index : null;
125
+ }
126
+ /**
127
+ * Finds every invoker button targeting `node` through `commandfor`, narrowed
128
+ * to whichever carries `command`. Invoker buttons can render anywhere in the
129
+ * document, so this searches the whole document, not just `node`'s descendants.
130
+ *
131
+ * @param node Carousel viewport the invoker buttons target.
132
+ * @param command `--ui-prev` or `--ui-next`, the command to filter for.
133
+ */
134
+ function findInvokerButtons(node, command) {
135
+ if (node.id === "")
136
+ return [];
137
+ let candidates = document.querySelectorAll(`[commandfor="${CSS.escape(node.id)}"]`);
138
+ let buttons = [];
139
+ for (let candidate of candidates) {
140
+ if (candidate instanceof HTMLButtonElement && candidate.getAttribute("command") === command) {
141
+ buttons.push(candidate);
142
+ }
143
+ }
144
+ return buttons;
145
+ }
146
+ /**
147
+ * Applies, or clears, an invoker button's disabled state: sets the native
148
+ * `disabled` property, which drops it from tab order and stops it dispatching
149
+ * its command, and mirrors it onto `aria-disabled` to match the contract.
150
+ *
151
+ * @param button Invoker button to update.
152
+ * @param disabled Whether the button's target direction has nothing left to scroll toward.
153
+ */
154
+ function setInvokerDisabled(button, disabled) {
155
+ button.disabled = disabled;
156
+ if (disabled)
157
+ button.setAttribute("aria-disabled", "true");
158
+ else
159
+ button.removeAttribute("aria-disabled");
160
+ }
161
+ /**
162
+ * Mirrors `node`'s current scroll position onto every `--ui-prev`/`--ui-next`
163
+ * invoker button targeting it, disabling whichever direction has nothing left
164
+ * to scroll toward.
165
+ *
166
+ * @param node Carousel viewport whose scroll edges are read.
167
+ */
168
+ function syncInvokerDisabled(node) {
169
+ let { atStart, atEnd } = readScrollEdges(node);
170
+ for (let button of findInvokerButtons(node, PREV_COMMAND))
171
+ setInvokerDisabled(button, atStart);
172
+ for (let button of findInvokerButtons(node, NEXT_COMMAND))
173
+ setInvokerDisabled(button, atEnd);
174
+ }
175
+ /**
176
+ * Adds `--ui-prev`/`--ui-next`/`--ui-goto` command handling to a Carousel
177
+ * viewport, scrolling by page or to a `data-slide` index and re-syncing every
178
+ * invoker button's disabled state on every command, scroll, and resize.
179
+ *
180
+ * @example
181
+ * <div id="cart-carousel" mix={carouselControls()}>
182
+ * <div data-carousel-slide>Slide 1</div>
183
+ * <div data-carousel-slide>Slide 2</div>
184
+ * </div>
185
+ * <button commandfor="cart-carousel" command="--ui-prev">Previous</button>
186
+ * <button commandfor="cart-carousel" command="--ui-next">Next</button>
187
+ * <button commandfor="cart-carousel" command="--ui-goto" data-slide="1">Slide 2</button>
188
+ */
189
+ export const carouselControls = createMixin((handle) => {
190
+ handle.addEventListener("insert", (event) => {
191
+ let viewport = event.node;
192
+ syncInvokerDisabled(viewport);
193
+ let observer = new ResizeObserver(() => syncInvokerDisabled(viewport));
194
+ observer.observe(viewport);
195
+ handle.signal.addEventListener("abort", () => observer.disconnect());
196
+ });
197
+ return () => createElement(handle.element, {
198
+ mix: [
199
+ on("command", (event) => {
200
+ let commandEvent = asCommandEvent(event);
201
+ let viewport = event.currentTarget;
202
+ switch (commandEvent.command) {
203
+ case PREV_COMMAND:
204
+ scrollByPage(viewport, -1);
205
+ return;
206
+ case NEXT_COMMAND:
207
+ scrollByPage(viewport, 1);
208
+ return;
209
+ case GOTO_COMMAND: {
210
+ let index = readGotoSlideIndex(commandEvent.source);
211
+ if (index !== null)
212
+ scrollToSlide(viewport, index);
213
+ return;
214
+ }
215
+ }
216
+ }),
217
+ on("scroll", (event) => {
218
+ syncInvokerDisabled(event.currentTarget);
219
+ }),
220
+ ],
221
+ });
222
+ });
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Bridges a Chart.Bar, Chart.Line, Chart.Area, or Chart.Pie root to its
3
+ * sibling Chart.Tooltip surface: tracks whichever plotted point the pointer
4
+ * or keyboard focus currently resolves to, and mirrors it onto
5
+ * Chart.Tooltip's rows and position.
6
+ *
7
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
8
+ * @copyright Sergio Xalambrí 2026
9
+ */
10
+ import type { MixinFactory } from "remix/ui";
11
+ /**
12
+ * Attribute every plottable point a chart root renders carries: a bar's
13
+ * `<rect>`, a line or area's vertex marker, or a pie's wedge `<path>`.
14
+ * `chartTooltip()` reads it to build its pointer-tracked candidate set.
15
+ */
16
+ export declare const CHART_POINT_ATTRIBUTE = "data-chart-point";
17
+ /**
18
+ * Attribute a point carries its already-localized label on — the category,
19
+ * series name, or slice name a chart renders it under. `chartTooltip()`
20
+ * copies it unchanged into the matching row's {@link CHART_TOOLTIP_LABEL_ATTRIBUTE}.
21
+ */
22
+ export declare const CHART_POINT_LABEL_ATTRIBUTE = "data-chart-label";
23
+ /**
24
+ * Attribute a point carries its already-formatted value on, rendered through
25
+ * the consumer's own `Intl` formatting. `chartTooltip()` copies it unchanged
26
+ * into the matching row's {@link CHART_TOOLTIP_VALUE_ATTRIBUTE} slot.
27
+ */
28
+ export declare const CHART_POINT_VALUE_ATTRIBUTE = "data-chart-value";
29
+ /**
30
+ * Attribute an ancestor of a cluster of related points carries — every
31
+ * series' point for one category in a grouped bar chart. Every point beneath
32
+ * the nearest such ancestor populates the tooltip together, one row each.
33
+ */
34
+ export declare const CHART_POINT_GROUP_ATTRIBUTE = "data-chart-group";
35
+ /**
36
+ * Attribute Chart.Tooltip's own root element carries. `chartTooltip()` finds
37
+ * it among its host's parent element's descendants — the sibling
38
+ * relationship a chart root and its Chart.Tooltip render in.
39
+ */
40
+ export declare const CHART_TOOLTIP_ATTRIBUTE = "data-chart-tooltip";
41
+ /**
42
+ * Attribute every pre-rendered row inside Chart.Tooltip carries, one per
43
+ * series it could ever need to show, in document order. `chartTooltip()`
44
+ * fills as many as the active point set holds and hides the rest.
45
+ */
46
+ export declare const CHART_TOOLTIP_ROW_ATTRIBUTE = "data-chart-tooltip-row";
47
+ /**
48
+ * Attribute the element inside a Chart.Tooltip row that receives the active
49
+ * point's {@link CHART_POINT_LABEL_ATTRIBUTE} text carries.
50
+ */
51
+ export declare const CHART_TOOLTIP_LABEL_ATTRIBUTE = "data-chart-tooltip-label";
52
+ /**
53
+ * Attribute the element inside a Chart.Tooltip row that receives the active
54
+ * point's {@link CHART_POINT_VALUE_ATTRIBUTE} text carries.
55
+ */
56
+ export declare const CHART_TOOLTIP_VALUE_ATTRIBUTE = "data-chart-tooltip-value";
57
+ /**
58
+ * CSS custom property `chartTooltip()` writes on Chart.Tooltip's host with
59
+ * the active point's horizontal pixel offset, relative to the chart root's
60
+ * own parent element, for its own styling to read back via `var()`.
61
+ */
62
+ export declare const CHART_TOOLTIP_X_PROPERTY = "--ui-chart-tooltip-x";
63
+ /**
64
+ * CSS custom property `chartTooltip()` writes on Chart.Tooltip's host with
65
+ * the active point's vertical pixel offset, relative to the chart root's own
66
+ * parent element, read back the same way as {@link CHART_TOOLTIP_X_PROPERTY}.
67
+ */
68
+ export declare const CHART_TOOLTIP_Y_PROPERTY = "--ui-chart-tooltip-y";
69
+ /** DOM event type dispatched on a chart root by {@link chartTooltip} whenever the active point set changes. */
70
+ declare const CHART_TOOLTIP_CHANGE_EVENT: "ui:chart-tooltip-change";
71
+ declare global {
72
+ interface HTMLElementEventMap {
73
+ [CHART_TOOLTIP_CHANGE_EVENT]: ChartTooltipChangeEvent;
74
+ }
75
+ }
76
+ /**
77
+ * One point's already-localized label and value text, read off
78
+ * {@link CHART_POINT_LABEL_ATTRIBUTE} and {@link CHART_POINT_VALUE_ATTRIBUTE},
79
+ * as carried by {@link ChartTooltipChangeEvent}.
80
+ */
81
+ export interface ChartTooltipPoint {
82
+ /** The point's label, copied from {@link CHART_POINT_LABEL_ATTRIBUTE} unchanged. */
83
+ readonly label: string;
84
+ /** The point's value, copied from {@link CHART_POINT_VALUE_ATTRIBUTE} unchanged. */
85
+ readonly value: string;
86
+ }
87
+ /**
88
+ * Dispatched on a chart root by {@link chartTooltip} every time the active
89
+ * point set changes, carrying every active point's label and value so a
90
+ * consumer can drive a live-region announcement or cross-highlight a legend.
91
+ */
92
+ export declare class ChartTooltipChangeEvent extends Event {
93
+ /** Every currently active point's label and value, in document order, or an empty array when nothing is active. */
94
+ readonly points: readonly ChartTooltipPoint[];
95
+ /**
96
+ * @param points Every currently active point's label and value.
97
+ */
98
+ constructor(points: readonly ChartTooltipPoint[]);
99
+ }
100
+ /**
101
+ * Adds pointer- and focus-tracked tooltip coordination to a Chart.Bar,
102
+ * Chart.Line, Chart.Area, or Chart.Pie root, resolving the active point and
103
+ * its group into the sibling Chart.Tooltip's rows, position, and events.
104
+ *
105
+ * @returns A mixin descriptor for a chart root's `mix` prop.
106
+ * @example
107
+ * <div mix={[css({ position: "relative" })]}>
108
+ * <Chart.Bar data={points} mix={chartTooltip()} />
109
+ * <Chart.Tooltip>
110
+ * <Chart.Tooltip.Row>
111
+ * <Chart.Tooltip.Label />
112
+ * <Chart.Tooltip.Value />
113
+ * </Chart.Tooltip.Row>
114
+ * </Chart.Tooltip>
115
+ * </div>
116
+ */
117
+ export declare const chartTooltip: MixinFactory<HTMLElement>;
118
+ export {};
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Bridges a Chart.Bar, Chart.Line, Chart.Area, or Chart.Pie root to its
3
+ * sibling Chart.Tooltip surface: tracks whichever plotted point the pointer
4
+ * or keyboard focus currently resolves to, and mirrors it onto
5
+ * Chart.Tooltip's rows and position.
6
+ *
7
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
8
+ * @copyright Sergio Xalambrí 2026
9
+ */
10
+ import { createElement, createMixin, on } from "remix/ui";
11
+ /**
12
+ * Attribute every plottable point a chart root renders carries: a bar's
13
+ * `<rect>`, a line or area's vertex marker, or a pie's wedge `<path>`.
14
+ * `chartTooltip()` reads it to build its pointer-tracked candidate set.
15
+ */
16
+ export const CHART_POINT_ATTRIBUTE = "data-chart-point";
17
+ /**
18
+ * Attribute a point carries its already-localized label on — the category,
19
+ * series name, or slice name a chart renders it under. `chartTooltip()`
20
+ * copies it unchanged into the matching row's {@link CHART_TOOLTIP_LABEL_ATTRIBUTE}.
21
+ */
22
+ export const CHART_POINT_LABEL_ATTRIBUTE = "data-chart-label";
23
+ /**
24
+ * Attribute a point carries its already-formatted value on, rendered through
25
+ * the consumer's own `Intl` formatting. `chartTooltip()` copies it unchanged
26
+ * into the matching row's {@link CHART_TOOLTIP_VALUE_ATTRIBUTE} slot.
27
+ */
28
+ export const CHART_POINT_VALUE_ATTRIBUTE = "data-chart-value";
29
+ /**
30
+ * Attribute an ancestor of a cluster of related points carries — every
31
+ * series' point for one category in a grouped bar chart. Every point beneath
32
+ * the nearest such ancestor populates the tooltip together, one row each.
33
+ */
34
+ export const CHART_POINT_GROUP_ATTRIBUTE = "data-chart-group";
35
+ /**
36
+ * Attribute Chart.Tooltip's own root element carries. `chartTooltip()` finds
37
+ * it among its host's parent element's descendants — the sibling
38
+ * relationship a chart root and its Chart.Tooltip render in.
39
+ */
40
+ export const CHART_TOOLTIP_ATTRIBUTE = "data-chart-tooltip";
41
+ /**
42
+ * Attribute every pre-rendered row inside Chart.Tooltip carries, one per
43
+ * series it could ever need to show, in document order. `chartTooltip()`
44
+ * fills as many as the active point set holds and hides the rest.
45
+ */
46
+ export const CHART_TOOLTIP_ROW_ATTRIBUTE = "data-chart-tooltip-row";
47
+ /**
48
+ * Attribute the element inside a Chart.Tooltip row that receives the active
49
+ * point's {@link CHART_POINT_LABEL_ATTRIBUTE} text carries.
50
+ */
51
+ export const CHART_TOOLTIP_LABEL_ATTRIBUTE = "data-chart-tooltip-label";
52
+ /**
53
+ * Attribute the element inside a Chart.Tooltip row that receives the active
54
+ * point's {@link CHART_POINT_VALUE_ATTRIBUTE} text carries.
55
+ */
56
+ export const CHART_TOOLTIP_VALUE_ATTRIBUTE = "data-chart-tooltip-value";
57
+ /**
58
+ * CSS custom property `chartTooltip()` writes on Chart.Tooltip's host with
59
+ * the active point's horizontal pixel offset, relative to the chart root's
60
+ * own parent element, for its own styling to read back via `var()`.
61
+ */
62
+ export const CHART_TOOLTIP_X_PROPERTY = "--ui-chart-tooltip-x";
63
+ /**
64
+ * CSS custom property `chartTooltip()` writes on Chart.Tooltip's host with
65
+ * the active point's vertical pixel offset, relative to the chart root's own
66
+ * parent element, read back the same way as {@link CHART_TOOLTIP_X_PROPERTY}.
67
+ */
68
+ export const CHART_TOOLTIP_Y_PROPERTY = "--ui-chart-tooltip-y";
69
+ /**
70
+ * Largest pixel distance from the pointer to a point's center that still
71
+ * resolves as hovering it once no point sits directly beneath the pointer,
72
+ * keeping empty chart margin from always resolving to the nearest point.
73
+ */
74
+ const NEAREST_POINT_MAX_DISTANCE_PX = 48;
75
+ /** DOM event type dispatched on a chart root by {@link chartTooltip} whenever the active point set changes. */
76
+ const CHART_TOOLTIP_CHANGE_EVENT = "ui:chart-tooltip-change";
77
+ /**
78
+ * Dispatched on a chart root by {@link chartTooltip} every time the active
79
+ * point set changes, carrying every active point's label and value so a
80
+ * consumer can drive a live-region announcement or cross-highlight a legend.
81
+ */
82
+ export class ChartTooltipChangeEvent extends Event {
83
+ /** Every currently active point's label and value, in document order, or an empty array when nothing is active. */
84
+ points;
85
+ /**
86
+ * @param points Every currently active point's label and value.
87
+ */
88
+ constructor(points) {
89
+ super(CHART_TOOLTIP_CHANGE_EVENT, { bubbles: true });
90
+ this.points = points;
91
+ }
92
+ }
93
+ /**
94
+ * Reads every point beneath `host`, in document order.
95
+ *
96
+ * @param host Chart root to search beneath.
97
+ * @returns Every element carrying {@link CHART_POINT_ATTRIBUTE}.
98
+ */
99
+ function queryPoints(host) {
100
+ return Array.from(host.querySelectorAll(`[${CHART_POINT_ATTRIBUTE}]`));
101
+ }
102
+ /**
103
+ * Resolves the point directly beneath viewport position `(clientX, clientY)`,
104
+ * scoped to `host` — the precise case, matching a pointer sitting anywhere
105
+ * over a filled bar, area, pie wedge, or exactly on a line's vertex marker.
106
+ *
107
+ * @param host Chart root the resolved point must fall inside.
108
+ * @param clientX Pointer's horizontal viewport position.
109
+ * @param clientY Pointer's vertical viewport position.
110
+ * @returns The point directly beneath the position, or `undefined` when none sits there.
111
+ */
112
+ function hitTestPoint(host, clientX, clientY) {
113
+ let element = document.elementFromPoint(clientX, clientY);
114
+ let point = element?.closest(`[${CHART_POINT_ATTRIBUTE}]`) ?? undefined;
115
+ return point && host.contains(point) ? point : undefined;
116
+ }
117
+ /**
118
+ * Resolves the point whose center sits closest to viewport position
119
+ * `(clientX, clientY)`, within {@link NEAREST_POINT_MAX_DISTANCE_PX} — the
120
+ * fallback for a pointer near, but not exactly on, a thin vertex marker.
121
+ *
122
+ * @param host Chart root to search beneath.
123
+ * @param clientX Pointer's horizontal viewport position.
124
+ * @param clientY Pointer's vertical viewport position.
125
+ * @returns The nearest point within range, or `undefined` when every point sits too far away (or none render at all).
126
+ */
127
+ function nearestPoint(host, clientX, clientY) {
128
+ let nearest;
129
+ let nearestDistance = Infinity;
130
+ for (let point of queryPoints(host)) {
131
+ let rect = point.getBoundingClientRect();
132
+ let dx = rect.left + rect.width / 2 - clientX;
133
+ let dy = rect.top + rect.height / 2 - clientY;
134
+ let distance = Math.sqrt(dx * dx + dy * dy);
135
+ if (distance < nearestDistance) {
136
+ nearestDistance = distance;
137
+ nearest = point;
138
+ }
139
+ }
140
+ return nearest !== undefined && nearestDistance <= NEAREST_POINT_MAX_DISTANCE_PX
141
+ ? nearest
142
+ : undefined;
143
+ }
144
+ /**
145
+ * Resolves the active point at viewport position `(clientX, clientY)`: an
146
+ * exact {@link hitTestPoint} hit first, falling back to {@link nearestPoint}
147
+ * when the pointer isn't directly over any point.
148
+ *
149
+ * @param host Chart root to resolve a point against.
150
+ * @param clientX Pointer's horizontal viewport position.
151
+ * @param clientY Pointer's vertical viewport position.
152
+ * @returns The resolved point, or `undefined` when neither strategy finds one.
153
+ */
154
+ function resolvePointAt(host, clientX, clientY) {
155
+ return hitTestPoint(host, clientX, clientY) ?? nearestPoint(host, clientX, clientY);
156
+ }
157
+ /**
158
+ * Resolves `anchor`'s group: every point beneath its nearest enclosing
159
+ * {@link CHART_POINT_GROUP_ATTRIBUTE} ancestor, scoped to `host`, or `anchor`
160
+ * alone when it has no such ancestor.
161
+ *
162
+ * @param host Chart root the group's ancestor must fall inside.
163
+ * @param anchor Point to resolve the group for.
164
+ * @returns Every point in `anchor`'s group, in document order.
165
+ */
166
+ function resolveGroup(host, anchor) {
167
+ let container = anchor.closest(`[${CHART_POINT_GROUP_ATTRIBUTE}]`);
168
+ if (container && host.contains(container)) {
169
+ return Array.from(container.querySelectorAll(`[${CHART_POINT_ATTRIBUTE}]`));
170
+ }
171
+ return [anchor];
172
+ }
173
+ /**
174
+ * Reads each point's already-localized label and value off
175
+ * {@link CHART_POINT_LABEL_ATTRIBUTE} and {@link CHART_POINT_VALUE_ATTRIBUTE}.
176
+ *
177
+ * @param points Points to read, in the order the result should preserve.
178
+ * @returns One {@link ChartTooltipPoint} per input point, in the same order.
179
+ */
180
+ function readPoints(points) {
181
+ return points.map((point) => ({
182
+ label: point.getAttribute(CHART_POINT_LABEL_ATTRIBUTE) ?? "",
183
+ value: point.getAttribute(CHART_POINT_VALUE_ATTRIBUTE) ?? "",
184
+ }));
185
+ }
186
+ /**
187
+ * Finds the Chart.Tooltip sibling a chart root's own mixin drives: the
188
+ * nearest element carrying {@link CHART_TOOLTIP_ATTRIBUTE} among `host`'s
189
+ * parent element's descendants.
190
+ *
191
+ * @param host Chart root to search alongside.
192
+ * @returns The matched Chart.Tooltip, or `undefined` when `host` has no parent or renders no such sibling.
193
+ */
194
+ function findTooltip(host) {
195
+ return (host.parentElement?.querySelector(`[${CHART_TOOLTIP_ATTRIBUTE}]`) ?? undefined);
196
+ }
197
+ /**
198
+ * Fills as many of `tooltip`'s pre-rendered rows as `points` holds, in
199
+ * document order, and hides every row beyond that count.
200
+ *
201
+ * @param tooltip Chart.Tooltip host to write rows onto.
202
+ * @param points Active point set to fill rows from, in the order rows should receive them.
203
+ */
204
+ function writeRows(tooltip, points) {
205
+ let rows = tooltip.querySelectorAll(`[${CHART_TOOLTIP_ROW_ATTRIBUTE}]`);
206
+ rows.forEach((row, index) => {
207
+ let point = points[index];
208
+ row.hidden = point === undefined;
209
+ if (point === undefined)
210
+ return;
211
+ let label = row.querySelector(`[${CHART_TOOLTIP_LABEL_ATTRIBUTE}]`);
212
+ let value = row.querySelector(`[${CHART_TOOLTIP_VALUE_ATTRIBUTE}]`);
213
+ if (label)
214
+ label.textContent = point.label;
215
+ if (value)
216
+ value.textContent = point.value;
217
+ });
218
+ }
219
+ /**
220
+ * Writes `anchor`'s screen position onto `tooltip` as
221
+ * {@link CHART_TOOLTIP_X_PROPERTY} and {@link CHART_TOOLTIP_Y_PROPERTY},
222
+ * relative to `host`'s own parent element, the shared positioning container.
223
+ *
224
+ * @param host Chart root `anchor` belongs to.
225
+ * @param tooltip Chart.Tooltip host to write the position onto.
226
+ * @param anchor Active point to position the tooltip against.
227
+ */
228
+ function writePosition(host, tooltip, anchor) {
229
+ let origin = (host.parentElement ?? host).getBoundingClientRect();
230
+ let anchorRect = anchor.getBoundingClientRect();
231
+ let x = anchorRect.left + anchorRect.width / 2 - origin.left;
232
+ let y = anchorRect.top - origin.top;
233
+ tooltip.style.setProperty(CHART_TOOLTIP_X_PROPERTY, `${x}px`);
234
+ tooltip.style.setProperty(CHART_TOOLTIP_Y_PROPERTY, `${y}px`);
235
+ }
236
+ /**
237
+ * Resolves the point carrying {@link CHART_POINT_ATTRIBUTE} that `target`
238
+ * itself is, or is nested inside, scoped to `host`.
239
+ *
240
+ * @param host Chart root the resolved point must fall inside.
241
+ * @param target Candidate element — typically a focus event's target or related target.
242
+ * @returns The matched point, or `undefined` when `target` isn't a point, or isn't inside `host`.
243
+ */
244
+ function resolveOwnPoint(host, target) {
245
+ if (!(target instanceof Element))
246
+ return undefined;
247
+ let point = target.closest(`[${CHART_POINT_ATTRIBUTE}]`) ?? undefined;
248
+ return point && host.contains(point) ? point : undefined;
249
+ }
250
+ /**
251
+ * Adds pointer- and focus-tracked tooltip coordination to a Chart.Bar,
252
+ * Chart.Line, Chart.Area, or Chart.Pie root, resolving the active point and
253
+ * its group into the sibling Chart.Tooltip's rows, position, and events.
254
+ *
255
+ * @returns A mixin descriptor for a chart root's `mix` prop.
256
+ * @example
257
+ * <div mix={[css({ position: "relative" })]}>
258
+ * <Chart.Bar data={points} mix={chartTooltip()} />
259
+ * <Chart.Tooltip>
260
+ * <Chart.Tooltip.Row>
261
+ * <Chart.Tooltip.Label />
262
+ * <Chart.Tooltip.Value />
263
+ * </Chart.Tooltip.Row>
264
+ * </Chart.Tooltip>
265
+ * </div>
266
+ */
267
+ export const chartTooltip = createMixin((handle) => {
268
+ let activePoint;
269
+ /** Activates `anchor` on `host`'s Chart.Tooltip and reports the change, unless `anchor` is already active. */
270
+ function activate(host, anchor) {
271
+ if (anchor === activePoint)
272
+ return;
273
+ activePoint = anchor;
274
+ let points = readPoints(resolveGroup(host, anchor));
275
+ let tooltip = findTooltip(host);
276
+ if (tooltip) {
277
+ writeRows(tooltip, points);
278
+ writePosition(host, tooltip, anchor);
279
+ tooltip.setAttribute("data-visible", "");
280
+ }
281
+ host.dispatchEvent(new ChartTooltipChangeEvent(points));
282
+ }
283
+ /** Deactivates `host`'s Chart.Tooltip and reports the change, unless nothing is currently active. */
284
+ function deactivate(host) {
285
+ if (activePoint === undefined)
286
+ return;
287
+ activePoint = undefined;
288
+ findTooltip(host)?.removeAttribute("data-visible");
289
+ host.dispatchEvent(new ChartTooltipChangeEvent([]));
290
+ }
291
+ return () => createElement(handle.element, {
292
+ mix: [
293
+ on("pointermove", (event) => {
294
+ let host = event.currentTarget;
295
+ let point = resolvePointAt(host, event.clientX, event.clientY);
296
+ if (point)
297
+ activate(host, point);
298
+ else
299
+ deactivate(host);
300
+ }),
301
+ on("pointerdown", (event) => {
302
+ let host = event.currentTarget;
303
+ let point = resolvePointAt(host, event.clientX, event.clientY);
304
+ if (point)
305
+ activate(host, point);
306
+ }),
307
+ on("pointerleave", (event) => {
308
+ deactivate(event.currentTarget);
309
+ }),
310
+ on("focusin", (event) => {
311
+ let host = event.currentTarget;
312
+ let point = resolveOwnPoint(host, event.target);
313
+ if (point)
314
+ activate(host, point);
315
+ }),
316
+ on("focusout", (event) => {
317
+ let host = event.currentTarget;
318
+ if (resolveOwnPoint(host, event.relatedTarget) === undefined)
319
+ deactivate(host);
320
+ }),
321
+ ],
322
+ });
323
+ });