@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,368 @@
1
+ /**
2
+ * Bridges a message scroller's viewport to `ScrollFollowModel`, reporting
3
+ * live scroll position, viewport size, and turn visibility into the model
4
+ * and fulfilling its scroll intents by writing scroll position directly, so
5
+ * every visible part of the widget renders purely from state the model owns.
6
+ * Why JS: tracking live scroll position, size, and turn geometry, and
7
+ * telling a deliberate scroll from an auto-follow correction, needs script;
8
+ * no CSS selector expresses that. No-JS baseline: turns still render in
9
+ * document order and the viewport still scrolls natively by wheel, touch, and keyboard.
10
+ *
11
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
12
+ * @copyright Sergio Xalambrí 2026
13
+ */
14
+ import { createElement, createMixin, on } from "remix/ui";
15
+ import { prefersReducedMotion } from "../utils/prefers-reduced-motion.js";
16
+ /**
17
+ * Attribute every conversational turn exposes itself on, its value the
18
+ * turn's stable id; `messageFollow()` reads it to find the anchor turn and
19
+ * to drive its lazily attached `IntersectionObserver`'s visibility tracking.
20
+ */
21
+ export const MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE = "data-scroll-anchor";
22
+ /**
23
+ * Attribute the viewport's jump-to-latest control carries. `messageFollow()`
24
+ * finds it beneath the viewport to wire its click and to mirror
25
+ * `ScrollFollowModel.pinned` onto its visibility and tab-order reachability.
26
+ */
27
+ export const MESSAGE_SCROLLER_JUMP_ATTRIBUTE = "data-scroll-jump";
28
+ /**
29
+ * Attribute `messageFollow()` mirrors onto the viewport whenever
30
+ * `ScrollFollowModel.pinned` is `true` — present while auto-follow is
31
+ * engaged, absent once the reader has scrolled away from the live edge.
32
+ */
33
+ export const MESSAGE_SCROLLER_AUTOSCROLLING_ATTRIBUTE = "data-autoscrolling";
34
+ /**
35
+ * Attribute `messageFollow()` mirrors onto the viewport: a space-separated
36
+ * token list of edges still reachable (`"start"`, `"end"`, or `"start end"`),
37
+ * readable via `[data-scrollable~="end"]`; removed once neither edge is reachable.
38
+ */
39
+ export const MESSAGE_SCROLLER_SCROLLABLE_ATTRIBUTE = "data-scrollable";
40
+ /**
41
+ * How many pixels of rounding error the viewport's scroll position may still
42
+ * sit at from a true edge and count as reached, so sub-pixel layout rounding
43
+ * never leaves an edge visually reached but reported as still reachable.
44
+ */
45
+ const EDGE_TOLERANCE_PX = 1;
46
+ /**
47
+ * Keys whose native scrolling on a focused viewport — or a focused
48
+ * descendant — advances or retreats the reader's position: the keyboard
49
+ * half of detecting an intentional scroll away from the live edge.
50
+ */
51
+ const SCROLL_KEYS = new Set(["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End"]);
52
+ /**
53
+ * Resolves the behavior a scroll-fulfilling call should animate with,
54
+ * collapsing to an instant jump under `prefers-reduced-motion: reduce` so a
55
+ * long jump never rides motion the reader has asked the platform to avoid.
56
+ *
57
+ * @returns `"instant"` when the reader prefers reduced motion, `"smooth"` otherwise.
58
+ */
59
+ function resolveScrollBehavior() {
60
+ return prefersReducedMotion() ? "instant" : "smooth";
61
+ }
62
+ /**
63
+ * Measures which of the viewport's two scrollable edges the reader can still
64
+ * reach, within {@link EDGE_TOLERANCE_PX} of the true edge.
65
+ *
66
+ * @param host Viewport element to measure.
67
+ * @returns Whether the start and end edges still have more content beyond them.
68
+ */
69
+ function readScrollEdges(host) {
70
+ let maxScrollTop = Math.max(0, host.scrollHeight - host.clientHeight);
71
+ return {
72
+ start: host.scrollTop > EDGE_TOLERANCE_PX,
73
+ end: host.scrollTop < maxScrollTop - EDGE_TOLERANCE_PX,
74
+ };
75
+ }
76
+ /**
77
+ * Finds the turn nearest the viewport's start edge: the first element
78
+ * carrying {@link MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE} whose bottom edge
79
+ * hasn't yet scrolled past the viewport's top edge, read back to hold position on prepend.
80
+ *
81
+ * @param host Viewport element to search beneath.
82
+ * @returns The turn nearest the start edge, or `undefined` when the viewport holds none.
83
+ */
84
+ function findAnchorItem(host) {
85
+ let hostTop = host.getBoundingClientRect().top;
86
+ let items = host.querySelectorAll(`[${MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE}]`);
87
+ for (let item of items) {
88
+ if (item.getBoundingClientRect().bottom > hostTop)
89
+ return item;
90
+ }
91
+ return undefined;
92
+ }
93
+ /**
94
+ * Finds the turn carrying a specific id in
95
+ * {@link MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE} — the lookup a `"message"`-type
96
+ * {@link ScrollFollowModel.ScrollRequest} is fulfilled against.
97
+ *
98
+ * @param host Viewport element to search beneath.
99
+ * @param id Id to match against the attribute's value.
100
+ * @returns The matching turn, or `undefined` when none carries `id`.
101
+ */
102
+ function findItemById(host, id) {
103
+ return (host.querySelector(`[${MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE}="${CSS.escape(id)}"]`) ??
104
+ undefined);
105
+ }
106
+ /**
107
+ * Reports whether `node` sits earlier in document order than `reference` —
108
+ * the test that tells a turn prepended above the reader's current anchor
109
+ * apart from one appended below it.
110
+ *
111
+ * @param node Node to test.
112
+ * @param reference Node to test `node`'s position against.
113
+ * @returns `true` when `node` precedes `reference` in the document.
114
+ */
115
+ function precedes(node, reference) {
116
+ let position = reference.compareDocumentPosition(node);
117
+ return (position & Node.DOCUMENT_POSITION_PRECEDING) !== 0;
118
+ }
119
+ /**
120
+ * Jumps the viewport straight to its end edge when `model` is pinned, the
121
+ * auto-follow behavior keeping a reader glued to the live edge as turns
122
+ * arrive; always instant, since animating every streamed token would read as constant motion.
123
+ *
124
+ * @param host Viewport element to scroll.
125
+ * @param model Model whose pinned state gates the jump.
126
+ */
127
+ function stickToEndIfPinned(host, model) {
128
+ if (model.pinned)
129
+ host.scrollTop = host.scrollHeight;
130
+ }
131
+ /**
132
+ * Re-measures the viewport's reachable edges and anchor turn into `model`,
133
+ * and re-derives its pinned state: reaching the end edge re-engages
134
+ * auto-follow, while a reader-initiated scroll away from it disengages it.
135
+ *
136
+ * @param host Viewport element to measure.
137
+ * @param model Model to report the measurement into.
138
+ * @param userInitiated Whether the triggering scroll came from the reader's own gesture.
139
+ */
140
+ function resync(host, model, userInitiated) {
141
+ let edges = readScrollEdges(host);
142
+ model.setReachableEdges(edges);
143
+ if (!edges.end)
144
+ model.setPinned(true);
145
+ else if (userInitiated)
146
+ model.setPinned(false);
147
+ let anchor = findAnchorItem(host);
148
+ model.setAnchorTurnId(anchor?.getAttribute(MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE) ?? null);
149
+ }
150
+ /**
151
+ * Performs the scroll a pending {@link ScrollFollowModel.ScrollRequest}
152
+ * describes: jumping or animating to the end, start, or a specific turn at
153
+ * its requested alignment, respecting `prefers-reduced-motion` throughout.
154
+ *
155
+ * @param host Viewport element to scroll.
156
+ * @param request Scroll request consumed from the model.
157
+ */
158
+ function fulfillScrollRequest(host, request) {
159
+ switch (request.type) {
160
+ case "end":
161
+ host.scrollTo({ top: host.scrollHeight, behavior: resolveScrollBehavior() });
162
+ return;
163
+ case "start":
164
+ host.scrollTo({ top: 0, behavior: resolveScrollBehavior() });
165
+ return;
166
+ case "message": {
167
+ let target = findItemById(host, request.id);
168
+ target?.scrollIntoView({
169
+ block: request.align,
170
+ behavior: request.smooth ? resolveScrollBehavior() : "instant",
171
+ });
172
+ return;
173
+ }
174
+ }
175
+ }
176
+ /**
177
+ * Builds {@link MESSAGE_SCROLLER_SCROLLABLE_ATTRIBUTE}'s value from the
178
+ * model's reachable edges.
179
+ *
180
+ * @param model Model to read reachable edges from.
181
+ * @returns The attribute value to set, or `null` to remove the attribute entirely.
182
+ */
183
+ function scrollableTokens(model) {
184
+ let tokens = [];
185
+ if (model.startReachable)
186
+ tokens.push("start");
187
+ if (model.endReachable)
188
+ tokens.push("end");
189
+ return tokens.length > 0 ? tokens.join(" ") : null;
190
+ }
191
+ /**
192
+ * Mirrors `model`'s state onto the viewport and its jump-to-latest control:
193
+ * autoscrolling and scrollable attributes track `pinned` and reachable
194
+ * edges, and `inert` hides the control from tab order in the same step as visibility.
195
+ *
196
+ * @param host Viewport element to mirror state onto.
197
+ * @param model Model to read state from.
198
+ */
199
+ function syncAttributesFromModel(host, model) {
200
+ if (model.pinned)
201
+ host.setAttribute(MESSAGE_SCROLLER_AUTOSCROLLING_ATTRIBUTE, "");
202
+ else
203
+ host.removeAttribute(MESSAGE_SCROLLER_AUTOSCROLLING_ATTRIBUTE);
204
+ let tokens = scrollableTokens(model);
205
+ if (tokens)
206
+ host.setAttribute(MESSAGE_SCROLLER_SCROLLABLE_ATTRIBUTE, tokens);
207
+ else
208
+ host.removeAttribute(MESSAGE_SCROLLER_SCROLLABLE_ATTRIBUTE);
209
+ let button = host.querySelector(`[${MESSAGE_SCROLLER_JUMP_ATTRIBUTE}]`);
210
+ if (!button)
211
+ return;
212
+ let visible = !model.pinned;
213
+ button.inert = !visible;
214
+ if (visible)
215
+ button.setAttribute("data-visible", "");
216
+ else
217
+ button.removeAttribute("data-visible");
218
+ }
219
+ /**
220
+ * Adds live-scroll coordination to a message scroller's viewport: reports
221
+ * scroll position, size, and turn visibility into `model`, mirrors its
222
+ * pinned and reachable-edge state back onto the viewport, and fulfills its scroll requests.
223
+ *
224
+ * @param model Scroll-follow state shared with the rest of the widget.
225
+ * @example
226
+ * let model = new ScrollFollowModel();
227
+ * <div class="viewport" mix={messageFollow(model)}>
228
+ * <div class="content">
229
+ * {turns.map((turn) => (
230
+ * <div key={turn.id} data-scroll-anchor={turn.id}>{turn.body}</div>
231
+ * ))}
232
+ * </div>
233
+ * <button data-scroll-jump aria-label={jumpToLatestLabel}>↓</button>
234
+ * </div>
235
+ */
236
+ export const messageFollow = createMixin((handle) => {
237
+ let hostNode;
238
+ let boundModel;
239
+ let userScrollIntent = false;
240
+ let itemsObserver;
241
+ let observedItems = new Set();
242
+ /**
243
+ * Lazily creates the visibility observer the first time a turn exists
244
+ * beneath `host`, then keeps it watching exactly the turns currently
245
+ * rendered, reporting hidden any turn that has left the document.
246
+ */
247
+ function ensureItemsObserved(host, model) {
248
+ for (let item of observedItems) {
249
+ if (host.contains(item))
250
+ continue;
251
+ itemsObserver?.unobserve(item);
252
+ observedItems.delete(item);
253
+ let id = item.getAttribute(MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE);
254
+ if (id)
255
+ model.setMessageVisible(id, false);
256
+ }
257
+ let items = host.querySelectorAll(`[${MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE}]`);
258
+ if (items.length === 0)
259
+ return;
260
+ if (!itemsObserver) {
261
+ itemsObserver = new IntersectionObserver((entries) => {
262
+ for (let entry of entries) {
263
+ let id = entry.target.getAttribute(MESSAGE_SCROLLER_ANCHOR_ATTRIBUTE);
264
+ if (id)
265
+ model.setMessageVisible(id, entry.isIntersecting);
266
+ }
267
+ }, { root: host });
268
+ }
269
+ for (let item of items) {
270
+ if (observedItems.has(item))
271
+ continue;
272
+ observedItems.add(item);
273
+ itemsObserver.observe(item);
274
+ }
275
+ }
276
+ /**
277
+ * Reacts to a batch of mutations: synchronously shifts scroll position for
278
+ * turns prepended above the anchor, before the next paint, so the
279
+ * reader's view stays visually still, then re-syncs after appended turns settle.
280
+ */
281
+ function handleMutations(host, model, records) {
282
+ let anchorId = model.anchorTurnId;
283
+ let anchorNode = anchorId ? findItemById(host, anchorId) : undefined;
284
+ let prependHeight = 0;
285
+ let appendedNew = false;
286
+ for (let record of records) {
287
+ for (let node of record.addedNodes) {
288
+ if (!(node instanceof HTMLElement))
289
+ continue;
290
+ if (anchorNode && precedes(node, anchorNode))
291
+ prependHeight += node.getBoundingClientRect().height;
292
+ else
293
+ appendedNew = true;
294
+ }
295
+ }
296
+ if (prependHeight > 0)
297
+ host.scrollTop += prependHeight;
298
+ if (appendedNew)
299
+ stickToEndIfPinned(host, model);
300
+ ensureItemsObserved(host, model);
301
+ resync(host, model, false);
302
+ }
303
+ handle.addEventListener("insert", (event) => {
304
+ hostNode = event.node;
305
+ if (boundModel) {
306
+ stickToEndIfPinned(hostNode, boundModel);
307
+ ensureItemsObserved(hostNode, boundModel);
308
+ resync(hostNode, boundModel, false);
309
+ }
310
+ let mutationObserver = new MutationObserver((records) => {
311
+ if (hostNode && boundModel)
312
+ handleMutations(hostNode, boundModel, records);
313
+ });
314
+ mutationObserver.observe(event.node, { childList: true, subtree: true });
315
+ let resizeObserver = new ResizeObserver(() => {
316
+ if (!hostNode || !boundModel)
317
+ return;
318
+ stickToEndIfPinned(hostNode, boundModel);
319
+ resync(hostNode, boundModel, false);
320
+ });
321
+ resizeObserver.observe(event.node);
322
+ handle.signal.addEventListener("abort", () => {
323
+ mutationObserver.disconnect();
324
+ resizeObserver.disconnect();
325
+ itemsObserver?.disconnect();
326
+ });
327
+ });
328
+ handle.addEventListener("remove", () => {
329
+ hostNode = undefined;
330
+ });
331
+ return (model) => {
332
+ if (boundModel !== model) {
333
+ boundModel = model;
334
+ model.addEventListener("change", () => {
335
+ if (!hostNode)
336
+ return;
337
+ syncAttributesFromModel(hostNode, model);
338
+ let request = model.consumeScrollRequest();
339
+ if (request)
340
+ fulfillScrollRequest(hostNode, request);
341
+ }, { signal: handle.signal });
342
+ }
343
+ return createElement(handle.element, {
344
+ mix: [
345
+ on("scroll", (event) => {
346
+ resync(event.currentTarget, model, userScrollIntent);
347
+ userScrollIntent = false;
348
+ }),
349
+ on("wheel", () => {
350
+ userScrollIntent = true;
351
+ }),
352
+ on("touchmove", () => {
353
+ userScrollIntent = true;
354
+ }),
355
+ on("keydown", (event) => {
356
+ if (SCROLL_KEYS.has(event.key))
357
+ userScrollIntent = true;
358
+ }),
359
+ on("click", (event) => {
360
+ let target = event.target;
361
+ if (target instanceof Element && target.closest(`[${MESSAGE_SCROLLER_JUMP_ATTRIBUTE}]`)) {
362
+ model.scrollToEnd();
363
+ }
364
+ }),
365
+ ],
366
+ });
367
+ };
368
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Focus coordination for an OtpField group: advances focus on each typed
3
+ * digit, retreats on `Backspace` from an empty slot, and splits a pasted
4
+ * code across every slot it fits, starting at the slot that received it.
5
+ * Why JS: distributing typed and pasted characters across single-character
6
+ * inputs, moving focus along with them, requires reading each keystroke and
7
+ * clipboard payload as it arrives; no CSS selector expresses that. No-JS
8
+ * baseline: the group still renders as ordinary text inputs, each reachable
9
+ * through `Tab`; only auto-advance, retreat, and paste-splitting are unavailable.
10
+ *
11
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
12
+ * @copyright Sergio Xalambrí 2026
13
+ */
14
+ /**
15
+ * Attribute every OtpField slot input exposes itself on. `otpSlots()` reads
16
+ * every element carrying this attribute beneath the host, in document
17
+ * order, to find each slot's neighbors and assemble the full code.
18
+ */
19
+ export declare const OTP_SLOT_ATTRIBUTE = "data-otp-slot";
20
+ /** DOM event type dispatched by {@link otpSlots} once every slot holds a character. */
21
+ declare const OTP_COMPLETE_EVENT: "ui:otp-complete";
22
+ declare global {
23
+ interface HTMLElementEventMap {
24
+ [OTP_COMPLETE_EVENT]: OtpCompleteEvent;
25
+ }
26
+ }
27
+ /**
28
+ * Dispatched on the OtpField group host by {@link otpSlots} the moment every
29
+ * slot holds a character, carrying the assembled code for validation or
30
+ * auto-submit; redispatches only when the assembled code actually changes.
31
+ */
32
+ export declare class OtpCompleteEvent extends Event {
33
+ /** Slot values joined in document order, one character per slot. */
34
+ readonly code: string;
35
+ /**
36
+ * @param code Assembled code at dispatch time.
37
+ */
38
+ constructor(code: string);
39
+ }
40
+ /**
41
+ * Coordinates focus across an OtpField group's slot inputs identified by
42
+ * {@link OTP_SLOT_ATTRIBUTE}, querying them fresh on every interaction so
43
+ * slots can be added, removed, or disabled without the mixin losing sync.
44
+ *
45
+ * @example
46
+ * <div role="group" mix={otpSlots()}>
47
+ * <input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 1 })} />
48
+ * <input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 2 })} />
49
+ * <input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 3 })} />
50
+ * </div>
51
+ */
52
+ export declare const otpSlots: import("remix/ui").MixinFactory<HTMLElement, [], import("remix/ui").ElementProps>;
53
+ export {};
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Focus coordination for an OtpField group: advances focus on each typed
3
+ * digit, retreats on `Backspace` from an empty slot, and splits a pasted
4
+ * code across every slot it fits, starting at the slot that received it.
5
+ * Why JS: distributing typed and pasted characters across single-character
6
+ * inputs, moving focus along with them, requires reading each keystroke and
7
+ * clipboard payload as it arrives; no CSS selector expresses that. No-JS
8
+ * baseline: the group still renders as ordinary text inputs, each reachable
9
+ * through `Tab`; only auto-advance, retreat, and paste-splitting are unavailable.
10
+ *
11
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
12
+ * @copyright Sergio Xalambrí 2026
13
+ */
14
+ import { createElement, createMixin, on } from "remix/ui";
15
+ /**
16
+ * Attribute every OtpField slot input exposes itself on. `otpSlots()` reads
17
+ * every element carrying this attribute beneath the host, in document
18
+ * order, to find each slot's neighbors and assemble the full code.
19
+ */
20
+ export const OTP_SLOT_ATTRIBUTE = "data-otp-slot";
21
+ /** DOM event type dispatched by {@link otpSlots} once every slot holds a character. */
22
+ const OTP_COMPLETE_EVENT = "ui:otp-complete";
23
+ /**
24
+ * Dispatched on the OtpField group host by {@link otpSlots} the moment every
25
+ * slot holds a character, carrying the assembled code for validation or
26
+ * auto-submit; redispatches only when the assembled code actually changes.
27
+ */
28
+ export class OtpCompleteEvent extends Event {
29
+ /** Slot values joined in document order, one character per slot. */
30
+ code;
31
+ /**
32
+ * @param code Assembled code at dispatch time.
33
+ */
34
+ constructor(code) {
35
+ super(OTP_COMPLETE_EVENT, { bubbles: true });
36
+ this.code = code;
37
+ }
38
+ }
39
+ /**
40
+ * Reads every enabled slot input beneath `host`, in document order; disabled
41
+ * slots are skipped, so auto-advance, retreat, and paste distribution only
42
+ * ever touch slots a consumer has left interactive.
43
+ *
44
+ * @param host OtpField group element the slots are read from.
45
+ * @returns The group's slot inputs, in document order.
46
+ */
47
+ function querySlots(host) {
48
+ return Array.from(host.querySelectorAll(`[${OTP_SLOT_ATTRIBUTE}]:not(:disabled)`));
49
+ }
50
+ /**
51
+ * Joins every slot's value in order, or returns `null` while any slot is
52
+ * still empty, so callers only ever see a code once it's actually complete.
53
+ *
54
+ * @param slots Slot inputs in document order.
55
+ * @returns The assembled code, or `null` when at least one slot is empty.
56
+ */
57
+ function assembleCode(slots) {
58
+ let values = slots.map((slot) => slot.value);
59
+ return values.some((value) => value.length === 0) ? null : values.join("");
60
+ }
61
+ /**
62
+ * Writes each character of `text` — interior whitespace stripped, so a code
63
+ * copied as "123 456" lands as six characters — into consecutive slots from
64
+ * `startIndex`, overwriting until every character is placed or slots run out.
65
+ *
66
+ * @param slots Slot inputs in document order.
67
+ * @param startIndex Index of the slot the distribution begins at.
68
+ * @param text Typed or pasted text to distribute across the slots.
69
+ * @returns Index of the slot that should receive focus once distribution finishes.
70
+ */
71
+ function distributeAcrossSlots(slots, startIndex, text) {
72
+ let characters = Array.from(text.replace(/\s+/g, ""));
73
+ let filled = 0;
74
+ for (let character of characters) {
75
+ let index = startIndex + filled;
76
+ if (index >= slots.length)
77
+ break;
78
+ slots[index].value = character;
79
+ filled++;
80
+ }
81
+ return Math.min(startIndex + filled, slots.length - 1);
82
+ }
83
+ /**
84
+ * Coordinates focus across an OtpField group's slot inputs identified by
85
+ * {@link OTP_SLOT_ATTRIBUTE}, querying them fresh on every interaction so
86
+ * slots can be added, removed, or disabled without the mixin losing sync.
87
+ *
88
+ * @example
89
+ * <div role="group" mix={otpSlots()}>
90
+ * <input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 1 })} />
91
+ * <input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 2 })} />
92
+ * <input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 3 })} />
93
+ * </div>
94
+ */
95
+ export const otpSlots = createMixin((handle) => {
96
+ let lastCode = null;
97
+ /** Dispatches {@link OtpCompleteEvent} on `host` when `slots` just became complete with a code other than the last one reported. */
98
+ function reportIfComplete(host, slots) {
99
+ let code = assembleCode(slots);
100
+ if (code === null) {
101
+ lastCode = null;
102
+ return;
103
+ }
104
+ if (code === lastCode)
105
+ return;
106
+ lastCode = code;
107
+ host.dispatchEvent(new OtpCompleteEvent(code));
108
+ }
109
+ return () => createElement(handle.element, {
110
+ mix: [
111
+ on("input", (event) => {
112
+ let target = event.target;
113
+ if (!(target instanceof HTMLInputElement))
114
+ return;
115
+ if (!target.matches(`[${OTP_SLOT_ATTRIBUTE}]`))
116
+ return;
117
+ if (target.value.length === 0)
118
+ return;
119
+ let host = event.currentTarget;
120
+ let slots = querySlots(host);
121
+ let index = slots.indexOf(target);
122
+ if (index === -1)
123
+ return;
124
+ if (target.value.length > 1) {
125
+ let focusIndex = distributeAcrossSlots(slots, index, target.value);
126
+ slots[focusIndex]?.focus();
127
+ }
128
+ else {
129
+ slots[index + 1]?.focus();
130
+ }
131
+ reportIfComplete(host, slots);
132
+ }),
133
+ on("keydown", (event) => {
134
+ if (event.key !== "Backspace")
135
+ return;
136
+ let target = event.target;
137
+ if (!(target instanceof HTMLInputElement))
138
+ return;
139
+ if (!target.matches(`[${OTP_SLOT_ATTRIBUTE}]`))
140
+ return;
141
+ if (target.value.length > 0)
142
+ return;
143
+ let host = event.currentTarget;
144
+ let slots = querySlots(host);
145
+ let index = slots.indexOf(target);
146
+ let previous = index === -1 ? undefined : slots[index - 1];
147
+ if (!previous)
148
+ return;
149
+ event.preventDefault();
150
+ previous.value = "";
151
+ previous.focus();
152
+ reportIfComplete(host, slots);
153
+ }),
154
+ on("paste", (event) => {
155
+ let target = event.target;
156
+ if (!(target instanceof HTMLInputElement))
157
+ return;
158
+ if (!target.matches(`[${OTP_SLOT_ATTRIBUTE}]`))
159
+ return;
160
+ let text = event.clipboardData?.getData("text") ?? "";
161
+ if (text === "")
162
+ return;
163
+ event.preventDefault();
164
+ let host = event.currentTarget;
165
+ let slots = querySlots(host);
166
+ let index = slots.indexOf(target);
167
+ if (index === -1)
168
+ return;
169
+ let focusIndex = distributeAcrossSlots(slots, index, text);
170
+ slots[focusIndex]?.focus();
171
+ reportIfComplete(host, slots);
172
+ }),
173
+ ],
174
+ });
175
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Why JS: remembering a Sidebar's collapsed state across a full page
3
+ * navigation means writing it somewhere the next server render can read
4
+ * back before any markup reaches the browser, and answering a `--ui-toggle`
5
+ * command dispatched from a trigger button elsewhere on the page — neither
6
+ * has an HTML or CSS equivalent.
7
+ * No-JS baseline: the collapse checkbox beneath the Sidebar root still
8
+ * drives the collapse purely through CSS via its own `<label>`; only
9
+ * cross-navigation memory is unavailable without this mixin.
10
+ *
11
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
12
+ * @copyright Sergio Xalambrí 2026
13
+ */
14
+ import type { ElementProps, MixinFactory } from "remix/ui";
15
+ /**
16
+ * Attribute the Sidebar's collapse checkbox carries. {@link persist} reads
17
+ * and flips this single descendant of its host, the same element the
18
+ * Sidebar's own styles key their `:checked` selector off.
19
+ */
20
+ export declare const SIDEBAR_TOGGLE_ATTRIBUTE = "data-sidebar-toggle";
21
+ /**
22
+ * Mirrors a Sidebar's collapsed state into a cookie, so a fresh page load
23
+ * renders it already collapsed or expanded, and answers the `--ui-toggle`
24
+ * command so a trigger button anywhere on the page can flip the Sidebar.
25
+ *
26
+ * @param key Cookie name the collapsed state persists under — scope it per
27
+ * Sidebar instance on a page that renders more than one.
28
+ * @returns A mixin descriptor for the Sidebar root's `mix` prop.
29
+ * @example
30
+ * <div id="app-sidebar" mix={[persist("app-sidebar:collapsed")]}>
31
+ * <input type="checkbox" data-sidebar-toggle hidden />
32
+ * ...
33
+ * </div>
34
+ * <button commandfor="app-sidebar" command="--ui-toggle">Toggle sidebar</button>
35
+ */
36
+ export declare const persist: MixinFactory<HTMLElement, [key: string], ElementProps>;