@lo-tek/interfaces 0.0.0 → 0.37.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 (456) hide show
  1. package/CHANGELOG.md +3254 -0
  2. package/LICENSE +21 -0
  3. package/README.md +128 -1
  4. package/agent/astro.md +400 -0
  5. package/agent/bundles.md +429 -0
  6. package/agent/datastar.md +409 -0
  7. package/agent/html.md +388 -0
  8. package/agent/react.md +440 -0
  9. package/agent/templates.md +472 -0
  10. package/core/lotek-core.wasm +0 -0
  11. package/core/lotek.wasm +0 -0
  12. package/dist/cli.d.ts +12 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +14 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/components/css/accordion/accordion.d.ts +37 -0
  17. package/dist/components/css/accordion/accordion.d.ts.map +1 -0
  18. package/dist/components/css/accordion/accordion.js +31 -0
  19. package/dist/components/css/accordion/accordion.js.map +1 -0
  20. package/dist/components/css/alert/alert.d.ts +35 -0
  21. package/dist/components/css/alert/alert.d.ts.map +1 -0
  22. package/dist/components/css/alert/alert.js +29 -0
  23. package/dist/components/css/alert/alert.js.map +1 -0
  24. package/dist/components/css/avatar/avatar.d.ts +40 -0
  25. package/dist/components/css/avatar/avatar.d.ts.map +1 -0
  26. package/dist/components/css/avatar/avatar.js +30 -0
  27. package/dist/components/css/avatar/avatar.js.map +1 -0
  28. package/dist/components/css/badge/badge.d.ts +24 -0
  29. package/dist/components/css/badge/badge.d.ts.map +1 -0
  30. package/dist/components/css/badge/badge.js +24 -0
  31. package/dist/components/css/badge/badge.js.map +1 -0
  32. package/dist/components/css/breadcrumbs/breadcrumbs.d.ts +26 -0
  33. package/dist/components/css/breadcrumbs/breadcrumbs.d.ts.map +1 -0
  34. package/dist/components/css/breadcrumbs/breadcrumbs.js +24 -0
  35. package/dist/components/css/breadcrumbs/breadcrumbs.js.map +1 -0
  36. package/dist/components/css/button/button.d.ts +26 -0
  37. package/dist/components/css/button/button.d.ts.map +1 -0
  38. package/dist/components/css/button/button.js +25 -0
  39. package/dist/components/css/button/button.js.map +1 -0
  40. package/dist/components/css/card/card.d.ts +36 -0
  41. package/dist/components/css/card/card.d.ts.map +1 -0
  42. package/dist/components/css/card/card.js +28 -0
  43. package/dist/components/css/card/card.js.map +1 -0
  44. package/dist/components/css/checkbox/checkbox.d.ts +32 -0
  45. package/dist/components/css/checkbox/checkbox.d.ts.map +1 -0
  46. package/dist/components/css/checkbox/checkbox.js +27 -0
  47. package/dist/components/css/checkbox/checkbox.js.map +1 -0
  48. package/dist/components/css/divider/divider.d.ts +29 -0
  49. package/dist/components/css/divider/divider.d.ts.map +1 -0
  50. package/dist/components/css/divider/divider.js +23 -0
  51. package/dist/components/css/divider/divider.js.map +1 -0
  52. package/dist/components/css/error-text/error-text.d.ts +24 -0
  53. package/dist/components/css/error-text/error-text.d.ts.map +1 -0
  54. package/dist/components/css/error-text/error-text.js +18 -0
  55. package/dist/components/css/error-text/error-text.js.map +1 -0
  56. package/dist/components/css/fieldset/fieldset.d.ts +55 -0
  57. package/dist/components/css/fieldset/fieldset.d.ts.map +1 -0
  58. package/dist/components/css/fieldset/fieldset.js +39 -0
  59. package/dist/components/css/fieldset/fieldset.js.map +1 -0
  60. package/dist/components/css/file-upload/file-upload.d.ts +41 -0
  61. package/dist/components/css/file-upload/file-upload.d.ts.map +1 -0
  62. package/dist/components/css/file-upload/file-upload.js +32 -0
  63. package/dist/components/css/file-upload/file-upload.js.map +1 -0
  64. package/dist/components/css/heading/heading.d.ts +29 -0
  65. package/dist/components/css/heading/heading.d.ts.map +1 -0
  66. package/dist/components/css/heading/heading.js +23 -0
  67. package/dist/components/css/heading/heading.js.map +1 -0
  68. package/dist/components/css/help-text/help-text.d.ts +24 -0
  69. package/dist/components/css/help-text/help-text.d.ts.map +1 -0
  70. package/dist/components/css/help-text/help-text.js +23 -0
  71. package/dist/components/css/help-text/help-text.js.map +1 -0
  72. package/dist/components/css/icon/icon.d.ts +34 -0
  73. package/dist/components/css/icon/icon.d.ts.map +1 -0
  74. package/dist/components/css/icon/icon.js +25 -0
  75. package/dist/components/css/icon/icon.js.map +1 -0
  76. package/dist/components/css/input/input.d.ts +40 -0
  77. package/dist/components/css/input/input.d.ts.map +1 -0
  78. package/dist/components/css/input/input.js +45 -0
  79. package/dist/components/css/input/input.js.map +1 -0
  80. package/dist/components/css/label/label.d.ts +33 -0
  81. package/dist/components/css/label/label.d.ts.map +1 -0
  82. package/dist/components/css/label/label.js +23 -0
  83. package/dist/components/css/label/label.js.map +1 -0
  84. package/dist/components/css/link/link.d.ts +28 -0
  85. package/dist/components/css/link/link.d.ts.map +1 -0
  86. package/dist/components/css/link/link.js +20 -0
  87. package/dist/components/css/link/link.js.map +1 -0
  88. package/dist/components/css/list/list.d.ts +31 -0
  89. package/dist/components/css/list/list.d.ts.map +1 -0
  90. package/dist/components/css/list/list.js +25 -0
  91. package/dist/components/css/list/list.js.map +1 -0
  92. package/dist/components/css/pagination/pagination.d.ts +27 -0
  93. package/dist/components/css/pagination/pagination.d.ts.map +1 -0
  94. package/dist/components/css/pagination/pagination.js +25 -0
  95. package/dist/components/css/pagination/pagination.js.map +1 -0
  96. package/dist/components/css/paragraph/paragraph.d.ts +36 -0
  97. package/dist/components/css/paragraph/paragraph.d.ts.map +1 -0
  98. package/dist/components/css/paragraph/paragraph.js +26 -0
  99. package/dist/components/css/paragraph/paragraph.js.map +1 -0
  100. package/dist/components/css/progress/progress.d.ts +53 -0
  101. package/dist/components/css/progress/progress.d.ts.map +1 -0
  102. package/dist/components/css/progress/progress.js +38 -0
  103. package/dist/components/css/progress/progress.js.map +1 -0
  104. package/dist/components/css/radio/radio.d.ts +32 -0
  105. package/dist/components/css/radio/radio.d.ts.map +1 -0
  106. package/dist/components/css/radio/radio.js +27 -0
  107. package/dist/components/css/radio/radio.js.map +1 -0
  108. package/dist/components/css/search/search.d.ts +34 -0
  109. package/dist/components/css/search/search.d.ts.map +1 -0
  110. package/dist/components/css/search/search.js +32 -0
  111. package/dist/components/css/search/search.js.map +1 -0
  112. package/dist/components/css/select/select.d.ts +40 -0
  113. package/dist/components/css/select/select.d.ts.map +1 -0
  114. package/dist/components/css/select/select.js +31 -0
  115. package/dist/components/css/select/select.js.map +1 -0
  116. package/dist/components/css/shared.d.ts +90 -0
  117. package/dist/components/css/shared.d.ts.map +1 -0
  118. package/dist/components/css/shared.js +167 -0
  119. package/dist/components/css/shared.js.map +1 -0
  120. package/dist/components/css/skeleton/skeleton.d.ts +29 -0
  121. package/dist/components/css/skeleton/skeleton.d.ts.map +1 -0
  122. package/dist/components/css/skeleton/skeleton.js +23 -0
  123. package/dist/components/css/skeleton/skeleton.js.map +1 -0
  124. package/dist/components/css/skip-link/skip-link.d.ts +18 -0
  125. package/dist/components/css/skip-link/skip-link.d.ts.map +1 -0
  126. package/dist/components/css/skip-link/skip-link.js +16 -0
  127. package/dist/components/css/skip-link/skip-link.js.map +1 -0
  128. package/dist/components/css/spinner/spinner.d.ts +33 -0
  129. package/dist/components/css/spinner/spinner.d.ts.map +1 -0
  130. package/dist/components/css/spinner/spinner.js +25 -0
  131. package/dist/components/css/spinner/spinner.js.map +1 -0
  132. package/dist/components/css/sr-only/sr-only.d.ts +17 -0
  133. package/dist/components/css/sr-only/sr-only.d.ts.map +1 -0
  134. package/dist/components/css/sr-only/sr-only.js +15 -0
  135. package/dist/components/css/sr-only/sr-only.js.map +1 -0
  136. package/dist/components/css/switch/switch.d.ts +37 -0
  137. package/dist/components/css/switch/switch.d.ts.map +1 -0
  138. package/dist/components/css/switch/switch.js +29 -0
  139. package/dist/components/css/switch/switch.js.map +1 -0
  140. package/dist/components/css/table/table.d.ts +76 -0
  141. package/dist/components/css/table/table.d.ts.map +1 -0
  142. package/dist/components/css/table/table.js +59 -0
  143. package/dist/components/css/table/table.js.map +1 -0
  144. package/dist/components/css/tag/tag.d.ts +35 -0
  145. package/dist/components/css/tag/tag.d.ts.map +1 -0
  146. package/dist/components/css/tag/tag.js +27 -0
  147. package/dist/components/css/tag/tag.js.map +1 -0
  148. package/dist/components/css/textarea/textarea.d.ts +23 -0
  149. package/dist/components/css/textarea/textarea.d.ts.map +1 -0
  150. package/dist/components/css/textarea/textarea.js +18 -0
  151. package/dist/components/css/textarea/textarea.js.map +1 -0
  152. package/dist/components/css/toggle-group/toggle-group.d.ts +31 -0
  153. package/dist/components/css/toggle-group/toggle-group.d.ts.map +1 -0
  154. package/dist/components/css/toggle-group/toggle-group.js +29 -0
  155. package/dist/components/css/toggle-group/toggle-group.js.map +1 -0
  156. package/dist/components/css/tooltip/tooltip.d.ts +31 -0
  157. package/dist/components/css/tooltip/tooltip.d.ts.map +1 -0
  158. package/dist/components/css/tooltip/tooltip.js +29 -0
  159. package/dist/components/css/tooltip/tooltip.js.map +1 -0
  160. package/dist/components/default-texts.d.ts +35 -0
  161. package/dist/components/default-texts.d.ts.map +1 -0
  162. package/dist/components/default-texts.js +35 -0
  163. package/dist/components/default-texts.js.map +1 -0
  164. package/dist/components/events.d.ts +77 -0
  165. package/dist/components/events.d.ts.map +1 -0
  166. package/dist/components/events.js +3 -0
  167. package/dist/components/events.js.map +1 -0
  168. package/dist/components/frame/dialog/dialog.d.ts +122 -0
  169. package/dist/components/frame/dialog/dialog.d.ts.map +1 -0
  170. package/dist/components/frame/dialog/dialog.js +112 -0
  171. package/dist/components/frame/dialog/dialog.js.map +1 -0
  172. package/dist/components/frame/dialog/lt-dialog.d.ts +104 -0
  173. package/dist/components/frame/dialog/lt-dialog.d.ts.map +1 -0
  174. package/dist/components/frame/dialog/lt-dialog.js +431 -0
  175. package/dist/components/frame/dialog/lt-dialog.js.map +1 -0
  176. package/dist/components/frame/error-summary/error-summary.d.ts +40 -0
  177. package/dist/components/frame/error-summary/error-summary.d.ts.map +1 -0
  178. package/dist/components/frame/error-summary/error-summary.js +32 -0
  179. package/dist/components/frame/error-summary/error-summary.js.map +1 -0
  180. package/dist/components/frame/error-summary/lt-error-summary.d.ts +82 -0
  181. package/dist/components/frame/error-summary/lt-error-summary.d.ts.map +1 -0
  182. package/dist/components/frame/error-summary/lt-error-summary.js +302 -0
  183. package/dist/components/frame/error-summary/lt-error-summary.js.map +1 -0
  184. package/dist/components/frame/field/field-core.d.ts +92 -0
  185. package/dist/components/frame/field/field-core.d.ts.map +1 -0
  186. package/dist/components/frame/field/field-core.js +63 -0
  187. package/dist/components/frame/field/field-core.js.map +1 -0
  188. package/dist/components/frame/field/lt-field.d.ts +173 -0
  189. package/dist/components/frame/field/lt-field.d.ts.map +1 -0
  190. package/dist/components/frame/field/lt-field.js +580 -0
  191. package/dist/components/frame/field/lt-field.js.map +1 -0
  192. package/dist/components/frame/popover/lt-popover.d.ts +132 -0
  193. package/dist/components/frame/popover/lt-popover.d.ts.map +1 -0
  194. package/dist/components/frame/popover/lt-popover.js +490 -0
  195. package/dist/components/frame/popover/lt-popover.js.map +1 -0
  196. package/dist/components/frame/popover/popover.d.ts +49 -0
  197. package/dist/components/frame/popover/popover.d.ts.map +1 -0
  198. package/dist/components/frame/popover/popover.js +64 -0
  199. package/dist/components/frame/popover/popover.js.map +1 -0
  200. package/dist/components/frame/session-timeout/lt-session-timeout.d.ts +198 -0
  201. package/dist/components/frame/session-timeout/lt-session-timeout.d.ts.map +1 -0
  202. package/dist/components/frame/session-timeout/lt-session-timeout.js +573 -0
  203. package/dist/components/frame/session-timeout/lt-session-timeout.js.map +1 -0
  204. package/dist/components/frame/session-timeout/session-timeout.d.ts +113 -0
  205. package/dist/components/frame/session-timeout/session-timeout.d.ts.map +1 -0
  206. package/dist/components/frame/session-timeout/session-timeout.js +101 -0
  207. package/dist/components/frame/session-timeout/session-timeout.js.map +1 -0
  208. package/dist/components/frame/suggestion/lt-suggestion.d.ts +361 -0
  209. package/dist/components/frame/suggestion/lt-suggestion.d.ts.map +1 -0
  210. package/dist/components/frame/suggestion/lt-suggestion.js +1152 -0
  211. package/dist/components/frame/suggestion/lt-suggestion.js.map +1 -0
  212. package/dist/components/frame/suggestion/suggestion.d.ts +143 -0
  213. package/dist/components/frame/suggestion/suggestion.d.ts.map +1 -0
  214. package/dist/components/frame/suggestion/suggestion.js +127 -0
  215. package/dist/components/frame/suggestion/suggestion.js.map +1 -0
  216. package/dist/components/frame/tabs/lt-tabs.d.ts +404 -0
  217. package/dist/components/frame/tabs/lt-tabs.d.ts.map +1 -0
  218. package/dist/components/frame/tabs/lt-tabs.js +1201 -0
  219. package/dist/components/frame/tabs/lt-tabs.js.map +1 -0
  220. package/dist/components/frame/tabs/tabs.d.ts +112 -0
  221. package/dist/components/frame/tabs/tabs.d.ts.map +1 -0
  222. package/dist/components/frame/tabs/tabs.js +107 -0
  223. package/dist/components/frame/tabs/tabs.js.map +1 -0
  224. package/dist/components/host-element.d.ts +135 -0
  225. package/dist/components/host-element.d.ts.map +1 -0
  226. package/dist/components/host-element.js +366 -0
  227. package/dist/components/host-element.js.map +1 -0
  228. package/dist/components/standalone/connection-status/connection-status.d.ts +28 -0
  229. package/dist/components/standalone/connection-status/connection-status.d.ts.map +1 -0
  230. package/dist/components/standalone/connection-status/connection-status.js +22 -0
  231. package/dist/components/standalone/connection-status/connection-status.js.map +1 -0
  232. package/dist/components/standalone/connection-status/lt-connection-status.d.ts +81 -0
  233. package/dist/components/standalone/connection-status/lt-connection-status.d.ts.map +1 -0
  234. package/dist/components/standalone/connection-status/lt-connection-status.js +216 -0
  235. package/dist/components/standalone/connection-status/lt-connection-status.js.map +1 -0
  236. package/dist/components/standalone/toast/lt-toast.d.ts +109 -0
  237. package/dist/components/standalone/toast/lt-toast.d.ts.map +1 -0
  238. package/dist/components/standalone/toast/lt-toast.js +256 -0
  239. package/dist/components/standalone/toast/lt-toast.js.map +1 -0
  240. package/dist/components/standalone/toast/toast.d.ts +52 -0
  241. package/dist/components/standalone/toast/toast.d.ts.map +1 -0
  242. package/dist/components/standalone/toast/toast.js +42 -0
  243. package/dist/components/standalone/toast/toast.js.map +1 -0
  244. package/dist/diagnostics/core.d.ts +137 -0
  245. package/dist/diagnostics/core.d.ts.map +1 -0
  246. package/dist/diagnostics/core.js +72 -0
  247. package/dist/diagnostics/core.js.map +1 -0
  248. package/dist/diagnostics/default-core.d.ts +10 -0
  249. package/dist/diagnostics/default-core.d.ts.map +1 -0
  250. package/dist/diagnostics/default-core.js +72 -0
  251. package/dist/diagnostics/default-core.js.map +1 -0
  252. package/dist/diagnostics/index.d.ts +84 -0
  253. package/dist/diagnostics/index.d.ts.map +1 -0
  254. package/dist/diagnostics/index.js +106 -0
  255. package/dist/diagnostics/index.js.map +1 -0
  256. package/dist/dom.d.ts +55 -0
  257. package/dist/dom.d.ts.map +1 -0
  258. package/dist/dom.js +162 -0
  259. package/dist/dom.js.map +1 -0
  260. package/dist/index.d.ts +97 -0
  261. package/dist/index.d.ts.map +1 -0
  262. package/dist/index.js +58 -0
  263. package/dist/index.js.map +1 -0
  264. package/dist/jsx/react.d.ts +180 -0
  265. package/dist/jsx/react.d.ts.map +1 -0
  266. package/dist/jsx/react.js +2 -0
  267. package/dist/jsx/react.js.map +1 -0
  268. package/dist/lotek.css +3617 -0
  269. package/dist/lt.d.ts +325 -0
  270. package/dist/lt.d.ts.map +1 -0
  271. package/dist/lt.js +183 -0
  272. package/dist/lt.js.map +1 -0
  273. package/dist/react.d.ts +492 -0
  274. package/dist/react.d.ts.map +1 -0
  275. package/dist/react.js +296 -0
  276. package/dist/react.js.map +1 -0
  277. package/dist/register.d.ts +17 -0
  278. package/dist/register.d.ts.map +1 -0
  279. package/dist/register.js +35 -0
  280. package/dist/register.js.map +1 -0
  281. package/dist/tokens/color.d.ts +43 -0
  282. package/dist/tokens/color.d.ts.map +1 -0
  283. package/dist/tokens/color.js +123 -0
  284. package/dist/tokens/color.js.map +1 -0
  285. package/dist/tokens/contract.d.ts +18 -0
  286. package/dist/tokens/contract.d.ts.map +1 -0
  287. package/dist/tokens/contract.js +18 -0
  288. package/dist/tokens/contract.js.map +1 -0
  289. package/dist/tokens/matrix-cells.d.ts +30 -0
  290. package/dist/tokens/matrix-cells.d.ts.map +1 -0
  291. package/dist/tokens/matrix-cells.js +273 -0
  292. package/dist/tokens/matrix-cells.js.map +1 -0
  293. package/dist/tokens/matrix.d.ts +18 -0
  294. package/dist/tokens/matrix.d.ts.map +1 -0
  295. package/dist/tokens/matrix.js +21 -0
  296. package/dist/tokens/matrix.js.map +1 -0
  297. package/dist/tokens/theme-check.d.ts +42 -0
  298. package/dist/tokens/theme-check.d.ts.map +1 -0
  299. package/dist/tokens/theme-check.js +10 -0
  300. package/dist/tokens/theme-check.js.map +1 -0
  301. package/dist/tokens/theme.d.ts +94 -0
  302. package/dist/tokens/theme.d.ts.map +1 -0
  303. package/dist/tokens/theme.js +14 -0
  304. package/dist/tokens/theme.js.map +1 -0
  305. package/dist/tokens/tokens.d.ts +122 -0
  306. package/dist/tokens/tokens.d.ts.map +1 -0
  307. package/dist/tokens/tokens.js +158 -0
  308. package/dist/tokens/tokens.js.map +1 -0
  309. package/dist/vocabulary/classes.d.ts +3 -0
  310. package/dist/vocabulary/classes.d.ts.map +1 -0
  311. package/dist/vocabulary/classes.js +1320 -0
  312. package/dist/vocabulary/classes.js.map +1 -0
  313. package/dist/vocabulary/elements.d.ts +3 -0
  314. package/dist/vocabulary/elements.d.ts.map +1 -0
  315. package/dist/vocabulary/elements.js +410 -0
  316. package/dist/vocabulary/elements.js.map +1 -0
  317. package/dist/vocabulary/types.d.ts +175 -0
  318. package/dist/vocabulary/types.d.ts.map +1 -0
  319. package/dist/vocabulary/types.js +11 -0
  320. package/dist/vocabulary/types.js.map +1 -0
  321. package/dist/wasi-host.d.ts +24 -0
  322. package/dist/wasi-host.d.ts.map +1 -0
  323. package/dist/wasi-host.js +140 -0
  324. package/dist/wasi-host.js.map +1 -0
  325. package/live-templates.xml +62 -0
  326. package/manifest/files.json +373 -0
  327. package/manifest/manifest.json +4965 -0
  328. package/manifest/manifest.schema.json +513 -0
  329. package/package.json +398 -5
  330. package/src/cli.ts +21 -0
  331. package/src/components/css/accordion/accordion.css +102 -0
  332. package/src/components/css/accordion/accordion.ts +50 -0
  333. package/src/components/css/alert/alert.css +53 -0
  334. package/src/components/css/alert/alert.ts +48 -0
  335. package/src/components/css/avatar/avatar.css +96 -0
  336. package/src/components/css/avatar/avatar.ts +57 -0
  337. package/src/components/css/badge/badge.css +42 -0
  338. package/src/components/css/badge/badge.ts +43 -0
  339. package/src/components/css/breadcrumbs/breadcrumbs.css +62 -0
  340. package/src/components/css/breadcrumbs/breadcrumbs.ts +30 -0
  341. package/src/components/css/button/button.css +128 -0
  342. package/src/components/css/button/button.ts +44 -0
  343. package/src/components/css/card/card.css +65 -0
  344. package/src/components/css/card/card.ts +50 -0
  345. package/src/components/css/checkbox/checkbox.css +114 -0
  346. package/src/components/css/checkbox/checkbox.ts +50 -0
  347. package/src/components/css/divider/divider.css +38 -0
  348. package/src/components/css/divider/divider.ts +42 -0
  349. package/src/components/css/error-text/error-text.css +21 -0
  350. package/src/components/css/error-text/error-text.ts +37 -0
  351. package/src/components/css/fieldset/fieldset.css +72 -0
  352. package/src/components/css/fieldset/fieldset.ts +87 -0
  353. package/src/components/css/file-upload/file-upload.css +102 -0
  354. package/src/components/css/file-upload/file-upload.ts +65 -0
  355. package/src/components/css/heading/heading.css +33 -0
  356. package/src/components/css/heading/heading.ts +42 -0
  357. package/src/components/css/help-text/help-text.css +24 -0
  358. package/src/components/css/help-text/help-text.ts +42 -0
  359. package/src/components/css/icon/icon.css +20 -0
  360. package/src/components/css/icon/icon.ts +44 -0
  361. package/src/components/css/input/input.css +145 -0
  362. package/src/components/css/input/input.ts +77 -0
  363. package/src/components/css/label/label.css +42 -0
  364. package/src/components/css/label/label.ts +51 -0
  365. package/src/components/css/link/link.css +38 -0
  366. package/src/components/css/link/link.ts +38 -0
  367. package/src/components/css/list/list.css +53 -0
  368. package/src/components/css/list/list.ts +44 -0
  369. package/src/components/css/pagination/pagination.css +95 -0
  370. package/src/components/css/pagination/pagination.ts +33 -0
  371. package/src/components/css/paragraph/paragraph.css +31 -0
  372. package/src/components/css/paragraph/paragraph.ts +53 -0
  373. package/src/components/css/progress/progress.css +161 -0
  374. package/src/components/css/progress/progress.ts +78 -0
  375. package/src/components/css/radio/radio.css +94 -0
  376. package/src/components/css/radio/radio.ts +50 -0
  377. package/src/components/css/search/search.css +50 -0
  378. package/src/components/css/search/search.ts +56 -0
  379. package/src/components/css/select/select.css +321 -0
  380. package/src/components/css/select/select.ts +63 -0
  381. package/src/components/css/shared.ts +199 -0
  382. package/src/components/css/skeleton/skeleton.css +62 -0
  383. package/src/components/css/skeleton/skeleton.ts +43 -0
  384. package/src/components/css/skip-link/skip-link.css +41 -0
  385. package/src/components/css/skip-link/skip-link.ts +22 -0
  386. package/src/components/css/spinner/spinner.css +48 -0
  387. package/src/components/css/spinner/spinner.ts +48 -0
  388. package/src/components/css/sr-only/sr-only.css +16 -0
  389. package/src/components/css/sr-only/sr-only.ts +21 -0
  390. package/src/components/css/switch/switch.css +105 -0
  391. package/src/components/css/switch/switch.ts +50 -0
  392. package/src/components/css/table/table.css +159 -0
  393. package/src/components/css/table/table.ts +107 -0
  394. package/src/components/css/tag/tag.css +58 -0
  395. package/src/components/css/tag/tag.ts +49 -0
  396. package/src/components/css/textarea/textarea.css +83 -0
  397. package/src/components/css/textarea/textarea.ts +40 -0
  398. package/src/components/css/toggle-group/toggle-group.css +92 -0
  399. package/src/components/css/toggle-group/toggle-group.ts +37 -0
  400. package/src/components/css/tooltip/tooltip.css +89 -0
  401. package/src/components/css/tooltip/tooltip.ts +37 -0
  402. package/src/components/default-texts.ts +34 -0
  403. package/src/components/events.ts +68 -0
  404. package/src/components/frame/dialog/dialog.css +306 -0
  405. package/src/components/frame/dialog/dialog.ts +166 -0
  406. package/src/components/frame/dialog/lt-dialog.ts +510 -0
  407. package/src/components/frame/error-summary/error-summary.css +47 -0
  408. package/src/components/frame/error-summary/error-summary.ts +56 -0
  409. package/src/components/frame/error-summary/lt-error-summary.ts +344 -0
  410. package/src/components/frame/field/field-core.ts +152 -0
  411. package/src/components/frame/field/field.css +17 -0
  412. package/src/components/frame/field/lt-field.ts +753 -0
  413. package/src/components/frame/popover/lt-popover.ts +555 -0
  414. package/src/components/frame/popover/popover.css +50 -0
  415. package/src/components/frame/popover/popover.ts +102 -0
  416. package/src/components/frame/session-timeout/lt-session-timeout.ts +681 -0
  417. package/src/components/frame/session-timeout/session-timeout.css +50 -0
  418. package/src/components/frame/session-timeout/session-timeout.ts +156 -0
  419. package/src/components/frame/suggestion/lt-suggestion.ts +1358 -0
  420. package/src/components/frame/suggestion/suggestion.css +132 -0
  421. package/src/components/frame/suggestion/suggestion.ts +172 -0
  422. package/src/components/frame/tabs/lt-tabs.ts +1319 -0
  423. package/src/components/frame/tabs/tabs.css +128 -0
  424. package/src/components/frame/tabs/tabs.ts +188 -0
  425. package/src/components/host-element.ts +400 -0
  426. package/src/components/standalone/connection-status/connection-status.css +41 -0
  427. package/src/components/standalone/connection-status/connection-status.ts +41 -0
  428. package/src/components/standalone/connection-status/lt-connection-status.ts +242 -0
  429. package/src/components/standalone/toast/lt-toast.ts +300 -0
  430. package/src/components/standalone/toast/toast.css +78 -0
  431. package/src/components/standalone/toast/toast.ts +70 -0
  432. package/src/diagnostics/core.ts +210 -0
  433. package/src/diagnostics/default-core.ts +81 -0
  434. package/src/diagnostics/index.ts +150 -0
  435. package/src/dom.ts +185 -0
  436. package/src/index.ts +218 -0
  437. package/src/jsx/react.ts +212 -0
  438. package/src/lt.ts +192 -0
  439. package/src/react.ts +411 -0
  440. package/src/register.ts +43 -0
  441. package/src/tailwind/tailwind.css +169 -0
  442. package/src/tokens/boundary.css +104 -0
  443. package/src/tokens/color-contract.json +231 -0
  444. package/src/tokens/color.ts +150 -0
  445. package/src/tokens/contract.ts +24 -0
  446. package/src/tokens/matrix-cells.ts +375 -0
  447. package/src/tokens/matrix.ts +32 -0
  448. package/src/tokens/theme-check.ts +51 -0
  449. package/src/tokens/theme.ts +104 -0
  450. package/src/tokens/tokens.css +569 -0
  451. package/src/tokens/tokens.ts +223 -0
  452. package/src/vocabulary/classes.ts +1322 -0
  453. package/src/vocabulary/elements.ts +412 -0
  454. package/src/vocabulary/types.ts +178 -0
  455. package/src/wasi-host.ts +155 -0
  456. package/web-types.json +800 -0
@@ -0,0 +1,1319 @@
1
+ import {
2
+ defineElement,
3
+ derivedParts,
4
+ HostElement,
5
+ isServerControlled,
6
+ SERVER_CONTROLLED,
7
+ setAttr,
8
+ setFlag,
9
+ uniqueId,
10
+ warnAboutMarkup,
11
+ } from "../../host-element.js"
12
+ export const LT_TABS_TAG = "lt-tabs" as const
13
+
14
+ /**
15
+ * The parts the tabs look for, as selectors relative to the element. The
16
+ * web component finds its parts with these, and the manifest describes them
17
+ * for anyone writing the markup by hand, so the two cannot disagree.
18
+ */
19
+ export const LT_TABS_PARTS = {
20
+ /** The tab list: the one the server gave the role, or the class from `tabs.css`. */
21
+ list: "[role='tablist'], .lt-tabs__list",
22
+ /**
23
+ * A tab is a link to a panel in the tab list. A link is the only tab
24
+ * pattern that works without JavaScript: without the script the tab list is
25
+ * a table of contents, and the links lead to the panels. If the server has
26
+ * written the roles, only the links with `role="tab"` are tabs.
27
+ */
28
+ tab: "a[role='tab'][href^='#'], .lt-tabs__list a[href^='#']:not([role])",
29
+ /** A panel: the role when it is there, otherwise the class without a role. */
30
+ panel: "[role='tabpanel'], .lt-tabs__panel:not([role])",
31
+ } as const
32
+
33
+ const LIST_SELECTOR = LT_TABS_PARTS.list
34
+ const TAB_SELECTOR = LT_TABS_PARTS.tab
35
+ /** What the server has called a tab, including what is not a link. */
36
+ const ANY_TAB_SELECTOR = "[role='tab']"
37
+ /** The heading in a panel, which gives the panel its name. */
38
+ const HEADING_SELECTOR = ":scope > :is(h1, h2, h3, h4, h5, h6)"
39
+
40
+ /**
41
+ * The id a tab points to, or `null` when it is not a link to a fragment.
42
+ * `href="#"` on its own points to nothing.
43
+ *
44
+ * `href` is the truth, and `aria-controls` is written from it. The fragment
45
+ * is looked up the way the browser does: as written, and otherwise decoded,
46
+ * so both `#attachments` and `#s%C3%B8knaden` find their panel.
47
+ */
48
+ function linkTarget(tab: Element): string | null {
49
+ if (tab.localName !== "a") return null
50
+ const href = tab.getAttribute("href") ?? ""
51
+ if (!href.startsWith("#") || href.length < 2) return null
52
+ return href.slice(1)
53
+ }
54
+
55
+ function decoded(fragment: string): string | null {
56
+ try {
57
+ const plain = decodeURIComponent(fragment)
58
+ return plain === fragment ? null : plain
59
+ } catch {
60
+ return null
61
+ }
62
+ }
63
+
64
+ /** Text as a name is computed: whitespace collapsed, and trimmed. */
65
+ function flat(text: string): string {
66
+ return text.replace(/\s+/g, " ").trim()
67
+ }
68
+
69
+ /** Is the element hidden from assistive technology: `hidden`, `aria-hidden` or CSS? */
70
+ function hiddenFromAT(element: Element): boolean {
71
+ if (element.getAttribute("aria-hidden") === "true") return true
72
+ if (element.hasAttribute("hidden")) return true
73
+ if (!(element instanceof HTMLElement) || !element.isConnected) return false
74
+ const style = getComputedStyle(element)
75
+ return style.display === "none" || style.visibility === "hidden"
76
+ }
77
+
78
+ /**
79
+ * The text an element contributes to a name, as AccName 1.2 computes it from
80
+ * step 2.
81
+ *
82
+ * `aria-labelledby` (2B), `aria-label` on something inside, `alt` on an
83
+ * image, and the text, but not what is hidden from assistive technology.
84
+ * `textContent` included hidden text, such as "Messages (3)", and gave an
85
+ * empty name to a tab with only an icon and `aria-label`.
86
+ *
87
+ * - `includeHidden`: when a hidden element is pointed to directly with
88
+ * `aria-labelledby`, it is included anyway, with everything inside it (2A).
89
+ * - `inReference`: the node is inside an `aria-labelledby` that is already
90
+ * being followed, and then another one is not followed (2B).
91
+ *
92
+ * Text from CSS, `::before` and `::after` (2F.ii), is not included. LO-TEK's
93
+ * tabs do not use it, and reading `content` correctly is a lot of code for
94
+ * something nobody needs (decided by the maintainer on 23 October).
95
+ */
96
+ function textOf(
97
+ node: Node,
98
+ includeHidden = false,
99
+ inReference = false,
100
+ ): string {
101
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? ""
102
+ if (!(node instanceof Element)) return ""
103
+ if (!includeHidden && hiddenFromAT(node)) return ""
104
+ if (!inReference) {
105
+ const referenced = referencedText(node)
106
+ if (referenced !== "") return ` ${referenced} `
107
+ }
108
+ const label = node.getAttribute("aria-label")
109
+ if (label && flat(label) !== "") return ` ${label} `
110
+ if (node.localName === "img") return ` ${node.getAttribute("alt") ?? ""} `
111
+ let text = ""
112
+ for (const child of node.childNodes)
113
+ text += textOf(child, includeHidden, inReference)
114
+ return text
115
+ }
116
+
117
+ /** The text from the elements `aria-labelledby` points to, or empty (AccName 2B). */
118
+ function referencedText(element: Element): string {
119
+ const ids = element.getAttribute("aria-labelledby")
120
+ if (!ids) return ""
121
+ const root = element.getRootNode() as Document | ShadowRoot
122
+ return flat(
123
+ ids
124
+ .split(/\s+/)
125
+ .map((id) => (id === "" ? null : root.getElementById?.(id)))
126
+ .filter((e): e is HTMLElement => Boolean(e))
127
+ .map((e) => textOf(e, hiddenFromAT(e), true))
128
+ .join(" "),
129
+ )
130
+ }
131
+
132
+ /** The name of an element, as a screen reader computes it. */
133
+ function accessibleName(element: Element): string {
134
+ const referenced = referencedText(element)
135
+ if (referenced !== "") return referenced
136
+ const label = element.getAttribute("aria-label")
137
+ if (label && flat(label) !== "") return flat(label)
138
+ let text = ""
139
+ for (const child of element.childNodes) text += textOf(child)
140
+ if (flat(text) !== "") return flat(text)
141
+ return flat(element.getAttribute("title") ?? "")
142
+ }
143
+
144
+ /**
145
+ * The name a panel gets when it points to the element with `aria-labelledby`.
146
+ *
147
+ * Not the same as the element's name: inside an `aria-labelledby`, the
148
+ * element's `aria-labelledby` is not followed (AccName 2B), and a hidden
149
+ * element is included (2A). A heading with `aria-labelledby` pointing to
150
+ * "Attachments" and the text "Enclosures" gave the panel the name
151
+ * "Enclosures", while the web component thought it was "Attachments".
152
+ */
153
+ function nameAsReferenced(element: Element): string {
154
+ return flat(textOf(element, hiddenFromAT(element), true))
155
+ }
156
+
157
+ /**
158
+ * What the web component last wrote on a node, and what the server last said.
159
+ *
160
+ * `aria-selected` on the tabs and `hidden` on the panels are both read and
161
+ * written. A naive read is the web component's echo of itself: bare markup
162
+ * got `aria-selected="true"` on the first tab from the web component, and
163
+ * when the server switched tab with a patch that only touched the panels,
164
+ * the web component read its earlier selection back and hid the panel the
165
+ * server had just shown. If something other than what the web component
166
+ * wrote is there, the server has touched it, and it is the server's word. If
167
+ * the same is there, what the server said last applies.
168
+ */
169
+ type Word = { written: string | null; server: string | null }
170
+
171
+ /**
172
+ * Keyboard behaviour in a tab list, and the wiring when the markup comes
173
+ * without it.
174
+ *
175
+ * The tabs are links to their panels, the way GOV.UK does it:
176
+ *
177
+ * ```html
178
+ * <lt-tabs>
179
+ * <ul class="lt-tabs__list" aria-label="Parts of the case">
180
+ * <li><a href="#application">Application</a></li>
181
+ * <li><a href="#attachments">Attachments</a></li>
182
+ * </ul>
183
+ * <section class="lt-tabs__panel" id="application"><h2>Application</h2>…</section>
184
+ * <section class="lt-tabs__panel" id="attachments"><h2>Attachments</h2>…</section>
185
+ * </lt-tabs>
186
+ * ```
187
+ *
188
+ * Without JavaScript this is a table of contents with all the panels one
189
+ * after another, and the links work. What the template writes is an id on
190
+ * the panels, and it needs the links anyway.
191
+ *
192
+ * The web component never writes an id on a tab or a panel. Datastar and
193
+ * idiomorph recognise an element by its id, and an element with an id the
194
+ * server did not send is replaced at the next update, along with the tab
195
+ * selection and focus. The panels' ids come from the server, so they are
196
+ * kept. What the web component fills in, it computes from the markup: the
197
+ * roles, `aria-controls` from `href`, `role="presentation"` on the list
198
+ * items, and the panel's name, which is the tab's. The heading in the panel
199
+ * is the name when it says the same as the tab. Only the selected panel is a
200
+ * tab stop.
201
+ *
202
+ * The panels that are not selected are hidden with `hidden="until-found"`, so
203
+ * find in page and a link to something in a panel reach them, and the
204
+ * browser fires `beforematch`, which the web component selects the tab from.
205
+ * If the server wrote `hidden` itself, it is written back in the server's
206
+ * form, across the whole tab list: `lt.tabs()` from
207
+ * `@lo-tek/interfaces/react` gives `hidden=""`, because React cannot write
208
+ * `until-found`. The address selects the tab when the page loads and when it
209
+ * changes, and each selection is written to the address, unless it already
210
+ * points to the selected panel or something in it. On load the server's
211
+ * `aria-selected` comes before the address, and under `server-controlled`
212
+ * the address never selects.
213
+ *
214
+ * What the server has written stays. Which tab is selected is read from
215
+ * `aria-selected`, and when that is missing, from which panel is not hidden;
216
+ * if nothing is said, it is the first. Before the web component is
217
+ * registered, `tabs.css` shows only the panel the web component is going to
218
+ * select: the first visible one, or the one the address points to, so the
219
+ * content does not jump when the rest are hidden.
220
+ *
221
+ * What the web component then does is what the browser does not do by
222
+ * itself: Tab skips past the whole tab list and into the panel, while the
223
+ * arrow keys move between the tabs. With `activation="manual"` the arrow keys
224
+ * only move focus, and Enter or Space selects.
225
+ *
226
+ * The tab selection belongs to the user, and the web component restores it
227
+ * when a patch strips it. If the server needs to move the tab, as in
228
+ * "continue to step 2", set `server-controlled` on the host, and then every
229
+ * patch decides.
230
+ */
231
+ export class LtTabs extends HostElement {
232
+ /**
233
+ * `server-controlled` and `activation`. Which tab is selected is in the
234
+ * markup the server sent, as `aria-selected` on the tab and `hidden` on the
235
+ * panels, and is read from there. A separate `selected` would have been a
236
+ * parallel copy of the same thing.
237
+ */
238
+ static observedAttributes = [SERVER_CONTROLLED, "activation"] as const
239
+
240
+ private observer?: MutationObserver
241
+ /**
242
+ * The tab the user selected, remembered so a patch cannot take it.
243
+ *
244
+ * The node itself, not the index and not `href`. An index is not an
245
+ * identity: if the server inserts a tab first in the list, the same index
246
+ * points to something else, and the selection jumps to a tab the user never
247
+ * pressed.
248
+ *
249
+ * A morph keeps the links, since they have no id. If the patch replaces the
250
+ * link itself, as `innerHTML` does, the tab is a different one, and then
251
+ * the web component forgets the selection rather than guessing; the address
252
+ * still has it, see `selectFromAddress`.
253
+ *
254
+ * `undefined` means the user has not selected anything yet, and then the
255
+ * server's markup applies.
256
+ */
257
+ private chosenTab?: HTMLElement
258
+ /**
259
+ * Roles the web component set itself. Tells a bare tab list, where every
260
+ * link is a tab, from one where the server wrote the roles, where a link
261
+ * without a role is something else, such as a help link.
262
+ */
263
+ private readonly roledByMe = new WeakSet<Element>()
264
+ private selectedMemory = new WeakMap<Element, Word>()
265
+ private hiddenMemory = new WeakMap<Element, Word>()
266
+ /**
267
+ * The form the server hides panels in, the last time it hid something:
268
+ * `""` from `lt.tabs()`, `"until-found"` or something else. The web
269
+ * component writes `hidden` in that form on every panel in the tab list,
270
+ * including a panel the server never hid. Otherwise one panel got
271
+ * `until-found` and the others `""` in the same tab list. If the server has
272
+ * never hidden anything, it is `until-found`, so find in page reaches the
273
+ * panel.
274
+ */
275
+ private hiddenForm = "until-found"
276
+ /**
277
+ * The id the web component gave the heading in a panel, per panel. A morph
278
+ * strips the id from the heading and `aria-labelledby` from the panel,
279
+ * since neither was in the server's HTML, and the panel must get the same
280
+ * one back, so a screen reader does not follow a reference that changes
281
+ * under it.
282
+ */
283
+ private readonly headingIds = new WeakMap<Element, string>()
284
+ /** The name the web component wrote in `aria-label` on a panel without a heading. */
285
+ private readonly labelByMe = new WeakMap<Element, string>()
286
+ /**
287
+ * The tab the user clicked under `server-controlled`, until the server
288
+ * answers.
289
+ *
290
+ * It is not the user's selection in the sense of `chosenTab`: it is never
291
+ * restored against the server's word. It only lasts until someone else has
292
+ * touched `aria-selected` or `hidden`, added a tab or a panel, removed the
293
+ * tab, or removed `server-controlled`. Without it, `repair()` read the
294
+ * server's old word from memory in the next microtask and undid the click,
295
+ * so the tabs could not be switched, and a `data-attr:hidden` that wrote the
296
+ * same as the web component had just written was never seen.
297
+ */
298
+ private pendingTab?: HTMLElement
299
+ /**
300
+ * The panel the browser is revealing after `beforematch`.
301
+ *
302
+ * The browser removes `hidden` itself after the event, and then moves on to
303
+ * the ancestors, such as an outer panel or a closed `<details>`. But only as
304
+ * long as the panel still has `hidden="until-found"` when the event is done.
305
+ * When the search comes from the user, the browser runs the microtasks after
306
+ * each listener, the observer included, and when the web component removed
307
+ * `hidden` in that round, Chromium and WebKit stopped. The match in a tab
308
+ * list inside a hidden panel stayed invisible. The panel is therefore not
309
+ * touched until the next task, when the browser is done, see `revealed()`.
310
+ */
311
+ private revealing?: Element
312
+ /**
313
+ * Whether the tab list has loaded: whether the address or the server's
314
+ * selection has been read. That happens the first time the tab list has
315
+ * tabs and the address can be resolved, see `sync()`, not when the element
316
+ * is connected. An `<lt-tabs>` the server fills in later otherwise always
317
+ * got the first tab.
318
+ */
319
+ private started = false
320
+ /**
321
+ * The root `beforematch` is listened for on. The event bubbles, but is not
322
+ * `composed`, so from a panel in a shadow root it never reaches the
323
+ * document.
324
+ */
325
+ private root?: Document | ShadowRoot
326
+
327
+ connectedCallback(): void {
328
+ /*
329
+ * The attributes are included, not just the children. A morph strips what
330
+ * is not in the server's HTML, and the tab selection is exactly that:
331
+ * something the user did after the page arrived. Every write compares
332
+ * first, or the observer would trigger itself.
333
+ */
334
+ // One listener on the host, not one per tab. Capture phase, so a listener
335
+ // on the tab list that stops the event does not take clicks and arrow
336
+ // keys from the tabs.
337
+ this.addEventListener("click", this.handleClick, true)
338
+ this.addEventListener("keydown", this.handleKeydown, true)
339
+ // Find in page, or a link to something in a panel hidden with
340
+ // `until-found`. On the document, not on the host: a panel can be outside
341
+ // `<lt-tabs>`, and then the event never reaches the host.
342
+ document.addEventListener("beforematch", this.handleBeforematch, true)
343
+ const root = this.getRootNode() as Document | ShadowRoot
344
+ if (root !== document) {
345
+ this.root = root
346
+ root.addEventListener("beforematch", this.handleBeforematch, true)
347
+ }
348
+ window.addEventListener("hashchange", this.handleHashchange)
349
+ this.observer = new MutationObserver((records) => {
350
+ if (this.concerns(records)) this.sync()
351
+ })
352
+ this.observer.observe(this, {
353
+ childList: true,
354
+ subtree: true,
355
+ attributes: true,
356
+ // The panel's name is the tab's. idiomorph changes the text in a text
357
+ // node, with nothing else the observer sees.
358
+ characterData: true,
359
+ // `disabled` is included because the web component reads it: if a patch
360
+ // disables the selected tab, the tab stop moves to one that can take
361
+ // focus. `alt`, `aria-hidden` and `title` change the name of a tab.
362
+ attributeFilter: [
363
+ "aria-selected",
364
+ "tabindex",
365
+ "hidden",
366
+ "disabled",
367
+ "aria-disabled",
368
+ // The wiring the web component sets when the markup came without it,
369
+ // and restores when a patch removes it.
370
+ "role",
371
+ "id",
372
+ "href",
373
+ "aria-controls",
374
+ "aria-labelledby",
375
+ "aria-label",
376
+ "alt",
377
+ "aria-hidden",
378
+ "title",
379
+ ],
380
+ })
381
+ this.sync()
382
+ }
383
+
384
+ attributeChangedCallback(name: string): void {
385
+ // `server-controlled` switched on midway: the web component lets go, and
386
+ // the next patch decides.
387
+ if (name === SERVER_CONTROLLED && isServerControlled(this)) {
388
+ this.chosenTab = undefined
389
+ // What is there now is the starting point. Without this the tab list
390
+ // jumped back to the tab the server last named, before the user chose
391
+ // another. But as when the server answers a click: `aria-selected` the
392
+ // web component wrote is not the server's. When everything counted as
393
+ // the server's, it took precedence over `hidden`, and a server that
394
+ // moves the tab with `hidden` alone was not heard.
395
+ this.releasePending()
396
+ }
397
+ }
398
+
399
+ disconnectedCallback(): void {
400
+ this.observer?.disconnect()
401
+ this.observer = undefined
402
+ this.removeEventListener("click", this.handleClick, true)
403
+ this.removeEventListener("keydown", this.handleKeydown, true)
404
+ document.removeEventListener("beforematch", this.handleBeforematch, true)
405
+ this.root?.removeEventListener("beforematch", this.handleBeforematch, true)
406
+ this.root = undefined
407
+ window.removeEventListener("hashchange", this.handleHashchange)
408
+ // If the element is connected again, the address is read again.
409
+ this.started = false
410
+ }
411
+
412
+ /**
413
+ * The tabs that belong to this tab list, and only those.
414
+ *
415
+ * Tabs inside tabs are ordinary markup. Without the boundary an inner tab
416
+ * list became part of the outer one: a click on an inner tab hid the outer
417
+ * panel it was in, and both web components attached listeners to the same
418
+ * tabs.
419
+ */
420
+ private get tabs(): HTMLElement[] {
421
+ return derivedParts<HTMLElement>(
422
+ this,
423
+ TAB_SELECTOR,
424
+ "tab",
425
+ this.roledByMe,
426
+ ).filter((tab) => linkTarget(tab) !== null)
427
+ }
428
+
429
+ /** The server's word about an attribute, against what the web component last wrote. */
430
+ private serverWord(
431
+ memory: WeakMap<Element, Word>,
432
+ element: Element,
433
+ now: string | null,
434
+ ): string | null {
435
+ const known = memory.get(element)
436
+ if (!known) return now
437
+ return now !== known.written ? now : known.server
438
+ }
439
+
440
+ /** Is there something on a tab or a panel other than what the web component wrote? */
441
+ private touchedByOthers(): boolean {
442
+ return this.tabs.some((tab) => {
443
+ const selected = this.selectedMemory.get(tab)
444
+ if (!selected || tab.getAttribute("aria-selected") !== selected.written) {
445
+ return true
446
+ }
447
+ const panel = this.panelFor(tab)
448
+ if (!panel) return false
449
+ const hidden = this.hiddenMemory.get(panel)
450
+ return !hidden || panel.getAttribute("hidden") !== hidden.written
451
+ })
452
+ }
453
+
454
+ /**
455
+ * Releases the click, and makes what is in the markup now the server's
456
+ * word.
457
+ *
458
+ * The memory holds the server's word from before the click, and it is
459
+ * stale: the server has answered. An attribute the server wrote the same as
460
+ * the web component cannot be told from one it did not touch, so the old
461
+ * words won, and the tab list jumped back to the tab from before the click
462
+ * just as the server confirmed the new one.
463
+ *
464
+ * `hidden` on the panels is therefore read as it is. `aria-selected` is read
465
+ * as it is when the server has touched at least one tab, that is, when the
466
+ * server speaks through `aria-selected`. If it has not, the values are the
467
+ * ones the web component wrote for the click, and then the panels say which
468
+ * tab applies.
469
+ */
470
+ private releasePending(): void {
471
+ this.pendingTab = undefined
472
+ const tabs = this.tabs
473
+ const serverSpoke = tabs.some((tab) => {
474
+ const now = tab.getAttribute("aria-selected")
475
+ const known = this.selectedMemory.get(tab)
476
+ // A new, bare tab has said nothing. Had it counted, the click's
477
+ // `aria-selected` was read as the server's, and a later move with
478
+ // `hidden` alone was undone.
479
+ return known ? now !== known.written : now !== null
480
+ })
481
+ this.hiddenMemory = new WeakMap()
482
+ if (serverSpoke) {
483
+ this.selectedMemory = new WeakMap()
484
+ return
485
+ }
486
+ for (const tab of tabs) {
487
+ this.selectedMemory.set(tab, {
488
+ written: tab.getAttribute("aria-selected"),
489
+ server: null,
490
+ })
491
+ }
492
+ }
493
+
494
+ private serverSelected(tab: Element): string | null {
495
+ return this.serverWord(
496
+ this.selectedMemory,
497
+ tab,
498
+ tab.getAttribute("aria-selected"),
499
+ )
500
+ }
501
+
502
+ /** The server's word about `hidden` on the panel: the form, or `null` for visible. */
503
+ private serverHidden(panel: Element): string | null {
504
+ return this.serverWord(
505
+ this.hiddenMemory,
506
+ panel,
507
+ panel.getAttribute("hidden"),
508
+ )
509
+ }
510
+
511
+ /**
512
+ * Can any of the changes concern the tab list?
513
+ *
514
+ * The observer sees the whole tree, and a suggestion field, a counter or an
515
+ * inner tab list in a panel changes `aria-selected`, `hidden` and text on
516
+ * every keystroke. Each of them gave a full round, with styles read for the
517
+ * names. Only what is deep inside one of the tab list's panels is skipped,
518
+ * and only when it is neither a heading in the panel, something
519
+ * `aria-labelledby` points to, nor an id, which can make an element
520
+ * something a tab points to. Everything else gives a round, as before.
521
+ */
522
+ private concerns(records: MutationRecord[]): boolean {
523
+ let panels: HTMLElement[] | undefined
524
+ let names: Set<string> | undefined
525
+ for (const record of records) {
526
+ if (record.type === "attributes" && record.attributeName === "id")
527
+ return true
528
+ const target =
529
+ record.target instanceof Element
530
+ ? record.target
531
+ : record.target.parentElement
532
+ if (!target) return true
533
+ panels ??= this.tabs.flatMap((tab) => this.panelFor(tab) ?? [])
534
+ const panel = panels.find((p) => p !== target && p.contains(target))
535
+ if (!panel) return true
536
+ const heading = target.closest("h1, h2, h3, h4, h5, h6")
537
+ if (heading && heading.parentElement === panel) return true
538
+ names ??= this.watchedIds(panels)
539
+ if (this.within(target, names)) return true
540
+ if (record.type === "childList") {
541
+ for (const node of [...record.addedNodes, ...record.removedNodes])
542
+ if (this.carries(node, names)) return true
543
+ }
544
+ }
545
+ return false
546
+ }
547
+
548
+ /**
549
+ * The ids `aria-labelledby` points to from the tabs, what is inside them,
550
+ * and the panels. Before the tab list has loaded, also the id the address
551
+ * points to: the tab list waits for that element, see `sync()`, and it can
552
+ * arrive deep inside a panel.
553
+ */
554
+ private watchedIds(panels: HTMLElement[]): Set<string> {
555
+ const ids = new Set<string>()
556
+ if (!this.started) {
557
+ const hash = location.hash.slice(1)
558
+ if (hash !== "") ids.add(hash)
559
+ const plain = decoded(hash)
560
+ if (plain !== null) ids.add(plain)
561
+ }
562
+ const from = (element: Element) => {
563
+ for (const id of (element.getAttribute("aria-labelledby") ?? "").split(
564
+ /\s+/,
565
+ ))
566
+ if (id !== "") ids.add(id)
567
+ }
568
+ for (const tab of this.tabs) {
569
+ from(tab)
570
+ for (const inner of tab.querySelectorAll("[aria-labelledby]")) from(inner)
571
+ }
572
+ for (const panel of panels) from(panel)
573
+ return ids
574
+ }
575
+
576
+ /** Is the element inside an element with one of the ids, or is it one itself? */
577
+ private within(element: Element, ids: Set<string>): boolean {
578
+ if (ids.size === 0) return false
579
+ for (let e: Element | null = element; e; e = e.parentElement)
580
+ if (e.id && ids.has(e.id)) return true
581
+ return false
582
+ }
583
+
584
+ /** Does an added or removed node carry one of the ids, itself or inside it? */
585
+ private carries(node: Node, ids: Set<string>): boolean {
586
+ if (!(node instanceof Element) || ids.size === 0) return false
587
+ if (node.id && ids.has(node.id)) return true
588
+ for (const inner of node.querySelectorAll("[id]"))
589
+ if (ids.has(inner.id)) return true
590
+ return false
591
+ }
592
+
593
+ /** The tab list the tabs are in, when it belongs to this web component. */
594
+ private get list(): HTMLElement | null {
595
+ // The first tab list that belongs to this web component, not the first in
596
+ // the tree: when the panels with an inner tab list come before the outer
597
+ // tab list, the inner one was first.
598
+ for (const list of this.querySelectorAll<HTMLElement>(LIST_SELECTOR))
599
+ if (list.closest(this.localName) === this) return list
600
+ return null
601
+ }
602
+
603
+ /**
604
+ * The panel a tab controls, through the id it points to.
605
+ *
606
+ * The panel can be outside the host. It is then not in what the web
607
+ * component observes, so if a patch strips `hidden` from it, it does not
608
+ * come back by itself. If the tab points to nothing, the answer is nothing,
609
+ * and the web component warns. The order is not a fallback: two tabs could
610
+ * then have got the same panel, and the two wrote opposite `hidden` on it in
611
+ * every single round.
612
+ */
613
+ private panelFor(tab: HTMLElement): HTMLElement | null {
614
+ const target = linkTarget(tab)
615
+ return target === null ? null : this.byFragment(target)
616
+ }
617
+
618
+ /** The element a fragment points to, as written or decoded. */
619
+ private byFragment(fragment: string): HTMLElement | null {
620
+ const root = this.getRootNode() as Document | ShadowRoot
621
+ const found = root.getElementById?.(fragment)
622
+ if (found) return found
623
+ // A fragment can be encoded, such as `#s%C3%B8knaden`.
624
+ const plain = decoded(fragment)
625
+ return plain === null ? null : (root.getElementById?.(plain) ?? null)
626
+ }
627
+
628
+ /**
629
+ * A tab that cannot be selected, with either mouse or keyboard: disabled,
630
+ * or hidden with `hidden`. A hidden tab cannot take focus, so when an arrow
631
+ * key selected it, the tab stop was left on something Tab never reaches.
632
+ */
633
+ private isDisabled(tab: HTMLElement): boolean {
634
+ return (
635
+ tab.hasAttribute("disabled") ||
636
+ tab.getAttribute("aria-disabled") === "true" ||
637
+ tab.hasAttribute("hidden")
638
+ )
639
+ }
640
+
641
+ /** The arrow keys only move focus, and Enter or Space selects. */
642
+ private get manual(): boolean {
643
+ return this.getAttribute("activation") === "manual"
644
+ }
645
+
646
+ /**
647
+ * The index of the marked tab, or `-1` when none is.
648
+ *
649
+ * `selected` answers 0 in that case, because it is public API and a tab
650
+ * list in practice always has a selected tab. But that lie cannot be used
651
+ * internally: when it said 0 with nothing marked, `select(0)` returned at
652
+ * once, and the tab list did not respond to a click at all.
653
+ */
654
+ private get markedIndex(): number {
655
+ return this.tabs.findIndex(
656
+ (tab) => tab.getAttribute("aria-selected") === "true",
657
+ )
658
+ }
659
+
660
+ /** The index of the selected tab. */
661
+ get selected(): number {
662
+ const index = this.markedIndex
663
+ return index < 0 ? 0 : index
664
+ }
665
+
666
+ set selected(index: number) {
667
+ // React 19 writes the property when it exists, and the documentation
668
+ // shows `tabs.selected` as API. A getter alone threw on assignment.
669
+ this.select(index)
670
+ }
671
+
672
+ private sync(): void {
673
+ /*
674
+ * The first time the tab list has tabs, it has loaded. If the server has
675
+ * said which tab is selected, that applies: the server cannot see the
676
+ * address, and the React entry's `lt.tabs()` writes `aria-selected`.
677
+ * When the web component selected from the address before React
678
+ * hydrated, React reported a mismatch for every attribute it changed.
679
+ * Otherwise the address selects. The server's word is read before the
680
+ * web component writes anything.
681
+ */
682
+ // Loaded when the tab list has tabs and the address can be resolved: it
683
+ // is empty, or the element it points to exists. When the tab list came
684
+ // before the panels, or the content after the panel, the address
685
+ // otherwise found nothing, and the first tab was selected over the one
686
+ // the user asked for. Waiting for every tab to have a panel was not
687
+ // enough: with one link pointing to nothing, the tab list never loaded.
688
+ // If the address points to something that never comes, such as
689
+ // `#/case/1`, there is nothing to select either. The server's word is read
690
+ // through the memory, so a new connection does not take the web
691
+ // component's writes for the server's.
692
+ const tabs = this.tabs
693
+ const hash = location.hash.slice(1)
694
+ const loading =
695
+ !this.started &&
696
+ tabs.length > 0 &&
697
+ (hash === "" || this.byFragment(hash) !== null)
698
+ const serverChose =
699
+ loading && tabs.some((tab) => this.serverSelected(tab) === "true")
700
+ this.wire()
701
+ this.bind()
702
+ this.repair()
703
+ if (!loading) return
704
+ this.started = true
705
+ if (serverChose) this.alignAddress(this.markedIndex)
706
+ else this.selectFromAddress()
707
+ }
708
+
709
+ /**
710
+ * Fills in the wiring where the markup came without it.
711
+ *
712
+ * Only what is missing, with one exception: `aria-controls` is written from
713
+ * `href`, since the two are the same information and `href` is the one that
714
+ * works without JavaScript. Any other attribute the server has written is
715
+ * the server's word, even when it says something other than the web
716
+ * component would have said.
717
+ */
718
+ private wire(): void {
719
+ const list = this.list
720
+ if (list && !list.hasAttribute("role")) setAttr(list, "role", "tablist")
721
+ // In a list each list item is only a wrapper around the tab. Without the
722
+ // role a screen reader says "list, 2 items" before each tab.
723
+ if (list && (list.localName === "ul" || list.localName === "ol")) {
724
+ for (const item of list.children) {
725
+ if (item.localName === "li" && !item.hasAttribute("role")) {
726
+ setAttr(item, "role", "presentation")
727
+ }
728
+ }
729
+ }
730
+
731
+ /*
732
+ * Each panel gets its name once, from the first tab that points to it.
733
+ * When two tabs pointed to the same one, through a mistake in the markup,
734
+ * each of them gave the panel its name in every round, and the observer
735
+ * called itself forever.
736
+ */
737
+ const named = new Set<HTMLElement>()
738
+ for (const tab of this.tabs) {
739
+ if (!tab.hasAttribute("role")) {
740
+ setAttr(tab, "role", "tab")
741
+ this.roledByMe.add(tab)
742
+ }
743
+ const panel = this.panelFor(tab)
744
+ setAttr(tab, "aria-controls", panel?.id ?? linkTarget(tab))
745
+ if (!panel) continue
746
+
747
+ if (!panel.hasAttribute("role")) {
748
+ setAttr(panel, "role", "tabpanel")
749
+ this.roledByMe.add(panel)
750
+ }
751
+ if (named.has(panel)) continue
752
+ named.add(panel)
753
+ this.name(panel, tab)
754
+ }
755
+ }
756
+
757
+ /**
758
+ * Gives the panel a name, when the server has not given it one.
759
+ *
760
+ * The panel is named what the tab is named, as the APG does it. The APG
761
+ * lets the panel point to the tab, but the tab has no id here, and the web
762
+ * component writes none. If the heading in the panel says the same as the
763
+ * tab, the heading is the name, and it can get an id from the web
764
+ * component: it has no state the user can lose. Otherwise the name is the
765
+ * tab's, as `aria-label`.
766
+ *
767
+ * An `aria-label` or `aria-labelledby` the server wrote is never changed,
768
+ * even when the reference points to something that does not exist yet.
769
+ * Until it arrives, the tab's name stands as `aria-label`: a reference
770
+ * without a match is ignored when the name is computed, and then
771
+ * `aria-label` applies.
772
+ */
773
+ private name(panel: HTMLElement, tab: HTMLElement): void {
774
+ const ownLabel = this.labelByMe.get(panel)
775
+ const label = panel.getAttribute("aria-label")
776
+ if (label !== null && label !== ownLabel) return
777
+
778
+ const tabName = accessibleName(tab)
779
+ const named = panel.getAttribute("aria-labelledby")
780
+ const remembered = this.headingIds.get(panel)
781
+ if (named !== null && named !== remembered) {
782
+ if (this.resolves(named)) this.dropOwnLabel(panel)
783
+ else this.setOwnLabel(panel, tabName)
784
+ return
785
+ }
786
+
787
+ // Without a name on the tab there is nothing to give the panel. An empty
788
+ // `aria-label` would also have taken the name from the heading.
789
+ if (tabName === "") {
790
+ this.dropOwnLabel(panel)
791
+ return
792
+ }
793
+ const heading = panel.querySelector<HTMLElement>(HEADING_SELECTOR)
794
+ if (heading && nameAsReferenced(heading) === tabName) {
795
+ this.dropOwnLabel(panel)
796
+ // If the reference is the web component's, and the heading lost its id
797
+ // in a morph, it gets the same one back.
798
+ let id = heading.id
799
+ if (!id) {
800
+ id = remembered ?? uniqueId("lt-tabs-heading")
801
+ setAttr(heading, "id", id)
802
+ }
803
+ this.headingIds.set(panel, id)
804
+ setAttr(panel, "aria-labelledby", id)
805
+ return
806
+ }
807
+
808
+ if (named !== null) {
809
+ setAttr(panel, "aria-labelledby", null)
810
+ this.headingIds.delete(panel)
811
+ }
812
+ this.setOwnLabel(panel, tabName)
813
+ }
814
+
815
+ /** Writes the tab's name as `aria-label`, and remembers that the web component wrote it. */
816
+ private setOwnLabel(panel: HTMLElement, text: string): void {
817
+ setAttr(panel, "aria-label", text)
818
+ this.labelByMe.set(panel, text)
819
+ }
820
+
821
+ /** Removes the fallback, when a name that exists has taken over. */
822
+ private dropOwnLabel(panel: HTMLElement): void {
823
+ if (!this.labelByMe.has(panel)) return
824
+ setAttr(panel, "aria-label", null)
825
+ this.labelByMe.delete(panel)
826
+ }
827
+
828
+ /** Does at least one of the ids point to an element that exists? */
829
+ private resolves(ids: string): boolean {
830
+ const root = this.getRootNode() as Document | ShadowRoot
831
+ return ids
832
+ .split(/\s+/)
833
+ .some((id) => id !== "" && (root.getElementById?.(id) ?? null) !== null)
834
+ }
835
+
836
+ /**
837
+ * The tab the server says is selected, when the user has not selected
838
+ * anything.
839
+ *
840
+ * The server's word, not what is there: what the web component wrote does
841
+ * not count, see `Word`. `aria-selected` first. When that is missing, as in
842
+ * markup written without JavaScript, `hidden` on the panels says the same:
843
+ * the first panel the server shows belongs to the selected tab. If the
844
+ * markup says nothing, or hides every panel, it is the first, which is what
845
+ * a tab list starts on anyway.
846
+ */
847
+ private get derivedIndex(): number {
848
+ const tabs = this.tabs
849
+ const marked = tabs.findIndex((tab) => this.serverSelected(tab) === "true")
850
+ if (marked >= 0) return marked
851
+
852
+ const shown = tabs.findIndex((tab) => {
853
+ const panel = this.panelFor(tab)
854
+ return panel !== null && this.serverHidden(panel) === null
855
+ })
856
+ return shown < 0 ? 0 : shown
857
+ }
858
+
859
+ /**
860
+ * Restores the user's selection after a patch.
861
+ *
862
+ * Without this the template had to write
863
+ * `data-preserve-attr="aria-selected tabindex"` on every tab and `hidden` on
864
+ * every panel, that is, list the attributes the web component was going to
865
+ * touch. No compiler looked at that list.
866
+ *
867
+ * `apply()` is called whether or not the tabs look right, because a patch
868
+ * may have touched only the panels. That is the narrow patch the
869
+ * documentation itself recommends, and a check on `aria-selected` alone did
870
+ * not see it: the tab said one thing and the screen another.
871
+ */
872
+ private repair(): void {
873
+ if (this.pendingTab) {
874
+ const index = this.tabs.indexOf(this.pendingTab)
875
+ if (isServerControlled(this) && index >= 0 && !this.touchedByOthers()) {
876
+ this.apply(index)
877
+ return
878
+ }
879
+ this.releasePending()
880
+ }
881
+
882
+ if (!this.chosenTab || isServerControlled(this)) {
883
+ /*
884
+ * No user selection to restore, so the server's word decides, and it
885
+ * is written out in full: `aria-selected`, the tab stop and `hidden` in
886
+ * step. Bare structure without `aria-selected` thus gets the first tab
887
+ * selected and the other panels hidden, and a patch that only touched
888
+ * the panels also moves the selection. That applies under
889
+ * `server-controlled` too: the web component does not restore the
890
+ * user's selection there, but still writes out what the server's
891
+ * markup says. If everything already matches, `apply()` writes nothing.
892
+ */
893
+ if (this.tabs.length > 0) {
894
+ const index = this.derivedIndex
895
+ this.apply(index)
896
+ if (this.started) this.alignAddress(index)
897
+ }
898
+ return
899
+ }
900
+
901
+ const index = this.tabs.indexOf(this.chosenTab)
902
+ if (index < 0) {
903
+ /*
904
+ * The tab no longer exists. The server has sent something else, and
905
+ * then the server's markup applies.
906
+ *
907
+ * With one exception: the markup must hang together afterwards. When
908
+ * the patch removed the marked tab, the tab list is left without a
909
+ * single `aria-selected="true"`, every panel is hidden, and a click
910
+ * does nothing. The web component then selects what the server's
911
+ * markup says, the same way as when the user had not selected
912
+ * anything: `aria-selected`, then the first panel the server shows,
913
+ * then the first tab.
914
+ *
915
+ * The selection is announced with an event, because it was made by the
916
+ * web component and not by the user. Without the event an app that
917
+ * loads the panel's content or writes the selection to the address
918
+ * would never learn that it moved.
919
+ */
920
+ const lostPanel = this.panelFor(this.chosenTab)
921
+ this.chosenTab = undefined
922
+ // The server marked a tab itself. Then that applies, and the panels and
923
+ // the tab stop are written to match it, even when nothing else gave the
924
+ // observer another round.
925
+ if (this.markedIndex >= 0) {
926
+ const marked = this.derivedIndex
927
+ this.apply(marked)
928
+ this.alignAddress(marked)
929
+ return
930
+ }
931
+ if (this.tabs.length > 0) {
932
+ // The address says which tab the user was on, and is the only thing
933
+ // that survives the links being replaced. If it is the same panel as
934
+ // before, the selection has not changed, only the links, and then
935
+ // nothing is announced.
936
+ const fromAddress = this.addressIndex
937
+ const index = fromAddress >= 0 ? fromAddress : this.derivedIndex
938
+ const tab = this.tabs[index]
939
+ this.apply(index)
940
+ if (this.panelFor(tab) === lostPanel) {
941
+ this.chosenTab = tab
942
+ return
943
+ }
944
+ if (fromAddress >= 0) this.chosenTab = tab
945
+ this.showInAddress(index)
946
+ this.notify(index)
947
+ }
948
+ return
949
+ }
950
+
951
+ this.apply(index)
952
+ }
953
+
954
+ private bind(): void {
955
+ const tabs = this.tabs
956
+
957
+ if (tabs.length === 0) {
958
+ warnAboutMarkup(
959
+ this,
960
+ "found no tabs. The tab list needs a .lt-tabs__list with links " +
961
+ 'to the panels, such as <a href="#attachments">; without them a ' +
962
+ 'screen reader says "link" where it should say "tab, 2 of 3, ' +
963
+ 'selected", and the arrow keys do nothing.',
964
+ // An empty `<lt-tabs>` is a region the server has not filled yet,
965
+ // and that is not a mistake in the markup.
966
+ () => this.childElementCount > 0 && this.tabs.length === 0,
967
+ )
968
+ return
969
+ }
970
+
971
+ // Without the numbers in the message. If it interpolates a number, every
972
+ // round is a new message, and the warning comes again for every panel
973
+ // that appears instead of once.
974
+ warnAboutMarkup(
975
+ this,
976
+ "has tabs without a panel: a link points to an id that does not " +
977
+ "exist. Write an id on each .lt-tabs__panel, the same one the " +
978
+ "link points to, or the tabs without a panel can be selected " +
979
+ "without anything being shown.",
980
+ () => this.tabs.some((tab) => this.panelFor(tab) === null),
981
+ )
982
+
983
+ warnAboutMarkup(
984
+ this,
985
+ 'has a tab without href: role="tab" is on something that is not ' +
986
+ "a link to a panel. Tabs are links, such as <a " +
987
+ 'href="#attachments">, so they work without JavaScript, and the ' +
988
+ "component leaves anything that is not a link alone.",
989
+ () => this.nonLinkTabs().length > 0,
990
+ )
991
+
992
+ warnAboutMarkup(
993
+ this,
994
+ "has a tab list without a name. Write aria-label on " +
995
+ '.lt-tabs__list, such as aria-label="Parts of the case", or ' +
996
+ "aria-labelledby pointing to a heading; without a name a screen " +
997
+ 'reader only says "tab list".',
998
+ () => {
999
+ const list = this.list
1000
+ if (!list || this.tabs.length === 0) return false
1001
+ const label = list.getAttribute("aria-label")
1002
+ const labelledby = list.getAttribute("aria-labelledby")
1003
+ return (
1004
+ (label === null || flat(label) === "") &&
1005
+ (labelledby === null || !this.resolves(labelledby))
1006
+ )
1007
+ },
1008
+ )
1009
+ }
1010
+
1011
+ /** What the server has called a tab in the tab list, but is not a link to a panel. */
1012
+ private nonLinkTabs(): Element[] {
1013
+ const list = this.list
1014
+ if (!list) return []
1015
+ const tabs = new Set<Element>(this.tabs)
1016
+ return [...list.querySelectorAll(ANY_TAB_SELECTOR)].filter(
1017
+ (e) => e.closest(this.localName) === this && !tabs.has(e),
1018
+ )
1019
+ }
1020
+
1021
+ /**
1022
+ * The tab in this tab list the event came from, or -1.
1023
+ *
1024
+ * `indexOf` and not just `closest`: a tab list inside a panel bubbles its
1025
+ * clicks up here too, and they do not belong to this tab list.
1026
+ */
1027
+ private tabIndexOf(event: Event): number {
1028
+ const target = event.target
1029
+ if (!(target instanceof Element)) return -1
1030
+ const tab = target.closest("[role='tab']")
1031
+ return tab ? this.tabs.indexOf(tab as HTMLElement) : -1
1032
+ }
1033
+
1034
+ private handleClick = (event: MouseEvent): void => {
1035
+ const index = this.tabIndexOf(event)
1036
+ if (index < 0) return
1037
+ const tab = this.tabs[index]
1038
+ // With a modifier the browser opens the link somewhere else, and that is
1039
+ // the user's choice, not a tab selection.
1040
+ if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
1041
+ return
1042
+ }
1043
+ // Without this the page jumped to the panel.
1044
+ event.preventDefault()
1045
+ if (this.isDisabled(tab)) return
1046
+ this.select(index)
1047
+ }
1048
+
1049
+ /** Find in page or a link revealed a hidden panel. */
1050
+ private handleBeforematch = (event: Event): void => {
1051
+ // Also under `server-controlled`, like a click: the selection stands until
1052
+ // the server answers, and `tab-select` tells the app. Otherwise the web
1053
+ // component hid the match again in the next round.
1054
+ const panel = event.target
1055
+ const index = this.tabs.findIndex((tab) => this.panelFor(tab) === panel)
1056
+ if (index < 0 || !(panel instanceof Element)) return
1057
+ // The browser removes `hidden` on the panel itself, see `revealing`.
1058
+ this.revealing = panel
1059
+ try {
1060
+ this.select(index)
1061
+ } finally {
1062
+ // After an event from a script, the browser reveals nothing.
1063
+ if (event.isTrusted) setTimeout(() => this.revealed(panel), 0)
1064
+ else this.revealing = undefined
1065
+ }
1066
+ }
1067
+
1068
+ /**
1069
+ * Releases the panel after `beforematch`, in the task after the browser has
1070
+ * finished revealing, and writes the tab list.
1071
+ *
1072
+ * Usually the browser has removed `hidden` by then. It has not when the
1073
+ * panel was taken out of the document during the event, and without this
1074
+ * round the panel stayed hidden even though the tab was selected.
1075
+ */
1076
+ private revealed(panel: Element): void {
1077
+ if (this.revealing !== panel) return
1078
+ this.revealing = undefined
1079
+ if (this.isConnected) this.sync()
1080
+ }
1081
+
1082
+ private handleHashchange = (): void => {
1083
+ this.selectFromAddress()
1084
+ }
1085
+
1086
+ /**
1087
+ * The index of the tab the address points to, or -1: the panel itself, such
1088
+ * as `#attachments`, or something inside it, such as a heading in the panel.
1089
+ */
1090
+ private get addressIndex(): number {
1091
+ const hash = location.hash.slice(1)
1092
+ if (!hash) return -1
1093
+ const target = this.byFragment(hash)
1094
+ if (!target) return -1
1095
+ return this.tabs.findIndex((tab) => {
1096
+ const panel = this.panelFor(tab)
1097
+ return panel !== null && (panel === target || panel.contains(target))
1098
+ })
1099
+ }
1100
+
1101
+ /**
1102
+ * Corrects the address when it points to another tab in the tab list than
1103
+ * the selected one, as when the server has moved the selection. An address
1104
+ * to something outside the tab list stays.
1105
+ */
1106
+ private alignAddress(index: number): void {
1107
+ const pointsAt = this.addressIndex
1108
+ if (pointsAt >= 0 && pointsAt !== index) this.showInAddress(index)
1109
+ }
1110
+
1111
+ /**
1112
+ * Writes the tab to the address, so it can be shared, and so the selection
1113
+ * survives the server replacing the links.
1114
+ *
1115
+ * If the address already points to the selected panel or something in it,
1116
+ * it stays: a link into the content must not be lost. `replaceState`, so
1117
+ * the selection does not become an entry in the history.
1118
+ */
1119
+ private showInAddress(index: number): void {
1120
+ const tab = this.tabs[index]
1121
+ const panel = tab ? this.panelFor(tab) : null
1122
+ if (!tab || !panel) return
1123
+ if (this.addressIndex === index) return
1124
+ // Resolved against the page's address, not against `<base>`: with
1125
+ // `<base href="/">`, which Angular has, the path was replaced silently,
1126
+ // and with a `<base>` to another origin `replaceState` threw.
1127
+ const url = new URL(tab.getAttribute("href") ?? "", location.href).href
1128
+ try {
1129
+ history.replaceState(history.state, "", url)
1130
+ } catch {
1131
+ // Safari throws after a hundred calls in ten seconds. The address is an
1132
+ // extra, so the selection applies anyway.
1133
+ }
1134
+ }
1135
+
1136
+ /**
1137
+ * Selects the tab the address points to.
1138
+ *
1139
+ * On load, on `hashchange`, and when the server replaces the links without
1140
+ * saying which one is selected: the selection is then still in the
1141
+ * address. Not under `server-controlled`, where the server decides.
1142
+ */
1143
+ private selectFromAddress(): void {
1144
+ if (isServerControlled(this)) return
1145
+ const index = this.addressIndex
1146
+ if (index >= 0) this.select(index)
1147
+ }
1148
+
1149
+ private handleKeydown = (event: KeyboardEvent): void => {
1150
+ // Every keystroke in a field in a panel comes here. The cheap checks first.
1151
+ if (!(event.target instanceof Element)) return
1152
+ if (!event.target.closest("[role='tab']")) return
1153
+ const tabs = this.tabs
1154
+ const current = this.tabIndexOf(event)
1155
+ if (current < 0) return
1156
+ // Alt+Left is "back" in the browser, and Cmd+arrow moves through the
1157
+ // history on macOS. With a modifier the key is not for the tabs.
1158
+ if (event.altKey || event.ctrlKey || event.metaKey) return
1159
+
1160
+ // Space selects with manual activation. A link does nothing on Space by
1161
+ // itself, and Enter sends a click, which `handleClick` handles.
1162
+ if (this.manual && event.key === " ") {
1163
+ event.preventDefault()
1164
+ this.select(current)
1165
+ return
1166
+ }
1167
+
1168
+ // On a page read from right to left the next tab is to the left. Without
1169
+ // this the right arrow moved focus visually backwards.
1170
+ const rtl = getComputedStyle(this).direction === "rtl"
1171
+ // Up and down arrows stole page scrolling in a horizontal tab list and
1172
+ // departed from WAI-ARIA. They apply only when the tab list says it is
1173
+ // vertical.
1174
+ const vertical =
1175
+ tabs[current]
1176
+ .closest("[role='tablist']")
1177
+ ?.getAttribute("aria-orientation") === "vertical"
1178
+ const steps: Record<string, number> = vertical
1179
+ ? { ArrowDown: 1, ArrowUp: -1 }
1180
+ : { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1 }
1181
+
1182
+ let next: number | undefined
1183
+
1184
+ if (event.key in steps) {
1185
+ next = this.nextEnabled(current, steps[event.key])
1186
+ } else if (event.key === "Home") {
1187
+ next = this.nextEnabled(-1, 1)
1188
+ } else if (event.key === "End") {
1189
+ next = this.nextEnabled(tabs.length, -1)
1190
+ }
1191
+
1192
+ if (next === undefined) return
1193
+
1194
+ event.preventDefault()
1195
+ if (!this.manual) this.select(next)
1196
+ tabs[next].focus()
1197
+ }
1198
+
1199
+ /**
1200
+ * The next tab that can be selected, in one direction, wrapping round if
1201
+ * needed.
1202
+ *
1203
+ * A tab that cannot be selected is skipped. When a hidden tab was selected,
1204
+ * it got the tab stop, and Tab never reached the tab list. The keyboard
1205
+ * user was locked out.
1206
+ */
1207
+ private nextEnabled(from: number, step: number): number | undefined {
1208
+ const tabs = this.tabs
1209
+ for (let i = 1; i <= tabs.length; i++) {
1210
+ const index = (from + step * i + tabs.length * i) % tabs.length
1211
+ if (!this.isDisabled(tabs[index])) return index
1212
+ }
1213
+ return undefined
1214
+ }
1215
+
1216
+ /** Selects a tab and fires the event. */
1217
+ select(index: number): void {
1218
+ const tabs = this.tabs
1219
+ if (index < 0 || index >= tabs.length) return
1220
+ if (this.isDisabled(tabs[index])) return
1221
+ // `markedIndex` and not `selected`: the latter answers 0 also when nothing
1222
+ // is marked, and then the first tab could never be selected.
1223
+ if (index === this.markedIndex) return
1224
+
1225
+ // No memory when the server decides the selection. Without this a
1226
+ // selection made while the attribute was there would be restored the
1227
+ // moment someone removed it again.
1228
+ if (!isServerControlled(this)) this.chosenTab = tabs[index]
1229
+ this.apply(index)
1230
+ if (isServerControlled(this)) this.pendingTab = tabs[index]
1231
+ this.showInAddress(index)
1232
+ this.notify(index)
1233
+ }
1234
+
1235
+ /** Announces which tab is selected now. */
1236
+ private notify(index: number): void {
1237
+ this.dispatchEvent(
1238
+ new CustomEvent("tab-select", {
1239
+ detail: { index },
1240
+ bubbles: true,
1241
+ composed: true,
1242
+ }),
1243
+ )
1244
+ }
1245
+
1246
+ /**
1247
+ * Writes the selection out into the markup.
1248
+ *
1249
+ * Every write compares first. The web component observes the same
1250
+ * attributes it sets, so a write without a comparison would trigger the
1251
+ * observer, which would write again, forever.
1252
+ */
1253
+ private apply(index: number): void {
1254
+ const tabs = this.tabs
1255
+ /*
1256
+ * The tab stop is the selected tab, unless a patch has disabled or hidden
1257
+ * it. Then the next tab that can be selected gets it, or Tab skips past
1258
+ * the whole tab list.
1259
+ */
1260
+ const stop = this.isDisabled(tabs[index])
1261
+ ? (this.nextEnabled(index, 1) ?? index)
1262
+ : index
1263
+ /*
1264
+ * A panel is visible when any tab pointing to it is selected, and is
1265
+ * written once. When two tabs point to the same one, through a mistake in
1266
+ * the markup, they would otherwise write opposite `hidden` on it in every
1267
+ * round, and the page would freeze.
1268
+ */
1269
+ const panels = new Map<HTMLElement, boolean>()
1270
+
1271
+ tabs.forEach((tab, i) => {
1272
+ const chosen = i === index
1273
+ // The server's word is noted before the write, or the write was read as
1274
+ // the server's in the next round.
1275
+ const server = this.serverSelected(tab)
1276
+ setAttr(tab, "aria-selected", String(chosen))
1277
+ this.selectedMemory.set(tab, { written: String(chosen), server })
1278
+ setAttr(tab, "tabindex", i === stop ? "0" : "-1")
1279
+
1280
+ const panel = this.panelFor(tab)
1281
+ if (panel) panels.set(panel, (panels.get(panel) ?? false) || chosen)
1282
+ })
1283
+
1284
+ // The form is read from a panel the server hides before anything is
1285
+ // written, or a panel to be hidden first in the tab list was written in a
1286
+ // different form from the ones the server hides.
1287
+ for (const panel of panels.keys()) {
1288
+ const form = this.serverHidden(panel)
1289
+ if (form !== null) {
1290
+ this.hiddenForm = form
1291
+ break
1292
+ }
1293
+ }
1294
+
1295
+ for (const [panel, shown] of panels) {
1296
+ const server = this.serverHidden(panel)
1297
+ const written = shown ? null : this.hiddenForm
1298
+ if (panel !== this.revealing) {
1299
+ if (written === null) setFlag(panel, "hidden", false)
1300
+ else setAttr(panel, "hidden", written)
1301
+ this.hiddenMemory.set(panel, { written, server })
1302
+ }
1303
+ /*
1304
+ * Only the selected panel is a tab stop, so Tab from the tab list goes
1305
+ * straight into the content that was just shown. A panel with
1306
+ * `hidden="until-found"` keeps its box, so with `tabindex="0"` it was
1307
+ * an invisible stop for the keyboard. Another value the server wrote,
1308
+ * such as `-1`, stays.
1309
+ */
1310
+ const tabindex = panel.getAttribute("tabindex")
1311
+ if (shown && tabindex === null) setAttr(panel, "tabindex", "0")
1312
+ else if (!shown && tabindex === "0") setAttr(panel, "tabindex", null)
1313
+ }
1314
+ }
1315
+ }
1316
+
1317
+ export function defineLtTabs(tagName: string = LT_TABS_TAG): void {
1318
+ defineElement(tagName, LtTabs)
1319
+ }