tyrell-components 1.0.0-RC6

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 (330) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +221 -0
  3. package/css/tyrell.css +1783 -0
  4. package/dist/tyrell.css +1783 -0
  5. package/dist/tyrell.js +2 -0
  6. package/lib/base/ty-component.d.ts +133 -0
  7. package/lib/base/ty-component.d.ts.map +1 -0
  8. package/lib/base/ty-component.js +297 -0
  9. package/lib/base/ty-component.js.map +1 -0
  10. package/lib/components/button.d.ts +126 -0
  11. package/lib/components/button.d.ts.map +1 -0
  12. package/lib/components/button.js +244 -0
  13. package/lib/components/button.js.map +1 -0
  14. package/lib/components/calendar-month.d.ts +132 -0
  15. package/lib/components/calendar-month.d.ts.map +1 -0
  16. package/lib/components/calendar-month.js +440 -0
  17. package/lib/components/calendar-month.js.map +1 -0
  18. package/lib/components/calendar-navigation.d.ts +137 -0
  19. package/lib/components/calendar-navigation.d.ts.map +1 -0
  20. package/lib/components/calendar-navigation.js +366 -0
  21. package/lib/components/calendar-navigation.js.map +1 -0
  22. package/lib/components/calendar.d.ts +166 -0
  23. package/lib/components/calendar.d.ts.map +1 -0
  24. package/lib/components/calendar.js +774 -0
  25. package/lib/components/calendar.js.map +1 -0
  26. package/lib/components/checkbox.d.ts +189 -0
  27. package/lib/components/checkbox.d.ts.map +1 -0
  28. package/lib/components/checkbox.js +400 -0
  29. package/lib/components/checkbox.js.map +1 -0
  30. package/lib/components/copy.d.ts +180 -0
  31. package/lib/components/copy.d.ts.map +1 -0
  32. package/lib/components/copy.js +393 -0
  33. package/lib/components/copy.js.map +1 -0
  34. package/lib/components/date-picker.d.ts +379 -0
  35. package/lib/components/date-picker.d.ts.map +1 -0
  36. package/lib/components/date-picker.js +1586 -0
  37. package/lib/components/date-picker.js.map +1 -0
  38. package/lib/components/dropdown.d.ts +402 -0
  39. package/lib/components/dropdown.d.ts.map +1 -0
  40. package/lib/components/dropdown.js +1552 -0
  41. package/lib/components/dropdown.js.map +1 -0
  42. package/lib/components/icon.d.ts +118 -0
  43. package/lib/components/icon.d.ts.map +1 -0
  44. package/lib/components/icon.js +245 -0
  45. package/lib/components/icon.js.map +1 -0
  46. package/lib/components/input.d.ts +270 -0
  47. package/lib/components/input.d.ts.map +1 -0
  48. package/lib/components/input.js +721 -0
  49. package/lib/components/input.js.map +1 -0
  50. package/lib/components/modal.d.ts +58 -0
  51. package/lib/components/modal.d.ts.map +1 -0
  52. package/lib/components/modal.js +473 -0
  53. package/lib/components/modal.js.map +1 -0
  54. package/lib/components/multiselect.d.ts +397 -0
  55. package/lib/components/multiselect.d.ts.map +1 -0
  56. package/lib/components/multiselect.js +1580 -0
  57. package/lib/components/multiselect.js.map +1 -0
  58. package/lib/components/option.d.ts +66 -0
  59. package/lib/components/option.d.ts.map +1 -0
  60. package/lib/components/option.js +314 -0
  61. package/lib/components/option.js.map +1 -0
  62. package/lib/components/popup.d.ts +43 -0
  63. package/lib/components/popup.d.ts.map +1 -0
  64. package/lib/components/popup.js +380 -0
  65. package/lib/components/popup.js.map +1 -0
  66. package/lib/components/radio.d.ts +198 -0
  67. package/lib/components/radio.d.ts.map +1 -0
  68. package/lib/components/radio.js +437 -0
  69. package/lib/components/radio.js.map +1 -0
  70. package/lib/components/resize-observer.d.ts +48 -0
  71. package/lib/components/resize-observer.d.ts.map +1 -0
  72. package/lib/components/resize-observer.js +108 -0
  73. package/lib/components/resize-observer.js.map +1 -0
  74. package/lib/components/scroll-container.d.ts +51 -0
  75. package/lib/components/scroll-container.d.ts.map +1 -0
  76. package/lib/components/scroll-container.js +239 -0
  77. package/lib/components/scroll-container.js.map +1 -0
  78. package/lib/components/step.d.ts +26 -0
  79. package/lib/components/step.d.ts.map +1 -0
  80. package/lib/components/step.js +75 -0
  81. package/lib/components/step.js.map +1 -0
  82. package/lib/components/switch.d.ts +111 -0
  83. package/lib/components/switch.d.ts.map +1 -0
  84. package/lib/components/switch.js +240 -0
  85. package/lib/components/switch.js.map +1 -0
  86. package/lib/components/tab.d.ts +23 -0
  87. package/lib/components/tab.d.ts.map +1 -0
  88. package/lib/components/tab.js +76 -0
  89. package/lib/components/tab.js.map +1 -0
  90. package/lib/components/tabs.d.ts +93 -0
  91. package/lib/components/tabs.d.ts.map +1 -0
  92. package/lib/components/tabs.js +653 -0
  93. package/lib/components/tabs.js.map +1 -0
  94. package/lib/components/tag.d.ts +144 -0
  95. package/lib/components/tag.d.ts.map +1 -0
  96. package/lib/components/tag.js +316 -0
  97. package/lib/components/tag.js.map +1 -0
  98. package/lib/components/textarea.d.ts +241 -0
  99. package/lib/components/textarea.d.ts.map +1 -0
  100. package/lib/components/textarea.js +585 -0
  101. package/lib/components/textarea.js.map +1 -0
  102. package/lib/components/tooltip.d.ts +40 -0
  103. package/lib/components/tooltip.d.ts.map +1 -0
  104. package/lib/components/tooltip.js +439 -0
  105. package/lib/components/tooltip.js.map +1 -0
  106. package/lib/components/wizard.d.ts +86 -0
  107. package/lib/components/wizard.d.ts.map +1 -0
  108. package/lib/components/wizard.js +636 -0
  109. package/lib/components/wizard.js.map +1 -0
  110. package/lib/icons/fontawesome/brands.d.ts +557 -0
  111. package/lib/icons/fontawesome/brands.d.ts.map +1 -0
  112. package/lib/icons/fontawesome/brands.js +557 -0
  113. package/lib/icons/fontawesome/brands.js.map +1 -0
  114. package/lib/icons/fontawesome/regular.d.ts +281 -0
  115. package/lib/icons/fontawesome/regular.d.ts.map +1 -0
  116. package/lib/icons/fontawesome/regular.js +281 -0
  117. package/lib/icons/fontawesome/regular.js.map +1 -0
  118. package/lib/icons/fontawesome/solid.d.ts +1992 -0
  119. package/lib/icons/fontawesome/solid.d.ts.map +1 -0
  120. package/lib/icons/fontawesome/solid.js +1992 -0
  121. package/lib/icons/fontawesome/solid.js.map +1 -0
  122. package/lib/icons/heroicons/micro.d.ts +324 -0
  123. package/lib/icons/heroicons/micro.d.ts.map +1 -0
  124. package/lib/icons/heroicons/micro.js +1032 -0
  125. package/lib/icons/heroicons/micro.js.map +1 -0
  126. package/lib/icons/heroicons/mini.d.ts +332 -0
  127. package/lib/icons/heroicons/mini.d.ts.map +1 -0
  128. package/lib/icons/heroicons/mini.js +1038 -0
  129. package/lib/icons/heroicons/mini.js.map +1 -0
  130. package/lib/icons/heroicons/outline.d.ts +332 -0
  131. package/lib/icons/heroicons/outline.d.ts.map +1 -0
  132. package/lib/icons/heroicons/outline.js +993 -0
  133. package/lib/icons/heroicons/outline.js.map +1 -0
  134. package/lib/icons/heroicons/solid.d.ts +332 -0
  135. package/lib/icons/heroicons/solid.d.ts.map +1 -0
  136. package/lib/icons/heroicons/solid.js +1063 -0
  137. package/lib/icons/heroicons/solid.js.map +1 -0
  138. package/lib/icons/lucide.d.ts +1872 -0
  139. package/lib/icons/lucide.d.ts.map +1 -0
  140. package/lib/icons/lucide.js +28212 -0
  141. package/lib/icons/lucide.js.map +1 -0
  142. package/lib/icons/material/filled.d.ts +2180 -0
  143. package/lib/icons/material/filled.d.ts.map +1 -0
  144. package/lib/icons/material/filled.js +14003 -0
  145. package/lib/icons/material/filled.js.map +1 -0
  146. package/lib/icons/material/outlined.d.ts +2142 -0
  147. package/lib/icons/material/outlined.d.ts.map +1 -0
  148. package/lib/icons/material/outlined.js +14545 -0
  149. package/lib/icons/material/outlined.js.map +1 -0
  150. package/lib/icons/material/round.d.ts +2147 -0
  151. package/lib/icons/material/round.d.ts.map +1 -0
  152. package/lib/icons/material/round.js +14779 -0
  153. package/lib/icons/material/round.js.map +1 -0
  154. package/lib/icons/material/sharp.d.ts +2147 -0
  155. package/lib/icons/material/sharp.d.ts.map +1 -0
  156. package/lib/icons/material/sharp.js +14189 -0
  157. package/lib/icons/material/sharp.js.map +1 -0
  158. package/lib/icons/material/two-tone.d.ts +2185 -0
  159. package/lib/icons/material/two-tone.d.ts.map +1 -0
  160. package/lib/icons/material/two-tone.js +17152 -0
  161. package/lib/icons/material/two-tone.js.map +1 -0
  162. package/lib/index.d.ts +78 -0
  163. package/lib/index.d.ts.map +1 -0
  164. package/lib/index.js +71 -0
  165. package/lib/index.js.map +1 -0
  166. package/lib/styles/button.d.ts +14 -0
  167. package/lib/styles/button.d.ts.map +1 -0
  168. package/lib/styles/button.js +457 -0
  169. package/lib/styles/button.js.map +1 -0
  170. package/lib/styles/calendar-month.d.ts +6 -0
  171. package/lib/styles/calendar-month.d.ts.map +1 -0
  172. package/lib/styles/calendar-month.js +275 -0
  173. package/lib/styles/calendar-month.js.map +1 -0
  174. package/lib/styles/calendar-navigation.d.ts +6 -0
  175. package/lib/styles/calendar-navigation.d.ts.map +1 -0
  176. package/lib/styles/calendar-navigation.js +143 -0
  177. package/lib/styles/calendar-navigation.js.map +1 -0
  178. package/lib/styles/calendar.d.ts +6 -0
  179. package/lib/styles/calendar.d.ts.map +1 -0
  180. package/lib/styles/calendar.js +28 -0
  181. package/lib/styles/calendar.js.map +1 -0
  182. package/lib/styles/checkbox.d.ts +9 -0
  183. package/lib/styles/checkbox.d.ts.map +1 -0
  184. package/lib/styles/checkbox.js +19 -0
  185. package/lib/styles/checkbox.js.map +1 -0
  186. package/lib/styles/copy.d.ts +7 -0
  187. package/lib/styles/copy.d.ts.map +1 -0
  188. package/lib/styles/copy.js +94 -0
  189. package/lib/styles/copy.js.map +1 -0
  190. package/lib/styles/custom-scrollbar.d.ts +6 -0
  191. package/lib/styles/custom-scrollbar.d.ts.map +1 -0
  192. package/lib/styles/custom-scrollbar.js +157 -0
  193. package/lib/styles/custom-scrollbar.js.map +1 -0
  194. package/lib/styles/date-picker.d.ts +6 -0
  195. package/lib/styles/date-picker.d.ts.map +1 -0
  196. package/lib/styles/date-picker.js +435 -0
  197. package/lib/styles/date-picker.js.map +1 -0
  198. package/lib/styles/dropdown.d.ts +12 -0
  199. package/lib/styles/dropdown.d.ts.map +1 -0
  200. package/lib/styles/dropdown.js +983 -0
  201. package/lib/styles/dropdown.js.map +1 -0
  202. package/lib/styles/icon.d.ts +6 -0
  203. package/lib/styles/icon.d.ts.map +1 -0
  204. package/lib/styles/icon.js +241 -0
  205. package/lib/styles/icon.js.map +1 -0
  206. package/lib/styles/input.d.ts +7 -0
  207. package/lib/styles/input.d.ts.map +1 -0
  208. package/lib/styles/input.js +685 -0
  209. package/lib/styles/input.js.map +1 -0
  210. package/lib/styles/modal.d.ts +8 -0
  211. package/lib/styles/modal.d.ts.map +1 -0
  212. package/lib/styles/modal.js +134 -0
  213. package/lib/styles/modal.js.map +1 -0
  214. package/lib/styles/multiselect.d.ts +6 -0
  215. package/lib/styles/multiselect.d.ts.map +1 -0
  216. package/lib/styles/multiselect.js +774 -0
  217. package/lib/styles/multiselect.js.map +1 -0
  218. package/lib/styles/option.d.ts +6 -0
  219. package/lib/styles/option.d.ts.map +1 -0
  220. package/lib/styles/option.js +116 -0
  221. package/lib/styles/option.js.map +1 -0
  222. package/lib/styles/popup.d.ts +8 -0
  223. package/lib/styles/popup.d.ts.map +1 -0
  224. package/lib/styles/popup.js +95 -0
  225. package/lib/styles/popup.js.map +1 -0
  226. package/lib/styles/radio.d.ts +8 -0
  227. package/lib/styles/radio.d.ts.map +1 -0
  228. package/lib/styles/radio.js +160 -0
  229. package/lib/styles/radio.js.map +1 -0
  230. package/lib/styles/resize-observer.d.ts +6 -0
  231. package/lib/styles/resize-observer.d.ts.map +1 -0
  232. package/lib/styles/resize-observer.js +18 -0
  233. package/lib/styles/resize-observer.js.map +1 -0
  234. package/lib/styles/scroll-container.d.ts +6 -0
  235. package/lib/styles/scroll-container.d.ts.map +1 -0
  236. package/lib/styles/scroll-container.js +198 -0
  237. package/lib/styles/scroll-container.js.map +1 -0
  238. package/lib/styles/step.d.ts +5 -0
  239. package/lib/styles/step.d.ts.map +1 -0
  240. package/lib/styles/step.js +50 -0
  241. package/lib/styles/step.js.map +1 -0
  242. package/lib/styles/switch.d.ts +9 -0
  243. package/lib/styles/switch.d.ts.map +1 -0
  244. package/lib/styles/switch.js +100 -0
  245. package/lib/styles/switch.js.map +1 -0
  246. package/lib/styles/tab.d.ts +5 -0
  247. package/lib/styles/tab.d.ts.map +1 -0
  248. package/lib/styles/tab.js +51 -0
  249. package/lib/styles/tab.js.map +1 -0
  250. package/lib/styles/tabs.d.ts +13 -0
  251. package/lib/styles/tabs.d.ts.map +1 -0
  252. package/lib/styles/tabs.js +184 -0
  253. package/lib/styles/tabs.js.map +1 -0
  254. package/lib/styles/tag.d.ts +6 -0
  255. package/lib/styles/tag.d.ts.map +1 -0
  256. package/lib/styles/tag.js +420 -0
  257. package/lib/styles/tag.js.map +1 -0
  258. package/lib/styles/textarea.d.ts +6 -0
  259. package/lib/styles/textarea.d.ts.map +1 -0
  260. package/lib/styles/textarea.js +350 -0
  261. package/lib/styles/textarea.js.map +1 -0
  262. package/lib/styles/tooltip.d.ts +9 -0
  263. package/lib/styles/tooltip.d.ts.map +1 -0
  264. package/lib/styles/tooltip.js +136 -0
  265. package/lib/styles/tooltip.js.map +1 -0
  266. package/lib/styles/wizard.d.ts +25 -0
  267. package/lib/styles/wizard.d.ts.map +1 -0
  268. package/lib/styles/wizard.js +325 -0
  269. package/lib/styles/wizard.js.map +1 -0
  270. package/lib/types/common.d.ts +143 -0
  271. package/lib/types/common.d.ts.map +1 -0
  272. package/lib/types/common.js +5 -0
  273. package/lib/types/common.js.map +1 -0
  274. package/lib/utils/calendar-utils.d.ts +176 -0
  275. package/lib/utils/calendar-utils.d.ts.map +1 -0
  276. package/lib/utils/calendar-utils.js +370 -0
  277. package/lib/utils/calendar-utils.js.map +1 -0
  278. package/lib/utils/custom-scrollbar.d.ts +82 -0
  279. package/lib/utils/custom-scrollbar.d.ts.map +1 -0
  280. package/lib/utils/custom-scrollbar.js +320 -0
  281. package/lib/utils/custom-scrollbar.js.map +1 -0
  282. package/lib/utils/icon-registry.d.ts +78 -0
  283. package/lib/utils/icon-registry.d.ts.map +1 -0
  284. package/lib/utils/icon-registry.js +304 -0
  285. package/lib/utils/icon-registry.js.map +1 -0
  286. package/lib/utils/locale.d.ts +136 -0
  287. package/lib/utils/locale.d.ts.map +1 -0
  288. package/lib/utils/locale.js +213 -0
  289. package/lib/utils/locale.js.map +1 -0
  290. package/lib/utils/mobile.d.ts +14 -0
  291. package/lib/utils/mobile.d.ts.map +1 -0
  292. package/lib/utils/mobile.js +21 -0
  293. package/lib/utils/mobile.js.map +1 -0
  294. package/lib/utils/number-format.d.ts +83 -0
  295. package/lib/utils/number-format.d.ts.map +1 -0
  296. package/lib/utils/number-format.js +143 -0
  297. package/lib/utils/number-format.js.map +1 -0
  298. package/lib/utils/parse-boolean.d.ts +39 -0
  299. package/lib/utils/parse-boolean.d.ts.map +1 -0
  300. package/lib/utils/parse-boolean.js +58 -0
  301. package/lib/utils/parse-boolean.js.map +1 -0
  302. package/lib/utils/positioning.d.ts +143 -0
  303. package/lib/utils/positioning.d.ts.map +1 -0
  304. package/lib/utils/positioning.js +308 -0
  305. package/lib/utils/positioning.js.map +1 -0
  306. package/lib/utils/property-capture.d.ts +132 -0
  307. package/lib/utils/property-capture.d.ts.map +1 -0
  308. package/lib/utils/property-capture.js +152 -0
  309. package/lib/utils/property-capture.js.map +1 -0
  310. package/lib/utils/property-manager.d.ts +90 -0
  311. package/lib/utils/property-manager.d.ts.map +1 -0
  312. package/lib/utils/property-manager.js +197 -0
  313. package/lib/utils/property-manager.js.map +1 -0
  314. package/lib/utils/resize-observer.d.ts +42 -0
  315. package/lib/utils/resize-observer.d.ts.map +1 -0
  316. package/lib/utils/resize-observer.js +71 -0
  317. package/lib/utils/resize-observer.js.map +1 -0
  318. package/lib/utils/scroll-lock.d.ts +79 -0
  319. package/lib/utils/scroll-lock.d.ts.map +1 -0
  320. package/lib/utils/scroll-lock.js +197 -0
  321. package/lib/utils/scroll-lock.js.map +1 -0
  322. package/lib/utils/styles.d.ts +27 -0
  323. package/lib/utils/styles.d.ts.map +1 -0
  324. package/lib/utils/styles.js +53 -0
  325. package/lib/utils/styles.js.map +1 -0
  326. package/lib/version.d.ts +8 -0
  327. package/lib/version.d.ts.map +1 -0
  328. package/lib/version.js +11 -0
  329. package/lib/version.js.map +1 -0
  330. package/package.json +159 -0
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Core positioning engine for floating elements
3
+ * Adapted from ty.positioning ClojureScript implementation
4
+ *
5
+ * Handles smart positioning of tooltips, dropdowns, popups, and other
6
+ * floating elements relative to anchor elements with automatic overflow
7
+ * detection and placement fallback.
8
+ */
9
+ // ============================================================================
10
+ // Placement Definitions
11
+ // ============================================================================
12
+ /**
13
+ * Map of all placement configurations
14
+ */
15
+ export const placements = {
16
+ 'top-start': {
17
+ vertical: 'top',
18
+ horizontal: 'start',
19
+ },
20
+ 'top': {
21
+ vertical: 'top',
22
+ horizontal: 'center',
23
+ },
24
+ 'top-end': {
25
+ vertical: 'top',
26
+ horizontal: 'end',
27
+ },
28
+ 'right-start': {
29
+ vertical: 'center',
30
+ horizontal: 'end',
31
+ orientation: 'vertical',
32
+ },
33
+ 'right': {
34
+ vertical: 'center',
35
+ horizontal: 'end',
36
+ orientation: 'vertical',
37
+ },
38
+ 'right-end': {
39
+ vertical: 'end',
40
+ horizontal: 'end',
41
+ orientation: 'vertical',
42
+ },
43
+ 'bottom-start': {
44
+ vertical: 'bottom',
45
+ horizontal: 'start',
46
+ },
47
+ 'bottom': {
48
+ vertical: 'bottom',
49
+ horizontal: 'center',
50
+ },
51
+ 'bottom-end': {
52
+ vertical: 'bottom',
53
+ horizontal: 'end',
54
+ },
55
+ 'left-start': {
56
+ vertical: 'center',
57
+ horizontal: 'start',
58
+ orientation: 'vertical',
59
+ },
60
+ 'left': {
61
+ vertical: 'center',
62
+ horizontal: 'start',
63
+ orientation: 'vertical',
64
+ },
65
+ 'left-end': {
66
+ vertical: 'end',
67
+ horizontal: 'start',
68
+ orientation: 'vertical',
69
+ },
70
+ };
71
+ /**
72
+ * Default placement preference lists for different use cases
73
+ */
74
+ export const placementPreferences = {
75
+ default: [
76
+ 'bottom-start', 'bottom-end', 'top-start', 'top-end',
77
+ 'bottom', 'top', 'left', 'right'
78
+ ],
79
+ tooltip: [
80
+ 'top', 'bottom', 'left', 'right',
81
+ 'top-start', 'top-end', 'bottom-start', 'bottom-end'
82
+ ],
83
+ dropdown: [
84
+ 'bottom-start', 'bottom-end', 'top-start', 'top-end',
85
+ 'bottom', 'top', 'right', 'left'
86
+ ],
87
+ };
88
+ // ============================================================================
89
+ // DOM Measurement Helpers
90
+ // ============================================================================
91
+ /**
92
+ * Get element dimensions relative to viewport with calculated center points
93
+ */
94
+ export function getElementRect(el) {
95
+ const rect = el.getBoundingClientRect();
96
+ return {
97
+ top: rect.top,
98
+ left: rect.left,
99
+ right: rect.right,
100
+ bottom: rect.bottom,
101
+ width: rect.width,
102
+ height: rect.height,
103
+ centerX: rect.left + rect.width / 2,
104
+ centerY: rect.top + rect.height / 2,
105
+ };
106
+ }
107
+ /**
108
+ * Get viewport dimensions and scroll position
109
+ */
110
+ export function getViewportRect() {
111
+ return {
112
+ width: window.innerWidth,
113
+ height: window.innerHeight,
114
+ scrollX: window.scrollX,
115
+ scrollY: window.scrollY,
116
+ };
117
+ }
118
+ // ============================================================================
119
+ // Position Calculation
120
+ // ============================================================================
121
+ /**
122
+ * Calculate position for a specific placement
123
+ * Returns x, y coordinates and overflow information
124
+ */
125
+ export function calculatePlacement(options) {
126
+ const { targetRect, floatingRect, placement, offset, padding, scrollbarWidth, containerPadding, } = options;
127
+ const config = placements[placement];
128
+ const { vertical, horizontal, orientation } = config;
129
+ const viewport = getViewportRect();
130
+ // Calculate X position
131
+ let x;
132
+ if (orientation === 'vertical') {
133
+ // Left/right placements
134
+ if (horizontal === 'start') {
135
+ x = targetRect.left - floatingRect.width - offset + containerPadding;
136
+ }
137
+ else {
138
+ x = targetRect.right + offset - containerPadding;
139
+ }
140
+ }
141
+ else {
142
+ // Top/bottom placements
143
+ if (horizontal === 'start') {
144
+ x = targetRect.left;
145
+ }
146
+ else if (horizontal === 'center') {
147
+ x = targetRect.centerX - floatingRect.width / 2;
148
+ }
149
+ else {
150
+ x = targetRect.right - floatingRect.width;
151
+ }
152
+ }
153
+ // Calculate Y position
154
+ let y;
155
+ if (orientation === 'vertical') {
156
+ // Left/right placements
157
+ if (vertical === 'center') {
158
+ y = targetRect.centerY - floatingRect.height / 2;
159
+ }
160
+ else if (vertical === 'end') {
161
+ y = targetRect.bottom - floatingRect.height - containerPadding;
162
+ }
163
+ else {
164
+ y = targetRect.top;
165
+ }
166
+ }
167
+ else {
168
+ // Top/bottom placements
169
+ if (vertical === 'top') {
170
+ y = targetRect.top - floatingRect.height - offset + containerPadding;
171
+ }
172
+ else {
173
+ y = targetRect.bottom + offset - containerPadding;
174
+ }
175
+ }
176
+ // Calculate overflow for each edge
177
+ const overflow = {
178
+ top: Math.min(0, y - padding),
179
+ left: Math.min(0, x - padding),
180
+ bottom: Math.min(0, viewport.height - (y + floatingRect.height + padding)),
181
+ right: Math.min(0, viewport.width - (x + floatingRect.width + padding + scrollbarWidth)),
182
+ };
183
+ // Sum of absolute overflow values
184
+ const overflowAmount = Object.values(overflow).reduce((sum, val) => sum + Math.abs(val), 0);
185
+ return {
186
+ x: Math.round(x),
187
+ y: Math.round(y),
188
+ placement,
189
+ overflow,
190
+ overflowAmount,
191
+ fits: overflowAmount === 0,
192
+ };
193
+ }
194
+ /**
195
+ * Find the best position for the floating element
196
+ * Tries all preference placements and returns the one that fits best
197
+ */
198
+ export function findBestPosition(options) {
199
+ const { targetEl, floatingEl, preferences = placementPreferences.default, offset = 8, padding = 8, containerPadding = 0, } = options;
200
+ const targetRect = getElementRect(targetEl);
201
+ const floatingRect = getElementRect(floatingEl);
202
+ const scrollbarWidth = 15;
203
+ // Calculate all candidate positions
204
+ const candidates = preferences.map(placement => calculatePlacement({
205
+ targetRect,
206
+ floatingRect,
207
+ placement,
208
+ offset,
209
+ padding,
210
+ containerPadding,
211
+ scrollbarWidth,
212
+ }));
213
+ // Find first that fits, or one with least overflow
214
+ const bestPosition = candidates.find(c => c.fits) ||
215
+ candidates.reduce((best, current) => current.overflowAmount < best.overflowAmount ? current : best);
216
+ // Adjust for scrollbar if needed
217
+ if (bestPosition.overflow.right < 0) {
218
+ bestPosition.x += bestPosition.overflow.right;
219
+ }
220
+ return bestPosition;
221
+ }
222
+ // ============================================================================
223
+ // Auto-Update Functionality
224
+ // ============================================================================
225
+ /**
226
+ * Create auto-update system for position tracking
227
+ * Continuously monitors and updates position when target or floating element changes
228
+ *
229
+ * @param targetEl - The anchor element to position relative to
230
+ * @param floatingEl - The floating element to position
231
+ * @param updateFn - Callback function that receives new position data
232
+ * @param config - Position options (same as findBestPosition)
233
+ * @returns Cleanup function to stop auto-updating
234
+ */
235
+ export function autoUpdate(targetEl, floatingEl, updateFn, config) {
236
+ let active = true;
237
+ let scrollRafId = null;
238
+ let resizeTimeout = null;
239
+ let resizeObserver = null;
240
+ let mutationObserver = null;
241
+ // Update function that recalculates position
242
+ const update = () => {
243
+ if (!active)
244
+ return;
245
+ const position = findBestPosition({
246
+ targetEl,
247
+ floatingEl,
248
+ ...config,
249
+ });
250
+ updateFn(position);
251
+ };
252
+ // Initial update
253
+ update();
254
+ // Debounced update for resize events
255
+ const debouncedUpdate = () => {
256
+ if (resizeTimeout !== null) {
257
+ clearTimeout(resizeTimeout);
258
+ }
259
+ resizeTimeout = window.setTimeout(() => {
260
+ resizeTimeout = null;
261
+ update();
262
+ }, 10);
263
+ };
264
+ // RAF-based scroll handler for smooth updates
265
+ const handleScroll = () => {
266
+ if (!active)
267
+ return;
268
+ if (scrollRafId === null) {
269
+ scrollRafId = requestAnimationFrame(() => {
270
+ scrollRafId = null;
271
+ update();
272
+ });
273
+ }
274
+ };
275
+ // Observe size changes on target, floating element, and body
276
+ resizeObserver = new ResizeObserver(debouncedUpdate);
277
+ resizeObserver.observe(targetEl);
278
+ resizeObserver.observe(floatingEl);
279
+ resizeObserver.observe(document.body);
280
+ // Observe DOM attribute changes on target
281
+ mutationObserver = new MutationObserver(update);
282
+ mutationObserver.observe(targetEl, {
283
+ attributes: true,
284
+ attributeFilter: ['class', 'style'],
285
+ });
286
+ // Listen for scroll events (capture phase for better performance)
287
+ window.addEventListener('scroll', handleScroll, true);
288
+ window.addEventListener('resize', debouncedUpdate);
289
+ // Return cleanup function
290
+ return () => {
291
+ active = false;
292
+ if (scrollRafId !== null) {
293
+ cancelAnimationFrame(scrollRafId);
294
+ }
295
+ if (resizeTimeout !== null) {
296
+ clearTimeout(resizeTimeout);
297
+ }
298
+ if (resizeObserver) {
299
+ resizeObserver.disconnect();
300
+ }
301
+ if (mutationObserver) {
302
+ mutationObserver.disconnect();
303
+ }
304
+ window.removeEventListener('scroll', handleScroll, true);
305
+ window.removeEventListener('resize', debouncedUpdate);
306
+ };
307
+ }
308
+ //# sourceMappingURL=positioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positioning.js","sourceRoot":"","sources":["../../src/utils/positioning.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmHH,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAuC;IAC5D,WAAW,EAAE;QACX,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,OAAO;KACpB;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,QAAQ;KACrB;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;KAClB;IACD,aAAa,EAAE;QACb,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,UAAU;KACxB;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,UAAU;KACxB;IACD,WAAW,EAAE;QACX,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,UAAU;KACxB;IACD,cAAc,EAAE;QACd,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,OAAO;KACpB;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Aa,KAAK,IAAI,EAAE,CAAC;YAC3B,YAAY,CAAC,aAAa,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,cAAc,EAAE,CAAC;YACnB,cAAc,CAAC,UAAU,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,gBAAgB,EAAE,CAAC;YACrB,gBAAgB,CAAC,UAAU,EAAE,CAAC;QAChC,CAAC;QACD,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QACzD,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Property Capture Utility
3
+ *
4
+ * Solves the problem of frameworks (React, Reagent, etc.) setting properties
5
+ * on custom elements BEFORE connectedCallback runs.
6
+ *
7
+ * PROBLEM:
8
+ * 1. Framework creates element: document.createElement('ty-dropdown')
9
+ * 2. Framework sets properties: element.value = "foo"
10
+ * 3. Constructor runs and defines getters/setters
11
+ * 4. BUT properties were already set, creating instance properties
12
+ * 5. Instance properties shadow the class getters/setters
13
+ * 6. connectedCallback runs - too late!
14
+ *
15
+ * SOLUTION:
16
+ * In connectedCallback, capture any pre-set properties and apply them properly.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * connectedCallback(): void {
21
+ * const preSetProps = capturePreSetProperties(this, [
22
+ * 'value', 'clearable', 'disabled'
23
+ * ])
24
+ *
25
+ * if (preSetProps.value !== undefined) {
26
+ * this._value = preSetProps.value
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ /**
32
+ * Captured property data
33
+ */
34
+ export interface CapturedProperty<T = any> {
35
+ name: string;
36
+ value: T;
37
+ hadProperty: boolean;
38
+ }
39
+ /**
40
+ * Options for property capture
41
+ */
42
+ export interface PropertyCaptureOptions {
43
+ /**
44
+ * Whether to delete instance properties after capture (default: true)
45
+ * This ensures the class getter/setter will work going forward
46
+ */
47
+ cleanup?: boolean;
48
+ }
49
+ /**
50
+ * Capture properties that were set before connectedCallback
51
+ *
52
+ * @param element - The custom element instance
53
+ * @param propertyNames - Array of property names to check
54
+ * @param options - Capture options
55
+ * @returns Record of captured properties with metadata
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const captured = capturePreSetProperties(this, ['value', 'disabled'])
60
+ * // {
61
+ * // value: { name: 'value', value: 'foo', hadProperty: true },
62
+ * // disabled: { name: 'disabled', value: undefined, hadProperty: false }
63
+ * // }
64
+ * ```
65
+ */
66
+ export declare function capturePreSetProperties(element: HTMLElement, propertyNames: string[], options?: PropertyCaptureOptions): Record<string, CapturedProperty>;
67
+ /**
68
+ * Simpler API - just get the values that were pre-set
69
+ *
70
+ * @param element - The custom element instance
71
+ * @param propertyNames - Array of property names to check
72
+ * @param options - Capture options
73
+ * @returns Record of property names to values (only includes properties that were set)
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const values = getCapturedValues(this, ['value', 'disabled'])
78
+ * if (values.value !== undefined) {
79
+ * this._value = values.value
80
+ * }
81
+ * ```
82
+ */
83
+ export declare function getCapturedValues(element: HTMLElement, propertyNames: string[], options?: PropertyCaptureOptions): Record<string, any>;
84
+ /**
85
+ * Mapping of public property names to private field names
86
+ */
87
+ export type PropertyMap = Record<string, string>;
88
+ /**
89
+ * Automatically apply pre-set properties to private fields
90
+ *
91
+ * @param element - The custom element instance
92
+ * @param propertyNames - Array of property names to check
93
+ * @param propertyMap - Optional mapping of public names to private field names
94
+ * Default: adds underscore prefix (e.g., 'value' -> '_value')
95
+ * @param options - Capture options
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // Simple usage (uses _propertyName convention)
100
+ * applyPreSetProperties(this, ['value', 'disabled'])
101
+ * // Sets this._value and this._disabled
102
+ *
103
+ * // Custom mapping
104
+ * applyPreSetProperties(this, ['value'], { value: 'internalValue' })
105
+ * // Sets this.internalValue
106
+ * ```
107
+ */
108
+ export declare function applyPreSetProperties(element: any, propertyNames: string[], propertyMap?: PropertyMap, options?: PropertyCaptureOptions): void;
109
+ /**
110
+ * Helper for components with standard _propertyName pattern
111
+ *
112
+ * @param element - The custom element instance
113
+ * @param propertyNames - Array of property names to check
114
+ * @param transformer - Optional function to transform values before setting
115
+ * @param options - Capture options
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * connectedCallback(): void {
120
+ * // Basic usage
121
+ * captureAndApplyProperties(this, ['value', 'disabled', 'required'])
122
+ *
123
+ * // With transformation
124
+ * captureAndApplyProperties(this, ['value'], (name, value) => {
125
+ * if (name === 'value') return this.parseValue(value)
126
+ * return value
127
+ * })
128
+ * }
129
+ * ```
130
+ */
131
+ export declare function captureAndApplyProperties(element: any, propertyNames: string[], transformer?: (name: string, value: any) => any, options?: PropertyCaptureOptions): void;
132
+ //# sourceMappingURL=property-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-capture.d.ts","sourceRoot":"","sources":["../../src/utils/property-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,CAAC,CAAA;IACR,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,GAAE,sBAA0C,GAClD,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAmBlC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAWrB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,GAAG,EACZ,aAAa,EAAE,MAAM,EAAE,EACvB,WAAW,CAAC,EAAE,WAAW,EACzB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,IAAI,CAUN;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,GAAG,EACZ,aAAa,EAAE,MAAM,EAAE,EACvB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,EAC/C,OAAO,CAAC,EAAE,sBAAsB,GAC/B,IAAI,CAUN"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Property Capture Utility
3
+ *
4
+ * Solves the problem of frameworks (React, Reagent, etc.) setting properties
5
+ * on custom elements BEFORE connectedCallback runs.
6
+ *
7
+ * PROBLEM:
8
+ * 1. Framework creates element: document.createElement('ty-dropdown')
9
+ * 2. Framework sets properties: element.value = "foo"
10
+ * 3. Constructor runs and defines getters/setters
11
+ * 4. BUT properties were already set, creating instance properties
12
+ * 5. Instance properties shadow the class getters/setters
13
+ * 6. connectedCallback runs - too late!
14
+ *
15
+ * SOLUTION:
16
+ * In connectedCallback, capture any pre-set properties and apply them properly.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * connectedCallback(): void {
21
+ * const preSetProps = capturePreSetProperties(this, [
22
+ * 'value', 'clearable', 'disabled'
23
+ * ])
24
+ *
25
+ * if (preSetProps.value !== undefined) {
26
+ * this._value = preSetProps.value
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ /**
32
+ * Capture properties that were set before connectedCallback
33
+ *
34
+ * @param element - The custom element instance
35
+ * @param propertyNames - Array of property names to check
36
+ * @param options - Capture options
37
+ * @returns Record of captured properties with metadata
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const captured = capturePreSetProperties(this, ['value', 'disabled'])
42
+ * // {
43
+ * // value: { name: 'value', value: 'foo', hadProperty: true },
44
+ * // disabled: { name: 'disabled', value: undefined, hadProperty: false }
45
+ * // }
46
+ * ```
47
+ */
48
+ export function capturePreSetProperties(element, propertyNames, options = { cleanup: true }) {
49
+ const captured = {};
50
+ for (const name of propertyNames) {
51
+ const descriptor = Object.getOwnPropertyDescriptor(element, name);
52
+ captured[name] = {
53
+ name,
54
+ value: descriptor?.value,
55
+ hadProperty: descriptor !== undefined && descriptor.value !== undefined
56
+ };
57
+ // Clean up instance property so class getter/setter works
58
+ if (options.cleanup && captured[name].hadProperty) {
59
+ delete element[name];
60
+ }
61
+ }
62
+ return captured;
63
+ }
64
+ /**
65
+ * Simpler API - just get the values that were pre-set
66
+ *
67
+ * @param element - The custom element instance
68
+ * @param propertyNames - Array of property names to check
69
+ * @param options - Capture options
70
+ * @returns Record of property names to values (only includes properties that were set)
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const values = getCapturedValues(this, ['value', 'disabled'])
75
+ * if (values.value !== undefined) {
76
+ * this._value = values.value
77
+ * }
78
+ * ```
79
+ */
80
+ export function getCapturedValues(element, propertyNames, options) {
81
+ const captured = capturePreSetProperties(element, propertyNames, options);
82
+ const values = {};
83
+ for (const [name, data] of Object.entries(captured)) {
84
+ if (data.hadProperty) {
85
+ values[name] = data.value;
86
+ }
87
+ }
88
+ return values;
89
+ }
90
+ /**
91
+ * Automatically apply pre-set properties to private fields
92
+ *
93
+ * @param element - The custom element instance
94
+ * @param propertyNames - Array of property names to check
95
+ * @param propertyMap - Optional mapping of public names to private field names
96
+ * Default: adds underscore prefix (e.g., 'value' -> '_value')
97
+ * @param options - Capture options
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // Simple usage (uses _propertyName convention)
102
+ * applyPreSetProperties(this, ['value', 'disabled'])
103
+ * // Sets this._value and this._disabled
104
+ *
105
+ * // Custom mapping
106
+ * applyPreSetProperties(this, ['value'], { value: 'internalValue' })
107
+ * // Sets this.internalValue
108
+ * ```
109
+ */
110
+ export function applyPreSetProperties(element, propertyNames, propertyMap, options) {
111
+ const captured = capturePreSetProperties(element, propertyNames, options);
112
+ for (const [name, data] of Object.entries(captured)) {
113
+ if (data.hadProperty) {
114
+ // Determine the private field name
115
+ const privateName = propertyMap?.[name] || `_${name}`;
116
+ element[privateName] = data.value;
117
+ }
118
+ }
119
+ }
120
+ /**
121
+ * Helper for components with standard _propertyName pattern
122
+ *
123
+ * @param element - The custom element instance
124
+ * @param propertyNames - Array of property names to check
125
+ * @param transformer - Optional function to transform values before setting
126
+ * @param options - Capture options
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * connectedCallback(): void {
131
+ * // Basic usage
132
+ * captureAndApplyProperties(this, ['value', 'disabled', 'required'])
133
+ *
134
+ * // With transformation
135
+ * captureAndApplyProperties(this, ['value'], (name, value) => {
136
+ * if (name === 'value') return this.parseValue(value)
137
+ * return value
138
+ * })
139
+ * }
140
+ * ```
141
+ */
142
+ export function captureAndApplyProperties(element, propertyNames, transformer, options) {
143
+ const captured = capturePreSetProperties(element, propertyNames, options);
144
+ for (const [name, data] of Object.entries(captured)) {
145
+ if (data.hadProperty) {
146
+ const privateName = `_${name}`;
147
+ const value = transformer ? transformer(name, data.value) : data.value;
148
+ element[privateName] = value;
149
+ }
150
+ }
151
+ }
152
+ //# sourceMappingURL=property-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-capture.js","sourceRoot":"","sources":["../../src/utils/property-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAsBH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAoB,EACpB,aAAuB,EACvB,UAAkC,EAAE,OAAO,EAAE,IAAI,EAAE;IA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