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

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 (393) hide show
  1. package/AGENTS.md +122 -0
  2. package/CHANGELOG.md +1541 -0
  3. package/README.md +71 -53
  4. package/bin/tyrell.mjs +77 -0
  5. package/css/tyrell-colors-static.css +1 -0
  6. package/css/tyrell-theme.css +1 -0
  7. package/css/tyrell.css +1 -1783
  8. package/dist/tyrell-colors-static.css +1 -0
  9. package/dist/tyrell-theme.css +1 -0
  10. package/dist/tyrell.css +1 -1783
  11. package/dist/tyrell.js +1 -1
  12. package/guides/AGENT_INSTRUCTIONS.md +124 -0
  13. package/guides/AI_GUIDE.md +53 -0
  14. package/guides/CSS_GUIDE.md +1016 -0
  15. package/guides/DATASTAR_TY_GUIDE.md +657 -0
  16. package/guides/ICONS_GUIDE.md +212 -0
  17. package/guides/TY_GUIDE.md +937 -0
  18. package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
  19. package/guides/clj/CODE_SPLITTING.md +279 -0
  20. package/guides/clj/COMPONENT_GUIDE.md +391 -0
  21. package/guides/clj/HELIX_TY_GUIDE.md +428 -0
  22. package/guides/clj/I18N_GUIDE.md +478 -0
  23. package/guides/clj/LAYOUT_GUIDE.md +273 -0
  24. package/guides/clj/QUICKSTART.md +266 -0
  25. package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
  26. package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
  27. package/guides/clj/ROUTING_GUIDE.md +346 -0
  28. package/guides/clj/UIX_TY_GUIDE.md +319 -0
  29. package/guides/js/HTMX_TY_GUIDE.md +252 -0
  30. package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
  31. package/guides/js/REACT_TY_GUIDE.md +983 -0
  32. package/guides/js/SVELTE_TY_GUIDE.md +682 -0
  33. package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
  34. package/guides/js/VUE_TY_GUIDE.md +738 -0
  35. package/lib/base/ty-component.d.ts +57 -13
  36. package/lib/base/ty-component.js +266 -292
  37. package/lib/components/button.d.ts +33 -18
  38. package/lib/components/button.js +317 -267
  39. package/lib/components/calendar-month.d.ts +30 -47
  40. package/lib/components/calendar-month.js +455 -429
  41. package/lib/components/calendar-navigation.d.ts +41 -49
  42. package/lib/components/calendar-navigation.js +287 -346
  43. package/lib/components/calendar.d.ts +73 -83
  44. package/lib/components/calendar.js +837 -762
  45. package/lib/components/checkbox.d.ts +26 -75
  46. package/lib/components/checkbox.js +298 -391
  47. package/lib/components/copy.d.ts +20 -60
  48. package/lib/components/copy.js +276 -380
  49. package/lib/components/date-picker.d.ts +100 -183
  50. package/lib/components/date-picker.js +1155 -1570
  51. package/lib/components/file-upload.d.ts +16 -15
  52. package/lib/components/file-upload.js +436 -426
  53. package/lib/components/icon.d.ts +3 -24
  54. package/lib/components/icon.js +141 -230
  55. package/lib/components/input.d.ts +93 -108
  56. package/lib/components/input.js +734 -710
  57. package/lib/components/modal.d.ts +39 -29
  58. package/lib/components/modal.js +419 -438
  59. package/lib/components/option.d.ts +20 -35
  60. package/lib/components/option.js +184 -309
  61. package/lib/components/popup.d.ts +2 -17
  62. package/lib/components/popup.js +353 -347
  63. package/lib/components/radio.d.ts +33 -25
  64. package/lib/components/radio.js +433 -422
  65. package/lib/components/resize-observer.d.ts +3 -30
  66. package/lib/components/resize-observer.js +71 -103
  67. package/lib/components/scroll-container.d.ts +21 -14
  68. package/lib/components/scroll-container.js +292 -234
  69. package/lib/components/select.d.ts +458 -0
  70. package/lib/components/select.js +1458 -0
  71. package/lib/components/selected-tags.d.ts +60 -0
  72. package/lib/components/selected-tags.js +225 -0
  73. package/lib/components/sortable.d.ts +175 -0
  74. package/lib/components/sortable.js +1844 -0
  75. package/lib/components/step.d.ts +1 -6
  76. package/lib/components/step.js +62 -68
  77. package/lib/components/switch.d.ts +15 -15
  78. package/lib/components/switch.js +237 -231
  79. package/lib/components/tab.d.ts +50 -7
  80. package/lib/components/tab.js +203 -69
  81. package/lib/components/tabs.d.ts +19 -64
  82. package/lib/components/tabs.js +600 -618
  83. package/lib/components/tag.d.ts +14 -52
  84. package/lib/components/tag.js +231 -306
  85. package/lib/components/textarea.d.ts +58 -89
  86. package/lib/components/textarea.js +523 -573
  87. package/lib/components/tooltip.d.ts +8 -13
  88. package/lib/components/tooltip.js +322 -409
  89. package/lib/components/wizard.d.ts +7 -54
  90. package/lib/components/wizard.js +376 -606
  91. package/lib/icons/fontawesome/brands.d.ts +0 -1
  92. package/lib/icons/fontawesome/brands.js +0 -8
  93. package/lib/icons/fontawesome/regular.d.ts +0 -1
  94. package/lib/icons/fontawesome/regular.js +0 -8
  95. package/lib/icons/fontawesome/solid.d.ts +0 -1
  96. package/lib/icons/fontawesome/solid.js +0 -8
  97. package/lib/icons/heroicons/micro.d.ts +0 -1
  98. package/lib/icons/heroicons/micro.js +392 -400
  99. package/lib/icons/heroicons/mini.d.ts +0 -1
  100. package/lib/icons/heroicons/mini.js +382 -390
  101. package/lib/icons/heroicons/outline.d.ts +0 -1
  102. package/lib/icons/heroicons/outline.js +337 -345
  103. package/lib/icons/heroicons/solid.d.ts +0 -1
  104. package/lib/icons/heroicons/solid.js +407 -415
  105. package/lib/icons/lucide.d.ts +0 -1
  106. package/lib/icons/lucide.js +24479 -26351
  107. package/lib/icons/material/filled.d.ts +0 -1
  108. package/lib/icons/material/filled.js +9653 -9663
  109. package/lib/icons/material/outlined.d.ts +0 -1
  110. package/lib/icons/material/outlined.js +10271 -10281
  111. package/lib/icons/material/round.d.ts +0 -1
  112. package/lib/icons/material/round.js +10495 -10505
  113. package/lib/icons/material/sharp.d.ts +0 -1
  114. package/lib/icons/material/sharp.js +9905 -9915
  115. package/lib/icons/material/two-tone.d.ts +0 -1
  116. package/lib/icons/material/two-tone.js +12792 -12802
  117. package/lib/index.d.ts +7 -4
  118. package/lib/index.js +26 -39
  119. package/lib/styles/button.d.ts +24 -7
  120. package/lib/styles/button.js +285 -445
  121. package/lib/styles/calendar-month.d.ts +7 -6
  122. package/lib/styles/calendar-month.js +158 -226
  123. package/lib/styles/calendar-navigation.d.ts +2 -6
  124. package/lib/styles/calendar-navigation.js +108 -127
  125. package/lib/styles/calendar.d.ts +3 -3
  126. package/lib/styles/calendar.js +87 -23
  127. package/lib/styles/checkbox.d.ts +7 -6
  128. package/lib/styles/checkbox.js +101 -15
  129. package/lib/styles/copy.d.ts +3 -2
  130. package/lib/styles/copy.js +91 -71
  131. package/lib/styles/custom-scrollbar.d.ts +1 -2
  132. package/lib/styles/custom-scrollbar.js +80 -115
  133. package/lib/styles/date-picker.d.ts +4 -6
  134. package/lib/styles/date-picker.js +321 -388
  135. package/lib/styles/field-size.d.ts +6 -0
  136. package/lib/styles/field-size.js +91 -0
  137. package/lib/styles/file-upload.d.ts +1 -2
  138. package/lib/styles/file-upload.js +143 -188
  139. package/lib/styles/icon.d.ts +2 -6
  140. package/lib/styles/icon.js +92 -170
  141. package/lib/styles/input.d.ts +4 -7
  142. package/lib/styles/input.js +148 -643
  143. package/lib/styles/modal.d.ts +1 -2
  144. package/lib/styles/modal.js +127 -108
  145. package/lib/styles/option.d.ts +2 -6
  146. package/lib/styles/option.js +53 -96
  147. package/lib/styles/popup.d.ts +1 -2
  148. package/lib/styles/popup.js +47 -77
  149. package/lib/styles/radio.d.ts +3 -2
  150. package/lib/styles/radio.js +90 -116
  151. package/lib/styles/resize-observer.d.ts +1 -2
  152. package/lib/styles/resize-observer.js +2 -12
  153. package/lib/styles/scroll-container.d.ts +1 -2
  154. package/lib/styles/scroll-container.js +103 -146
  155. package/lib/styles/select-base.d.ts +8 -0
  156. package/lib/styles/select-base.js +752 -0
  157. package/lib/styles/select.d.ts +11 -0
  158. package/lib/styles/select.js +229 -0
  159. package/lib/styles/sortable.d.ts +16 -0
  160. package/lib/styles/sortable.js +85 -0
  161. package/lib/styles/step.d.ts +1 -2
  162. package/lib/styles/step.js +15 -34
  163. package/lib/styles/switch.d.ts +3 -2
  164. package/lib/styles/switch.js +52 -68
  165. package/lib/styles/tab.d.ts +1 -2
  166. package/lib/styles/tab.js +86 -34
  167. package/lib/styles/tabs.d.ts +3 -11
  168. package/lib/styles/tabs.js +204 -162
  169. package/lib/styles/tag.d.ts +2 -6
  170. package/lib/styles/tag.js +168 -362
  171. package/lib/styles/textarea.d.ts +1 -2
  172. package/lib/styles/textarea.js +238 -306
  173. package/lib/styles/tooltip.d.ts +4 -3
  174. package/lib/styles/tooltip.js +3 -131
  175. package/lib/styles/wizard.d.ts +8 -20
  176. package/lib/styles/wizard.js +306 -295
  177. package/lib/types/common.d.ts +9 -8
  178. package/lib/types/common.js +8 -5
  179. package/lib/utils/calendar-utils.d.ts +49 -65
  180. package/lib/utils/calendar-utils.js +158 -343
  181. package/lib/utils/custom-scrollbar.d.ts +6 -20
  182. package/lib/utils/custom-scrollbar.js +273 -317
  183. package/lib/utils/flavor-sheet.d.ts +31 -0
  184. package/lib/utils/flavor-sheet.js +17 -0
  185. package/lib/utils/icon-registry.d.ts +0 -15
  186. package/lib/utils/icon-registry.js +138 -279
  187. package/lib/utils/icons.d.ts +9 -0
  188. package/lib/utils/icons.js +1 -0
  189. package/lib/utils/loader-registry.d.ts +2 -3
  190. package/lib/utils/loader-registry.js +3 -35
  191. package/lib/utils/locale.d.ts +2 -80
  192. package/lib/utils/locale.js +30 -205
  193. package/lib/utils/mobile.d.ts +0 -1
  194. package/lib/utils/mobile.js +1 -18
  195. package/lib/utils/number-format.d.ts +6 -24
  196. package/lib/utils/number-format.js +53 -136
  197. package/lib/utils/positioning.d.ts +72 -22
  198. package/lib/utils/positioning.js +224 -298
  199. package/lib/utils/property-capture.d.ts +5 -27
  200. package/lib/utils/property-capture.js +36 -144
  201. package/lib/utils/property-manager.d.ts +6 -6
  202. package/lib/utils/property-manager.js +127 -196
  203. package/lib/utils/resize-observer.d.ts +0 -1
  204. package/lib/utils/resize-observer.js +23 -59
  205. package/lib/utils/scroll-lock.d.ts +10 -11
  206. package/lib/utils/scroll-lock.js +165 -173
  207. package/lib/utils/styles.d.ts +0 -6
  208. package/lib/utils/styles.js +17 -48
  209. package/lib/utils/upgrade-properties.d.ts +21 -0
  210. package/lib/utils/upgrade-properties.js +47 -0
  211. package/lib/utils/validity.d.ts +122 -0
  212. package/lib/utils/validity.js +289 -0
  213. package/lib/version.d.ts +1 -2
  214. package/lib/version.js +1 -11
  215. package/package.json +66 -18
  216. package/lib/base/ty-component.d.ts.map +0 -1
  217. package/lib/base/ty-component.js.map +0 -1
  218. package/lib/components/button.d.ts.map +0 -1
  219. package/lib/components/button.js.map +0 -1
  220. package/lib/components/calendar-month.d.ts.map +0 -1
  221. package/lib/components/calendar-month.js.map +0 -1
  222. package/lib/components/calendar-navigation.d.ts.map +0 -1
  223. package/lib/components/calendar-navigation.js.map +0 -1
  224. package/lib/components/calendar.d.ts.map +0 -1
  225. package/lib/components/calendar.js.map +0 -1
  226. package/lib/components/checkbox.d.ts.map +0 -1
  227. package/lib/components/checkbox.js.map +0 -1
  228. package/lib/components/copy.d.ts.map +0 -1
  229. package/lib/components/copy.js.map +0 -1
  230. package/lib/components/date-picker.d.ts.map +0 -1
  231. package/lib/components/date-picker.js.map +0 -1
  232. package/lib/components/dropdown.d.ts +0 -404
  233. package/lib/components/dropdown.d.ts.map +0 -1
  234. package/lib/components/dropdown.js +0 -1563
  235. package/lib/components/dropdown.js.map +0 -1
  236. package/lib/components/file-upload.d.ts.map +0 -1
  237. package/lib/components/file-upload.js.map +0 -1
  238. package/lib/components/icon.d.ts.map +0 -1
  239. package/lib/components/icon.js.map +0 -1
  240. package/lib/components/input.d.ts.map +0 -1
  241. package/lib/components/input.js.map +0 -1
  242. package/lib/components/modal.d.ts.map +0 -1
  243. package/lib/components/modal.js.map +0 -1
  244. package/lib/components/multiselect.d.ts +0 -408
  245. package/lib/components/multiselect.d.ts.map +0 -1
  246. package/lib/components/multiselect.js +0 -1611
  247. package/lib/components/multiselect.js.map +0 -1
  248. package/lib/components/option.d.ts.map +0 -1
  249. package/lib/components/option.js.map +0 -1
  250. package/lib/components/popup.d.ts.map +0 -1
  251. package/lib/components/popup.js.map +0 -1
  252. package/lib/components/radio.d.ts.map +0 -1
  253. package/lib/components/radio.js.map +0 -1
  254. package/lib/components/resize-observer.d.ts.map +0 -1
  255. package/lib/components/resize-observer.js.map +0 -1
  256. package/lib/components/scroll-container.d.ts.map +0 -1
  257. package/lib/components/scroll-container.js.map +0 -1
  258. package/lib/components/step.d.ts.map +0 -1
  259. package/lib/components/step.js.map +0 -1
  260. package/lib/components/switch.d.ts.map +0 -1
  261. package/lib/components/switch.js.map +0 -1
  262. package/lib/components/tab.d.ts.map +0 -1
  263. package/lib/components/tab.js.map +0 -1
  264. package/lib/components/tabs.d.ts.map +0 -1
  265. package/lib/components/tabs.js.map +0 -1
  266. package/lib/components/tag.d.ts.map +0 -1
  267. package/lib/components/tag.js.map +0 -1
  268. package/lib/components/textarea.d.ts.map +0 -1
  269. package/lib/components/textarea.js.map +0 -1
  270. package/lib/components/tooltip.d.ts.map +0 -1
  271. package/lib/components/tooltip.js.map +0 -1
  272. package/lib/components/wizard.d.ts.map +0 -1
  273. package/lib/components/wizard.js.map +0 -1
  274. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  275. package/lib/icons/fontawesome/brands.js.map +0 -1
  276. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  277. package/lib/icons/fontawesome/regular.js.map +0 -1
  278. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  279. package/lib/icons/fontawesome/solid.js.map +0 -1
  280. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  281. package/lib/icons/heroicons/micro.js.map +0 -1
  282. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  283. package/lib/icons/heroicons/mini.js.map +0 -1
  284. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  285. package/lib/icons/heroicons/outline.js.map +0 -1
  286. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  287. package/lib/icons/heroicons/solid.js.map +0 -1
  288. package/lib/icons/lucide.d.ts.map +0 -1
  289. package/lib/icons/lucide.js.map +0 -1
  290. package/lib/icons/material/filled.d.ts.map +0 -1
  291. package/lib/icons/material/filled.js.map +0 -1
  292. package/lib/icons/material/outlined.d.ts.map +0 -1
  293. package/lib/icons/material/outlined.js.map +0 -1
  294. package/lib/icons/material/round.d.ts.map +0 -1
  295. package/lib/icons/material/round.js.map +0 -1
  296. package/lib/icons/material/sharp.d.ts.map +0 -1
  297. package/lib/icons/material/sharp.js.map +0 -1
  298. package/lib/icons/material/two-tone.d.ts.map +0 -1
  299. package/lib/icons/material/two-tone.js.map +0 -1
  300. package/lib/index.d.ts.map +0 -1
  301. package/lib/index.js.map +0 -1
  302. package/lib/styles/button.d.ts.map +0 -1
  303. package/lib/styles/button.js.map +0 -1
  304. package/lib/styles/calendar-month.d.ts.map +0 -1
  305. package/lib/styles/calendar-month.js.map +0 -1
  306. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  307. package/lib/styles/calendar-navigation.js.map +0 -1
  308. package/lib/styles/calendar.d.ts.map +0 -1
  309. package/lib/styles/calendar.js.map +0 -1
  310. package/lib/styles/checkbox.d.ts.map +0 -1
  311. package/lib/styles/checkbox.js.map +0 -1
  312. package/lib/styles/copy.d.ts.map +0 -1
  313. package/lib/styles/copy.js.map +0 -1
  314. package/lib/styles/custom-scrollbar.d.ts.map +0 -1
  315. package/lib/styles/custom-scrollbar.js.map +0 -1
  316. package/lib/styles/date-picker.d.ts.map +0 -1
  317. package/lib/styles/date-picker.js.map +0 -1
  318. package/lib/styles/dropdown.d.ts +0 -12
  319. package/lib/styles/dropdown.d.ts.map +0 -1
  320. package/lib/styles/dropdown.js +0 -1048
  321. package/lib/styles/dropdown.js.map +0 -1
  322. package/lib/styles/file-upload.d.ts.map +0 -1
  323. package/lib/styles/file-upload.js.map +0 -1
  324. package/lib/styles/icon.d.ts.map +0 -1
  325. package/lib/styles/icon.js.map +0 -1
  326. package/lib/styles/input.d.ts.map +0 -1
  327. package/lib/styles/input.js.map +0 -1
  328. package/lib/styles/modal.d.ts.map +0 -1
  329. package/lib/styles/modal.js.map +0 -1
  330. package/lib/styles/multiselect.d.ts +0 -6
  331. package/lib/styles/multiselect.d.ts.map +0 -1
  332. package/lib/styles/multiselect.js +0 -837
  333. package/lib/styles/multiselect.js.map +0 -1
  334. package/lib/styles/option.d.ts.map +0 -1
  335. package/lib/styles/option.js.map +0 -1
  336. package/lib/styles/popup.d.ts.map +0 -1
  337. package/lib/styles/popup.js.map +0 -1
  338. package/lib/styles/radio.d.ts.map +0 -1
  339. package/lib/styles/radio.js.map +0 -1
  340. package/lib/styles/resize-observer.d.ts.map +0 -1
  341. package/lib/styles/resize-observer.js.map +0 -1
  342. package/lib/styles/scroll-container.d.ts.map +0 -1
  343. package/lib/styles/scroll-container.js.map +0 -1
  344. package/lib/styles/step.d.ts.map +0 -1
  345. package/lib/styles/step.js.map +0 -1
  346. package/lib/styles/switch.d.ts.map +0 -1
  347. package/lib/styles/switch.js.map +0 -1
  348. package/lib/styles/tab.d.ts.map +0 -1
  349. package/lib/styles/tab.js.map +0 -1
  350. package/lib/styles/tabs.d.ts.map +0 -1
  351. package/lib/styles/tabs.js.map +0 -1
  352. package/lib/styles/tag.d.ts.map +0 -1
  353. package/lib/styles/tag.js.map +0 -1
  354. package/lib/styles/textarea.d.ts.map +0 -1
  355. package/lib/styles/textarea.js.map +0 -1
  356. package/lib/styles/tooltip.d.ts.map +0 -1
  357. package/lib/styles/tooltip.js.map +0 -1
  358. package/lib/styles/wizard.d.ts.map +0 -1
  359. package/lib/styles/wizard.js.map +0 -1
  360. package/lib/types/common.d.ts.map +0 -1
  361. package/lib/types/common.js.map +0 -1
  362. package/lib/utils/calendar-utils.d.ts.map +0 -1
  363. package/lib/utils/calendar-utils.js.map +0 -1
  364. package/lib/utils/custom-scrollbar.d.ts.map +0 -1
  365. package/lib/utils/custom-scrollbar.js.map +0 -1
  366. package/lib/utils/icon-registry.d.ts.map +0 -1
  367. package/lib/utils/icon-registry.js.map +0 -1
  368. package/lib/utils/loader-registry.d.ts.map +0 -1
  369. package/lib/utils/loader-registry.js.map +0 -1
  370. package/lib/utils/locale.d.ts.map +0 -1
  371. package/lib/utils/locale.js.map +0 -1
  372. package/lib/utils/mobile.d.ts.map +0 -1
  373. package/lib/utils/mobile.js.map +0 -1
  374. package/lib/utils/number-format.d.ts.map +0 -1
  375. package/lib/utils/number-format.js.map +0 -1
  376. package/lib/utils/parse-boolean.d.ts +0 -39
  377. package/lib/utils/parse-boolean.d.ts.map +0 -1
  378. package/lib/utils/parse-boolean.js +0 -58
  379. package/lib/utils/parse-boolean.js.map +0 -1
  380. package/lib/utils/positioning.d.ts.map +0 -1
  381. package/lib/utils/positioning.js.map +0 -1
  382. package/lib/utils/property-capture.d.ts.map +0 -1
  383. package/lib/utils/property-capture.js.map +0 -1
  384. package/lib/utils/property-manager.d.ts.map +0 -1
  385. package/lib/utils/property-manager.js.map +0 -1
  386. package/lib/utils/resize-observer.d.ts.map +0 -1
  387. package/lib/utils/resize-observer.js.map +0 -1
  388. package/lib/utils/scroll-lock.d.ts.map +0 -1
  389. package/lib/utils/scroll-lock.js.map +0 -1
  390. package/lib/utils/styles.d.ts.map +0 -1
  391. package/lib/utils/styles.js.map +0 -1
  392. package/lib/version.d.ts.map +0 -1
  393. package/lib/version.js.map +0 -1
@@ -1,721 +1,745 @@
1
- /**
2
- * TyInput Web Component
3
- * PORTED FROM: clj/ty/components/input.cljs
4
- * Phase D: Complete with debounce feature for input and change events
5
- *
6
- * Enhanced input component with:
7
- * - Label, error messages, semantic styling
8
- * - Icon slots (start/end)
9
- * - Numeric formatting with shadow values
10
- * - Currency, percent, compact notation
11
- * - Format-on-blur / raw-on-focus behavior
12
- * - Debounce (0-5000ms) for input/change events
13
- * - Immediate event firing on blur (cancels pending debounce)
14
- *
15
- * NOTE: Checkbox functionality is in separate ty-checkbox component
16
- */
1
+ import { DEFAULT_SIZE } from '../types/common.js';
17
2
  import { TyComponent } from '../base/ty-component.js';
18
3
  import { ensureStyles } from '../utils/styles.js';
19
- import { inputStyles } from '../styles/input.js';
4
+ import { syncCustomFlavorSheet } from '../utils/flavor-sheet.js';
5
+ import { inputStyles, inputCustomFlavorCss } from '../styles/input.js';
20
6
  import { formatNumber, parseNumericValue, shouldFormat as shouldFormatType } from '../utils/number-format.js';
21
7
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
22
- /**
23
- * Required indicator SVG icon (from Lucide)
24
- */
25
- const REQUIRED_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-asterisk-icon lucide-asterisk"><path d="M12 6v12"/><path d="M17.196 9 6.804 15"/><path d="m6.804 9 10.392 6"/></svg>`;
8
+ import { REQUIRED_ICON_SVG } from '../utils/icons.js';
9
+ import { nativeMessage, nativeValidity, lengthValidity, toLimit } from '../utils/validity.js';
10
+ const EYE_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>`;
11
+ const EYE_OFF_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"/><path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"/><path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"/><path d="m2 2 20 20"/></svg>`;
26
12
  export class TyInput extends TyComponent {
27
- constructor() {
28
- super(); // TyComponent handles attachInternals() and attachShadow()
29
- // ============================================================================
30
- // INTERNAL STATE - Not managed by PropertyManager
31
- // NOTE: _internals provided by TyComponent base class
32
- // ============================================================================
33
- // Shadow value - parsed numeric value for formatting
34
- this._shadowValue = null;
35
- // Focus state - toggles format/raw display
36
- this._isFocused = false;
37
- // Listener setup tracking
38
- this._listenersSetup = false;
39
- // Store references to handlers for cleanup
40
- this._inputHandler = null;
41
- this._changeHandler = null;
42
- this._focusHandler = null;
43
- this._blurHandler = null;
44
- // Debounce timers
45
- this._inputDebounceTimer = null;
46
- this._changeDebounceTimer = null;
47
- // Apply styles to shadow root
48
- const shadow = this.shadowRoot;
49
- ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
50
- }
51
- /**
52
- * Called when component connects to DOM
53
- * TyComponent already handled pre-connection property capture
54
- */
55
- onConnect() {
56
- // Initialize shadow value from current value property
57
- this.initializeShadowValue();
58
- // NOTE: Event listeners are set up in render() after input element is created
59
- // setupEventListeners() will be called after initial render
60
- // Setup locale observer to watch for ancestor lang changes
61
- this._localeObserver = observeLocaleChanges(this, () => {
62
- this.render();
63
- });
64
- }
65
- /**
66
- * Called when component disconnects from DOM
67
- */
68
- onDisconnect() {
69
- // Clean up event listeners
70
- this.removeEventListeners();
71
- // Cleanup locale observer
72
- if (this._localeObserver) {
73
- this._localeObserver();
74
- this._localeObserver = undefined;
75
- }
76
- // Clear any pending debounce timers
77
- if (this._inputDebounceTimer !== null) {
78
- clearTimeout(this._inputDebounceTimer);
79
- this._inputDebounceTimer = null;
80
- }
81
- if (this._changeDebounceTimer !== null) {
82
- clearTimeout(this._changeDebounceTimer);
83
- this._changeDebounceTimer = null;
84
- }
85
- }
86
- // ============================================================================
87
- // TYCOMPONENT LIFECYCLE HOOKS
88
- // ============================================================================
89
- /**
90
- * Handle property changes - called BEFORE render
91
- * This replaces the old attributeChangedCallback logic
92
- */
93
- onPropertiesChanged(changes) {
94
- for (const { name, newValue } of changes) {
95
- switch (name) {
96
- case 'value':
97
- // Parse to shadow value for numeric types
98
- this._shadowValue = this.parseShadowValue(newValue || '');
99
- break;
100
- case 'type':
101
- // Re-parse shadow value when type changes
102
- const currentValue = this.getProperty('value') || '';
103
- this._shadowValue = this.parseShadowValue(currentValue);
104
- break;
105
- case 'error':
106
- // Auto-set flavor to danger when error is present and flavor is neutral
107
- if (newValue && this.getProperty('flavor') === 'neutral') {
108
- // Use setProperty to trigger proper lifecycle
109
- this.setProperty('flavor', 'danger');
110
- }
111
- break;
112
- }
113
- }
114
- }
115
- /**
116
- * Hook: Called when form is reset
117
- * Clear shadow value and focus state
118
- */
119
- onFormReset() {
120
- // Reset shadow value to default (empty)
121
- this._shadowValue = null;
122
- // Reset focus state
123
- this._isFocused = false;
124
- // Clear any pending debounce timers
125
- if (this._inputDebounceTimer !== null) {
126
- clearTimeout(this._inputDebounceTimer);
127
- this._inputDebounceTimer = null;
128
- }
129
- if (this._changeDebounceTimer !== null) {
130
- clearTimeout(this._changeDebounceTimer);
131
- this._changeDebounceTimer = null;
132
- }
133
- this.render();
134
- }
135
- /**
136
- * Override form value to return shadow value
137
- * This ensures numeric types submit their parsed values
138
- */
139
- getFormValue() {
140
- const formValue = this._shadowValue !== null ? String(this._shadowValue) : null;
141
- return formValue;
142
- }
143
- /**
144
- * Initialize shadow value from the initial value attribute
145
- */
146
- initializeShadowValue() {
147
- const currentValue = this.getProperty('value');
148
- if (currentValue) {
149
- this._shadowValue = this.parseShadowValue(currentValue);
150
- // Update form value
151
- this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
152
- }
153
- }
154
- /**
155
- * Parse a string value to the appropriate shadow value type
156
- */
157
- parseShadowValue(value) {
158
- // Defensive check: ensure value is actually a string before calling .trim()
159
- if (!value || typeof value !== 'string' || value.trim() === '')
160
- return null;
161
- // For numeric types, parse to number
162
- if (shouldFormatType(this.type)) {
163
- const parsed = parseNumericValue(value);
164
- if (parsed !== null && this.precision === 0) {
165
- return Math.round(parsed);
166
- }
167
- return parsed;
168
- }
169
- // For other types, keep as string
170
- return value;
171
- }
172
- /**
173
- * Check if current input should format numbers
174
- */
175
- shouldFormat() {
176
- return shouldFormatType(this.type) &&
177
- !this._isFocused &&
178
- this._shadowValue !== null &&
179
- typeof this._shadowValue === 'number';
180
- }
181
- /**
182
- * Get the format configuration for current input
183
- */
184
- getFormatConfig() {
185
- return {
186
- type: this.type,
187
- locale: this.locale, // Use getter which calls getEffectiveLocale correctly
188
- currency: this.currency,
189
- precision: this.precision
190
- };
191
- }
192
- /**
193
- * Get the display value (formatted or raw)
194
- */
195
- getDisplayValue() {
196
- if (this.shouldFormat()) {
197
- let valueToFormat = this._shadowValue;
198
- // For percent: divide by 100 (user enters 15, displays as 15%)
199
- // This matches ClojureScript behavior
200
- if (this.type === 'percent') {
201
- valueToFormat = valueToFormat / 100;
202
- }
203
- return formatNumber(valueToFormat, this.getFormatConfig());
204
- }
205
- return this._shadowValue !== null ? String(this._shadowValue) : '';
206
- }
207
- // ============================================================================
208
- // PROPERTY ACCESSORS - Simplified with TyComponent
209
- // NOTE: validateFlavor removed - now handled by property configuration
210
- // ============================================================================
211
- // Core properties - simple getProperty/setProperty pattern
212
- get type() { return this.getProperty('type'); }
213
- set type(v) { this.setProperty('type', v); }
214
- // Value - special getter returns shadow value
215
- get value() {
216
- return this._shadowValue !== null ? String(this._shadowValue) : '';
217
- }
218
- set value(v) { this.setProperty('value', v); }
219
- get name() { return this.getProperty('name'); }
220
- set name(v) { this.setProperty('name', v); }
221
- get placeholder() { return this.getProperty('placeholder'); }
222
- set placeholder(v) { this.setProperty('placeholder', v); }
223
- get label() { return this.getProperty('label'); }
224
- set label(v) { this.setProperty('label', v); }
225
- get disabled() { return this.getProperty('disabled'); }
226
- set disabled(v) { this.setProperty('disabled', v); }
227
- get required() { return this.getProperty('required'); }
228
- set required(v) { this.setProperty('required', v); }
229
- get error() { return this.getProperty('error'); }
230
- set error(v) { this.setProperty('error', v); }
231
- get size() { return this.getProperty('size'); }
232
- set size(v) { this.setProperty('size', v); }
233
- get flavor() { return this.getProperty('flavor'); }
234
- set flavor(v) { this.setProperty('flavor', v); }
235
- // Numeric formatting properties
236
- get currency() { return this.getProperty('currency'); }
237
- set currency(v) { this.setProperty('currency', v); }
238
- // Locale - special getter uses getEffectiveLocale()
239
- get locale() {
240
- return getEffectiveLocale(this, this.getProperty('locale'));
241
- }
242
- set locale(v) { this.setProperty('locale', v); }
243
- get precision() { return this.getProperty('precision'); }
244
- set precision(v) { this.setProperty('precision', v); }
245
- // Debounce property
246
- get debounce() { return this.getProperty('debounce'); }
247
- set debounce(v) { this.setProperty('debounce', v); }
248
- // Form property
249
- get form() {
250
- return this._internals.form;
251
- }
252
- /**
253
- * Build CSS class list for input wrapper
254
- */
255
- buildClassList() {
256
- const classes = [this.size, this.flavor];
257
- if (this.disabled)
258
- classes.push('disabled');
259
- if (this.required)
260
- classes.push('required');
261
- if (this.error)
262
- classes.push('error');
263
- return classes.join(' ');
264
- }
265
- /**
266
- * Dispatch input event (helper method for debouncing)
267
- */
268
- dispatchInputEvent(rawValue, originalEvent) {
269
- this.dispatchEvent(new CustomEvent('input', {
270
- detail: {
271
- value: this._shadowValue,
272
- formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
273
- rawValue: rawValue,
274
- originalEvent: originalEvent
275
- },
276
- bubbles: true,
277
- composed: true
278
- }));
279
- }
280
- /**
281
- * Dispatch change event (helper method for debouncing)
282
- */
283
- dispatchChangeEvent(rawValue, originalEvent) {
284
- this.dispatchEvent(new CustomEvent('change', {
285
- detail: {
286
- value: this._shadowValue,
287
- formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
288
- rawValue: rawValue,
289
- originalEvent: originalEvent
290
- },
291
- bubbles: true,
292
- composed: true
293
- }));
294
- }
295
- /**
296
- * Remove event listeners for cleanup
297
- */
298
- removeEventListeners() {
299
- if (!this._listenersSetup)
300
- return;
301
- const shadow = this.shadowRoot;
302
- if (!shadow)
303
- return;
304
- const inputEl = shadow.querySelector('input');
305
- if (!inputEl)
306
- return;
307
- // Remove all event listeners using stored handler references
308
- if (this._inputHandler) {
309
- inputEl.removeEventListener('input', this._inputHandler);
310
- this._inputHandler = null;
311
- }
312
- if (this._changeHandler) {
313
- inputEl.removeEventListener('change', this._changeHandler);
314
- this._changeHandler = null;
315
- }
316
- if (this._focusHandler) {
317
- inputEl.removeEventListener('focus', this._focusHandler);
318
- this._focusHandler = null;
319
- }
320
- if (this._blurHandler) {
321
- inputEl.removeEventListener('blur', this._blurHandler);
322
- this._blurHandler = null;
323
- }
324
- this._listenersSetup = false;
325
- }
326
- /**
327
- * Setup event listeners for input element
328
- * IMPORTANT: Only called ONCE, not on every render (like ClojureScript)
329
- */
330
- setupEventListeners() {
331
- if (this._listenersSetup) {
332
- return; // Already setup
333
- }
334
- const shadow = this.shadowRoot;
335
- const inputEl = shadow.querySelector('input');
336
- const wrapperEl = shadow.querySelector('.input-wrapper');
337
- if (!inputEl || !wrapperEl) {
338
- console.warn('[TyInput.setupEventListeners] ⚠️ Input element not found!');
339
- return;
340
- }
341
- // Create and store handler references for cleanup
342
- // Input event - update shadow value and form (with debounce support)
343
- this._inputHandler = (e) => {
344
- // Stop native event from propagating - only our custom event should bubble
345
- e.stopPropagation();
346
- e.stopImmediatePropagation();
347
- const target = e.target;
348
- const rawValue = target.value;
349
- // Parse to shadow value
350
- this._shadowValue = this.parseShadowValue(rawValue);
351
- // Update form value with shadow value
352
- this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
353
- // Clear existing timer
354
- if (this._inputDebounceTimer !== null) {
355
- clearTimeout(this._inputDebounceTimer);
356
- }
357
- // If debounce is set, debounce the event
358
- if (this.debounce > 0) {
359
- this._inputDebounceTimer = window.setTimeout(() => {
360
- // Use current value, not the captured rawValue
361
- this.dispatchInputEvent(inputEl.value, e);
362
- this._inputDebounceTimer = null;
363
- }, this.debounce);
364
- }
365
- else {
366
- // Fire immediately if no debounce
367
- this.dispatchInputEvent(rawValue, e);
368
- }
369
- };
370
- // Change event (with debounce support)
371
- this._changeHandler = (e) => {
372
- // Stop native event from propagating - only our custom event should bubble
373
- e.stopPropagation();
374
- e.stopImmediatePropagation();
375
- const target = e.target;
376
- const rawValue = target.value;
377
- // Parse to shadow value
378
- this._shadowValue = this.parseShadowValue(rawValue);
379
- // Update form value
380
- this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
381
- // Clear existing timer
382
- if (this._changeDebounceTimer !== null) {
383
- clearTimeout(this._changeDebounceTimer);
384
- }
385
- // If debounce is set, debounce the event
386
- if (this.debounce > 0) {
387
- this._changeDebounceTimer = window.setTimeout(() => {
388
- // Use current value, not the captured rawValue
389
- this.dispatchChangeEvent(inputEl.value, e);
390
- this._changeDebounceTimer = null;
391
- }, this.debounce);
392
- }
393
- else {
394
- // Fire immediately if no debounce
395
- this.dispatchChangeEvent(rawValue, e);
396
- }
397
- };
398
- // Focus event - show raw value for numeric types
399
- this._focusHandler = (e) => {
400
- this._isFocused = true;
401
- wrapperEl.classList.add('focused');
402
- // For numeric types, show raw shadow value
403
- if (shouldFormatType(this.type) && this._shadowValue !== null) {
404
- inputEl.value = String(this._shadowValue);
405
- }
406
- this.dispatchEvent(new CustomEvent('focus', {
407
- detail: { originalEvent: e },
408
- bubbles: true,
409
- composed: true
410
- }));
411
- };
412
- // Blur event - fire pending debounced events immediately, then show formatted value
413
- this._blurHandler = (e) => {
414
- const target = e.target;
415
- const rawValue = target.value;
416
- // Fire any pending debounced input event immediately on blur
417
- if (this._inputDebounceTimer !== null) {
418
- clearTimeout(this._inputDebounceTimer);
419
- this._inputDebounceTimer = null;
420
- this.dispatchInputEvent(rawValue, e);
421
- }
422
- // Fire any pending debounced change event immediately on blur
423
- if (this._changeDebounceTimer !== null) {
424
- clearTimeout(this._changeDebounceTimer);
425
- this._changeDebounceTimer = null;
426
- this.dispatchChangeEvent(rawValue, e);
427
- }
428
- this._isFocused = false;
429
- wrapperEl.classList.remove('focused');
430
- // For numeric types, show formatted value
431
- if (this.shouldFormat()) {
432
- inputEl.value = this.getDisplayValue();
433
- }
434
- this.dispatchEvent(new CustomEvent('blur', {
435
- detail: { originalEvent: e },
436
- bubbles: true,
437
- composed: true
438
- }));
439
- };
440
- // Add event listeners
441
- inputEl.addEventListener('input', this._inputHandler);
442
- inputEl.addEventListener('change', this._changeHandler);
443
- inputEl.addEventListener('focus', this._focusHandler);
444
- inputEl.addEventListener('blur', this._blurHandler);
445
- this._listenersSetup = true;
446
- }
447
- /**
448
- * Render the input component with wrapper and slots
449
- * Phase C: Uses getDisplayValue() for formatted output
450
- *
451
- */
452
- render() {
453
- const shadow = this.shadowRoot;
454
- const existingInput = shadow.querySelector('input');
455
- const existingWrapper = shadow.querySelector('.input-wrapper');
456
- const existingLabel = shadow.querySelector('.input-label');
457
- const existingError = shadow.querySelector('.error-message');
458
- const classes = this.buildClassList();
459
- // Map input type (all numeric types use 'text' in DOM, others pass through)
460
- const inputType = ['password', 'email', 'tel', 'url'].includes(this.type)
461
- ? this.type
462
- : 'text';
463
- // Set inputmode for mobile keyboard hint
464
- const inputMode = shouldFormatType(this.type) ? 'decimal'
465
- : this.type === 'email' ? 'email'
466
- : this.type === 'tel' ? 'tel'
467
- : this.type === 'url' ? 'url'
468
- : undefined;
469
- // Get display value (formatted or raw based on focus)
470
- const displayValue = this.getDisplayValue();
471
- // If input exists, just update properties (like ClojureScript does)
472
- if (existingInput && existingWrapper) {
473
- existingInput.type = inputType;
474
- existingInput.value = displayValue;
475
- existingInput.placeholder = this.placeholder;
476
- existingInput.name = this.name;
477
- if (inputMode)
478
- existingInput.inputMode = inputMode;
479
- else
480
- existingInput.removeAttribute('inputmode');
481
- // Update wrapper classes
482
- existingWrapper.className = `input-wrapper ${classes}`;
483
- // Set disabled property AND manage attribute
484
- existingInput.disabled = this.disabled;
485
- if (this.disabled) {
486
- existingInput.setAttribute('disabled', '');
487
- }
488
- else {
489
- existingInput.removeAttribute('disabled');
490
- }
491
- // Set required property AND manage attribute
492
- existingInput.required = this.required;
493
- if (this.required) {
494
- existingInput.setAttribute('required', '');
495
- }
496
- else {
497
- existingInput.removeAttribute('required');
498
- }
499
- // ===== BUG FIX: Dynamic label creation =====
500
- // Update or CREATE label if needed
501
- if (this.label) {
502
- if (existingLabel) {
503
- // Label exists, just update it
504
- existingLabel.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
505
- existingLabel.style.display = 'flex';
506
- }
507
- else {
508
- // Label doesn't exist but we need one - CREATE IT!
509
- const labelEl = document.createElement('label');
510
- labelEl.className = 'input-label';
511
- labelEl.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
512
- // Insert label BEFORE the input-wrapper
513
- const container = shadow.querySelector('.input-container');
514
- if (container) {
515
- container.insertBefore(labelEl, existingWrapper);
516
- }
517
- }
518
- }
519
- else if (existingLabel) {
520
- // No label text, hide existing label
521
- ;
522
- existingLabel.style.display = 'none';
523
- }
524
- // Update error message
525
- if (this.error) {
526
- if (existingError) {
527
- existingError.textContent = this.error;
528
- }
529
- else {
530
- const errorEl = document.createElement('div');
531
- errorEl.className = 'error-message';
532
- errorEl.textContent = this.error;
533
- shadow.querySelector('.input-container')?.appendChild(errorEl);
534
- }
535
- }
536
- else if (existingError) {
537
- existingError.remove();
538
- }
539
- }
540
- else {
541
- // Create initial structure with wrapper and slots
542
- const labelHtml = this.label ? `
543
- <label class="input-label">
544
- ${this.label}
545
- ${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}
546
- </label>
547
- ` : '';
548
- const errorHtml = this.error ? `
549
- <div class="error-message">${this.error}</div>
550
- ` : '';
551
- shadow.innerHTML = `
552
- <div class="input-container">
553
- ${labelHtml}
554
- <div class="input-wrapper ${classes}">
555
- <slot name="start"></slot>
556
- <input
557
- type="${inputType}"
558
- value="${displayValue}"
559
- placeholder="${this.placeholder}"
560
- name="${this.name}"
561
- ${inputMode ? `inputmode="${inputMode}"` : ''}
562
- />
563
- <slot name="end"></slot>
564
- </div>
565
- ${errorHtml}
566
- </div>
567
- `;
568
- // Set boolean properties after creating element
569
- const inputEl = shadow.querySelector('input');
570
- inputEl.disabled = this.disabled;
571
- inputEl.required = this.required;
572
- // Setup event listeners ONCE
573
- this.setupEventListeners();
574
- }
575
- }
13
+ constructor() {
14
+ super();
15
+ this._shadowValue = null;
16
+ this._isFocused = false;
17
+ this._listenersSetup = false;
18
+ this._customFlavorSheet = null;
19
+ this._inputHandler = null;
20
+ this._changeHandler = null;
21
+ this._focusHandler = null;
22
+ this._blurHandler = null;
23
+ this._inputDebounceTimer = null;
24
+ this._changeDebounceTimer = null;
25
+ this._implicitSubmit = (e) => {
26
+ if (e.key !== 'Enter' || e.isComposing || e.defaultPrevented)
27
+ return;
28
+ const form = this._internals.form;
29
+ if (!form)
30
+ return;
31
+ const controls = Array.from(form.elements);
32
+ const isSubmitter = (el) => (el instanceof HTMLButtonElement && el.type === 'submit') ||
33
+ (el instanceof HTMLInputElement && (el.type === 'submit' || el.type === 'image')) ||
34
+ (el.tagName === 'TY-BUTTON' && !['button', 'reset'].includes(el.getAttribute('type') ?? ''));
35
+ const submitter = controls.find(isSubmitter);
36
+ if (submitter) {
37
+ if (submitter.disabled || submitter.hasAttribute('disabled'))
38
+ return;
39
+ e.preventDefault();
40
+ const target = submitter.tagName === 'TY-BUTTON'
41
+ ? submitter.shadowRoot?.querySelector('button') ?? submitter
42
+ : submitter;
43
+ target.click();
44
+ return;
45
+ }
46
+ const textFields = controls.filter((el) => el.tagName === 'TY-INPUT' ||
47
+ (el instanceof HTMLInputElement && !['button', 'checkbox', 'radio', 'file', 'hidden', 'image', 'reset', 'submit', 'range', 'color'].includes(el.type)));
48
+ if (textFields.length === 1) {
49
+ e.preventDefault();
50
+ form.requestSubmit();
51
+ }
52
+ };
53
+ const shadow = this.shadowRoot;
54
+ ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
55
+ }
56
+ onConnect() {
57
+ if (!this._rendered)
58
+ this.initializeShadowValue();
59
+ this._localeObserver = observeLocaleChanges(this, () => {
60
+ this.render();
61
+ });
62
+ this._syncCustomFlavor();
63
+ if (this._rendered) {
64
+ this.render();
65
+ this.setupEventListeners();
66
+ }
67
+ }
68
+ _syncCustomFlavor() {
69
+ this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => inputCustomFlavorCss(base));
70
+ }
71
+ onDisconnect() {
72
+ this.removeEventListeners();
73
+ if (this._localeObserver) {
74
+ this._localeObserver();
75
+ this._localeObserver = undefined;
76
+ }
77
+ if (this._inputDebounceTimer !== null) {
78
+ clearTimeout(this._inputDebounceTimer);
79
+ this._inputDebounceTimer = null;
80
+ }
81
+ if (this._changeDebounceTimer !== null) {
82
+ clearTimeout(this._changeDebounceTimer);
83
+ this._changeDebounceTimer = null;
84
+ }
85
+ }
86
+ onPropertiesChanged(changes) {
87
+ for (const { name, newValue } of changes) {
88
+ switch (name) {
89
+ case 'flavor':
90
+ this._syncCustomFlavor();
91
+ break;
92
+ case 'value':
93
+ this._shadowValue = this.parseShadowValue(newValue || '');
94
+ break;
95
+ case 'type':
96
+ const currentValue = this.getProperty('value') || '';
97
+ this._shadowValue = this.parseShadowValue(currentValue);
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ onFormReset() {
103
+ this._shadowValue = null;
104
+ this.initializeShadowValue();
105
+ this._isFocused = false;
106
+ if (this._inputDebounceTimer !== null) {
107
+ clearTimeout(this._inputDebounceTimer);
108
+ this._inputDebounceTimer = null;
109
+ }
110
+ if (this._changeDebounceTimer !== null) {
111
+ clearTimeout(this._changeDebounceTimer);
112
+ this._changeDebounceTimer = null;
113
+ }
114
+ this.render();
115
+ }
116
+ getFormValue() {
117
+ const formValue = this._shadowValue !== null ? String(this._shadowValue) : '';
118
+ return formValue;
119
+ }
120
+ initializeShadowValue() {
121
+ const currentValue = this.getProperty('value');
122
+ if (currentValue) {
123
+ this._shadowValue = this.parseShadowValue(currentValue);
124
+ this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
125
+ }
126
+ else {
127
+ this._internals.setFormValue('');
128
+ }
129
+ }
130
+ parseShadowValue(value) {
131
+ if (!value || typeof value !== 'string' || value.trim() === '')
132
+ return null;
133
+ if (shouldFormatType(this.type)) {
134
+ const parsed = parseNumericValue(value);
135
+ if (parsed !== null && this.precision === 0) {
136
+ return Math.round(parsed);
137
+ }
138
+ return parsed;
139
+ }
140
+ return value;
141
+ }
142
+ shouldFormat() {
143
+ return shouldFormatType(this.type) &&
144
+ !this._isFocused &&
145
+ this._shadowValue !== null &&
146
+ typeof this._shadowValue === 'number';
147
+ }
148
+ getFormatConfig() {
149
+ return {
150
+ type: this.type,
151
+ locale: this.locale,
152
+ currency: this.currency,
153
+ precision: this.precision
154
+ };
155
+ }
156
+ getDisplayValue() {
157
+ if (this.shouldFormat()) {
158
+ let valueToFormat = this._shadowValue;
159
+ if (this.type === 'percent') {
160
+ valueToFormat = valueToFormat / 100;
161
+ }
162
+ return formatNumber(valueToFormat, this.getFormatConfig());
163
+ }
164
+ return this._shadowValue !== null ? String(this._shadowValue) : '';
165
+ }
166
+ get type() { return this.getProperty('type'); }
167
+ set type(v) { this.setProperty('type', v); }
168
+ get value() {
169
+ return this._shadowValue !== null ? String(this._shadowValue) : '';
170
+ }
171
+ set value(v) { this.setProperty('value', v); }
172
+ get name() { return this.getProperty('name'); }
173
+ set name(v) { this.setProperty('name', v); }
174
+ get placeholder() { return this.getProperty('placeholder'); }
175
+ set placeholder(v) { this.setProperty('placeholder', v); }
176
+ get label() { return this.getProperty('label'); }
177
+ set label(v) { this.setProperty('label', v); }
178
+ get disabled() { return this.getProperty('disabled'); }
179
+ set disabled(v) { this.setProperty('disabled', v); }
180
+ focus(options) {
181
+ this.shadowRoot?.querySelector('input')?.focus(options);
182
+ }
183
+ get required() { return this.getProperty('required'); }
184
+ set required(v) { this.setProperty('required', v); }
185
+ get pattern() { return this.getProperty('pattern'); }
186
+ set pattern(v) { this.setProperty('pattern', v ?? ''); }
187
+ get minLength() { return toLimit(this.getProperty('minlength')) ?? -1; }
188
+ set minLength(v) { this.setProperty('minlength', v == null || v < 0 ? '' : String(v)); }
189
+ get maxLength() { return toLimit(this.getProperty('maxlength')) ?? -1; }
190
+ set maxLength(v) { this.setProperty('maxlength', v == null || v < 0 ? '' : String(v)); }
191
+ get min() { return this.getProperty('min'); }
192
+ set min(v) { this.setProperty('min', v == null ? '' : String(v)); }
193
+ get max() { return this.getProperty('max'); }
194
+ set max(v) { this.setProperty('max', v == null ? '' : String(v)); }
195
+ get tooShortMessage() { return this.getProperty('tooShortMessage'); }
196
+ set tooShortMessage(v) { this.setProperty('tooShortMessage', v ?? ''); }
197
+ get tooLongMessage() { return this.getProperty('tooLongMessage'); }
198
+ set tooLongMessage(v) { this.setProperty('tooLongMessage', v ?? ''); }
199
+ get error() { return this.getProperty('error'); }
200
+ set error(v) { this.setProperty('error', v); }
201
+ get size() { return this.getProperty('size'); }
202
+ set size(v) { this.setProperty('size', v); }
203
+ get flavor() { return this.getProperty('flavor'); }
204
+ set flavor(v) { this.setProperty('flavor', v); }
205
+ get currency() { return this.getProperty('currency'); }
206
+ set currency(v) { this.setProperty('currency', v); }
207
+ get locale() {
208
+ return getEffectiveLocale(this, this.getProperty('locale'));
209
+ }
210
+ set locale(v) { this.setProperty('locale', v); }
211
+ get precision() { return this.getProperty('precision'); }
212
+ set precision(v) { this.setProperty('precision', v); }
213
+ get debounce() { return this.getProperty('debounce'); }
214
+ set debounce(v) { this.setProperty('debounce', v); }
215
+ get form() {
216
+ return this._internals.form;
217
+ }
218
+ buildClassList() {
219
+ const classes = [];
220
+ if (this.disabled)
221
+ classes.push('disabled');
222
+ if (this.required)
223
+ classes.push('required');
224
+ if (this.error)
225
+ classes.push('error');
226
+ return classes.join(' ');
227
+ }
228
+ dispatchInputEvent(rawValue, originalEvent) {
229
+ this.dispatchEvent(new CustomEvent('input', {
230
+ detail: {
231
+ value: this._shadowValue,
232
+ formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
233
+ rawValue: rawValue,
234
+ originalEvent: originalEvent
235
+ },
236
+ bubbles: true,
237
+ composed: true
238
+ }));
239
+ }
240
+ dispatchChangeEvent(rawValue, originalEvent) {
241
+ this.dispatchEvent(new CustomEvent('change', {
242
+ detail: {
243
+ value: this._shadowValue,
244
+ formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
245
+ rawValue: rawValue,
246
+ originalEvent: originalEvent
247
+ },
248
+ bubbles: true,
249
+ composed: true
250
+ }));
251
+ }
252
+ removeEventListeners() {
253
+ if (!this._listenersSetup)
254
+ return;
255
+ const shadow = this.shadowRoot;
256
+ if (!shadow)
257
+ return;
258
+ const inputEl = shadow.querySelector('input');
259
+ if (!inputEl)
260
+ return;
261
+ if (this._inputHandler) {
262
+ inputEl.removeEventListener('input', this._inputHandler);
263
+ this._inputHandler = null;
264
+ }
265
+ if (this._changeHandler) {
266
+ inputEl.removeEventListener('change', this._changeHandler);
267
+ this._changeHandler = null;
268
+ }
269
+ if (this._focusHandler) {
270
+ inputEl.removeEventListener('focus', this._focusHandler);
271
+ this._focusHandler = null;
272
+ }
273
+ if (this._blurHandler) {
274
+ inputEl.removeEventListener('blur', this._blurHandler);
275
+ this._blurHandler = null;
276
+ }
277
+ inputEl.removeEventListener('keydown', this._implicitSubmit);
278
+ this._listenersSetup = false;
279
+ }
280
+ setupEventListeners() {
281
+ if (this._listenersSetup) {
282
+ return;
283
+ }
284
+ const shadow = this.shadowRoot;
285
+ const inputEl = shadow.querySelector('input');
286
+ const wrapperEl = shadow.querySelector('.input-wrapper');
287
+ if (!inputEl || !wrapperEl) {
288
+ console.warn('[TyInput.setupEventListeners] ⚠️ Input element not found!');
289
+ return;
290
+ }
291
+ this._inputHandler = (e) => {
292
+ this._userEdited = true;
293
+ e.stopPropagation();
294
+ e.stopImmediatePropagation();
295
+ const target = e.target;
296
+ const rawValue = target.value;
297
+ this._shadowValue = this.parseShadowValue(rawValue);
298
+ this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
299
+ this.updateValidity();
300
+ if (this._inputDebounceTimer !== null) {
301
+ clearTimeout(this._inputDebounceTimer);
302
+ }
303
+ if (this.debounce > 0) {
304
+ this._inputDebounceTimer = window.setTimeout(() => {
305
+ this.dispatchInputEvent(inputEl.value, e);
306
+ this._inputDebounceTimer = null;
307
+ }, this.debounce);
308
+ }
309
+ else {
310
+ this.dispatchInputEvent(rawValue, e);
311
+ }
312
+ };
313
+ this._changeHandler = (e) => {
314
+ e.stopPropagation();
315
+ e.stopImmediatePropagation();
316
+ const target = e.target;
317
+ const rawValue = target.value;
318
+ this._shadowValue = this.parseShadowValue(rawValue);
319
+ this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
320
+ this.updateValidity();
321
+ if (this._changeDebounceTimer !== null) {
322
+ clearTimeout(this._changeDebounceTimer);
323
+ }
324
+ if (this.debounce > 0) {
325
+ this._changeDebounceTimer = window.setTimeout(() => {
326
+ this.dispatchChangeEvent(inputEl.value, e);
327
+ this._changeDebounceTimer = null;
328
+ }, this.debounce);
329
+ }
330
+ else {
331
+ this.dispatchChangeEvent(rawValue, e);
332
+ }
333
+ };
334
+ this._focusHandler = (e) => {
335
+ this._isFocused = true;
336
+ wrapperEl.classList.add('focused');
337
+ if (shouldFormatType(this.type) && this._shadowValue !== null) {
338
+ inputEl.value = String(this._shadowValue);
339
+ }
340
+ this.dispatchEvent(new CustomEvent('focus', {
341
+ detail: { originalEvent: e },
342
+ bubbles: true,
343
+ composed: true
344
+ }));
345
+ };
346
+ this._blurHandler = (e) => {
347
+ const target = e.target;
348
+ const rawValue = target.value;
349
+ if (this._inputDebounceTimer !== null) {
350
+ clearTimeout(this._inputDebounceTimer);
351
+ this._inputDebounceTimer = null;
352
+ this.dispatchInputEvent(rawValue, e);
353
+ }
354
+ if (this._changeDebounceTimer !== null) {
355
+ clearTimeout(this._changeDebounceTimer);
356
+ this._changeDebounceTimer = null;
357
+ this.dispatchChangeEvent(rawValue, e);
358
+ }
359
+ this._isFocused = false;
360
+ wrapperEl.classList.remove('focused');
361
+ if (this._userEdited)
362
+ this.revealValidity();
363
+ if (this.shouldFormat()) {
364
+ inputEl.value = this.getDisplayValue();
365
+ }
366
+ this.dispatchEvent(new CustomEvent('blur', {
367
+ detail: { originalEvent: e },
368
+ bubbles: true,
369
+ composed: true
370
+ }));
371
+ };
372
+ inputEl.addEventListener('input', this._inputHandler);
373
+ inputEl.addEventListener('change', this._changeHandler);
374
+ inputEl.addEventListener('focus', this._focusHandler);
375
+ inputEl.addEventListener('blur', this._blurHandler);
376
+ inputEl.addEventListener('keydown', this._implicitSubmit);
377
+ this._listenersSetup = true;
378
+ }
379
+ render() {
380
+ const shadow = this.shadowRoot;
381
+ const existingInput = shadow.querySelector('input');
382
+ const existingWrapper = shadow.querySelector('.input-wrapper');
383
+ const existingLabel = shadow.querySelector('.ty-field-label');
384
+ const existingError = shadow.querySelector('.error-message');
385
+ const classes = this.buildClassList();
386
+ const focused = !!existingInput && shadow.activeElement === existingInput;
387
+ if (!focused)
388
+ this._isFocused = false;
389
+ const inputType = ['password', 'email', 'tel', 'url'].includes(this.type)
390
+ ? this.type
391
+ : 'text';
392
+ const inputMode = shouldFormatType(this.type) ? 'decimal'
393
+ : this.type === 'email' ? 'email'
394
+ : this.type === 'tel' ? 'tel'
395
+ : this.type === 'url' ? 'url'
396
+ : undefined;
397
+ const displayValue = this.getDisplayValue();
398
+ if (existingInput && existingWrapper) {
399
+ const revealed = inputType === 'password' &&
400
+ shadow.querySelector('.password-toggle')?.getAttribute('aria-pressed') === 'true';
401
+ existingInput.type = revealed ? 'text' : inputType;
402
+ if (existingInput.value !== displayValue)
403
+ existingInput.value = displayValue;
404
+ existingInput.placeholder = this.placeholder;
405
+ existingInput.name = this.name;
406
+ if (inputMode)
407
+ existingInput.inputMode = inputMode;
408
+ else
409
+ existingInput.removeAttribute('inputmode');
410
+ existingWrapper.className = `input-wrapper ${classes}`;
411
+ existingWrapper.classList.toggle('focused', focused);
412
+ existingInput.disabled = this.disabled;
413
+ if (this.disabled) {
414
+ existingInput.setAttribute('disabled', '');
415
+ }
416
+ else {
417
+ existingInput.removeAttribute('disabled');
418
+ }
419
+ existingInput.required = this.required;
420
+ if (this.required) {
421
+ existingInput.setAttribute('required', '');
422
+ }
423
+ else {
424
+ existingInput.removeAttribute('required');
425
+ }
426
+ this.syncConstraintAttributes(existingInput);
427
+ if (this.label)
428
+ existingInput.setAttribute('aria-label', this.label);
429
+ else
430
+ existingInput.removeAttribute('aria-label');
431
+ if (this.label) {
432
+ if (existingLabel) {
433
+ existingLabel.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
434
+ existingLabel.style.display = 'flex';
435
+ }
436
+ else {
437
+ const labelEl = document.createElement('label');
438
+ labelEl.className = 'ty-field-label';
439
+ labelEl.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
440
+ const container = shadow.querySelector('.input-container');
441
+ if (container) {
442
+ container.insertBefore(labelEl, existingWrapper);
443
+ }
444
+ }
445
+ }
446
+ else if (existingLabel) {
447
+ ;
448
+ existingLabel.style.display = 'none';
449
+ }
450
+ if (this.error) {
451
+ if (existingError) {
452
+ existingError.textContent = this.error;
453
+ }
454
+ else {
455
+ const errorEl = document.createElement('div');
456
+ errorEl.className = 'error-message';
457
+ errorEl.textContent = this.error;
458
+ shadow.querySelector('.input-container')?.appendChild(errorEl);
459
+ }
460
+ }
461
+ else if (existingError) {
462
+ existingError.remove();
463
+ }
464
+ }
465
+ else {
466
+ const labelHtml = this.label ? `
467
+ <label class="ty-field-label">
468
+ ${this.label}
469
+ ${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}
470
+ </label>
471
+ ` : '';
472
+ const errorHtml = this.error ? `
473
+ <div class="error-message">${this.error}</div>
474
+ ` : '';
475
+ shadow.innerHTML = `
476
+ <div class="input-container">
477
+ ${labelHtml}
478
+ <div class="input-wrapper ${classes}">
479
+ <slot name="start"></slot>
480
+ <input
481
+ type="${inputType}"
482
+ value="${displayValue}"
483
+ placeholder="${this.placeholder}"
484
+ name="${this.name}"
485
+ ${inputMode ? `inputmode="${inputMode}"` : ''}
486
+ />
487
+ <slot name="end"></slot>
488
+ ${inputType === 'password' ? `
489
+ <button class="password-toggle" type="button"
490
+ aria-label="Show password" aria-pressed="false">
491
+ ${EYE_ICON_SVG}
492
+ </button>` : ''}
493
+ </div>
494
+ ${errorHtml}
495
+ </div>
496
+ `;
497
+ const inputEl = shadow.querySelector('input');
498
+ inputEl.disabled = this.disabled;
499
+ inputEl.required = this.required;
500
+ this.syncConstraintAttributes(inputEl);
501
+ if (this.label)
502
+ inputEl.setAttribute('aria-label', this.label);
503
+ this.setupPasswordToggle();
504
+ this.setupEventListeners();
505
+ }
506
+ this.updateValidity();
507
+ }
508
+ setupPasswordToggle() {
509
+ const shadow = this.shadowRoot;
510
+ const toggle = shadow.querySelector('.password-toggle');
511
+ const inputEl = shadow.querySelector('input');
512
+ if (!toggle || !inputEl)
513
+ return;
514
+ toggle.addEventListener('mousedown', (e) => e.preventDefault());
515
+ toggle.addEventListener('click', () => {
516
+ const reveal = inputEl.type === 'password';
517
+ const { selectionStart, selectionEnd, selectionDirection } = inputEl;
518
+ inputEl.type = reveal ? 'text' : 'password';
519
+ if (selectionStart !== null && shadow.activeElement === inputEl) {
520
+ inputEl.getBoundingClientRect();
521
+ inputEl.setSelectionRange(selectionStart, selectionEnd, selectionDirection ?? undefined);
522
+ }
523
+ toggle.innerHTML = reveal ? EYE_OFF_ICON_SVG : EYE_ICON_SVG;
524
+ toggle.setAttribute('aria-label', reveal ? 'Hide password' : 'Show password');
525
+ toggle.setAttribute('aria-pressed', String(reveal));
526
+ });
527
+ }
528
+ syncConstraintAttributes(inputEl) {
529
+ const text = !shouldFormatType(this.type);
530
+ const set = (name, v) => text && v !== '' ? inputEl.setAttribute(name, v) : inputEl.removeAttribute(name);
531
+ set('pattern', this.pattern);
532
+ set('minlength', toLimit(this.getProperty('minlength')) != null ? String(this.minLength) : '');
533
+ set('maxlength', toLimit(this.getProperty('maxlength')) != null ? String(this.maxLength) : '');
534
+ }
535
+ updateValidity() {
536
+ const inputEl = this.shadowRoot?.querySelector('input');
537
+ if (this.disabled) {
538
+ this.applyValidity({});
539
+ return;
540
+ }
541
+ const current = inputEl ? inputEl.value : String(this.getProperty('value') ?? '');
542
+ if (current.trim() === '') {
543
+ if (this.required) {
544
+ this.applyValidity({ valueMissing: true }, nativeMessage('input', { type: 'text', required: true }), inputEl ?? undefined);
545
+ }
546
+ else {
547
+ this.applyValidity({});
548
+ }
549
+ return;
550
+ }
551
+ const flags = {};
552
+ const messages = [];
553
+ const fail = (flag, message) => {
554
+ flags[flag] = true;
555
+ messages.push(message);
556
+ };
557
+ if (shouldFormatType(this.type)) {
558
+ const n = typeof this._shadowValue === 'number' ? this._shadowValue : null;
559
+ if (n !== null && (this.min || this.max)) {
560
+ const { validity, message } = nativeValidity('input', { type: 'number', step: 'any', min: this.min, max: this.max }, String(n));
561
+ if (validity.rangeUnderflow)
562
+ fail('rangeUnderflow', message);
563
+ if (validity.rangeOverflow)
564
+ fail('rangeOverflow', message);
565
+ }
566
+ }
567
+ else {
568
+ if (inputEl?.validity.typeMismatch)
569
+ fail('typeMismatch', inputEl.validationMessage);
570
+ if (inputEl?.validity.patternMismatch)
571
+ fail('patternMismatch', inputEl.validationMessage);
572
+ const { tooShort, tooLong } = lengthValidity(current, {
573
+ minlength: this.getProperty('minlength'),
574
+ maxlength: this.getProperty('maxlength'),
575
+ tooShortMessage: this.tooShortMessage,
576
+ tooLongMessage: this.tooLongMessage,
577
+ }, inputEl);
578
+ if (tooShort)
579
+ fail('tooShort', tooShort);
580
+ if (tooLong)
581
+ fail('tooLong', tooLong);
582
+ }
583
+ this.applyValidity(flags, messages[0], inputEl ?? undefined);
584
+ }
576
585
  }
577
586
  TyInput.formAssociated = true;
578
- // ============================================================================
579
- // PROPERTY CONFIGURATION - Declarative property lifecycle
580
- // ============================================================================
581
587
  TyInput.properties = {
582
- // Core properties
583
- type: {
584
- type: 'string',
585
- visual: true,
586
- default: 'text',
587
- validate: (v) => {
588
- const validTypes = [
589
- 'text', 'email', 'password', 'number', 'tel', 'url',
590
- 'currency', 'percent', 'compact'
591
- ];
592
- return validTypes.includes(v);
593
- },
594
- coerce: (v) => {
595
- const validTypes = [
596
- 'text', 'email', 'password', 'number', 'tel', 'url',
597
- 'currency', 'percent', 'compact'
598
- ];
599
- if (!validTypes.includes(v)) {
600
- console.warn(`[ty-input] Invalid type '${v}'. Using 'text'.`);
601
- return 'text';
602
- }
603
- return v;
604
- }
605
- },
606
- value: {
607
- type: 'string',
608
- visual: true,
609
- formValue: true,
610
- emitChange: true,
611
- default: ''
612
- },
613
- name: {
614
- type: 'string',
615
- default: ''
616
- },
617
- placeholder: {
618
- type: 'string',
619
- visual: true,
620
- default: ''
621
- },
622
- label: {
623
- type: 'string',
624
- visual: true,
625
- default: ''
626
- },
627
- disabled: {
628
- type: 'boolean',
629
- visual: true,
630
- default: false
631
- },
632
- required: {
633
- type: 'boolean',
634
- visual: true,
635
- default: false
636
- },
637
- error: {
638
- type: 'string',
639
- visual: true,
640
- default: ''
641
- },
642
- size: {
643
- type: 'string',
644
- visual: true,
645
- default: 'md',
646
- validate: (v) => ['xs', 'sm', 'md', 'lg', 'xl'].includes(v),
647
- coerce: (v) => {
648
- if (!['xs', 'sm', 'md', 'lg', 'xl'].includes(v)) {
649
- console.warn(`[ty-input] Invalid size '${v}'. Using 'md'.`);
650
- return 'md';
651
- }
652
- return v;
653
- }
654
- },
655
- flavor: {
656
- type: 'string',
657
- visual: true,
658
- default: 'neutral',
659
- validate: (v) => {
660
- const valid = ['primary', 'secondary', 'success', 'danger', 'warning', 'neutral'];
661
- return valid.includes(v);
662
- },
663
- coerce: (v) => {
664
- const valid = ['primary', 'secondary', 'success', 'danger', 'warning', 'neutral'];
665
- if (!valid.includes(v)) {
666
- console.warn(`[ty-input] Invalid flavor '${v}'. Using 'neutral'.`);
667
- return 'neutral';
668
- }
669
- return v;
670
- }
671
- },
672
- // Numeric formatting properties
673
- currency: {
674
- type: 'string',
675
- visual: true,
676
- default: 'USD'
677
- },
678
- locale: {
679
- type: 'string',
680
- visual: true,
681
- default: 'en-US'
682
- },
683
- precision: {
684
- type: 'number',
685
- visual: true,
686
- default: undefined,
687
- validate: (v) => {
688
- if (v === undefined || v === null)
689
- return true;
690
- return typeof v === 'number' && v >= 0 && v <= 10;
691
- },
692
- coerce: (v) => {
693
- if (v === undefined || v === null)
694
- return undefined;
695
- const num = Number(v);
696
- if (isNaN(num))
697
- return undefined;
698
- return Math.max(0, Math.min(10, Math.floor(num)));
699
- }
700
- },
701
- // Debounce property
702
- debounce: {
703
- type: 'number',
704
- default: 0,
705
- validate: (v) => {
706
- const num = Number(v);
707
- return !isNaN(num) && num >= 0 && num <= 5000;
708
- },
709
- coerce: (v) => {
710
- const num = Number(v);
711
- if (isNaN(num))
712
- return 0;
713
- return Math.max(0, Math.min(5000, Math.floor(num)));
714
- }
715
- }
588
+ type: {
589
+ type: 'string',
590
+ visual: true,
591
+ default: 'text',
592
+ validate: (v) => {
593
+ const validTypes = [
594
+ 'text', 'email', 'password', 'number', 'tel', 'url',
595
+ 'currency', 'percent', 'compact'
596
+ ];
597
+ return validTypes.includes(v);
598
+ },
599
+ coerce: (v) => {
600
+ const validTypes = [
601
+ 'text', 'email', 'password', 'number', 'tel', 'url',
602
+ 'currency', 'percent', 'compact'
603
+ ];
604
+ if (!validTypes.includes(v)) {
605
+ console.warn(`[ty-input] Invalid type '${v}'. Using 'text'.`);
606
+ return 'text';
607
+ }
608
+ return v;
609
+ }
610
+ },
611
+ value: {
612
+ type: 'string',
613
+ visual: true,
614
+ formValue: true,
615
+ emitChange: true,
616
+ default: ''
617
+ },
618
+ name: {
619
+ type: 'string',
620
+ default: ''
621
+ },
622
+ placeholder: {
623
+ type: 'string',
624
+ visual: true,
625
+ default: ''
626
+ },
627
+ label: {
628
+ type: 'string',
629
+ visual: true,
630
+ default: ''
631
+ },
632
+ disabled: {
633
+ type: 'boolean',
634
+ visual: true,
635
+ default: false
636
+ },
637
+ required: {
638
+ type: 'boolean',
639
+ visual: true,
640
+ default: false
641
+ },
642
+ pattern: {
643
+ type: 'string',
644
+ visual: true,
645
+ default: ''
646
+ },
647
+ minlength: {
648
+ type: 'string',
649
+ visual: true,
650
+ default: ''
651
+ },
652
+ maxlength: {
653
+ type: 'string',
654
+ visual: true,
655
+ default: ''
656
+ },
657
+ min: {
658
+ type: 'string',
659
+ visual: true,
660
+ default: ''
661
+ },
662
+ max: {
663
+ type: 'string',
664
+ visual: true,
665
+ default: ''
666
+ },
667
+ tooShortMessage: {
668
+ type: 'string',
669
+ visual: true,
670
+ default: ''
671
+ },
672
+ tooLongMessage: {
673
+ type: 'string',
674
+ visual: true,
675
+ default: ''
676
+ },
677
+ error: {
678
+ type: 'string',
679
+ visual: true,
680
+ default: ''
681
+ },
682
+ size: {
683
+ type: 'string',
684
+ visual: true,
685
+ default: DEFAULT_SIZE,
686
+ validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
687
+ coerce: (v) => {
688
+ if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
689
+ console.warn(`[ty-input] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
690
+ return DEFAULT_SIZE;
691
+ }
692
+ return v;
693
+ }
694
+ },
695
+ flavor: {
696
+ type: 'string',
697
+ visual: true,
698
+ default: 'neutral'
699
+ },
700
+ currency: {
701
+ type: 'string',
702
+ visual: true,
703
+ default: 'USD'
704
+ },
705
+ locale: {
706
+ type: 'string',
707
+ visual: true,
708
+ default: 'en-US'
709
+ },
710
+ precision: {
711
+ type: 'number',
712
+ visual: true,
713
+ default: undefined,
714
+ validate: (v) => {
715
+ if (v === undefined || v === null)
716
+ return true;
717
+ return typeof v === 'number' && v >= 0 && v <= 10;
718
+ },
719
+ coerce: (v) => {
720
+ if (v === undefined || v === null)
721
+ return undefined;
722
+ const num = Number(v);
723
+ if (isNaN(num))
724
+ return undefined;
725
+ return Math.max(0, Math.min(10, Math.floor(num)));
726
+ }
727
+ },
728
+ debounce: {
729
+ type: 'number',
730
+ default: 0,
731
+ validate: (v) => {
732
+ const num = Number(v);
733
+ return !isNaN(num) && num >= 0 && num <= 5000;
734
+ },
735
+ coerce: (v) => {
736
+ const num = Number(v);
737
+ if (isNaN(num))
738
+ return 0;
739
+ return Math.max(0, Math.min(5000, Math.floor(num)));
740
+ }
741
+ }
716
742
  };
717
- // Register the custom element
718
743
  if (!customElements.get('ty-input')) {
719
- customElements.define('ty-input', TyInput);
744
+ customElements.define('ty-input', TyInput);
720
745
  }
721
- //# sourceMappingURL=input.js.map