@lilydesignsystem/alpine-headless 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (642) hide show
  1. package/LICENSE.md +64 -0
  2. package/README.md +52 -2
  3. package/components/accordion-checkbox.html +37 -0
  4. package/components/accordion-link.html +18 -0
  5. package/components/accordion-list-item.html +19 -0
  6. package/components/accordion-list.html +17 -0
  7. package/components/accordion-nav.html +47 -0
  8. package/components/action-bar-button.html +18 -0
  9. package/components/action-bar.html +28 -0
  10. package/components/action-group.html +55 -0
  11. package/components/action-link.html +18 -0
  12. package/components/address-input.html +18 -0
  13. package/components/addressograph-box.html +18 -0
  14. package/components/affix.html +18 -0
  15. package/components/age-view.html +16 -0
  16. package/components/ai-label.html +18 -0
  17. package/components/alba-community-health-index-input.html +18 -0
  18. package/components/alba-community-health-index-view.html +14 -0
  19. package/components/alert-dialog.html +33 -0
  20. package/components/alert.html +21 -0
  21. package/components/allergy-record-list-item.html +38 -0
  22. package/components/allergy-record-list.html +38 -0
  23. package/components/angle-slider-range-input.html +19 -0
  24. package/components/announcement-banner.html +18 -0
  25. package/components/answer.html +18 -0
  26. package/components/aotearoa-national-health-index-input.html +18 -0
  27. package/components/aotearoa-national-health-index-view.html +14 -0
  28. package/components/area-chart.html +47 -0
  29. package/components/argentina-codigo-unico-de-identificacion-laboral-input.html +18 -0
  30. package/components/argentina-codigo-unico-de-identificacion-laboral-view.html +14 -0
  31. package/components/article-layout.html +17 -0
  32. package/components/as-saudiyah-raqm-al-huwiyah-al-wataniyah-input.html +18 -0
  33. package/components/as-saudiyah-raqm-al-huwiyah-al-wataniyah-view.html +14 -0
  34. package/components/aspect-ratio-container.html +14 -0
  35. package/components/australia-individual-healthcare-identifier-input.html +18 -0
  36. package/components/australia-individual-healthcare-identifier-view.html +14 -0
  37. package/components/australia-tax-file-number-input.html +18 -0
  38. package/components/australia-tax-file-number-view.html +14 -0
  39. package/components/autosuggest.html +32 -0
  40. package/components/avatar-group.html +18 -0
  41. package/components/avatar-image.html +17 -0
  42. package/components/avatar-text.html +17 -0
  43. package/components/avatar.html +18 -0
  44. package/components/back-link.html +18 -0
  45. package/components/badge.html +19 -0
  46. package/components/banner-box.html +18 -0
  47. package/components/banner.html +19 -0
  48. package/components/bar-chart.html +47 -0
  49. package/components/barcode-image.html +16 -0
  50. package/components/beach-ball.html +21 -0
  51. package/components/belgique-numero-de-registre-national-input.html +18 -0
  52. package/components/belgique-numero-de-registre-national-view.html +14 -0
  53. package/components/bharat-aadhaar-input.html +18 -0
  54. package/components/bharat-aadhaar-view.html +12 -0
  55. package/components/blockquote.html +21 -0
  56. package/components/body-map.html +60 -0
  57. package/components/body-text.html +14 -0
  58. package/components/brasil-cartao-nacional-de-saude-input.html +18 -0
  59. package/components/brasil-cartao-nacional-de-saude-view.html +14 -0
  60. package/components/breadcrumb-link.html +18 -0
  61. package/components/breadcrumb-list-item.html +19 -0
  62. package/components/breadcrumb-list.html +17 -0
  63. package/components/breadcrumb-nav.html +17 -0
  64. package/components/bulgaria-edinen-grazhdanski-nomer-input.html +18 -0
  65. package/components/bulgaria-edinen-grazhdanski-nomer-view.html +14 -0
  66. package/components/button-group.html +18 -0
  67. package/components/button-input.html +16 -0
  68. package/components/button.html +17 -0
  69. package/components/byline.html +19 -0
  70. package/components/calendar-day-table.html +30 -0
  71. package/components/calendar-month-table.html +30 -0
  72. package/components/calendar-range-picker.html +18 -0
  73. package/components/calendar-table-body.html +19 -0
  74. package/components/calendar-table-foot.html +19 -0
  75. package/components/calendar-table-head.html +19 -0
  76. package/components/calendar-table-row.html +19 -0
  77. package/components/calendar-table-td.html +22 -0
  78. package/components/calendar-table-th.html +23 -0
  79. package/components/calendar-table.html +19 -0
  80. package/components/calendar-week-table.html +30 -0
  81. package/components/calendar-year-table.html +30 -0
  82. package/components/call-to-action.html +17 -0
  83. package/components/canada-social-insurance-number-input.html +18 -0
  84. package/components/canada-social-insurance-number-view.html +14 -0
  85. package/components/candlestick-chart.html +47 -0
  86. package/components/caption.html +16 -0
  87. package/components/card.html +18 -0
  88. package/components/care-card.html +19 -0
  89. package/components/carousel.html +54 -0
  90. package/components/cascader.html +89 -0
  91. package/components/cesko-cestovni-pas-input.html +18 -0
  92. package/components/cesko-cestovni-pas-view.html +12 -0
  93. package/components/cesko-rodne-cislo-input.html +18 -0
  94. package/components/cesko-rodne-cislo-view.html +14 -0
  95. package/components/character-counter.html +30 -0
  96. package/components/character.html +18 -0
  97. package/components/chat-composer.html +44 -0
  98. package/components/chat-list-item.html +17 -0
  99. package/components/chat-list.html +17 -0
  100. package/components/chat-message.html +17 -0
  101. package/components/chat-nav.html +17 -0
  102. package/components/check-list-item.html +19 -0
  103. package/components/check-list.html +18 -0
  104. package/components/checkbox-group.html +18 -0
  105. package/components/checkbox-input.html +16 -0
  106. package/components/chile-rol-unico-nacional-input.html +18 -0
  107. package/components/chile-rol-unico-nacional-view.html +14 -0
  108. package/components/choropleth-chart.html +47 -0
  109. package/components/citation.html +14 -0
  110. package/components/clamp-text.html +20 -0
  111. package/components/clipboard-copy-button.html +19 -0
  112. package/components/coachmark.html +40 -0
  113. package/components/code-block.html +18 -0
  114. package/components/code.html +14 -0
  115. package/components/collapsible.html +19 -0
  116. package/components/collection-list-item.html +31 -0
  117. package/components/collection-list.html +17 -0
  118. package/components/colombia-cedula-de-ciudadania-input.html +18 -0
  119. package/components/colombia-cedula-de-ciudadania-view.html +14 -0
  120. package/components/color-input.html +16 -0
  121. package/components/color-radio-group.html +18 -0
  122. package/components/color-radio-input.html +19 -0
  123. package/components/column-chart.html +47 -0
  124. package/components/combobox.html +49 -0
  125. package/components/command.html +51 -0
  126. package/components/comment.html +18 -0
  127. package/components/composed-chart.html +47 -0
  128. package/components/container-with-fixed-width.html +18 -0
  129. package/components/container-with-fluid-width.html +18 -0
  130. package/components/container.html +14 -0
  131. package/components/content-block.html +17 -0
  132. package/components/contents-link.html +29 -0
  133. package/components/contents-list-item.html +19 -0
  134. package/components/contents-list.html +17 -0
  135. package/components/contents-nav.html +17 -0
  136. package/components/context-menu-item.html +19 -0
  137. package/components/context-menu.html +41 -0
  138. package/components/contextual-help.html +43 -0
  139. package/components/convert-div.html +18 -0
  140. package/components/convert-from-div.html +14 -0
  141. package/components/convert-from-unit-div.html +14 -0
  142. package/components/convert-from-value-div.html +14 -0
  143. package/components/convert-into-div.html +14 -0
  144. package/components/convert-into-unit-div.html +14 -0
  145. package/components/convert-into-value-div.html +14 -0
  146. package/components/currency-input.html +18 -0
  147. package/components/cymru-rhif-y-gwasanaeth-iechyd-gwladol-input.html +18 -0
  148. package/components/cymru-rhif-y-gwasanaeth-iechyd-gwladol-view.html +14 -0
  149. package/components/danmark-personnummer-input.html +18 -0
  150. package/components/danmark-personnummer-view.html +14 -0
  151. package/components/data-filter-form.html +26 -0
  152. package/components/data-table-body.html +19 -0
  153. package/components/data-table-foot.html +19 -0
  154. package/components/data-table-head.html +19 -0
  155. package/components/data-table-row.html +19 -0
  156. package/components/data-table-td.html +22 -0
  157. package/components/data-table-th.html +23 -0
  158. package/components/data-table.html +19 -0
  159. package/components/date-field.html +38 -0
  160. package/components/date-input.html +16 -0
  161. package/components/date-range.html +26 -0
  162. package/components/date-time-local-input.html +16 -0
  163. package/components/date-time-now-input.html +37 -0
  164. package/components/date-time-view.html +18 -0
  165. package/components/decision-support-card.html +52 -0
  166. package/components/description-list-item.html +14 -0
  167. package/components/description-list.html +17 -0
  168. package/components/details.html +15 -0
  169. package/components/deutschland-krankenversichertennummer-input.html +18 -0
  170. package/components/deutschland-krankenversichertennummer-view.html +14 -0
  171. package/components/device-record-list-item.html +29 -0
  172. package/components/device-record-list.html +29 -0
  173. package/components/dial-group.html +18 -0
  174. package/components/dial.html +19 -0
  175. package/components/dialog.html +32 -0
  176. package/components/diff.html +18 -0
  177. package/components/digital-object-identifier-link.html +18 -0
  178. package/components/do-list-item.html +20 -0
  179. package/components/do-list.html +18 -0
  180. package/components/document-list-item.html +14 -0
  181. package/components/document-list.html +17 -0
  182. package/components/dont-list-item.html +20 -0
  183. package/components/dont-list.html +18 -0
  184. package/components/download-button.html +21 -0
  185. package/components/draft.html +19 -0
  186. package/components/drawer.html +36 -0
  187. package/components/dropdown-menu.html +56 -0
  188. package/components/early-warning-score-view.html +19 -0
  189. package/components/ecuador-cedula-de-identidad-input.html +18 -0
  190. package/components/ecuador-cedula-de-identidad-view.html +14 -0
  191. package/components/editable-form.html +31 -0
  192. package/components/editable.html +25 -0
  193. package/components/eesti-isikukood-input.html +18 -0
  194. package/components/eesti-isikukood-view.html +14 -0
  195. package/components/eire-individual-health-identifier-input.html +20 -0
  196. package/components/eire-individual-health-identifier-view.html +14 -0
  197. package/components/ellada-dematerialised-securities-system-input.html +18 -0
  198. package/components/ellada-dematerialised-securities-system-view.html +14 -0
  199. package/components/email-input.html +16 -0
  200. package/components/email-link.html +18 -0
  201. package/components/emoji-character-radio-group.html +18 -0
  202. package/components/emoji-character-radio-input.html +18 -0
  203. package/components/emoji.html +18 -0
  204. package/components/empty-state.html +20 -0
  205. package/components/end-notes.html +17 -0
  206. package/components/england-national-health-service-number-input.html +18 -0
  207. package/components/england-national-health-service-number-view.html +14 -0
  208. package/components/error-message.html +18 -0
  209. package/components/error-summary.html +20 -0
  210. package/components/espana-codigo-de-identificacion-fiscal-input.html +18 -0
  211. package/components/espana-codigo-de-identificacion-fiscal-view.html +14 -0
  212. package/components/espana-tarjeta-sanitaria-individual-input.html +18 -0
  213. package/components/espana-tarjeta-sanitaria-individual-view.html +14 -0
  214. package/components/event.html +17 -0
  215. package/components/expander.html +33 -0
  216. package/components/feature-card.html +31 -0
  217. package/components/feature-photo.html +25 -0
  218. package/components/field.html +17 -0
  219. package/components/fieldset.html +18 -0
  220. package/components/figure.html +18 -0
  221. package/components/file-dialog.html +32 -0
  222. package/components/file-input.html +16 -0
  223. package/components/file-manager.html +18 -0
  224. package/components/file-tree.html +93 -0
  225. package/components/file-upload.html +35 -0
  226. package/components/five-face-rating-radio-group.html +18 -0
  227. package/components/five-face-rating-radio-input.html +18 -0
  228. package/components/five-face-rating-view.html +19 -0
  229. package/components/five-star-rating-radio-group.html +18 -0
  230. package/components/five-star-rating-radio-input.html +18 -0
  231. package/components/five-star-rating-view.html +19 -0
  232. package/components/flair.html +18 -0
  233. package/components/flex-stack.html +18 -0
  234. package/components/float-button.html +20 -0
  235. package/components/floating-panel.html +19 -0
  236. package/components/footer.html +17 -0
  237. package/components/footnote.html +18 -0
  238. package/components/form.html +17 -0
  239. package/components/framer.html +18 -0
  240. package/components/france-numero-d-identification-au-repertoire-input.html +20 -0
  241. package/components/france-numero-d-identification-au-repertoire-view.html +14 -0
  242. package/components/funnel-chart.html +47 -0
  243. package/components/gantt-table-tbody.html +19 -0
  244. package/components/gantt-table-td.html +22 -0
  245. package/components/gantt-table-tfoot.html +19 -0
  246. package/components/gantt-table-th.html +23 -0
  247. package/components/gantt-table-thead.html +19 -0
  248. package/components/gantt-table-tr.html +19 -0
  249. package/components/gantt-table.html +19 -0
  250. package/components/gauge-chart.html +50 -0
  251. package/components/go-to-next-section.html +16 -0
  252. package/components/go-to-previous-section.html +16 -0
  253. package/components/go-to-top.html +18 -0
  254. package/components/government-banner.html +35 -0
  255. package/components/government-identifier.html +33 -0
  256. package/components/grail-layout-bottom-footer.html +17 -0
  257. package/components/grail-layout-center-main.html +17 -0
  258. package/components/grail-layout-left-aside.html +17 -0
  259. package/components/grail-layout-right-aside.html +17 -0
  260. package/components/grail-layout-top-header.html +17 -0
  261. package/components/grail-layout.html +14 -0
  262. package/components/graphic-block.html +23 -0
  263. package/components/grid.html +22 -0
  264. package/components/hamburger-menu.html +33 -0
  265. package/components/hanguk-jumin-deungnok-beonho-input.html +18 -0
  266. package/components/hanguk-jumin-deungnok-beonho-view.html +14 -0
  267. package/components/header.html +17 -0
  268. package/components/headline.html +22 -0
  269. package/components/heatmap-chart-with-year-of-days.html +55 -0
  270. package/components/heatmap-chart.html +50 -0
  271. package/components/hero-headline.html +23 -0
  272. package/components/hero.html +17 -0
  273. package/components/hidden-input.html +17 -0
  274. package/components/hint.html +14 -0
  275. package/components/hong-kong-identity-card-input.html +18 -0
  276. package/components/hong-kong-identity-card-view.html +14 -0
  277. package/components/horizontal-scroller.html +19 -0
  278. package/components/hover-card.html +30 -0
  279. package/components/hrvatska-osobni-identifikacijski-broj-input.html +18 -0
  280. package/components/hrvatska-osobni-identifikacijski-broj-view.html +14 -0
  281. package/components/iban-input.html +17 -0
  282. package/components/iban-view.html +12 -0
  283. package/components/icon-button.html +18 -0
  284. package/components/icon-list-item.html +22 -0
  285. package/components/icon-list.html +17 -0
  286. package/components/icon.html +18 -0
  287. package/components/image-cropper.html +20 -0
  288. package/components/image-file-input.html +16 -0
  289. package/components/image-input.html +16 -0
  290. package/components/image.html +16 -0
  291. package/components/immunization-record-list-item.html +31 -0
  292. package/components/immunization-record-list.html +31 -0
  293. package/components/indonesia-nomor-induk-kependudukan-input.html +18 -0
  294. package/components/indonesia-nomor-induk-kependudukan-view.html +14 -0
  295. package/components/info-state.html +37 -0
  296. package/components/information-callout.html +18 -0
  297. package/components/input-group.html +28 -0
  298. package/components/input-with-mask.html +28 -0
  299. package/components/input.html +16 -0
  300. package/components/inset-text.html +18 -0
  301. package/components/international-patient-summary-section.html +32 -0
  302. package/components/international-patient-summary.html +100 -0
  303. package/components/iran-kod-e-melli-input.html +18 -0
  304. package/components/iran-kod-e-melli-view.html +14 -0
  305. package/components/island-kennitala-input.html +18 -0
  306. package/components/island-kennitala-view.html +14 -0
  307. package/components/italia-codice-fiscale-input.html +18 -0
  308. package/components/italia-codice-fiscale-view.html +14 -0
  309. package/components/kanban-table-body.html +19 -0
  310. package/components/kanban-table-foot.html +19 -0
  311. package/components/kanban-table-head.html +19 -0
  312. package/components/kanban-table-row.html +19 -0
  313. package/components/kanban-table-td.html +22 -0
  314. package/components/kanban-table-th.html +23 -0
  315. package/components/kanban-table.html +19 -0
  316. package/components/kbd-shortcut.html +27 -0
  317. package/components/kbd.html +19 -0
  318. package/components/kypros-national-passport-number-input.html +18 -0
  319. package/components/kypros-national-passport-number-view.html +14 -0
  320. package/components/label.html +17 -0
  321. package/components/latvija-personas-kods-input.html +18 -0
  322. package/components/latvija-personas-kods-view.html +14 -0
  323. package/components/liechtenstein-national-identity-card-number-input.html +18 -0
  324. package/components/liechtenstein-national-identity-card-number-view.html +14 -0
  325. package/components/liechtenstein-passport-number-input.html +18 -0
  326. package/components/liechtenstein-passport-number-view.html +14 -0
  327. package/components/lietuva-asmens-kodas-input.html +18 -0
  328. package/components/lietuva-asmens-kodas-view.html +14 -0
  329. package/components/lietuva-pasas-input.html +18 -0
  330. package/components/lietuva-pasas-view.html +12 -0
  331. package/components/line-chart.html +47 -0
  332. package/components/listbox.html +36 -0
  333. package/components/loading.html +19 -0
  334. package/components/luxembourg-matricule-input.html +18 -0
  335. package/components/luxembourg-matricule-view.html +14 -0
  336. package/components/magyarorszag-taj-szam-input.html +18 -0
  337. package/components/magyarorszag-taj-szam-view.html +14 -0
  338. package/components/malaysia-kad-pengenalan-input.html +18 -0
  339. package/components/malaysia-kad-pengenalan-view.html +14 -0
  340. package/components/malta-national-identification-number-input.html +18 -0
  341. package/components/malta-national-identification-number-view.html +14 -0
  342. package/components/malta-passport-number-input.html +18 -0
  343. package/components/malta-passport-number-view.html +14 -0
  344. package/components/mark.html +12 -0
  345. package/components/masonry.html +18 -0
  346. package/components/measurement-instance-input.html +16 -0
  347. package/components/measurement-instance-view.html +14 -0
  348. package/components/measurement-system-input.html +16 -0
  349. package/components/measurement-system-view.html +14 -0
  350. package/components/measurement-unit-input.html +16 -0
  351. package/components/measurement-unit-view.html +14 -0
  352. package/components/medical-banner-box-for-advice.html +19 -0
  353. package/components/medical-banner-box-for-danger.html +19 -0
  354. package/components/medical-banner-box.html +19 -0
  355. package/components/medical-banner.html +30 -0
  356. package/components/medication-record-list-item.html +29 -0
  357. package/components/medication-record-list.html +29 -0
  358. package/components/medication-view.html +19 -0
  359. package/components/mentions-input.html +54 -0
  360. package/components/menu-bar-button.html +19 -0
  361. package/components/menu-bar.html +37 -0
  362. package/components/menu-group.html +22 -0
  363. package/components/menu-item.html +19 -0
  364. package/components/menu.html +37 -0
  365. package/components/meter.html +20 -0
  366. package/components/mexico-clave-unica-de-registro-de-poblacion-input.html +18 -0
  367. package/components/mexico-clave-unica-de-registro-de-poblacion-view.html +14 -0
  368. package/components/middle-truncation.html +29 -0
  369. package/components/misr-al-raqm-al-qawmi-input.html +18 -0
  370. package/components/misr-al-raqm-al-qawmi-view.html +14 -0
  371. package/components/mockup-browser.html +18 -0
  372. package/components/mockup-laptop.html +18 -0
  373. package/components/mockup-phone-landscape.html +18 -0
  374. package/components/mockup-phone-portrait.html +18 -0
  375. package/components/mockup-shell.html +18 -0
  376. package/components/mockup-tablet-landscape.html +18 -0
  377. package/components/mockup-tablet-portrait.html +18 -0
  378. package/components/mockup-watch.html +18 -0
  379. package/components/mockup-window.html +18 -0
  380. package/components/month-input.html +16 -0
  381. package/components/multi-select-with-extras.html +25 -0
  382. package/components/multi-select.html +22 -0
  383. package/components/navigation-menu.html +37 -0
  384. package/components/nederland-burgerservice-nummer-input.html +18 -0
  385. package/components/nederland-burgerservice-nummer-view.html +14 -0
  386. package/components/nederland-identiteitskaart-nummer-input.html +18 -0
  387. package/components/nederland-identiteitskaart-nummer-view.html +14 -0
  388. package/components/nederland-paspoort-nummer-input.html +18 -0
  389. package/components/nederland-paspoort-nummer-view.html +14 -0
  390. package/components/net-promoter-score-radio-group.html +18 -0
  391. package/components/net-promoter-score-radio-input.html +18 -0
  392. package/components/net-promoter-score-view.html +14 -0
  393. package/components/newsletter-signup.html +57 -0
  394. package/components/nigeria-national-identification-number-input.html +18 -0
  395. package/components/nigeria-national-identification-number-view.html +14 -0
  396. package/components/nihon-kojin-bango-input.html +18 -0
  397. package/components/nihon-kojin-bango-view.html +14 -0
  398. package/components/norge-fodselsnummer-input.html +18 -0
  399. package/components/norge-fodselsnummer-view.html +14 -0
  400. package/components/notification.html +19 -0
  401. package/components/number-input.html +16 -0
  402. package/components/numeric-rating-scale-picker.html +104 -0
  403. package/components/observation-view.html +22 -0
  404. package/components/one-time-password-input.html +24 -0
  405. package/components/option.html +19 -0
  406. package/components/organization.html +17 -0
  407. package/components/osterreich-sozialversicherungsnummer-input.html +18 -0
  408. package/components/osterreich-sozialversicherungsnummer-view.html +14 -0
  409. package/components/overlay-container.html +18 -0
  410. package/components/padding-reset.html +14 -0
  411. package/components/pagination-link.html +18 -0
  412. package/components/pagination-list-item.html +19 -0
  413. package/components/pagination-list.html +17 -0
  414. package/components/pagination-nav.html +17 -0
  415. package/components/pakistan-computerized-national-identity-card-input.html +18 -0
  416. package/components/pakistan-computerized-national-identity-card-view.html +14 -0
  417. package/components/panel.html +18 -0
  418. package/components/password-input-or-text-input-div.html +29 -0
  419. package/components/password-input.html +16 -0
  420. package/components/person.html +17 -0
  421. package/components/phase-banner.html +18 -0
  422. package/components/photo-pack.html +18 -0
  423. package/components/pictogram.html +31 -0
  424. package/components/picture.html +24 -0
  425. package/components/pie-chart.html +47 -0
  426. package/components/pilipinas-philhealth-identification-number-input.html +18 -0
  427. package/components/pilipinas-philhealth-identification-number-view.html +14 -0
  428. package/components/pin-input-div.html +38 -0
  429. package/components/place.html +17 -0
  430. package/components/polska-numer-identyfikacji-podatkowej-input.html +18 -0
  431. package/components/polska-numer-identyfikacji-podatkowej-view.html +14 -0
  432. package/components/polska-pesel-input.html +18 -0
  433. package/components/polska-pesel-view.html +12 -0
  434. package/components/popconfirm-dialog.html +54 -0
  435. package/components/popover.html +41 -0
  436. package/components/popup.html +46 -0
  437. package/components/portugal-numero-de-identificacao-fiscal-input.html +18 -0
  438. package/components/portugal-numero-de-identificacao-fiscal-view.html +14 -0
  439. package/components/portugal-passaporte-input.html +18 -0
  440. package/components/portugal-passaporte-view.html +14 -0
  441. package/components/postal-code-input.html +16 -0
  442. package/components/postal-code-view.html +14 -0
  443. package/components/prathet-thai-lek-prajam-tua-prachachon-input.html +18 -0
  444. package/components/prathet-thai-lek-prajam-tua-prachachon-view.html +14 -0
  445. package/components/problem-record-list-item.html +37 -0
  446. package/components/problem-record-list.html +37 -0
  447. package/components/procedure-record-list-item.html +29 -0
  448. package/components/procedure-record-list.html +29 -0
  449. package/components/product-card.html +36 -0
  450. package/components/progress-bar.html +19 -0
  451. package/components/progress-circle.html +21 -0
  452. package/components/progress-spinner.html +19 -0
  453. package/components/progress.html +19 -0
  454. package/components/qr-code-image.html +18 -0
  455. package/components/question.html +18 -0
  456. package/components/radar-chart.html +50 -0
  457. package/components/radio-group.html +18 -0
  458. package/components/radio-input.html +16 -0
  459. package/components/range-input.html +16 -0
  460. package/components/record-list-item.html +28 -0
  461. package/components/record-list.html +28 -0
  462. package/components/red-amber-green-radio-group.html +18 -0
  463. package/components/red-amber-green-radio-input.html +18 -0
  464. package/components/red-amber-green-view.html +17 -0
  465. package/components/red-orange-yellow-green-blue-radio-group.html +18 -0
  466. package/components/red-orange-yellow-green-blue-radio-input.html +18 -0
  467. package/components/red-orange-yellow-green-blue-view.html +14 -0
  468. package/components/related-content.html +17 -0
  469. package/components/reset-input.html +16 -0
  470. package/components/resizable.html +20 -0
  471. package/components/review-date.html +16 -0
  472. package/components/ring-chart.html +47 -0
  473. package/components/romania-cod-numeric-personal-input.html +18 -0
  474. package/components/romania-cod-numeric-personal-view.html +14 -0
  475. package/components/romania-pasaport-input.html +18 -0
  476. package/components/romania-pasaport-view.html +14 -0
  477. package/components/rossiya-snils-input.html +18 -0
  478. package/components/rossiya-snils-view.html +16 -0
  479. package/components/sankey-chart.html +50 -0
  480. package/components/scatter-chart.html +47 -0
  481. package/components/schweiz-ahv-nummer-input.html +18 -0
  482. package/components/schweiz-ahv-nummer-view.html +14 -0
  483. package/components/screen-reader-span.html +14 -0
  484. package/components/scroll-area.html +19 -0
  485. package/components/scroll-bar.html +20 -0
  486. package/components/scroller-base.html +19 -0
  487. package/components/scroller-video.html +38 -0
  488. package/components/scroller.html +30 -0
  489. package/components/search-input.html +16 -0
  490. package/components/section-heading.html +22 -0
  491. package/components/section-link.html +18 -0
  492. package/components/section-list-item.html +14 -0
  493. package/components/section-list.html +17 -0
  494. package/components/section-nav.html +17 -0
  495. package/components/segment-group-item.html +21 -0
  496. package/components/segment-group.html +37 -0
  497. package/components/select-with-extras.html +14 -0
  498. package/components/select.html +17 -0
  499. package/components/separator.html +16 -0
  500. package/components/share-page.html +18 -0
  501. package/components/sheet.html +36 -0
  502. package/components/show-more.html +31 -0
  503. package/components/sidebar.html +17 -0
  504. package/components/signature-pad.html +18 -0
  505. package/components/singapore-national-registration-identity-card-input.html +18 -0
  506. package/components/singapore-national-registration-identity-card-view.html +16 -0
  507. package/components/skeleton.html +18 -0
  508. package/components/skip-link.html +18 -0
  509. package/components/slide-out-drawer.html +36 -0
  510. package/components/slider-button.html +19 -0
  511. package/components/slider.html +21 -0
  512. package/components/slovenija-emso-input.html +18 -0
  513. package/components/slovenija-emso-view.html +14 -0
  514. package/components/slovensko-pas-input.html +18 -0
  515. package/components/slovensko-pas-view.html +12 -0
  516. package/components/slovensko-rodne-cislo-input.html +18 -0
  517. package/components/slovensko-rodne-cislo-view.html +14 -0
  518. package/components/sonner.html +19 -0
  519. package/components/south-africa-identity-number-input.html +18 -0
  520. package/components/south-africa-identity-number-view.html +14 -0
  521. package/components/sparkline.html +18 -0
  522. package/components/split-button.html +59 -0
  523. package/components/split-view.html +36 -0
  524. package/components/splitter.html +20 -0
  525. package/components/statistic.html +36 -0
  526. package/components/status-light.html +22 -0
  527. package/components/status-tag.html +17 -0
  528. package/components/step-list-item.html +18 -0
  529. package/components/step-list.html +18 -0
  530. package/components/sticky-promo-banner.html +30 -0
  531. package/components/streaming-text.html +32 -0
  532. package/components/submit-input.html +16 -0
  533. package/components/success-panel.html +18 -0
  534. package/components/summary-box.html +22 -0
  535. package/components/summary-list-item.html +17 -0
  536. package/components/summary-list.html +17 -0
  537. package/components/sunburst-chart.html +47 -0
  538. package/components/suomi-henkilotunnus-input.html +18 -0
  539. package/components/suomi-henkilotunnus-view.html +14 -0
  540. package/components/super-banner.html +19 -0
  541. package/components/sverige-personnummer-input.html +18 -0
  542. package/components/sverige-personnummer-view.html +14 -0
  543. package/components/switch-button.html +19 -0
  544. package/components/tab-bar-button.html +27 -0
  545. package/components/tab-bar.html +59 -0
  546. package/components/tab-panel.html +34 -0
  547. package/components/table-body.html +16 -0
  548. package/components/table-foot.html +16 -0
  549. package/components/table-head.html +16 -0
  550. package/components/table-row.html +18 -0
  551. package/components/table-td.html +20 -0
  552. package/components/table-th.html +24 -0
  553. package/components/table.html +17 -0
  554. package/components/tag-group.html +18 -0
  555. package/components/tag-input-div.html +41 -0
  556. package/components/tag.html +15 -0
  557. package/components/taiwan-guomin-shenfenzheng-tongyi-bianhao-input.html +18 -0
  558. package/components/taiwan-guomin-shenfenzheng-tongyi-bianhao-view.html +14 -0
  559. package/components/task-bar-button.html +17 -0
  560. package/components/task-bar.html +19 -0
  561. package/components/task-list-item.html +20 -0
  562. package/components/task-list.html +18 -0
  563. package/components/tel-input.html +16 -0
  564. package/components/tel-link.html +18 -0
  565. package/components/text-area-input-with-character-counter.html +32 -0
  566. package/components/text-area-input.html +17 -0
  567. package/components/text-input-with-search.html +30 -0
  568. package/components/text-input.html +16 -0
  569. package/components/theme-provider.html +18 -0
  570. package/components/theme-select-option.html +19 -0
  571. package/components/theme-select.html +17 -0
  572. package/components/theme-view.html +14 -0
  573. package/components/thinking.html +21 -0
  574. package/components/tile-map.html +21 -0
  575. package/components/tile.html +18 -0
  576. package/components/time-input.html +16 -0
  577. package/components/time-picker-input.html +19 -0
  578. package/components/timeline-list-item.html +19 -0
  579. package/components/timeline-list.html +17 -0
  580. package/components/timeout-dialog.html +18 -0
  581. package/components/timer-button.html +20 -0
  582. package/components/timer.html +19 -0
  583. package/components/toast.html +19 -0
  584. package/components/toggle-button.html +19 -0
  585. package/components/toggle-group.html +30 -0
  586. package/components/tool-bar-button.html +17 -0
  587. package/components/tool-bar.html +19 -0
  588. package/components/tool-call-error.html +17 -0
  589. package/components/tool-call-input.html +18 -0
  590. package/components/tool-call-name.html +12 -0
  591. package/components/tool-call-output.html +18 -0
  592. package/components/tool-call-status.html +16 -0
  593. package/components/tool-call.html +58 -0
  594. package/components/tooltip.html +30 -0
  595. package/components/tour-list-item.html +20 -0
  596. package/components/tour-list.html +19 -0
  597. package/components/tour.html +59 -0
  598. package/components/transfer-list.html +37 -0
  599. package/components/tree-link.html +18 -0
  600. package/components/tree-list-item.html +21 -0
  601. package/components/tree-list.html +71 -0
  602. package/components/tree-menu.html +71 -0
  603. package/components/tree-nav.html +76 -0
  604. package/components/tree-select.html +89 -0
  605. package/components/tuaisceart-eireann-health-and-care-number-input.html +20 -0
  606. package/components/tuaisceart-eireann-health-and-care-number-view.html +14 -0
  607. package/components/turkiye-tc-kimlik-numarasi-input.html +18 -0
  608. package/components/turkiye-tc-kimlik-numarasi-view.html +14 -0
  609. package/components/ukrayina-reyestratsiyniy-nomer-oblikovoyi-kartky-platnyka-podatkiv-input.html +18 -0
  610. package/components/ukrayina-reyestratsiyniy-nomer-oblikovoyi-kartky-platnyka-podatkiv-view.html +16 -0
  611. package/components/united-kingdom-national-health-service-number-input.html +18 -0
  612. package/components/united-kingdom-national-health-service-number-view.html +14 -0
  613. package/components/united-kingdom-national-insurance-number-input.html +18 -0
  614. package/components/united-kingdom-national-insurance-number-view.html +14 -0
  615. package/components/united-states-social-security-number-input.html +18 -0
  616. package/components/united-states-social-security-number-view.html +14 -0
  617. package/components/url-input.html +16 -0
  618. package/components/uruguay-cedula-de-identidad-input.html +18 -0
  619. package/components/uruguay-cedula-de-identidad-view.html +14 -0
  620. package/components/validation-list-item.html +18 -0
  621. package/components/validation-list.html +18 -0
  622. package/components/video-player.html +25 -0
  623. package/components/viet-nam-can-cuoc-cong-dan-input.html +18 -0
  624. package/components/viet-nam-can-cuoc-cong-dan-view.html +14 -0
  625. package/components/visible.html +17 -0
  626. package/components/warning-callout.html +18 -0
  627. package/components/warning-text.html +22 -0
  628. package/components/watermark.html +26 -0
  629. package/components/week-input.html +16 -0
  630. package/components/wheel-picker.html +46 -0
  631. package/components/yisrael-teudat-zehut-input.html +18 -0
  632. package/components/yisrael-teudat-zehut-view.html +14 -0
  633. package/components/zhongguo-jumin-shenfenzheng-haoma-input.html +18 -0
  634. package/components/zhongguo-jumin-shenfenzheng-haoma-view.html +14 -0
  635. package/index.js +27 -0
  636. package/index.md +53 -0
  637. package/lily-alpine.js +2922 -0
  638. package/middle-truncation.js +74 -0
  639. package/overflow-navigation.js +141 -0
  640. package/package.json +57 -4
  641. package/page-check.js +102 -0
  642. package/wheel-picker.js +219 -0
package/lily-alpine.js ADDED
@@ -0,0 +1,2922 @@
1
+ // Lily Design System — Alpine.js headless plugin.
2
+ //
3
+ // Registers the Alpine.data() behaviours the component snippets in
4
+ // components/*.html use. The snippets own the markup, ARIA and class
5
+ // hooks; this plugin owns state and keyboard handling only. It ships no
6
+ // CSS, no text and no icons. Every behaviour exposes its bindings as
7
+ // x-bind objects so a consumer can reuse them on their own elements.
8
+ //
9
+ // import Alpine from "alpinejs";
10
+ // import lily from "@lilydesignsystem/alpine-headless/plugin";
11
+ // Alpine.plugin(lily);
12
+ // Alpine.start();
13
+
14
+ import { menuKeydown } from "./menu-keys.js";
15
+ import { attachCropper, attachGrid, attachSplitView, attachToolbar } from "./widget-keys.js";
16
+ import { truncateMiddle } from "./middle-truncation.js";
17
+ import { setupOverflowNavigation } from "./overflow-navigation.js";
18
+ import {
19
+ isWheelRtl,
20
+ isWheelTypeaheadKey,
21
+ nextWheelIndex,
22
+ nextWheelPrefix,
23
+ watchWheelScroll,
24
+ wheelMoveKey,
25
+ wheelTypeaheadIndex,
26
+ } from "./wheel-picker.js";
27
+
28
+ /** What focus may land on when an overlay opens. */
29
+ const FOCUSABLE =
30
+ 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
31
+
32
+ /** Roving-focus keys shared by every composite widget (APG). */
33
+ function rovingIndex(key, index, count) {
34
+ if (key === "ArrowRight" || key === "ArrowDown") return (index + 1) % count;
35
+ if (key === "ArrowLeft" || key === "ArrowUp") return (index - 1 + count) % count;
36
+ if (key === "Home") return 0;
37
+ if (key === "End") return count - 1;
38
+ return -1;
39
+ }
40
+
41
+ /** Focus-move for menu-like widgets: returns the item to focus, or null. */
42
+ function menuTarget(key, items, from, horizontal) {
43
+ const next = horizontal ? "ArrowRight" : "ArrowDown";
44
+ const prev = horizontal ? "ArrowLeft" : "ArrowUp";
45
+ if (!items.length) return null;
46
+ if (key === next) return items[(from + 1) % items.length];
47
+ if (key === prev) return items[(from - 1 + items.length) % items.length];
48
+ if (key === "Home") return items[0];
49
+ if (key === "End") return items[items.length - 1];
50
+ return null;
51
+ }
52
+
53
+ /** How many descendants carry an x-bind starting with `prefix` (counts parts before they initialise). */
54
+ function boundCount(root, prefix) {
55
+ return Array.from(root.querySelectorAll("[x-bind]")).filter((e) =>
56
+ e.getAttribute("x-bind").startsWith(prefix),
57
+ ).length;
58
+ }
59
+
60
+ const MENU_ITEMS = '[role="menuitem"]:not([disabled])';
61
+
62
+ /**
63
+ * Shared APG tree-view behaviour for lilyTree, lilyTreeSelect and lilyCascader.
64
+ * Items are role="treeitem" carrying data-item; a branch has aria-expanded and
65
+ * owns a role="group". Visibility is read from the ancestors' aria-expanded.
66
+ */
67
+ function treeCore({ wrap = false, exclusive = false, expanded = [] } = {}) {
68
+ let buffer = "";
69
+ let timer;
70
+ const parentOf = (item) => item.parentElement?.closest('[role="treeitem"]') ?? null;
71
+ const ownText = (item) =>
72
+ Array.from(item.childNodes)
73
+ .filter(
74
+ (n) =>
75
+ n.nodeType !== 8 && !(n.nodeType === 1 && n.getAttribute("role") === "group"),
76
+ )
77
+ .map((n) => n.textContent || "")
78
+ .join("")
79
+ .trim()
80
+ .toLowerCase();
81
+ return {
82
+ expanded: [...expanded],
83
+ selected: [],
84
+ current: "",
85
+ allItems() {
86
+ return Array.from(this.$root.querySelectorAll('[role="treeitem"]'));
87
+ },
88
+ visibleItems() {
89
+ return this.allItems().filter((item) => {
90
+ for (let p = parentOf(item); p; p = parentOf(p)) {
91
+ if (p.getAttribute("aria-expanded") === "false") return false;
92
+ }
93
+ return true;
94
+ });
95
+ },
96
+ itemFor(id) {
97
+ return this.allItems().find((i) => i.dataset.item === id);
98
+ },
99
+ pathOf(id) {
100
+ const path = [];
101
+ for (let item = this.itemFor(id); item; item = parentOf(item))
102
+ path.unshift(item.dataset.item);
103
+ return path;
104
+ },
105
+ focusItem(item) {
106
+ if (!item) return;
107
+ this.current = item.dataset.item;
108
+ item.focus();
109
+ },
110
+ toggle(id) {
111
+ if (this.expanded.includes(id)) {
112
+ this.expanded = this.expanded.filter((e) => e !== id);
113
+ return;
114
+ }
115
+ let next = [...this.expanded, id];
116
+ if (exclusive) {
117
+ const item = this.itemFor(id);
118
+ const siblings = this.allItems().filter(
119
+ (i) => i !== item && parentOf(i) === parentOf(item),
120
+ );
121
+ next = next.filter((e) => !siblings.some((s) => s.dataset.item === e));
122
+ }
123
+ this.expanded = next;
124
+ },
125
+ choose(id) {
126
+ this.selected = [id];
127
+ this.$dispatch("lily:select", { selected: id, path: this.pathOf(id) });
128
+ },
129
+ activate(id, branch) {
130
+ if (branch) this.toggle(id);
131
+ else this.choose(id);
132
+ },
133
+ treeKey(event) {
134
+ const target = event.target;
135
+ const item = target.closest('[role="treeitem"]');
136
+ if (!item || !this.$root.contains(item)) return;
137
+ if (event.ctrlKey || event.metaKey || event.altKey) return;
138
+ if (event.key.length !== 1) buffer = "";
139
+ const visible = this.visibleItems();
140
+ const index = visible.indexOf(item);
141
+ const expandedState = item.getAttribute("aria-expanded");
142
+ const go = (to) => {
143
+ event.preventDefault();
144
+ this.focusItem(to);
145
+ };
146
+ switch (event.key) {
147
+ case "ArrowDown":
148
+ return go(
149
+ visible[
150
+ wrap
151
+ ? (index + 1) % visible.length
152
+ : Math.min(index + 1, visible.length - 1)
153
+ ],
154
+ );
155
+ case "ArrowUp":
156
+ return go(
157
+ visible[
158
+ wrap
159
+ ? (index - 1 + visible.length) % visible.length
160
+ : Math.max(index - 1, 0)
161
+ ],
162
+ );
163
+ case "Home":
164
+ return go(visible[0]);
165
+ case "End":
166
+ return go(visible[visible.length - 1]);
167
+ case "ArrowRight":
168
+ if (target !== item) return;
169
+ event.preventDefault();
170
+ if (expandedState === "false") this.toggle(item.dataset.item);
171
+ else if (expandedState === "true")
172
+ this.focusItem(item.querySelector('[role="group"] [role="treeitem"]'));
173
+ return;
174
+ case "ArrowLeft":
175
+ if (target !== item) return;
176
+ event.preventDefault();
177
+ if (expandedState === "true") this.toggle(item.dataset.item);
178
+ else this.focusItem(parentOf(item));
179
+ return;
180
+ case "Enter":
181
+ case " ":
182
+ if (target !== item) return;
183
+ event.preventDefault();
184
+ item.click(); // Its @click activates, so a key and a pointer tell the page the same thing.
185
+ return;
186
+ case "*":
187
+ event.preventDefault();
188
+ this.allItems()
189
+ .filter(
190
+ (i) =>
191
+ parentOf(i) === parentOf(item) &&
192
+ i.getAttribute("aria-expanded") === "false",
193
+ )
194
+ .forEach((i) => this.toggle(i.dataset.item));
195
+ return;
196
+ }
197
+ if (event.key.length !== 1) return;
198
+ event.preventDefault();
199
+ buffer += event.key.toLowerCase();
200
+ clearTimeout(timer);
201
+ timer = setTimeout(() => {
202
+ buffer = "";
203
+ }, 500);
204
+ const cycle = buffer.length === 1 || [...buffer].every((c) => c === buffer[0]);
205
+ const needle = cycle ? buffer[0] : buffer;
206
+ const cut = index + (cycle ? 1 : 0);
207
+ const ordered = visible.slice(cut).concat(visible.slice(0, cut));
208
+ this.focusItem(ordered.find((i) => ownText(i).startsWith(needle)));
209
+ },
210
+ tree: {
211
+ "@keydown"(event) {
212
+ this.treeKey(event);
213
+ },
214
+ },
215
+ group(id) {
216
+ return {
217
+ role: "group",
218
+ ":hidden"() {
219
+ return !this.expanded.includes(id);
220
+ },
221
+ };
222
+ },
223
+ item(id, branch = false) {
224
+ return {
225
+ role: "treeitem",
226
+ "data-item": id,
227
+ ":tabindex"() {
228
+ return (this.current ||
229
+ this.selected[0] ||
230
+ this.allItems()[0]?.dataset.item) === id
231
+ ? "0"
232
+ : "-1";
233
+ },
234
+ ":aria-selected"() {
235
+ return String(this.selected.includes(id));
236
+ },
237
+ ...(branch
238
+ ? {
239
+ ":aria-expanded"() {
240
+ return String(this.expanded.includes(id));
241
+ },
242
+ }
243
+ : {}),
244
+ "@focus"() {
245
+ this.current = id;
246
+ },
247
+ "@click"(event) {
248
+ if (event.target.closest('[role="treeitem"]') === this.$el)
249
+ this.activate(id, branch);
250
+ },
251
+ };
252
+ },
253
+ };
254
+ }
255
+
256
+ export default function lily(Alpine) {
257
+ // An image cropper, on its root: the crop rectangle's keys.
258
+ Alpine.directive("lily-cropper", (el, _, { cleanup }) => {
259
+ cleanup(attachCropper(el));
260
+ });
261
+
262
+ // A split view, on its root: the divider's keys, and data-split-percent kept in step.
263
+ Alpine.directive("lily-split-view", (el, _, { cleanup }) => {
264
+ cleanup(attachSplitView(el));
265
+ });
266
+
267
+ // A toolbar, on any element: x-lily-toolbar, with an optional selector for the button Escape clicks.
268
+ // KanbanTable, DataTable, GanttTable and the calendar tables: <table role="grid">. The grid keys, over the cells the
269
+ // consumer renders.
270
+ Alpine.directive("lily-grid", (el, _, { cleanup }) => {
271
+ cleanup(attachGrid(el));
272
+ });
273
+
274
+ Alpine.directive("lily-toolbar", (el, { expression }, { cleanup }) => {
275
+ cleanup(attachToolbar(el, expression ? { dismiss: expression } : {}));
276
+ });
277
+
278
+ // ToggleButton: <button aria-pressed>
279
+ Alpine.data("lilyToggleButton", (pressed = false) => ({
280
+ pressed,
281
+ button: {
282
+ type: "button",
283
+ ":aria-pressed"() {
284
+ return String(this.pressed);
285
+ },
286
+ "@click"() {
287
+ this.pressed = !this.pressed;
288
+ },
289
+ },
290
+ }));
291
+
292
+ // SwitchButton: <button role="switch" aria-checked>
293
+ Alpine.data("lilySwitchButton", (checked = false) => ({
294
+ checked,
295
+ button: {
296
+ type: "button",
297
+ role: "switch",
298
+ ":aria-checked"() {
299
+ return String(this.checked);
300
+ },
301
+ "@click"() {
302
+ this.checked = !this.checked;
303
+ },
304
+ },
305
+ }));
306
+
307
+ // Collapsible: a trigger button controlling one content region.
308
+ Alpine.data("lilyCollapsible", (expanded = false) => ({
309
+ expanded,
310
+ root: {
311
+ ":data-expanded"() {
312
+ return String(this.expanded);
313
+ },
314
+ },
315
+ trigger: {
316
+ type: "button",
317
+ ":aria-expanded"() {
318
+ return String(this.expanded);
319
+ },
320
+ "@click"() {
321
+ this.expanded = !this.expanded;
322
+ },
323
+ },
324
+ content: {
325
+ ":hidden"() {
326
+ return !this.expanded;
327
+ },
328
+ },
329
+ }));
330
+
331
+ // ShowMore: like Collapsible; the labels are the consumer's.
332
+ Alpine.data("lilyShowMore", (expanded = false) => ({
333
+ expanded,
334
+ root: {
335
+ ":data-expanded"() {
336
+ return String(this.expanded);
337
+ },
338
+ },
339
+ button: {
340
+ type: "button",
341
+ ":aria-expanded"() {
342
+ return String(this.expanded);
343
+ },
344
+ "@click"() {
345
+ this.expanded = !this.expanded;
346
+ },
347
+ },
348
+ content: {
349
+ ":data-expanded"() {
350
+ return String(this.expanded);
351
+ },
352
+ },
353
+ }));
354
+
355
+ // The Popover API helpers lilyPopover, lilyDropdownMenu and lilyContextMenu share (tasks.md P18-T8, P18-T11).
356
+ function popoverNative() {
357
+ return (
358
+ typeof HTMLElement !== "undefined" &&
359
+ typeof HTMLElement.prototype.showPopover === "function"
360
+ );
361
+ }
362
+ function syncPopover(node, open, native) {
363
+ if (!node || !native) return;
364
+ try {
365
+ if (open) node.showPopover();
366
+ else node.hidePopover();
367
+ } catch {
368
+ // Already in that state (older engines throw): nothing to do.
369
+ }
370
+ }
371
+
372
+ // P16-T4: a popup that is popover="manual" (top layer) and shown from the component's `open`. With the Popover
373
+ // API the browser's UA style hides it while closed and the effect shows or hides it; without (jsdom, older
374
+ // engines) the popover attribute is dropped, which would otherwise keep it hidden, and `hidden` is bound.
375
+ function manualPopover(isOpen) {
376
+ return {
377
+ ":popover"() {
378
+ return popoverNative() ? "manual" : false;
379
+ },
380
+ ":hidden"() {
381
+ return !popoverNative() && !isOpen(this);
382
+ },
383
+ "x-effect"() {
384
+ syncPopover(this.$el, Boolean(isOpen(this)), popoverNative());
385
+ },
386
+ };
387
+ }
388
+
389
+ // Popover (popover, popup, contextual-help): non-modal. The panel is
390
+ // popover="auto" and the trigger names it with command="toggle-popover"
391
+ // commandfor (and popovertarget), so the browser opens it and closes it
392
+ // on Escape and on a click outside (light dismiss), with no script; the
393
+ // panel's `toggle` event keeps `open` in step. Where the Popover API is
394
+ // missing (jsdom, engines before Chrome 114, Firefox 125, Safari 17) the
395
+ // panel falls back to `hidden` (dropping `popover`, which jsdom's UA
396
+ // stylesheet would otherwise keep hidden), the trigger toggles it, and
397
+ // Escape and an outside click close it. `focus: true` moves focus into
398
+ // the panel on open (popup).
399
+ Alpine.data("lilyPopover", (open = false, { focus = false } = {}) => ({
400
+ open,
401
+ init() {
402
+ // Native only: the fallback is the :hidden binding on the panel.
403
+ this.$nextTick(() => this.sync());
404
+ this.$watch("open", (value) => {
405
+ this.sync();
406
+ if (value && focus) this.$nextTick(() => this.focusIn());
407
+ });
408
+ },
409
+ native: popoverNative,
410
+ sync() {
411
+ syncPopover(this.$refs.panel, this.open, this.native());
412
+ },
413
+ focusIn() {
414
+ const panel = this.$refs.panel;
415
+ if (!panel) return;
416
+ (panel.querySelector(FOCUSABLE) || panel).focus();
417
+ },
418
+ close() {
419
+ this.open = false;
420
+ this.$refs.trigger?.focus();
421
+ },
422
+ root: {
423
+ ":data-open"() {
424
+ return String(this.open);
425
+ },
426
+ "@keydown.escape"() {
427
+ if (this.open) this.close();
428
+ },
429
+ // Not `.outside`: Alpine skips elements with no layout box, so it
430
+ // would never fire in a layout-less test DOM. Fallback only: with
431
+ // the Popover API the browser light-dismisses.
432
+ "@click.document"(event) {
433
+ if (this.open && !this.native() && !this.$el.contains(event.target))
434
+ this.open = false;
435
+ },
436
+ },
437
+ trigger: {
438
+ type: "button",
439
+ "x-ref": "trigger",
440
+ "aria-haspopup": "dialog",
441
+ ":aria-expanded"() {
442
+ return String(this.open);
443
+ },
444
+ "@click"(event) {
445
+ // With the Popover API the browser toggles the panel (command / popovertarget).
446
+ if (!event.defaultPrevented && !this.native()) this.open = !this.open;
447
+ },
448
+ },
449
+ panel: {
450
+ "x-ref": "panel",
451
+ ":data-open"() {
452
+ return String(this.open);
453
+ },
454
+ // Without the Popover API: no popover attribute (jsdom's UA stylesheet hides any [popover] it cannot
455
+ // open) and `hidden` instead. With it, the browser's UA style hides the closed popover.
456
+ ":popover"() {
457
+ return this.native() ? "auto" : false;
458
+ },
459
+ ":hidden"() {
460
+ return !this.native() && !this.open;
461
+ },
462
+ "@toggle"(event) {
463
+ this.open = event.newState === "open";
464
+ },
465
+ },
466
+ closer: {
467
+ type: "button",
468
+ "@click"() {
469
+ this.close();
470
+ },
471
+ },
472
+ }));
473
+
474
+ // Tooltip: shows on hover and keyboard focus, Escape dismisses (WCAG 1.4.13).
475
+ Alpine.data("lilyTooltip", () => ({
476
+ visible: false,
477
+ trigger: {
478
+ "@mouseenter"() {
479
+ this.visible = true;
480
+ },
481
+ "@mouseleave"() {
482
+ this.visible = false;
483
+ },
484
+ "@focus"() {
485
+ this.visible = true;
486
+ },
487
+ "@blur"() {
488
+ this.visible = false;
489
+ },
490
+ "@keydown.escape"() {
491
+ this.visible = false;
492
+ },
493
+ },
494
+ tooltip: {
495
+ role: "tooltip",
496
+ ":aria-hidden"() {
497
+ return String(!this.visible);
498
+ },
499
+ ":hidden"() {
500
+ return !this.visible;
501
+ },
502
+ "@mouseenter"() {
503
+ this.visible = true;
504
+ },
505
+ "@mouseleave"() {
506
+ this.visible = false;
507
+ },
508
+ },
509
+ }));
510
+
511
+ // ClipboardCopyButton: the text to copy is the consumer's.
512
+ Alpine.data("lilyClipboardCopy", (text = "") => ({
513
+ copied: false,
514
+ async copy() {
515
+ if (!globalThis.navigator?.clipboard) return;
516
+ await navigator.clipboard.writeText(text);
517
+ this.copied = true;
518
+ },
519
+ button: {
520
+ type: "button",
521
+ ":data-copied"() {
522
+ return String(this.copied);
523
+ },
524
+ "@click"() {
525
+ return this.copy();
526
+ },
527
+ },
528
+ }));
529
+
530
+ // ToggleGroup: independent toggle buttons in one role="group".
531
+ Alpine.data("lilyToggleGroup", (pressed = []) => ({
532
+ pressed: [...pressed],
533
+ isPressed(id) {
534
+ return this.pressed.includes(id);
535
+ },
536
+ toggleItem(id) {
537
+ this.pressed = this.isPressed(id)
538
+ ? this.pressed.filter((p) => p !== id)
539
+ : [...this.pressed, id];
540
+ },
541
+ item(id) {
542
+ return {
543
+ type: "button",
544
+ ":aria-pressed"() {
545
+ return String(this.isPressed(id));
546
+ },
547
+ "@click"() {
548
+ this.toggleItem(id);
549
+ },
550
+ };
551
+ },
552
+ }));
553
+
554
+ // Tabs: TabBar + TabBarButton + TabPanel with automatic activation,
555
+ // roving tabindex and Arrow / Home / End keys (APG tabs pattern).
556
+ Alpine.data("lilyTabs", (selected = "") => ({
557
+ selected,
558
+ tabIds() {
559
+ return Array.from(this.$el.querySelectorAll('[role="tab"]')).map((t) => t.dataset.tab);
560
+ },
561
+ tablist: {
562
+ "@keydown"(event) {
563
+ const tabs = Array.from(this.$el.querySelectorAll('[role="tab"]'));
564
+ const index = tabs.indexOf(document.activeElement);
565
+ if (index < 0) return;
566
+ const next = rovingIndex(event.key, index, tabs.length);
567
+ if (next < 0) return;
568
+ event.preventDefault();
569
+ tabs[next].focus();
570
+ this.selected = tabs[next].dataset.tab;
571
+ },
572
+ },
573
+ tab(id) {
574
+ return {
575
+ role: "tab",
576
+ type: "button",
577
+ "data-tab": id,
578
+ ":id"() {
579
+ return `${id}-tab`;
580
+ },
581
+ ":aria-controls"() {
582
+ return `${id}-panel`;
583
+ },
584
+ ":aria-selected"() {
585
+ return String(this.selected === id);
586
+ },
587
+ ":tabindex"() {
588
+ return this.selected === id ? "0" : "-1";
589
+ },
590
+ "@click"() {
591
+ this.selected = id;
592
+ },
593
+ };
594
+ },
595
+ panel(id) {
596
+ return {
597
+ role: "tabpanel",
598
+ tabindex: "0",
599
+ ":id"() {
600
+ return `${id}-panel`;
601
+ },
602
+ ":aria-labelledby"() {
603
+ return `${id}-tab`;
604
+ },
605
+ ":data-selected"() {
606
+ return String(this.selected === id);
607
+ },
608
+ ":hidden"() {
609
+ return this.selected !== id;
610
+ },
611
+ };
612
+ },
613
+ }));
614
+
615
+ // Dialog: native <dialog>; showModal() where the browser has it.
616
+ Alpine.data("lilyDialog", (open = false) => ({
617
+ open,
618
+ init() {
619
+ this.$watch("open", (value) => this.sync(value));
620
+ if (open) this.$nextTick(() => this.sync(true));
621
+ },
622
+ sync(value) {
623
+ const dialog = this.$refs.dialog;
624
+ if (!dialog) return;
625
+ if (value && !dialog.open) {
626
+ typeof dialog.showModal === "function"
627
+ ? dialog.showModal()
628
+ : dialog.setAttribute("open", "");
629
+ } else if (!value && dialog.open) {
630
+ typeof dialog.close === "function"
631
+ ? dialog.close()
632
+ : dialog.removeAttribute("open");
633
+ }
634
+ },
635
+ trigger: {
636
+ type: "button",
637
+ "aria-haspopup": "dialog",
638
+ "@click"() {
639
+ this.open = true;
640
+ },
641
+ },
642
+ dialog: {
643
+ "x-ref": "dialog",
644
+ "aria-modal": "true",
645
+ "@close"() {
646
+ this.open = false;
647
+ },
648
+ "@cancel"() {
649
+ this.open = false;
650
+ },
651
+ "@keydown.escape"(event) {
652
+ if (!event.defaultPrevented) this.open = false;
653
+ },
654
+ },
655
+ closer: {
656
+ type: "button",
657
+ "@click"() {
658
+ this.open = false;
659
+ },
660
+ },
661
+ }));
662
+ // Dismissible: a banner the user can close. Hides with `hidden` (never an
663
+ // inline style) and emits a bubbling `close` event.
664
+ Alpine.data("lilyDismissible", (open = true) => ({
665
+ open,
666
+ root: {
667
+ ":hidden"() {
668
+ return !this.open;
669
+ },
670
+ },
671
+ dismiss: {
672
+ type: "button",
673
+ "@click"() {
674
+ this.open = false;
675
+ this.$dispatch("close");
676
+ },
677
+ },
678
+ }));
679
+
680
+ // Accordion: trigger / region pairs by id; one open at a time unless `multiple`.
681
+ Alpine.data("lilyAccordion", (multiple = false, open = []) => ({
682
+ open: [...open],
683
+ isOpen(id) {
684
+ return this.open.includes(id);
685
+ },
686
+ toggle(id) {
687
+ if (this.isOpen(id)) this.open = this.open.filter((o) => o !== id);
688
+ else this.open = multiple ? [...this.open, id] : [id];
689
+ },
690
+ trigger(id) {
691
+ return {
692
+ type: "button",
693
+ ":id"() {
694
+ return `${id}-trigger`;
695
+ },
696
+ ":aria-controls"() {
697
+ return `${id}-panel`;
698
+ },
699
+ ":aria-expanded"() {
700
+ return String(this.isOpen(id));
701
+ },
702
+ "@click"() {
703
+ this.toggle(id);
704
+ },
705
+ };
706
+ },
707
+ panel(id) {
708
+ return {
709
+ role: "region",
710
+ ":id"() {
711
+ return `${id}-panel`;
712
+ },
713
+ ":aria-labelledby"() {
714
+ return `${id}-trigger`;
715
+ },
716
+ ":hidden"() {
717
+ return !this.isOpen(id);
718
+ },
719
+ };
720
+ },
721
+ }));
722
+
723
+ // CheckboxAccordion: a real checkbox is the disclosure control.
724
+ Alpine.data("lilyCheckboxAccordion", (checked = false) => ({
725
+ checked,
726
+ input: {
727
+ ":checked"() {
728
+ return this.checked;
729
+ },
730
+ ":aria-expanded"() {
731
+ return String(this.checked);
732
+ },
733
+ "@change"() {
734
+ this.checked = this.$el.checked;
735
+ },
736
+ },
737
+ panel: {
738
+ ":hidden"() {
739
+ return !this.checked;
740
+ },
741
+ },
742
+ }));
743
+
744
+ // HoverCard: opens on hover or focus within, stays open while the pointer
745
+ // is over the card (it is inside the root), Escape dismisses (WCAG 1.4.13).
746
+ Alpine.data("lilyHoverCard", () => ({
747
+ open: false,
748
+ root: {
749
+ ":data-open"() {
750
+ return String(this.open);
751
+ },
752
+ "@mouseenter"() {
753
+ this.open = true;
754
+ },
755
+ "@mouseleave"() {
756
+ this.open = false;
757
+ },
758
+ "@focusin"() {
759
+ this.open = true;
760
+ },
761
+ "@focusout"(event) {
762
+ if (!this.$el.contains(event.relatedTarget)) this.open = false;
763
+ },
764
+ "@keydown.escape"() {
765
+ this.open = false;
766
+ },
767
+ },
768
+ card: {
769
+ ...manualPopover((o) => o.open),
770
+ },
771
+ }));
772
+ // Modal surface (tasks.md P18-T6): drawer, sheet and slide-out drawer are a
773
+ // <dialog> opened with showModal(), so the browser traps Tab, makes the page
774
+ // inert and puts the panel in the top layer. Where showModal is missing
775
+ // (jsdom) it falls back to the open attribute. Focus moves in on open and
776
+ // returns to the opener on close; Escape, the native cancel event and a
777
+ // native close (form method="dialog") all set `open` to false.
778
+ Alpine.data("lilyModalSurface", (open = false) => ({
779
+ open,
780
+ opener: null,
781
+ init() {
782
+ this.$watch("open", (value) => this.sync(value));
783
+ if (open) this.$nextTick(() => this.sync(true));
784
+ },
785
+ sync(value) {
786
+ const dialog = this.$refs.surface;
787
+ if (!dialog) return;
788
+ if (value && !dialog.open) {
789
+ this.opener = document.activeElement;
790
+ typeof dialog.showModal === "function"
791
+ ? dialog.showModal()
792
+ : dialog.setAttribute("open", "");
793
+ if (!dialog.contains(document.activeElement)) {
794
+ (dialog.querySelector(FOCUSABLE) || dialog).focus();
795
+ }
796
+ } else if (!value && dialog.open) {
797
+ typeof dialog.close === "function"
798
+ ? dialog.close()
799
+ : dialog.removeAttribute("open");
800
+ const back = this.opener || this.$refs.trigger;
801
+ this.opener = null;
802
+ if (back && back !== document.body && back.isConnected) back.focus();
803
+ }
804
+ },
805
+ trigger: {
806
+ type: "button",
807
+ "x-ref": "trigger",
808
+ "aria-haspopup": "dialog",
809
+ ":aria-expanded"() {
810
+ return String(this.open);
811
+ },
812
+ "@click"() {
813
+ this.open = true;
814
+ },
815
+ },
816
+ surface: {
817
+ "x-ref": "surface",
818
+ "aria-modal": "true",
819
+ ":data-open"() {
820
+ return String(this.open);
821
+ },
822
+ "@close"() {
823
+ this.open = false;
824
+ },
825
+ "@cancel.prevent"() {
826
+ this.open = false;
827
+ },
828
+ "@keydown.escape.prevent"() {
829
+ this.open = false;
830
+ },
831
+ },
832
+ closer: {
833
+ type: "button",
834
+ "@click"() {
835
+ this.open = false;
836
+ },
837
+ },
838
+ }));
839
+ // Overlay: a dialog-role surface (popup; overlay-container uses `container`)
840
+ // opened by a trigger. Focus moves in on open and returns to the trigger on
841
+ // close; Escape closes. `container` is the backdrop form (overlay-container).
842
+ Alpine.data("lilyOverlay", (open = false) => ({
843
+ open,
844
+ init() {
845
+ this.$watch("open", (value) => {
846
+ if (value) this.$nextTick(() => this.focusIn());
847
+ });
848
+ },
849
+ focusIn() {
850
+ const surface = this.$refs.surface;
851
+ if (!surface) return;
852
+ const first = surface.querySelector(FOCUSABLE);
853
+ (first || surface).focus();
854
+ },
855
+ close() {
856
+ this.open = false;
857
+ this.$refs.trigger?.focus();
858
+ },
859
+ trigger: {
860
+ type: "button",
861
+ "x-ref": "trigger",
862
+ "aria-haspopup": "dialog",
863
+ ":aria-expanded"() {
864
+ return String(this.open);
865
+ },
866
+ "@click"() {
867
+ this.open = !this.open;
868
+ },
869
+ },
870
+ surface: {
871
+ "x-ref": "surface",
872
+ ":data-open"() {
873
+ return String(this.open);
874
+ },
875
+ ":hidden"() {
876
+ return !this.open;
877
+ },
878
+ "@keydown.escape"() {
879
+ if (this.open) this.close();
880
+ },
881
+ },
882
+ closer: {
883
+ type: "button",
884
+ "@click"() {
885
+ this.close();
886
+ },
887
+ },
888
+ container: {
889
+ role: "presentation",
890
+ ":data-open"() {
891
+ return String(this.open);
892
+ },
893
+ ":aria-hidden"() {
894
+ return String(!this.open);
895
+ },
896
+ ":hidden"() {
897
+ return !this.open;
898
+ },
899
+ "@click"(event) {
900
+ if (event.target === this.$el) this.$dispatch("overlay-close");
901
+ },
902
+ },
903
+ }));
904
+
905
+ // Confirm: a non-modal alertdialog with confirm and cancel. Emits the
906
+ // bubbling `lily:confirm` / `lily:cancel` events and closes; Escape cancels.
907
+ Alpine.data("lilyConfirm", (open = false) => ({
908
+ open,
909
+ root: {
910
+ ...manualPopover((o) => o.open),
911
+ "@keydown.escape"() {
912
+ if (this.open) this.cancel();
913
+ },
914
+ },
915
+ trigger: {
916
+ type: "button",
917
+ "aria-haspopup": "dialog",
918
+ ":aria-expanded"() {
919
+ return String(this.open);
920
+ },
921
+ "@click"() {
922
+ this.open = !this.open;
923
+ },
924
+ },
925
+ confirm() {
926
+ this.open = false;
927
+ this.$dispatch("lily:confirm");
928
+ },
929
+ cancel() {
930
+ this.open = false;
931
+ this.$dispatch("lily:cancel");
932
+ },
933
+ confirmButton: {
934
+ type: "button",
935
+ "@click"() {
936
+ this.confirm();
937
+ },
938
+ },
939
+ cancelButton: {
940
+ type: "button",
941
+ "@click"() {
942
+ this.cancel();
943
+ },
944
+ },
945
+ }));
946
+ // Menu / MenuBar: an always-visible menu with roving tabindex. Vertical
947
+ // for role="menu", horizontal for role="menubar"; arrows wrap, Home/End jump.
948
+ Alpine.data("lilyMenu", (orientation = "vertical") => ({
949
+ current: "",
950
+ ids() {
951
+ // $root, not $el: this runs while an item evaluates its own :tabindex.
952
+ return Array.from(this.$root.querySelectorAll(MENU_ITEMS)).map((i) => i.dataset.item);
953
+ },
954
+ menu: {
955
+ "@keydown"(event) {
956
+ menuKeydown(event, orientation);
957
+ },
958
+ // A parent item toggles its submenu; the keys and the rest are menu-keys.js.
959
+ "@click"(event) {
960
+ const item = event.target.closest("[aria-controls]");
961
+ if (!item || !this.$el.contains(item)) return;
962
+ const menu = document.getElementById(item.getAttribute("aria-controls"));
963
+ if (menu?.getAttribute("role") !== "menu") return;
964
+ const open = item.getAttribute("aria-expanded") !== "true";
965
+ item.setAttribute("aria-expanded", String(open));
966
+ menu.hidden = !open;
967
+ },
968
+ },
969
+ item(id) {
970
+ return {
971
+ role: "menuitem",
972
+ "data-item": id,
973
+ ":tabindex"() {
974
+ return (this.current || this.ids()[0]) === id ? "0" : "-1";
975
+ },
976
+ "@focus"() {
977
+ this.current = id;
978
+ },
979
+ };
980
+ },
981
+ }));
982
+
983
+ // DropdownMenu: a trigger opening a role="menu" popup (also the split-button
984
+ // menu and the action-group overflow). Focus moves to the first item on
985
+ // open and back to the trigger on close; Escape and a selection close,
986
+ // Tab and an outside click close without moving focus.
987
+ //
988
+ // The popup is popover="auto" (tasks.md P18-T11), as in lilyPopover: the
989
+ // trigger names it with command="toggle-popover" commandfor (and
990
+ // popovertarget), so the browser opens it and light-dismisses it with no
991
+ // script, and the `toggle` event keeps `open` in step. Where the Popover
992
+ // API is missing the popup falls back to `hidden` and the trigger and an
993
+ // outside click toggle it. The arrow-key focus code has no native
994
+ // equivalent and stays.
995
+ Alpine.data("lilyDropdownMenu", (open = false) => ({
996
+ open,
997
+ init() {
998
+ this.$nextTick(() => this.sync());
999
+ this.$watch("open", (value) => {
1000
+ this.sync();
1001
+ if (value) this.$nextTick(() => this.items()[0]?.focus());
1002
+ });
1003
+ },
1004
+ native: popoverNative,
1005
+ sync() {
1006
+ syncPopover(this.$refs.menu, this.open, this.native());
1007
+ },
1008
+ items() {
1009
+ return Array.from(this.$refs.menu?.querySelectorAll(MENU_ITEMS) ?? []);
1010
+ },
1011
+ close(returnFocus = true) {
1012
+ this.open = false;
1013
+ if (returnFocus) this.$refs.trigger?.focus();
1014
+ },
1015
+ root: {
1016
+ ":data-open"() {
1017
+ return String(this.open);
1018
+ },
1019
+ // Fallback only: with the Popover API the browser light-dismisses.
1020
+ "@click.document"(event) {
1021
+ if (this.open && !this.native() && !this.$el.contains(event.target))
1022
+ this.open = false;
1023
+ },
1024
+ },
1025
+ trigger: {
1026
+ type: "button",
1027
+ "x-ref": "trigger",
1028
+ "aria-haspopup": "menu",
1029
+ ":aria-expanded"() {
1030
+ return String(this.open);
1031
+ },
1032
+ "@click"(event) {
1033
+ // With the Popover API the browser toggles the popup (command / popovertarget).
1034
+ if (!event.defaultPrevented && !this.native()) this.open = !this.open;
1035
+ },
1036
+ "@keydown.arrow-down.prevent"() {
1037
+ this.open = true;
1038
+ },
1039
+ },
1040
+ menu: {
1041
+ role: "menu",
1042
+ "x-ref": "menu",
1043
+ ":popover"() {
1044
+ return this.native() ? "auto" : false;
1045
+ },
1046
+ ":hidden"() {
1047
+ return !this.native() && !this.open;
1048
+ },
1049
+ "@toggle"(event) {
1050
+ this.open = event.newState === "open";
1051
+ },
1052
+ "@keydown"(event) {
1053
+ if (event.key === "Escape") return this.close();
1054
+ if (event.key === "Tab") return this.close(false);
1055
+ const items = this.items();
1056
+ const target = menuTarget(
1057
+ event.key,
1058
+ items,
1059
+ items.indexOf(document.activeElement),
1060
+ false,
1061
+ );
1062
+ if (!target) return;
1063
+ event.preventDefault();
1064
+ target.focus();
1065
+ },
1066
+ },
1067
+ item: {
1068
+ role: "menuitem",
1069
+ tabindex: "-1",
1070
+ "@click"() {
1071
+ this.close();
1072
+ },
1073
+ },
1074
+ }));
1075
+
1076
+ // ContextMenu: opens on the right button, or the ContextMenu key / Shift+F10
1077
+ // on the focusable target. The pointer position is exposed as the CSS
1078
+ // custom properties --context-menu-x / --context-menu-y.
1079
+ //
1080
+ // The menu is popover="auto" (tasks.md P18-T11): opening shows it with
1081
+ // showPopover(), in the top layer, and the browser closes it on Escape and
1082
+ // on a click outside; the `toggle` event keeps `open` in step. Where the
1083
+ // Popover API is missing it falls back to `hidden` and an outside click.
1084
+ Alpine.data("lilyContextMenu", () => ({
1085
+ open: false,
1086
+ x: 0,
1087
+ y: 0,
1088
+ init() {
1089
+ this.$nextTick(() => this.sync());
1090
+ this.$watch("open", (value) => {
1091
+ this.sync();
1092
+ if (value) this.$nextTick(() => this.items()[0]?.focus());
1093
+ });
1094
+ },
1095
+ native: popoverNative,
1096
+ sync() {
1097
+ syncPopover(this.$refs.menu, this.open, this.native());
1098
+ },
1099
+ items() {
1100
+ return Array.from(this.$refs.menu?.querySelectorAll(MENU_ITEMS) ?? []);
1101
+ },
1102
+ close(returnFocus = true) {
1103
+ this.open = false;
1104
+ if (returnFocus) this.$refs.target?.focus();
1105
+ },
1106
+ target: {
1107
+ "x-ref": "target",
1108
+ "@contextmenu.prevent"(event) {
1109
+ this.x = event.clientX;
1110
+ this.y = event.clientY;
1111
+ this.open = true;
1112
+ },
1113
+ "@keydown"(event) {
1114
+ if (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey)) {
1115
+ event.preventDefault();
1116
+ const box = this.$el.getBoundingClientRect();
1117
+ this.x = box.left;
1118
+ this.y = box.bottom;
1119
+ this.open = true;
1120
+ }
1121
+ },
1122
+ },
1123
+ menu: {
1124
+ role: "menu",
1125
+ "x-ref": "menu",
1126
+ ":popover"() {
1127
+ return this.native() ? "auto" : false;
1128
+ },
1129
+ ":hidden"() {
1130
+ return !this.native() && !this.open;
1131
+ },
1132
+ "@toggle"(event) {
1133
+ this.open = event.newState === "open";
1134
+ },
1135
+ ":style"() {
1136
+ return { "--context-menu-x": `${this.x}px`, "--context-menu-y": `${this.y}px` };
1137
+ },
1138
+ // Fallback only: with the Popover API the browser light-dismisses.
1139
+ "@click.document"(event) {
1140
+ if (this.open && !this.native() && !this.$el.contains(event.target))
1141
+ this.open = false;
1142
+ },
1143
+ "@keydown"(event) {
1144
+ if (event.key === "Escape") return this.close();
1145
+ if (event.key === "Tab") return this.close(false);
1146
+ const items = this.items();
1147
+ const target = menuTarget(
1148
+ event.key,
1149
+ items,
1150
+ items.indexOf(document.activeElement),
1151
+ false,
1152
+ );
1153
+ if (!target) return;
1154
+ event.preventDefault();
1155
+ target.focus();
1156
+ },
1157
+ },
1158
+ item: {
1159
+ role: "menuitem",
1160
+ tabindex: "-1",
1161
+ "@click"() {
1162
+ this.close();
1163
+ },
1164
+ },
1165
+ }));
1166
+
1167
+ // Listbox: role="listbox" of role="option" items with roving focus
1168
+ // (arrows wrap, Home/End jump) and selection (single or multiple).
1169
+ Alpine.data("lilyListbox", (multiple = false, selected = []) => ({
1170
+ multiple,
1171
+ selected: [].concat(selected).filter((s) => s !== ""),
1172
+ current: "",
1173
+ ids() {
1174
+ // $root, not $el: this runs while an option evaluates its own :tabindex.
1175
+ return Array.from(this.$root.querySelectorAll('[role="option"]')).map(
1176
+ (o) => o.dataset.option,
1177
+ );
1178
+ },
1179
+ isSelected(id) {
1180
+ return this.selected.includes(id);
1181
+ },
1182
+ choose(id) {
1183
+ if (!this.multiple) this.selected = [id];
1184
+ else
1185
+ this.selected = this.isSelected(id)
1186
+ ? this.selected.filter((s) => s !== id)
1187
+ : [...this.selected, id];
1188
+ this.$dispatch("lily:select", { selected: [...this.selected] });
1189
+ },
1190
+ listbox: {
1191
+ role: "listbox",
1192
+ ":aria-multiselectable"() {
1193
+ return this.multiple ? "true" : null;
1194
+ },
1195
+ "@keydown"(event) {
1196
+ const options = Array.from(this.$el.querySelectorAll('[role="option"]'));
1197
+ const target = menuTarget(
1198
+ event.key,
1199
+ options,
1200
+ options.indexOf(document.activeElement),
1201
+ false,
1202
+ );
1203
+ if (!target) return;
1204
+ event.preventDefault();
1205
+ target.focus();
1206
+ },
1207
+ },
1208
+ option(id) {
1209
+ return {
1210
+ role: "option",
1211
+ "data-option": id,
1212
+ ":aria-selected"() {
1213
+ return String(this.isSelected(id));
1214
+ },
1215
+ ":tabindex"() {
1216
+ return (this.current || this.selected[0] || this.ids()[0]) === id ? "0" : "-1";
1217
+ },
1218
+ "@focus"() {
1219
+ this.current = id;
1220
+ },
1221
+ "@click"() {
1222
+ this.choose(id);
1223
+ },
1224
+ "@keydown.enter.prevent"() {
1225
+ this.choose(id);
1226
+ },
1227
+ "@keydown.space.prevent"() {
1228
+ this.choose(id);
1229
+ },
1230
+ };
1231
+ },
1232
+ }));
1233
+
1234
+ // SegmentGroup: a role="radiogroup" of role="radio" buttons. Arrow keys move
1235
+ // focus and select (APG radio group); one segment is in the tab order.
1236
+ Alpine.data("lilySegmentGroup", (selected = "") => ({
1237
+ selected,
1238
+ ids() {
1239
+ return Array.from(this.$root.querySelectorAll('[role="radio"]')).map(
1240
+ (r) => r.dataset.segment,
1241
+ );
1242
+ },
1243
+ group: {
1244
+ "@keydown"(event) {
1245
+ const items = Array.from(this.$el.querySelectorAll('[role="radio"]'));
1246
+ const from = items.indexOf(document.activeElement);
1247
+ if (from < 0) return;
1248
+ const next = rovingIndex(event.key, from, items.length);
1249
+ if (next < 0) return;
1250
+ const target = items[next];
1251
+ event.preventDefault();
1252
+ target.focus();
1253
+ this.selected = target.dataset.segment;
1254
+ this.$dispatch("lily:select", { selected: this.selected });
1255
+ },
1256
+ },
1257
+ segment(id) {
1258
+ return {
1259
+ role: "radio",
1260
+ type: "button",
1261
+ "data-segment": id,
1262
+ ":aria-checked"() {
1263
+ return String(this.selected === id);
1264
+ },
1265
+ ":tabindex"() {
1266
+ return (this.selected || this.ids()[0]) === id ? "0" : "-1";
1267
+ },
1268
+ "@click"() {
1269
+ this.selected = id;
1270
+ this.$dispatch("lily:select", { selected: id });
1271
+ },
1272
+ };
1273
+ },
1274
+ }));
1275
+
1276
+ // Autosuggest: a text input (role="combobox") proposing the consumer's
1277
+ // suggestions in a role="listbox". The consumer listens for lily:input (or
1278
+ // the input's own input event) and renders role="option" items into the
1279
+ // x-ref="list" element; a MutationObserver keeps the open state, the
1280
+ // option ids and the highlight in step. Choosing writes the option's
1281
+ // data-value (else its text) into the input and dispatches lily:select.
1282
+ Alpine.data("lilyAutosuggest", (value = "") => ({
1283
+ value,
1284
+ wanted: false,
1285
+ active: -1,
1286
+ count: 0,
1287
+ get open() {
1288
+ return this.wanted && this.count > 0;
1289
+ },
1290
+ init() {
1291
+ const list = this.$refs.list;
1292
+ this.refresh();
1293
+ new MutationObserver(() => this.refresh()).observe(list, {
1294
+ childList: true,
1295
+ subtree: true,
1296
+ });
1297
+ },
1298
+ options() {
1299
+ return Array.from(this.$refs.list.querySelectorAll('[role="option"]'));
1300
+ },
1301
+ refresh() {
1302
+ const options = this.options();
1303
+ this.count = options.length;
1304
+ if (this.active >= this.count) this.active = -1;
1305
+ this.mark();
1306
+ },
1307
+ mark() {
1308
+ const list = this.$refs.list;
1309
+ this.options().forEach((el, i) => {
1310
+ if (!el.id) el.id = `${list.id}-option-${i}`;
1311
+ el.setAttribute("aria-selected", String(this.open && i === this.active));
1312
+ });
1313
+ },
1314
+ move(active) {
1315
+ this.active = active;
1316
+ this.wanted = true;
1317
+ this.mark();
1318
+ },
1319
+ close() {
1320
+ this.wanted = false;
1321
+ this.active = -1;
1322
+ this.mark();
1323
+ },
1324
+ choose(el) {
1325
+ const chosen = el.getAttribute("data-value") ?? el.textContent.trim();
1326
+ this.value = chosen;
1327
+ this.close();
1328
+ this.$dispatch("lily:select", { value: chosen });
1329
+ },
1330
+ input: {
1331
+ role: "combobox",
1332
+ autocomplete: "off",
1333
+ "aria-autocomplete": "list",
1334
+ ":aria-expanded"() {
1335
+ return String(this.open);
1336
+ },
1337
+ ":aria-activedescendant"() {
1338
+ return this.open && this.active >= 0
1339
+ ? (this.options()[this.active]?.id ?? null)
1340
+ : null;
1341
+ },
1342
+ ":value"() {
1343
+ return this.value;
1344
+ },
1345
+ "@input"(event) {
1346
+ this.value = event.target.value;
1347
+ this.wanted = true;
1348
+ this.active = -1;
1349
+ this.mark();
1350
+ this.$dispatch("lily:input", { value: this.value });
1351
+ },
1352
+ "@keydown"(event) {
1353
+ if (event.isComposing) return;
1354
+ const count = this.count;
1355
+ const open = this.open;
1356
+ switch (event.key) {
1357
+ case "ArrowDown":
1358
+ if (count === 0) return;
1359
+ if (event.altKey) {
1360
+ if (open) return;
1361
+ this.wanted = true;
1362
+ this.mark();
1363
+ break;
1364
+ }
1365
+ this.move(open ? (this.active + 1) % count : 0);
1366
+ break;
1367
+ case "ArrowUp":
1368
+ if (event.altKey) {
1369
+ if (!open) return;
1370
+ this.close();
1371
+ break;
1372
+ }
1373
+ if (count === 0) return;
1374
+ this.move(open && this.active > 0 ? this.active - 1 : count - 1);
1375
+ break;
1376
+ case "Home":
1377
+ if (!open) return;
1378
+ this.move(0);
1379
+ break;
1380
+ case "End":
1381
+ if (!open) return;
1382
+ this.move(count - 1);
1383
+ break;
1384
+ case "Enter":
1385
+ if (!open || this.active < 0) return;
1386
+ this.choose(this.options()[this.active]);
1387
+ break;
1388
+ case "Escape":
1389
+ if (!open) return;
1390
+ this.close();
1391
+ break;
1392
+ default:
1393
+ return;
1394
+ }
1395
+ event.preventDefault();
1396
+ },
1397
+ "@blur"() {
1398
+ this.close();
1399
+ },
1400
+ },
1401
+ listbox: {
1402
+ role: "listbox",
1403
+ ":hidden"() {
1404
+ return !this.open;
1405
+ },
1406
+ "@mousedown.prevent"() {},
1407
+ "@click"(event) {
1408
+ const el = event.target.closest('[role="option"]');
1409
+ if (el) this.choose(el);
1410
+ },
1411
+ },
1412
+ }));
1413
+
1414
+ // Combobox: a text input driving a role="listbox" popup. The input keeps
1415
+ // DOM focus; the highlighted option is aria-activedescendant. Options are
1416
+ // filtered by the typed text (case-insensitive substring); ArrowDown/Up
1417
+ // move (wrapping), Enter chooses, Escape closes, an outside click closes.
1418
+ Alpine.data("lilyCombobox", (value = "", open = false) => ({
1419
+ value,
1420
+ open,
1421
+ active: "",
1422
+ visible() {
1423
+ return Array.from(this.$root.querySelectorAll('[role="option"]')).filter(
1424
+ (o) => !o.hidden,
1425
+ );
1426
+ },
1427
+ matches(el) {
1428
+ return !this.value || el.textContent.toLowerCase().includes(this.value.toLowerCase());
1429
+ },
1430
+ choose(el) {
1431
+ this.value = el.textContent.trim();
1432
+ this.open = false;
1433
+ this.active = "";
1434
+ this.$dispatch("lily:select", { value: this.value });
1435
+ },
1436
+ root: {
1437
+ ":data-open"() {
1438
+ return String(this.open);
1439
+ },
1440
+ "@click.document"(event) {
1441
+ if (this.open && !this.$el.contains(event.target)) this.open = false;
1442
+ },
1443
+ },
1444
+ input: {
1445
+ role: "combobox",
1446
+ autocomplete: "off",
1447
+ "aria-autocomplete": "list",
1448
+ ":aria-expanded"() {
1449
+ return String(this.open);
1450
+ },
1451
+ ":aria-activedescendant"() {
1452
+ return this.open && this.active ? this.active : null;
1453
+ },
1454
+ ":value"() {
1455
+ return this.value;
1456
+ },
1457
+ "@input"(event) {
1458
+ this.value = event.target.value;
1459
+ this.open = true;
1460
+ this.active = "";
1461
+ },
1462
+ "@keydown"(event) {
1463
+ if (event.isComposing) return;
1464
+ const close = () => {
1465
+ event.preventDefault();
1466
+ this.open = false;
1467
+ this.active = "";
1468
+ };
1469
+ const options = this.visible().filter(
1470
+ (o) => o.getAttribute("aria-disabled") !== "true",
1471
+ );
1472
+ if (event.key === "Escape") {
1473
+ if (this.open) close();
1474
+ return;
1475
+ }
1476
+ if (event.key === "Enter") {
1477
+ const el = options.find((o) => o.id === this.active);
1478
+ if (this.open && el) {
1479
+ event.preventDefault();
1480
+ this.choose(el);
1481
+ }
1482
+ return;
1483
+ }
1484
+ if (event.altKey && event.key === "ArrowUp") {
1485
+ if (this.open) close();
1486
+ return;
1487
+ }
1488
+ if (event.altKey && event.key === "ArrowDown") {
1489
+ if (this.open || !options.length) return;
1490
+ event.preventDefault();
1491
+ this.open = true;
1492
+ return;
1493
+ }
1494
+ const arrow = event.key === "ArrowDown" || event.key === "ArrowUp";
1495
+ const jump = this.open && (event.key === "Home" || event.key === "End");
1496
+ if ((!arrow && !jump) || !options.length) return;
1497
+ event.preventDefault();
1498
+ const target = !this.open
1499
+ ? options[event.key === "ArrowDown" ? 0 : options.length - 1]
1500
+ : menuTarget(
1501
+ event.key,
1502
+ options,
1503
+ options.findIndex((o) => o.id === this.active),
1504
+ false,
1505
+ );
1506
+ this.open = true;
1507
+ this.active = target.id;
1508
+ target.scrollIntoView?.({ block: "nearest" });
1509
+ },
1510
+ "@blur"() {
1511
+ this.open = false;
1512
+ this.active = "";
1513
+ },
1514
+ },
1515
+ listbox: {
1516
+ role: "listbox",
1517
+ ...manualPopover((o) => o.open),
1518
+ },
1519
+ option(id) {
1520
+ return {
1521
+ role: "option",
1522
+ id,
1523
+ ":hidden"() {
1524
+ return !this.matches(this.$el);
1525
+ },
1526
+ ":aria-selected"() {
1527
+ return String(this.active === id);
1528
+ },
1529
+ ":data-active"() {
1530
+ return String(this.active === id);
1531
+ },
1532
+ "@mousedown.prevent"() {},
1533
+ "@click"() {
1534
+ this.choose(this.$el);
1535
+ },
1536
+ };
1537
+ },
1538
+ }));
1539
+
1540
+ // Command: a role="search" palette. A search input filters the role="option"
1541
+ // results (case-insensitive substring); arrows move the active result
1542
+ // (aria-activedescendant, wrapping) and Enter activates it with a click.
1543
+ Alpine.data("lilyCommand", (value = "") => ({
1544
+ value,
1545
+ active: "",
1546
+ visible() {
1547
+ return Array.from(this.$root.querySelectorAll('[role="option"]')).filter(
1548
+ (o) => !o.hidden,
1549
+ );
1550
+ },
1551
+ matches(el) {
1552
+ return !this.value || el.textContent.toLowerCase().includes(this.value.toLowerCase());
1553
+ },
1554
+ input: {
1555
+ ":aria-activedescendant"() {
1556
+ return this.active || null;
1557
+ },
1558
+ ":value"() {
1559
+ return this.value;
1560
+ },
1561
+ "@input"(event) {
1562
+ this.value = event.target.value;
1563
+ this.active = "";
1564
+ },
1565
+ "@keydown"(event) {
1566
+ if (event.isComposing) return;
1567
+ const options = this.visible().filter(
1568
+ (o) => o.getAttribute("aria-disabled") !== "true",
1569
+ );
1570
+ if (!options.length) return;
1571
+ const index = options.findIndex((o) => o.id === this.active);
1572
+ const arrow = event.key === "ArrowDown" || event.key === "ArrowUp";
1573
+ if (arrow || (index >= 0 && (event.key === "Home" || event.key === "End"))) {
1574
+ event.preventDefault();
1575
+ const target = menuTarget(event.key, options, index, false);
1576
+ this.active = target.id;
1577
+ target.scrollIntoView?.({ block: "nearest" });
1578
+ } else if (index >= 0 && event.key === "Enter") {
1579
+ event.preventDefault();
1580
+ options[index].click();
1581
+ } else if (index >= 0 && event.key === "Escape") {
1582
+ event.preventDefault();
1583
+ this.active = "";
1584
+ }
1585
+ },
1586
+ },
1587
+ option(id) {
1588
+ return {
1589
+ role: "option",
1590
+ id,
1591
+ ":hidden"() {
1592
+ return !this.matches(this.$el);
1593
+ },
1594
+ ":aria-selected"() {
1595
+ return String(this.active === id);
1596
+ },
1597
+ ":data-active"() {
1598
+ return String(this.active === id);
1599
+ },
1600
+ };
1601
+ },
1602
+ }));
1603
+
1604
+ // Tree (tree-nav, tree-menu, file-tree): a role="tree" with roving tabindex
1605
+ // and the APG keys. `wrap` makes the arrows wrap (tree-menu); the others stop
1606
+ // at the ends.
1607
+ Alpine.data("lilyTree", (wrap = false, expanded = []) => ({
1608
+ ...treeCore({ wrap, expanded }),
1609
+ }));
1610
+
1611
+ // TreeSelect / Cascader: a role="combobox" trigger and a panel
1612
+ // with a tree. Opening moves focus into the tree; Escape returns it to the
1613
+ // trigger; choosing a leaf sets the selection and (single mode) closes.
1614
+ // `exclusive` opens one branch per level, which is the cascader.
1615
+ let treePopupCount = 0;
1616
+ const popupTree = (name, exclusive) =>
1617
+ Alpine.data(name, (multiple = false, expanded = []) => ({
1618
+ ...treeCore({ exclusive, expanded }),
1619
+ multiple,
1620
+ open: false,
1621
+ popupId: `tree-popup-${++treePopupCount}`,
1622
+ init() {
1623
+ this.$watch("open", (value) => {
1624
+ if (value)
1625
+ this.$nextTick(() =>
1626
+ this.focusItem(
1627
+ this.itemFor(this.selected[0]) ?? this.visibleItems()[0],
1628
+ ),
1629
+ );
1630
+ });
1631
+ },
1632
+ choose(id) {
1633
+ if (this.multiple) {
1634
+ this.selected = this.selected.includes(id)
1635
+ ? this.selected.filter((s) => s !== id)
1636
+ : [...this.selected, id];
1637
+ } else {
1638
+ this.selected = [id];
1639
+ this.open = false;
1640
+ this.$refs.trigger?.focus();
1641
+ }
1642
+ this.$dispatch("lily:select", {
1643
+ selected: [...this.selected],
1644
+ path: this.pathOf(id),
1645
+ });
1646
+ },
1647
+ root: {
1648
+ ":data-multiple"() {
1649
+ return this.multiple ? "true" : null;
1650
+ },
1651
+ "@keydown.escape"() {
1652
+ if (!this.open) return;
1653
+ this.open = false;
1654
+ this.$refs.trigger?.focus();
1655
+ },
1656
+ "@click.document"(event) {
1657
+ if (this.open && !this.$el.contains(event.target)) this.open = false;
1658
+ },
1659
+ },
1660
+ trigger: {
1661
+ type: "button",
1662
+ role: "combobox",
1663
+ "aria-haspopup": "tree",
1664
+ "x-ref": "trigger",
1665
+ ":aria-expanded"() {
1666
+ return String(this.open);
1667
+ },
1668
+ ":aria-controls"() {
1669
+ return this.popupId;
1670
+ },
1671
+ "@click"() {
1672
+ this.open = !this.open;
1673
+ },
1674
+ "@keydown.arrow-down.prevent"() {
1675
+ this.open = true;
1676
+ },
1677
+ },
1678
+ panel: {
1679
+ ...manualPopover((o) => o.open),
1680
+ ":id"() {
1681
+ return this.popupId;
1682
+ },
1683
+ },
1684
+ // aria-multiselectable is valid on the tree, not on the combobox root.
1685
+ tree: {
1686
+ "@keydown"(event) {
1687
+ this.treeKey(event);
1688
+ },
1689
+ ":aria-multiselectable"() {
1690
+ return this.multiple ? "true" : null;
1691
+ },
1692
+ },
1693
+ }));
1694
+ popupTree("lilyTreeSelect", false);
1695
+ popupTree("lilyCascader", true);
1696
+
1697
+ // CharacterCounter: a polite status "count / max" (or just count). Give it
1698
+ // `forId` to follow a field by id; otherwise set `count` yourself. Exposes
1699
+ // data-count, data-max, data-remaining and (only when over) data-over-limit.
1700
+ // A counter's root carries the data attributes; inside it the visible count is aria-hidden, and a visually hidden
1701
+ // role="status" takes the same text once the count has stopped changing for announceDelay ms, so a run of keystrokes
1702
+ // is announced once, as GOV.UK's character count does (spec/detent-lessons, P26-T9).
1703
+ const counterText = function () {
1704
+ return this.max == null ? String(this.count) : `${this.count} / ${this.max}`;
1705
+ };
1706
+ const announceCount = function () {
1707
+ this.announced = this.counterText;
1708
+ this.$watch("counterText", (next) => {
1709
+ clearTimeout(this._announceTimer);
1710
+ this._announceTimer = setTimeout(() => (this.announced = next), this.announceDelay);
1711
+ });
1712
+ };
1713
+ const counterShownBind = {
1714
+ "aria-hidden": "true",
1715
+ "x-text"() {
1716
+ return this.counterText;
1717
+ },
1718
+ };
1719
+ const counterStatusBind = {
1720
+ role: "status",
1721
+ "x-text"() {
1722
+ return this.announced;
1723
+ },
1724
+ };
1725
+ const counterBind = {
1726
+ ":data-count"() {
1727
+ return String(this.count);
1728
+ },
1729
+ ":data-max"() {
1730
+ return this.max == null ? null : String(this.max);
1731
+ },
1732
+ ":data-remaining"() {
1733
+ return this.max == null ? null : String(this.max - this.count);
1734
+ },
1735
+ ":data-over-limit"() {
1736
+ return this.max != null && this.count > this.max ? "" : null;
1737
+ },
1738
+ };
1739
+
1740
+ Alpine.data("lilyCharacterCounter", (max = null, forId = "", announceDelay = 1000) => ({
1741
+ count: 0,
1742
+ max,
1743
+ announceDelay,
1744
+ announced: "",
1745
+ get counterText() {
1746
+ return counterText.call(this);
1747
+ },
1748
+ destroy() {
1749
+ clearTimeout(this._announceTimer);
1750
+ },
1751
+ init() {
1752
+ const field = forId && document.getElementById(forId);
1753
+ if (field) this.count = field.value.length;
1754
+ announceCount.call(this);
1755
+ if (!field) return;
1756
+ field.addEventListener("input", () => {
1757
+ this.count = field.value.length;
1758
+ });
1759
+ },
1760
+ counter: counterBind,
1761
+ counterShown: counterShownBind,
1762
+ counterStatus: counterStatusBind,
1763
+ }));
1764
+
1765
+ // A textarea with its own counter, linked by aria-describedby.
1766
+ Alpine.data("lilyCountedTextarea", (max = null, value = "", announceDelay = 1000) => ({
1767
+ value,
1768
+ max,
1769
+ announceDelay,
1770
+ announced: "",
1771
+ get count() {
1772
+ return this.value.length;
1773
+ },
1774
+ get counterText() {
1775
+ return counterText.call(this);
1776
+ },
1777
+ init() {
1778
+ announceCount.call(this);
1779
+ },
1780
+ destroy() {
1781
+ clearTimeout(this._announceTimer);
1782
+ },
1783
+ textarea: {
1784
+ ":value"() {
1785
+ return this.value;
1786
+ },
1787
+ "@input"(event) {
1788
+ this.value = event.target.value;
1789
+ },
1790
+ ":aria-invalid"() {
1791
+ return this.max != null && this.count > this.max ? "true" : null;
1792
+ },
1793
+ },
1794
+ counter: counterBind,
1795
+ counterShown: counterShownBind,
1796
+ counterStatus: counterStatusBind,
1797
+ }));
1798
+
1799
+ // Password field with a show / hide toggle button (aria-pressed).
1800
+ Alpine.data("lilyPasswordToggle", (visible = false) => ({
1801
+ visible,
1802
+ input: {
1803
+ ":type"() {
1804
+ return this.visible ? "text" : "password";
1805
+ },
1806
+ autocomplete: "current-password",
1807
+ spellcheck: "false",
1808
+ },
1809
+ toggle: {
1810
+ type: "button",
1811
+ ":aria-pressed"() {
1812
+ return String(this.visible);
1813
+ },
1814
+ "@click"() {
1815
+ this.visible = !this.visible;
1816
+ },
1817
+ },
1818
+ }));
1819
+
1820
+ // PinInput: one digit per input. A digit moves focus on, Backspace on an empty
1821
+ // box moves back, arrows move, and a paste fills the boxes from the focused
1822
+ // one. Non-digits are dropped. `lily:complete` fires when every box is filled.
1823
+ Alpine.data("lilyPinInput", () => ({
1824
+ boxes() {
1825
+ return Array.from(this.$root.querySelectorAll("input"));
1826
+ },
1827
+ get value() {
1828
+ return this.boxes()
1829
+ .map((b) => b.value)
1830
+ .join("");
1831
+ },
1832
+ sync() {
1833
+ const value = this.value;
1834
+ this.$root.dataset.value = value;
1835
+ if (value.length === this.boxes().length) this.$dispatch("lily:complete", { value });
1836
+ },
1837
+ fill(boxes, from, digits) {
1838
+ digits.split("").forEach((d, k) => {
1839
+ if (boxes[from + k]) boxes[from + k].value = d;
1840
+ });
1841
+ boxes[Math.min(from + digits.length, boxes.length - 1)]?.focus();
1842
+ this.sync();
1843
+ },
1844
+ digit(i) {
1845
+ return {
1846
+ type: "text",
1847
+ inputmode: "numeric",
1848
+ maxlength: "1",
1849
+ autocomplete: "off",
1850
+ "@input"(event) {
1851
+ const boxes = this.boxes();
1852
+ const digits = event.target.value.replace(/\D/g, "");
1853
+ event.target.value = "";
1854
+ if (digits) this.fill(boxes, i, digits);
1855
+ else this.sync();
1856
+ },
1857
+ "@paste"(event) {
1858
+ event.preventDefault();
1859
+ this.fill(
1860
+ this.boxes(),
1861
+ i,
1862
+ (event.clipboardData?.getData("text") ?? "").replace(/\D/g, ""),
1863
+ );
1864
+ },
1865
+ "@keydown"(event) {
1866
+ const boxes = this.boxes();
1867
+ if (event.key === "Backspace" && !event.target.value && i > 0) {
1868
+ event.preventDefault();
1869
+ boxes[i - 1].value = "";
1870
+ boxes[i - 1].focus();
1871
+ this.sync();
1872
+ } else if (event.key === "ArrowLeft" && i > 0) {
1873
+ event.preventDefault();
1874
+ boxes[i - 1].focus();
1875
+ } else if (event.key === "ArrowRight" && i < boxes.length - 1) {
1876
+ event.preventDefault();
1877
+ boxes[i + 1].focus();
1878
+ }
1879
+ },
1880
+ };
1881
+ },
1882
+ }));
1883
+
1884
+ // TagInputDiv: Enter adds the trimmed text as a tag (duplicates ignored) and
1885
+ // clears the field; Backspace on an empty field removes the last tag.
1886
+ Alpine.data("lilyTagInputDiv", (tags = []) => ({
1887
+ tags: [...tags],
1888
+ add(text) {
1889
+ const tag = text.trim();
1890
+ if (!tag || this.tags.includes(tag)) return false;
1891
+ this.tags = [...this.tags, tag];
1892
+ this.$dispatch("lily:add", { value: tag, tags: [...this.tags] });
1893
+ return true;
1894
+ },
1895
+ remove(tag) {
1896
+ this.tags = this.tags.filter((t) => t !== tag);
1897
+ this.$dispatch("lily:remove", { value: tag, tags: [...this.tags] });
1898
+ },
1899
+ input: {
1900
+ type: "text",
1901
+ "@keydown"(event) {
1902
+ if (event.key === "Enter" && this.$el.value.trim()) {
1903
+ event.preventDefault();
1904
+ this.add(this.$el.value);
1905
+ this.$el.value = "";
1906
+ } else if (event.key === "Backspace" && !this.$el.value && this.tags.length) {
1907
+ this.remove(this.tags[this.tags.length - 1]);
1908
+ }
1909
+ },
1910
+ },
1911
+ }));
1912
+
1913
+ // CurrencyInput: a decimal text field that keeps only digits and one ".",
1914
+ // carries data-currency-code, and flags aria-invalid outside min / max.
1915
+ // Formatting (Intl.NumberFormat, locale) stays the consumer's.
1916
+ Alpine.data("lilyCurrencyInput", (currencyCode, min = null, max = null) => ({
1917
+ input: {
1918
+ type: "text",
1919
+ inputmode: "decimal",
1920
+ ":data-currency-code"() {
1921
+ return currencyCode ?? null;
1922
+ },
1923
+ "@input"() {
1924
+ const [whole, ...rest] = this.$el.value.replace(/[^\d.]/g, "").split(".");
1925
+ this.$el.value = rest.length ? `${whole}.${rest.join("")}` : whole;
1926
+ const n = Number(this.$el.value);
1927
+ const bad =
1928
+ this.$el.value !== "" && ((min != null && n < min) || (max != null && n > max));
1929
+ if (bad) this.$el.setAttribute("aria-invalid", "true");
1930
+ else this.$el.removeAttribute("aria-invalid");
1931
+ },
1932
+ },
1933
+ }));
1934
+
1935
+ // TextInputWithSearch: Enter in the field or the button emits `lily:search`.
1936
+ Alpine.data("lilySearch", (value = "") => ({
1937
+ value,
1938
+ search() {
1939
+ this.$dispatch("lily:search", { value: this.value });
1940
+ },
1941
+ input: {
1942
+ type: "text",
1943
+ ":value"() {
1944
+ return this.value;
1945
+ },
1946
+ "@input"(event) {
1947
+ this.value = event.target.value;
1948
+ },
1949
+ "@keydown.enter.prevent"() {
1950
+ this.search();
1951
+ },
1952
+ },
1953
+ button: {
1954
+ type: "button",
1955
+ "@click"() {
1956
+ this.search();
1957
+ },
1958
+ },
1959
+ }));
1960
+
1961
+ // MentionsInput: typing the trigger character opens suggestions filtered by
1962
+ // the text after it. Arrows move the active option (aria-activedescendant),
1963
+ // Enter replaces "@query" with the chosen option, Escape closes.
1964
+ Alpine.data("lilyMentions", (trigger = "@") => ({
1965
+ open: false,
1966
+ active: "",
1967
+ query: "",
1968
+ visible() {
1969
+ return Array.from(this.$root.querySelectorAll('[role="option"]')).filter(
1970
+ (o) => !o.hidden,
1971
+ );
1972
+ },
1973
+ match(el) {
1974
+ return el.textContent.toLowerCase().includes(this.query.toLowerCase());
1975
+ },
1976
+ scan(value) {
1977
+ const at = value.lastIndexOf(trigger);
1978
+ const tail = at < 0 ? null : value.slice(at + trigger.length);
1979
+ // An email address does not open it; text written without spaces does.
1980
+ const glued = at > 0 && /[A-Za-z0-9._-]$/.test(value.slice(0, at));
1981
+ this.open = tail !== null && !/\s/.test(tail) && !glued;
1982
+ this.query = this.open ? tail : "";
1983
+ this.active = "";
1984
+ },
1985
+ choose(el) {
1986
+ const input = this.$refs.input;
1987
+ const at = input.value.lastIndexOf(trigger);
1988
+ input.value = `${input.value.slice(0, at)}${trigger}${el.textContent.trim()} `;
1989
+ this.open = false;
1990
+ this.active = "";
1991
+ input.focus();
1992
+ this.$dispatch("lily:select", { value: el.textContent.trim() });
1993
+ },
1994
+ input: {
1995
+ "x-ref": "input",
1996
+ role: "combobox",
1997
+ "aria-haspopup": "listbox",
1998
+ "aria-autocomplete": "list",
1999
+ ":aria-expanded"() {
2000
+ return String(this.open);
2001
+ },
2002
+ ":aria-activedescendant"() {
2003
+ return this.open && this.active ? this.active : null;
2004
+ },
2005
+ "@input"(event) {
2006
+ this.scan(event.target.value);
2007
+ },
2008
+ "@keydown"(event) {
2009
+ if (event.isComposing || !this.open) return;
2010
+ if (event.key === "Escape") {
2011
+ event.preventDefault();
2012
+ this.open = false;
2013
+ this.active = "";
2014
+ return;
2015
+ }
2016
+ if (event.key === "Enter") {
2017
+ const el = this.visible().find((o) => o.id === this.active);
2018
+ if (el) {
2019
+ event.preventDefault();
2020
+ this.choose(el);
2021
+ }
2022
+ return;
2023
+ }
2024
+ if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
2025
+ event.preventDefault();
2026
+ const options = this.visible();
2027
+ if (!options.length) return;
2028
+ this.active = menuTarget(
2029
+ event.key,
2030
+ options,
2031
+ options.findIndex((o) => o.id === this.active),
2032
+ false,
2033
+ ).id;
2034
+ },
2035
+ },
2036
+ panel: {
2037
+ ...manualPopover((o) => o.open),
2038
+ },
2039
+ option(id) {
2040
+ return {
2041
+ role: "option",
2042
+ id,
2043
+ ":hidden"() {
2044
+ return !this.match(this.$el);
2045
+ },
2046
+ ":aria-selected"() {
2047
+ return String(this.active === id);
2048
+ },
2049
+ "@mousedown.prevent"() {},
2050
+ "@click"() {
2051
+ this.choose(this.$el);
2052
+ },
2053
+ };
2054
+ },
2055
+ }));
2056
+
2057
+ // Editable: a button-like display that swaps for a text field. Enter,
2058
+ // Space or a click edits; Enter confirms; Escape cancels. The display's
2059
+ // accessible name is "value, label" so the visible text is in the name.
2060
+ Alpine.data("lilyEditable", (value = "", editing = false, label = "", disabled = false) => ({
2061
+ value,
2062
+ draft: value,
2063
+ editing,
2064
+ disabled,
2065
+ label,
2066
+ edit() {
2067
+ if (this.disabled) return;
2068
+ this.draft = this.value;
2069
+ this.editing = true;
2070
+ this.$nextTick(() => this.$refs.input?.focus());
2071
+ },
2072
+ confirm() {
2073
+ this.value = this.draft;
2074
+ this.editing = false;
2075
+ this.$dispatch("lily:change", { value: this.value });
2076
+ this.$nextTick(() => this.$refs.display?.focus());
2077
+ },
2078
+ cancel() {
2079
+ this.draft = this.value;
2080
+ this.editing = false;
2081
+ this.$nextTick(() => this.$refs.display?.focus());
2082
+ },
2083
+ // A native button: focusable, with Enter and Space, so it needs no role and no keys of its own.
2084
+ display: {
2085
+ type: "button",
2086
+ "x-ref": "display",
2087
+ ":disabled"() {
2088
+ return this.disabled;
2089
+ },
2090
+ ":aria-label"() {
2091
+ return this.value ? `${this.value}, ${this.label}` : this.label;
2092
+ },
2093
+ ":hidden"() {
2094
+ return this.editing;
2095
+ },
2096
+ "x-text"() {
2097
+ return this.value;
2098
+ },
2099
+ "@click"() {
2100
+ this.edit();
2101
+ },
2102
+ },
2103
+ input: {
2104
+ type: "text",
2105
+ "x-ref": "input",
2106
+ ":aria-label"() {
2107
+ return this.label;
2108
+ },
2109
+ ":value"() {
2110
+ return this.draft;
2111
+ },
2112
+ ":hidden"() {
2113
+ return !this.editing;
2114
+ },
2115
+ "@input"(event) {
2116
+ this.draft = event.target.value;
2117
+ },
2118
+ "@keydown.enter.prevent"() {
2119
+ this.confirm();
2120
+ },
2121
+ "@keydown.escape.prevent"() {
2122
+ this.cancel();
2123
+ },
2124
+ },
2125
+ }));
2126
+
2127
+ // EditableForm: a form shown only while editing. Submit saves (the consumer
2128
+ // handles `lily:submit`) and closes; Escape cancels and closes. The form is
2129
+ // tabindex -1 and takes focus when it opens.
2130
+ Alpine.data("lilyEditableForm", (editing = false) => ({
2131
+ editing,
2132
+ edit() {
2133
+ this.editing = true;
2134
+ this.$nextTick(() => this.$refs.form?.focus());
2135
+ },
2136
+ cancel() {
2137
+ this.editing = false;
2138
+ this.$dispatch("lily:cancel");
2139
+ },
2140
+ editButton: {
2141
+ type: "button",
2142
+ ":hidden"() {
2143
+ return this.editing;
2144
+ },
2145
+ "@click"() {
2146
+ this.edit();
2147
+ },
2148
+ },
2149
+ form: {
2150
+ "x-ref": "form",
2151
+ tabindex: "-1",
2152
+ ":hidden"() {
2153
+ return !this.editing;
2154
+ },
2155
+ "@submit.prevent"() {
2156
+ this.editing = false;
2157
+ this.$dispatch("lily:submit", {
2158
+ values: Object.fromEntries(new FormData(this.$el)),
2159
+ });
2160
+ },
2161
+ "@keydown.escape"() {
2162
+ this.cancel();
2163
+ },
2164
+ },
2165
+ }));
2166
+
2167
+ // DataFilterForm: a role="search" form that never navigates. Submit emits
2168
+ // `lily:filter` with the field values; reset emits `lily:reset`.
2169
+ Alpine.data("lilyDataFilterForm", () => ({
2170
+ form: {
2171
+ role: "search",
2172
+ "@submit.prevent"() {
2173
+ this.$dispatch("lily:filter", {
2174
+ values: Object.fromEntries(new FormData(this.$el)),
2175
+ });
2176
+ },
2177
+ "@reset"() {
2178
+ this.$dispatch("lily:reset");
2179
+ },
2180
+ },
2181
+ }));
2182
+
2183
+ // NewsletterSignup: a state machine (idle | submitting | success | error)
2184
+ // surfaced as data-state. While submitting the field and button are
2185
+ // disabled; success is a polite status, error an alert. Submit emits
2186
+ // `lily:submit` — the consumer moves `state` on.
2187
+ Alpine.data("lilyNewsletterSignup", (state = "idle") => ({
2188
+ state,
2189
+ form: {
2190
+ ":data-state"() {
2191
+ return this.state;
2192
+ },
2193
+ "@submit.prevent"() {
2194
+ const email = this.$el.querySelector('input[type="email"]');
2195
+ this.$dispatch("lily:submit", { email: email?.value ?? "" });
2196
+ },
2197
+ },
2198
+ field: {
2199
+ ":disabled"() {
2200
+ return this.state === "submitting";
2201
+ },
2202
+ },
2203
+ submit: {
2204
+ ":disabled"() {
2205
+ return this.state === "submitting";
2206
+ },
2207
+ },
2208
+ success: {
2209
+ ":hidden"() {
2210
+ return this.state !== "success";
2211
+ },
2212
+ },
2213
+ error: {
2214
+ ":hidden"() {
2215
+ return this.state !== "error";
2216
+ },
2217
+ },
2218
+ }));
2219
+
2220
+ // DateTimeNowInput: date and time fields plus a button that fills both with
2221
+ // the current local date and time.
2222
+ Alpine.data("lilyDateTimeNow", () => ({
2223
+ date: "",
2224
+ time: "",
2225
+ now() {
2226
+ const d = new Date();
2227
+ const p = (n) => String(n).padStart(2, "0");
2228
+ this.date = `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
2229
+ this.time = `${p(d.getHours())}:${p(d.getMinutes())}`;
2230
+ this.$dispatch("lily:change", { date: this.date, time: this.time });
2231
+ },
2232
+ nowButton: {
2233
+ type: "button",
2234
+ "@click"() {
2235
+ this.now();
2236
+ },
2237
+ },
2238
+ }));
2239
+
2240
+ // Dial / slider keys (APG slider): Right/Up raise, Left/Down lower, Shift
2241
+ // moves ten steps, Home and End jump to the bounds.
2242
+ const sliderKey = (event, value, { min, max, step }) => {
2243
+ const big = event.shiftKey ? 10 : 1;
2244
+ let next = value;
2245
+ if (event.key === "ArrowRight" || event.key === "ArrowUp") next = value + step * big;
2246
+ else if (event.key === "ArrowLeft" || event.key === "ArrowDown") next = value - step * big;
2247
+ else if (event.key === "Home") next = min;
2248
+ else if (event.key === "End") next = max;
2249
+ else return null;
2250
+ return Math.min(max, Math.max(min, next));
2251
+ };
2252
+
2253
+ // Dial: a role="slider" div (there is no native dial). Focusable unless
2254
+ // disabled; aria-disabled only when disabled; data-value for CSS.
2255
+ Alpine.data("lilyDial", (value = 0, min = 0, max = 100, step = 1, disabled = false) => ({
2256
+ value: Math.min(max, Math.max(min, value)),
2257
+ min,
2258
+ max,
2259
+ step,
2260
+ disabled,
2261
+ dial: {
2262
+ role: "slider",
2263
+ ":tabindex"() {
2264
+ return this.disabled ? "-1" : "0";
2265
+ },
2266
+ ":aria-valuenow"() {
2267
+ return String(this.value);
2268
+ },
2269
+ ":aria-valuemin"() {
2270
+ return String(this.min);
2271
+ },
2272
+ ":aria-valuemax"() {
2273
+ return String(this.max);
2274
+ },
2275
+ ":aria-disabled"() {
2276
+ return this.disabled ? "true" : null;
2277
+ },
2278
+ ":data-value"() {
2279
+ return String(this.value);
2280
+ },
2281
+ "@keydown"(event) {
2282
+ if (this.disabled) return;
2283
+ const next = sliderKey(event, this.value, this);
2284
+ if (next === null) return;
2285
+ event.preventDefault();
2286
+ if (next === this.value) return;
2287
+ this.value = next;
2288
+ this.$dispatch("lily:change", { value: next });
2289
+ },
2290
+ },
2291
+ }));
2292
+
2293
+ // ScrollBar: a focusable role="scrollbar" div. Up/Left lower and
2294
+ // Down/Right raise by step, Page Up/Down by pageStep, Home/End jump to the
2295
+ // bounds. The consumer scrolls its content on lily:change and sets value
2296
+ // back as the content scrolls.
2297
+ Alpine.data("lilyScrollBar", (value = 0, min = 0, max = 100, step = 1, pageStep = 10) => ({
2298
+ value: Math.min(max, Math.max(min, value)),
2299
+ min,
2300
+ max,
2301
+ step,
2302
+ pageStep,
2303
+ bar: {
2304
+ role: "scrollbar",
2305
+ tabindex: "0",
2306
+ ":aria-valuenow"() {
2307
+ return String(this.value);
2308
+ },
2309
+ ":aria-valuemin"() {
2310
+ return String(this.min);
2311
+ },
2312
+ ":aria-valuemax"() {
2313
+ return String(this.max);
2314
+ },
2315
+ "@keydown"(event) {
2316
+ const moves = {
2317
+ ArrowUp: this.value - this.step,
2318
+ ArrowLeft: this.value - this.step,
2319
+ ArrowDown: this.value + this.step,
2320
+ ArrowRight: this.value + this.step,
2321
+ PageUp: this.value - this.pageStep,
2322
+ PageDown: this.value + this.pageStep,
2323
+ Home: this.min,
2324
+ End: this.max,
2325
+ };
2326
+ if (!(event.key in moves)) return;
2327
+ event.preventDefault();
2328
+ const next = Math.min(this.max, Math.max(this.min, moves[event.key]));
2329
+ if (next === this.value) return;
2330
+ this.value = next;
2331
+ this.$dispatch("lily:change", { value: next });
2332
+ },
2333
+ },
2334
+ }));
2335
+
2336
+ // SliderButton: a slide-to-confirm <button role="slider">, position 0-100 in
2337
+ // aria-valuenow. ArrowRight/ArrowLeft move by `step`, Home returns to 0,
2338
+ // End/Enter/Space complete it; reaching 100 dispatches lily:confirm and
2339
+ // resets to 0. A disabled button ignores the keys.
2340
+ Alpine.data("lilySliderButton", (step = 10) => ({
2341
+ position: 0,
2342
+ step,
2343
+ button: {
2344
+ type: "button",
2345
+ role: "slider",
2346
+ "aria-valuemin": "0",
2347
+ "aria-valuemax": "100",
2348
+ ":aria-valuenow"() {
2349
+ return String(this.position);
2350
+ },
2351
+ "@keydown"(event) {
2352
+ if (this.$el.disabled) return;
2353
+ const targets = {
2354
+ ArrowRight: this.position + this.step,
2355
+ ArrowLeft: this.position - this.step,
2356
+ Home: 0,
2357
+ End: 100,
2358
+ Enter: 100,
2359
+ " ": 100,
2360
+ };
2361
+ if (!(event.key in targets)) return;
2362
+ event.preventDefault();
2363
+ const next = targets[event.key];
2364
+ if (next >= 100) {
2365
+ this.position = 0;
2366
+ this.$dispatch("lily:confirm");
2367
+ } else {
2368
+ this.position = Math.max(0, next);
2369
+ }
2370
+ },
2371
+ },
2372
+ }));
2373
+
2374
+ // ToolBar: an APG toolbar. ArrowRight/ArrowLeft move focus among its
2375
+ // buttons and wrap, Home/End jump to the first and last; Tab enters and
2376
+ // leaves. Disabled buttons are skipped (they cannot take focus).
2377
+ Alpine.data("lilyToolBar", () => ({
2378
+ bar: {
2379
+ role: "toolbar",
2380
+ "@keydown"(event) {
2381
+ if (!["ArrowRight", "ArrowLeft", "Home", "End"].includes(event.key)) return;
2382
+ const items = Array.from(
2383
+ this.$el.querySelectorAll(
2384
+ "button:not([disabled]), [role='button'], [tabindex]:not([tabindex='-1'])",
2385
+ ),
2386
+ );
2387
+ if (!items.length) return;
2388
+ event.preventDefault();
2389
+ const index = items.indexOf(document.activeElement);
2390
+ const last = items.length - 1;
2391
+ const next = {
2392
+ ArrowRight: index < last ? index + 1 : 0,
2393
+ ArrowLeft: index > 0 ? index - 1 : last,
2394
+ Home: 0,
2395
+ End: last,
2396
+ }[event.key];
2397
+ items[next].focus();
2398
+ },
2399
+ },
2400
+ }));
2401
+
2402
+ // TourList: an ordered list of tour steps, shown while `active`. Escape
2403
+ // inside it sets `active` to false and dispatches lily:close.
2404
+ Alpine.data("lilyTourList", (active = true) => ({
2405
+ active,
2406
+ list: {
2407
+ tabindex: "-1",
2408
+ ":hidden"() {
2409
+ return !this.active;
2410
+ },
2411
+ "@keydown.escape"() {
2412
+ if (!this.active) return;
2413
+ this.active = false;
2414
+ this.$dispatch("lily:close");
2415
+ },
2416
+ },
2417
+ }));
2418
+
2419
+ // TileMap: the [data-tile] children are focusable tiles. ArrowRight/Left
2420
+ // step through them in order (stopping at the ends); ArrowDown/Up go to
2421
+ // the nearest tile in a lower or higher row, by position on screen;
2422
+ // Enter/Space dispatch a bubbling tile-activate on the focused tile;
2423
+ // Escape blurs it.
2424
+ Alpine.data("lilyTileMap", () => ({
2425
+ map: {
2426
+ "@keydown"(event) {
2427
+ const tiles = Array.from(this.$el.querySelectorAll("[data-tile]"));
2428
+ const focused = document.activeElement;
2429
+ const index = tiles.indexOf(focused);
2430
+ if (index === -1) return;
2431
+ const key = event.key;
2432
+ if (key === "ArrowRight" || key === "ArrowLeft") {
2433
+ event.preventDefault();
2434
+ const to = key === "ArrowRight" ? index + 1 : index - 1;
2435
+ tiles[Math.min(tiles.length - 1, Math.max(0, to))].focus();
2436
+ } else if (key === "ArrowDown" || key === "ArrowUp") {
2437
+ event.preventDefault();
2438
+ const here = focused.getBoundingClientRect();
2439
+ const x = here.left + here.width / 2;
2440
+ const below = key === "ArrowDown";
2441
+ const next = tiles
2442
+ .filter((t) => t !== focused)
2443
+ .map((t) => ({ t, r: t.getBoundingClientRect() }))
2444
+ .filter(({ r }) => (below ? r.top > here.top : r.top < here.top))
2445
+ .map(({ t, r }) => ({
2446
+ t,
2447
+ score: Math.abs(r.left + r.width / 2 - x) + Math.abs(r.top - here.top),
2448
+ }))
2449
+ .sort((a, b) => a.score - b.score)[0]?.t;
2450
+ next?.focus();
2451
+ } else if (key === "Enter" || key === " ") {
2452
+ event.preventDefault();
2453
+ focused.dispatchEvent(new CustomEvent("tile-activate", { bubbles: true }));
2454
+ } else if (key === "Escape") {
2455
+ event.preventDefault();
2456
+ focused.blur();
2457
+ }
2458
+ },
2459
+ },
2460
+ }));
2461
+
2462
+ // Splitter: a focusable role="separator" with a 0–100 position. The keys
2463
+ // that move it follow the orientation (Left/Right when the panes sit side by
2464
+ // side, Up/Down when stacked); Shift moves ten steps; Home/End jump to the
2465
+ // bounds. Dragging maps the pointer onto the separator's parent. The
2466
+ // position is also exposed as --splitter-position on the separator.
2467
+ Alpine.data(
2468
+ "lilySplitter",
2469
+ (value = 50, orientation = "vertical", min = 0, max = 100, step = 1) => ({
2470
+ value,
2471
+ orientation,
2472
+ min,
2473
+ max,
2474
+ step,
2475
+ set(next) {
2476
+ next = Math.min(this.max, Math.max(this.min, next));
2477
+ if (next === this.value) return;
2478
+ this.value = next;
2479
+ this.$dispatch("lily:change", { value: next });
2480
+ },
2481
+ separator: {
2482
+ role: "separator",
2483
+ tabindex: "0",
2484
+ ":aria-orientation"() {
2485
+ return this.orientation;
2486
+ },
2487
+ ":aria-valuenow"() {
2488
+ return String(this.value);
2489
+ },
2490
+ ":aria-valuemin"() {
2491
+ return String(this.min);
2492
+ },
2493
+ ":aria-valuemax"() {
2494
+ return String(this.max);
2495
+ },
2496
+ ":data-value"() {
2497
+ return String(this.value);
2498
+ },
2499
+ ":style"() {
2500
+ return { "--splitter-position": `${this.value}%` };
2501
+ },
2502
+ "@keydown"(event) {
2503
+ const sideBySide = this.orientation === "vertical";
2504
+ const keys = sideBySide
2505
+ ? ["ArrowLeft", "ArrowRight"]
2506
+ : ["ArrowUp", "ArrowDown"];
2507
+ if (sideBySide && getComputedStyle(this.$el).direction === "rtl")
2508
+ keys.reverse();
2509
+ const big = event.shiftKey ? 10 : 1;
2510
+ if (event.key === keys[0]) this.set(this.value - this.step * big);
2511
+ else if (event.key === keys[1]) this.set(this.value + this.step * big);
2512
+ else if (event.key === "Home") this.set(this.min);
2513
+ else if (event.key === "End") this.set(this.max);
2514
+ else if (event.key === "Enter") {
2515
+ // Collapse to the minimum, and restore.
2516
+ if (this.value > this.min) {
2517
+ this.restore = this.value;
2518
+ this.set(this.min);
2519
+ } else this.set(this.restore ?? this.max);
2520
+ } else return;
2521
+ event.preventDefault();
2522
+ },
2523
+ "@pointerdown"(event) {
2524
+ const parent = this.$el.parentElement;
2525
+ const sideBySide = this.orientation === "vertical";
2526
+ const move = (e) => {
2527
+ const box = parent.getBoundingClientRect();
2528
+ const size = sideBySide ? box.width : box.height;
2529
+ if (!size) return;
2530
+ const at = sideBySide ? e.clientX - box.left : e.clientY - box.top;
2531
+ this.set(Math.round(this.min + (at / size) * (this.max - this.min)));
2532
+ };
2533
+ const stop = () => {
2534
+ document.removeEventListener("pointermove", move);
2535
+ document.removeEventListener("pointerup", stop);
2536
+ };
2537
+ event.preventDefault();
2538
+ document.addEventListener("pointermove", move);
2539
+ document.addEventListener("pointerup", stop);
2540
+ },
2541
+ },
2542
+ }),
2543
+ );
2544
+
2545
+ // Carousel: one slide shown at a time (the rest hidden), previous / next
2546
+ // buttons that wrap, and a numeric "n / m" slide label. It never advances
2547
+ // by itself.
2548
+ Alpine.data("lilyCarousel", (index = 0) => ({
2549
+ index,
2550
+ total: 0,
2551
+ init() {
2552
+ this.total = this.count();
2553
+ },
2554
+ count() {
2555
+ return boundCount(this.$root, "slide(");
2556
+ },
2557
+ go(to) {
2558
+ const count = this.count();
2559
+ if (!count) return;
2560
+ this.index = (to + count) % count;
2561
+ this.$dispatch("lily:change", { index: this.index });
2562
+ },
2563
+ root: {
2564
+ ":data-index"() {
2565
+ return String(this.index);
2566
+ },
2567
+ },
2568
+ previous: {
2569
+ type: "button",
2570
+ "@click"() {
2571
+ this.go(this.index - 1);
2572
+ },
2573
+ },
2574
+ next: {
2575
+ type: "button",
2576
+ "@click"() {
2577
+ this.go(this.index + 1);
2578
+ },
2579
+ },
2580
+ slide(i) {
2581
+ return {
2582
+ role: "group",
2583
+ "aria-roledescription": "slide",
2584
+ ":aria-label"() {
2585
+ return `${i + 1} / ${this.total}`;
2586
+ },
2587
+ ":hidden"() {
2588
+ return this.index !== i;
2589
+ },
2590
+ ":data-active"() {
2591
+ return String(this.index === i);
2592
+ },
2593
+ };
2594
+ },
2595
+ }));
2596
+
2597
+ // Tour: steps shown one at a time, the current one aria-current="step".
2598
+ // Next on the last step finishes; Escape and close end the tour.
2599
+ Alpine.data("lilyTour", (step = 0, open = true) => ({
2600
+ step,
2601
+ open,
2602
+ total: 0,
2603
+ init() {
2604
+ this.total = this.count();
2605
+ },
2606
+ count() {
2607
+ return boundCount(this.$root, "item(");
2608
+ },
2609
+ go(to) {
2610
+ if (to < 0) return;
2611
+ if (to >= this.count()) return this.end("lily:finish");
2612
+ this.step = to;
2613
+ this.$dispatch("lily:change", { step: to });
2614
+ },
2615
+ end(type = "lily:close") {
2616
+ this.open = false;
2617
+ this.$dispatch(type);
2618
+ },
2619
+ // A non-modal dialog, as in Svelte (tasks.md P18-T13): no aria-modal, the page it points at stays usable.
2620
+ root: {
2621
+ role: "dialog",
2622
+ tabindex: "-1",
2623
+ ":hidden"() {
2624
+ return !this.open;
2625
+ },
2626
+ "@keydown.escape"() {
2627
+ if (this.open) this.end();
2628
+ },
2629
+ },
2630
+ previous: {
2631
+ type: "button",
2632
+ "@click"() {
2633
+ this.go(this.step - 1);
2634
+ },
2635
+ },
2636
+ next: {
2637
+ type: "button",
2638
+ "@click"() {
2639
+ this.go(this.step + 1);
2640
+ },
2641
+ },
2642
+ close: {
2643
+ type: "button",
2644
+ "@click"() {
2645
+ this.end();
2646
+ },
2647
+ },
2648
+ item(i) {
2649
+ return {
2650
+ ":aria-label"() {
2651
+ return `${i + 1} / ${this.total}`;
2652
+ },
2653
+ ":aria-current"() {
2654
+ return this.step === i ? "step" : null;
2655
+ },
2656
+ ":aria-hidden"() {
2657
+ return this.step === i ? null : "true";
2658
+ },
2659
+ ":hidden"() {
2660
+ return this.step !== i;
2661
+ },
2662
+ };
2663
+ },
2664
+ }));
2665
+
2666
+ // Coachmark: a non-modal dialog (aria-modal="false") with a dismiss button;
2667
+ // Escape dismisses. Hidden while closed.
2668
+ Alpine.data("lilyCoachmark", (open = true) => ({
2669
+ open,
2670
+ dismiss() {
2671
+ this.open = false;
2672
+ this.$dispatch("lily:dismiss");
2673
+ },
2674
+ root: {
2675
+ ...manualPopover((o) => o.open),
2676
+ "@keydown.escape"() {
2677
+ if (this.open) this.dismiss();
2678
+ },
2679
+ },
2680
+ dismissButton: {
2681
+ type: "button",
2682
+ "@click"() {
2683
+ this.dismiss();
2684
+ },
2685
+ },
2686
+ }));
2687
+
2688
+ // FileUpload: a button opens the hidden native file input; the status
2689
+ // (aria-live="polite") carries the file count in data-file-count.
2690
+ Alpine.data("lilyFileUpload", () => ({
2691
+ count: 0,
2692
+ trigger: {
2693
+ type: "button",
2694
+ "@click"() {
2695
+ this.$refs.input.click();
2696
+ },
2697
+ },
2698
+ input: {
2699
+ "x-ref": "input",
2700
+ type: "file",
2701
+ "@change"(event) {
2702
+ const files = Array.from(event.target.files ?? []);
2703
+ this.count = files.length;
2704
+ this.$dispatch("lily:change", { files });
2705
+ },
2706
+ },
2707
+ status: {
2708
+ "aria-live": "polite",
2709
+ ":data-file-count"() {
2710
+ return String(this.count);
2711
+ },
2712
+ "x-text"() {
2713
+ return this.count ? String(this.count) : "";
2714
+ },
2715
+ },
2716
+ }));
2717
+
2718
+ // MiddleTruncation: the text shortened in the middle to the root's measured width (canvas metrics in its own font),
2719
+ // re-measured on resize. The full text stays in the page for assistive technology; ellipsis has no default.
2720
+ Alpine.data("lilyMiddleTruncation", (options = {}) => ({
2721
+ text: options.text ?? "",
2722
+ ellipsis: options.ellipsis ?? "",
2723
+ strategy: options.strategy ?? "even",
2724
+ end: options.end,
2725
+ shown: null,
2726
+ _observer: null,
2727
+ _frame: 0,
2728
+ _context: undefined,
2729
+ init() {
2730
+ this.recalculate();
2731
+ if (typeof ResizeObserver !== "undefined") {
2732
+ this._observer = new ResizeObserver(() => {
2733
+ cancelAnimationFrame(this._frame);
2734
+ this._frame = requestAnimationFrame(() => this.recalculate());
2735
+ });
2736
+ this._observer.observe(this.$el);
2737
+ }
2738
+ this.$watch(
2739
+ () => [this.text, this.ellipsis, this.strategy, this.end],
2740
+ () => this.recalculate(),
2741
+ );
2742
+ },
2743
+ destroy() {
2744
+ cancelAnimationFrame(this._frame);
2745
+ this._observer?.disconnect();
2746
+ },
2747
+ recalculate() {
2748
+ const el = this.$el;
2749
+ const width = el.clientWidth;
2750
+ if (this._context === undefined)
2751
+ this._context = document.createElement("canvas").getContext("2d");
2752
+ const ctx = this._context;
2753
+ if (!ctx || width <= 0) {
2754
+ this.shown = null;
2755
+ return;
2756
+ }
2757
+ const style = getComputedStyle(el);
2758
+ ctx.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
2759
+ const result = truncateMiddle(this.text, {
2760
+ ellipsis: this.ellipsis,
2761
+ strategy: this.strategy,
2762
+ end: this.end,
2763
+ maxWidth: width,
2764
+ measure: (t) => ctx.measureText(t).width,
2765
+ });
2766
+ this.shown = result === this.text ? null : result;
2767
+ },
2768
+ root: {
2769
+ ":data-strategy"() {
2770
+ return this.strategy;
2771
+ },
2772
+ ":data-truncated"() {
2773
+ return this.shown === null ? null : "";
2774
+ },
2775
+ },
2776
+ visual: {
2777
+ "x-text"() {
2778
+ return this.shown ?? this.text;
2779
+ },
2780
+ },
2781
+ full: {
2782
+ "x-text"() {
2783
+ return this.text;
2784
+ },
2785
+ },
2786
+ }));
2787
+
2788
+ // WheelPicker: a single-select listbox, vertical by default, where the selection follows the cursor (APG listbox). The roles
2789
+ // live in the snippet; this owns the value, the keys (arrows, Home/End, PageUp/PageDown, type-ahead), centring the selected
2790
+ // option, the optional hidden input (x-bind="input": its value, disabled with the picker), form reset, and scrolling: when
2791
+ // the user turns the wheel and it settles, the option in the middle is chosen.
2792
+ let wheelPickerCount = 0;
2793
+ Alpine.data("lilyWheelPicker", (config = {}) => ({
2794
+ options: config.options ?? [],
2795
+ value: config.value ?? "",
2796
+ loop: Boolean(config.loop),
2797
+ pageSize: config.pageSize ?? 5,
2798
+ disabled: Boolean(config.disabled),
2799
+ orientation: config.orientation === "horizontal" ? "horizontal" : "vertical",
2800
+ uid: `wheel-picker-${++wheelPickerCount}`,
2801
+ _typeahead: { prefix: "", at: 0 },
2802
+ _initial: config.value ?? "",
2803
+ _form: null,
2804
+ _resetTimer: undefined,
2805
+ init() {
2806
+ this.$nextTick(() => this.centre());
2807
+ this.$watch("value", () => this.$nextTick(() => this.centre()));
2808
+ // Form reset: a hidden input keeps its value through a reset, so put the picker back to its first value, one tick
2809
+ // after `reset` and not when it was cancelled. The input's own `form` follows a `form` attribute.
2810
+ this._form = this.$refs.input?.form ?? this.$el.closest("form");
2811
+ this._onReset = (event) => {
2812
+ clearTimeout(this._resetTimer);
2813
+ this._resetTimer = setTimeout(() => {
2814
+ if (event.defaultPrevented || this.value === this._initial) return;
2815
+ this.value = this._initial;
2816
+ this.$dispatch("change", { value: this._initial });
2817
+ }, 0);
2818
+ };
2819
+ this._form?.addEventListener("reset", this._onReset);
2820
+ // Scrolling chooses: when the user turns the wheel and it settles, the option in the middle becomes the value.
2821
+ this._stopScroll = watchWheelScroll(this.$refs.list, {
2822
+ options: () => this.options,
2823
+ selected: () => this.selectedIndex,
2824
+ orientation: () => this.orientation,
2825
+ disabled: () => this.disabled,
2826
+ choose: (index) => this.select(index),
2827
+ recentre: () => this.centre(),
2828
+ });
2829
+ },
2830
+ destroy() {
2831
+ this._stopScroll?.();
2832
+ clearTimeout(this._resetTimer);
2833
+ this._form?.removeEventListener("reset", this._onReset);
2834
+ },
2835
+ get selectedIndex() {
2836
+ return this.options.findIndex((o) => o.value === this.value);
2837
+ },
2838
+ select(index) {
2839
+ if (index < 0) return;
2840
+ const next = this.options[index].value;
2841
+ if (next === this.value) return; // applying the selection already held is a no-op
2842
+ this.value = next;
2843
+ this.$dispatch("change", { value: next });
2844
+ },
2845
+ // Only the list scrolls (never the page), and instantly: no animation. Moving by the distance between the two middles
2846
+ // works on either axis and in right-to-left.
2847
+ centre() {
2848
+ const list = this.$refs.list;
2849
+ const option = list?.querySelector(`[data-index="${this.selectedIndex}"]`);
2850
+ if (!list || !option) return;
2851
+ const box = list.getBoundingClientRect();
2852
+ const row = option.getBoundingClientRect();
2853
+ if (this.orientation === "horizontal")
2854
+ list.scrollLeft += row.left + row.width / 2 - (box.left + box.width / 2);
2855
+ else list.scrollTop += row.top + row.height / 2 - (box.top + box.height / 2);
2856
+ },
2857
+ input: {
2858
+ ":value"() {
2859
+ return this.value;
2860
+ },
2861
+ ":disabled"() {
2862
+ return this.disabled;
2863
+ },
2864
+ },
2865
+ list: {
2866
+ role: "listbox",
2867
+ ":aria-orientation"() {
2868
+ return this.orientation;
2869
+ },
2870
+ ":aria-disabled"() {
2871
+ return this.disabled ? "true" : null;
2872
+ },
2873
+ ":aria-activedescendant"() {
2874
+ return this.selectedIndex >= 0 ? `${this.uid}-option-${this.selectedIndex}` : null;
2875
+ },
2876
+ ":tabindex"() {
2877
+ return this.disabled ? -1 : 0;
2878
+ },
2879
+ "@keydown"(event) {
2880
+ if (this.disabled) return;
2881
+ const move = wheelMoveKey(event.key, this.orientation, isWheelRtl(this.$refs.list));
2882
+ if (move) {
2883
+ event.preventDefault();
2884
+ this.select(
2885
+ nextWheelIndex(this.options, this.selectedIndex, move, {
2886
+ loop: this.loop,
2887
+ pageSize: this.pageSize,
2888
+ }),
2889
+ );
2890
+ } else if (isWheelTypeaheadKey(event)) {
2891
+ this._typeahead = nextWheelPrefix(this._typeahead, event.key, Date.now());
2892
+ this.select(
2893
+ wheelTypeaheadIndex(
2894
+ this.options,
2895
+ this.selectedIndex,
2896
+ this._typeahead.prefix,
2897
+ ),
2898
+ );
2899
+ }
2900
+ },
2901
+ "@click"(event) {
2902
+ if (this.disabled) return;
2903
+ const target = event.target.closest('[role="option"]');
2904
+ if (!target || target.getAttribute("aria-disabled") === "true") return;
2905
+ this.select(Number(target.getAttribute("data-index")));
2906
+ this.$refs.list.focus();
2907
+ },
2908
+ },
2909
+ }));
2910
+
2911
+ // NavigationMenu overflow mode: the snippet owns the list, the hidden More item and the More list; this measures with a
2912
+ // ResizeObserver on the list and moves the items that do not fit (see overflow-navigation.js). Without it the links wrap.
2913
+ Alpine.data("lilyNavigationMenu", () => ({
2914
+ _overflow: null,
2915
+ init() {
2916
+ this._overflow = setupOverflowNavigation(this.$el);
2917
+ },
2918
+ destroy() {
2919
+ this._overflow?.dispose();
2920
+ },
2921
+ }));
2922
+ }