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