@arolariu/components 0.1.2 → 0.3.0

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 (360) hide show
  1. package/DEBUGGING.md +396 -396
  2. package/LICENSE.md +21 -21
  3. package/changelog.md +120 -118
  4. package/dist/components/ui/accordion.d.ts +6 -6
  5. package/dist/components/ui/accordion.d.ts.map +1 -1
  6. package/dist/components/ui/accordion.js +20 -28
  7. package/dist/components/ui/accordion.js.map +1 -1
  8. package/dist/components/ui/alert-dialog.d.ts +19 -13
  9. package/dist/components/ui/alert-dialog.d.ts.map +1 -1
  10. package/dist/components/ui/alert-dialog.js +40 -63
  11. package/dist/components/ui/alert-dialog.js.map +1 -1
  12. package/dist/components/ui/alert.d.ts +7 -8
  13. package/dist/components/ui/alert.d.ts.map +1 -1
  14. package/dist/components/ui/alert.js +18 -21
  15. package/dist/components/ui/alert.js.map +1 -1
  16. package/dist/components/ui/aspect-ratio.d.ts +1 -2
  17. package/dist/components/ui/aspect-ratio.d.ts.map +1 -1
  18. package/dist/components/ui/aspect-ratio.js +1 -8
  19. package/dist/components/ui/aspect-ratio.js.map +1 -1
  20. package/dist/components/ui/avatar.d.ts +5 -5
  21. package/dist/components/ui/avatar.d.ts.map +1 -1
  22. package/dist/components/ui/avatar.js +17 -20
  23. package/dist/components/ui/avatar.js.map +1 -1
  24. package/dist/components/ui/background-beams.d.ts.map +1 -1
  25. package/dist/components/ui/background-beams.js +6 -6
  26. package/dist/components/ui/background-beams.js.map +1 -1
  27. package/dist/components/ui/badge.d.ts +7 -7
  28. package/dist/components/ui/badge.d.ts.map +1 -1
  29. package/dist/components/ui/badge.js +9 -12
  30. package/dist/components/ui/badge.js.map +1 -1
  31. package/dist/components/ui/breadcrumb.d.ts +17 -9
  32. package/dist/components/ui/breadcrumb.d.ts.map +1 -1
  33. package/dist/components/ui/breadcrumb.js +32 -39
  34. package/dist/components/ui/breadcrumb.js.map +1 -1
  35. package/dist/components/ui/bubble-background.d.ts +1 -1
  36. package/dist/components/ui/bubble-background.d.ts.map +1 -1
  37. package/dist/components/ui/bubble-background.js +13 -13
  38. package/dist/components/ui/bubble-background.js.map +1 -1
  39. package/dist/components/ui/button-group.d.ts +13 -0
  40. package/dist/components/ui/button-group.d.ts.map +1 -0
  41. package/dist/components/ui/button-group.js +47 -0
  42. package/dist/components/ui/button-group.js.map +1 -0
  43. package/dist/components/ui/button.d.ts +8 -7
  44. package/dist/components/ui/button.d.ts.map +1 -1
  45. package/dist/components/ui/button.js +16 -15
  46. package/dist/components/ui/button.js.map +1 -1
  47. package/dist/components/ui/calendar.d.ts.map +1 -1
  48. package/dist/components/ui/calendar.js +22 -22
  49. package/dist/components/ui/calendar.js.map +1 -1
  50. package/dist/components/ui/card.d.ts +7 -8
  51. package/dist/components/ui/card.d.ts.map +1 -1
  52. package/dist/components/ui/card.js +33 -46
  53. package/dist/components/ui/card.js.map +1 -1
  54. package/dist/components/ui/carousel.d.ts +7 -8
  55. package/dist/components/ui/carousel.d.ts.map +1 -1
  56. package/dist/components/ui/carousel.js +30 -21
  57. package/dist/components/ui/carousel.js.map +1 -1
  58. package/dist/components/ui/chart.d.ts +37 -29
  59. package/dist/components/ui/chart.d.ts.map +1 -1
  60. package/dist/components/ui/chart.js +29 -27
  61. package/dist/components/ui/chart.js.map +1 -1
  62. package/dist/components/ui/checkbox.d.ts +2 -2
  63. package/dist/components/ui/checkbox.d.ts.map +1 -1
  64. package/dist/components/ui/checkbox.js +11 -13
  65. package/dist/components/ui/checkbox.js.map +1 -1
  66. package/dist/components/ui/collapsible.d.ts +4 -5
  67. package/dist/components/ui/collapsible.d.ts.map +1 -1
  68. package/dist/components/ui/collapsible.js +3 -20
  69. package/dist/components/ui/collapsible.js.map +1 -1
  70. package/dist/components/ui/command.d.ts +79 -17
  71. package/dist/components/ui/command.d.ts.map +1 -1
  72. package/dist/components/ui/command.js +52 -77
  73. package/dist/components/ui/command.js.map +1 -1
  74. package/dist/components/ui/context-menu.d.ts +23 -21
  75. package/dist/components/ui/context-menu.d.ts.map +1 -1
  76. package/dist/components/ui/context-menu.js +60 -104
  77. package/dist/components/ui/context-menu.js.map +1 -1
  78. package/dist/components/ui/counting-number.d.ts +1 -1
  79. package/dist/components/ui/counting-number.d.ts.map +1 -1
  80. package/dist/components/ui/counting-number.js +4 -3
  81. package/dist/components/ui/counting-number.js.map +1 -1
  82. package/dist/components/ui/dialog.d.ts +17 -13
  83. package/dist/components/ui/dialog.d.ts.map +1 -1
  84. package/dist/components/ui/dialog.js +38 -66
  85. package/dist/components/ui/dialog.js.map +1 -1
  86. package/dist/components/ui/dot-background.d.ts +10 -17
  87. package/dist/components/ui/dot-background.d.ts.map +1 -1
  88. package/dist/components/ui/dot-background.js +2 -2
  89. package/dist/components/ui/dot-background.js.map +1 -1
  90. package/dist/components/ui/drawer.d.ts +20 -11
  91. package/dist/components/ui/drawer.d.ts.map +1 -1
  92. package/dist/components/ui/drawer.js +37 -62
  93. package/dist/components/ui/drawer.js.map +1 -1
  94. package/dist/components/ui/dropdown-menu.d.ts +23 -21
  95. package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
  96. package/dist/components/ui/dropdown-menu.js +65 -109
  97. package/dist/components/ui/dropdown-menu.js.map +1 -1
  98. package/dist/components/ui/dropdrawer.d.ts +3 -3
  99. package/dist/components/ui/dropdrawer.d.ts.map +1 -1
  100. package/dist/components/ui/dropdrawer.js +13 -16
  101. package/dist/components/ui/dropdrawer.js.map +1 -1
  102. package/dist/components/ui/empty.d.ts +13 -0
  103. package/dist/components/ui/empty.d.ts.map +1 -0
  104. package/dist/components/ui/empty.js +65 -0
  105. package/dist/components/ui/empty.js.map +1 -0
  106. package/dist/components/ui/field.d.ts +25 -0
  107. package/dist/components/ui/field.d.ts.map +1 -0
  108. package/dist/components/ui/field.js +135 -0
  109. package/dist/components/ui/field.js.map +1 -0
  110. package/dist/components/ui/fireworks-background.d.ts.map +1 -1
  111. package/dist/components/ui/fireworks-background.js +1 -1
  112. package/dist/components/ui/fireworks-background.js.map +1 -1
  113. package/dist/components/ui/flip-button.d.ts +1 -1
  114. package/dist/components/ui/flip-button.d.ts.map +1 -1
  115. package/dist/components/ui/flip-button.js +3 -3
  116. package/dist/components/ui/flip-button.js.map +1 -1
  117. package/dist/components/ui/form.d.ts +7 -8
  118. package/dist/components/ui/form.d.ts.map +1 -1
  119. package/dist/components/ui/form.js +29 -28
  120. package/dist/components/ui/form.js.map +1 -1
  121. package/dist/components/ui/gradient-background.d.ts +1 -1
  122. package/dist/components/ui/gradient-background.d.ts.map +1 -1
  123. package/dist/components/ui/gradient-background.js +2 -2
  124. package/dist/components/ui/gradient-background.js.map +1 -1
  125. package/dist/components/ui/gradient-text.d.ts +1 -1
  126. package/dist/components/ui/gradient-text.d.ts.map +1 -1
  127. package/dist/components/ui/gradient-text.js +5 -5
  128. package/dist/components/ui/gradient-text.js.map +1 -1
  129. package/dist/components/ui/highlight-text.d.ts +1 -1
  130. package/dist/components/ui/highlight-text.d.ts.map +1 -1
  131. package/dist/components/ui/highlight-text.js +3 -3
  132. package/dist/components/ui/highlight-text.js.map +1 -1
  133. package/dist/components/ui/hole-background.d.ts.map +1 -1
  134. package/dist/components/ui/hole-background.js +11 -10
  135. package/dist/components/ui/hole-background.js.map +1 -1
  136. package/dist/components/ui/hover-card.d.ts +5 -5
  137. package/dist/components/ui/hover-card.d.ts.map +1 -1
  138. package/dist/components/ui/hover-card.js +12 -26
  139. package/dist/components/ui/hover-card.js.map +1 -1
  140. package/dist/components/ui/input-group.d.ts +17 -0
  141. package/dist/components/ui/input-group.d.ts.map +1 -0
  142. package/dist/components/ui/input-group.js +91 -0
  143. package/dist/components/ui/input-group.js.map +1 -0
  144. package/dist/components/ui/input-otp.d.ts +31 -8
  145. package/dist/components/ui/input-otp.d.ts.map +1 -1
  146. package/dist/components/ui/input-otp.js +24 -27
  147. package/dist/components/ui/input-otp.js.map +1 -1
  148. package/dist/components/ui/input.d.ts +1 -1
  149. package/dist/components/ui/input.d.ts.map +1 -1
  150. package/dist/components/ui/input.js +7 -8
  151. package/dist/components/ui/input.js.map +1 -1
  152. package/dist/components/ui/item.d.ts +24 -0
  153. package/dist/components/ui/item.d.ts.map +1 -0
  154. package/dist/components/ui/item.js +122 -0
  155. package/dist/components/ui/item.js.map +1 -0
  156. package/dist/components/ui/kbd.d.ts +5 -0
  157. package/dist/components/ui/kbd.d.ts.map +1 -0
  158. package/dist/components/ui/kbd.js +21 -0
  159. package/dist/components/ui/kbd.js.map +1 -0
  160. package/dist/components/ui/label.d.ts +3 -2
  161. package/dist/components/ui/label.d.ts.map +1 -1
  162. package/dist/components/ui/label.js +9 -8
  163. package/dist/components/ui/label.js.map +1 -1
  164. package/dist/components/ui/menubar.d.ts +20 -18
  165. package/dist/components/ui/menubar.d.ts.map +1 -1
  166. package/dist/components/ui/menubar.js +75 -95
  167. package/dist/components/ui/menubar.js.map +1 -1
  168. package/dist/components/ui/navigation-menu.d.ts +11 -13
  169. package/dist/components/ui/navigation-menu.d.ts.map +1 -1
  170. package/dist/components/ui/navigation-menu.js +39 -58
  171. package/dist/components/ui/navigation-menu.js.map +1 -1
  172. package/dist/components/ui/pagination.d.ts +25 -10
  173. package/dist/components/ui/pagination.d.ts.map +1 -1
  174. package/dist/components/ui/pagination.js +33 -41
  175. package/dist/components/ui/pagination.js.map +1 -1
  176. package/dist/components/ui/popover.d.ts +6 -6
  177. package/dist/components/ui/popover.d.ts.map +1 -1
  178. package/dist/components/ui/popover.js +10 -26
  179. package/dist/components/ui/popover.js.map +1 -1
  180. package/dist/components/ui/progress.d.ts +2 -2
  181. package/dist/components/ui/progress.d.ts.map +1 -1
  182. package/dist/components/ui/progress.js +8 -10
  183. package/dist/components/ui/progress.js.map +1 -1
  184. package/dist/components/ui/radio-group.d.ts +3 -3
  185. package/dist/components/ui/radio-group.d.ts.map +1 -1
  186. package/dist/components/ui/radio-group.js +17 -20
  187. package/dist/components/ui/radio-group.js.map +1 -1
  188. package/dist/components/ui/resizable.d.ts +21 -6
  189. package/dist/components/ui/resizable.d.ts.map +1 -1
  190. package/dist/components/ui/resizable.js +9 -21
  191. package/dist/components/ui/resizable.js.map +1 -1
  192. package/dist/components/ui/ripple-button.d.ts +1 -1
  193. package/dist/components/ui/ripple-button.d.ts.map +1 -1
  194. package/dist/components/ui/ripple-button.js +4 -4
  195. package/dist/components/ui/ripple-button.js.map +1 -1
  196. package/dist/components/ui/scratcher.d.ts.map +1 -1
  197. package/dist/components/ui/scratcher.js +7 -5
  198. package/dist/components/ui/scratcher.js.map +1 -1
  199. package/dist/components/ui/scroll-area.d.ts +3 -3
  200. package/dist/components/ui/scroll-area.d.ts.map +1 -1
  201. package/dist/components/ui/scroll-area.js +14 -18
  202. package/dist/components/ui/scroll-area.js.map +1 -1
  203. package/dist/components/ui/select.d.ts +11 -13
  204. package/dist/components/ui/select.d.ts.map +1 -1
  205. package/dist/components/ui/select.js +55 -78
  206. package/dist/components/ui/select.js.map +1 -1
  207. package/dist/components/ui/separator.d.ts +2 -2
  208. package/dist/components/ui/separator.d.ts.map +1 -1
  209. package/dist/components/ui/separator.js +7 -8
  210. package/dist/components/ui/separator.js.map +1 -1
  211. package/dist/components/ui/sheet.d.ts +24 -12
  212. package/dist/components/ui/sheet.d.ts.map +1 -1
  213. package/dist/components/ui/sheet.js +56 -68
  214. package/dist/components/ui/sheet.js.map +1 -1
  215. package/dist/components/ui/sidebar.d.ts +35 -39
  216. package/dist/components/ui/sidebar.d.ts.map +1 -1
  217. package/dist/components/ui/sidebar.js +115 -124
  218. package/dist/components/ui/sidebar.js.map +1 -1
  219. package/dist/components/ui/skeleton.d.ts +1 -1
  220. package/dist/components/ui/skeleton.d.ts.map +1 -1
  221. package/dist/components/ui/skeleton.js +2 -3
  222. package/dist/components/ui/skeleton.js.map +1 -1
  223. package/dist/components/ui/slider.d.ts +2 -2
  224. package/dist/components/ui/slider.d.ts.map +1 -1
  225. package/dist/components/ui/slider.js +12 -31
  226. package/dist/components/ui/slider.js.map +1 -1
  227. package/dist/components/ui/sonner.d.ts +4 -2
  228. package/dist/components/ui/sonner.d.ts.map +1 -1
  229. package/dist/components/ui/sonner.js +8 -5
  230. package/dist/components/ui/sonner.js.map +1 -1
  231. package/dist/components/ui/spinner.d.ts +4 -0
  232. package/dist/components/ui/spinner.d.ts.map +1 -0
  233. package/dist/components/ui/spinner.js +16 -0
  234. package/dist/components/ui/spinner.js.map +1 -0
  235. package/dist/components/ui/switch.d.ts +2 -2
  236. package/dist/components/ui/switch.d.ts.map +1 -1
  237. package/dist/components/ui/switch.js +8 -10
  238. package/dist/components/ui/switch.js.map +1 -1
  239. package/dist/components/ui/table.d.ts +9 -9
  240. package/dist/components/ui/table.d.ts.map +1 -1
  241. package/dist/components/ui/table.js +40 -49
  242. package/dist/components/ui/table.js.map +1 -1
  243. package/dist/components/ui/tabs.d.ts +6 -6
  244. package/dist/components/ui/tabs.d.ts.map +1 -1
  245. package/dist/components/ui/tabs.js +18 -27
  246. package/dist/components/ui/tabs.js.map +1 -1
  247. package/dist/components/ui/textarea.d.ts +1 -1
  248. package/dist/components/ui/textarea.d.ts.map +1 -1
  249. package/dist/components/ui/textarea.js +7 -8
  250. package/dist/components/ui/textarea.js.map +1 -1
  251. package/dist/components/ui/toggle-group.d.ts +9 -4
  252. package/dist/components/ui/toggle-group.d.ts.map +1 -1
  253. package/dist/components/ui/toggle-group.js +12 -16
  254. package/dist/components/ui/toggle-group.js.map +1 -1
  255. package/dist/components/ui/toggle.d.ts +9 -6
  256. package/dist/components/ui/toggle.d.ts.map +1 -1
  257. package/dist/components/ui/toggle.js +8 -9
  258. package/dist/components/ui/toggle.js.map +1 -1
  259. package/dist/components/ui/tooltip.d.ts +6 -6
  260. package/dist/components/ui/tooltip.d.ts.map +1 -1
  261. package/dist/components/ui/tooltip.js +14 -39
  262. package/dist/components/ui/tooltip.js.map +1 -1
  263. package/dist/components/ui/typewriter.d.ts.map +1 -1
  264. package/dist/components/ui/typewriter.js +9 -9
  265. package/dist/components/ui/typewriter.js.map +1 -1
  266. package/dist/hooks/useIsMobile.d.ts +2 -5
  267. package/dist/hooks/useIsMobile.d.ts.map +1 -1
  268. package/dist/hooks/useIsMobile.js +1 -1
  269. package/dist/hooks/useIsMobile.js.map +1 -1
  270. package/dist/hooks/useWindowSize.d.ts +0 -1
  271. package/dist/hooks/useWindowSize.d.ts.map +1 -1
  272. package/dist/hooks/useWindowSize.js +1 -1
  273. package/dist/hooks/useWindowSize.js.map +1 -1
  274. package/dist/index.css +841 -1128
  275. package/dist/index.css.map +1 -1
  276. package/dist/index.d.ts +43 -37
  277. package/dist/index.d.ts.map +1 -1
  278. package/dist/index.js +11 -5
  279. package/dist/lib/utilities.d.ts +9 -0
  280. package/dist/lib/utilities.d.ts.map +1 -0
  281. package/dist/lib/{utils.js → utilities.js} +1 -1
  282. package/dist/lib/utilities.js.map +1 -0
  283. package/package.json +121 -90
  284. package/{README.md → readme.md} +627 -627
  285. package/src/components/ui/accordion.tsx +55 -66
  286. package/src/components/ui/alert-dialog.tsx +124 -160
  287. package/src/components/ui/alert.tsx +56 -69
  288. package/src/components/ui/aspect-ratio.tsx +7 -12
  289. package/src/components/ui/avatar.tsx +43 -53
  290. package/src/components/ui/background-beams.tsx +145 -142
  291. package/src/components/ui/badge.tsx +39 -48
  292. package/src/components/ui/breadcrumb.tsx +94 -117
  293. package/src/components/ui/bubble-background.tsx +170 -189
  294. package/src/components/ui/button-group.tsx +69 -0
  295. package/src/components/ui/button.tsx +55 -61
  296. package/src/components/ui/calendar.tsx +175 -216
  297. package/src/components/ui/card.tsx +64 -97
  298. package/src/components/ui/carousel.tsx +216 -241
  299. package/src/components/ui/chart.tsx +293 -385
  300. package/src/components/ui/checkbox.tsx +27 -32
  301. package/src/components/ui/collapsible.tsx +11 -34
  302. package/src/components/ui/command.tsx +138 -184
  303. package/src/components/ui/context-menu.tsx +186 -255
  304. package/src/components/ui/counting-number.tsx +92 -108
  305. package/src/components/ui/dialog.tsx +106 -146
  306. package/src/components/ui/dot-background.tsx +153 -158
  307. package/src/components/ui/drawer.tsx +105 -141
  308. package/src/components/ui/dropdown-menu.tsx +188 -260
  309. package/src/components/ui/dropdrawer.tsx +865 -973
  310. package/src/components/ui/empty.tsx +86 -0
  311. package/src/components/ui/field.tsx +198 -0
  312. package/src/components/ui/fireworks-background.tsx +325 -378
  313. package/src/components/ui/flip-button.tsx +89 -110
  314. package/src/components/ui/form.tsx +144 -174
  315. package/src/components/ui/gradient-background.tsx +30 -43
  316. package/src/components/ui/gradient-text.tsx +62 -65
  317. package/src/components/ui/highlight-text.tsx +54 -71
  318. package/src/components/ui/hole-background.tsx +326 -361
  319. package/src/components/ui/hover-card.tsx +29 -44
  320. package/src/components/ui/input-group.tsx +145 -0
  321. package/src/components/ui/input-otp.tsx +66 -77
  322. package/src/components/ui/input.tsx +21 -22
  323. package/src/components/ui/item.tsx +163 -0
  324. package/src/components/ui/kbd.tsx +31 -0
  325. package/src/components/ui/label.tsx +23 -24
  326. package/src/components/ui/menubar.tsx +233 -279
  327. package/src/components/ui/navigation-menu.tsx +120 -171
  328. package/src/components/ui/pagination.tsx +92 -129
  329. package/src/components/ui/popover.tsx +33 -48
  330. package/src/components/ui/progress.tsx +24 -31
  331. package/src/components/ui/radio-group.tsx +43 -45
  332. package/src/components/ui/resizable.tsx +38 -56
  333. package/src/components/ui/ripple-button.tsx +90 -111
  334. package/src/components/ui/scratcher.tsx +167 -171
  335. package/src/components/ui/scroll-area.tsx +42 -58
  336. package/src/components/ui/select.tsx +145 -191
  337. package/src/components/ui/separator.tsx +26 -28
  338. package/src/components/ui/sheet.tsx +112 -145
  339. package/src/components/ui/sidebar.tsx +664 -729
  340. package/src/components/ui/skeleton.tsx +15 -19
  341. package/src/components/ui/slider.tsx +23 -63
  342. package/src/components/ui/sonner.tsx +36 -26
  343. package/src/components/ui/spinner.tsx +18 -0
  344. package/src/components/ui/switch.tsx +28 -31
  345. package/src/components/ui/table.tsx +93 -119
  346. package/src/components/ui/tabs.tsx +54 -66
  347. package/src/components/ui/textarea.tsx +21 -20
  348. package/src/components/ui/toggle-group.tsx +53 -73
  349. package/src/components/ui/toggle.tsx +44 -47
  350. package/src/components/ui/tooltip.tsx +32 -61
  351. package/src/components/ui/typewriter.tsx +173 -188
  352. package/src/hooks/useIsMobile.tsx +42 -45
  353. package/src/hooks/useWindowSize.tsx +66 -72
  354. package/src/index.css +67 -67
  355. package/src/index.ts +342 -408
  356. package/src/lib/utilities.ts +12 -0
  357. package/dist/lib/utils.d.ts +0 -7
  358. package/dist/lib/utils.d.ts.map +0 -1
  359. package/dist/lib/utils.js.map +0 -1
  360. package/src/lib/utils.ts +0 -10
@@ -1,378 +1,325 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
-
5
- import { cn } from "@/lib/utils";
6
-
7
- const rand = (min: number, max: number): number =>
8
- Math.random() * (max - min) + min;
9
- const randInt = (min: number, max: number): number =>
10
- Math.floor(Math.random() * (max - min) + min);
11
- const randColor = (): string => `hsl(${randInt(0, 360)}, 100%, 50%)`;
12
-
13
- interface ParticleType {
14
- x: number;
15
- y: number;
16
- color: string;
17
- speed: number;
18
- direction: number;
19
- vx: number;
20
- vy: number;
21
- gravity: number;
22
- friction: number;
23
- alpha: number;
24
- decay: number;
25
- size: number;
26
- update: () => void;
27
- draw: (ctx: CanvasRenderingContext2D) => void;
28
- isAlive: () => boolean;
29
- }
30
-
31
- const createParticle = (
32
- x: number,
33
- y: number,
34
- color: string,
35
- speed: number,
36
- direction: number,
37
- gravity: number,
38
- friction: number,
39
- size: number,
40
- ): ParticleType => {
41
- const vx = Math.cos(direction) * speed;
42
- const vy = Math.sin(direction) * speed;
43
- const alpha = 1;
44
- const decay = rand(0.005, 0.02);
45
-
46
- return {
47
- x,
48
- y,
49
- color,
50
- speed,
51
- direction,
52
- vx,
53
- vy,
54
- gravity,
55
- friction,
56
- alpha,
57
- decay,
58
- size,
59
- update() {
60
- this.vx *= this.friction;
61
- this.vy *= this.friction;
62
- this.vy += this.gravity;
63
- this.x += this.vx;
64
- this.y += this.vy;
65
- this.alpha -= this.decay;
66
- },
67
- draw(ctx: CanvasRenderingContext2D) {
68
- ctx.save();
69
- ctx.globalAlpha = this.alpha;
70
- ctx.beginPath();
71
- ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
72
- ctx.fillStyle = this.color;
73
- ctx.fill();
74
- ctx.restore();
75
- },
76
- isAlive() {
77
- return this.alpha > 0;
78
- },
79
- };
80
- };
81
-
82
- interface FireworkType {
83
- x: number;
84
- y: number;
85
- targetY: number;
86
- color: string;
87
- speed: number;
88
- size: number;
89
- angle: number;
90
- vx: number;
91
- vy: number;
92
- trail: { x: number; y: number }[];
93
- trailLength: number;
94
- exploded: boolean;
95
- update: () => boolean;
96
- explode: () => void;
97
- draw: (ctx: CanvasRenderingContext2D) => void;
98
- }
99
-
100
- const createFirework = (
101
- x: number,
102
- y: number,
103
- targetY: number,
104
- color: string,
105
- speed: number,
106
- size: number,
107
- particleSpeed: { min: number; max: number } | number,
108
- particleSize: { min: number; max: number } | number,
109
- onExplode: (particles: ParticleType[]) => void,
110
- ): FireworkType => {
111
- const angle = -Math.PI / 2 + rand(-0.3, 0.3);
112
- const vx = Math.cos(angle) * speed;
113
- const vy = Math.sin(angle) * speed;
114
- const trail: { x: number; y: number }[] = [];
115
- const trailLength = randInt(10, 25);
116
-
117
- return {
118
- x,
119
- y,
120
- targetY,
121
- color,
122
- speed,
123
- size,
124
- angle,
125
- vx,
126
- vy,
127
- trail,
128
- trailLength,
129
- exploded: false,
130
- update() {
131
- this.trail.push({ x: this.x, y: this.y });
132
- if (this.trail.length > this.trailLength) {
133
- this.trail.shift();
134
- }
135
- this.x += this.vx;
136
- this.y += this.vy;
137
- this.vy += 0.02;
138
- if (this.vy >= 0 || this.y <= this.targetY) {
139
- this.explode();
140
- return false;
141
- }
142
- return true;
143
- },
144
- explode() {
145
- const numParticles = randInt(50, 150);
146
- const particles: ParticleType[] = [];
147
- for (let i = 0; i < numParticles; i++) {
148
- const particleAngle = rand(0, Math.PI * 2);
149
- const localParticleSpeed = getValueByRange(particleSpeed);
150
- const localParticleSize = getValueByRange(particleSize);
151
- particles.push(
152
- createParticle(
153
- this.x,
154
- this.y,
155
- this.color,
156
- localParticleSpeed,
157
- particleAngle,
158
- 0.05,
159
- 0.98,
160
- localParticleSize,
161
- ),
162
- );
163
- }
164
- onExplode(particles);
165
- },
166
- draw(ctx: CanvasRenderingContext2D) {
167
- ctx.save();
168
- ctx.beginPath();
169
- if (this.trail.length > 1) {
170
- ctx.moveTo(this.trail[0].x, this.trail[0].y);
171
- for (const point of this.trail) {
172
- ctx.lineTo(point.x, point.y);
173
- }
174
- } else {
175
- ctx.moveTo(this.x, this.y);
176
- ctx.lineTo(this.x, this.y);
177
- }
178
- ctx.strokeStyle = this.color;
179
- ctx.lineWidth = this.size;
180
- ctx.lineCap = "round";
181
- ctx.stroke();
182
- ctx.restore();
183
- },
184
- };
185
- };
186
-
187
- const getValueByRange = (
188
- range: { min: number; max: number } | number,
189
- ): number => {
190
- if (typeof range === "number") {
191
- return range;
192
- }
193
- return rand(range.min, range.max);
194
- };
195
-
196
- const getColor = (color: string | string[] | undefined): string => {
197
- if (Array.isArray(color)) {
198
- return color[randInt(0, color.length)];
199
- }
200
- return color ?? randColor();
201
- };
202
-
203
- interface FireworksBackgroundProps
204
- extends Omit<React.HTMLAttributes<HTMLDivElement>, "color"> {
205
- canvasProps?: React.HTMLAttributes<HTMLCanvasElement>;
206
- population?: number;
207
- color?: string | string[];
208
- fireworkSpeed?: { min: number; max: number } | number;
209
- fireworkSize?: { min: number; max: number } | number;
210
- particleSpeed?: { min: number; max: number } | number;
211
- particleSize?: { min: number; max: number } | number;
212
- }
213
-
214
- const FireworksBackground = React.forwardRef<
215
- HTMLDivElement,
216
- FireworksBackgroundProps
217
- >(
218
- (
219
- {
220
- className,
221
- canvasProps,
222
- population = 1,
223
- color,
224
- fireworkSpeed = { min: 4, max: 8 },
225
- fireworkSize = { min: 2, max: 5 },
226
- particleSpeed = { min: 2, max: 7 },
227
- particleSize = { min: 1, max: 5 },
228
- ...props
229
- },
230
- ref,
231
- ) => {
232
- const canvasRef = React.useRef<HTMLCanvasElement>(null);
233
- const containerRef = React.useRef<HTMLDivElement>(null);
234
- React.useImperativeHandle(
235
- ref,
236
- () => containerRef.current as HTMLDivElement,
237
- );
238
-
239
- React.useEffect(() => {
240
- const canvas = canvasRef.current;
241
- const container = containerRef.current;
242
- if (!canvas || !container) return;
243
- const ctx = canvas.getContext("2d");
244
- if (!ctx) return;
245
-
246
- let maxX = window.innerWidth;
247
- let ratio = container.offsetHeight / container.offsetWidth;
248
- let maxY = maxX * ratio;
249
- canvas.width = maxX;
250
- canvas.height = maxY;
251
-
252
- const setCanvasSize = () => {
253
- maxX = window.innerWidth;
254
- ratio = container.offsetHeight / container.offsetWidth;
255
- maxY = maxX * ratio;
256
- canvas.width = maxX;
257
- canvas.height = maxY;
258
- };
259
- window.addEventListener("resize", setCanvasSize);
260
-
261
- const explosions: ParticleType[] = [];
262
- const fireworks: FireworkType[] = [];
263
-
264
- const handleExplosion = (particles: ParticleType[]) => {
265
- explosions.push(...particles);
266
- };
267
-
268
- const launchFirework = () => {
269
- const x = rand(maxX * 0.1, maxX * 0.9);
270
- const y = maxY;
271
- const targetY = rand(maxY * 0.1, maxY * 0.4);
272
- const fireworkColor = getColor(color);
273
- const speed = getValueByRange(fireworkSpeed);
274
- const size = getValueByRange(fireworkSize);
275
- fireworks.push(
276
- createFirework(
277
- x,
278
- y,
279
- targetY,
280
- fireworkColor,
281
- speed,
282
- size,
283
- particleSpeed,
284
- particleSize,
285
- handleExplosion,
286
- ),
287
- );
288
- const timeout = rand(300, 800) / population;
289
- setTimeout(launchFirework, timeout);
290
- };
291
-
292
- launchFirework();
293
-
294
- let animationFrameId: number;
295
- const animate = () => {
296
- ctx.clearRect(0, 0, maxX, maxY);
297
-
298
- for (let i = fireworks.length - 1; i >= 0; i--) {
299
- const firework = fireworks[i];
300
- if (!firework.update()) {
301
- fireworks.splice(i, 1);
302
- } else {
303
- firework.draw(ctx);
304
- }
305
- }
306
-
307
- for (let i = explosions.length - 1; i >= 0; i--) {
308
- const particle = explosions[i];
309
- particle.update();
310
- if (particle.isAlive()) {
311
- particle.draw(ctx);
312
- } else {
313
- explosions.splice(i, 1);
314
- }
315
- }
316
-
317
- animationFrameId = requestAnimationFrame(animate);
318
- };
319
-
320
- animate();
321
-
322
- const handleClick = (event: MouseEvent) => {
323
- const x = event.clientX;
324
- const y = maxY;
325
- const targetY = event.clientY;
326
- const fireworkColor = getColor(color);
327
- const speed = getValueByRange(fireworkSpeed);
328
- const size = getValueByRange(fireworkSize);
329
- fireworks.push(
330
- createFirework(
331
- x,
332
- y,
333
- targetY,
334
- fireworkColor,
335
- speed,
336
- size,
337
- particleSpeed,
338
- particleSize,
339
- handleExplosion,
340
- ),
341
- );
342
- };
343
-
344
- container.addEventListener("click", handleClick);
345
-
346
- return () => {
347
- window.removeEventListener("resize", setCanvasSize);
348
- container.removeEventListener("click", handleClick);
349
- cancelAnimationFrame(animationFrameId);
350
- };
351
- }, [
352
- population,
353
- color,
354
- fireworkSpeed,
355
- fireworkSize,
356
- particleSpeed,
357
- particleSize,
358
- ]);
359
-
360
- return (
361
- <div
362
- ref={containerRef}
363
- className={cn("relative size-full overflow-hidden", className)}
364
- {...props}
365
- >
366
- <canvas
367
- {...canvasProps}
368
- ref={canvasRef}
369
- className={cn("absolute inset-0 size-full", canvasProps?.className)}
370
- />
371
- </div>
372
- );
373
- },
374
- );
375
-
376
- FireworksBackground.displayName = "FireworksBackground";
377
-
378
- export { FireworksBackground, type FireworksBackgroundProps };
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ import {cn} from "@/lib/utilities";
6
+
7
+ const rand = (min: number, max: number): number => Math.random() * (max - min) + min;
8
+ const randInt = (min: number, max: number): number => Math.floor(Math.random() * (max - min) + min);
9
+ const randColor = (): string => `hsl(${randInt(0, 360)}, 100%, 50%)`;
10
+
11
+ interface ParticleType {
12
+ x: number;
13
+ y: number;
14
+ color: string;
15
+ speed: number;
16
+ direction: number;
17
+ vx: number;
18
+ vy: number;
19
+ gravity: number;
20
+ friction: number;
21
+ alpha: number;
22
+ decay: number;
23
+ size: number;
24
+ update: () => void;
25
+ draw: (ctx: CanvasRenderingContext2D) => void;
26
+ isAlive: () => boolean;
27
+ }
28
+
29
+ const createParticle = (
30
+ x: number,
31
+ y: number,
32
+ color: string,
33
+ speed: number,
34
+ direction: number,
35
+ gravity: number,
36
+ friction: number,
37
+ size: number,
38
+ ): ParticleType => {
39
+ const vx = Math.cos(direction) * speed;
40
+ const vy = Math.sin(direction) * speed;
41
+ const alpha = 1;
42
+ const decay = rand(0.005, 0.02);
43
+
44
+ return {
45
+ x,
46
+ y,
47
+ color,
48
+ speed,
49
+ direction,
50
+ vx,
51
+ vy,
52
+ gravity,
53
+ friction,
54
+ alpha,
55
+ decay,
56
+ size,
57
+ update() {
58
+ this.vx *= this.friction;
59
+ this.vy *= this.friction;
60
+ this.vy += this.gravity;
61
+ this.x += this.vx;
62
+ this.y += this.vy;
63
+ this.alpha -= this.decay;
64
+ },
65
+ draw(ctx: CanvasRenderingContext2D) {
66
+ ctx.save();
67
+ ctx.globalAlpha = this.alpha;
68
+ ctx.beginPath();
69
+ ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
70
+ ctx.fillStyle = this.color;
71
+ ctx.fill();
72
+ ctx.restore();
73
+ },
74
+ isAlive() {
75
+ return this.alpha > 0;
76
+ },
77
+ };
78
+ };
79
+
80
+ interface FireworkType {
81
+ x: number;
82
+ y: number;
83
+ targetY: number;
84
+ color: string;
85
+ speed: number;
86
+ size: number;
87
+ angle: number;
88
+ vx: number;
89
+ vy: number;
90
+ trail: {x: number; y: number}[];
91
+ trailLength: number;
92
+ exploded: boolean;
93
+ update: () => boolean;
94
+ explode: () => void;
95
+ draw: (ctx: CanvasRenderingContext2D) => void;
96
+ }
97
+
98
+ const createFirework = (
99
+ x: number,
100
+ y: number,
101
+ targetY: number,
102
+ color: string,
103
+ speed: number,
104
+ size: number,
105
+ particleSpeed: {min: number; max: number} | number,
106
+ particleSize: {min: number; max: number} | number,
107
+ onExplode: (particles: ParticleType[]) => void,
108
+ ): FireworkType => {
109
+ const angle = -Math.PI / 2 + rand(-0.3, 0.3);
110
+ const vx = Math.cos(angle) * speed;
111
+ const vy = Math.sin(angle) * speed;
112
+ const trail: {x: number; y: number}[] = [];
113
+ const trailLength = randInt(10, 25);
114
+
115
+ return {
116
+ x,
117
+ y,
118
+ targetY,
119
+ color,
120
+ speed,
121
+ size,
122
+ angle,
123
+ vx,
124
+ vy,
125
+ trail,
126
+ trailLength,
127
+ exploded: false,
128
+ update() {
129
+ this.trail.push({x: this.x, y: this.y});
130
+ if (this.trail.length > this.trailLength) {
131
+ this.trail.shift();
132
+ }
133
+ this.x += this.vx;
134
+ this.y += this.vy;
135
+ this.vy += 0.02;
136
+ if (this.vy >= 0 || this.y <= this.targetY) {
137
+ this.explode();
138
+ return false;
139
+ }
140
+ return true;
141
+ },
142
+ explode() {
143
+ const numParticles = randInt(50, 150);
144
+ const particles: ParticleType[] = [];
145
+ for (let i = 0; i < numParticles; i++) {
146
+ const particleAngle = rand(0, Math.PI * 2);
147
+ const localParticleSpeed = getValueByRange(particleSpeed);
148
+ const localParticleSize = getValueByRange(particleSize);
149
+ particles.push(createParticle(this.x, this.y, this.color, localParticleSpeed, particleAngle, 0.05, 0.98, localParticleSize));
150
+ }
151
+ onExplode(particles);
152
+ },
153
+ draw(ctx: CanvasRenderingContext2D) {
154
+ ctx.save();
155
+ ctx.beginPath();
156
+ if (this.trail.length > 1) {
157
+ ctx.moveTo(this.trail[0].x, this.trail[0].y);
158
+ for (const point of this.trail) {
159
+ ctx.lineTo(point.x, point.y);
160
+ }
161
+ } else {
162
+ ctx.moveTo(this.x, this.y);
163
+ ctx.lineTo(this.x, this.y);
164
+ }
165
+ ctx.strokeStyle = this.color;
166
+ ctx.lineWidth = this.size;
167
+ ctx.lineCap = "round";
168
+ ctx.stroke();
169
+ ctx.restore();
170
+ },
171
+ };
172
+ };
173
+
174
+ const getValueByRange = (range: {min: number; max: number} | number): number => {
175
+ if (typeof range === "number") {
176
+ return range;
177
+ }
178
+ return rand(range.min, range.max);
179
+ };
180
+
181
+ const getColor = (color: string | string[] | undefined): string => {
182
+ if (Array.isArray(color)) {
183
+ return color[randInt(0, color.length)];
184
+ }
185
+ return color ?? randColor();
186
+ };
187
+
188
+ interface FireworksBackgroundProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "color"> {
189
+ canvasProps?: React.HTMLAttributes<HTMLCanvasElement>;
190
+ population?: number;
191
+ color?: string | string[];
192
+ fireworkSpeed?: {min: number; max: number} | number;
193
+ fireworkSize?: {min: number; max: number} | number;
194
+ particleSpeed?: {min: number; max: number} | number;
195
+ particleSize?: {min: number; max: number} | number;
196
+ }
197
+
198
+ const FireworksBackground = React.forwardRef<HTMLDivElement, FireworksBackgroundProps>(
199
+ (
200
+ {
201
+ className,
202
+ canvasProps,
203
+ population = 1,
204
+ color,
205
+ fireworkSpeed = {min: 4, max: 8},
206
+ fireworkSize = {min: 2, max: 5},
207
+ particleSpeed = {min: 2, max: 7},
208
+ particleSize = {min: 1, max: 5},
209
+ ...props
210
+ },
211
+ ref,
212
+ ) => {
213
+ const canvasRef = React.useRef<HTMLCanvasElement>(null);
214
+ const containerRef = React.useRef<HTMLDivElement>(null);
215
+ React.useImperativeHandle(ref, () => containerRef.current as HTMLDivElement);
216
+
217
+ React.useEffect(() => {
218
+ const canvas = canvasRef.current;
219
+ const container = containerRef.current;
220
+ if (!canvas || !container) return;
221
+ const ctx = canvas.getContext("2d");
222
+ if (!ctx) return;
223
+
224
+ let maxX = window.innerWidth;
225
+ let ratio = container.offsetHeight / container.offsetWidth;
226
+ let maxY = maxX * ratio;
227
+ canvas.width = maxX;
228
+ canvas.height = maxY;
229
+
230
+ const setCanvasSize = () => {
231
+ maxX = window.innerWidth;
232
+ ratio = container.offsetHeight / container.offsetWidth;
233
+ maxY = maxX * ratio;
234
+ canvas.width = maxX;
235
+ canvas.height = maxY;
236
+ };
237
+ window.addEventListener("resize", setCanvasSize);
238
+
239
+ const explosions: ParticleType[] = [];
240
+ const fireworks: FireworkType[] = [];
241
+
242
+ const handleExplosion = (particles: ParticleType[]) => {
243
+ explosions.push(...particles);
244
+ };
245
+
246
+ const launchFirework = () => {
247
+ const x = rand(maxX * 0.1, maxX * 0.9);
248
+ const y = maxY;
249
+ const targetY = rand(maxY * 0.1, maxY * 0.4);
250
+ const fireworkColor = getColor(color);
251
+ const speed = getValueByRange(fireworkSpeed);
252
+ const size = getValueByRange(fireworkSize);
253
+ fireworks.push(createFirework(x, y, targetY, fireworkColor, speed, size, particleSpeed, particleSize, handleExplosion));
254
+ const timeout = rand(300, 800) / population;
255
+ setTimeout(launchFirework, timeout);
256
+ };
257
+
258
+ launchFirework();
259
+
260
+ // eslint-disable-next-line init-declarations -- firework animation id
261
+ let animationFrameId: number;
262
+ const animate = () => {
263
+ ctx.clearRect(0, 0, maxX, maxY);
264
+
265
+ for (let i = fireworks.length - 1; i >= 0; i--) {
266
+ const firework = fireworks[i];
267
+ if (firework.update()) {
268
+ firework.draw(ctx);
269
+ } else {
270
+ fireworks.splice(i, 1);
271
+ }
272
+ }
273
+
274
+ for (let i = explosions.length - 1; i >= 0; i--) {
275
+ const particle = explosions[i];
276
+ particle.update();
277
+ if (particle.isAlive()) {
278
+ particle.draw(ctx);
279
+ } else {
280
+ explosions.splice(i, 1);
281
+ }
282
+ }
283
+
284
+ animationFrameId = requestAnimationFrame(animate);
285
+ };
286
+
287
+ animate();
288
+
289
+ const handleClick = (event: MouseEvent) => {
290
+ const x = event.clientX;
291
+ const y = maxY;
292
+ const targetY = event.clientY;
293
+ const fireworkColor = getColor(color);
294
+ const speed = getValueByRange(fireworkSpeed);
295
+ const size = getValueByRange(fireworkSize);
296
+ fireworks.push(createFirework(x, y, targetY, fireworkColor, speed, size, particleSpeed, particleSize, handleExplosion));
297
+ };
298
+
299
+ container.addEventListener("click", handleClick);
300
+
301
+ return () => {
302
+ window.removeEventListener("resize", setCanvasSize);
303
+ container.removeEventListener("click", handleClick);
304
+ cancelAnimationFrame(animationFrameId);
305
+ };
306
+ }, [population, color, fireworkSpeed, fireworkSize, particleSpeed, particleSize]);
307
+
308
+ return (
309
+ <div
310
+ ref={containerRef}
311
+ className={cn("relative size-full overflow-hidden", className)}
312
+ {...props}>
313
+ <canvas
314
+ {...canvasProps}
315
+ ref={canvasRef}
316
+ className={cn("absolute inset-0 size-full", canvasProps?.className)}
317
+ />
318
+ </div>
319
+ );
320
+ },
321
+ );
322
+
323
+ FireworksBackground.displayName = "FireworksBackground";
324
+
325
+ export {FireworksBackground, type FireworksBackgroundProps};