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,636 +1,406 @@
1
- /**
2
- * Wizard Component
3
- *
4
- * A carousel-based wizard/stepper component with smooth animations, progress tracking, and completion state.
5
- * Features horizontal sliding transitions between steps, animated progress line, and step completion tracking.
6
- * Behaves like tabs - a "dumb" component that only renders and fires events. All navigation and validation
7
- * is controlled by the user.
8
- *
9
- * Features:
10
- * - Carousel animation with smooth sliding transitions between steps
11
- * - Fixed dimensions prevent layout shift between steps
12
- * - Animated progress line showing completion status
13
- * - Step indicators with completed/active/pending states
14
- * - Rich indicator support via slots (icons, custom content)
15
- * - Independent panel scrolling with scroll position reset
16
- * - ResizeObserver for responsive percentage widths
17
- * - Smart rendering - only updates DOM when necessary
18
- * - Accessibility with ARIA roles and attributes
19
- * - Fires events on step clicks - user controls navigation
20
- *
21
- * @example
22
- * <!-- Basic wizard with text labels -->
23
- * <ty-wizard width="900px" height="600px" active="welcome">
24
- * <ty-step id="welcome" label="Welcome">
25
- * <div class="p-6">
26
- * <h1>Welcome!</h1>
27
- * <button onclick="goToStep('account')">Next</button>
28
- * </div>
29
- * </ty-step>
30
- * <ty-step id="account" label="Account Setup">
31
- * <div class="p-6">
32
- * <h2>Account Setup</h2>
33
- * <button onclick="goToStep('welcome')">Previous</button>
34
- * <button onclick="goToStep('complete')">Next</button>
35
- * </div>
36
- * </ty-step>
37
- * </ty-wizard>
38
- *
39
- * @example
40
- * <!-- Wizard with custom indicators -->
41
- * <ty-wizard width="100%" height="700px" active="welcome" completed="welcome,account">
42
- * <!-- Custom indicator icons -->
43
- * <div slot="indicator-welcome">
44
- * <ty-icon name="hand" size="sm"></ty-icon>
45
- * </div>
46
- * <div slot="indicator-account">
47
- * <span class="text-lg font-bold">1</span>
48
- * </div>
49
- *
50
- * <ty-step id="welcome" label="Welcome">...</ty-step>
51
- * <ty-step id="account" label="Account">...</ty-step>
52
- * <ty-step id="profile" label="Profile">...</ty-step>
53
- * </ty-wizard>
54
- */
55
1
  import { ensureStyles } from '../utils/styles.js';
56
2
  import { wizardStyles } from '../styles/wizard.js';
57
- // ============================================================================
58
- // WeakMaps for State Management
59
- // ============================================================================
60
3
  const eventHandlers = new WeakMap();
61
- const resizeObservers = new WeakMap();
62
- // ============================================================================
63
- // Helper Functions - Attribute Parsing
64
- // ============================================================================
65
- /**
66
- * Extract wizard configuration from element attributes
67
- */
68
4
  function getWizardAttributes(el) {
69
- return {
70
- width: el.getAttribute('width') || '100%',
71
- height: el.getAttribute('height') || '700px',
72
- active: el.getAttribute('active'),
73
- completed: el.getAttribute('completed') || '',
74
- orientation: (el.getAttribute('orientation') || 'horizontal'),
75
- };
76
- }
77
- /**
78
- * Get all ty-step child elements
79
- */
5
+ return {
6
+ width: el.getAttribute('width') || '100%',
7
+ height: el.getAttribute('height') || '',
8
+ active: el.getAttribute('active'),
9
+ completed: el.getAttribute('completed') || '',
10
+ orientation: (el.getAttribute('orientation') || 'horizontal'),
11
+ };
12
+ }
80
13
  function getChildSteps(el) {
81
- return Array.from(el.querySelectorAll('ty-step'));
14
+ return Array.from(el.querySelectorAll('ty-step'));
82
15
  }
83
- /**
84
- * Get ID from a ty-step element
85
- */
86
16
  function getStepId(step) {
87
- return step.getAttribute('id');
17
+ return step.getAttribute('id');
88
18
  }
89
- /**
90
- * Get completed step IDs as a Set
91
- */
92
19
  function getCompletedStepIds(el) {
93
- const completedAttr = el.getAttribute('completed') || '';
94
- if (!completedAttr.trim())
95
- return new Set();
96
- return new Set(completedAttr.split(',').map(id => id.trim()).filter(Boolean));
97
- }
98
- /**
99
- * Check if wizard has a direct child indicator slot for this step-id.
100
- * Looks in ty-wizard's light DOM for slot='indicator-{step-id}' elements.
101
- */
20
+ const completedAttr = el.getAttribute('completed') || '';
21
+ if (!completedAttr.trim())
22
+ return new Set();
23
+ return new Set(completedAttr.split(',').map(id => id.trim()).filter(Boolean));
24
+ }
102
25
  function hasCustomIndicator(wizardEl, stepId) {
103
- return wizardEl.querySelector(`[slot='indicator-${stepId}']`) !== null;
26
+ return wizardEl.querySelector(`[slot='indicator-${stepId}']`) !== null;
104
27
  }
105
- /**
106
- * Check if step is disabled
107
- */
108
28
  function isStepDisabled(step) {
109
- return step.hasAttribute('disabled');
110
- }
111
- // ============================================================================
112
- // Helper Functions - Active Step Management
113
- // ============================================================================
114
- /**
115
- * Find index of step with given ID
116
- */
29
+ return step.hasAttribute('disabled');
30
+ }
117
31
  function findStepIndex(steps, stepId) {
118
- const index = steps.findIndex(step => getStepId(step) === stepId);
119
- return index >= 0 ? index : undefined;
32
+ const index = steps.findIndex(step => getStepId(step) === stepId);
33
+ return index >= 0 ? index : undefined;
120
34
  }
121
- /**
122
- * Get the active step ID, defaulting to first step if not specified
123
- */
124
35
  function getActiveStepId(el, steps) {
125
- const activeAttr = el.getAttribute('active');
126
- if (activeAttr && findStepIndex(steps, activeAttr) !== undefined) {
127
- return activeAttr;
128
- }
129
- // Default to first step
130
- if (steps.length > 0) {
131
- return getStepId(steps[0]);
132
- }
133
- return null;
134
- }
135
- /**
136
- * Set the active step by ID
137
- */
36
+ const activeAttr = el.getAttribute('active');
37
+ if (activeAttr && findStepIndex(steps, activeAttr) !== undefined) {
38
+ return activeAttr;
39
+ }
40
+ if (steps.length > 0) {
41
+ return getStepId(steps[0]);
42
+ }
43
+ return null;
44
+ }
138
45
  function setActiveStep(el, stepId) {
139
- el.setAttribute('active', stepId);
140
- }
141
- /**
142
- * Calculate progress percentage for the progress line overlay
143
- */
144
- function calculateProgressPercent(steps, activeId, completedIds) {
145
- if (steps.length <= 1 || !activeId)
146
- return 0;
147
- const activeIndex = steps.findIndex(s => getStepId(s) === activeId);
148
- // Progress bar shows progress up to the currently active step
149
- return (activeIndex / (steps.length - 1)) * 100;
150
- }
151
- /**
152
- * Dispatch ty-wizard-step-change event
153
- */
46
+ el.setAttribute('active', stepId);
47
+ }
154
48
  function dispatchStepChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
155
- const direction = previousIndex === null ? 'none'
156
- : activeIndex > previousIndex ? 'forward'
157
- : activeIndex < previousIndex ? 'backward'
158
- : 'none';
159
- const event = new CustomEvent('ty-wizard-step-change', {
160
- detail: {
161
- activeId,
162
- activeIndex,
163
- previousId,
164
- previousIndex,
165
- direction,
166
- },
167
- bubbles: true,
168
- cancelable: false,
169
- });
170
- el.dispatchEvent(event);
171
- }
172
- // ============================================================================
173
- // Event Handlers - Step Indicator Click
174
- // ============================================================================
175
- /**
176
- * Handle step indicator click - only dispatch event (like tabs)
177
- */
49
+ const direction = previousIndex === null ? 'none'
50
+ : activeIndex > previousIndex ? 'forward'
51
+ : activeIndex < previousIndex ? 'backward'
52
+ : 'none';
53
+ const event = new CustomEvent('ty-wizard-step-change', {
54
+ detail: {
55
+ activeId,
56
+ activeIndex,
57
+ previousId,
58
+ previousIndex,
59
+ direction,
60
+ },
61
+ bubbles: true,
62
+ cancelable: false,
63
+ });
64
+ el.dispatchEvent(event);
65
+ }
178
66
  function handleStepClick(el, stepId, event) {
179
- event.preventDefault();
180
- event.stopPropagation();
181
- const steps = getChildSteps(el);
182
- const targetIndex = steps.findIndex(s => getStepId(s) === stepId);
183
- if (targetIndex < 0)
184
- return;
185
- const currentActive = getActiveStepId(el, steps);
186
- const currentIndex = currentActive ? findStepIndex(steps, currentActive) ?? null : null;
187
- // Just dispatch event - user handles the actual navigation
188
- const direction = currentIndex === null ? 'none'
189
- : targetIndex > currentIndex ? 'forward'
190
- : targetIndex < currentIndex ? 'backward'
191
- : 'none';
192
- const event2 = new CustomEvent('ty-wizard-step-change', {
193
- detail: {
194
- activeId: stepId,
195
- activeIndex: targetIndex,
196
- previousId: currentActive,
197
- previousIndex: currentIndex,
198
- direction,
199
- },
200
- bubbles: true,
201
- cancelable: false,
202
- });
203
- el.dispatchEvent(event2);
204
- }
205
- /**
206
- * Cleanup existing event listeners
207
- */
67
+ event.preventDefault();
68
+ event.stopPropagation();
69
+ const steps = getChildSteps(el);
70
+ const targetIndex = steps.findIndex(s => getStepId(s) === stepId);
71
+ if (targetIndex < 0)
72
+ return;
73
+ const currentActive = getActiveStepId(el, steps);
74
+ const currentIndex = currentActive ? findStepIndex(steps, currentActive) ?? null : null;
75
+ const direction = currentIndex === null ? 'none'
76
+ : targetIndex > currentIndex ? 'forward'
77
+ : targetIndex < currentIndex ? 'backward'
78
+ : 'none';
79
+ const event2 = new CustomEvent('ty-wizard-step-change', {
80
+ detail: {
81
+ activeId: stepId,
82
+ activeIndex: targetIndex,
83
+ previousId: currentActive,
84
+ previousIndex: currentIndex,
85
+ direction,
86
+ },
87
+ bubbles: true,
88
+ cancelable: false,
89
+ });
90
+ el.dispatchEvent(event2);
91
+ }
208
92
  function cleanupEventListeners(el) {
209
- const handlers = eventHandlers.get(el);
210
- if (!handlers)
211
- return;
212
- const shadowRoot = el.shadowRoot;
213
- if (!shadowRoot)
214
- return;
215
- // Remove all step click handlers
216
- handlers.stepClickHandlers.forEach((handler, stepId) => {
217
- const button = shadowRoot.querySelector(`[data-step-id='${stepId}']`);
218
- if (button) {
219
- button.removeEventListener('pointerdown', handler);
220
- }
221
- });
222
- handlers.stepClickHandlers.clear();
223
- }
224
- /**
225
- * Setup event listeners for step indicator clicks
226
- */
93
+ const handlers = eventHandlers.get(el);
94
+ if (!handlers)
95
+ return;
96
+ const shadowRoot = el.shadowRoot;
97
+ if (!shadowRoot)
98
+ return;
99
+ handlers.stepClickHandlers.forEach((handler, stepId) => {
100
+ const button = shadowRoot.querySelector(`[data-step-id='${stepId}']`);
101
+ if (button) {
102
+ button.removeEventListener('pointerdown', handler);
103
+ button.removeEventListener('click', handler);
104
+ }
105
+ });
106
+ handlers.stepClickHandlers.clear();
107
+ }
227
108
  function setupEventListeners(el, shadowRoot, steps) {
228
- // Clean up any existing listeners first
229
- cleanupEventListeners(el);
230
- // Initialize handlers storage
231
- const handlers = {
232
- stepClickHandlers: new Map(),
233
- };
234
- // Add click listener for each step indicator
235
- steps.forEach((step) => {
236
- const stepId = getStepId(step);
237
- if (!stepId)
238
- return;
239
- const button = shadowRoot.querySelector(`[data-step-id='${stepId}']`);
240
- if (button) {
241
- const handler = (e) => handleStepClick(el, stepId, e);
242
- button.addEventListener('pointerdown', handler);
243
- handlers.stepClickHandlers.set(stepId, handler);
244
- }
245
- });
246
- // Store handlers for cleanup
247
- eventHandlers.set(el, handlers);
248
- }
249
- // ============================================================================
250
- // Transform & Positioning Updates
251
- // ============================================================================
252
- /**
253
- * Update the transform on panels-wrapper based on active index and measured width
254
- */
255
- function updateTransform(el, activeIndex) {
256
- const shadowRoot = el.shadowRoot;
257
- if (!shadowRoot)
258
- return;
259
- const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
260
- if (!panelsWrapper)
261
- return;
262
- // Measure the actual width of the container
263
- const containerWidth = el.offsetWidth;
264
- const offsetPx = activeIndex * containerWidth;
265
- // Apply transform directly in pixels
266
- panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
267
- }
268
- /**
269
- * Update progress line overlay width
270
- */
271
- function updateProgressLine(el) {
272
- const shadowRoot = el.shadowRoot;
273
- if (!shadowRoot)
274
- return;
275
- const progressOverlay = shadowRoot.querySelector('.progress-overlay');
276
- if (!progressOverlay)
277
- return;
278
- const steps = getChildSteps(el);
279
- const activeId = getActiveStepId(el, steps);
280
- const completedIds = getCompletedStepIds(el);
281
- const progressPercent = calculateProgressPercent(steps, activeId, completedIds);
282
- progressOverlay.style.width = `${progressPercent}%`;
283
- }
284
- /**
285
- * Update ARIA attributes on step indicators without re-rendering
286
- */
109
+ cleanupEventListeners(el);
110
+ const handlers = {
111
+ stepClickHandlers: new Map(),
112
+ };
113
+ steps.forEach((step) => {
114
+ const stepId = getStepId(step);
115
+ if (!stepId)
116
+ return;
117
+ const button = shadowRoot.querySelector(`[data-step-id='${stepId}']`);
118
+ if (button) {
119
+ const handler = (e) => {
120
+ if (e.type === 'click' && e.detail !== 0)
121
+ return;
122
+ handleStepClick(el, stepId, e);
123
+ };
124
+ button.addEventListener('pointerdown', handler);
125
+ button.addEventListener('click', handler);
126
+ handlers.stepClickHandlers.set(stepId, handler);
127
+ }
128
+ });
129
+ eventHandlers.set(el, handlers);
130
+ }
287
131
  function updateStepIndicators(el, shadowRoot, activeId) {
288
- const steps = getChildSteps(el);
289
- const completedIds = getCompletedStepIds(el);
290
- const activeIndex = activeId ? steps.findIndex(s => getStepId(s) === activeId) : 0;
291
- steps.forEach((step, index) => {
292
- const stepId = getStepId(step);
293
- if (!stepId)
294
- return;
295
- const button = shadowRoot.querySelector(`[data-step-id='${stepId}']`);
296
- const circle = shadowRoot.querySelector(`[data-step-id='${stepId}'] .step-circle`);
297
- const isActive = stepId === activeId;
298
- if (button) {
299
- button.setAttribute('aria-selected', String(isActive));
300
- button.setAttribute('tabindex', isActive ? '0' : '-1');
301
- button.setAttribute('data-active', String(isActive));
302
- }
303
- if (circle) {
304
- // Use same status logic as rendering (respects user's status attribute)
305
- const state = getStepStatus(step, stepId, activeId, completedIds);
306
- circle.setAttribute('data-state', state);
307
- }
308
- // Also set data-active on the slotted indicator element in light DOM
309
- const slottedIndicator = el.querySelector(`[slot='indicator-${stepId}']`);
310
- if (slottedIndicator) {
311
- slottedIndicator.setAttribute('data-active', String(isActive));
312
- }
313
- });
314
- }
315
- /**
316
- * Update pointer-events, opacity, and data-active on step panels without re-rendering
317
- */
132
+ const steps = getChildSteps(el);
133
+ const completedIds = getCompletedStepIds(el);
134
+ steps.forEach((step) => {
135
+ const stepId = getStepId(step);
136
+ if (!stepId)
137
+ return;
138
+ const button = shadowRoot.querySelector(`[data-step-id='${stepId}']`);
139
+ const circle = shadowRoot.querySelector(`[data-step-id='${stepId}'] .step-circle`);
140
+ const isActive = stepId === activeId;
141
+ if (button) {
142
+ button.setAttribute('aria-selected', String(isActive));
143
+ button.setAttribute('tabindex', isActive ? '0' : '-1');
144
+ button.setAttribute('data-active', String(isActive));
145
+ }
146
+ const state = getStepStatus(step, stepId, activeId, completedIds);
147
+ button?.setAttribute('data-state', state);
148
+ circle?.setAttribute('data-state', state);
149
+ const slottedIndicator = el.querySelector(`[slot='indicator-${stepId}']`);
150
+ if (slottedIndicator) {
151
+ slottedIndicator.setAttribute('data-active', String(isActive));
152
+ }
153
+ });
154
+ }
318
155
  function updatePanelInteraction(el, activeId) {
319
- const steps = getChildSteps(el);
320
- steps.forEach((step) => {
321
- const stepId = getStepId(step);
322
- if (!stepId)
323
- return;
324
- const isActive = stepId === activeId;
325
- // Set data-active attribute for framework conditional rendering
326
- step.setAttribute('data-active', String(isActive));
327
- if (isActive) {
328
- step.style.pointerEvents = 'auto';
329
- step.style.opacity = '1';
330
- }
331
- else {
332
- step.style.pointerEvents = 'none';
333
- step.style.opacity = '0';
334
- }
335
- });
336
- }
337
- /**
338
- * Update only the active step state without re-rendering DOM.
339
- * This is called when only the active or completed attribute changes.
340
- */
156
+ getChildSteps(el).forEach((step) => {
157
+ const stepId = getStepId(step);
158
+ if (!stepId)
159
+ return;
160
+ step.setAttribute('data-active', String(stepId === activeId));
161
+ });
162
+ }
341
163
  function updateActiveStepState(el, stepId) {
342
- const steps = getChildSteps(el);
343
- const shadowRoot = el.shadowRoot;
344
- if (!shadowRoot)
345
- return;
346
- const currentActive = getActiveStepId(el, steps);
347
- const currentIndex = currentActive ? findStepIndex(steps, currentActive) : undefined;
348
- const newIndex = findStepIndex(steps, stepId);
349
- // Only update if different step and valid
350
- if (currentActive === stepId || 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 step indicator states (visual + ARIA)
357
- updateStepIndicators(el, shadowRoot, stepId);
358
- // Update progress line overlay
359
- updateProgressLine(el);
360
- // Update pointer-events on panels
361
- updatePanelInteraction(el, stepId);
362
- // Reset scroll position of new active panel
363
- const newPanel = steps[newIndex];
364
- if (newPanel?.resetScroll) {
365
- newPanel.resetScroll();
366
- }
367
- // Dispatch change event
368
- dispatchStepChangeEvent(el, stepId, newIndex, currentActive, currentIndex ?? null);
369
- }
370
- // ============================================================================
371
- // ResizeObserver for Responsive Width
372
- // ============================================================================
373
- /**
374
- * Setup ResizeObserver for percentage widths
375
- */
376
- function setupResizeObserver(el) {
377
- // Clean up old observer
378
- const oldObserver = resizeObservers.get(el);
379
- if (oldObserver) {
380
- oldObserver.disconnect();
381
- }
382
- const { width } = getWizardAttributes(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 steps = getChildSteps(el);
389
- const activeId = getActiveStepId(el, steps);
390
- const activeIndex = activeId ? findStepIndex(steps, activeId) : 0;
391
- // Update CSS variable with measured width
392
- el.style.setProperty('--wizard-width', `${measuredWidth}px`);
393
- // Update transform with new width
394
- if (activeIndex !== undefined) {
395
- updateTransform(el, activeIndex);
396
- }
397
- });
398
- observer.observe(el);
399
- resizeObservers.set(el, observer);
400
- }
401
- }
402
- /**
403
- * Cleanup ResizeObserver
404
- */
405
- function cleanupResizeObserver(el) {
406
- const observer = resizeObservers.get(el);
407
- if (observer) {
408
- observer.disconnect();
409
- resizeObservers.delete(el);
410
- }
411
- }
412
- // ============================================================================
413
- // Rendering Functions
414
- // ============================================================================
415
- /**
416
- * Get step status - use user's explicit status attribute or fall back to automatic detection
417
- */
164
+ const steps = getChildSteps(el);
165
+ const shadowRoot = el.shadowRoot;
166
+ if (!shadowRoot)
167
+ return;
168
+ const currentActive = getActiveStepId(el, steps);
169
+ const currentIndex = currentActive ? findStepIndex(steps, currentActive) : undefined;
170
+ const newIndex = findStepIndex(steps, stepId);
171
+ if (currentActive === stepId || newIndex === undefined)
172
+ return;
173
+ el.style.setProperty('--ty-wizard-active-index', String(newIndex));
174
+ updateStepIndicators(el, shadowRoot, stepId);
175
+ updatePanelInteraction(el, stepId);
176
+ const newPanel = steps[newIndex];
177
+ if (newPanel?.resetScroll) {
178
+ newPanel.resetScroll();
179
+ }
180
+ dispatchStepChangeEvent(el, stepId, newIndex, currentActive, currentIndex ?? null);
181
+ }
418
182
  function getStepStatus(step, stepId, activeId, completedIds) {
419
- // Check if user provided explicit status
420
- const explicitStatus = step.getAttribute('status');
421
- if (explicitStatus && ['completed', 'active', 'pending', 'error'].includes(explicitStatus)) {
422
- return explicitStatus;
423
- }
424
- // Fall back to automatic detection
425
- const isActive = stepId === activeId;
426
- const isCompleted = completedIds.has(stepId);
427
- return isCompleted ? 'completed' : isActive ? 'active' : 'pending';
428
- }
429
- /**
430
- * Generate HTML for step indicators with progress line
431
- */
183
+ const explicitStatus = step.getAttribute('status');
184
+ if (explicitStatus && ['completed', 'active', 'pending', 'error'].includes(explicitStatus)) {
185
+ return explicitStatus;
186
+ }
187
+ const isActive = stepId === activeId;
188
+ const isCompleted = completedIds.has(stepId);
189
+ return isActive ? 'active' : isCompleted ? 'completed' : 'pending';
190
+ }
191
+ const CHECK_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"></polyline></svg>`;
192
+ const ALERT_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><line x1="12" y1="5" x2="12" y2="13"></line><line x1="12" y1="18.5" x2="12" y2="18.6"></line></svg>`;
193
+ const STATE_TEXT = {
194
+ completed: 'completed',
195
+ active: 'current',
196
+ pending: 'not started',
197
+ error: 'has an error',
198
+ };
432
199
  function renderStepIndicators(wizardEl, steps, activeId, completedIds) {
433
- const activeIndex = activeId ? steps.findIndex(s => getStepId(s) === activeId) : 0;
434
- const indicators = steps.map((step, index) => {
435
- const stepId = getStepId(step);
436
- if (!stepId)
437
- return '';
438
- const label = step.getAttribute('label') || `Step ${index + 1}`;
439
- const description = step.getAttribute('description') || '';
440
- const disabled = isStepDisabled(step);
441
- const isActive = stepId === activeId;
442
- const hasCustom = hasCustomIndicator(wizardEl, stepId);
443
- // User can override status via attribute
444
- const state = getStepStatus(step, stepId, activeId, completedIds);
445
- // Icon content varies by state
446
- let circleContent = '';
447
- if (hasCustom) {
448
- circleContent = `<slot name="indicator-${stepId}"></slot>`;
449
- }
450
- else if (state === 'completed') {
451
- // Checkmark for completed
452
- circleContent = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>`;
453
- }
454
- else if (state === 'error') {
455
- // X icon for error
456
- circleContent = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`;
457
- }
458
- else {
459
- // Number for active/pending
460
- circleContent = `<span style="font-size: 12px; font-weight: 700;">${index + 1}</span>`;
461
- }
462
- return `<button
463
- class="step-indicator"
464
- role="tab"
465
- data-step-id="${stepId}"
466
- id="step-${stepId}"
467
- aria-controls="panel-${stepId}"
468
- aria-selected="${isActive}"
469
- tabindex="${isActive ? '0' : '-1'}"
470
- data-active="${isActive}"
471
- ${disabled ? 'disabled aria-disabled="true"' : ''}
472
- >
473
- <div class="step-circle" data-state="${state}" part="step-circle">
474
- ${circleContent}
475
- </div>
476
- <div class="step-text">
477
- <span class="step-label">${label}</span>
478
- ${description ? `<span class="step-description">${description}</span>` : ''}
479
- </div>
480
- </button>`;
481
- }).join('');
482
- const progressPercent = calculateProgressPercent(steps, activeId, completedIds);
483
- const stepCount = steps.length;
484
- return `
485
- <div class="step-indicators-wrapper" part="indicators-wrapper">
486
- <div class="step-indicators" style="--step-count: ${stepCount}">
487
- <div class="progress-line" part="progress-line" role="progressbar" aria-valuenow="${Math.round(progressPercent)}" aria-valuemin="0" aria-valuemax="100">
488
- <div class="progress-overlay" style="width: ${progressPercent}%"></div>
489
- </div>
490
- ${indicators}
491
- </div>
492
- </div>
493
- `;
494
- }
495
- /**
496
- * Render the wizard container with step indicators and panel viewport.
497
- * Smart rendering: checks if structure exists and only updates when needed.
498
- */
200
+ const total = steps.length;
201
+ const activeIndex = Math.max(0, activeId ? steps.findIndex(s => getStepId(s) === activeId) : 0);
202
+ const indicators = steps.map((step, index) => {
203
+ const stepId = getStepId(step);
204
+ if (!stepId)
205
+ return '';
206
+ const label = step.getAttribute('label') || `Step ${index + 1}`;
207
+ const description = step.getAttribute('description') || '';
208
+ const disabled = isStepDisabled(step);
209
+ const isActive = stepId === activeId;
210
+ const state = getStepStatus(step, stepId, activeId, completedIds);
211
+ const circleContent = hasCustomIndicator(wizardEl, stepId)
212
+ ? `<slot name="indicator-${stepId}"></slot>`
213
+ : state === 'completed' ? CHECK_SVG
214
+ : state === 'error' ? ALERT_SVG
215
+ : `<span aria-hidden="true">${index + 1}</span>`;
216
+ return `<button
217
+ class="step-indicator"
218
+ role="tab"
219
+ type="button"
220
+ data-step-id="${stepId}"
221
+ id="step-${stepId}"
222
+ data-state="${state}"
223
+ data-done="${state === 'completed' || (state === 'active' && completedIds.has(stepId))}"
224
+ aria-selected="${isActive}"
225
+ tabindex="${isActive ? '0' : '-1'}"
226
+ data-active="${isActive}"
227
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
228
+ >
229
+ <span class="step-circle" data-state="${state}" part="step-circle">${circleContent}</span>
230
+ <span class="step-text">
231
+ <span class="step-label">${label}</span>
232
+ ${description ? `<span class="step-description">${description}</span>` : ''}
233
+ <span class="sr-only">, step ${index + 1} of ${total}, ${STATE_TEXT[state] ?? state}</span>
234
+ </span>
235
+ </button>`;
236
+ }).join('');
237
+ const active = steps[activeIndex];
238
+ const activeLabel = active ? (active.getAttribute('label') || `Step ${activeIndex + 1}`) : '';
239
+ const activeDescription = active?.getAttribute('description') || '';
240
+ const segments = steps.map((step) => {
241
+ const stepId = getStepId(step) || '';
242
+ return `<span class="compact-segment" data-state="${getStepStatus(step, stepId, activeId, completedIds)}"></span>`;
243
+ }).join('');
244
+ return `
245
+ <div class="step-indicators-wrapper" part="indicators-wrapper">
246
+ <div class="step-indicators" role="tablist" aria-label="Steps">
247
+ ${indicators}
248
+ </div>
249
+ <div class="step-compact">
250
+ <div class="compact-top">
251
+ <span class="compact-where">
252
+ <span class="compact-count">Step ${total ? activeIndex + 1 : 0} of ${total}</span>
253
+ <span class="compact-label">${activeLabel}</span>
254
+ </span>
255
+ ${activeDescription ? `<span class="compact-description">${activeDescription}</span>` : ''}
256
+ </div>
257
+ <div class="compact-segments" part="progress">${segments}</div>
258
+ </div>
259
+ </div>
260
+ `;
261
+ }
499
262
  function render(el) {
500
- const shadowRoot = el.shadowRoot;
501
- if (!shadowRoot)
502
- return;
503
- const { width, height } = getWizardAttributes(el);
504
- const steps = getChildSteps(el);
505
- const activeId = getActiveStepId(el, steps);
506
- const activeIndex = activeId ? (findStepIndex(steps, activeId) ?? 0) : 0;
507
- const completedIds = getCompletedStepIds(el);
508
- // Check if structure already exists
509
- const existingContainer = shadowRoot.querySelector('.wizard-container');
510
- const existingIndicators = shadowRoot.querySelector('.step-indicators-wrapper');
511
- const existingViewport = shadowRoot.querySelector('.panels-viewport');
512
- // Ensure styles are loaded
513
- ensureStyles(shadowRoot, { css: wizardStyles, id: 'ty-wizard' });
514
- // Set CSS variables for dimensions and step count
515
- el.style.setProperty('--wizard-width', width.includes('%') ? '100%' : width);
516
- el.style.setProperty('--wizard-height', height);
517
- el.style.setProperty('--active-index', String(activeIndex));
518
- el.style.setProperty('--step-count', String(steps.length));
519
- if (existingContainer && existingIndicators && existingViewport) {
520
- // === SMART UPDATE: Structure exists, only update what changed ===
521
- // Remove old indicators and replace
522
- existingIndicators.remove();
523
- const newIndicatorsHtml = renderStepIndicators(el, steps, activeId, completedIds);
524
- const tempDiv = document.createElement('div');
525
- tempDiv.innerHTML = newIndicatorsHtml;
526
- existingContainer.insertBefore(tempDiv.firstElementChild, existingViewport);
527
- // Re-setup event listeners (indicators were recreated)
528
- setupEventListeners(el, shadowRoot, steps);
529
- // Update ARIA and data-active attributes
530
- updateStepIndicators(el, shadowRoot, activeId || '');
531
- // Measure indicators height
532
- requestAnimationFrame(() => {
533
- const indicators = shadowRoot.querySelector('.step-indicators-wrapper');
534
- if (indicators) {
535
- const indicatorsHeight = indicators.offsetHeight;
536
- el.style.setProperty('--indicators-height', `${indicatorsHeight}px`);
537
- }
538
- // Update transform with current active index
539
- updateTransform(el, activeIndex);
540
- // Update progress line
541
- updateProgressLine(el);
542
- });
543
- // Update panel interaction states
544
- if (activeId) {
545
- updatePanelInteraction(el, activeId);
546
- }
547
- }
548
- else {
549
- // === FULL RENDER: First time or structure missing ===
550
- shadowRoot.innerHTML = `
551
- <div class="wizard-container">
552
- ${renderStepIndicators(el, steps, activeId, completedIds)}
553
- <div class="panels-viewport" part="panels-container">
554
- <div class="panels-wrapper">
555
- <slot></slot>
556
- </div>
557
- </div>
558
- </div>
559
- `;
560
- // Measure indicators height, update transform and progress after render
561
- requestAnimationFrame(() => {
562
- const indicators = shadowRoot.querySelector('.step-indicators-wrapper');
563
- if (indicators) {
564
- const indicatorsHeight = indicators.offsetHeight;
565
- el.style.setProperty('--indicators-height', `${indicatorsHeight}px`);
566
- }
567
- // Update transform with measured width
568
- updateTransform(el, activeIndex);
569
- // Update progress line
570
- updateProgressLine(el);
571
- });
572
- // Setup event listeners
573
- setupEventListeners(el, shadowRoot, steps);
574
- // Update ARIA and data-active attributes on initial render
575
- updateStepIndicators(el, shadowRoot, activeId || '');
576
- // Setup ResizeObserver for responsive width
577
- setupResizeObserver(el);
578
- // Update step panel states
579
- if (activeId) {
580
- updatePanelInteraction(el, activeId);
581
- }
582
- }
583
- }
584
- /**
585
- * Cleanup when wizard component is disconnected
586
- */
263
+ const shadowRoot = el.shadowRoot;
264
+ if (!shadowRoot)
265
+ return;
266
+ const { width, height } = getWizardAttributes(el);
267
+ const steps = getChildSteps(el);
268
+ const activeId = getActiveStepId(el, steps);
269
+ const completedIds = getCompletedStepIds(el);
270
+ steps.forEach((step) => {
271
+ const stepId = getStepId(step);
272
+ if (!stepId)
273
+ return;
274
+ step.setAttribute('role', 'tabpanel');
275
+ step.setAttribute('aria-labelledby', `step-${stepId}`);
276
+ step.setAttribute('tabindex', '0');
277
+ });
278
+ ensureStyles(shadowRoot, { css: wizardStyles, id: 'ty-wizard' });
279
+ el.style.setProperty('--ty-wizard-width', width);
280
+ el.style.setProperty('--ty-wizard-active-index', String(Math.max(0, activeId ? steps.findIndex(s => getStepId(s) === activeId) : 0)));
281
+ if (height)
282
+ el.style.setProperty('--ty-wizard-panel-height', height);
283
+ else
284
+ el.style.removeProperty('--ty-wizard-panel-height');
285
+ let container = shadowRoot.querySelector('.wizard-container');
286
+ let viewport = shadowRoot.querySelector('.panels-viewport');
287
+ if (!container || !viewport) {
288
+ shadowRoot.innerHTML = `
289
+ <div class="wizard-container">
290
+ <div class="panels-viewport" part="panels-container">
291
+ <div class="panels-wrapper">
292
+ <slot></slot>
293
+ </div>
294
+ </div>
295
+ </div>
296
+ `;
297
+ container = shadowRoot.querySelector('.wizard-container');
298
+ viewport = shadowRoot.querySelector('.panels-viewport');
299
+ }
300
+ shadowRoot.querySelector('.step-indicators-wrapper')?.remove();
301
+ const tmp = document.createElement('div');
302
+ tmp.innerHTML = renderStepIndicators(el, steps, activeId, completedIds);
303
+ container.insertBefore(tmp.firstElementChild, viewport);
304
+ setupEventListeners(el, shadowRoot, steps);
305
+ updateStepIndicators(el, shadowRoot, activeId || '');
306
+ if (activeId)
307
+ updatePanelInteraction(el, activeId);
308
+ if (!resizeObservers.has(el)) {
309
+ const ro = new ResizeObserver(() => updateCompact(el));
310
+ ro.observe(el);
311
+ resizeObservers.set(el, ro);
312
+ document.fonts?.ready.then(() => el.isConnected && updateCompact(el));
313
+ }
314
+ updateCompact(el);
315
+ }
316
+ function updateCompact(el) {
317
+ const shadowRoot = el.shadowRoot;
318
+ const container = shadowRoot?.querySelector('.wizard-container');
319
+ const wrapper = shadowRoot?.querySelector('.step-indicators-wrapper');
320
+ const rail = shadowRoot?.querySelector('.step-indicators');
321
+ if (!container || !wrapper || !rail)
322
+ return;
323
+ let compact;
324
+ if (el.getAttribute('orientation') === 'vertical') {
325
+ compact = el.clientWidth < 360;
326
+ }
327
+ else {
328
+ const buttons = Array.from(rail.querySelectorAll('.step-indicator'));
329
+ const px = (v) => parseFloat(v) || 0;
330
+ let natural = px(getComputedStyle(rail).columnGap) * Math.max(0, buttons.length - 1);
331
+ buttons.forEach((b, i) => {
332
+ const circle = b.querySelector('.step-circle');
333
+ const texts = Array.from(b.querySelectorAll('.step-label, .step-description'));
334
+ natural += (circle?.offsetWidth ?? 0) + px(getComputedStyle(b).columnGap)
335
+ + Math.max(0, ...texts.map((t) => t.scrollWidth));
336
+ if (i < buttons.length - 1) {
337
+ const after = getComputedStyle(b, '::after');
338
+ natural += px(getComputedStyle(b).columnGap) + px(after.minWidth) + px(after.marginLeft);
339
+ }
340
+ });
341
+ const cs = getComputedStyle(wrapper);
342
+ const available = wrapper.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
343
+ compact = natural > available + 0.5;
344
+ }
345
+ container.classList.toggle('compact', compact);
346
+ }
347
+ const resizeObservers = new WeakMap();
587
348
  function cleanup(el) {
588
- cleanupEventListeners(el);
589
- cleanupResizeObserver(el);
590
- }
591
- // ============================================================================
592
- // Component Definition
593
- // ============================================================================
594
- /**
595
- * TyWizard Web Component
596
- */
349
+ cleanupEventListeners(el);
350
+ resizeObservers.get(el)?.disconnect();
351
+ resizeObservers.delete(el);
352
+ }
597
353
  export class TyWizard extends HTMLElement {
598
- /** Observed attributes */
599
- static get observedAttributes() {
600
- return ['width', 'height', 'active', 'completed', 'orientation'];
601
- }
602
- constructor() {
603
- super();
604
- this.attachShadow({ mode: 'open' });
605
- }
606
- connectedCallback() {
607
- render(this);
608
- }
609
- disconnectedCallback() {
610
- cleanup(this);
611
- }
612
- attributeChangedCallback(name, oldValue, newValue) {
613
- // Smart rendering: only full render when structural attributes change
614
- if (name === 'active') {
615
- // Active step changed - update state, then do smart render
616
- if (newValue) {
617
- updateActiveStepState(this, newValue);
618
- }
619
- // Always call render after active change to update indicator states
620
- render(this);
621
- }
622
- else if (name === 'completed') {
623
- // Completed steps changed - update progress line and indicators
624
- render(this);
625
- }
626
- else {
627
- // Other attributes changed (width, height, linear, orientation) - full render
628
- render(this);
629
- }
630
- }
631
- }
632
- // Register the custom element
354
+ static get observedAttributes() {
355
+ return ['width', 'height', 'active', 'completed', 'orientation'];
356
+ }
357
+ constructor() {
358
+ super();
359
+ this._childObserver = null;
360
+ this._childRenderQueued = false;
361
+ this.attachShadow({ mode: 'open' });
362
+ }
363
+ connectedCallback() {
364
+ render(this);
365
+ this._childObserver = new MutationObserver((records) => {
366
+ const relevant = records.some((r) => (r.type === 'childList' && r.target === this) ||
367
+ (r.target.tagName === 'TY-STEP' && r.target.parentElement === this));
368
+ if (!relevant || this._childRenderQueued)
369
+ return;
370
+ this._childRenderQueued = true;
371
+ queueMicrotask(() => {
372
+ this._childRenderQueued = false;
373
+ if (this.isConnected)
374
+ render(this);
375
+ });
376
+ });
377
+ this._childObserver.observe(this, {
378
+ childList: true,
379
+ subtree: true,
380
+ attributes: true,
381
+ attributeFilter: ['status', 'label', 'description', 'disabled'],
382
+ });
383
+ }
384
+ disconnectedCallback() {
385
+ this._childObserver?.disconnect();
386
+ this._childObserver = null;
387
+ cleanup(this);
388
+ }
389
+ attributeChangedCallback(name, oldValue, newValue) {
390
+ if (name === 'active') {
391
+ if (newValue) {
392
+ updateActiveStepState(this, newValue);
393
+ }
394
+ render(this);
395
+ }
396
+ else if (name === 'completed') {
397
+ render(this);
398
+ }
399
+ else {
400
+ render(this);
401
+ }
402
+ }
403
+ }
633
404
  if (!customElements.get('ty-wizard')) {
634
- customElements.define('ty-wizard', TyWizard);
405
+ customElements.define('ty-wizard', TyWizard);
635
406
  }
636
- //# sourceMappingURL=wizard.js.map