tyrell-components 1.0.0-TC9 → 1.0.0-rc.21

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 (392) hide show
  1. package/AGENTS.md +122 -0
  2. package/CHANGELOG.md +1531 -0
  3. package/README.md +71 -53
  4. package/css/tyrell-colors-static.css +1 -0
  5. package/css/tyrell-theme.css +1 -0
  6. package/css/tyrell.css +1 -1783
  7. package/dist/tyrell-colors-static.css +1 -0
  8. package/dist/tyrell-theme.css +1 -0
  9. package/dist/tyrell.css +1 -1783
  10. package/dist/tyrell.js +1 -1
  11. package/guides/AGENT_INSTRUCTIONS.md +124 -0
  12. package/guides/AI_GUIDE.md +53 -0
  13. package/guides/CSS_GUIDE.md +1016 -0
  14. package/guides/DATASTAR_TY_GUIDE.md +657 -0
  15. package/guides/ICONS_GUIDE.md +212 -0
  16. package/guides/TY_GUIDE.md +935 -0
  17. package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
  18. package/guides/clj/CODE_SPLITTING.md +279 -0
  19. package/guides/clj/COMPONENT_GUIDE.md +391 -0
  20. package/guides/clj/HELIX_TY_GUIDE.md +428 -0
  21. package/guides/clj/I18N_GUIDE.md +478 -0
  22. package/guides/clj/LAYOUT_GUIDE.md +273 -0
  23. package/guides/clj/QUICKSTART.md +266 -0
  24. package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
  25. package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
  26. package/guides/clj/ROUTING_GUIDE.md +346 -0
  27. package/guides/clj/UIX_TY_GUIDE.md +319 -0
  28. package/guides/js/HTMX_TY_GUIDE.md +252 -0
  29. package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
  30. package/guides/js/REACT_TY_GUIDE.md +983 -0
  31. package/guides/js/SVELTE_TY_GUIDE.md +682 -0
  32. package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
  33. package/guides/js/VUE_TY_GUIDE.md +738 -0
  34. package/lib/base/ty-component.d.ts +57 -13
  35. package/lib/base/ty-component.js +266 -292
  36. package/lib/components/button.d.ts +33 -18
  37. package/lib/components/button.js +317 -267
  38. package/lib/components/calendar-month.d.ts +30 -47
  39. package/lib/components/calendar-month.js +455 -429
  40. package/lib/components/calendar-navigation.d.ts +41 -49
  41. package/lib/components/calendar-navigation.js +287 -346
  42. package/lib/components/calendar.d.ts +73 -83
  43. package/lib/components/calendar.js +837 -762
  44. package/lib/components/checkbox.d.ts +26 -75
  45. package/lib/components/checkbox.js +298 -391
  46. package/lib/components/copy.d.ts +20 -60
  47. package/lib/components/copy.js +276 -380
  48. package/lib/components/date-picker.d.ts +100 -183
  49. package/lib/components/date-picker.js +1155 -1570
  50. package/lib/components/file-upload.d.ts +16 -15
  51. package/lib/components/file-upload.js +436 -426
  52. package/lib/components/icon.d.ts +3 -24
  53. package/lib/components/icon.js +141 -230
  54. package/lib/components/input.d.ts +93 -108
  55. package/lib/components/input.js +734 -710
  56. package/lib/components/modal.d.ts +39 -29
  57. package/lib/components/modal.js +419 -438
  58. package/lib/components/option.d.ts +20 -35
  59. package/lib/components/option.js +184 -309
  60. package/lib/components/popup.d.ts +2 -17
  61. package/lib/components/popup.js +353 -347
  62. package/lib/components/radio.d.ts +33 -25
  63. package/lib/components/radio.js +433 -422
  64. package/lib/components/resize-observer.d.ts +3 -30
  65. package/lib/components/resize-observer.js +71 -103
  66. package/lib/components/scroll-container.d.ts +21 -14
  67. package/lib/components/scroll-container.js +292 -234
  68. package/lib/components/select.d.ts +446 -0
  69. package/lib/components/select.js +1381 -0
  70. package/lib/components/selected-tags.d.ts +60 -0
  71. package/lib/components/selected-tags.js +225 -0
  72. package/lib/components/sortable.d.ts +175 -0
  73. package/lib/components/sortable.js +1844 -0
  74. package/lib/components/step.d.ts +1 -6
  75. package/lib/components/step.js +62 -68
  76. package/lib/components/switch.d.ts +15 -15
  77. package/lib/components/switch.js +237 -231
  78. package/lib/components/tab.d.ts +50 -7
  79. package/lib/components/tab.js +203 -69
  80. package/lib/components/tabs.d.ts +19 -64
  81. package/lib/components/tabs.js +600 -618
  82. package/lib/components/tag.d.ts +14 -52
  83. package/lib/components/tag.js +231 -306
  84. package/lib/components/textarea.d.ts +58 -89
  85. package/lib/components/textarea.js +523 -573
  86. package/lib/components/tooltip.d.ts +8 -13
  87. package/lib/components/tooltip.js +322 -409
  88. package/lib/components/wizard.d.ts +7 -54
  89. package/lib/components/wizard.js +376 -606
  90. package/lib/icons/fontawesome/brands.d.ts +0 -1
  91. package/lib/icons/fontawesome/brands.js +0 -8
  92. package/lib/icons/fontawesome/regular.d.ts +0 -1
  93. package/lib/icons/fontawesome/regular.js +0 -8
  94. package/lib/icons/fontawesome/solid.d.ts +0 -1
  95. package/lib/icons/fontawesome/solid.js +0 -8
  96. package/lib/icons/heroicons/micro.d.ts +0 -1
  97. package/lib/icons/heroicons/micro.js +392 -400
  98. package/lib/icons/heroicons/mini.d.ts +0 -1
  99. package/lib/icons/heroicons/mini.js +382 -390
  100. package/lib/icons/heroicons/outline.d.ts +0 -1
  101. package/lib/icons/heroicons/outline.js +337 -345
  102. package/lib/icons/heroicons/solid.d.ts +0 -1
  103. package/lib/icons/heroicons/solid.js +407 -415
  104. package/lib/icons/lucide.d.ts +0 -1
  105. package/lib/icons/lucide.js +24479 -26351
  106. package/lib/icons/material/filled.d.ts +0 -1
  107. package/lib/icons/material/filled.js +9653 -9663
  108. package/lib/icons/material/outlined.d.ts +0 -1
  109. package/lib/icons/material/outlined.js +10271 -10281
  110. package/lib/icons/material/round.d.ts +0 -1
  111. package/lib/icons/material/round.js +10495 -10505
  112. package/lib/icons/material/sharp.d.ts +0 -1
  113. package/lib/icons/material/sharp.js +9905 -9915
  114. package/lib/icons/material/two-tone.d.ts +0 -1
  115. package/lib/icons/material/two-tone.js +12792 -12802
  116. package/lib/index.d.ts +7 -4
  117. package/lib/index.js +26 -39
  118. package/lib/styles/button.d.ts +24 -7
  119. package/lib/styles/button.js +285 -445
  120. package/lib/styles/calendar-month.d.ts +7 -6
  121. package/lib/styles/calendar-month.js +158 -226
  122. package/lib/styles/calendar-navigation.d.ts +2 -6
  123. package/lib/styles/calendar-navigation.js +108 -127
  124. package/lib/styles/calendar.d.ts +3 -3
  125. package/lib/styles/calendar.js +87 -23
  126. package/lib/styles/checkbox.d.ts +7 -6
  127. package/lib/styles/checkbox.js +101 -15
  128. package/lib/styles/copy.d.ts +3 -2
  129. package/lib/styles/copy.js +91 -71
  130. package/lib/styles/custom-scrollbar.d.ts +1 -2
  131. package/lib/styles/custom-scrollbar.js +80 -115
  132. package/lib/styles/date-picker.d.ts +4 -6
  133. package/lib/styles/date-picker.js +321 -388
  134. package/lib/styles/field-size.d.ts +6 -0
  135. package/lib/styles/field-size.js +91 -0
  136. package/lib/styles/file-upload.d.ts +1 -2
  137. package/lib/styles/file-upload.js +143 -188
  138. package/lib/styles/icon.d.ts +2 -6
  139. package/lib/styles/icon.js +92 -170
  140. package/lib/styles/input.d.ts +4 -7
  141. package/lib/styles/input.js +148 -643
  142. package/lib/styles/modal.d.ts +1 -2
  143. package/lib/styles/modal.js +127 -108
  144. package/lib/styles/option.d.ts +2 -6
  145. package/lib/styles/option.js +53 -96
  146. package/lib/styles/popup.d.ts +1 -2
  147. package/lib/styles/popup.js +47 -77
  148. package/lib/styles/radio.d.ts +3 -2
  149. package/lib/styles/radio.js +90 -116
  150. package/lib/styles/resize-observer.d.ts +1 -2
  151. package/lib/styles/resize-observer.js +2 -12
  152. package/lib/styles/scroll-container.d.ts +1 -2
  153. package/lib/styles/scroll-container.js +103 -146
  154. package/lib/styles/select-base.d.ts +8 -0
  155. package/lib/styles/select-base.js +747 -0
  156. package/lib/styles/select.d.ts +11 -0
  157. package/lib/styles/select.js +229 -0
  158. package/lib/styles/sortable.d.ts +16 -0
  159. package/lib/styles/sortable.js +85 -0
  160. package/lib/styles/step.d.ts +1 -2
  161. package/lib/styles/step.js +15 -34
  162. package/lib/styles/switch.d.ts +3 -2
  163. package/lib/styles/switch.js +52 -68
  164. package/lib/styles/tab.d.ts +1 -2
  165. package/lib/styles/tab.js +86 -34
  166. package/lib/styles/tabs.d.ts +3 -11
  167. package/lib/styles/tabs.js +204 -162
  168. package/lib/styles/tag.d.ts +2 -6
  169. package/lib/styles/tag.js +168 -362
  170. package/lib/styles/textarea.d.ts +1 -2
  171. package/lib/styles/textarea.js +238 -306
  172. package/lib/styles/tooltip.d.ts +4 -3
  173. package/lib/styles/tooltip.js +3 -131
  174. package/lib/styles/wizard.d.ts +8 -20
  175. package/lib/styles/wizard.js +306 -295
  176. package/lib/types/common.d.ts +9 -8
  177. package/lib/types/common.js +8 -5
  178. package/lib/utils/calendar-utils.d.ts +49 -65
  179. package/lib/utils/calendar-utils.js +158 -343
  180. package/lib/utils/custom-scrollbar.d.ts +6 -20
  181. package/lib/utils/custom-scrollbar.js +273 -317
  182. package/lib/utils/flavor-sheet.d.ts +31 -0
  183. package/lib/utils/flavor-sheet.js +17 -0
  184. package/lib/utils/icon-registry.d.ts +0 -15
  185. package/lib/utils/icon-registry.js +138 -279
  186. package/lib/utils/icons.d.ts +9 -0
  187. package/lib/utils/icons.js +1 -0
  188. package/lib/utils/loader-registry.d.ts +2 -3
  189. package/lib/utils/loader-registry.js +3 -35
  190. package/lib/utils/locale.d.ts +2 -80
  191. package/lib/utils/locale.js +30 -205
  192. package/lib/utils/mobile.d.ts +0 -1
  193. package/lib/utils/mobile.js +1 -18
  194. package/lib/utils/number-format.d.ts +6 -24
  195. package/lib/utils/number-format.js +53 -136
  196. package/lib/utils/positioning.d.ts +72 -22
  197. package/lib/utils/positioning.js +224 -298
  198. package/lib/utils/property-capture.d.ts +5 -27
  199. package/lib/utils/property-capture.js +36 -144
  200. package/lib/utils/property-manager.d.ts +6 -6
  201. package/lib/utils/property-manager.js +127 -196
  202. package/lib/utils/resize-observer.d.ts +0 -1
  203. package/lib/utils/resize-observer.js +23 -59
  204. package/lib/utils/scroll-lock.d.ts +10 -11
  205. package/lib/utils/scroll-lock.js +165 -173
  206. package/lib/utils/styles.d.ts +0 -6
  207. package/lib/utils/styles.js +17 -48
  208. package/lib/utils/upgrade-properties.d.ts +21 -0
  209. package/lib/utils/upgrade-properties.js +47 -0
  210. package/lib/utils/validity.d.ts +122 -0
  211. package/lib/utils/validity.js +289 -0
  212. package/lib/version.d.ts +1 -2
  213. package/lib/version.js +1 -11
  214. package/package.json +62 -18
  215. package/lib/base/ty-component.d.ts.map +0 -1
  216. package/lib/base/ty-component.js.map +0 -1
  217. package/lib/components/button.d.ts.map +0 -1
  218. package/lib/components/button.js.map +0 -1
  219. package/lib/components/calendar-month.d.ts.map +0 -1
  220. package/lib/components/calendar-month.js.map +0 -1
  221. package/lib/components/calendar-navigation.d.ts.map +0 -1
  222. package/lib/components/calendar-navigation.js.map +0 -1
  223. package/lib/components/calendar.d.ts.map +0 -1
  224. package/lib/components/calendar.js.map +0 -1
  225. package/lib/components/checkbox.d.ts.map +0 -1
  226. package/lib/components/checkbox.js.map +0 -1
  227. package/lib/components/copy.d.ts.map +0 -1
  228. package/lib/components/copy.js.map +0 -1
  229. package/lib/components/date-picker.d.ts.map +0 -1
  230. package/lib/components/date-picker.js.map +0 -1
  231. package/lib/components/dropdown.d.ts +0 -404
  232. package/lib/components/dropdown.d.ts.map +0 -1
  233. package/lib/components/dropdown.js +0 -1563
  234. package/lib/components/dropdown.js.map +0 -1
  235. package/lib/components/file-upload.d.ts.map +0 -1
  236. package/lib/components/file-upload.js.map +0 -1
  237. package/lib/components/icon.d.ts.map +0 -1
  238. package/lib/components/icon.js.map +0 -1
  239. package/lib/components/input.d.ts.map +0 -1
  240. package/lib/components/input.js.map +0 -1
  241. package/lib/components/modal.d.ts.map +0 -1
  242. package/lib/components/modal.js.map +0 -1
  243. package/lib/components/multiselect.d.ts +0 -408
  244. package/lib/components/multiselect.d.ts.map +0 -1
  245. package/lib/components/multiselect.js +0 -1611
  246. package/lib/components/multiselect.js.map +0 -1
  247. package/lib/components/option.d.ts.map +0 -1
  248. package/lib/components/option.js.map +0 -1
  249. package/lib/components/popup.d.ts.map +0 -1
  250. package/lib/components/popup.js.map +0 -1
  251. package/lib/components/radio.d.ts.map +0 -1
  252. package/lib/components/radio.js.map +0 -1
  253. package/lib/components/resize-observer.d.ts.map +0 -1
  254. package/lib/components/resize-observer.js.map +0 -1
  255. package/lib/components/scroll-container.d.ts.map +0 -1
  256. package/lib/components/scroll-container.js.map +0 -1
  257. package/lib/components/step.d.ts.map +0 -1
  258. package/lib/components/step.js.map +0 -1
  259. package/lib/components/switch.d.ts.map +0 -1
  260. package/lib/components/switch.js.map +0 -1
  261. package/lib/components/tab.d.ts.map +0 -1
  262. package/lib/components/tab.js.map +0 -1
  263. package/lib/components/tabs.d.ts.map +0 -1
  264. package/lib/components/tabs.js.map +0 -1
  265. package/lib/components/tag.d.ts.map +0 -1
  266. package/lib/components/tag.js.map +0 -1
  267. package/lib/components/textarea.d.ts.map +0 -1
  268. package/lib/components/textarea.js.map +0 -1
  269. package/lib/components/tooltip.d.ts.map +0 -1
  270. package/lib/components/tooltip.js.map +0 -1
  271. package/lib/components/wizard.d.ts.map +0 -1
  272. package/lib/components/wizard.js.map +0 -1
  273. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  274. package/lib/icons/fontawesome/brands.js.map +0 -1
  275. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  276. package/lib/icons/fontawesome/regular.js.map +0 -1
  277. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  278. package/lib/icons/fontawesome/solid.js.map +0 -1
  279. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  280. package/lib/icons/heroicons/micro.js.map +0 -1
  281. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  282. package/lib/icons/heroicons/mini.js.map +0 -1
  283. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  284. package/lib/icons/heroicons/outline.js.map +0 -1
  285. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  286. package/lib/icons/heroicons/solid.js.map +0 -1
  287. package/lib/icons/lucide.d.ts.map +0 -1
  288. package/lib/icons/lucide.js.map +0 -1
  289. package/lib/icons/material/filled.d.ts.map +0 -1
  290. package/lib/icons/material/filled.js.map +0 -1
  291. package/lib/icons/material/outlined.d.ts.map +0 -1
  292. package/lib/icons/material/outlined.js.map +0 -1
  293. package/lib/icons/material/round.d.ts.map +0 -1
  294. package/lib/icons/material/round.js.map +0 -1
  295. package/lib/icons/material/sharp.d.ts.map +0 -1
  296. package/lib/icons/material/sharp.js.map +0 -1
  297. package/lib/icons/material/two-tone.d.ts.map +0 -1
  298. package/lib/icons/material/two-tone.js.map +0 -1
  299. package/lib/index.d.ts.map +0 -1
  300. package/lib/index.js.map +0 -1
  301. package/lib/styles/button.d.ts.map +0 -1
  302. package/lib/styles/button.js.map +0 -1
  303. package/lib/styles/calendar-month.d.ts.map +0 -1
  304. package/lib/styles/calendar-month.js.map +0 -1
  305. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  306. package/lib/styles/calendar-navigation.js.map +0 -1
  307. package/lib/styles/calendar.d.ts.map +0 -1
  308. package/lib/styles/calendar.js.map +0 -1
  309. package/lib/styles/checkbox.d.ts.map +0 -1
  310. package/lib/styles/checkbox.js.map +0 -1
  311. package/lib/styles/copy.d.ts.map +0 -1
  312. package/lib/styles/copy.js.map +0 -1
  313. package/lib/styles/custom-scrollbar.d.ts.map +0 -1
  314. package/lib/styles/custom-scrollbar.js.map +0 -1
  315. package/lib/styles/date-picker.d.ts.map +0 -1
  316. package/lib/styles/date-picker.js.map +0 -1
  317. package/lib/styles/dropdown.d.ts +0 -12
  318. package/lib/styles/dropdown.d.ts.map +0 -1
  319. package/lib/styles/dropdown.js +0 -1048
  320. package/lib/styles/dropdown.js.map +0 -1
  321. package/lib/styles/file-upload.d.ts.map +0 -1
  322. package/lib/styles/file-upload.js.map +0 -1
  323. package/lib/styles/icon.d.ts.map +0 -1
  324. package/lib/styles/icon.js.map +0 -1
  325. package/lib/styles/input.d.ts.map +0 -1
  326. package/lib/styles/input.js.map +0 -1
  327. package/lib/styles/modal.d.ts.map +0 -1
  328. package/lib/styles/modal.js.map +0 -1
  329. package/lib/styles/multiselect.d.ts +0 -6
  330. package/lib/styles/multiselect.d.ts.map +0 -1
  331. package/lib/styles/multiselect.js +0 -837
  332. package/lib/styles/multiselect.js.map +0 -1
  333. package/lib/styles/option.d.ts.map +0 -1
  334. package/lib/styles/option.js.map +0 -1
  335. package/lib/styles/popup.d.ts.map +0 -1
  336. package/lib/styles/popup.js.map +0 -1
  337. package/lib/styles/radio.d.ts.map +0 -1
  338. package/lib/styles/radio.js.map +0 -1
  339. package/lib/styles/resize-observer.d.ts.map +0 -1
  340. package/lib/styles/resize-observer.js.map +0 -1
  341. package/lib/styles/scroll-container.d.ts.map +0 -1
  342. package/lib/styles/scroll-container.js.map +0 -1
  343. package/lib/styles/step.d.ts.map +0 -1
  344. package/lib/styles/step.js.map +0 -1
  345. package/lib/styles/switch.d.ts.map +0 -1
  346. package/lib/styles/switch.js.map +0 -1
  347. package/lib/styles/tab.d.ts.map +0 -1
  348. package/lib/styles/tab.js.map +0 -1
  349. package/lib/styles/tabs.d.ts.map +0 -1
  350. package/lib/styles/tabs.js.map +0 -1
  351. package/lib/styles/tag.d.ts.map +0 -1
  352. package/lib/styles/tag.js.map +0 -1
  353. package/lib/styles/textarea.d.ts.map +0 -1
  354. package/lib/styles/textarea.js.map +0 -1
  355. package/lib/styles/tooltip.d.ts.map +0 -1
  356. package/lib/styles/tooltip.js.map +0 -1
  357. package/lib/styles/wizard.d.ts.map +0 -1
  358. package/lib/styles/wizard.js.map +0 -1
  359. package/lib/types/common.d.ts.map +0 -1
  360. package/lib/types/common.js.map +0 -1
  361. package/lib/utils/calendar-utils.d.ts.map +0 -1
  362. package/lib/utils/calendar-utils.js.map +0 -1
  363. package/lib/utils/custom-scrollbar.d.ts.map +0 -1
  364. package/lib/utils/custom-scrollbar.js.map +0 -1
  365. package/lib/utils/icon-registry.d.ts.map +0 -1
  366. package/lib/utils/icon-registry.js.map +0 -1
  367. package/lib/utils/loader-registry.d.ts.map +0 -1
  368. package/lib/utils/loader-registry.js.map +0 -1
  369. package/lib/utils/locale.d.ts.map +0 -1
  370. package/lib/utils/locale.js.map +0 -1
  371. package/lib/utils/mobile.d.ts.map +0 -1
  372. package/lib/utils/mobile.js.map +0 -1
  373. package/lib/utils/number-format.d.ts.map +0 -1
  374. package/lib/utils/number-format.js.map +0 -1
  375. package/lib/utils/parse-boolean.d.ts +0 -39
  376. package/lib/utils/parse-boolean.d.ts.map +0 -1
  377. package/lib/utils/parse-boolean.js +0 -58
  378. package/lib/utils/parse-boolean.js.map +0 -1
  379. package/lib/utils/positioning.d.ts.map +0 -1
  380. package/lib/utils/positioning.js.map +0 -1
  381. package/lib/utils/property-capture.d.ts.map +0 -1
  382. package/lib/utils/property-capture.js.map +0 -1
  383. package/lib/utils/property-manager.d.ts.map +0 -1
  384. package/lib/utils/property-manager.js.map +0 -1
  385. package/lib/utils/resize-observer.d.ts.map +0 -1
  386. package/lib/utils/resize-observer.js.map +0 -1
  387. package/lib/utils/scroll-lock.d.ts.map +0 -1
  388. package/lib/utils/scroll-lock.js.map +0 -1
  389. package/lib/utils/styles.d.ts.map +0 -1
  390. package/lib/utils/styles.js.map +0 -1
  391. package/lib/version.d.ts.map +0 -1
  392. package/lib/version.js.map +0 -1
@@ -1,653 +1,635 @@
1
- /**
2
- * Tabs Component
3
- *
4
- * A carousel-based tabs component with smooth animations and fixed container dimensions.
5
- * Features horizontal sliding transitions, smart positioning marker, and independent panel scrolling.
6
- *
7
- * Features:
8
- * - Carousel animation with smooth sliding transitions
9
- * - Fixed dimensions prevent layout shift between tabs
10
- * - Animated marker that follows active tab button
11
- * - Rich label support via slots (icons, badges, custom content)
12
- * - Custom marker slot for complete active tab styling control
13
- * - Independent panel scrolling with scroll position reset
14
- * - ResizeObserver for responsive percentage widths
15
- * - Smart rendering - only updates DOM when necessary
16
- * - Accessibility with ARIA roles and attributes
17
- * - Top/bottom placement for tab buttons
18
- *
19
- * @example
20
- * <!-- Basic tabs with text labels -->
21
- * <ty-tabs width="800px" height="600px" active="general">
22
- * <ty-tab id="general" label="General Settings">
23
- * <div class="p-6">General content...</div>
24
- * </ty-tab>
25
- * <ty-tab id="advanced" label="Advanced Settings">
26
- * <div class="p-6">Advanced content...</div>
27
- * </ty-tab>
28
- * </ty-tabs>
29
- *
30
- * @example
31
- * <!-- Rich labels with icons and badges -->
32
- * <ty-tabs width="800px" height="600px">
33
- * <!-- Rich label as direct child -->
34
- * <span slot="label-profile" class="flex items-center gap-2">
35
- * <ty-icon name="user" size="sm"></ty-icon>
36
- * Profile
37
- * </span>
38
- *
39
- * <span slot="label-notifications" class="flex items-center gap-2">
40
- * <ty-icon name="bell" size="sm"></ty-icon>
41
- * Notifications
42
- * <span class="ty-bg-danger ty-text-danger++ px-2 py-0.5 rounded-full text-xs">5</span>
43
- * </span>
44
- *
45
- * <!-- Tab panels -->
46
- * <ty-tab id="profile">...</ty-tab>
47
- * <ty-tab id="notifications">...</ty-tab>
48
- * </ty-tabs>
49
- *
50
- * @example
51
- * <!-- Custom marker styling -->
52
- * <ty-tabs width="100%" height="400px">
53
- * <!-- Gradient marker slot -->
54
- * <div slot="marker" style="
55
- * background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
56
- * border-radius: 0.5rem;
57
- * box-shadow: 0 2px 8px rgba(0,0,0,0.15);
58
- * "></div>
59
- *
60
- * <ty-tab id="tab1" label="Dashboard">...</ty-tab>
61
- * <ty-tab id="tab2" label="Analytics">...</ty-tab>
62
- * </ty-tabs>
63
- */
64
1
  import { ensureStyles } from '../utils/styles.js';
65
2
  import { tabsStyles } from '../styles/tabs.js';
66
- // ============================================================================
67
- // WeakMaps for State Management
68
- // ============================================================================
69
3
  const eventHandlers = new WeakMap();
70
4
  const resizeObservers = new WeakMap();
71
- // ============================================================================
72
- // Helper Functions - Attribute Parsing
73
- // ============================================================================
74
- /**
75
- * Extract tabs configuration from element attributes
76
- */
5
+ const shownTabs = new WeakMap();
6
+ const instanceSheets = new WeakMap();
7
+ const pendingInitialSnap = new WeakMap();
8
+ let userInputs = 0;
9
+ const countInput = () => { userInputs++; };
10
+ addEventListener('pointerdown', countInput, { capture: true, passive: true });
11
+ addEventListener('keydown', countInput, { capture: true, passive: true });
12
+ const awaitedTabs = new WeakMap();
13
+ let snapCount = 0;
77
14
  function getTabsAttributes(el) {
78
- return {
79
- width: el.getAttribute('width') || '100%',
80
- height: el.getAttribute('height') || '400px',
81
- active: el.getAttribute('active'),
82
- placement: (el.getAttribute('placement') || 'top'),
83
- };
84
- }
85
- /**
86
- * Get all ty-tab child elements
87
- */
15
+ return {
16
+ placement: (el.getAttribute('placement') || 'top'),
17
+ fixed: el.hasAttribute('fixed'),
18
+ };
19
+ }
88
20
  function getChildTabs(el) {
89
- return Array.from(el.querySelectorAll('ty-tab'));
21
+ return Array.from(el.querySelectorAll(':scope > ty-tab'));
90
22
  }
91
- /**
92
- * Get ID from a ty-tab element
93
- */
94
23
  function getTabId(tab) {
95
- return tab.getAttribute('id');
24
+ return tab.getAttribute('id');
25
+ }
26
+ function getSlotLabel(tabsEl, tabId) {
27
+ return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
96
28
  }
97
- /**
98
- * Check if ty-tabs has a direct child label slot for this tab-id.
99
- * Looks in ty-tabs' light DOM for slot='label-{tab-id}' elements.
100
- */
101
29
  function hasSlotLabel(tabsEl, tabId) {
102
- return tabsEl.querySelector(`[slot='label-${tabId}']`) !== null;
30
+ return getSlotLabel(tabsEl, tabId) !== null;
103
31
  }
104
- /**
105
- * Determine label type: 'slot' (rich content) or 'text' (simple attribute).
106
- * Checks ty-tabs element for slot='label-{tab-id}' direct children.
107
- */
108
32
  function getTabLabelType(tabsEl, tab) {
109
- const tabId = getTabId(tab);
110
- if (tabId && hasSlotLabel(tabsEl, tabId)) {
111
- return 'slot';
112
- }
113
- return 'text';
114
- }
115
- /**
116
- * Check if tab is disabled
117
- */
33
+ const tabId = getTabId(tab);
34
+ if (tabId && hasSlotLabel(tabsEl, tabId)) {
35
+ return 'slot';
36
+ }
37
+ return 'text';
38
+ }
118
39
  function isTabDisabled(tab) {
119
- return tab.hasAttribute('disabled');
40
+ return tab.hasAttribute('disabled');
120
41
  }
121
- /**
122
- * Check if user provided custom marker content via slot
123
- */
124
42
  function hasCustomMarker(el) {
125
- return el.querySelector('[slot="marker"]') !== null;
126
- }
127
- // ============================================================================
128
- // Helper Functions - Active Tab Management
129
- // ============================================================================
130
- /**
131
- * Find index of tab with given ID
132
- */
43
+ return el.querySelector(':scope > [slot="marker"]') !== null;
44
+ }
133
45
  function findTabIndex(tabs, tabId) {
134
- const index = tabs.findIndex(tab => getTabId(tab) === tabId);
135
- return index >= 0 ? index : undefined;
46
+ const index = tabs.findIndex(tab => getTabId(tab) === tabId);
47
+ return index >= 0 ? index : undefined;
48
+ }
49
+ function currentActive(el) {
50
+ return shownTabs.get(el) ?? null;
136
51
  }
137
- /**
138
- * Get the active tab ID, defaulting to first tab if not specified
139
- */
140
52
  function getActiveTabId(el, tabs) {
141
- const activeAttr = el.getAttribute('active');
142
- if (activeAttr && findTabIndex(tabs, activeAttr) !== undefined) {
143
- return activeAttr;
144
- }
145
- // Default to first tab
146
- if (tabs.length > 0) {
147
- return getTabId(tabs[0]);
148
- }
149
- return null;
150
- }
151
- /**
152
- * Set the active tab by ID
153
- */
154
- function setActiveTab(el, tabId) {
155
- el.setAttribute('active', tabId);
156
- }
157
- /**
158
- * Dispatch ty-tab-change event
159
- */
53
+ const ids = tabs.map(getTabId).filter((id) => !!id);
54
+ const activeAttr = el.getAttribute('active');
55
+ if (activeAttr && ids.includes(activeAttr))
56
+ return activeAttr;
57
+ const shown = shownTabs.get(el);
58
+ if (shown && ids.includes(shown))
59
+ return shown;
60
+ return ids[0] ?? null;
61
+ }
62
+ function activateTab(el, tabId) {
63
+ el.setAttribute('active', tabId);
64
+ syncShownTab(el, true);
65
+ }
160
66
  function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
161
- const event = new CustomEvent('ty-tab-change', {
162
- detail: {
163
- activeId,
164
- activeIndex,
165
- previousId,
166
- previousIndex,
167
- },
168
- bubbles: true,
169
- cancelable: false,
170
- });
171
- el.dispatchEvent(event);
172
- }
173
- // ============================================================================
174
- // Event Handlers - Tab Button Click
175
- // ============================================================================
176
- /**
177
- * Handle tab button click
178
- */
67
+ const event = new CustomEvent('ty-tab-change', {
68
+ detail: {
69
+ activeId,
70
+ activeIndex,
71
+ previousId,
72
+ previousIndex,
73
+ },
74
+ bubbles: true,
75
+ cancelable: false,
76
+ });
77
+ el.dispatchEvent(event);
78
+ }
179
79
  function handleTabClick(el, tabId, event) {
180
- event.preventDefault();
181
- event.stopPropagation();
182
- // Set the active attribute (which will trigger state update)
183
- setActiveTab(el, tabId);
184
- }
185
- /**
186
- * Cleanup existing event listeners
187
- */
80
+ event.preventDefault();
81
+ event.stopPropagation();
82
+ activateTab(el, tabId);
83
+ }
188
84
  function cleanupEventListeners(el) {
189
- const handlers = eventHandlers.get(el);
190
- if (!handlers)
191
- return;
192
- const shadowRoot = el.shadowRoot;
193
- if (!shadowRoot)
194
- return;
195
- // Remove all tab click handlers
196
- handlers.tabClickHandlers.forEach((handler, tabId) => {
197
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
198
- if (button) {
199
- button.removeEventListener('pointerdown', handler);
200
- }
201
- });
202
- handlers.tabClickHandlers.clear();
203
- }
204
- /**
205
- * Setup event listeners for tab button clicks
206
- */
85
+ const handlers = eventHandlers.get(el);
86
+ if (!handlers)
87
+ return;
88
+ const shadowRoot = el.shadowRoot;
89
+ if (!shadowRoot)
90
+ return;
91
+ handlers.tabClickHandlers.forEach((handler, tabId) => {
92
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
93
+ if (button) {
94
+ button.removeEventListener('click', handler);
95
+ }
96
+ });
97
+ handlers.tabKeydownHandlers.forEach((handler, tabId) => {
98
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
99
+ if (button) {
100
+ button.removeEventListener('keydown', handler);
101
+ }
102
+ });
103
+ handlers.tabClickHandlers.clear();
104
+ handlers.tabKeydownHandlers.clear();
105
+ }
106
+ function handleTabKeydown(el, shadowRoot, tabId, e) {
107
+ if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key))
108
+ return;
109
+ const ids = Array.from(shadowRoot.querySelectorAll('.tab-buttons [data-tab-id]:not([disabled])')).map((b) => b.getAttribute('data-tab-id'));
110
+ const i = ids.indexOf(tabId);
111
+ if (i < 0 || ids.length === 0)
112
+ return;
113
+ e.preventDefault();
114
+ const next = e.key === 'Home' ? ids[0]
115
+ : e.key === 'End' ? ids[ids.length - 1]
116
+ : e.key === 'ArrowRight' ? ids[(i + 1) % ids.length]
117
+ : ids[(i - 1 + ids.length) % ids.length];
118
+ if (next === tabId)
119
+ return;
120
+ handleTabClick(el, next, e);
121
+ requestAnimationFrame(() => {
122
+ shadowRoot.querySelector(`.tab-buttons [data-tab-id='${next}']`)?.focus();
123
+ });
124
+ }
207
125
  function setupEventListeners(el, shadowRoot, tabs) {
208
- // Clean up any existing listeners first
209
- cleanupEventListeners(el);
210
- // Initialize handlers storage
211
- const handlers = {
212
- tabClickHandlers: new Map(),
213
- };
214
- // Add click listener for each tab button
215
- tabs.forEach((tab) => {
216
- const tabId = getTabId(tab);
217
- if (!tabId)
218
- return;
219
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
220
- if (button) {
221
- const handler = (e) => handleTabClick(el, tabId, e);
222
- button.addEventListener('pointerdown', handler);
223
- handlers.tabClickHandlers.set(tabId, handler);
224
- }
225
- });
226
- // Store handlers for cleanup
227
- eventHandlers.set(el, handlers);
228
- }
229
- // ============================================================================
230
- // Transform & Positioning Updates
231
- // ============================================================================
232
- /**
233
- * Update the transform on panels-wrapper based on active index and measured width
234
- */
126
+ cleanupEventListeners(el);
127
+ const handlers = {
128
+ tabClickHandlers: new Map(),
129
+ tabKeydownHandlers: new Map(),
130
+ };
131
+ tabs.forEach((tab) => {
132
+ const tabId = getTabId(tab);
133
+ if (!tabId)
134
+ return;
135
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
136
+ if (button) {
137
+ const handler = (e) => handleTabClick(el, tabId, e);
138
+ const keydownHandler = (e) => handleTabKeydown(el, shadowRoot, tabId, e);
139
+ button.addEventListener('click', handler);
140
+ button.addEventListener('keydown', keydownHandler);
141
+ handlers.tabClickHandlers.set(tabId, handler);
142
+ handlers.tabKeydownHandlers.set(tabId, keydownHandler);
143
+ }
144
+ });
145
+ eventHandlers.set(el, handlers);
146
+ }
147
+ function carouselTransform(activeIndex) {
148
+ return `translateX(${activeIndex * -100}%)`;
149
+ }
150
+ function snapNextChange(container) {
151
+ if (!container)
152
+ return;
153
+ const token = String(++snapCount);
154
+ container.setAttribute('data-snap', token);
155
+ requestAnimationFrame(() => requestAnimationFrame(() => {
156
+ if (container.getAttribute('data-snap') === token)
157
+ container.removeAttribute('data-snap');
158
+ }));
159
+ }
235
160
  function updateTransform(el, activeIndex) {
236
- const shadowRoot = el.shadowRoot;
237
- if (!shadowRoot)
238
- return;
239
- const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
240
- if (!panelsWrapper)
241
- return;
242
- // Measure the actual width of the container
243
- const containerWidth = el.offsetWidth;
244
- const offsetPx = activeIndex * containerWidth;
245
- // Apply transform directly in pixels
246
- panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
247
- }
248
- /**
249
- * Update ARIA attributes on tab buttons without re-rendering
250
- */
161
+ const panelsWrapper = el.shadowRoot?.querySelector('.panels-wrapper');
162
+ if (panelsWrapper)
163
+ panelsWrapper.style.transform = carouselTransform(activeIndex);
164
+ }
165
+ function setAttr(node, name, value) {
166
+ if (node.getAttribute(name) !== value)
167
+ node.setAttribute(name, value);
168
+ }
169
+ function syncInstanceSheet(el, shownId) {
170
+ const shadowRoot = el.shadowRoot;
171
+ if (!shadowRoot)
172
+ return;
173
+ let sheet = instanceSheets.get(el);
174
+ if (!sheet) {
175
+ sheet = new CSSStyleSheet();
176
+ sheet.replaceSync(':host {} ::slotted(ty-tab) {}');
177
+ const hide = sheet.cssRules[1].style;
178
+ hide.setProperty('opacity', '0', 'important');
179
+ hide.setProperty('visibility', 'hidden', 'important');
180
+ hide.setProperty('pointer-events', 'none', 'important');
181
+ shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, sheet];
182
+ instanceSheets.set(el, sheet);
183
+ }
184
+ const host = sheet.cssRules[0].style;
185
+ for (const prop of ['width', 'height']) {
186
+ const value = el.getAttribute(prop);
187
+ if (value)
188
+ host.setProperty(prop, value, 'important');
189
+ else
190
+ host.removeProperty(prop);
191
+ }
192
+ sheet.cssRules[1].selectorText = shownId
193
+ ? `::slotted(ty-tab:not(#${CSS.escape(shownId)}))`
194
+ : '::slotted(ty-tab)';
195
+ }
251
196
  function updateAriaAttributes(el, shadowRoot, activeId) {
252
- const tabs = getChildTabs(el);
253
- tabs.forEach((tab, idx) => {
254
- const tabId = getTabId(tab);
255
- if (!tabId)
256
- return;
257
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
258
- const isActive = tabId === activeId;
259
- if (button) {
260
- button.setAttribute('aria-selected', String(isActive));
261
- button.setAttribute('tabindex', isActive ? '0' : '-1');
262
- // Add data-active attribute for styling slotted content
263
- button.setAttribute('data-active', String(isActive));
264
- // Also set data-active on the slotted label element in light DOM
265
- const slottedLabel = el.querySelector(`[slot='label-${tabId}']`);
266
- if (slottedLabel) {
267
- slottedLabel.setAttribute('data-active', String(isActive));
268
- }
269
- }
270
- });
271
- }
272
- /**
273
- * Update pointer-events, opacity, and data-active on tab panels without re-rendering
274
- */
197
+ const tabs = getChildTabs(el);
198
+ tabs.forEach((tab, idx) => {
199
+ const tabId = getTabId(tab);
200
+ if (!tabId)
201
+ return;
202
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
203
+ const isActive = tabId === activeId;
204
+ if (button) {
205
+ button.setAttribute('aria-selected', String(isActive));
206
+ button.setAttribute('tabindex', isActive ? '0' : '-1');
207
+ button.setAttribute('data-active', String(isActive));
208
+ const slottedLabel = getSlotLabel(el, tabId);
209
+ if (slottedLabel) {
210
+ setAttr(slottedLabel, 'data-active', String(isActive));
211
+ }
212
+ }
213
+ });
214
+ }
275
215
  function updatePanelInteraction(el, activeId) {
276
- const tabs = getChildTabs(el);
277
- tabs.forEach((tab) => {
278
- const tabId = getTabId(tab);
279
- if (!tabId)
280
- return;
281
- const isActive = tabId === activeId;
282
- // Set data-active attribute for framework conditional rendering
283
- tab.setAttribute('data-active', String(isActive));
284
- if (isActive) {
285
- tab.style.pointerEvents = 'auto';
286
- tab.style.opacity = '1';
287
- }
288
- else {
289
- tab.style.pointerEvents = 'none';
290
- tab.style.opacity = '0';
291
- }
292
- });
293
- }
294
- /**
295
- * Calculate marker position and dimensions based on active tab button.
296
- * Returns position object with left, top, width, height in pixels, or null if button not found.
297
- */
216
+ syncInstanceSheet(el, activeId);
217
+ getChildTabs(el).forEach((tab) => {
218
+ const tabId = getTabId(tab);
219
+ tab.setShown?.(!!tabId && tabId === activeId);
220
+ if (!tabId)
221
+ return;
222
+ setAttr(tab, 'data-active', String(tabId === activeId));
223
+ });
224
+ }
298
225
  function calculateMarkerPosition(el, shadowRoot, activeId) {
299
- const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
300
- const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
301
- if (!button || !buttonsContainer)
302
- return null;
303
- const buttonRect = button.getBoundingClientRect();
304
- // Use offset properties for position relative to container (accounts for padding)
305
- const left = button.offsetLeft;
306
- const top = button.offsetTop;
307
- return {
308
- left,
309
- top,
310
- width: buttonRect.width,
311
- height: buttonRect.height,
312
- };
313
- }
314
- /**
315
- * Update marker wrapper position and dimensions to match active tab button
316
- */
317
- function updateMarker(el, activeId) {
318
- const shadowRoot = el.shadowRoot;
319
- if (!shadowRoot)
320
- return;
321
- const marker = shadowRoot.querySelector('.marker-wrapper');
322
- if (!marker)
323
- return;
324
- const position = calculateMarkerPosition(el, shadowRoot, activeId);
325
- if (!position)
326
- return;
327
- marker.style.left = `${position.left}px`;
328
- marker.style.top = `${position.top}px`;
329
- marker.style.width = `${position.width}px`;
330
- marker.style.height = `${position.height}px`;
331
- }
332
- /**
333
- * Update only the active tab state without re-rendering DOM.
334
- * Called from `attributeChangedCallback` when the `active` attribute changes.
335
- *
336
- * `previousId` MUST be the value the attribute held *before* it was changed —
337
- * never call `getActiveTabId(el, ...)` here, because the attribute has already
338
- * been updated to `tabId` by the time this runs. Reading it back would always
339
- * yield the new value, making the change-detection guard below trip on every
340
- * click and silently suppress `ty-tab-change` dispatch.
341
- */
342
- function updateActiveTabState(el, tabId, previousId) {
343
- const tabs = getChildTabs(el);
344
- const shadowRoot = el.shadowRoot;
345
- if (!shadowRoot)
346
- return;
347
- const currentIndex = previousId ? findTabIndex(tabs, previousId) : undefined;
348
- const newIndex = findTabIndex(tabs, tabId);
349
- // Only update if different tab and valid
350
- if (previousId === tabId || newIndex === undefined)
351
- return;
352
- // Update CSS variable for transform
353
- el.style.setProperty('--active-index', String(newIndex));
354
- // Update transform directly
355
- updateTransform(el, newIndex);
356
- // Update ARIA attributes on buttons
357
- updateAriaAttributes(el, shadowRoot, tabId);
358
- // Update pointer-events on panels
359
- updatePanelInteraction(el, tabId);
360
- // Update marker position to match new active tab
361
- updateMarker(el, tabId);
362
- // Reset scroll position of new active panel
363
- const newPanel = tabs[newIndex];
364
- if (newPanel?.resetScroll) {
365
- newPanel.resetScroll();
366
- }
367
- // Dispatch change event
368
- dispatchTabChangeEvent(el, tabId, newIndex, previousId, currentIndex ?? null);
369
- }
370
- // ============================================================================
371
- // ResizeObserver for Responsive Width
372
- // ============================================================================
373
- /**
374
- * Setup ResizeObserver for percentage widths and marker updates
375
- */
226
+ const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
227
+ const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
228
+ if (!button || !buttonsContainer)
229
+ return null;
230
+ const left = button.offsetLeft;
231
+ const top = button.offsetTop;
232
+ const width = button.offsetWidth;
233
+ const height = button.offsetHeight;
234
+ return { left, top, width, height };
235
+ }
236
+ function updateMarker(el, activeId, forceSnap = false) {
237
+ const shadowRoot = el.shadowRoot;
238
+ if (!shadowRoot)
239
+ return;
240
+ const marker = shadowRoot.querySelector('.marker-wrapper');
241
+ if (!marker)
242
+ return;
243
+ const position = calculateMarkerPosition(el, shadowRoot, activeId);
244
+ if (!position)
245
+ return;
246
+ const snap = forceSnap || !marker.style.left || marker.offsetWidth === 0;
247
+ if (snap)
248
+ marker.style.transition = 'none';
249
+ marker.style.left = `${position.left}px`;
250
+ marker.style.top = `${position.top}px`;
251
+ marker.style.width = `${position.width}px`;
252
+ marker.style.height = `${position.height}px`;
253
+ if (snap) {
254
+ marker.getBoundingClientRect();
255
+ marker.style.transition = '';
256
+ }
257
+ }
258
+ function syncShownTab(el, user = false) {
259
+ const shadowRoot = el.shadowRoot;
260
+ if (!shadowRoot)
261
+ return;
262
+ const tabs = getChildTabs(el);
263
+ const previousId = shownTabs.get(el) ?? null;
264
+ const tabId = getActiveTabId(el, tabs);
265
+ const newIndex = (tabId ? findTabIndex(tabs, tabId) : undefined) ?? 0;
266
+ const container = shadowRoot.querySelector('.tabs-container');
267
+ if (tabId === previousId) {
268
+ const wrapper = shadowRoot.querySelector('.panels-wrapper');
269
+ if (wrapper && wrapper.style.transform !== carouselTransform(newIndex)) {
270
+ snapNextChange(container);
271
+ wrapper.style.transform = carouselTransform(newIndex);
272
+ }
273
+ return;
274
+ }
275
+ shownTabs.set(el, tabId);
276
+ const initial = previousId === null;
277
+ const arrived = !user && tabId !== null && awaitedTabs.get(el) === tabId;
278
+ awaitedTabs.delete(el);
279
+ const requested = el.getAttribute('active');
280
+ if (initial && requested && requested !== tabId)
281
+ awaitedTabs.set(el, requested);
282
+ const snap = !user && (initial || arrived || pendingInitialSnap.get(el) === userInputs);
283
+ if (initial)
284
+ pendingInitialSnap.set(el, userInputs);
285
+ else if (!arrived)
286
+ pendingInitialSnap.delete(el);
287
+ if (snap)
288
+ snapNextChange(container);
289
+ updateTransform(el, newIndex);
290
+ updateAriaAttributes(el, shadowRoot, tabId || '');
291
+ updatePanelInteraction(el, tabId);
292
+ if (!tabId || initial)
293
+ return;
294
+ updateMarker(el, tabId, snap);
295
+ scrollActiveIntoView(el, tabId, !snap);
296
+ shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
297
+ item.setAttribute('data-active', String(item.dataset.tabId === tabId));
298
+ });
299
+ tabs[newIndex]?.resetScroll?.();
300
+ if (arrived)
301
+ return;
302
+ const previousIndex = findTabIndex(tabs, previousId);
303
+ dispatchTabChangeEvent(el, tabId, newIndex, previousIndex === undefined ? null : previousId, previousIndex ?? null);
304
+ tabs[newIndex]?._requestLoad?.(newIndex);
305
+ }
376
306
  function setupResizeObserver(el) {
377
- // Clean up old observer
378
- const oldObserver = resizeObservers.get(el);
379
- if (oldObserver) {
380
- oldObserver.disconnect();
381
- }
382
- const { width } = getTabsAttributes(el);
383
- // Only setup observer for percentage widths
384
- if (width.includes('%')) {
385
- const observer = new ResizeObserver((entries) => {
386
- const entry = entries[0];
387
- const measuredWidth = entry.contentRect.width;
388
- const tabs = getChildTabs(el);
389
- const activeId = getActiveTabId(el, tabs);
390
- const activeIndex = activeId ? findTabIndex(tabs, activeId) : 0;
391
- // Update CSS variable with measured width
392
- el.style.setProperty('--tabs-width', `${measuredWidth}px`);
393
- // Update transform with new width
394
- if (activeIndex !== undefined) {
395
- updateTransform(el, activeIndex);
396
- }
397
- // Update marker position (tab button positions may have changed)
398
- if (activeId) {
399
- updateMarker(el, activeId);
400
- }
401
- });
402
- observer.observe(el);
403
- resizeObservers.set(el, observer);
404
- }
405
- }
406
- /**
407
- * Cleanup ResizeObserver
408
- */
307
+ const oldObserver = resizeObservers.get(el);
308
+ if (oldObserver) {
309
+ oldObserver.disconnect();
310
+ }
311
+ const observer = new ResizeObserver(() => {
312
+ const activeId = currentActive(el);
313
+ updateOverflow(el);
314
+ if (activeId) {
315
+ updateMarker(el, activeId);
316
+ scrollActiveIntoView(el, activeId, false);
317
+ }
318
+ });
319
+ observer.observe(el);
320
+ resizeObservers.set(el, observer);
321
+ }
409
322
  function cleanupResizeObserver(el) {
410
- const observer = resizeObservers.get(el);
411
- if (observer) {
412
- observer.disconnect();
413
- resizeObservers.delete(el);
414
- }
415
- }
416
- // ============================================================================
417
- // Rendering Functions
418
- // ============================================================================
419
- /**
420
- * Generate HTML for tab buttons using slots for rich labels.
421
- * Slots are looked up as direct children of tabs-el with slot='label-{tab-id}'.
422
- * Also renders marker wrapper with optional default underline (only if no custom marker).
423
- */
323
+ const observer = resizeObservers.get(el);
324
+ if (observer) {
325
+ observer.disconnect();
326
+ resizeObservers.delete(el);
327
+ }
328
+ }
424
329
  function renderTabButtons(tabsEl, tabs, activeId) {
425
- const buttons = tabs.map((tab) => {
426
- const tabId = getTabId(tab);
427
- if (!tabId)
428
- return '';
429
- const labelType = getTabLabelType(tabsEl, tab);
430
- const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
431
- const disabled = isTabDisabled(tab);
432
- const active = tabId === activeId;
433
- return `<button
434
- class="tab-button"
435
- role="tab"
436
- data-tab-id="${tabId}"
437
- id="tab-${tabId}"
438
- aria-controls="panel-${tabId}"
439
- aria-selected="${active}"
440
- tabindex="${active ? '0' : '-1'}"
441
- data-active="${active}"
442
- ${disabled ? 'disabled aria-disabled="true"' : ''}
443
- >
444
- ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : textLabel}
445
- </button>`;
446
- }).join('');
447
- return `
448
- <div class="tab-buttons" role="tablist" part="buttons-container">
449
- <div class="marker-wrapper" part="marker-wrapper">
450
- ${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
451
- <slot name="marker"></slot>
452
- </div>
453
- ${buttons}
454
- </div>
455
- `;
456
- }
457
- /**
458
- * Generate HTML for ONLY the button elements (no marker wrapper).
459
- * Used during smart updates to preserve the marker wrapper.
460
- */
330
+ const buttons = tabs.map((tab) => {
331
+ const tabId = getTabId(tab);
332
+ if (!tabId)
333
+ return '';
334
+ const labelType = getTabLabelType(tabsEl, tab);
335
+ const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
336
+ const disabled = isTabDisabled(tab);
337
+ const active = tabId === activeId;
338
+ return `<button
339
+ class="tab-button"
340
+ role="tab"
341
+ data-tab-id="${tabId}"
342
+ id="tab-${tabId}"
343
+ aria-selected="${active}"
344
+ tabindex="${active ? '0' : '-1'}"
345
+ data-active="${active}"
346
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
347
+ >
348
+ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
349
+ </button>`;
350
+ }).join('');
351
+ return `
352
+ <div class="tab-buttons" part="buttons-container">
353
+ <div class="tab-strip" role="tablist" part="strip">
354
+ <div class="marker-wrapper" part="marker-wrapper">
355
+ ${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
356
+ <slot name="marker"></slot>
357
+ </div>
358
+ ${buttons}
359
+ </div>
360
+ </div>
361
+ `;
362
+ }
461
363
  function renderButtonsOnly(tabsEl, tabs, activeId) {
462
- return tabs.map((tab) => {
463
- const tabId = getTabId(tab);
464
- if (!tabId)
465
- return '';
466
- const labelType = getTabLabelType(tabsEl, tab);
467
- const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
468
- const disabled = isTabDisabled(tab);
469
- const active = tabId === activeId;
470
- return `<button
471
- class="tab-button"
472
- role="tab"
473
- data-tab-id="${tabId}"
474
- id="tab-${tabId}"
475
- aria-controls="panel-${tabId}"
476
- aria-selected="${active}"
477
- tabindex="${active ? '0' : '-1'}"
478
- data-active="${active}"
479
- ${disabled ? 'disabled aria-disabled="true"' : ''}
480
- >
481
- ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : textLabel}
482
- </button>`;
483
- }).join('');
484
- }
485
- /**
486
- * Render the tabs container with buttons and panel viewport.
487
- * Smart rendering: checks if structure exists and only updates when needed.
488
- */
364
+ return tabs.map((tab) => {
365
+ const tabId = getTabId(tab);
366
+ if (!tabId)
367
+ return '';
368
+ const labelType = getTabLabelType(tabsEl, tab);
369
+ const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
370
+ const disabled = isTabDisabled(tab);
371
+ const active = tabId === activeId;
372
+ return `<button
373
+ class="tab-button"
374
+ role="tab"
375
+ data-tab-id="${tabId}"
376
+ id="tab-${tabId}"
377
+ aria-selected="${active}"
378
+ tabindex="${active ? '0' : '-1'}"
379
+ data-active="${active}"
380
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
381
+ >
382
+ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
383
+ </button>`;
384
+ }).join('');
385
+ }
386
+ function getTabMenuLabel(tabsEl, tab) {
387
+ const tabId = getTabId(tab);
388
+ if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
389
+ const slotted = getSlotLabel(tabsEl, tabId);
390
+ return slotted?.textContent?.trim() || tabId;
391
+ }
392
+ return tab.getAttribute('label') || 'Tab';
393
+ }
394
+ function removeOverflowMenu(shadowRoot) {
395
+ shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
396
+ }
397
+ function renderOverflowMenu(el, container, allTabs) {
398
+ const activeId = getActiveTabId(el, allTabs);
399
+ const trigger = document.createElement('button');
400
+ trigger.className = 'tab-overflow-trigger';
401
+ trigger.type = 'button';
402
+ trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
403
+ trigger.textContent = '⋯';
404
+ const popup = document.createElement('ty-popup');
405
+ popup.setAttribute('placement', 'bottom');
406
+ const menu = document.createElement('div');
407
+ menu.className = 'tab-overflow-menu';
408
+ menu.setAttribute('role', 'menu');
409
+ allTabs.forEach((tab) => {
410
+ const tabId = getTabId(tab);
411
+ if (!tabId)
412
+ return;
413
+ const item = document.createElement('button');
414
+ item.type = 'button';
415
+ item.className = 'tab-overflow-item';
416
+ item.setAttribute('role', 'menuitem');
417
+ item.setAttribute('data-tab-id', tabId);
418
+ item.setAttribute('data-active', String(tabId === activeId));
419
+ item.textContent = getTabMenuLabel(el, tab);
420
+ if (isTabDisabled(tab)) {
421
+ item.disabled = true;
422
+ }
423
+ else {
424
+ item.addEventListener('click', () => {
425
+ activateTab(el, tabId);
426
+ popup.closePopup?.();
427
+ });
428
+ }
429
+ menu.appendChild(item);
430
+ });
431
+ popup.appendChild(menu);
432
+ trigger.appendChild(popup);
433
+ container.appendChild(trigger);
434
+ }
435
+ function updateOverflow(el) {
436
+ const shadowRoot = el.shadowRoot;
437
+ if (!shadowRoot)
438
+ return;
439
+ const container = shadowRoot.querySelector('.tab-buttons');
440
+ const strip = shadowRoot.querySelector('.tab-strip');
441
+ if (!container || !strip)
442
+ return;
443
+ if (getTabsAttributes(el).fixed) {
444
+ removeOverflowMenu(shadowRoot);
445
+ strip.classList.add('unclipped');
446
+ strip.style.removeProperty('--fade-left');
447
+ strip.style.removeProperty('--fade-right');
448
+ return;
449
+ }
450
+ const savedScrollLeft = strip.scrollLeft;
451
+ removeOverflowMenu(shadowRoot);
452
+ if (strip.clientWidth <= 0)
453
+ return;
454
+ const buttons = strip.querySelectorAll('.tab-button');
455
+ const last = buttons[buttons.length - 1];
456
+ const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
457
+ const stripWidth = strip.clientWidth;
458
+ const hidden = contentWidth - stripWidth;
459
+ strip.classList.toggle('unclipped', hidden <= 1);
460
+ if (hidden <= 1) {
461
+ strip.scrollLeft = savedScrollLeft;
462
+ updateEdgeFades(strip);
463
+ return;
464
+ }
465
+ renderOverflowMenu(el, container, getChildTabs(el));
466
+ const triggerCost = container.clientWidth - strip.clientWidth;
467
+ if (hidden <= triggerCost) {
468
+ removeOverflowMenu(shadowRoot);
469
+ }
470
+ strip.scrollLeft = savedScrollLeft;
471
+ updateEdgeFades(strip);
472
+ }
473
+ function updateEdgeFades(strip) {
474
+ const maxScroll = strip.scrollWidth - strip.clientWidth;
475
+ const fade = (distance) => `${distance > 1 ? Math.min(28, distance) : 0}px`;
476
+ strip.style.setProperty('--fade-left', fade(strip.scrollLeft));
477
+ strip.style.setProperty('--fade-right', fade(maxScroll - strip.scrollLeft));
478
+ }
479
+ function scrollActiveIntoView(el, activeId, smooth) {
480
+ const shadowRoot = el.shadowRoot;
481
+ if (!shadowRoot)
482
+ return;
483
+ const strip = shadowRoot.querySelector('.tab-strip');
484
+ const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
485
+ if (!strip || !button || strip.clientWidth <= 0)
486
+ return;
487
+ const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
488
+ const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
489
+ if (Math.round(target) !== Math.round(strip.scrollLeft)) {
490
+ const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
491
+ strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
492
+ }
493
+ }
489
494
  function render(el) {
490
- const shadowRoot = el.shadowRoot;
491
- if (!shadowRoot)
492
- return;
493
- const { width, height, placement } = getTabsAttributes(el);
494
- const tabs = getChildTabs(el);
495
- const activeId = getActiveTabId(el, tabs);
496
- const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
497
- // Check if structure already exists
498
- const existingContainer = shadowRoot.querySelector('.tabs-container');
499
- const existingButtons = shadowRoot.querySelector('.tab-buttons');
500
- const existingViewport = shadowRoot.querySelector('.panels-viewport');
501
- // Ensure styles are loaded
502
- ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
503
- // Dev warning for too many tabs
504
- if (tabs.length > 7) {
505
- console.warn(`[ty-tabs] More than 7 tabs detected (${tabs.length} tabs). ` +
506
- 'This may cause overflow and poor UX. ' +
507
- 'Consider using sidebar navigation, accordion menu, or other patterns.');
508
- }
509
- // Set CSS variables for dimensions
510
- el.style.setProperty('--tabs-width', width.includes('%') ? '100%' : width);
511
- el.style.setProperty('--tabs-height', height);
512
- el.style.setProperty('--active-index', String(activeIndex));
513
- if (existingContainer && existingButtons && existingViewport) {
514
- // === SMART UPDATE: Structure exists, only update what changed ===
515
- // Update placement if changed
516
- existingContainer.setAttribute('data-placement', placement);
517
- // SMART UPDATE: Preserve marker wrapper, only update buttons
518
- const allButtons = existingButtons.querySelectorAll('.tab-button');
519
- allButtons.forEach(button => button.remove());
520
- // Generate and append new buttons after the marker wrapper
521
- const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
522
- const tempDiv = document.createElement('div');
523
- tempDiv.innerHTML = buttonsHtml;
524
- Array.from(tempDiv.children).forEach(button => {
525
- existingButtons.appendChild(button);
526
- });
527
- // Re-setup event listeners (buttons were recreated)
528
- setupEventListeners(el, shadowRoot, tabs);
529
- // Update ARIA and data-active attributes on initial render
530
- updateAriaAttributes(el, shadowRoot, activeId || '');
531
- // Measure button height and update marker after update
532
- requestAnimationFrame(() => {
533
- const buttons = shadowRoot.querySelector('.tab-buttons');
534
- if (buttons) {
535
- const buttonsHeight = buttons.offsetHeight;
536
- el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
537
- }
538
- // Update transform with current active index
539
- updateTransform(el, activeIndex);
540
- // Update marker position to match active tab
541
- if (activeId) {
542
- updateMarker(el, activeId);
543
- }
544
- });
545
- // Update panel interaction states
546
- if (activeId) {
547
- updatePanelInteraction(el, activeId);
548
- }
549
- }
550
- else {
551
- // === FULL RENDER: First time or structure missing ===
552
- shadowRoot.innerHTML = `
553
- <div class="tabs-container" data-placement="${placement}">
554
- ${renderTabButtons(el, tabs, activeId)}
555
- <div class="panels-viewport" part="panels-container">
556
- <div class="panels-wrapper">
557
- <slot></slot>
558
- </div>
559
- </div>
560
- </div>
561
- `;
562
- // Measure button height, update transform and marker after render
563
- requestAnimationFrame(() => {
564
- const buttons = shadowRoot.querySelector('.tab-buttons');
565
- if (buttons) {
566
- const buttonsHeight = buttons.offsetHeight;
567
- el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
568
- }
569
- // Update transform with measured width
570
- updateTransform(el, activeIndex);
571
- // Update marker position to match active tab
572
- if (activeId) {
573
- updateMarker(el, activeId);
574
- }
575
- });
576
- // Setup event listeners
577
- setupEventListeners(el, shadowRoot, tabs);
578
- // Update ARIA and data-active attributes on initial render
579
- updateAriaAttributes(el, shadowRoot, activeId || '');
580
- // Setup ResizeObserver for responsive width
581
- setupResizeObserver(el);
582
- // Update tab panel states
583
- if (activeId) {
584
- updatePanelInteraction(el, activeId);
585
- }
586
- // Listen for marker slot changes to hide default marker
587
- const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
588
- if (markerSlot) {
589
- const updateDefaultMarkerVisibility = () => {
590
- const defaultMarker = shadowRoot.querySelector('.default-marker');
591
- if (defaultMarker) {
592
- const hasCustom = markerSlot.assignedElements().length > 0;
593
- defaultMarker.style.display = hasCustom ? 'none' : '';
594
- }
595
- };
596
- markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
597
- // Check immediately in case content is already slotted
598
- updateDefaultMarkerVisibility();
599
- }
600
- }
601
- }
602
- /**
603
- * Cleanup when tabs component is disconnected
604
- */
495
+ const shadowRoot = el.shadowRoot;
496
+ if (!shadowRoot)
497
+ return;
498
+ const { placement, fixed } = getTabsAttributes(el);
499
+ const tabs = getChildTabs(el);
500
+ const activeId = getActiveTabId(el, tabs);
501
+ const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
502
+ tabs.forEach((tab) => tab.setPanelLabel?.(getTabMenuLabel(el, tab)));
503
+ const existingContainer = shadowRoot.querySelector('.tabs-container');
504
+ const existingButtons = shadowRoot.querySelector('.tab-buttons');
505
+ const existingStrip = shadowRoot.querySelector('.tab-strip');
506
+ const existingViewport = shadowRoot.querySelector('.panels-viewport');
507
+ ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
508
+ if (existingContainer && existingButtons && existingStrip && existingViewport) {
509
+ existingContainer.setAttribute('data-placement', placement);
510
+ existingContainer.toggleAttribute('data-fixed', fixed);
511
+ const savedScrollLeft = existingStrip.scrollLeft;
512
+ existingButtons.querySelector('.tab-overflow-trigger')?.remove();
513
+ const allButtons = existingStrip.querySelectorAll('.tab-button');
514
+ allButtons.forEach(button => button.remove());
515
+ const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
516
+ const tempDiv = document.createElement('div');
517
+ tempDiv.innerHTML = buttonsHtml;
518
+ Array.from(tempDiv.children).forEach(button => {
519
+ existingStrip.appendChild(button);
520
+ });
521
+ existingStrip.scrollLeft = savedScrollLeft;
522
+ setupEventListeners(el, shadowRoot, tabs);
523
+ updateAriaAttributes(el, shadowRoot, activeId || '');
524
+ const firstShow = !shownTabs.get(el);
525
+ requestAnimationFrame(() => {
526
+ const currentId = currentActive(el);
527
+ updateOverflow(el);
528
+ if (currentId) {
529
+ updateMarker(el, currentId, firstShow);
530
+ scrollActiveIntoView(el, currentId, !firstShow);
531
+ }
532
+ });
533
+ updatePanelInteraction(el, activeId);
534
+ }
535
+ else {
536
+ shadowRoot.innerHTML = `
537
+ <div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
538
+ ${renderTabButtons(el, tabs, activeId)}
539
+ <div class="panels-viewport" part="panels-container">
540
+ <div class="panels-wrapper" style="transform: ${carouselTransform(activeIndex)}">
541
+ <slot></slot>
542
+ </div>
543
+ </div>
544
+ </div>
545
+ `;
546
+ requestAnimationFrame(() => {
547
+ const currentId = currentActive(el);
548
+ updateOverflow(el);
549
+ if (currentId) {
550
+ updateMarker(el, currentId);
551
+ scrollActiveIntoView(el, currentId, false);
552
+ }
553
+ });
554
+ setupEventListeners(el, shadowRoot, tabs);
555
+ updateAriaAttributes(el, shadowRoot, activeId || '');
556
+ const strip = shadowRoot.querySelector('.tab-strip');
557
+ strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
558
+ updatePanelInteraction(el, activeId);
559
+ const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
560
+ if (markerSlot) {
561
+ const updateDefaultMarkerVisibility = () => {
562
+ const defaultMarker = shadowRoot.querySelector('.default-marker');
563
+ if (defaultMarker) {
564
+ const hasCustom = markerSlot.assignedElements().length > 0;
565
+ defaultMarker.style.display = hasCustom ? 'none' : '';
566
+ }
567
+ };
568
+ markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
569
+ updateDefaultMarkerVisibility();
570
+ }
571
+ }
572
+ }
605
573
  function cleanup(el) {
606
- cleanupEventListeners(el);
607
- cleanupResizeObserver(el);
608
- }
609
- // ============================================================================
610
- // Component Definition
611
- // ============================================================================
612
- /**
613
- * TyTabs Web Component
614
- */
574
+ cleanupEventListeners(el);
575
+ cleanupResizeObserver(el);
576
+ }
615
577
  export class TyTabs extends HTMLElement {
616
- /** Observed attributes */
617
- static get observedAttributes() {
618
- return ['width', 'height', 'active', 'placement'];
619
- }
620
- constructor() {
621
- super();
622
- this.attachShadow({ mode: 'open' });
623
- }
624
- connectedCallback() {
625
- render(this);
626
- }
627
- disconnectedCallback() {
628
- cleanup(this);
629
- }
630
- attributeChangedCallback(name, oldValue, newValue) {
631
- // Smart rendering: only full render when structural attributes change
632
- if (name === 'active') {
633
- // Active tab changed - update state, then do smart render
634
- if (newValue) {
635
- // Pass `oldValue` explicitly so the change-detection inside
636
- // `updateActiveTabState` compares against the previous value
637
- // rather than re-reading the (already updated) attribute.
638
- updateActiveTabState(this, newValue, oldValue);
639
- }
640
- // Always call render after active change to update button states
641
- render(this);
642
- }
643
- else {
644
- // Other attributes changed (width, height, placement) - full render
645
- render(this);
646
- }
647
- }
648
- }
649
- // Register the custom element
578
+ static get observedAttributes() {
579
+ return ['width', 'height', 'active', 'placement', 'fixed'];
580
+ }
581
+ constructor() {
582
+ super();
583
+ this._childObserver = null;
584
+ this._updateQueued = false;
585
+ this._structureDirty = false;
586
+ this.attachShadow({ mode: 'open' });
587
+ }
588
+ get activeTab() {
589
+ return shownTabs.get(this) ?? null;
590
+ }
591
+ connectedCallback() {
592
+ render(this);
593
+ syncShownTab(this);
594
+ setupResizeObserver(this);
595
+ this._childObserver = new MutationObserver(() => this._queueUpdate(true));
596
+ this._childObserver.observe(this, { childList: true });
597
+ }
598
+ disconnectedCallback() {
599
+ this._childObserver?.disconnect();
600
+ this._childObserver = null;
601
+ cleanup(this);
602
+ }
603
+ _queueUpdate(structure) {
604
+ this._structureDirty || (this._structureDirty = structure);
605
+ if (this._updateQueued)
606
+ return;
607
+ this._updateQueued = true;
608
+ queueMicrotask(() => {
609
+ this._updateQueued = false;
610
+ if (!this.isConnected)
611
+ return;
612
+ if (this._childObserver?.takeRecords().length)
613
+ this._structureDirty = true;
614
+ if (this._structureDirty) {
615
+ this._structureDirty = false;
616
+ render(this);
617
+ }
618
+ syncShownTab(this);
619
+ });
620
+ }
621
+ attributeChangedCallback(name, oldValue, newValue) {
622
+ if (!this.isConnected)
623
+ return;
624
+ if (name === 'active') {
625
+ if (oldValue !== newValue)
626
+ awaitedTabs.delete(this);
627
+ this._queueUpdate(false);
628
+ }
629
+ else
630
+ render(this);
631
+ }
632
+ }
650
633
  if (!customElements.get('ty-tabs')) {
651
- customElements.define('ty-tabs', TyTabs);
634
+ customElements.define('ty-tabs', TyTabs);
652
635
  }
653
- //# sourceMappingURL=tabs.js.map