@ember-joinery/primitives 0.0.0-stage → 1.0.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 (485) hide show
  1. package/CHANGELOG.md +472 -0
  2. package/LICENSE.md +9 -0
  3. package/NOTICE +532 -0
  4. package/README.md +11 -2
  5. package/addon-main.cjs +4 -0
  6. package/declarations/-private/combobox-list.d.ts +59 -0
  7. package/declarations/-private/combobox-list.d.ts.map +1 -0
  8. package/declarations/-private/command-score.d.ts +33 -0
  9. package/declarations/-private/command-score.d.ts.map +1 -0
  10. package/declarations/-private/delay-group.d.ts +47 -0
  11. package/declarations/-private/delay-group.d.ts.map +1 -0
  12. package/declarations/-private/dialog.d.ts +180 -0
  13. package/declarations/-private/dialog.d.ts.map +1 -0
  14. package/declarations/-private/form-control.d.ts +70 -0
  15. package/declarations/-private/form-control.d.ts.map +1 -0
  16. package/declarations/-private/form-data.d.ts +14 -0
  17. package/declarations/-private/form-data.d.ts.map +1 -0
  18. package/declarations/-private/hover-intent.d.ts +48 -0
  19. package/declarations/-private/hover-intent.d.ts.map +1 -0
  20. package/declarations/-private/image-loading.d.ts +77 -0
  21. package/declarations/-private/image-loading.d.ts.map +1 -0
  22. package/declarations/-private/indicator.d.ts +27 -0
  23. package/declarations/-private/indicator.d.ts.map +1 -0
  24. package/declarations/-private/instances.d.ts +11 -0
  25. package/declarations/-private/instances.d.ts.map +1 -0
  26. package/declarations/-private/layout-styles.d.ts +34 -0
  27. package/declarations/-private/layout-styles.d.ts.map +1 -0
  28. package/declarations/-private/menu.d.ts +616 -0
  29. package/declarations/-private/menu.d.ts.map +1 -0
  30. package/declarations/-private/observers.d.ts +35 -0
  31. package/declarations/-private/observers.d.ts.map +1 -0
  32. package/declarations/-private/popper.d.ts +149 -0
  33. package/declarations/-private/popper.d.ts.map +1 -0
  34. package/declarations/-private/presence-chart.d.ts +39 -0
  35. package/declarations/-private/presence-chart.d.ts.map +1 -0
  36. package/declarations/-private/promise-state.d.ts +41 -0
  37. package/declarations/-private/promise-state.d.ts.map +1 -0
  38. package/declarations/-private/scroll-end.d.ts +16 -0
  39. package/declarations/-private/scroll-end.d.ts.map +1 -0
  40. package/declarations/-private/scroll-visibility.d.ts +68 -0
  41. package/declarations/-private/scroll-visibility.d.ts.map +1 -0
  42. package/declarations/-private/toast.d.ts +119 -0
  43. package/declarations/-private/toast.d.ts.map +1 -0
  44. package/declarations/-private/typeahead-search.d.ts +29 -0
  45. package/declarations/-private/typeahead-search.d.ts.map +1 -0
  46. package/declarations/accordion.d.ts +284 -0
  47. package/declarations/accordion.d.ts.map +1 -0
  48. package/declarations/alert-dialog.d.ts +80 -0
  49. package/declarations/alert-dialog.d.ts.map +1 -0
  50. package/declarations/anchor/component.d.ts +63 -0
  51. package/declarations/anchor/component.d.ts.map +1 -0
  52. package/declarations/anchor/index.d.ts +7 -0
  53. package/declarations/anchor/index.d.ts.map +1 -0
  54. package/declarations/anchor/middleware.d.ts +46 -0
  55. package/declarations/anchor/middleware.d.ts.map +1 -0
  56. package/declarations/anchor/modifier.d.ts +34 -0
  57. package/declarations/anchor/modifier.d.ts.map +1 -0
  58. package/declarations/anchor/options.d.ts +112 -0
  59. package/declarations/anchor/options.d.ts.map +1 -0
  60. package/declarations/anchor/position.d.ts +36 -0
  61. package/declarations/anchor/position.d.ts.map +1 -0
  62. package/declarations/anchor.d.ts +2 -0
  63. package/declarations/as.d.ts +33 -0
  64. package/declarations/as.d.ts.map +1 -0
  65. package/declarations/aspect-ratio.d.ts +34 -0
  66. package/declarations/aspect-ratio.d.ts.map +1 -0
  67. package/declarations/avatar.d.ts +178 -0
  68. package/declarations/avatar.d.ts.map +1 -0
  69. package/declarations/body-class.d.ts +30 -0
  70. package/declarations/body-class.d.ts.map +1 -0
  71. package/declarations/breadcrumb.d.ts +64 -0
  72. package/declarations/breadcrumb.d.ts.map +1 -0
  73. package/declarations/calendar/dates.d.ts +142 -0
  74. package/declarations/calendar/dates.d.ts.map +1 -0
  75. package/declarations/calendar/index.d.ts +59 -0
  76. package/declarations/calendar/index.d.ts.map +1 -0
  77. package/declarations/calendar/state.d.ts +415 -0
  78. package/declarations/calendar/state.d.ts.map +1 -0
  79. package/declarations/calendar.d.ts +3 -0
  80. package/declarations/checkbox.d.ts +71 -0
  81. package/declarations/checkbox.d.ts.map +1 -0
  82. package/declarations/collapsible.d.ts +216 -0
  83. package/declarations/collapsible.d.ts.map +1 -0
  84. package/declarations/color-scheme.d.ts +115 -0
  85. package/declarations/color-scheme.d.ts.map +1 -0
  86. package/declarations/combobox.d.ts +569 -0
  87. package/declarations/combobox.d.ts.map +1 -0
  88. package/declarations/command.d.ts +410 -0
  89. package/declarations/command.d.ts.map +1 -0
  90. package/declarations/context-menu.d.ts +155 -0
  91. package/declarations/context-menu.d.ts.map +1 -0
  92. package/declarations/controllable-state.d.ts +85 -0
  93. package/declarations/controllable-state.d.ts.map +1 -0
  94. package/declarations/dialog.d.ts +80 -0
  95. package/declarations/dialog.d.ts.map +1 -0
  96. package/declarations/direction.d.ts +55 -0
  97. package/declarations/direction.d.ts.map +1 -0
  98. package/declarations/dismiss.d.ts +111 -0
  99. package/declarations/dismiss.d.ts.map +1 -0
  100. package/declarations/dom-context.d.ts +74 -0
  101. package/declarations/dom-context.d.ts.map +1 -0
  102. package/declarations/drawer/controller.d.ts +174 -0
  103. package/declarations/drawer/controller.d.ts.map +1 -0
  104. package/declarations/drawer/index.d.ts +105 -0
  105. package/declarations/drawer/index.d.ts.map +1 -0
  106. package/declarations/drawer/machine.d.ts +139 -0
  107. package/declarations/drawer/machine.d.ts.map +1 -0
  108. package/declarations/drawer/parts.d.ts +85 -0
  109. package/declarations/drawer/parts.d.ts.map +1 -0
  110. package/declarations/drawer.d.ts +2 -0
  111. package/declarations/dropdown-menu.d.ts +169 -0
  112. package/declarations/dropdown-menu.d.ts.map +1 -0
  113. package/declarations/external-link.d.ts +26 -0
  114. package/declarations/external-link.d.ts.map +1 -0
  115. package/declarations/file-drop.d.ts +119 -0
  116. package/declarations/file-drop.d.ts.map +1 -0
  117. package/declarations/focus-scope.d.ts +105 -0
  118. package/declarations/focus-scope.d.ts.map +1 -0
  119. package/declarations/focus.d.ts +114 -0
  120. package/declarations/focus.d.ts.map +1 -0
  121. package/declarations/head.d.ts +20 -0
  122. package/declarations/head.d.ts.map +1 -0
  123. package/declarations/heading.d.ts +59 -0
  124. package/declarations/heading.d.ts.map +1 -0
  125. package/declarations/hero.d.ts +32 -0
  126. package/declarations/hero.d.ts.map +1 -0
  127. package/declarations/hide-others.d.ts +35 -0
  128. package/declarations/hide-others.d.ts.map +1 -0
  129. package/declarations/hover-card.d.ts +148 -0
  130. package/declarations/hover-card.d.ts.map +1 -0
  131. package/declarations/i18n.d.ts +47 -0
  132. package/declarations/i18n.d.ts.map +1 -0
  133. package/declarations/id.d.ts +15 -0
  134. package/declarations/id.d.ts.map +1 -0
  135. package/declarations/iframe.d.ts +12 -0
  136. package/declarations/iframe.d.ts.map +1 -0
  137. package/declarations/incremental-each.d.ts +81 -0
  138. package/declarations/incremental-each.d.ts.map +1 -0
  139. package/declarations/index.d.ts +108 -0
  140. package/declarations/index.d.ts.map +1 -0
  141. package/declarations/input-otp.d.ts +201 -0
  142. package/declarations/input-otp.d.ts.map +1 -0
  143. package/declarations/keys.d.ts +50 -0
  144. package/declarations/keys.d.ts.map +1 -0
  145. package/declarations/label.d.ts +36 -0
  146. package/declarations/label.d.ts.map +1 -0
  147. package/declarations/layer.d.ts +56 -0
  148. package/declarations/layer.d.ts.map +1 -0
  149. package/declarations/link-helper.d.ts +73 -0
  150. package/declarations/link-helper.d.ts.map +1 -0
  151. package/declarations/link.d.ts +60 -0
  152. package/declarations/link.d.ts.map +1 -0
  153. package/declarations/load.d.ts +47 -0
  154. package/declarations/load.d.ts.map +1 -0
  155. package/declarations/menubar.d.ts +231 -0
  156. package/declarations/menubar.d.ts.map +1 -0
  157. package/declarations/message-scroller/components.d.ts +229 -0
  158. package/declarations/message-scroller/components.d.ts.map +1 -0
  159. package/declarations/message-scroller/geometry.d.ts +95 -0
  160. package/declarations/message-scroller/geometry.d.ts.map +1 -0
  161. package/declarations/message-scroller/index.d.ts +4 -0
  162. package/declarations/message-scroller/index.d.ts.map +1 -0
  163. package/declarations/message-scroller/state.d.ts +124 -0
  164. package/declarations/message-scroller/state.d.ts.map +1 -0
  165. package/declarations/message-scroller.d.ts +2 -0
  166. package/declarations/messages.d.ts +166 -0
  167. package/declarations/messages.d.ts.map +1 -0
  168. package/declarations/narrowing.d.ts +24 -0
  169. package/declarations/narrowing.d.ts.map +1 -0
  170. package/declarations/native-form.d.ts +56 -0
  171. package/declarations/native-form.d.ts.map +1 -0
  172. package/declarations/native-value.d.ts +47 -0
  173. package/declarations/native-value.d.ts.map +1 -0
  174. package/declarations/navigation-menu.d.ts +406 -0
  175. package/declarations/navigation-menu.d.ts.map +1 -0
  176. package/declarations/on-resize.d.ts +32 -0
  177. package/declarations/on-resize.d.ts.map +1 -0
  178. package/declarations/part.d.ts +99 -0
  179. package/declarations/part.d.ts.map +1 -0
  180. package/declarations/popover.d.ts +236 -0
  181. package/declarations/popover.d.ts.map +1 -0
  182. package/declarations/portal/index.d.ts +3 -0
  183. package/declarations/portal/index.d.ts.map +1 -0
  184. package/declarations/portal/portal.d.ts +46 -0
  185. package/declarations/portal/portal.d.ts.map +1 -0
  186. package/declarations/portal/targets.d.ts +40 -0
  187. package/declarations/portal/targets.d.ts.map +1 -0
  188. package/declarations/portal.d.ts +2 -0
  189. package/declarations/presence.d.ts +80 -0
  190. package/declarations/presence.d.ts.map +1 -0
  191. package/declarations/progress.d.ts +98 -0
  192. package/declarations/progress.d.ts.map +1 -0
  193. package/declarations/proper-links.d.ts +69 -0
  194. package/declarations/proper-links.d.ts.map +1 -0
  195. package/declarations/qp.d.ts +55 -0
  196. package/declarations/qp.d.ts.map +1 -0
  197. package/declarations/questionnaire/components.d.ts +348 -0
  198. package/declarations/questionnaire/components.d.ts.map +1 -0
  199. package/declarations/questionnaire/index.d.ts +4 -0
  200. package/declarations/questionnaire/index.d.ts.map +1 -0
  201. package/declarations/questionnaire/state.d.ts +400 -0
  202. package/declarations/questionnaire/state.d.ts.map +1 -0
  203. package/declarations/questionnaire/utils.d.ts +65 -0
  204. package/declarations/questionnaire/utils.d.ts.map +1 -0
  205. package/declarations/questionnaire.d.ts +2 -0
  206. package/declarations/radio-group.d.ts +115 -0
  207. package/declarations/radio-group.d.ts.map +1 -0
  208. package/declarations/rating.d.ts +214 -0
  209. package/declarations/rating.d.ts.map +1 -0
  210. package/declarations/resizable/components.d.ts +107 -0
  211. package/declarations/resizable/components.d.ts.map +1 -0
  212. package/declarations/resizable/index.d.ts +4 -0
  213. package/declarations/resizable/index.d.ts.map +1 -0
  214. package/declarations/resizable/layout.d.ts +93 -0
  215. package/declarations/resizable/layout.d.ts.map +1 -0
  216. package/declarations/resizable/state.d.ts +211 -0
  217. package/declarations/resizable/state.d.ts.map +1 -0
  218. package/declarations/resizable.d.ts +2 -0
  219. package/declarations/resize-observer.d.ts +40 -0
  220. package/declarations/resize-observer.d.ts.map +1 -0
  221. package/declarations/roving-focus.d.ts +204 -0
  222. package/declarations/roving-focus.d.ts.map +1 -0
  223. package/declarations/scroll-area/components.d.ts +125 -0
  224. package/declarations/scroll-area/components.d.ts.map +1 -0
  225. package/declarations/scroll-area/index.d.ts +3 -0
  226. package/declarations/scroll-area/index.d.ts.map +1 -0
  227. package/declarations/scroll-area/state.d.ts +147 -0
  228. package/declarations/scroll-area/state.d.ts.map +1 -0
  229. package/declarations/scroll-area.d.ts +2 -0
  230. package/declarations/scroll-lock.d.ts +69 -0
  231. package/declarations/scroll-lock.d.ts.map +1 -0
  232. package/declarations/scroller.d.ts +71 -0
  233. package/declarations/scroller.d.ts.map +1 -0
  234. package/declarations/select.d.ts +459 -0
  235. package/declarations/select.d.ts.map +1 -0
  236. package/declarations/separator.d.ts +71 -0
  237. package/declarations/separator.d.ts.map +1 -0
  238. package/declarations/service.d.ts +83 -0
  239. package/declarations/service.d.ts.map +1 -0
  240. package/declarations/shadowed.d.ts +63 -0
  241. package/declarations/shadowed.d.ts.map +1 -0
  242. package/declarations/slider.d.ts +283 -0
  243. package/declarations/slider.d.ts.map +1 -0
  244. package/declarations/sticky-footer.d.ts +43 -0
  245. package/declarations/sticky-footer.d.ts.map +1 -0
  246. package/declarations/store.d.ts +47 -0
  247. package/declarations/store.d.ts.map +1 -0
  248. package/declarations/switch.d.ts +76 -0
  249. package/declarations/switch.d.ts.map +1 -0
  250. package/declarations/tabs.d.ts +250 -0
  251. package/declarations/tabs.d.ts.map +1 -0
  252. package/declarations/toast/icons.d.ts +29 -0
  253. package/declarations/toast/icons.d.ts.map +1 -0
  254. package/declarations/toast/index.d.ts +4 -0
  255. package/declarations/toast/index.d.ts.map +1 -0
  256. package/declarations/toast/item.d.ts +162 -0
  257. package/declarations/toast/item.d.ts.map +1 -0
  258. package/declarations/toast/state.d.ts +276 -0
  259. package/declarations/toast/state.d.ts.map +1 -0
  260. package/declarations/toast/styles.d.ts +20 -0
  261. package/declarations/toast/styles.d.ts.map +1 -0
  262. package/declarations/toast/toaster.d.ts +173 -0
  263. package/declarations/toast/toaster.d.ts.map +1 -0
  264. package/declarations/toast.d.ts +2 -0
  265. package/declarations/toggle-group.d.ts +161 -0
  266. package/declarations/toggle-group.d.ts.map +1 -0
  267. package/declarations/toggle.d.ts +70 -0
  268. package/declarations/toggle.d.ts.map +1 -0
  269. package/declarations/tooltip.d.ts +227 -0
  270. package/declarations/tooltip.d.ts.map +1 -0
  271. package/declarations/typeahead.d.ts +97 -0
  272. package/declarations/typeahead.d.ts.map +1 -0
  273. package/declarations/viewport.d.ts +109 -0
  274. package/declarations/viewport.d.ts.map +1 -0
  275. package/declarations/visually-hidden.d.ts +42 -0
  276. package/declarations/visually-hidden.d.ts.map +1 -0
  277. package/declarations/zoetrope.d.ts +120 -0
  278. package/declarations/zoetrope.d.ts.map +1 -0
  279. package/dist/accordion.js +367 -0
  280. package/dist/accordion.js.map +1 -0
  281. package/dist/alert-dialog.js +122 -0
  282. package/dist/alert-dialog.js.map +1 -0
  283. package/dist/anchor.js +2 -0
  284. package/dist/anchor.js.map +1 -0
  285. package/dist/as.js +60 -0
  286. package/dist/as.js.map +1 -0
  287. package/dist/aspect-ratio.js +59 -0
  288. package/dist/aspect-ratio.js.map +1 -0
  289. package/dist/avatar.js +464 -0
  290. package/dist/avatar.js.map +1 -0
  291. package/dist/body-class.js +57 -0
  292. package/dist/body-class.js.map +1 -0
  293. package/dist/breadcrumb.js +59 -0
  294. package/dist/breadcrumb.js.map +1 -0
  295. package/dist/calendar.js +1494 -0
  296. package/dist/calendar.js.map +1 -0
  297. package/dist/checkbox.js +81 -0
  298. package/dist/checkbox.js.map +1 -0
  299. package/dist/collapsible.js +255 -0
  300. package/dist/collapsible.js.map +1 -0
  301. package/dist/color-scheme.js +306 -0
  302. package/dist/color-scheme.js.map +1 -0
  303. package/dist/combobox.js +1413 -0
  304. package/dist/combobox.js.map +1 -0
  305. package/dist/command.js +1054 -0
  306. package/dist/command.js.map +1 -0
  307. package/dist/component-DqLt83fo.js +886 -0
  308. package/dist/component-DqLt83fo.js.map +1 -0
  309. package/dist/components-CWfg0cFs.js +1745 -0
  310. package/dist/components-CWfg0cFs.js.map +1 -0
  311. package/dist/components-DBWszEI3.js +1285 -0
  312. package/dist/components-DBWszEI3.js.map +1 -0
  313. package/dist/components-DI8Azu05.js +1542 -0
  314. package/dist/components-DI8Azu05.js.map +1 -0
  315. package/dist/components-F0Ini448.js +875 -0
  316. package/dist/components-F0Ini448.js.map +1 -0
  317. package/dist/context-menu.js +207 -0
  318. package/dist/context-menu.js.map +1 -0
  319. package/dist/controllable-state.js +134 -0
  320. package/dist/controllable-state.js.map +1 -0
  321. package/dist/delay-group-B1K03gBL.js +75 -0
  322. package/dist/delay-group-B1K03gBL.js.map +1 -0
  323. package/dist/dialog-3gfz_8NA.js +349 -0
  324. package/dist/dialog-3gfz_8NA.js.map +1 -0
  325. package/dist/dialog.js +57 -0
  326. package/dist/dialog.js.map +1 -0
  327. package/dist/direction.js +75 -0
  328. package/dist/direction.js.map +1 -0
  329. package/dist/dismiss.js +329 -0
  330. package/dist/dismiss.js.map +1 -0
  331. package/dist/dom-context.js +104 -0
  332. package/dist/dom-context.js.map +1 -0
  333. package/dist/drawer.js +1456 -0
  334. package/dist/drawer.js.map +1 -0
  335. package/dist/dropdown-menu.js +201 -0
  336. package/dist/dropdown-menu.js.map +1 -0
  337. package/dist/external-link.js +21 -0
  338. package/dist/external-link.js.map +1 -0
  339. package/dist/file-drop.js +183 -0
  340. package/dist/file-drop.js.map +1 -0
  341. package/dist/focus-scope.js +292 -0
  342. package/dist/focus-scope.js.map +1 -0
  343. package/dist/focus.js +307 -0
  344. package/dist/focus.js.map +1 -0
  345. package/dist/form-control-Ca_KHSKK.js +177 -0
  346. package/dist/form-control-Ca_KHSKK.js.map +1 -0
  347. package/dist/head.js +25 -0
  348. package/dist/head.js.map +1 -0
  349. package/dist/heading.js +152 -0
  350. package/dist/heading.js.map +1 -0
  351. package/dist/hero.js +36 -0
  352. package/dist/hero.js.map +1 -0
  353. package/dist/hide-others.js +108 -0
  354. package/dist/hide-others.js.map +1 -0
  355. package/dist/hover-card.js +246 -0
  356. package/dist/hover-card.js.map +1 -0
  357. package/dist/hover-intent-Bxb83fgX.js +92 -0
  358. package/dist/hover-intent-Bxb83fgX.js.map +1 -0
  359. package/dist/i18n.js +72 -0
  360. package/dist/i18n.js.map +1 -0
  361. package/dist/id.js +24 -0
  362. package/dist/id.js.map +1 -0
  363. package/dist/iframe.js +19 -0
  364. package/dist/iframe.js.map +1 -0
  365. package/dist/incremental-each.js +181 -0
  366. package/dist/incremental-each.js.map +1 -0
  367. package/dist/index.js +87 -0
  368. package/dist/index.js.map +1 -0
  369. package/dist/indicator-sYuRuFJA.js +26 -0
  370. package/dist/indicator-sYuRuFJA.js.map +1 -0
  371. package/dist/input-otp.js +611 -0
  372. package/dist/input-otp.js.map +1 -0
  373. package/dist/keys.js +65 -0
  374. package/dist/keys.js.map +1 -0
  375. package/dist/label.js +41 -0
  376. package/dist/label.js.map +1 -0
  377. package/dist/layer.js +157 -0
  378. package/dist/layer.js.map +1 -0
  379. package/dist/layout-styles-DY86so8a.js +81 -0
  380. package/dist/layout-styles-DY86so8a.js.map +1 -0
  381. package/dist/link-helper.js +122 -0
  382. package/dist/link-helper.js.map +1 -0
  383. package/dist/link.js +39 -0
  384. package/dist/link.js.map +1 -0
  385. package/dist/load.js +54 -0
  386. package/dist/load.js.map +1 -0
  387. package/dist/menu-Da1LFCet.js +1109 -0
  388. package/dist/menu-Da1LFCet.js.map +1 -0
  389. package/dist/menubar.js +357 -0
  390. package/dist/menubar.js.map +1 -0
  391. package/dist/message-scroller.js +2 -0
  392. package/dist/message-scroller.js.map +1 -0
  393. package/dist/messages.js +168 -0
  394. package/dist/messages.js.map +1 -0
  395. package/dist/narrowing.js +29 -0
  396. package/dist/narrowing.js.map +1 -0
  397. package/dist/native-form.js +134 -0
  398. package/dist/native-form.js.map +1 -0
  399. package/dist/native-value.js +125 -0
  400. package/dist/native-value.js.map +1 -0
  401. package/dist/navigation-menu.js +872 -0
  402. package/dist/navigation-menu.js.map +1 -0
  403. package/dist/observers-aItWe029.js +113 -0
  404. package/dist/observers-aItWe029.js.map +1 -0
  405. package/dist/on-resize.js +47 -0
  406. package/dist/on-resize.js.map +1 -0
  407. package/dist/part.js +291 -0
  408. package/dist/part.js.map +1 -0
  409. package/dist/popover.js +419 -0
  410. package/dist/popover.js.map +1 -0
  411. package/dist/popper-BbTzV8dP.js +323 -0
  412. package/dist/popper-BbTzV8dP.js.map +1 -0
  413. package/dist/portal-U554WDI9.js +214 -0
  414. package/dist/portal-U554WDI9.js.map +1 -0
  415. package/dist/portal.js +2 -0
  416. package/dist/portal.js.map +1 -0
  417. package/dist/presence.js +243 -0
  418. package/dist/presence.js.map +1 -0
  419. package/dist/progress.js +106 -0
  420. package/dist/progress.js.map +1 -0
  421. package/dist/promise-state-BMi2zVoT.js +91 -0
  422. package/dist/promise-state-BMi2zVoT.js.map +1 -0
  423. package/dist/proper-links.js +136 -0
  424. package/dist/proper-links.js.map +1 -0
  425. package/dist/qp.js +77 -0
  426. package/dist/qp.js.map +1 -0
  427. package/dist/questionnaire.js +2 -0
  428. package/dist/questionnaire.js.map +1 -0
  429. package/dist/radio-group.js +149 -0
  430. package/dist/radio-group.js.map +1 -0
  431. package/dist/rating.js +261 -0
  432. package/dist/rating.js.map +1 -0
  433. package/dist/resizable.js +2 -0
  434. package/dist/resizable.js.map +1 -0
  435. package/dist/resize-observer.js +85 -0
  436. package/dist/resize-observer.js.map +1 -0
  437. package/dist/roving-focus.js +355 -0
  438. package/dist/roving-focus.js.map +1 -0
  439. package/dist/scroll-area.js +2 -0
  440. package/dist/scroll-area.js.map +1 -0
  441. package/dist/scroll-end-Cer8JSIB.js +87 -0
  442. package/dist/scroll-end-Cer8JSIB.js.map +1 -0
  443. package/dist/scroll-lock.js +267 -0
  444. package/dist/scroll-lock.js.map +1 -0
  445. package/dist/scroller.js +117 -0
  446. package/dist/scroller.js.map +1 -0
  447. package/dist/select.js +1223 -0
  448. package/dist/select.js.map +1 -0
  449. package/dist/separator.js +80 -0
  450. package/dist/separator.js.map +1 -0
  451. package/dist/service.js +160 -0
  452. package/dist/service.js.map +1 -0
  453. package/dist/shadowed.js +70 -0
  454. package/dist/shadowed.js.map +1 -0
  455. package/dist/slider.js +586 -0
  456. package/dist/slider.js.map +1 -0
  457. package/dist/sticky-footer.js +40 -0
  458. package/dist/sticky-footer.js.map +1 -0
  459. package/dist/store-BjiAd-KP.js +93 -0
  460. package/dist/store-BjiAd-KP.js.map +1 -0
  461. package/dist/store.js +4 -0
  462. package/dist/store.js.map +1 -0
  463. package/dist/switch.js +58 -0
  464. package/dist/switch.js.map +1 -0
  465. package/dist/tabs.js +458 -0
  466. package/dist/tabs.js.map +1 -0
  467. package/dist/toast.js +2 -0
  468. package/dist/toast.js.map +1 -0
  469. package/dist/toaster-DwprFZ1J.js +1518 -0
  470. package/dist/toaster-DwprFZ1J.js.map +1 -0
  471. package/dist/toggle-group.js +221 -0
  472. package/dist/toggle-group.js.map +1 -0
  473. package/dist/toggle.js +78 -0
  474. package/dist/toggle.js.map +1 -0
  475. package/dist/tooltip.js +422 -0
  476. package/dist/tooltip.js.map +1 -0
  477. package/dist/typeahead.js +233 -0
  478. package/dist/typeahead.js.map +1 -0
  479. package/dist/viewport.js +138 -0
  480. package/dist/viewport.js.map +1 -0
  481. package/dist/visually-hidden.js +49 -0
  482. package/dist/visually-hidden.js.map +1 -0
  483. package/dist/zoetrope.js +336 -0
  484. package/dist/zoetrope.js.map +1 -0
  485. package/package.json +101 -3
@@ -0,0 +1,1542 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked, cached } from '@glimmer/tracking';
3
+ import { registerDestructor } from '@ember/destroyable';
4
+ import { modifier } from 'ember-modifier';
5
+ import { As } from './as.js';
6
+ import { Consume, Provide } from './dom-context.js';
7
+ import { part } from './part.js';
8
+ import { buildWaiter } from '@ember/test-waiters';
9
+ import { s as scrollEnd } from './scroll-end-Cer8JSIB.js';
10
+ import { isUndefined } from '@sindresorhus/is';
11
+ import { g, i, n } from 'decorator-transforms/runtime';
12
+ import { t, translate } from './i18n.js';
13
+ import { messages } from './messages.js';
14
+ import { precompileTemplate } from '@ember/template-compilation';
15
+ import { setComponentTemplate } from '@ember/component';
16
+ import templateOnly from '@ember/component/template-only';
17
+
18
+ // The message scroller's measurements, ported from @shadcn/react's message-scroller/geometry.ts
19
+ // (shadcn-ui/ui@8ab2771). One change: every distance read off the screen
20
+ // (`getBoundingClientRect()`) is turned back into CSS pixels, the unit of `scrollTop`, by the
21
+ // viewport's scale, so a scroller inside a scaled ancestor (a `transform: scale()`, such as the
22
+ // test container's) lands where it would unscaled. Unscaled, the scale is 1 and the numbers are
23
+ // upstream's.
24
+
25
+ /** The edges the viewport can still scroll toward. */
26
+
27
+ /** Where the reader is in the transcript. */
28
+
29
+ /** Where a command lines its target up in the viewport. */
30
+
31
+ /** Two fractional scroll positions this close are the same: zoom and HiDPI rounding drift. */
32
+ const SCROLL_POSITION_EPSILON = 0.5;
33
+ const EMPTY_SCROLLABLE = Object.freeze({
34
+ start: false,
35
+ end: false
36
+ });
37
+ const EMPTY_IDS = [];
38
+ const EMPTY_VISIBILITY = Object.freeze({
39
+ currentAnchorId: null,
40
+ visibleMessageIds: EMPTY_IDS
41
+ });
42
+
43
+ /**
44
+ * How much the screen scales the viewport: an on-screen length (`getBoundingClientRect()`) is
45
+ * this many times its CSS length. 1 unless an ancestor transforms it.
46
+ */
47
+ function getScale(viewport) {
48
+ const height = viewport.offsetHeight;
49
+ if (!height) return 1;
50
+ const scale = viewport.getBoundingClientRect().height / height;
51
+ return Number.isFinite(scale) && scale > 0 ? scale : 1;
52
+ }
53
+ function getMessageScrollerScrollable({
54
+ content,
55
+ scrollEdgeThreshold,
56
+ spacer,
57
+ viewport
58
+ }) {
59
+ if (!viewport || !content) return EMPTY_SCROLLABLE;
60
+ const contentBottom = getContentBottom({
61
+ content,
62
+ spacer,
63
+ viewport
64
+ });
65
+ return {
66
+ start: viewport.scrollTop > scrollEdgeThreshold,
67
+ end: contentBottom - viewport.scrollTop - viewport.clientHeight > scrollEdgeThreshold
68
+ };
69
+ }
70
+ function getMessageScrollerVisibilityState({
71
+ content,
72
+ scrollMargin,
73
+ scrollPreviousItemPeek,
74
+ spacer,
75
+ viewport,
76
+ visibleMessageIds
77
+ }) {
78
+ if (!content || !viewport) return EMPTY_VISIBILITY;
79
+ const scale = getScale(viewport);
80
+ const viewportRect = viewport.getBoundingClientRect();
81
+ // The reading line sits scrollPreviousItemPeek below scrollMargin: anchored turns land there
82
+ // with the previous turn peeking above. A row only peeking in that band has not been read
83
+ // down to yet, so it counts as neither visible nor current.
84
+ const lineTop = viewportRect.top + (scrollMargin + scrollPreviousItemPeek) * scale;
85
+ const trackByLayout = isUndefined(globalThis.IntersectionObserver);
86
+ const visible = [];
87
+ let currentAnchorId = null;
88
+
89
+ // Rows in document order, so the visible ids come out top to bottom.
90
+ for (const item of getMessageScrollerItems(content, spacer)) {
91
+ const messageId = item.dataset['messageId'];
92
+ if (!messageId) continue;
93
+ const isAnchor = item.dataset['scrollAnchor'] === 'true';
94
+ // Anchors need a rect to place the current line; the others lean on the observer's set
95
+ // (or a rect, where there is no observer).
96
+ const rect = isAnchor || trackByLayout ? item.getBoundingClientRect() : null;
97
+ const isVisible = trackByLayout && rect ? rect.bottom > lineTop && rect.top < viewportRect.bottom : visibleMessageIds.has(messageId);
98
+ if (isVisible) visible.push(messageId);
99
+ // Current is the last anchor to have reached the reading line: the turn you scrolled to
100
+ // wins over newer turns lower down, the previous turn peeking above the line has been
101
+ // passed, and it stays current after its header scrolls out of the viewport.
102
+ if (isAnchor && rect && rect.top <= lineTop + SCROLL_POSITION_EPSILON * scale) {
103
+ currentAnchorId = messageId;
104
+ }
105
+ }
106
+ if (visible.length === 0 && currentAnchorId === null) return EMPTY_VISIBILITY;
107
+ return {
108
+ currentAnchorId,
109
+ visibleMessageIds: visible
110
+ };
111
+ }
112
+
113
+ /** The transcript's rows: every element in the content but the tail spacer. */
114
+ function getMessageScrollerItems(content, spacer) {
115
+ return Array.from(content.children).filter(child => child instanceof HTMLElement && child !== spacer);
116
+ }
117
+ const isAnchor = item => item?.dataset['scrollAnchor'] === 'true';
118
+
119
+ /** The first anchor among the rows from `previousItemCount` on: the ones just appended. */
120
+ function getNewScrollAnchor(items, previousItemCount) {
121
+ for (let index = previousItemCount; index < items.length; index++) {
122
+ if (isAnchor(items[index])) return items[index];
123
+ }
124
+ return null;
125
+ }
126
+
127
+ /** The first anchor that hasn't been placed yet: a row that became an anchor in place. */
128
+ function getUnanchoredScrollAnchor(items, handledAnchors) {
129
+ for (const item of items) {
130
+ if (isAnchor(item) && !handledAnchors.has(item)) return item;
131
+ }
132
+ return null;
133
+ }
134
+
135
+ /** Whether more than one of the rows just appended is an anchor. */
136
+ function hasMultipleNewScrollAnchors(items, previousItemCount) {
137
+ let count = 0;
138
+ for (let index = previousItemCount; index < items.length; index++) {
139
+ if (!isAnchor(items[index])) continue;
140
+ count += 1;
141
+ if (count > 1) return true;
142
+ }
143
+ return false;
144
+ }
145
+
146
+ /** The last anchor in the transcript. */
147
+ function getLastScrollAnchor(items) {
148
+ for (let index = items.length - 1; index >= 0; index--) {
149
+ if (isAnchor(items[index])) return items[index];
150
+ }
151
+ return null;
152
+ }
153
+
154
+ /** The first row with a `messageId` that shows in the viewport. */
155
+ function getFirstVisibleMessageItem({
156
+ content,
157
+ spacer,
158
+ viewport
159
+ }) {
160
+ const viewportRect = viewport.getBoundingClientRect();
161
+ for (const item of getMessageScrollerItems(content, spacer)) {
162
+ if (!item.dataset['messageId']) continue;
163
+ const rect = item.getBoundingClientRect();
164
+ if (rect.bottom > viewportRect.top && rect.top < viewportRect.bottom) return item;
165
+ }
166
+ return null;
167
+ }
168
+
169
+ /** The `scrollTop` that lines `element` up at `align`, `scrollMargin` from that edge. */
170
+ function getElementScrollTop({
171
+ align,
172
+ element,
173
+ scrollMargin,
174
+ spacer,
175
+ viewport
176
+ }) {
177
+ const elementTop = getElementTop(element, viewport);
178
+ const elementHeight = element.getBoundingClientRect().height / getScale(viewport);
179
+ const contentPadding = getContentBlockPadding(spacer);
180
+ if (align === 'center') {
181
+ const insetHeight = Math.max(0, viewport.clientHeight - contentPadding.start - contentPadding.end);
182
+ return elementTop - contentPadding.start - (insetHeight - elementHeight) / 2 - scrollMargin;
183
+ }
184
+ if (align === 'end') {
185
+ return elementTop - viewport.clientHeight + elementHeight + contentPadding.end + scrollMargin;
186
+ }
187
+ if (align === 'nearest') {
188
+ const elementBottom = elementTop + elementHeight;
189
+ const viewportTop = viewport.scrollTop + contentPadding.start;
190
+ const viewportBottom = viewport.scrollTop + viewport.clientHeight - contentPadding.end;
191
+ if (elementTop >= viewportTop && elementBottom <= viewportBottom) return viewport.scrollTop;
192
+ if (elementTop < viewportTop) return elementTop - contentPadding.start - scrollMargin;
193
+ return elementBottom - viewport.clientHeight + contentPadding.end + scrollMargin;
194
+ }
195
+ return elementTop - contentPadding.start - scrollMargin;
196
+ }
197
+
198
+ /** Where `element` starts in the viewport's scrolled content, in CSS pixels. */
199
+ function getElementTop(element, viewport) {
200
+ return getElementViewportTop(element, viewport) + viewport.scrollTop;
201
+ }
202
+
203
+ /** Where `element` starts below the viewport's top edge, in CSS pixels. */
204
+ function getElementViewportTop(element, viewport) {
205
+ const delta = element.getBoundingClientRect().top - viewport.getBoundingClientRect().top;
206
+ return delta / getScale(viewport);
207
+ }
208
+
209
+ /** How tall the tail spacer must be for `scrollTop` to be reachable. */
210
+ function getTailSpacerHeight({
211
+ content,
212
+ scrollTop,
213
+ spacer,
214
+ viewport
215
+ }) {
216
+ return scrollTop + viewport.clientHeight - getContentBottom({
217
+ content,
218
+ spacer,
219
+ viewport
220
+ });
221
+ }
222
+
223
+ /** Where the last row ends in the scrolled content, with the content's padding, spacer aside. */
224
+ function getContentBottom({
225
+ content,
226
+ spacer,
227
+ viewport
228
+ }) {
229
+ const items = getMessageScrollerItems(content, spacer);
230
+ const padding = getBlockPadding(content);
231
+ const scale = getScale(viewport);
232
+ const viewportTop = viewport.getBoundingClientRect().top;
233
+ const scrollTop = viewport.scrollTop;
234
+ let contentBottom = padding.start + padding.end;
235
+ for (const item of items) {
236
+ const bottom = (item.getBoundingClientRect().bottom - viewportTop) / scale;
237
+ contentBottom = Math.max(contentBottom, bottom + scrollTop + padding.end);
238
+ }
239
+ return contentBottom;
240
+ }
241
+
242
+ /** How far the viewport can scroll. */
243
+ function getMaxScrollTop(viewport) {
244
+ return Math.max(0, viewport.scrollHeight - viewport.clientHeight);
245
+ }
246
+ function getBlockPadding(element) {
247
+ const style = window.getComputedStyle(element);
248
+ return {
249
+ end: readCssPixel(style.paddingBlockEnd || style.paddingBottom),
250
+ start: readCssPixel(style.paddingBlockStart || style.paddingTop)
251
+ };
252
+ }
253
+
254
+ /** The content's block padding, found from the spacer inside it. */
255
+ function getContentBlockPadding(spacer) {
256
+ const content = spacer?.parentElement;
257
+ if (!content) return {
258
+ end: 0,
259
+ start: 0
260
+ };
261
+ return getBlockPadding(content);
262
+ }
263
+
264
+ /** The row gap of a flex container, which the spacer takes back with a negative margin. */
265
+ function getFlexGap(element) {
266
+ if (!element) return 0;
267
+ const style = window.getComputedStyle(element);
268
+ const gap = style.rowGap === 'normal' ? style.gap : style.rowGap;
269
+ return readCssPixel(gap);
270
+ }
271
+ function readCssPixel(value) {
272
+ if (!value) return 0;
273
+ const number = Number.parseFloat(value);
274
+ return Number.isFinite(number) ? number : 0;
275
+ }
276
+
277
+ // The message scroller's behaviour, ported from @shadcn/react's message-scroller
278
+ // (use-message-scroller-controller.ts, use-message-scroller-commands.ts,
279
+ // use-message-scroller-refs.ts and stores.ts, shadcn-ui/ui@8ab2771). Upstream keeps it in refs
280
+ // and mirrors the state onto the DOM so scrolling never re-renders a row; here it is one class
281
+ // with plain fields, and only the three things a template reads are tracked: which edges can be
282
+ // scrolled to, whether the opening position is pending, and (while something watches it) the
283
+ // reader's place.
284
+ const waiter = buildWaiter('@ember-joinery/primitives:message-scroller');
285
+
286
+ /** Distance from an edge that still counts as at it: rounding differs between engines. */
287
+ const DEFAULT_SCROLL_EDGE_THRESHOLD = 8;
288
+
289
+ /** How much of the previous row stays in view above a newly anchored turn, in pixels. */
290
+ const DEFAULT_SCROLL_PREVIOUS_ITEM_PEEK = 64;
291
+
292
+ /** The margin a command leaves on the edge it lines its target up with, in pixels. */
293
+ const DEFAULT_SCROLL_MARGIN = 0;
294
+
295
+ /** How long `data-autoscrolling` stays after a programmatic scroll to the end, in ms. */
296
+ const AUTOSCROLLING_CLEAR_DELAY = 180;
297
+
298
+ /** The viewport keys that are the reader scrolling on purpose: they release following. */
299
+ const USER_SCROLL_KEYS = new Set(['ArrowDown', 'ArrowUp', 'End', 'Home', 'PageDown', 'PageUp', ' ']);
300
+
301
+ /** Where a saved transcript opens, once, on its first render with rows. */
302
+
303
+ /** Which edge a scroll button scrolls to. */
304
+
305
+ /** What `scrollToMessage`, `scrollToEnd` and `scrollToStart` take. */
306
+
307
+ /** What the scroller takes: the provider's arguments. */
308
+
309
+ /**
310
+ * How the viewport reacts to content and resizes, from what the reader and the commands did:
311
+ * following the end, left alone, holding a turn at the reading line while it streams, or
312
+ * letting a programmatic jump settle.
313
+ */
314
+
315
+ /** One frame of work, held by the test waiter until it runs or is cancelled. */
316
+ class Frame {
317
+ #id = null;
318
+ #token = null;
319
+ get pending() {
320
+ return this.#id !== null;
321
+ }
322
+
323
+ /** Runs `callback` next frame, unless one is already pending. */
324
+ request(callback) {
325
+ if (this.#id !== null) return;
326
+ this.#token = waiter.beginAsync();
327
+ this.#id = requestAnimationFrame(() => {
328
+ this.#id = null;
329
+ const token = this.#token;
330
+ this.#token = null;
331
+ try {
332
+ callback();
333
+ } finally {
334
+ waiter.endAsync(token);
335
+ }
336
+ });
337
+ }
338
+
339
+ /** Runs `callback` next frame, in place of one already pending. */
340
+ replace(callback) {
341
+ this.cancel();
342
+ this.request(callback);
343
+ }
344
+ cancel() {
345
+ if (this.#id !== null) cancelAnimationFrame(this.#id);
346
+ this.#id = null;
347
+ if (this.#token !== null) waiter.endAsync(this.#token);
348
+ this.#token = null;
349
+ }
350
+ }
351
+ const sameScrollable = (a, b) => a.start === b.start && a.end === b.end;
352
+ const sameVisibility = (a, b) => a.currentAnchorId === b.currentAnchorId && a.visibleMessageIds.length === b.visibleMessageIds.length && a.visibleMessageIds.every((id, index) => id === b.visibleMessageIds[index]);
353
+
354
+ /**
355
+ * One message scroller's state and behaviour: the provider makes one, and its parts register
356
+ * their elements with it. It decides when to scroll (the opening position, following the end,
357
+ * anchoring a new turn, keeping the reader's row in place when history is prepended), runs the
358
+ * commands, and tracks which edges can be scrolled to and, while something watches, where the
359
+ * reader is.
360
+ */
361
+ class MessageScrollerState {
362
+ static {
363
+ g(this.prototype, "scrollable", [tracked], function () {
364
+ return EMPTY_SCROLLABLE;
365
+ });
366
+ }
367
+ #scrollable = (i(this, "scrollable"), void 0);
368
+ /** Which edges the viewport can scroll toward. `end` stays false while it follows the end. */
369
+ static {
370
+ g(this.prototype, "pendingDefaultScroll", [tracked]);
371
+ }
372
+ #pendingDefaultScroll = (i(this, "pendingDefaultScroll"), void 0);
373
+ /** Whether the opening position is still to be applied (`end` and `last-anchor` only). */
374
+ static {
375
+ g(this.prototype, "visibility", [tracked], function () {
376
+ return EMPTY_VISIBILITY;
377
+ });
378
+ }
379
+ #visibility = (i(this, "visibility"), void 0);
380
+ /** Where the reader is: up to date while a `Visibility` (or `observeVisibility()`) watches. */
381
+ /** Keep the first visible row in place when rows are prepended (the viewport's argument). */
382
+ preserveScrollOnPrepend = true;
383
+ #options;
384
+ #mode;
385
+ #lastDefaultScrollPosition;
386
+ #lastAutoScroll;
387
+ #autoscrolling = false;
388
+ #autoscrollingTimeout = null;
389
+ #autoscrollingToken = null;
390
+ #defaultScrollPositionApplied = false;
391
+ #itemCount = 0;
392
+ #items = [];
393
+ #firstItem = null;
394
+ #lastScrollTop = 0;
395
+ #streamingTurn = null;
396
+ #pendingScrollToMessage = null;
397
+ #prependRestore = null;
398
+ #spacerGap = 0;
399
+ #spacerHeight = 0;
400
+ #handledScrollAnchors = new WeakSet();
401
+ #messageElements = new Map();
402
+ #visibleMessageIds = new Set();
403
+ #visibilityObserver = null;
404
+ #visibilityWatchers = 0;
405
+ #mountScheduled = false;
406
+ #contentRendered = false;
407
+ #destroyed = false;
408
+ #stateFrame = new Frame();
409
+ #resizeFrame = new Frame();
410
+ #visibilityFrame = new Frame();
411
+ #pendingScrollFrame = new Frame();
412
+ root = null;
413
+ viewport = null;
414
+ content = null;
415
+ spacer = null;
416
+ constructor(options = () => ({})) {
417
+ this.#options = options;
418
+ const {
419
+ autoScroll = false,
420
+ defaultScrollPosition = 'end'
421
+ } = options();
422
+ this.#mode = autoScroll ? 'following-bottom' : 'free-scrolling';
423
+ this.#lastAutoScroll = autoScroll;
424
+ this.#lastDefaultScrollPosition = defaultScrollPosition;
425
+ this.pendingDefaultScroll = defaultScrollPosition === 'end' || defaultScrollPosition === 'last-anchor';
426
+ }
427
+
428
+ // ----- Options ------------------------------------------------------------------------------
429
+
430
+ get #autoScroll() {
431
+ return this.#options().autoScroll ?? false;
432
+ }
433
+ get #defaultScrollPosition() {
434
+ return this.#options().defaultScrollPosition ?? 'end';
435
+ }
436
+ get #scrollEdgeThreshold() {
437
+ return this.#options().scrollEdgeThreshold ?? DEFAULT_SCROLL_EDGE_THRESHOLD;
438
+ }
439
+ get #scrollMargin() {
440
+ return this.#options().scrollMargin ?? DEFAULT_SCROLL_MARGIN;
441
+ }
442
+ get #scrollPreviousItemPeek() {
443
+ return this.#options().scrollPreviousItemPeek ?? DEFAULT_SCROLL_PREVIOUS_ITEM_PEEK;
444
+ }
445
+
446
+ /**
447
+ * The provider calls this on every render, with its arguments as they are. A change to
448
+ * `autoScroll` or `defaultScrollPosition` is acted on after the render, as upstream's layout
449
+ * effects do.
450
+ */
451
+ optionsChanged() {
452
+ const {
453
+ autoScroll = false,
454
+ defaultScrollPosition = 'end'
455
+ } = this.#options();
456
+ if (defaultScrollPosition !== this.#lastDefaultScrollPosition) {
457
+ this.#lastDefaultScrollPosition = defaultScrollPosition;
458
+ // The pending-scroll hold is for the first render only: a later change applies the new
459
+ // opening position without hiding the viewport again.
460
+ this.#defaultScrollPositionApplied = false;
461
+ this.#scheduleMount();
462
+ }
463
+ if (autoScroll !== this.#lastAutoScroll) {
464
+ this.#lastAutoScroll = autoScroll;
465
+ this.#afterRender(() => {
466
+ if (autoScroll && this.#mode === 'following-bottom' && this.#itemCount > 0) {
467
+ this.scrollToEnd({
468
+ behavior: 'auto'
469
+ });
470
+ } else {
471
+ this.#commitScrollState();
472
+ }
473
+ });
474
+ }
475
+ }
476
+
477
+ // ----- Elements -----------------------------------------------------------------------------
478
+
479
+ /** The root registers itself: it mirrors the scroll-state attributes. */
480
+ setRoot = element => {
481
+ this.root = element;
482
+ if (element) {
483
+ this.#writeStateAttributes(this.scrollable);
484
+ this.#scheduleMount();
485
+ }
486
+ };
487
+
488
+ /** The viewport registers itself: it scrolls, and is the visibility observer's root. */
489
+ setViewport = element => {
490
+ this.viewport = element;
491
+ if (element) {
492
+ this.#writeStateAttributes(this.scrollable);
493
+ if (this.#visibilityWatchers > 0) this.#startVisibility();
494
+ this.#scheduleMount();
495
+ } else {
496
+ this.#stopVisibility();
497
+ }
498
+ };
499
+
500
+ /** The content registers itself: its children are the rows. */
501
+ setContent = element => {
502
+ this.content = element;
503
+ if (element) {
504
+ // Its rows rendered with it, before any mutation could be observed.
505
+ this.#contentRendered = true;
506
+ this.#scheduleMount();
507
+ }
508
+ };
509
+
510
+ /** The tail spacer registers itself: it makes room below an anchored turn. */
511
+ setSpacer = element => {
512
+ this.spacer = element;
513
+ this.#spacerGap = getFlexGap(element?.parentElement ?? null);
514
+ };
515
+
516
+ /** A row with a `messageId` registers itself, and unregisters (`element` null) when it goes. */
517
+ registerMessage = (messageId, element, removedElement) => {
518
+ if (element) {
519
+ this.#messageElements.set(messageId, element);
520
+ this.#visibilityObserver?.observe(element);
521
+ this.#scheduleVisibilitySync();
522
+ if (this.#pendingScrollToMessage?.messageId === messageId) {
523
+ this.#schedulePendingScrollToMessageFlush();
524
+ }
525
+ return;
526
+ }
527
+ if (removedElement && this.#messageElements.get(messageId) === removedElement) {
528
+ this.#messageElements.delete(messageId);
529
+ this.#visibleMessageIds.delete(messageId);
530
+ this.#visibilityObserver?.unobserve(removedElement);
531
+ this.#scheduleVisibilitySync();
532
+ }
533
+ };
534
+
535
+ // ----- Connecting the parts' elements -------------------------------------------------------
536
+
537
+ /** The root's modifier: registers it until the returned cleanup runs. */
538
+ connectRoot(element) {
539
+ this.setRoot(element);
540
+ return () => {
541
+ if (this.root === element) this.setRoot(null);
542
+ };
543
+ }
544
+
545
+ /**
546
+ * The viewport's modifier: registers it, and listens for its scrolls, the reader's scroll
547
+ * gestures (wheel, touch, scroll keys) and its resizes, until the returned cleanup runs.
548
+ */
549
+ connectViewport(element) {
550
+ this.setViewport(element);
551
+ const passive = {
552
+ passive: true
553
+ };
554
+ element.addEventListener('scroll', this.handleScroll, passive);
555
+ element.addEventListener('wheel', this.userScrollIntent, passive);
556
+ element.addEventListener('touchmove', this.userScrollIntent, passive);
557
+ element.addEventListener('keydown', this.handleKeydown);
558
+ const resizes = this.#observeResizes(element);
559
+ return () => {
560
+ element.removeEventListener('scroll', this.handleScroll);
561
+ element.removeEventListener('wheel', this.userScrollIntent);
562
+ element.removeEventListener('touchmove', this.userScrollIntent);
563
+ element.removeEventListener('keydown', this.handleKeydown);
564
+ resizes();
565
+ if (this.viewport === element) this.setViewport(null);
566
+ };
567
+ }
568
+
569
+ /**
570
+ * The content's modifier: registers it, and hears rows come and go (its children) and its
571
+ * resizes, until the returned cleanup runs.
572
+ */
573
+ connectContent(element) {
574
+ this.setContent(element);
575
+ const mutations = isUndefined(globalThis.MutationObserver) ? undefined : new MutationObserver(() => this.handleContentChange());
576
+ mutations?.observe(element, {
577
+ childList: true
578
+ });
579
+ const resizes = this.#observeResizes(element);
580
+ return () => {
581
+ mutations?.disconnect();
582
+ resizes();
583
+ if (this.content === element) this.setContent(null);
584
+ };
585
+ }
586
+
587
+ /** The spacer's modifier. */
588
+ connectSpacer(element) {
589
+ this.setSpacer(element);
590
+ return () => {
591
+ if (this.spacer === element) this.setSpacer(null);
592
+ };
593
+ }
594
+
595
+ /** A row's modifier: registers it by its `messageId` (if it has one) until the cleanup runs. */
596
+ connectItem(element, messageId) {
597
+ if (!messageId) return () => {};
598
+ this.registerMessage(messageId, element);
599
+ return () => this.registerMessage(messageId, null, element);
600
+ }
601
+
602
+ /**
603
+ * Resizes are handled a frame later: handling one resizes the spacer inside the observed
604
+ * content, and resizing an observed element while its resize is delivered makes the browser
605
+ * report a "ResizeObserver loop".
606
+ */
607
+ #observeResizes(element) {
608
+ if (isUndefined(globalThis.ResizeObserver)) return () => {};
609
+ const observer = new ResizeObserver(() => this.#resizeFrame.replace(this.handleResize));
610
+ observer.observe(element);
611
+ return () => observer.disconnect();
612
+ }
613
+
614
+ // ----- Events -------------------------------------------------------------------------------
615
+
616
+ /** The viewport scrolled, whoever scrolled it. */
617
+ handleScroll = () => {
618
+ // A spacer left behind when a stream ends before the reply drains it: a scroll to the real
619
+ // bottom finishes the job, and following re-arms once it reaches zero.
620
+ this.#drainReleasedSpacer();
621
+ this.#commitScrollState();
622
+ this.#scheduleVisibilitySync();
623
+ this.#capturePrependAnchor();
624
+ };
625
+
626
+ /**
627
+ * The reader scrolled on purpose (wheel, touch, a scroll key): that releases following, the
628
+ * anchored turn and a jump still settling, so they never fight the reader.
629
+ */
630
+ userScrollIntent = () => {
631
+ if (this.#mode === 'following-bottom' || this.#mode === 'anchored-to-message' || this.#mode === 'settling-jump') {
632
+ this.#streamingTurn = null;
633
+ this.#mode = 'free-scrolling';
634
+ }
635
+ };
636
+
637
+ /** A key went down in the viewport: a scroll key is the reader scrolling. */
638
+ handleKeydown = event => {
639
+ if (USER_SCROLL_KEYS.has(event.key)) this.userScrollIntent();
640
+ };
641
+
642
+ /** The rows changed: some were appended, prepended, removed or replaced. */
643
+ handleContentChange = () => {
644
+ const content = this.content;
645
+ if (!content || this.#destroyed) return;
646
+ const items = getMessageScrollerItems(content, this.spacer);
647
+ // Glimmer moves its own markers (the text nodes around a block) among the rows, which a
648
+ // childList observer reports though no row came or went. React's commits don't, so
649
+ // upstream reconciles on every report; here the rows must have changed first.
650
+ const previous = this.#items;
651
+ if (previous.length === items.length && previous.every((item, index) => item === items[index])) {
652
+ return;
653
+ }
654
+ this.#items = items;
655
+ const previousItemCount = this.#itemCount;
656
+ const previousFirstItem = this.#firstItem;
657
+ this.#itemCount = items.length;
658
+ this.#firstItem = items[0] ?? null;
659
+ this.#reconcileScrollPosition(items, previousItemCount, previousFirstItem);
660
+ this.#capturePrependAnchor();
661
+ };
662
+
663
+ /** The viewport or the content changed size. */
664
+ handleResize = () => {
665
+ if (this.#destroyed) return;
666
+ if (this.#mode === 'following-bottom' && this.#autoScroll) {
667
+ this.scrollToEnd({
668
+ behavior: 'auto'
669
+ });
670
+ return;
671
+ }
672
+ // Hold the anchored turn in place as what's below it resizes (a reply streaming in), so
673
+ // the shrinking room doesn't let the browser clamp scrollTop and drop the turn.
674
+ const previousSpacerHeight = this.#spacerHeight;
675
+ if (this.#reanchorToAnchoredMessage()) {
676
+ // The reply below the anchor uses up the tail spacer as it grows. Once it's gone the
677
+ // reply fills the viewport and the reader is at the live edge, so following takes over.
678
+ // Only on the >0 → 0 step, so a turn taller than the viewport stays held.
679
+ if (this.#autoScroll && previousSpacerHeight > 0 && this.#spacerHeight === 0) {
680
+ this.scrollToEnd({
681
+ behavior: 'auto'
682
+ });
683
+ }
684
+ return;
685
+ }
686
+ if (this.#drainReleasedSpacer()) return;
687
+ this.#scheduleStateCommit();
688
+ this.#scheduleVisibilitySync();
689
+ };
690
+
691
+ // ----- Commands -----------------------------------------------------------------------------
692
+
693
+ /** Scrolls to the top. `false` only while the viewport isn't rendered. */
694
+ scrollToStart = ({
695
+ behavior = 'auto'
696
+ } = {}) => {
697
+ if (!this.viewport) return false;
698
+ this.#setTailSpacerHeight(0);
699
+ this.#streamingTurn = null;
700
+ this.#mode = 'free-scrolling';
701
+ this.#scrollToPosition(0, {
702
+ behavior
703
+ });
704
+ this.#scheduleVisibilitySync();
705
+ return true;
706
+ };
707
+
708
+ /**
709
+ * Scrolls to the latest row, and with `autoScroll`, follows the end again. `false` only while
710
+ * the viewport isn't rendered.
711
+ */
712
+ scrollToEnd = ({
713
+ behavior = 'auto'
714
+ } = {}) => {
715
+ const viewport = this.viewport;
716
+ if (!viewport) return false;
717
+ this.#setTailSpacerHeight(0);
718
+ this.#streamingTurn = null;
719
+ this.#mode = this.#autoScroll ? 'following-bottom' : 'free-scrolling';
720
+ this.#scrollToPosition(getMaxScrollTop(viewport), {
721
+ autoscrolling: true,
722
+ behavior
723
+ });
724
+ this.#scheduleVisibilitySync();
725
+ return true;
726
+ };
727
+
728
+ /**
729
+ * Scrolls to the row with this `messageId`. Before any row has rendered it is queued, for a
730
+ * permalink resolved while the transcript loads; after that, a missing id gives `false`.
731
+ * `true` means it scrolled or was queued, not that the row is in view yet.
732
+ */
733
+ scrollToMessage = (messageId, options) => {
734
+ const element = this.#messageElements.get(messageId);
735
+ if (!element) {
736
+ if (this.#itemCount === 0) {
737
+ this.#pendingScrollToMessage = {
738
+ messageId,
739
+ options
740
+ };
741
+ this.#markDefaultScrollPositionApplied();
742
+ return true;
743
+ }
744
+ return false;
745
+ }
746
+ this.#markDefaultScrollPositionApplied();
747
+ if (this.#scrollToElement(element, options)) {
748
+ this.#pendingScrollToMessage = null;
749
+ return true;
750
+ }
751
+ this.#pendingScrollToMessage = {
752
+ messageId,
753
+ options
754
+ };
755
+ return true;
756
+ };
757
+
758
+ // ----- Visibility ---------------------------------------------------------------------------
759
+
760
+ /**
761
+ * Starts tracking where the reader is (`visibility`), until the function it returns is
762
+ * called. Tracking is paid for only while something watches.
763
+ */
764
+ observeVisibility = () => {
765
+ this.#visibilityWatchers += 1;
766
+ if (this.#visibilityWatchers === 1) this.#startVisibility();
767
+ let stopped = false;
768
+ return () => {
769
+ if (stopped) return;
770
+ stopped = true;
771
+ this.#visibilityWatchers -= 1;
772
+ if (this.#visibilityWatchers === 0) this.#stopVisibility();
773
+ };
774
+ };
775
+ #startVisibility() {
776
+ const viewport = this.viewport;
777
+ if (!viewport || this.#visibilityWatchers === 0) return;
778
+ if (isUndefined(globalThis.IntersectionObserver)) {
779
+ this.#scheduleVisibilitySync();
780
+ return;
781
+ }
782
+ if (!this.#visibilityObserver) {
783
+ const scale = getScale(viewport);
784
+ this.#visibilityObserver = new IntersectionObserver(entries => {
785
+ for (const entry of entries) {
786
+ const messageId = entry.target.dataset['messageId'];
787
+ if (!messageId) continue;
788
+ if (entry.isIntersecting) this.#visibleMessageIds.add(messageId);else this.#visibleMessageIds.delete(messageId);
789
+ }
790
+ this.#scheduleVisibilitySync();
791
+ }, {
792
+ root: viewport,
793
+ // The root's top edge moves down to the reading line, so a previous turn peeking in
794
+ // the margin and peek band doesn't count as visible, in step with currentAnchorId.
795
+ rootMargin: `${-(this.#scrollMargin + this.#scrollPreviousItemPeek) * scale}px 0px 0px 0px`,
796
+ threshold: [0, 0.01, 0.5, 1]
797
+ });
798
+ }
799
+ for (const element of this.#messageElements.values()) this.#visibilityObserver.observe(element);
800
+ this.#scheduleVisibilitySync();
801
+ }
802
+ #stopVisibility() {
803
+ this.#visibilityFrame.cancel();
804
+ this.#visibilityObserver?.disconnect();
805
+ this.#visibilityObserver = null;
806
+ this.#visibleMessageIds.clear();
807
+ this.#afterRender(() => this.#setVisibility(EMPTY_VISIBILITY));
808
+ }
809
+ #setVisibility(next) {
810
+ if (!sameVisibility(this.visibility, next)) this.visibility = next;
811
+ }
812
+ #scheduleVisibilitySync() {
813
+ if (this.#visibilityWatchers === 0) return;
814
+ this.#visibilityFrame.request(() => {
815
+ // The last watcher may have gone in the meantime.
816
+ if (this.#visibilityWatchers === 0 || this.#destroyed) return;
817
+ this.#setVisibility(getMessageScrollerVisibilityState({
818
+ content: this.content,
819
+ scrollMargin: this.#scrollMargin,
820
+ scrollPreviousItemPeek: this.#scrollPreviousItemPeek,
821
+ spacer: this.spacer,
822
+ viewport: this.viewport,
823
+ visibleMessageIds: this.#visibleMessageIds
824
+ }));
825
+ });
826
+ }
827
+
828
+ // ----- State --------------------------------------------------------------------------------
829
+
830
+ #writeStateAttributes(state) {
831
+ const scrollable = [state.start && 'start', state.end && 'end'].filter(Boolean).join(' ');
832
+ for (const element of [this.root, this.viewport]) {
833
+ if (!element) continue;
834
+ if (scrollable) element.setAttribute('data-scrollable', scrollable);else element.removeAttribute('data-scrollable');
835
+ element.toggleAttribute('data-autoscrolling', this.#autoscrolling);
836
+ }
837
+ }
838
+
839
+ /**
840
+ * The one place following the end starts and stops: it arms at the end, and lets go when the
841
+ * reader scrolls up (a scrollbar drag included), but not during a programmatic scroll, nor
842
+ * while a freshly anchored turn is held (the tail spacer makes it read as "at the end").
843
+ */
844
+ #reconcileFollowMode(scrollable) {
845
+ const scrollTop = this.viewport?.scrollTop ?? 0;
846
+ // Content growing past the live edge also reads as "not at the end", but only a scroll up
847
+ // moves scrollTop up; growth must not release following.
848
+ const scrolledUp = scrollTop < this.#lastScrollTop - SCROLL_POSITION_EPSILON;
849
+ this.#lastScrollTop = scrollTop;
850
+ if (this.#autoScroll && !scrollable.end && this.#spacerHeight === 0 && this.#mode !== 'settling-jump' && this.#mode !== 'anchored-to-message') {
851
+ this.#mode = 'following-bottom';
852
+ } else if (this.#mode === 'following-bottom' && scrollable.end && scrolledUp && !this.#autoscrolling) {
853
+ this.#mode = 'free-scrolling';
854
+ }
855
+ }
856
+ #commitScrollState() {
857
+ if (this.#destroyed) return;
858
+ const next = getMessageScrollerScrollable({
859
+ content: this.content,
860
+ scrollEdgeThreshold: this.#scrollEdgeThreshold,
861
+ spacer: this.spacer,
862
+ viewport: this.viewport
863
+ });
864
+ this.#reconcileFollowMode(next);
865
+ // While following, the scroller is already closing any gap a streamed chunk opened, so
866
+ // showing "more below" would flash the scroll button once per chunk.
867
+ const published = this.#mode === 'following-bottom' ? {
868
+ ...next,
869
+ end: false
870
+ } : next;
871
+ this.#writeStateAttributes(published);
872
+ // A command can run while a template renders (a part's modifier calls one): the tracked
873
+ // value changes after it.
874
+ this.#afterRender(() => {
875
+ if (!sameScrollable(this.scrollable, published)) this.scrollable = published;
876
+ });
877
+ }
878
+ #scheduleStateCommit() {
879
+ this.#stateFrame.request(() => this.#commitScrollState());
880
+ }
881
+ #setAutoScrolling(autoscrolling) {
882
+ if (this.#autoscrollingTimeout !== null) {
883
+ clearTimeout(this.#autoscrollingTimeout);
884
+ this.#autoscrollingTimeout = null;
885
+ waiter.endAsync(this.#autoscrollingToken);
886
+ this.#autoscrollingToken = null;
887
+ }
888
+ if (this.#autoscrolling !== autoscrolling) {
889
+ this.#autoscrolling = autoscrolling;
890
+ this.#commitScrollState();
891
+ }
892
+ if (autoscrolling) {
893
+ this.#autoscrollingToken = waiter.beginAsync();
894
+ this.#autoscrollingTimeout = setTimeout(() => {
895
+ this.#autoscrollingTimeout = null;
896
+ const token = this.#autoscrollingToken;
897
+ this.#autoscrollingToken = null;
898
+ this.#autoscrolling = false;
899
+ this.#commitScrollState();
900
+ waiter.endAsync(token);
901
+ }, AUTOSCROLLING_CLEAR_DELAY);
902
+ }
903
+ }
904
+
905
+ /**
906
+ * Writes the tail spacer's height (hidden at zero). It moves nothing: it makes room below an
907
+ * anchored turn, and gives it back as a reply fills it.
908
+ */
909
+ #setTailSpacerHeight(height) {
910
+ const spacer = this.spacer;
911
+ if (!spacer) return;
912
+ const next = Math.max(0, Math.ceil(height));
913
+ if (this.#spacerHeight === next) return;
914
+ this.#spacerHeight = next;
915
+ spacer.hidden = next === 0;
916
+ spacer.style.height = `${next}px`;
917
+ spacer.style.marginTop = next > 0 ? `${-this.#spacerGap}px` : '';
918
+ }
919
+ #scrollToPosition(scrollTop, {
920
+ behavior = 'auto',
921
+ autoscrolling = false
922
+ } = {}) {
923
+ const viewport = this.viewport;
924
+ if (!viewport) return;
925
+ const next = Math.max(0, scrollTop);
926
+ if (Math.abs(viewport.scrollTop - next) <= SCROLL_POSITION_EPSILON) {
927
+ viewport.scrollTop = next;
928
+ this.#commitScrollState();
929
+ return;
930
+ }
931
+ viewport.scrollTo({
932
+ top: next,
933
+ behavior
934
+ });
935
+ // Upstream marks the scroll before it starts; after, an instant scroll's state is already
936
+ // where it lands, so the button doesn't flash in for the frame before it.
937
+ if (autoscrolling) this.#setAutoScrolling(true);
938
+ if (behavior === 'smooth') {
939
+ // A smooth scroll takes a while to start and to end: tests wait for both.
940
+ const token = waiter.beginAsync();
941
+ void scrollEnd(viewport, {
942
+ top: next
943
+ }).then(() => waiter.endAsync(token));
944
+ }
945
+ this.#scheduleStateCommit();
946
+ }
947
+ #scrollToElement(element, {
948
+ align = 'start',
949
+ behavior = 'auto',
950
+ scrollMargin = this.#scrollMargin
951
+ } = {}, {
952
+ keepPreviousPeek = false
953
+ } = {}) {
954
+ const content = this.content;
955
+ const viewport = this.viewport;
956
+ if (!content || !viewport || !content.contains(element)) return false;
957
+ const scrollTop = getElementScrollTop({
958
+ align,
959
+ element,
960
+ scrollMargin: keepPreviousPeek ? scrollMargin + this.#scrollPreviousItemPeek : scrollMargin,
961
+ spacer: this.spacer,
962
+ viewport
963
+ });
964
+ this.#setTailSpacerHeight(getTailSpacerHeight({
965
+ content,
966
+ scrollTop,
967
+ spacer: this.spacer,
968
+ viewport
969
+ }));
970
+ // Seed the prepend anchor with the target, so a prepend that lands before this scroll
971
+ // settles still keeps it in place; once it settles, the scroll handler re-captures the
972
+ // first visible row.
973
+ this.#prependRestore = {
974
+ element,
975
+ viewportTop: getElementViewportTop(element, viewport)
976
+ };
977
+ this.#mode = keepPreviousPeek ? 'anchored-to-message' : 'settling-jump';
978
+ this.#streamingTurn = keepPreviousPeek ? element : null;
979
+ this.#scrollToPosition(scrollTop, {
980
+ behavior
981
+ });
982
+ this.#scheduleVisibilitySync();
983
+ return true;
984
+ }
985
+ #reanchorToAnchoredMessage() {
986
+ const element = this.#streamingTurn;
987
+ if (!element || !element.isConnected || this.#mode !== 'anchored-to-message') return false;
988
+ // Place it again, so the spacer fits the new content height and the turn stays put.
989
+ return this.#scrollToElement(element, {
990
+ align: 'start'
991
+ }, {
992
+ keepPreviousPeek: true
993
+ });
994
+ }
995
+ #flushPendingScrollToMessage() {
996
+ const pending = this.#pendingScrollToMessage;
997
+ if (!pending) return false;
998
+ const element = this.#messageElements.get(pending.messageId);
999
+ if (!element) return false;
1000
+ if (!this.#scrollToElement(element, pending.options)) return false;
1001
+ this.#pendingScrollToMessage = null;
1002
+ this.#markDefaultScrollPositionApplied();
1003
+ return true;
1004
+ }
1005
+ #schedulePendingScrollToMessageFlush() {
1006
+ this.#pendingScrollFrame.request(() => {
1007
+ if (this.#flushPendingScrollToMessage()) this.#capturePrependAnchor();
1008
+ });
1009
+ }
1010
+ #markDefaultScrollPositionApplied() {
1011
+ this.#defaultScrollPositionApplied = true;
1012
+ this.#clearPendingDefaultScroll();
1013
+ }
1014
+ #clearPendingDefaultScroll() {
1015
+ if (!this.pendingDefaultScroll) return;
1016
+ // Never during the render that registered a part: a template has read it.
1017
+ this.#afterRender(() => this.pendingDefaultScroll = false);
1018
+ }
1019
+ #applyDefaultScrollPosition() {
1020
+ const position = this.#defaultScrollPosition;
1021
+ if (this.#defaultScrollPositionApplied || this.#itemCount === 0) return false;
1022
+ let handled;
1023
+ if (position === 'last-anchor') {
1024
+ const content = this.content;
1025
+ const viewport = this.viewport;
1026
+ const anchor = content && viewport ? getLastScrollAnchor(getMessageScrollerItems(content, this.spacer)) : null;
1027
+ if (!content || !viewport || !anchor) {
1028
+ handled = this.scrollToEnd({
1029
+ behavior: 'auto'
1030
+ });
1031
+ } else {
1032
+ const anchorTop = getElementTop(anchor, viewport);
1033
+ const contentBottom = getContentBottom({
1034
+ content,
1035
+ spacer: this.spacer,
1036
+ viewport
1037
+ });
1038
+ // A short last turn fits below its anchor, so the end shows all of it with no gap.
1039
+ const lastTurnFits = contentBottom - anchorTop <= viewport.clientHeight;
1040
+ handled = lastTurnFits ? this.scrollToEnd({
1041
+ behavior: 'auto'
1042
+ }) : this.#scrollToElement(anchor, {
1043
+ align: 'start'
1044
+ }, {
1045
+ keepPreviousPeek: true
1046
+ });
1047
+ }
1048
+ } else {
1049
+ handled = position === 'end' ? this.scrollToEnd({
1050
+ behavior: 'auto'
1051
+ }) : this.scrollToStart({
1052
+ behavior: 'auto'
1053
+ });
1054
+ }
1055
+ if (!handled) return false;
1056
+ this.#markDefaultScrollPositionApplied();
1057
+ return true;
1058
+ }
1059
+
1060
+ // The order of the branches matters: first rows, prepended, appended, updated in place.
1061
+ #reconcileScrollPosition(items, previousItemCount, previousFirstItem) {
1062
+ if (this.#flushPendingScrollToMessage()) return;
1063
+ if (previousItemCount === 0) {
1064
+ if (this.#applyDefaultScrollPosition()) return;
1065
+ if (items.length > 0 && this.#autoScroll && this.scrollToEnd({
1066
+ behavior: 'auto'
1067
+ })) return;
1068
+ this.#commitScrollState();
1069
+ this.#scheduleVisibilitySync();
1070
+ return;
1071
+ }
1072
+ const previousFirstItemIndex = previousFirstItem ? items.indexOf(previousFirstItem) : -1;
1073
+ if (this.preserveScrollOnPrepend && previousFirstItemIndex > 0) {
1074
+ // Prepended rows are history, not new turns: keep the reader where they were. A no-op
1075
+ // where the browser's own scroll anchoring already did it.
1076
+ this.#restorePrependedAnchor();
1077
+ return;
1078
+ }
1079
+ if (items.length > previousItemCount) {
1080
+ const anchor = getNewScrollAnchor(items, previousItemCount);
1081
+ if (anchor) {
1082
+ // While following the end, a batch of several anchored turns arriving at once keeps
1083
+ // following, rather than pulling back to the first of them. One new anchor moves to the
1084
+ // top as usual.
1085
+ if (this.#autoScroll && this.#mode === 'following-bottom' && hasMultipleNewScrollAnchors(items, previousItemCount)) {
1086
+ this.scrollToEnd({
1087
+ behavior: 'auto'
1088
+ });
1089
+ return;
1090
+ }
1091
+ this.#scrollToElement(anchor, {
1092
+ align: 'start'
1093
+ }, {
1094
+ keepPreviousPeek: true
1095
+ });
1096
+ this.#handledScrollAnchors.add(anchor);
1097
+ return;
1098
+ }
1099
+ }
1100
+ if (items.length === previousItemCount) {
1101
+ const anchor = getUnanchoredScrollAnchor(items, this.#handledScrollAnchors);
1102
+ if (anchor) {
1103
+ this.#scrollToElement(anchor, {
1104
+ align: 'start'
1105
+ }, {
1106
+ keepPreviousPeek: true
1107
+ });
1108
+ this.#handledScrollAnchors.add(anchor);
1109
+ return;
1110
+ }
1111
+ }
1112
+
1113
+ // Appends with no new anchor, and updates in place: keep following the end if it still
1114
+ // is, else just commit the state.
1115
+ if (this.#mode === 'following-bottom' && this.#autoScroll) {
1116
+ this.scrollToEnd({
1117
+ behavior: 'auto'
1118
+ });
1119
+ } else {
1120
+ this.#commitScrollState();
1121
+ this.#scheduleVisibilitySync();
1122
+ }
1123
+ }
1124
+ #restorePrependedAnchor() {
1125
+ const anchor = this.#prependRestore;
1126
+ const viewport = this.viewport;
1127
+ if (!anchor || !viewport || !anchor.element.isConnected) return false;
1128
+ // Compared within the viewport, not the content: where the browser's scroll anchoring
1129
+ // already kept the row in place, this changes nothing, and it corrects the scroll where it
1130
+ // didn't (Safari), without trusting a capability flag.
1131
+ const delta = getElementViewportTop(anchor.element, viewport) - anchor.viewportTop;
1132
+ if (Math.abs(delta) <= SCROLL_POSITION_EPSILON) return false;
1133
+ viewport.scrollTop += delta;
1134
+ anchor.viewportTop = getElementViewportTop(anchor.element, viewport);
1135
+ this.#scheduleStateCommit();
1136
+ this.#scheduleVisibilitySync();
1137
+ return true;
1138
+ }
1139
+ #capturePrependAnchor() {
1140
+ const content = this.content;
1141
+ const viewport = this.viewport;
1142
+ if (!content || !viewport) {
1143
+ this.#prependRestore = null;
1144
+ return;
1145
+ }
1146
+ const anchor = getFirstVisibleMessageItem({
1147
+ content,
1148
+ spacer: this.spacer,
1149
+ viewport
1150
+ });
1151
+ this.#prependRestore = anchor ? {
1152
+ element: anchor,
1153
+ viewportTop: getElementViewportTop(anchor, viewport)
1154
+ } : null;
1155
+ }
1156
+
1157
+ /**
1158
+ * A scroll by the reader during an anchored stream lets go of the anchor and strands the
1159
+ * spacer it had reserved. Drain it: as the reply grows, or as the reader scrolls to the real
1160
+ * bottom, shrink it toward zero without moving the reader, and hand back to following once
1161
+ * it's gone. `true` when it drained to zero and following took over. It leaves the spacer
1162
+ * alone during a programmatic scroll, and while the reader is above it.
1163
+ */
1164
+ #drainReleasedSpacer() {
1165
+ if (!this.#autoScroll || this.#spacerHeight <= 0 || this.#mode === 'following-bottom' || this.#mode === 'anchored-to-message' || this.#mode === 'settling-jump' || this.#autoscrolling) {
1166
+ return false;
1167
+ }
1168
+ const viewport = this.viewport;
1169
+ const content = this.content;
1170
+ if (!viewport || !content) return false;
1171
+ const contentBottom = getContentBottom({
1172
+ content,
1173
+ spacer: this.spacer,
1174
+ viewport
1175
+ });
1176
+ const viewportBottom = viewport.scrollTop + viewport.clientHeight;
1177
+ // How far the reader has scrolled into the spacer: none while they are above it.
1178
+ if (viewportBottom - contentBottom <= 0) return false;
1179
+ // From the geometry each time, so it converges instead of overshooting across a fling.
1180
+ const next = Math.max(0, contentBottom + this.#spacerHeight - viewportBottom);
1181
+ if (next === 0) {
1182
+ this.scrollToEnd({
1183
+ behavior: 'auto'
1184
+ });
1185
+ return true;
1186
+ }
1187
+ this.#setTailSpacerHeight(next);
1188
+ return false;
1189
+ }
1190
+
1191
+ // ----- Lifecycle ----------------------------------------------------------------------------
1192
+
1193
+ /**
1194
+ * After the render that registered a part: apply the opening position (or, with no rows,
1195
+ * stop holding the viewport hidden), as upstream's provider does in a layout effect.
1196
+ */
1197
+ #scheduleMount() {
1198
+ if (this.#mountScheduled) return;
1199
+ this.#mountScheduled = true;
1200
+ this.#afterRender(() => {
1201
+ this.#mountScheduled = false;
1202
+ if (!this.content || !this.viewport) return;
1203
+ // The content's rows first, as upstream's content does in its own layout effect, which
1204
+ // runs before the provider's.
1205
+ if (this.#contentRendered) {
1206
+ this.#contentRendered = false;
1207
+ const applied = this.#defaultScrollPositionApplied;
1208
+ this.handleContentChange();
1209
+ if (!applied && this.#defaultScrollPositionApplied) return;
1210
+ }
1211
+ if (this.#applyDefaultScrollPosition()) return;
1212
+ if (this.#itemCount === 0) this.#clearPendingDefaultScroll();
1213
+ if (this.#autoScroll && this.#mode === 'following-bottom' && this.#itemCount > 0) {
1214
+ this.scrollToEnd({
1215
+ behavior: 'auto'
1216
+ });
1217
+ return;
1218
+ }
1219
+ this.#commitScrollState();
1220
+ });
1221
+ }
1222
+
1223
+ /**
1224
+ * Runs `callback` once the current render is over (a microtask), held by the test waiter.
1225
+ * Registration happens while rendering, when a tracked value the template has read can't
1226
+ * change.
1227
+ */
1228
+ #afterRender(callback) {
1229
+ const token = waiter.beginAsync();
1230
+ queueMicrotask(() => {
1231
+ try {
1232
+ if (!this.#destroyed) callback();
1233
+ } finally {
1234
+ waiter.endAsync(token);
1235
+ }
1236
+ });
1237
+ }
1238
+
1239
+ /** Stops everything it scheduled. The provider calls it when it goes. */
1240
+ destroy() {
1241
+ this.#destroyed = true;
1242
+ this.#stateFrame.cancel();
1243
+ this.#visibilityFrame.cancel();
1244
+ this.#pendingScrollFrame.cancel();
1245
+ this.#resizeFrame.cancel();
1246
+ if (this.#autoscrollingTimeout !== null) {
1247
+ clearTimeout(this.#autoscrollingTimeout);
1248
+ this.#autoscrollingTimeout = null;
1249
+ waiter.endAsync(this.#autoscrollingToken);
1250
+ this.#autoscrollingToken = null;
1251
+ }
1252
+ this.#visibilityObserver?.disconnect();
1253
+ this.#visibilityObserver = null;
1254
+ }
1255
+ }
1256
+
1257
+ const connectRoot = modifier((element, [state]) => state.connectRoot(element));
1258
+ const connectViewport = modifier((element, [state, preserve]) => {
1259
+ state.preserveScrollOnPrepend = preserve ?? true;
1260
+ return state.connectViewport(element);
1261
+ });
1262
+ const connectContent = modifier((element, [state]) => state.connectContent(element));
1263
+ const connectSpacer = modifier((element, [state]) => state.connectSpacer(element));
1264
+ const connectItem = modifier((element, [state, messageId]) => state.connectItem(element, messageId));
1265
+ // ----- Root ----------------------------------------------------------------------------------
1266
+
1267
+ /**
1268
+ * The scroller's frame, around the viewport and its buttons: upstream's `MessageScroller.Root`.
1269
+ * Like the viewport, it carries `data-scrollable` (`start`, `end`, both or none) and
1270
+ * `data-autoscrolling`, for styling the frame by scroll state, and `data-pending-scroll` until
1271
+ * the opening position applies.
1272
+ */
1273
+ const MessageScrollerRoot = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n <As @as={{@as}} data-test-jn=\"message-scroller\" data-test-jn-name={{@name}} ...attributes data-pending-scroll={{if context.data.pendingDefaultScroll \"\"}} {{connectRoot context.data}}>{{yield}}</As>\n</Consume>", {
1274
+ strictMode: true,
1275
+ scope: () => ({
1276
+ Consume,
1277
+ MessageScrollerState,
1278
+ As,
1279
+ connectRoot
1280
+ })
1281
+ }), templateOnly());
1282
+ // ----- Viewport ------------------------------------------------------------------------------
1283
+
1284
+ /**
1285
+ * The part that scrolls: a labelled region (`role="region"`, `Messages`) a keyboard can reach
1286
+ * and scroll (`tabindex="0"`). The reader scrolling it, by wheel, touch, a scroll key or the
1287
+ * scrollbar, lets go of following and of an anchored turn. It is hidden
1288
+ * (`data-pending-scroll`) until the opening position applies, so the transcript doesn't jump.
1289
+ */
1290
+ const MessageScrollerViewport = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n <As @as={{@as}} role=\"region\" aria-label={{if @label @label (t messages.messageScrollerLabel)}} tabindex=\"0\" data-test-jn-part=\"viewport\" ...attributes data-pending-scroll={{if context.data.pendingDefaultScroll \"\"}} {{connectViewport context.data @preserveScrollOnPrepend}}>{{yield}}</As>\n</Consume>", {
1291
+ strictMode: true,
1292
+ scope: () => ({
1293
+ Consume,
1294
+ MessageScrollerState,
1295
+ As,
1296
+ t,
1297
+ messages,
1298
+ connectViewport
1299
+ })
1300
+ }), templateOnly());
1301
+ // ----- Content -------------------------------------------------------------------------------
1302
+
1303
+ /**
1304
+ * The transcript: its children are the rows, each a `MessageScrollerItem`. It is a live region
1305
+ * (`role="log"`, `aria-relevant="additions"`), so a new row is announced, but not every token
1306
+ * streamed into one; give it `aria-busy` while a turn streams to hold the announcement until
1307
+ * the row is done.
1308
+ */
1309
+ const MessageScrollerContent = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n <As @as={{@as}} role=\"log\" aria-relevant=\"additions\" data-test-jn-part=\"content\" ...attributes {{connectContent context.data}}>\n {{yield}}\n <div aria-hidden=\"true\" data-message-scroller-spacer hidden class={{@spacerClass}} {{connectSpacer context.data}}></div>\n </As>\n</Consume>", {
1310
+ strictMode: true,
1311
+ scope: () => ({
1312
+ Consume,
1313
+ MessageScrollerState,
1314
+ As,
1315
+ connectContent,
1316
+ connectSpacer
1317
+ })
1318
+ }), templateOnly());
1319
+ // ----- Item ----------------------------------------------------------------------------------
1320
+
1321
+ /**
1322
+ * One row of the transcript: a message, a marker, a typing row, a separator, a "load earlier"
1323
+ * row. Give the rows that can be jumped to a `@messageId`, and the one that starts a turn (a
1324
+ * user's message, a "joined the chat" marker) `@scrollAnchor`.
1325
+ */
1326
+ const MessageScrollerItem = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n <As @as={{@as}} data-message-id={{@messageId}} data-scroll-anchor={{if @scrollAnchor \"true\" \"false\"}} data-test-jn-part=\"item\" data-test-jn-value={{@messageId}} ...attributes {{connectItem context.data @messageId}}>{{yield}}</As>\n</Consume>", {
1327
+ strictMode: true,
1328
+ scope: () => ({
1329
+ Consume,
1330
+ MessageScrollerState,
1331
+ As,
1332
+ connectItem
1333
+ })
1334
+ }), templateOnly());
1335
+ // ----- Button --------------------------------------------------------------------------------
1336
+ /** What the button's modifier takes. */
1337
+
1338
+ /** Whether a button pointing that way has somewhere to go. */function isActive(scroller, direction) {
1339
+ return direction === 'start' ? scroller.scrollable.start : scroller.scrollable.end;
1340
+ }
1341
+ /**
1342
+ * Makes an element (a Button of your own) the scroller's button: it scrolls to its edge, and
1343
+ * while there is nothing to scroll to it is `inert`, out of the tab order, and
1344
+ * `data-active="false"`, so it never leaves a stop for the keyboard. While it is active, the
1345
+ * element keeps a `tabindex` of its own. A click listener of yours that comes before it (as
1346
+ * `{{on "click"}}` in `...attributes` does) runs first, and stops the scroll by calling
1347
+ * `event.preventDefault()`, as upstream's `onClick` does. As a component, it is
1348
+ * `MessageScrollerButton`.
1349
+ */
1350
+ const messageScrollerButton = part(({
1351
+ scroller,
1352
+ direction = 'end',
1353
+ behavior = 'smooth'
1354
+ }) => {
1355
+ const active = isActive(scroller, direction);
1356
+ return {
1357
+ attributes: {
1358
+ 'data-active': active ? 'true' : 'false',
1359
+ 'data-direction': direction,
1360
+ inert: !active,
1361
+ // Unset while active, so the element's own tabindex, if it has one, comes back.
1362
+ tabindex: active ? null : '-1',
1363
+ 'data-test-jn-part': 'button',
1364
+ 'data-test-jn-value': direction
1365
+ },
1366
+ on: {
1367
+ click: event => {
1368
+ // A listener of the caller's that ran first may have taken the click over.
1369
+ if (event.defaultPrevented || !isActive(scroller, direction)) return;
1370
+ event.currentTarget?.blur();
1371
+ if (direction === 'start') scroller.scrollToStart({
1372
+ behavior
1373
+ });else scroller.scrollToEnd({
1374
+ behavior
1375
+ });
1376
+ }
1377
+ }
1378
+ };
1379
+ });
1380
+ class ButtonLabel extends Component {
1381
+ get text() {
1382
+ if (this.args.label) return this.args.label;
1383
+ return translate(this, this.args.direction === 'start' ? messages.messageScrollerToStart : messages.messageScrollerToEnd);
1384
+ }
1385
+ static {
1386
+ setComponentTemplate(precompileTemplate("{{this.text}}", {
1387
+ strictMode: true
1388
+ }), this);
1389
+ }
1390
+ }
1391
+ /**
1392
+ * Scrolls to the start or the end of the transcript (`@direction`, default `end`): "jump to
1393
+ * latest". It is a real button, `inert` and out of the tab order while there is nothing to
1394
+ * scroll to; with `autoScroll`, pressing it follows the end again.
1395
+ */
1396
+ const MessageScrollerButton = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n <As @as={{@as}} @tag=\"button\" type=\"button\" ...attributes {{messageScrollerButton scroller=context.data direction=@direction behavior=@behavior}}>\n {{#if (has-block)}}\n {{yield}}\n {{else}}\n <span><ButtonLabel @label={{@label}} @direction={{@direction}} /></span>\n {{/if}}\n </As>\n</Consume>", {
1397
+ strictMode: true,
1398
+ scope: () => ({
1399
+ Consume,
1400
+ MessageScrollerState,
1401
+ As,
1402
+ messageScrollerButton,
1403
+ ButtonLabel
1404
+ })
1405
+ }), templateOnly());
1406
+ // ----- Visibility ----------------------------------------------------------------------------
1407
+ class VisibilityWatcher extends Component {
1408
+ constructor(owner, args) {
1409
+ super(owner, args);
1410
+ registerDestructor(this, args.scroller.observeVisibility());
1411
+ }
1412
+ static {
1413
+ setComponentTemplate(precompileTemplate("{{yield @scroller.visibility}}", {
1414
+ strictMode: true
1415
+ }), this);
1416
+ }
1417
+ }
1418
+ /**
1419
+ * Tracks where the reader is while it is rendered, as upstream's `useMessageScrollerVisibility`
1420
+ * does while subscribed: the anchored turn they are in (`currentAnchorId`, which stays set
1421
+ * after it scrolls out of view) and the rows in view (`visibleMessageIds`). Nothing is tracked
1422
+ * while none is rendered. Rows need a `@messageId` to count.
1423
+ */
1424
+ const MessageScrollerVisibility = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n <VisibilityWatcher @scroller={{context.data}} as |visibility|>{{yield visibility}}</VisibilityWatcher>\n</Consume>", {
1425
+ strictMode: true,
1426
+ scope: () => ({
1427
+ Consume,
1428
+ MessageScrollerState,
1429
+ VisibilityWatcher
1430
+ })
1431
+ }), templateOnly());
1432
+ // ----- Provider ------------------------------------------------------------------------------
1433
+ /** The parts a provider yields, which a styled provider replaces with its own. */
1434
+
1435
+ /**
1436
+ * What a provider yields: its parts, and the scroller's commands and state, for controls
1437
+ * anywhere inside it (upstream's `useMessageScroller` and `useMessageScrollerScrollable`).
1438
+ */
1439
+
1440
+ const PRIMITIVE_PARTS = {
1441
+ Root: MessageScrollerRoot,
1442
+ Viewport: MessageScrollerViewport,
1443
+ Content: MessageScrollerContent,
1444
+ Item: MessageScrollerItem,
1445
+ Button: MessageScrollerButton,
1446
+ Visibility: MessageScrollerVisibility
1447
+ };
1448
+ /** Each provider's yield, for `<MessageScrollerConsumer>`. */
1449
+ const APIS = new WeakMap();
1450
+ /**
1451
+ * A chat transcript's scroller: upstream's `MessageScroller.Provider`, from `@shadcn/react`. It
1452
+ * owns the scroll behaviour and renders nothing of its own; its parts render the frame, the
1453
+ * viewport, the rows and the buttons, wherever they are inside it, and controls anywhere inside
1454
+ * it can drive it:
1455
+ *
1456
+ * <MessageScrollerProvider @autoScroll={{true}} as |s|>
1457
+ * <s.Root>
1458
+ * <s.Viewport>
1459
+ * <s.Content>
1460
+ * {{#each this.messages as |message|}}
1461
+ * <s.Item @messageId={{message.id}} @scrollAnchor={{this.isUser message}}>…</s.Item>
1462
+ * {{/each}}
1463
+ * </s.Content>
1464
+ * </s.Viewport>
1465
+ * <s.Button />
1466
+ * </s.Root>
1467
+ * <button type="button" {{on "click" (fn s.scrollToMessage "intro" (hash behavior="smooth"))}}>Back to the start</button>
1468
+ * </MessageScrollerProvider>
1469
+ *
1470
+ * The parts are also exported on their own (`MessageScrollerItem`), for a component of yours
1471
+ * that renders a row: they find the provider above them.
1472
+ */
1473
+ class MessageScrollerProvider extends Component {
1474
+ state;
1475
+ constructor(owner, args) {
1476
+ super(owner, args);
1477
+ this.state = new MessageScrollerState(() => this.args);
1478
+ registerDestructor(this, () => this.state.destroy());
1479
+ }
1480
+ get api() {
1481
+ const state = this.state;
1482
+ const parts = this.args.parts ?? PRIMITIVE_PARTS;
1483
+ const api = {
1484
+ Root: parts.Root,
1485
+ Viewport: parts.Viewport,
1486
+ Content: parts.Content,
1487
+ Item: parts.Item,
1488
+ Button: parts.Button,
1489
+ Visibility: parts.Visibility,
1490
+ scrollToMessage: state.scrollToMessage,
1491
+ scrollToEnd: state.scrollToEnd,
1492
+ scrollToStart: state.scrollToStart,
1493
+ get scrollable() {
1494
+ return state.scrollable;
1495
+ },
1496
+ state
1497
+ };
1498
+ APIS.set(state, api);
1499
+ return api;
1500
+ }
1501
+ /** Called with the arguments in the template, so a change to one reaches the scroller. */
1502
+ static {
1503
+ n(this.prototype, "api", [cached]);
1504
+ }
1505
+ syncOptions = (..._options) => {
1506
+ this.state.optionsChanged();
1507
+ return undefined;
1508
+ };
1509
+ static {
1510
+ setComponentTemplate(precompileTemplate("{{this.syncOptions @autoScroll @defaultScrollPosition @scrollEdgeThreshold @scrollMargin @scrollPreviousItemPeek}}\n<Provide @data={{this.state}} @key={{MessageScrollerState}} @element={{false}}>\n {{yield this.api}}\n</Provide>", {
1511
+ strictMode: true,
1512
+ scope: () => ({
1513
+ Provide,
1514
+ MessageScrollerState
1515
+ })
1516
+ }), this);
1517
+ }
1518
+ }
1519
+ /**
1520
+ * Gives what the nearest `MessageScrollerProvider` above it yields, to a component of yours
1521
+ * inside it that isn't handed it: a jump menu, a status line.
1522
+ *
1523
+ * <MessageScrollerConsumer as |s|>
1524
+ * {{if s.scrollable.end "New messages below" "Up to date"}}
1525
+ * </MessageScrollerConsumer>
1526
+ */
1527
+ const MessageScrollerConsumer = setComponentTemplate(precompileTemplate("<Consume @key={{MessageScrollerState}} as |context|>\n {{yield (apiOf context.data)}}\n</Consume>", {
1528
+ strictMode: true,
1529
+ scope: () => ({
1530
+ Consume,
1531
+ MessageScrollerState,
1532
+ apiOf
1533
+ })
1534
+ }), templateOnly());
1535
+ function apiOf(state) {
1536
+ const api = APIS.get(state);
1537
+ if (!api) throw new Error('Joinery: <MessageScrollerConsumer> found no provider above it');
1538
+ return api;
1539
+ }
1540
+
1541
+ export { DEFAULT_SCROLL_EDGE_THRESHOLD as D, MessageScrollerButton as M, USER_SCROLL_KEYS as U, DEFAULT_SCROLL_MARGIN as a, DEFAULT_SCROLL_PREVIOUS_ITEM_PEEK as b, MessageScrollerConsumer as c, MessageScrollerContent as d, MessageScrollerItem as e, MessageScrollerProvider as f, MessageScrollerRoot as g, MessageScrollerState as h, MessageScrollerViewport as i, MessageScrollerVisibility as j, messageScrollerButton as m };
1542
+ //# sourceMappingURL=components-DI8Azu05.js.map