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,585 +1,535 @@
1
- /**
2
- * ty-textarea - Enhanced textarea component with auto-resize functionality
3
- *
4
- * Features:
5
- * - Auto-resize based on content
6
- * - Form-associated custom element
7
- * - Min/max height constraints
8
- * - Size variants (xs, sm, md, lg, xl)
9
- * - Validation states (error, required)
10
- * - Manual resize control options
11
- * - Accessibility support
12
- *
13
- * @example
14
- * ```html
15
- * <!-- Basic usage -->
16
- * <ty-textarea label="Description" placeholder="Enter details..."></ty-textarea>
17
- *
18
- * <!-- With validation -->
19
- * <ty-textarea
20
- * label="Bio"
21
- * required
22
- * error="Bio is required"
23
- * size="lg">
24
- * </ty-textarea>
25
- *
26
- * <!-- With height constraints -->
27
- * <ty-textarea
28
- * min-height="100px"
29
- * max-height="300px"
30
- * placeholder="Auto-resizing textarea">
31
- * </ty-textarea>
32
- *
33
- * <!-- Manual resize control -->
34
- * <ty-textarea resize="vertical"></ty-textarea>
35
- * ```
36
- *
37
- * @fires {CustomEvent<{value: string, originalEvent: Event}>} input - Emitted on input
38
- * @fires {CustomEvent<{value: string, originalEvent: Event}>} change - Emitted on change
39
- */
1
+ import { DEFAULT_SIZE } from '../types/common.js';
40
2
  import { TyComponent } from '../base/ty-component.js';
41
3
  import { ensureStyles } from '../utils/styles.js';
42
4
  import { textareaStyles } from '../styles/textarea.js';
43
5
  import { CustomScrollbar, isCustomScrollbarEnabled } from '../utils/custom-scrollbar.js';
44
6
  import { customScrollbarStyles } from '../styles/custom-scrollbar.js';
45
- /**
46
- * Required icon SVG (matches input.ts)
47
- */
48
- const REQUIRED_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>`;
7
+ import { nativeMessage, lengthValidity, toLimit } from '../utils/validity.js';
8
+ import { REQUIRED_ICON_SVG } from '../utils/icons.js';
49
9
  export class TyTextarea extends TyComponent {
50
- constructor() {
51
- super(); // TyComponent handles attachInternals() and attachShadow()
52
- // ============================================================================
53
- // INTERNAL STATE - Not managed by PropertyManager
54
- // NOTE: _internals provided by TyComponent base class
55
- // ============================================================================
56
- // DOM element references
57
- this._textareaEl = null;
58
- this._dummyEl = null;
59
- this._scrollbar = null;
60
- // Focus state
61
- this._isFocused = false;
62
- /**
63
- * Handle textarea input event
64
- */
65
- this.handleInputEvent = (e) => {
66
- const target = e.target;
67
- const newValue = target.value;
68
- // Update value via property (triggers proper lifecycle)
69
- this.value = newValue;
70
- // Trigger resize after state update
71
- if (this._textareaEl && this._dummyEl) {
72
- this.resizeTextarea(this._textareaEl, this._dummyEl);
73
- }
74
- // Emit custom events
75
- this.emitValueEvents(e);
76
- };
77
- /**
78
- * Handle textarea focus event
79
- */
80
- this.handleFocusEvent = () => {
81
- this._isFocused = true;
82
- };
83
- /**
84
- * Handle textarea blur event
85
- */
86
- this.handleBlurEvent = () => {
87
- this._isFocused = false;
88
- };
89
- // Apply styles to shadow root
90
- const shadow = this.shadowRoot;
91
- ensureStyles(shadow, { css: textareaStyles, id: 'ty-textarea' });
92
- // Add custom scrollbar styles
93
- if (isCustomScrollbarEnabled()) {
94
- ensureStyles(shadow, { css: customScrollbarStyles, id: 'ty-custom-scrollbar' });
95
- }
96
- }
97
- // observedAttributes auto-generated by TyComponent from properties config
98
- // ============================================================================
99
- // TYCOMPONENT LIFECYCLE HOOKS
100
- // ============================================================================
101
- /**
102
- * Called when component connects to DOM
103
- * TyComponent already handled pre-connection property capture
104
- */
105
- onConnect() {
106
- // No special initialization needed - TyComponent handles everything
107
- // Just render the component
108
- }
109
- /**
110
- * Called when component disconnects from DOM
111
- */
112
- onDisconnect() {
113
- // Cleanup scrollbar
114
- this._destroyScrollbar();
115
- // Cleanup event listeners if needed
116
- if (this._textareaEl) {
117
- const newTextarea = this._textareaEl.cloneNode(true);
118
- this._textareaEl.parentNode?.replaceChild(newTextarea, this._textareaEl);
119
- this._textareaEl = null;
120
- }
121
- this._dummyEl = null;
122
- }
123
- /**
124
- * Handle property changes - called BEFORE render
125
- * This replaces the old attributeChangedCallback logic
126
- */
127
- onPropertiesChanged(changes) {
128
- // No special handling needed for textarea
129
- // All property changes will trigger render() automatically if marked as visual
130
- }
131
- /**
132
- * Override form value to return current value
133
- */
134
- getFormValue() {
135
- return this.getProperty('value') || null;
136
- }
137
- // ============================================================================
138
- // PROPERTY ACCESSORS - Simplified with TyComponent
139
- // ============================================================================
140
- get value() { return this.getProperty('value'); }
141
- set value(v) { this.setProperty('value', v); }
142
- get name() { return this.getProperty('name'); }
143
- set name(v) { this.setProperty('name', v); }
144
- get placeholder() { return this.getProperty('placeholder'); }
145
- set placeholder(v) { this.setProperty('placeholder', v); }
146
- get label() { return this.getProperty('label'); }
147
- set label(v) { this.setProperty('label', v); }
148
- get disabled() { return this.getProperty('disabled'); }
149
- set disabled(v) { this.setProperty('disabled', v); }
150
- get required() { return this.getProperty('required'); }
151
- set required(v) { this.setProperty('required', v); }
152
- get error() { return this.getProperty('error'); }
153
- set error(v) { this.setProperty('error', v); }
154
- get size() {
155
- return this.getProperty('size');
156
- }
157
- set size(v) {
158
- this.setProperty('size', v);
159
- }
160
- get rows() { return this.getProperty('rows'); }
161
- set rows(v) { this.setProperty('rows', v); }
162
- get cols() { return this.getProperty('cols'); }
163
- set cols(v) { this.setProperty('cols', v); }
164
- get resize() {
165
- return this.getProperty('resize');
166
- }
167
- set resize(v) {
168
- this.setProperty('resize', v);
169
- }
170
- get minHeight() { return this.getProperty('minHeight'); }
171
- set minHeight(v) { this.setProperty('minHeight', v); }
172
- get maxHeight() { return this.getProperty('maxHeight'); }
173
- set maxHeight(v) { this.setProperty('maxHeight', v); }
174
- // ===== HELPER METHODS =====
175
- /**
176
- * Extract font-related CSS properties from element
177
- */
178
- getFontStyle(el) {
179
- const computedStyle = window.getComputedStyle(el);
180
- return {
181
- fontFamily: computedStyle.fontFamily,
182
- fontSize: computedStyle.fontSize,
183
- fontWeight: computedStyle.fontWeight,
184
- lineHeight: computedStyle.lineHeight,
185
- letterSpacing: computedStyle.letterSpacing,
186
- fontStyle: computedStyle.fontStyle
187
- };
188
- }
189
- /**
190
- * Extract spacing-related CSS properties from element
191
- */
192
- getSpacingStyle(el) {
193
- const computedStyle = window.getComputedStyle(el);
194
- return {
195
- padding: computedStyle.padding,
196
- paddingTop: computedStyle.paddingTop,
197
- paddingRight: computedStyle.paddingRight,
198
- paddingBottom: computedStyle.paddingBottom,
199
- paddingLeft: computedStyle.paddingLeft,
200
- margin: computedStyle.margin,
201
- borderWidth: computedStyle.borderWidth
202
- };
203
- }
204
- /**
205
- * Setup the hidden dummy element for height measurement
206
- */
207
- setupDummyElement(textareaEl) {
208
- const root = this.shadowRoot;
209
- const existingDummy = root.querySelector('.textarea-dummy');
210
- // Remove existing dummy if present
211
- if (existingDummy) {
212
- existingDummy.remove();
213
- }
214
- // Create new dummy element
215
- const dummyEl = document.createElement('pre');
216
- const fontStyle = this.getFontStyle(textareaEl);
217
- const spacingStyle = this.getSpacingStyle(textareaEl);
218
- // Set dummy element class
219
- dummyEl.className = 'textarea-dummy';
220
- // Apply styles to match textarea
221
- const style = dummyEl.style;
222
- style.position = 'absolute';
223
- style.top = '0';
224
- style.left = '0';
225
- style.visibility = 'hidden';
226
- style.whiteSpace = 'pre-wrap';
227
- style.wordBreak = 'break-word';
228
- style.boxSizing = 'border-box';
229
- style.overflow = 'hidden';
230
- style.pointerEvents = 'none';
231
- // Apply font styles
232
- Object.entries(fontStyle).forEach(([prop, value]) => {
233
- ;
234
- style[prop] = value;
235
- });
236
- // Apply spacing styles
237
- Object.entries(spacingStyle).forEach(([prop, value]) => {
238
- ;
239
- style[prop] = value;
240
- });
241
- // Append to shadow root
242
- root.appendChild(dummyEl);
243
- this._dummyEl = dummyEl;
244
- return dummyEl;
245
- }
246
- /**
247
- * Resize textarea based on dummy element content with min/max height constraints
248
- */
249
- resizeTextarea(textareaEl, dummyEl) {
250
- if (!textareaEl || !dummyEl)
251
- return;
252
- const value = this.value;
253
- const placeholder = this.placeholder;
254
- const content = (value === '' && placeholder) ? placeholder : value + ' ';
255
- const currentHeight = textareaEl.clientHeight;
256
- // Set dummy content
257
- dummyEl.textContent = content;
258
- // Set dummy width to match textarea
259
- dummyEl.style.width = `${textareaEl.clientWidth}px`;
260
- // Get measured height
261
- const measuredHeight = dummyEl.scrollHeight;
262
- // Parse min/max heights
263
- const minHeight = this.minHeight ? parseInt(this.minHeight.replace('px', ''), 10) : null;
264
- const maxHeight = this.maxHeight ? parseInt(this.maxHeight.replace('px', ''), 10) : null;
265
- // Apply constraints
266
- let constrainedHeight = measuredHeight;
267
- if (minHeight !== null)
268
- constrainedHeight = Math.max(constrainedHeight, minHeight);
269
- if (maxHeight !== null)
270
- constrainedHeight = Math.min(constrainedHeight, maxHeight);
271
- // Only update if height changed significantly (avoid micro-adjustments)
272
- if (Math.abs(constrainedHeight - currentHeight) > 2) {
273
- textareaEl.style.height = `${constrainedHeight}px`;
274
- // Set overflow based on whether we hit max-height
275
- const needsScroll = maxHeight !== null && measuredHeight >= maxHeight;
276
- if (needsScroll) {
277
- textareaEl.style.overflowY = 'auto';
278
- this._setupScrollbar(textareaEl);
279
- }
280
- else {
281
- textareaEl.style.overflowY = 'hidden';
282
- this._destroyScrollbar();
283
- }
284
- }
285
- // Keep scrollbar thumb in sync after resize
286
- this._scrollbar?.update();
287
- }
288
- // ============ Custom Scrollbar ============
289
- _setupScrollbar(textareaEl) {
290
- if (this._scrollbar || !isCustomScrollbarEnabled())
291
- return;
292
- // Hide native scrollbar (Firefox + Chrome/Safari via data attribute)
293
- textareaEl.style.scrollbarWidth = 'none';
294
- this.setAttribute('data-custom-scroll', '');
295
- this._scrollbar = new CustomScrollbar(textareaEl, {
296
- vertical: true,
297
- horizontal: false
298
- });
299
- // Append track to the textarea wrapper (position: relative)
300
- const wrapper = this.shadowRoot.querySelector('.textarea-wrapper');
301
- if (wrapper && this._scrollbar.trackY) {
302
- wrapper.appendChild(this._scrollbar.trackY);
303
- }
304
- }
305
- _destroyScrollbar() {
306
- if (!this._scrollbar)
307
- return;
308
- this._scrollbar.trackY?.remove();
309
- this._scrollbar.destroy();
310
- this._scrollbar = null;
311
- // Restore native scrollbar
312
- this.removeAttribute('data-custom-scroll');
313
- if (this._textareaEl) {
314
- this._textareaEl.style.scrollbarWidth = '';
315
- }
316
- }
317
- /**
318
- * Emit custom input and change events
319
- */
320
- emitValueEvents(originalEvent) {
321
- const value = this.value;
322
- // Update form internals
323
- this._internals.setFormValue(value || '');
324
- // Emit custom events
325
- const data = {
326
- bubbles: true,
327
- composed: true,
328
- detail: {
329
- value,
330
- originalEvent
331
- }
332
- };
333
- // Use setTimeout to ensure these fire after standard events
334
- setTimeout(() => {
335
- this.dispatchEvent(new CustomEvent('input', data));
336
- this.dispatchEvent(new CustomEvent('change', data));
337
- }, 0);
338
- }
339
- /**
340
- * Build class list for textarea element
341
- */
342
- buildClassList() {
343
- const classes = [this.size];
344
- if (this.disabled)
345
- classes.push('disabled');
346
- if (this.required)
347
- classes.push('required');
348
- if (this.error)
349
- classes.push('error');
350
- if (this.resize !== 'none')
351
- classes.push(`resize-${this.resize}`);
352
- const customClass = this.getAttribute('class');
353
- if (customClass)
354
- classes.push(customClass);
355
- return classes.join(' ');
356
- }
357
- /**
358
- * Apply min/max height constraints to textarea element
359
- */
360
- applyHeightConstraints(textareaEl) {
361
- if (this.minHeight) {
362
- textareaEl.style.minHeight = this.minHeight;
363
- }
364
- if (this.maxHeight) {
365
- textareaEl.style.maxHeight = this.maxHeight;
366
- }
367
- }
368
- /**
369
- * Setup event listeners for textarea
370
- */
371
- setupTextareaEvents(textareaEl) {
372
- textareaEl.addEventListener('input', this.handleInputEvent);
373
- textareaEl.addEventListener('change', this.handleInputEvent);
374
- textareaEl.addEventListener('focus', this.handleFocusEvent);
375
- textareaEl.addEventListener('blur', this.handleBlurEvent);
376
- }
377
- // ===== RENDER =====
378
- render() {
379
- const root = this.shadowRoot;
380
- const existingContainer = root.querySelector('.textarea-container');
381
- const existingLabel = root.querySelector('label');
382
- const existingTextarea = root.querySelector('textarea');
383
- const existingError = root.querySelector('.error-message');
384
- if (existingContainer && existingTextarea) {
385
- // Update existing elements
386
- // Update label
387
- if (this.label) {
388
- if (existingLabel) {
389
- existingLabel.innerHTML = this.label +
390
- (this.required ? ` <span class="required-icon">${REQUIRED_ICON}</span>` : '');
391
- existingLabel.style.display = 'block';
392
- }
393
- }
394
- else if (existingLabel) {
395
- existingLabel.style.display = 'none';
396
- }
397
- // Update textarea
398
- existingTextarea.value = this.value || '';
399
- existingTextarea.placeholder = this.placeholder || '';
400
- existingTextarea.disabled = this.disabled;
401
- existingTextarea.required = this.required;
402
- existingTextarea.className = this.buildClassList();
403
- // Set name for form association
404
- if (this.name) {
405
- existingTextarea.setAttribute('name', this.name);
406
- }
407
- else {
408
- existingTextarea.removeAttribute('name');
409
- }
410
- // Set rows/cols
411
- if (this.rows)
412
- existingTextarea.setAttribute('rows', this.rows);
413
- if (this.cols)
414
- existingTextarea.setAttribute('cols', this.cols);
415
- // Apply height constraints
416
- this.applyHeightConstraints(existingTextarea);
417
- // Update error message
418
- if (this.error) {
419
- if (!existingError) {
420
- const errorEl = document.createElement('div');
421
- errorEl.className = 'error-message';
422
- existingContainer.appendChild(errorEl);
423
- }
424
- const errorEl = root.querySelector('.error-message');
425
- if (errorEl)
426
- errorEl.textContent = this.error;
427
- }
428
- else if (existingError) {
429
- existingError.remove();
430
- }
431
- // Setup dummy element and trigger resize
432
- const dummyEl = this.setupDummyElement(existingTextarea);
433
- setTimeout(() => this.resizeTextarea(existingTextarea, dummyEl), 0);
434
- this._textareaEl = existingTextarea;
435
- }
436
- else {
437
- // Create new structure
438
- const container = document.createElement('div');
439
- container.className = 'textarea-container';
440
- const labelEl = document.createElement('label');
441
- labelEl.className = 'textarea-label';
442
- if (this.label) {
443
- labelEl.innerHTML = this.label +
444
- (this.required ? ` <span class="required-icon">${REQUIRED_ICON}</span>` : '');
445
- labelEl.style.display = 'block';
446
- }
447
- else {
448
- labelEl.style.display = 'none';
449
- }
450
- const textareaEl = document.createElement('textarea');
451
- textareaEl.value = this.value || '';
452
- textareaEl.placeholder = this.placeholder || '';
453
- textareaEl.disabled = this.disabled;
454
- textareaEl.required = this.required;
455
- textareaEl.className = this.buildClassList();
456
- // Set name for form association
457
- if (this.name) {
458
- textareaEl.setAttribute('name', this.name);
459
- }
460
- // Set default or specified rows/cols
461
- textareaEl.setAttribute('rows', this.rows || '3');
462
- if (this.cols)
463
- textareaEl.setAttribute('cols', this.cols);
464
- // Apply height constraints
465
- this.applyHeightConstraints(textareaEl);
466
- // Setup event listeners
467
- this.setupTextareaEvents(textareaEl);
468
- // Build structure — wrapper provides position context for custom scrollbar
469
- const wrapperEl = document.createElement('div');
470
- wrapperEl.className = 'textarea-wrapper';
471
- wrapperEl.appendChild(textareaEl);
472
- container.appendChild(labelEl);
473
- container.appendChild(wrapperEl);
474
- // Add error message if present
475
- if (this.error) {
476
- const errorEl = document.createElement('div');
477
- errorEl.className = 'error-message';
478
- errorEl.textContent = this.error;
479
- container.appendChild(errorEl);
480
- }
481
- root.appendChild(container);
482
- // Setup dummy element and trigger initial resize
483
- const dummyEl = this.setupDummyElement(textareaEl);
484
- setTimeout(() => this.resizeTextarea(textareaEl, dummyEl), 0);
485
- this._textareaEl = textareaEl;
486
- }
487
- }
10
+ constructor() {
11
+ super();
12
+ this._textareaEl = null;
13
+ this._dummyEl = null;
14
+ this._scrollbar = null;
15
+ this._isFocused = false;
16
+ this.handleInputEvent = (e) => {
17
+ this._userEdited = true;
18
+ e.stopPropagation();
19
+ e.stopImmediatePropagation();
20
+ const target = e.target;
21
+ const newValue = target.value;
22
+ this.value = newValue;
23
+ if (this._textareaEl && this._dummyEl) {
24
+ this.resizeTextarea(this._textareaEl, this._dummyEl);
25
+ }
26
+ this._internals.setFormValue(this.value || '');
27
+ this.updateValidity();
28
+ this.emitValueEvent('input', e);
29
+ };
30
+ this._valueAtFocus = null;
31
+ this.handleFocusEvent = () => {
32
+ this._isFocused = true;
33
+ this._valueAtFocus = this.value;
34
+ };
35
+ this.handleBlurEvent = (e) => {
36
+ this._isFocused = false;
37
+ if (this._userEdited)
38
+ this.revealValidity();
39
+ if (this._valueAtFocus !== null && this.value !== this._valueAtFocus) {
40
+ this.emitValueEvent('change', e);
41
+ }
42
+ this._valueAtFocus = null;
43
+ };
44
+ const shadow = this.shadowRoot;
45
+ ensureStyles(shadow, { css: textareaStyles, id: 'ty-textarea' });
46
+ if (isCustomScrollbarEnabled()) {
47
+ ensureStyles(shadow, { css: customScrollbarStyles, id: 'ty-custom-scrollbar' });
48
+ }
49
+ }
50
+ onConnect() {
51
+ this.updateFormValue();
52
+ if (this._rendered) {
53
+ this.render();
54
+ if (this._textareaEl)
55
+ this.setupTextareaEvents(this._textareaEl);
56
+ }
57
+ }
58
+ onDisconnect() {
59
+ this._destroyScrollbar();
60
+ if (this._textareaEl)
61
+ this.removeTextareaEvents(this._textareaEl);
62
+ }
63
+ onPropertiesChanged(changes) {
64
+ }
65
+ getFormValue() {
66
+ return this.getProperty('value') || '';
67
+ }
68
+ get value() { return this.getProperty('value'); }
69
+ set value(v) { this.setProperty('value', v); }
70
+ get name() { return this.getProperty('name'); }
71
+ set name(v) { this.setProperty('name', v); }
72
+ get placeholder() { return this.getProperty('placeholder'); }
73
+ set placeholder(v) { this.setProperty('placeholder', v); }
74
+ get label() { return this.getProperty('label'); }
75
+ set label(v) { this.setProperty('label', v); }
76
+ get disabled() { return this.getProperty('disabled'); }
77
+ set disabled(v) { this.setProperty('disabled', v); }
78
+ focus(options) {
79
+ this.shadowRoot?.querySelector('textarea')?.focus(options);
80
+ }
81
+ get required() { return this.getProperty('required'); }
82
+ set required(v) { this.setProperty('required', v); }
83
+ get minLength() { return toLimit(this.getProperty('minlength')) ?? -1; }
84
+ set minLength(v) { this.setProperty('minlength', v == null || v < 0 ? '' : String(v)); }
85
+ get maxLength() { return toLimit(this.getProperty('maxlength')) ?? -1; }
86
+ set maxLength(v) { this.setProperty('maxlength', v == null || v < 0 ? '' : String(v)); }
87
+ get tooShortMessage() { return this.getProperty('tooShortMessage'); }
88
+ set tooShortMessage(v) { this.setProperty('tooShortMessage', v ?? ''); }
89
+ get tooLongMessage() { return this.getProperty('tooLongMessage'); }
90
+ set tooLongMessage(v) { this.setProperty('tooLongMessage', v ?? ''); }
91
+ get error() { return this.getProperty('error'); }
92
+ set error(v) { this.setProperty('error', v); }
93
+ get size() {
94
+ return this.getProperty('size');
95
+ }
96
+ set size(v) {
97
+ this.setProperty('size', v);
98
+ }
99
+ get rows() { return this.getProperty('rows'); }
100
+ set rows(v) { this.setProperty('rows', v); }
101
+ get cols() { return this.getProperty('cols'); }
102
+ set cols(v) { this.setProperty('cols', v); }
103
+ get resize() {
104
+ return this.getProperty('resize');
105
+ }
106
+ set resize(v) {
107
+ this.setProperty('resize', v);
108
+ }
109
+ get minHeight() { return this.getProperty('minHeight'); }
110
+ set minHeight(v) { this.setProperty('minHeight', v); }
111
+ get maxHeight() { return this.getProperty('maxHeight'); }
112
+ set maxHeight(v) { this.setProperty('maxHeight', v); }
113
+ getFontStyle(el) {
114
+ const computedStyle = window.getComputedStyle(el);
115
+ return {
116
+ fontFamily: computedStyle.fontFamily,
117
+ fontSize: computedStyle.fontSize,
118
+ fontWeight: computedStyle.fontWeight,
119
+ lineHeight: computedStyle.lineHeight,
120
+ letterSpacing: computedStyle.letterSpacing,
121
+ fontStyle: computedStyle.fontStyle
122
+ };
123
+ }
124
+ getSpacingStyle(el) {
125
+ const computedStyle = window.getComputedStyle(el);
126
+ return {
127
+ padding: computedStyle.padding,
128
+ paddingTop: computedStyle.paddingTop,
129
+ paddingRight: computedStyle.paddingRight,
130
+ paddingBottom: computedStyle.paddingBottom,
131
+ paddingLeft: computedStyle.paddingLeft,
132
+ margin: computedStyle.margin,
133
+ borderWidth: computedStyle.borderWidth
134
+ };
135
+ }
136
+ setupDummyElement(textareaEl) {
137
+ const root = this.shadowRoot;
138
+ const existingDummy = root.querySelector('.textarea-dummy');
139
+ if (existingDummy) {
140
+ existingDummy.remove();
141
+ }
142
+ const dummyEl = document.createElement('pre');
143
+ const fontStyle = this.getFontStyle(textareaEl);
144
+ const spacingStyle = this.getSpacingStyle(textareaEl);
145
+ dummyEl.className = 'textarea-dummy';
146
+ const style = dummyEl.style;
147
+ style.position = 'absolute';
148
+ style.top = '0';
149
+ style.left = '0';
150
+ style.visibility = 'hidden';
151
+ style.whiteSpace = 'pre-wrap';
152
+ style.wordBreak = 'break-word';
153
+ style.boxSizing = 'border-box';
154
+ style.overflow = 'hidden';
155
+ style.pointerEvents = 'none';
156
+ Object.entries(fontStyle).forEach(([prop, value]) => {
157
+ ;
158
+ style[prop] = value;
159
+ });
160
+ Object.entries(spacingStyle).forEach(([prop, value]) => {
161
+ ;
162
+ style[prop] = value;
163
+ });
164
+ root.appendChild(dummyEl);
165
+ this._dummyEl = dummyEl;
166
+ return dummyEl;
167
+ }
168
+ resizeTextarea(textareaEl, dummyEl) {
169
+ if (!textareaEl || !dummyEl)
170
+ return;
171
+ const value = this.value;
172
+ const placeholder = this.placeholder;
173
+ const content = (value === '' && placeholder) ? placeholder : value + ' ';
174
+ const currentHeight = textareaEl.clientHeight;
175
+ dummyEl.textContent = content;
176
+ dummyEl.style.width = `${textareaEl.clientWidth}px`;
177
+ const measuredHeight = dummyEl.scrollHeight;
178
+ const minHeight = this.minHeight ? parseInt(this.minHeight.replace('px', ''), 10) : null;
179
+ const maxHeight = this.maxHeight ? parseInt(this.maxHeight.replace('px', ''), 10) : null;
180
+ let constrainedHeight = measuredHeight;
181
+ if (minHeight !== null)
182
+ constrainedHeight = Math.max(constrainedHeight, minHeight);
183
+ if (maxHeight !== null)
184
+ constrainedHeight = Math.min(constrainedHeight, maxHeight);
185
+ if (Math.abs(constrainedHeight - currentHeight) > 2) {
186
+ textareaEl.style.height = `${constrainedHeight}px`;
187
+ const needsScroll = maxHeight !== null && measuredHeight >= maxHeight;
188
+ if (needsScroll) {
189
+ textareaEl.style.overflowY = 'auto';
190
+ this._setupScrollbar(textareaEl);
191
+ }
192
+ else {
193
+ textareaEl.style.overflowY = 'hidden';
194
+ this._destroyScrollbar();
195
+ }
196
+ }
197
+ else if (maxHeight !== null && measuredHeight >= maxHeight && !this._scrollbar) {
198
+ textareaEl.style.overflowY = 'auto';
199
+ this._setupScrollbar(textareaEl);
200
+ }
201
+ this._scrollbar?.update();
202
+ }
203
+ _setupScrollbar(textareaEl) {
204
+ if (this._scrollbar || !isCustomScrollbarEnabled())
205
+ return;
206
+ textareaEl.style.scrollbarWidth = 'none';
207
+ this.setAttribute('data-custom-scroll', '');
208
+ this._scrollbar = new CustomScrollbar(textareaEl, {
209
+ vertical: true,
210
+ horizontal: false
211
+ });
212
+ const scroll = this.shadowRoot.querySelector('.textarea-scroll');
213
+ if (scroll && this._scrollbar.trackY) {
214
+ scroll.appendChild(this._scrollbar.trackY);
215
+ }
216
+ }
217
+ _destroyScrollbar() {
218
+ if (!this._scrollbar)
219
+ return;
220
+ this._scrollbar.trackY?.remove();
221
+ this._scrollbar.destroy();
222
+ this._scrollbar = null;
223
+ this.removeAttribute('data-custom-scroll');
224
+ if (this._textareaEl) {
225
+ this._textareaEl.style.scrollbarWidth = '';
226
+ }
227
+ }
228
+ emitValueEvent(type, originalEvent) {
229
+ const data = {
230
+ bubbles: true,
231
+ composed: true,
232
+ detail: {
233
+ value: this.value,
234
+ originalEvent
235
+ }
236
+ };
237
+ this.dispatchEvent(new CustomEvent(type, data));
238
+ }
239
+ buildClassList() {
240
+ const classes = [this.size];
241
+ if (this.disabled)
242
+ classes.push('disabled');
243
+ if (this.required)
244
+ classes.push('required');
245
+ if (this.error)
246
+ classes.push('error');
247
+ if (this.resize !== 'none')
248
+ classes.push(`resize-${this.resize}`);
249
+ const customClass = this.getAttribute('class');
250
+ if (customClass)
251
+ classes.push(customClass);
252
+ return classes.join(' ');
253
+ }
254
+ applyHeightConstraints(textareaEl) {
255
+ if (this.minHeight) {
256
+ textareaEl.style.minHeight = this.minHeight;
257
+ }
258
+ if (this.maxHeight) {
259
+ textareaEl.style.maxHeight = this.maxHeight;
260
+ }
261
+ }
262
+ setupTextareaEvents(textareaEl) {
263
+ textareaEl.addEventListener('input', this.handleInputEvent);
264
+ textareaEl.addEventListener('focus', this.handleFocusEvent);
265
+ textareaEl.addEventListener('blur', this.handleBlurEvent);
266
+ }
267
+ removeTextareaEvents(textareaEl) {
268
+ textareaEl.removeEventListener('input', this.handleInputEvent);
269
+ textareaEl.removeEventListener('focus', this.handleFocusEvent);
270
+ textareaEl.removeEventListener('blur', this.handleBlurEvent);
271
+ }
272
+ render() {
273
+ const root = this.shadowRoot;
274
+ const existingContainer = root.querySelector('.textarea-container');
275
+ const existingLabel = root.querySelector('label');
276
+ const existingTextarea = root.querySelector('textarea');
277
+ const existingError = root.querySelector('.error-message');
278
+ if (existingContainer && existingTextarea) {
279
+ if (this.label) {
280
+ if (existingLabel) {
281
+ existingLabel.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
282
+ existingLabel.style.display = 'flex';
283
+ }
284
+ }
285
+ else if (existingLabel) {
286
+ existingLabel.style.display = 'none';
287
+ }
288
+ if (existingTextarea.value !== (this.value || ''))
289
+ existingTextarea.value = this.value || '';
290
+ existingTextarea.placeholder = this.placeholder || '';
291
+ existingTextarea.disabled = this.disabled;
292
+ existingTextarea.required = this.required;
293
+ this.syncConstraintAttributes(existingTextarea);
294
+ existingTextarea.className = this.buildClassList();
295
+ if (this.label)
296
+ existingTextarea.setAttribute('aria-label', this.label);
297
+ else
298
+ existingTextarea.removeAttribute('aria-label');
299
+ if (this.name) {
300
+ existingTextarea.setAttribute('name', this.name);
301
+ }
302
+ else {
303
+ existingTextarea.removeAttribute('name');
304
+ }
305
+ if (this.rows)
306
+ existingTextarea.setAttribute('rows', this.rows);
307
+ if (this.cols)
308
+ existingTextarea.setAttribute('cols', this.cols);
309
+ this.applyHeightConstraints(existingTextarea);
310
+ if (this.error) {
311
+ if (!existingError) {
312
+ const errorEl = document.createElement('div');
313
+ errorEl.className = 'error-message';
314
+ existingContainer.appendChild(errorEl);
315
+ }
316
+ const errorEl = root.querySelector('.error-message');
317
+ if (errorEl)
318
+ errorEl.textContent = this.error;
319
+ }
320
+ else if (existingError) {
321
+ existingError.remove();
322
+ }
323
+ const dummyEl = this.setupDummyElement(existingTextarea);
324
+ setTimeout(() => this.resizeTextarea(existingTextarea, dummyEl), 0);
325
+ this._textareaEl = existingTextarea;
326
+ }
327
+ else {
328
+ const container = document.createElement('div');
329
+ container.className = 'textarea-container';
330
+ const labelEl = document.createElement('label');
331
+ labelEl.className = 'ty-field-label';
332
+ if (this.label) {
333
+ labelEl.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
334
+ labelEl.style.display = 'flex';
335
+ }
336
+ else {
337
+ labelEl.style.display = 'none';
338
+ }
339
+ const textareaEl = document.createElement('textarea');
340
+ textareaEl.value = this.value || '';
341
+ textareaEl.placeholder = this.placeholder || '';
342
+ textareaEl.disabled = this.disabled;
343
+ textareaEl.required = this.required;
344
+ this.syncConstraintAttributes(textareaEl);
345
+ textareaEl.className = this.buildClassList();
346
+ if (this.label)
347
+ textareaEl.setAttribute('aria-label', this.label);
348
+ if (this.name) {
349
+ textareaEl.setAttribute('name', this.name);
350
+ }
351
+ textareaEl.setAttribute('rows', this.rows || '3');
352
+ if (this.cols)
353
+ textareaEl.setAttribute('cols', this.cols);
354
+ this.applyHeightConstraints(textareaEl);
355
+ this.setupTextareaEvents(textareaEl);
356
+ const wrapperEl = document.createElement('div');
357
+ wrapperEl.className = 'textarea-wrapper';
358
+ const headerEl = document.createElement('div');
359
+ headerEl.className = 'textarea-header';
360
+ const headerSlot = document.createElement('slot');
361
+ headerSlot.setAttribute('name', 'header');
362
+ headerEl.appendChild(headerSlot);
363
+ const scrollEl = document.createElement('div');
364
+ scrollEl.className = 'textarea-scroll';
365
+ scrollEl.appendChild(textareaEl);
366
+ const footerEl = document.createElement('div');
367
+ footerEl.className = 'textarea-footer';
368
+ const footerSlot = document.createElement('slot');
369
+ footerSlot.setAttribute('name', 'footer');
370
+ footerEl.appendChild(footerSlot);
371
+ wrapperEl.appendChild(headerEl);
372
+ wrapperEl.appendChild(scrollEl);
373
+ wrapperEl.appendChild(footerEl);
374
+ const syncSlot = (slot, region) => {
375
+ const update = () => region.classList.toggle('has-content', slot.assignedNodes({ flatten: true }).length > 0);
376
+ slot.addEventListener('slotchange', update);
377
+ update();
378
+ };
379
+ syncSlot(headerSlot, headerEl);
380
+ syncSlot(footerSlot, footerEl);
381
+ container.appendChild(labelEl);
382
+ container.appendChild(wrapperEl);
383
+ if (this.error) {
384
+ const errorEl = document.createElement('div');
385
+ errorEl.className = 'error-message';
386
+ errorEl.textContent = this.error;
387
+ container.appendChild(errorEl);
388
+ }
389
+ root.appendChild(container);
390
+ const dummyEl = this.setupDummyElement(textareaEl);
391
+ setTimeout(() => this.resizeTextarea(textareaEl, dummyEl), 0);
392
+ this._textareaEl = textareaEl;
393
+ }
394
+ this.updateValidity();
395
+ }
396
+ syncConstraintAttributes(ta) {
397
+ const set = (name, limit) => limit !== null ? ta.setAttribute(name, String(limit)) : ta.removeAttribute(name);
398
+ set('minlength', toLimit(this.getProperty('minlength')));
399
+ set('maxlength', toLimit(this.getProperty('maxlength')));
400
+ }
401
+ updateValidity() {
402
+ const ta = this.shadowRoot?.querySelector('textarea');
403
+ if (this.disabled) {
404
+ this.applyValidity({});
405
+ return;
406
+ }
407
+ const current = ta ? ta.value : String(this.value ?? '');
408
+ if (current.trim() === '') {
409
+ if (this.required) {
410
+ this.applyValidity({ valueMissing: true }, nativeMessage('textarea', { required: true }), ta ?? undefined);
411
+ }
412
+ else {
413
+ this.applyValidity({});
414
+ }
415
+ return;
416
+ }
417
+ const { tooShort, tooLong } = lengthValidity(current, {
418
+ minlength: this.getProperty('minlength'),
419
+ maxlength: this.getProperty('maxlength'),
420
+ tooShortMessage: this.tooShortMessage,
421
+ tooLongMessage: this.tooLongMessage,
422
+ }, ta);
423
+ this.applyValidity({ tooShort: !!tooShort, tooLong: !!tooLong }, tooShort ?? tooLong, ta ?? undefined);
424
+ }
488
425
  }
489
426
  TyTextarea.formAssociated = true;
490
- // ============================================================================
491
- // PROPERTY CONFIGURATION - Declarative property lifecycle
492
- // ============================================================================
493
427
  TyTextarea.properties = {
494
- // Core properties
495
- value: {
496
- type: 'string',
497
- visual: true,
498
- formValue: true,
499
- emitChange: true,
500
- default: ''
501
- },
502
- name: {
503
- type: 'string',
504
- default: ''
505
- },
506
- placeholder: {
507
- type: 'string',
508
- visual: true,
509
- default: ''
510
- },
511
- label: {
512
- type: 'string',
513
- visual: true,
514
- default: ''
515
- },
516
- disabled: {
517
- type: 'boolean',
518
- visual: true,
519
- default: false
520
- },
521
- required: {
522
- type: 'boolean',
523
- visual: true,
524
- default: false
525
- },
526
- error: {
527
- type: 'string',
528
- visual: true,
529
- default: ''
530
- },
531
- size: {
532
- type: 'string',
533
- visual: true,
534
- default: 'md',
535
- validate: (v) => ['xs', 'sm', 'md', 'lg', 'xl'].includes(v),
536
- coerce: (v) => {
537
- if (!['xs', 'sm', 'md', 'lg', 'xl'].includes(v)) {
538
- console.warn(`[ty-textarea] Invalid size '${v}'. Using 'md'.`);
539
- return 'md';
540
- }
541
- return v;
542
- }
543
- },
544
- // Layout properties
545
- rows: {
546
- type: 'string',
547
- visual: true,
548
- default: '3',
549
- coerce: (v) => String(v)
550
- },
551
- cols: {
552
- type: 'string',
553
- visual: true,
554
- default: '',
555
- coerce: (v) => v ? String(v) : ''
556
- },
557
- resize: {
558
- type: 'string',
559
- visual: true,
560
- default: 'none',
561
- validate: (v) => ['none', 'both', 'horizontal', 'vertical'].includes(v),
562
- coerce: (v) => {
563
- if (!['none', 'both', 'horizontal', 'vertical'].includes(v)) {
564
- console.warn(`[ty-textarea] Invalid resize '${v}'. Using 'none'.`);
565
- return 'none';
566
- }
567
- return v;
568
- }
569
- },
570
- minHeight: {
571
- type: 'string',
572
- visual: true,
573
- default: ''
574
- },
575
- maxHeight: {
576
- type: 'string',
577
- visual: true,
578
- default: ''
579
- }
428
+ value: {
429
+ type: 'string',
430
+ visual: true,
431
+ formValue: true,
432
+ emitChange: true,
433
+ default: ''
434
+ },
435
+ name: {
436
+ type: 'string',
437
+ default: ''
438
+ },
439
+ placeholder: {
440
+ type: 'string',
441
+ visual: true,
442
+ default: ''
443
+ },
444
+ label: {
445
+ type: 'string',
446
+ visual: true,
447
+ default: ''
448
+ },
449
+ disabled: {
450
+ type: 'boolean',
451
+ visual: true,
452
+ default: false
453
+ },
454
+ required: {
455
+ type: 'boolean',
456
+ visual: true,
457
+ default: false
458
+ },
459
+ minlength: {
460
+ type: 'string',
461
+ visual: true,
462
+ default: ''
463
+ },
464
+ maxlength: {
465
+ type: 'string',
466
+ visual: true,
467
+ default: ''
468
+ },
469
+ tooShortMessage: {
470
+ type: 'string',
471
+ visual: true,
472
+ default: ''
473
+ },
474
+ tooLongMessage: {
475
+ type: 'string',
476
+ visual: true,
477
+ default: ''
478
+ },
479
+ error: {
480
+ type: 'string',
481
+ visual: true,
482
+ default: ''
483
+ },
484
+ size: {
485
+ type: 'string',
486
+ visual: true,
487
+ default: DEFAULT_SIZE,
488
+ validate: (v) => ['xs', 'sm', 'md', 'lg', 'xl'].includes(v),
489
+ coerce: (v) => {
490
+ if (!['xs', 'sm', 'md', 'lg', 'xl'].includes(v)) {
491
+ console.warn(`[ty-textarea] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
492
+ return DEFAULT_SIZE;
493
+ }
494
+ return v;
495
+ }
496
+ },
497
+ rows: {
498
+ type: 'string',
499
+ visual: true,
500
+ default: '3',
501
+ coerce: (v) => String(v)
502
+ },
503
+ cols: {
504
+ type: 'string',
505
+ visual: true,
506
+ default: '',
507
+ coerce: (v) => v ? String(v) : ''
508
+ },
509
+ resize: {
510
+ type: 'string',
511
+ visual: true,
512
+ default: 'none',
513
+ validate: (v) => ['none', 'both', 'horizontal', 'vertical'].includes(v),
514
+ coerce: (v) => {
515
+ if (!['none', 'both', 'horizontal', 'vertical'].includes(v)) {
516
+ console.warn(`[ty-textarea] Invalid resize '${v}'. Using 'none'.`);
517
+ return 'none';
518
+ }
519
+ return v;
520
+ }
521
+ },
522
+ minHeight: {
523
+ type: 'string',
524
+ visual: true,
525
+ default: ''
526
+ },
527
+ maxHeight: {
528
+ type: 'string',
529
+ visual: true,
530
+ default: ''
531
+ }
580
532
  };
581
- // Register the component
582
533
  if (!customElements.get('ty-textarea')) {
583
- customElements.define('ty-textarea', TyTextarea);
534
+ customElements.define('ty-textarea', TyTextarea);
584
535
  }
585
- //# sourceMappingURL=textarea.js.map