@readdy/anim 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/animations/button/3d-flip/index.js +60 -0
  2. package/animations/button/3d-flip/react.tsx +29 -0
  3. package/animations/button/3d-flip/style.css +17 -0
  4. package/animations/button/blur-fade-in/index.js +21 -0
  5. package/animations/button/blur-fade-in/react.tsx +26 -0
  6. package/animations/button/blur-fade-in/style.css +27 -0
  7. package/animations/button/border-beam/index.js +172 -0
  8. package/animations/button/border-beam/react.tsx +55 -0
  9. package/animations/button/border-beam/style.css +59 -0
  10. package/animations/button/bounce-elastic/index.js +21 -0
  11. package/animations/button/bounce-elastic/react.tsx +26 -0
  12. package/animations/button/bounce-elastic/style.css +31 -0
  13. package/animations/button/bubble-button/index.js +317 -0
  14. package/animations/button/bubble-button/react.tsx +19 -0
  15. package/animations/button/bubble-button/style.css +245 -0
  16. package/animations/button/confetti-button/index.js +66 -0
  17. package/animations/button/confetti-button/react.tsx +30 -0
  18. package/animations/button/confetti-button/style.css +48 -0
  19. package/animations/button/glow-cta/index.js +69 -0
  20. package/animations/button/glow-cta/react.tsx +45 -0
  21. package/animations/button/glow-cta/style.css +78 -0
  22. package/animations/button/magnetic-hover/index.js +61 -0
  23. package/animations/button/magnetic-hover/react.tsx +29 -0
  24. package/animations/button/magnetic-hover/style.css +18 -0
  25. package/animations/button/pulse/index.js +21 -0
  26. package/animations/button/pulse/react.tsx +26 -0
  27. package/animations/button/pulse/style.css +24 -0
  28. package/animations/button/rainbow-button/index.js +21 -0
  29. package/animations/button/rainbow-button/react.tsx +26 -0
  30. package/animations/button/rainbow-button/style.css +54 -0
  31. package/animations/button/shimmer-border/index.js +28 -0
  32. package/animations/button/shimmer-border/react.tsx +41 -0
  33. package/animations/button/shimmer-border/style.css +53 -0
  34. package/animations/button/sketch-button/index.js +16 -0
  35. package/animations/button/sketch-button/react.tsx +19 -0
  36. package/animations/button/sketch-button/style.css +25 -0
  37. package/animations/card/blur-rise/index.js +21 -0
  38. package/animations/card/blur-rise/react.tsx +26 -0
  39. package/animations/card/blur-rise/style.css +27 -0
  40. package/animations/card/bounce-in-bottom/index.js +21 -0
  41. package/animations/card/bounce-in-bottom/react.tsx +26 -0
  42. package/animations/card/bounce-in-bottom/style.css +31 -0
  43. package/animations/card/card-fan-spread/index.js +146 -0
  44. package/animations/card/card-fan-spread/react.tsx +35 -0
  45. package/animations/card/card-fan-spread/style.css +90 -0
  46. package/animations/card/card-flip/index.js +203 -0
  47. package/animations/card/card-flip/react.tsx +35 -0
  48. package/animations/card/card-flip/style.css +71 -0
  49. package/animations/card/float-idle/index.js +21 -0
  50. package/animations/card/float-idle/react.tsx +26 -0
  51. package/animations/card/float-idle/style.css +21 -0
  52. package/animations/card/image-magnifier/index.js +333 -0
  53. package/animations/card/image-magnifier/react.tsx +31 -0
  54. package/animations/card/image-magnifier/style.css +42 -0
  55. package/animations/card/image-zoom-rotate/index.js +48 -0
  56. package/animations/card/image-zoom-rotate/react.tsx +31 -0
  57. package/animations/card/image-zoom-rotate/style.css +20 -0
  58. package/animations/card/pop-in-stack/index.js +25 -0
  59. package/animations/card/pop-in-stack/react.tsx +33 -0
  60. package/animations/card/pop-in-stack/style.css +25 -0
  61. package/animations/card/reveal-from-top/index.js +21 -0
  62. package/animations/card/reveal-from-top/react.tsx +26 -0
  63. package/animations/card/reveal-from-top/style.css +28 -0
  64. package/animations/card/rgb-split-glitch/index.js +28 -0
  65. package/animations/card/rgb-split-glitch/react.tsx +41 -0
  66. package/animations/card/rgb-split-glitch/style.css +33 -0
  67. package/animations/card/tilted-card/index.js +64 -0
  68. package/animations/card/tilted-card/react.tsx +33 -0
  69. package/animations/card/tilted-card/style.css +27 -0
  70. package/animations/header/anime-splittext/index.js +108 -0
  71. package/animations/header/anime-splittext/react.tsx +30 -0
  72. package/animations/header/anime-splittext/style.css +71 -0
  73. package/animations/header/bounce-in-down/index.js +40 -0
  74. package/animations/header/bounce-in-down/react.tsx +29 -0
  75. package/animations/header/bounce-in-down/style.css +40 -0
  76. package/animations/header/fly-in-chars/index.js +46 -0
  77. package/animations/header/fly-in-chars/react.tsx +30 -0
  78. package/animations/header/fly-in-chars/style.css +29 -0
  79. package/animations/header/gradient-text/index.js +21 -0
  80. package/animations/header/gradient-text/react.tsx +26 -0
  81. package/animations/header/gradient-text/style.css +28 -0
  82. package/animations/header/letter-bounce/index.js +33 -0
  83. package/animations/header/letter-bounce/react.tsx +34 -0
  84. package/animations/header/letter-bounce/style.css +25 -0
  85. package/animations/header/roll-in/index.js +40 -0
  86. package/animations/header/roll-in/react.tsx +29 -0
  87. package/animations/header/roll-in/style.css +31 -0
  88. package/animations/header/shimmer-text/index.js +16 -0
  89. package/animations/header/shimmer-text/react.tsx +28 -0
  90. package/animations/header/shimmer-text/style.css +29 -0
  91. package/animations/header/shuffle/index.js +118 -0
  92. package/animations/header/shuffle/react.tsx +50 -0
  93. package/animations/header/shuffle/style.css +25 -0
  94. package/animations/header/split-text/index.js +72 -0
  95. package/animations/header/split-text/react.tsx +38 -0
  96. package/animations/header/split-text/style.css +31 -0
  97. package/animations/header/text-type/index.js +267 -0
  98. package/animations/header/text-type/react.tsx +63 -0
  99. package/animations/header/text-type/style.css +37 -0
  100. package/animations/header/word-curtain-reveal/index.js +97 -0
  101. package/animations/header/word-curtain-reveal/react.tsx +30 -0
  102. package/animations/header/word-curtain-reveal/style.css +39 -0
  103. package/dist/button/3d-flip/react.js +21 -0
  104. package/dist/button/3d-flip.js +61 -0
  105. package/dist/button/blur-fade-in/react.js +28 -0
  106. package/dist/button/blur-fade-in.js +17 -0
  107. package/dist/button/border-beam/react.js +22 -0
  108. package/dist/button/border-beam.js +168 -0
  109. package/dist/button/bounce-elastic/react.js +28 -0
  110. package/dist/button/bounce-elastic.js +17 -0
  111. package/dist/button/bubble-button/react.js +20 -0
  112. package/dist/button/bubble-button.js +318 -0
  113. package/dist/button/confetti-button/react.js +21 -0
  114. package/dist/button/confetti-button.js +67 -0
  115. package/dist/button/glow-cta/react.js +23 -0
  116. package/dist/button/glow-cta.js +65 -0
  117. package/dist/button/magnetic-hover/react.js +21 -0
  118. package/dist/button/magnetic-hover.js +62 -0
  119. package/dist/button/pulse/react.js +28 -0
  120. package/dist/button/pulse.js +17 -0
  121. package/dist/button/rainbow-button/react.js +28 -0
  122. package/dist/button/rainbow-button.js +17 -0
  123. package/dist/button/shimmer-border/react.js +22 -0
  124. package/dist/button/shimmer-border.js +24 -0
  125. package/dist/button/sketch-button/react.js +20 -0
  126. package/dist/button/sketch-button.js +17 -0
  127. package/dist/card/blur-rise/react.js +28 -0
  128. package/dist/card/blur-rise.js +17 -0
  129. package/dist/card/bounce-in-bottom/react.js +28 -0
  130. package/dist/card/bounce-in-bottom.js +17 -0
  131. package/dist/card/card-fan-spread/react.js +20 -0
  132. package/dist/card/card-fan-spread.js +147 -0
  133. package/dist/card/float-idle/react.js +28 -0
  134. package/dist/card/float-idle.js +17 -0
  135. package/dist/card/image-magnifier/react.js +22 -0
  136. package/dist/card/image-magnifier.js +334 -0
  137. package/dist/card/image-zoom-rotate/react.js +21 -0
  138. package/dist/card/image-zoom-rotate.js +49 -0
  139. package/dist/card/pop-in-stack/react.js +20 -0
  140. package/dist/card/pop-in-stack.js +26 -0
  141. package/dist/card/reveal-from-top/react.js +28 -0
  142. package/dist/card/reveal-from-top.js +17 -0
  143. package/dist/card/rgb-split-glitch/react.js +22 -0
  144. package/dist/card/rgb-split-glitch.js +24 -0
  145. package/dist/card/tilted-card/react.js +21 -0
  146. package/dist/card/tilted-card.js +65 -0
  147. package/dist/chunks/constants-EnH6-Pz4.js +66 -0
  148. package/dist/chunks/constants-ZTHic1pf.js +66 -0
  149. package/dist/chunks/pointer-follow-B3RFnn_q.js +93 -0
  150. package/dist/chunks/pointer-follow-BETANySn.js +93 -0
  151. package/dist/chunks/reduced-motion-BpQYuEzK.js +17 -0
  152. package/dist/chunks/reduced-motion-HX79Ac8G.js +17 -0
  153. package/dist/chunks/resolve-card-media-Cj3V_oms.js +43 -0
  154. package/dist/chunks/resolve-card-media-DBIU-duL.js +43 -0
  155. package/dist/chunks/text-split-D02jltVh.js +191 -0
  156. package/dist/chunks/text-split-frOR4UpH.js +191 -0
  157. package/dist/full.css +1 -0
  158. package/dist/full.js +3192 -0
  159. package/dist/header/anime-splittext/react.js +22 -0
  160. package/dist/header/anime-splittext.js +109 -0
  161. package/dist/header/bounce-in-down/react.js +32 -0
  162. package/dist/header/bounce-in-down.js +36 -0
  163. package/dist/header/fly-in-chars/react.js +23 -0
  164. package/dist/header/fly-in-chars.js +47 -0
  165. package/dist/header/gradient-text/react.js +28 -0
  166. package/dist/header/gradient-text.js +17 -0
  167. package/dist/header/letter-bounce/react.js +23 -0
  168. package/dist/header/letter-bounce.js +34 -0
  169. package/dist/header/roll-in/react.js +32 -0
  170. package/dist/header/roll-in.js +36 -0
  171. package/dist/header/shimmer-text/react.js +27 -0
  172. package/dist/header/shimmer-text.js +17 -0
  173. package/dist/header/shuffle/react.js +30 -0
  174. package/dist/header/shuffle.js +119 -0
  175. package/dist/header/split-text/react.js +26 -0
  176. package/dist/header/split-text.js +73 -0
  177. package/dist/header/text-type/react.js +43 -0
  178. package/dist/header/text-type.js +268 -0
  179. package/dist/header/word-curtain-reveal/react.js +22 -0
  180. package/dist/header/word-curtain-reveal.js +98 -0
  181. package/dist/meta.json +6 -0
  182. package/dist/metadata.json +1051 -0
  183. package/dist/react.css +1 -0
  184. package/dist/types/animations/button/3d-flip/index.d.ts +3 -0
  185. package/dist/types/animations/button/3d-flip/react.d.ts +8 -0
  186. package/dist/types/animations/button/blur-fade-in/index.d.ts +3 -0
  187. package/dist/types/animations/button/blur-fade-in/react.d.ts +13 -0
  188. package/dist/types/animations/button/border-beam/index.d.ts +3 -0
  189. package/dist/types/animations/button/border-beam/react.d.ts +25 -0
  190. package/dist/types/animations/button/bounce-elastic/index.d.ts +3 -0
  191. package/dist/types/animations/button/bounce-elastic/react.d.ts +13 -0
  192. package/dist/types/animations/button/bubble-button/index.d.ts +3 -0
  193. package/dist/types/animations/button/bubble-button/react.d.ts +4 -0
  194. package/dist/types/animations/button/confetti-button/index.d.ts +3 -0
  195. package/dist/types/animations/button/confetti-button/react.d.ts +8 -0
  196. package/dist/types/animations/button/glow-cta/index.d.ts +3 -0
  197. package/dist/types/animations/button/glow-cta/react.d.ts +20 -0
  198. package/dist/types/animations/button/magnetic-hover/index.d.ts +3 -0
  199. package/dist/types/animations/button/magnetic-hover/react.d.ts +8 -0
  200. package/dist/types/animations/button/pulse/index.d.ts +3 -0
  201. package/dist/types/animations/button/pulse/react.d.ts +13 -0
  202. package/dist/types/animations/button/rainbow-button/index.d.ts +3 -0
  203. package/dist/types/animations/button/rainbow-button/react.d.ts +13 -0
  204. package/dist/types/animations/button/shimmer-border/index.d.ts +3 -0
  205. package/dist/types/animations/button/shimmer-border/react.d.ts +18 -0
  206. package/dist/types/animations/button/sketch-button/index.d.ts +3 -0
  207. package/dist/types/animations/button/sketch-button/react.d.ts +4 -0
  208. package/dist/types/animations/card/blur-rise/index.d.ts +3 -0
  209. package/dist/types/animations/card/blur-rise/react.d.ts +13 -0
  210. package/dist/types/animations/card/bounce-in-bottom/index.d.ts +3 -0
  211. package/dist/types/animations/card/bounce-in-bottom/react.d.ts +13 -0
  212. package/dist/types/animations/card/card-fan-spread/index.d.ts +3 -0
  213. package/dist/types/animations/card/card-fan-spread/react.d.ts +11 -0
  214. package/dist/types/animations/card/card-flip/index.d.ts +3 -0
  215. package/dist/types/animations/card/card-flip/react.d.ts +11 -0
  216. package/dist/types/animations/card/float-idle/index.d.ts +3 -0
  217. package/dist/types/animations/card/float-idle/react.d.ts +13 -0
  218. package/dist/types/animations/card/image-magnifier/index.d.ts +3 -0
  219. package/dist/types/animations/card/image-magnifier/react.d.ts +9 -0
  220. package/dist/types/animations/card/image-zoom-rotate/index.d.ts +3 -0
  221. package/dist/types/animations/card/image-zoom-rotate/react.d.ts +9 -0
  222. package/dist/types/animations/card/pop-in-stack/index.d.ts +3 -0
  223. package/dist/types/animations/card/pop-in-stack/react.d.ts +10 -0
  224. package/dist/types/animations/card/reveal-from-top/index.d.ts +3 -0
  225. package/dist/types/animations/card/reveal-from-top/react.d.ts +13 -0
  226. package/dist/types/animations/card/rgb-split-glitch/index.d.ts +3 -0
  227. package/dist/types/animations/card/rgb-split-glitch/react.d.ts +18 -0
  228. package/dist/types/animations/card/tilted-card/index.d.ts +3 -0
  229. package/dist/types/animations/card/tilted-card/react.d.ts +10 -0
  230. package/dist/types/animations/header/anime-splittext/index.d.ts +3 -0
  231. package/dist/types/animations/header/anime-splittext/react.d.ts +8 -0
  232. package/dist/types/animations/header/bounce-in-down/index.d.ts +3 -0
  233. package/dist/types/animations/header/bounce-in-down/react.d.ts +13 -0
  234. package/dist/types/animations/header/fly-in-chars/index.d.ts +3 -0
  235. package/dist/types/animations/header/fly-in-chars/react.d.ts +8 -0
  236. package/dist/types/animations/header/gradient-text/index.d.ts +3 -0
  237. package/dist/types/animations/header/gradient-text/react.d.ts +13 -0
  238. package/dist/types/animations/header/letter-bounce/index.d.ts +3 -0
  239. package/dist/types/animations/header/letter-bounce/react.d.ts +10 -0
  240. package/dist/types/animations/header/roll-in/index.d.ts +3 -0
  241. package/dist/types/animations/header/roll-in/react.d.ts +13 -0
  242. package/dist/types/animations/header/shimmer-text/index.d.ts +3 -0
  243. package/dist/types/animations/header/shimmer-text/react.d.ts +4 -0
  244. package/dist/types/animations/header/shuffle/index.d.ts +3 -0
  245. package/dist/types/animations/header/shuffle/react.d.ts +14 -0
  246. package/dist/types/animations/header/split-text/index.d.ts +3 -0
  247. package/dist/types/animations/header/split-text/react.d.ts +10 -0
  248. package/dist/types/animations/header/text-type/index.d.ts +3 -0
  249. package/dist/types/animations/header/text-type/react.d.ts +13 -0
  250. package/dist/types/animations/header/word-curtain-reveal/index.d.ts +3 -0
  251. package/dist/types/animations/header/word-curtain-reveal/react.d.ts +8 -0
  252. package/dist/types/react-barrel.d.ts +34 -0
  253. package/dist/types/scripts/bundle-all.d.ts +173 -0
  254. package/dist/types/scripts/check-metadata.d.ts +1 -0
  255. package/dist/types/scripts/copy-metadata.d.ts +1 -0
  256. package/dist/types/scripts/generate-animation-id-map.d.ts +1 -0
  257. package/dist/types/scripts/generate-dist-meta.d.ts +1 -0
  258. package/dist/types/scripts/generate-preview-manifest.d.ts +1 -0
  259. package/dist/types/scripts/update-metadata.d.ts +1 -0
  260. package/dist/types/shared/constants.d.ts +34 -0
  261. package/dist/types/shared/meta.d.ts +18 -0
  262. package/dist/types/shared/pointer-follow.d.ts +8 -0
  263. package/dist/types/shared/reduced-motion.d.ts +11 -0
  264. package/dist/types/shared/resolve-card-media.d.ts +1 -0
  265. package/dist/types/shared/text-split.d.ts +19 -0
  266. package/dist/types/stories/3d-flip.stories.d.ts +7 -0
  267. package/dist/types/stories/_helpers.d.ts +24 -0
  268. package/dist/types/stories/anime-splittext.stories.d.ts +8 -0
  269. package/dist/types/stories/blur-fade-in.stories.d.ts +8 -0
  270. package/dist/types/stories/blur-rise.stories.d.ts +8 -0
  271. package/dist/types/stories/blur-to-sharp-rise-header.stories.d.ts +8 -0
  272. package/dist/types/stories/border-beam.stories.d.ts +8 -0
  273. package/dist/types/stories/bounce-elastic.stories.d.ts +8 -0
  274. package/dist/types/stories/bounce-in-bottom.stories.d.ts +8 -0
  275. package/dist/types/stories/bounce-in-down.stories.d.ts +9 -0
  276. package/dist/types/stories/bubble-button.stories.d.ts +8 -0
  277. package/dist/types/stories/card-fan-spread.stories.d.ts +7 -0
  278. package/dist/types/stories/card-flip.stories.d.ts +7 -0
  279. package/dist/types/stories/confetti-button.stories.d.ts +7 -0
  280. package/dist/types/stories/float-idle.stories.d.ts +8 -0
  281. package/dist/types/stories/fly-in-chars.stories.d.ts +8 -0
  282. package/dist/types/stories/glow-cta.stories.d.ts +9 -0
  283. package/dist/types/stories/gradient-text.stories.d.ts +9 -0
  284. package/dist/types/stories/image-magnifier.stories.d.ts +10 -0
  285. package/dist/types/stories/image-zoom-rotate.stories.d.ts +7 -0
  286. package/dist/types/stories/letter-bounce.stories.d.ts +8 -0
  287. package/dist/types/stories/magic-ui-border-beam-card.stories.d.ts +8 -0
  288. package/dist/types/stories/magnetic-hover.stories.d.ts +7 -0
  289. package/dist/types/stories/pop-in-stack.stories.d.ts +7 -0
  290. package/dist/types/stories/pulse.stories.d.ts +8 -0
  291. package/dist/types/stories/rainbow-button.stories.d.ts +8 -0
  292. package/dist/types/stories/reveal-from-top.stories.d.ts +8 -0
  293. package/dist/types/stories/rgb-split-glitch.stories.d.ts +8 -0
  294. package/dist/types/stories/roll-in.stories.d.ts +9 -0
  295. package/dist/types/stories/shimmer-border.stories.d.ts +9 -0
  296. package/dist/types/stories/shimmer-text.stories.d.ts +8 -0
  297. package/dist/types/stories/shuffle.stories.d.ts +8 -0
  298. package/dist/types/stories/sketch-button.stories.d.ts +7 -0
  299. package/dist/types/stories/split-text.stories.d.ts +8 -0
  300. package/dist/types/stories/text-type.stories.d.ts +8 -0
  301. package/dist/types/stories/tilted-card.stories.d.ts +7 -0
  302. package/dist/types/stories/word-curtain-reveal.stories.d.ts +8 -0
  303. package/package.json +166 -0
  304. package/react-barrel.js +44 -0
  305. package/shared/constants.js +64 -0
  306. package/shared/meta.js +21 -0
  307. package/shared/pointer-follow.js +91 -0
  308. package/shared/reduced-motion.js +15 -0
  309. package/shared/resolve-card-media.js +41 -0
  310. package/shared/text-split.js +188 -0
@@ -0,0 +1,317 @@
1
+ import './style.css'
2
+ import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
3
+ import { buildAnimClass, buildAnimDomId, buildAnimId } from '../../../shared/constants.js'
4
+
5
+ export const ANIMATION_ID = buildAnimId('bubble-button')
6
+
7
+ const CSS_CLASS = buildAnimClass('bubble-button')
8
+ const ACTIVE_CLASS = buildAnimClass('bubble-button-active')
9
+ const HOVER_CLASS = buildAnimClass('bubble-button-hover')
10
+ const FALLBACK_CLASS = buildAnimClass('bubble-button-fallback')
11
+ const CONTAINER_CLASS = buildAnimClass('bubble-button-container')
12
+ const EFFECT_CONTAINER_CLASS = buildAnimClass('bubble-button-effect-container')
13
+ const EFFECT_BUTTON_CLASS = buildAnimClass('bubble-button-effect-button')
14
+ const CIRCLE_CLASS = buildAnimClass('bubble-button-circle')
15
+ const FILTER_ID = buildAnimDomId('bubble-goo')
16
+ const FILTER_ROOT_ID = buildAnimDomId('bubble-goo-root')
17
+
18
+ const stateMap = new WeakMap()
19
+ let gooFilterRefCount = 0
20
+
21
+ function ensureGooFilter() {
22
+ gooFilterRefCount += 1
23
+ if (document.getElementById(FILTER_ID)) {
24
+ return
25
+ }
26
+
27
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
28
+ svg.id = FILTER_ROOT_ID
29
+ svg.setAttribute('aria-hidden', 'true')
30
+ svg.style.position = 'absolute'
31
+ svg.style.width = '0'
32
+ svg.style.height = '0'
33
+ svg.style.pointerEvents = 'none'
34
+
35
+ svg.innerHTML = `
36
+ <defs>
37
+ <filter id="${FILTER_ID}">
38
+ <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
39
+ <feColorMatrix
40
+ in="blur"
41
+ mode="matrix"
42
+ values="
43
+ 1 0 0 0 0
44
+ 0 1 0 0 0
45
+ 0 0 1 0 0
46
+ 0 0 0 19 -9
47
+ "
48
+ result="goo"
49
+ />
50
+ <feComposite in="SourceGraphic" in2="goo" />
51
+ </filter>
52
+ </defs>
53
+ `
54
+
55
+ document.body.appendChild(svg)
56
+ }
57
+
58
+ function releaseGooFilter() {
59
+ gooFilterRefCount = Math.max(gooFilterRefCount - 1, 0)
60
+ if (gooFilterRefCount === 0) {
61
+ document.getElementById(FILTER_ROOT_ID)?.remove()
62
+ }
63
+ }
64
+
65
+ function createCircle(position, slot) {
66
+ const circle = document.createElement('span')
67
+ circle.className = `${CIRCLE_CLASS} ${CIRCLE_CLASS}-${position} ${CIRCLE_CLASS}-${position}-${slot}`
68
+ return circle
69
+ }
70
+
71
+ function ensureStructure(el) {
72
+ let container = el.parentElement
73
+
74
+ if (!container?.classList.contains(CONTAINER_CLASS)) {
75
+ container = document.createElement('span')
76
+ container.className = CONTAINER_CLASS
77
+ el.parentNode?.insertBefore(container, el)
78
+ container.appendChild(el)
79
+ }
80
+
81
+ let effectContainer = container.querySelector(`.${EFFECT_CONTAINER_CLASS}`)
82
+ if (!effectContainer) {
83
+ effectContainer = document.createElement('span')
84
+ effectContainer.className = EFFECT_CONTAINER_CLASS
85
+ effectContainer.style.filter = `url(#${FILTER_ID})`
86
+ effectContainer.style.webkitFilter = `url(#${FILTER_ID})`
87
+
88
+ effectContainer.appendChild(createCircle('top-left', 1))
89
+ effectContainer.appendChild(createCircle('top-left', 2))
90
+ effectContainer.appendChild(createCircle('top-left', 3))
91
+
92
+ const effectButton = document.createElement('span')
93
+ effectButton.className = EFFECT_BUTTON_CLASS
94
+ effectContainer.appendChild(effectButton)
95
+
96
+ effectContainer.appendChild(createCircle('bottom-right', 1))
97
+ effectContainer.appendChild(createCircle('bottom-right', 2))
98
+ effectContainer.appendChild(createCircle('bottom-right', 3))
99
+
100
+ container.appendChild(effectContainer)
101
+ }
102
+
103
+ return {
104
+ container,
105
+ effectContainer,
106
+ effectButton: effectContainer.querySelector(`.${EFFECT_BUTTON_CLASS}`),
107
+ circlesTopLeft: Array.from(effectContainer.querySelectorAll(`.${CIRCLE_CLASS}-top-left`)),
108
+ circlesBottomRight: Array.from(effectContainer.querySelectorAll(`.${CIRCLE_CLASS}-bottom-right`)),
109
+ }
110
+ }
111
+
112
+ function setAccent(container, el) {
113
+ const computed = window.getComputedStyle(el)
114
+ const backgroundColor = computed.backgroundColor
115
+ const accent = backgroundColor && backgroundColor !== 'rgba(0, 0, 0, 0)' ? backgroundColor : '#4f6bff'
116
+ container.style.setProperty('--readdy-anim-bubble-accent', accent)
117
+ }
118
+
119
+ function clearAnimations(state) {
120
+ state.animations.forEach((animation) => {
121
+ animation.cancel()
122
+ })
123
+ state.animations = []
124
+ }
125
+
126
+ function trackAnimation(state, animation) {
127
+ if (!animation) {
128
+ return
129
+ }
130
+
131
+ state.animations.push(animation)
132
+ const forget = () => {
133
+ state.animations = state.animations.filter((item) => item !== animation)
134
+ }
135
+ animation.addEventListener('finish', forget, { once: true })
136
+ animation.addEventListener('cancel', forget, { once: true })
137
+ }
138
+
139
+ function clearInlineState(state) {
140
+ const nodes = [
141
+ state.effectButton,
142
+ ...state.circlesTopLeft,
143
+ ...state.circlesBottomRight,
144
+ ].filter(Boolean)
145
+
146
+ nodes.forEach((node) => {
147
+ node.style.opacity = ''
148
+ node.style.transform = ''
149
+ })
150
+ }
151
+
152
+ function resetState(state) {
153
+ clearAnimations(state)
154
+ state.container.classList.remove(ACTIVE_CLASS)
155
+ state.container.classList.remove(HOVER_CLASS)
156
+ clearInlineState(state)
157
+ }
158
+
159
+ function hasWAAPI() {
160
+ return typeof Element.prototype.animate === 'function'
161
+ }
162
+
163
+ function playBurst(state) {
164
+ const { container, effectButton, circlesTopLeft, circlesBottomRight } = state
165
+
166
+ container.classList.remove(ACTIVE_CLASS)
167
+ void container.offsetWidth
168
+ container.classList.add(HOVER_CLASS)
169
+ container.classList.add(ACTIVE_CLASS)
170
+
171
+ if (!state.supportsWAAPI) {
172
+ return
173
+ }
174
+
175
+ clearAnimations(state)
176
+
177
+ trackAnimation(
178
+ state,
179
+ effectButton?.animate(
180
+ [
181
+ { transform: 'translateY(-50%) scaleY(1)', opacity: 1 },
182
+ { transform: 'translateY(-50%) scaleY(1.1)', opacity: 1, offset: 0.34 },
183
+ { transform: 'translateY(-50%) scale(1)', opacity: 1 },
184
+ ],
185
+ {
186
+ duration: 1000,
187
+ easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
188
+ fill: 'forwards',
189
+ }
190
+ )
191
+ )
192
+
193
+ const topFrames = [
194
+ [
195
+ { transform: 'translate(0, 0) rotate(-45deg) scale(1)', opacity: 1 },
196
+ { transform: 'translate(-25px, -25px) rotate(-45deg) scale(1, 2)', opacity: 1, offset: 0.5 },
197
+ { transform: 'translate(-19px, -27px) rotate(-45deg) scale(0.2)', opacity: 0.95, offset: 0.58 },
198
+ { transform: 'translate(-24px, -42px) rotate(-45deg) scale(0)', opacity: 0 },
199
+ ],
200
+ [
201
+ { transform: 'translate(0, 0) rotate(-45deg) scale(1)', opacity: 1 },
202
+ { transform: 'translate(-25px, -25px) rotate(-45deg) scale(1, 2)', opacity: 1, offset: 0.5 },
203
+ { transform: 'translate(-35px, -32px) rotate(-45deg) scale(1, 0.8)', opacity: 0.95, offset: 0.58 },
204
+ { transform: 'translate(-45px, -42px) rotate(-45deg) scale(0.4)', opacity: 0 },
205
+ ],
206
+ [
207
+ { transform: 'translate(0, 0) rotate(-45deg) scale(1)', opacity: 1 },
208
+ { transform: 'translate(-25px, -25px) rotate(-45deg) scale(1, 2)', opacity: 1, offset: 0.5 },
209
+ { transform: 'translate(-40px, -19px) rotate(-45deg) scale(0.2)', opacity: 0.95, offset: 0.58 },
210
+ { transform: 'translate(-55px, -14px) rotate(-45deg) scale(0)', opacity: 0 },
211
+ ],
212
+ ]
213
+
214
+ const bottomFrames = [
215
+ [
216
+ { transform: 'translate(0, 0) rotate(45deg) scale(1)', opacity: 1 },
217
+ { transform: 'translate(30px, 30px) rotate(45deg) scale(1)', opacity: 1, offset: 0.48 },
218
+ { transform: 'translate(24px, 33px) rotate(45deg) scale(0.2)', opacity: 0.95, offset: 0.56 },
219
+ { transform: 'translate(29px, 48px) rotate(45deg) scale(0)', opacity: 0 },
220
+ ],
221
+ [
222
+ { transform: 'translate(0, 0) rotate(45deg) scale(1)', opacity: 1 },
223
+ { transform: 'translate(30px, 30px) rotate(45deg) scale(1)', opacity: 1, offset: 0.48 },
224
+ { transform: 'translate(37px, 33px) rotate(45deg) scale(0.8)', opacity: 0.95, offset: 0.56 },
225
+ { transform: 'translate(44px, 40px) rotate(45deg) scale(0.4)', opacity: 0 },
226
+ ],
227
+ [
228
+ { transform: 'translate(0, 0) rotate(45deg) scale(1)', opacity: 1 },
229
+ { transform: 'translate(30px, 30px) rotate(45deg) scale(1)', opacity: 1, offset: 0.48 },
230
+ { transform: 'translate(45px, 24px) rotate(45deg) scale(0.2)', opacity: 0.95, offset: 0.56 },
231
+ { transform: 'translate(60px, 19px) rotate(45deg) scale(0)', opacity: 0 },
232
+ ],
233
+ ]
234
+
235
+ circlesTopLeft.forEach((circle, index) => {
236
+ trackAnimation(
237
+ state,
238
+ circle.animate(topFrames[index], {
239
+ duration: 1200,
240
+ easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
241
+ fill: 'forwards',
242
+ })
243
+ )
244
+ })
245
+
246
+ circlesBottomRight.forEach((circle, index) => {
247
+ trackAnimation(
248
+ state,
249
+ circle.animate(bottomFrames[index], {
250
+ duration: 1100,
251
+ easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
252
+ fill: 'forwards',
253
+ })
254
+ )
255
+ })
256
+ }
257
+
258
+ export function init(el) {
259
+ destroy(el)
260
+ el.classList.add(CSS_CLASS)
261
+
262
+ if (prefersReducedMotion()) {
263
+ return
264
+ }
265
+
266
+ ensureGooFilter()
267
+ const structure = ensureStructure(el)
268
+ setAccent(structure.container, el)
269
+
270
+ const state = {
271
+ ...structure,
272
+ animations: [],
273
+ supportsWAAPI: hasWAAPI(),
274
+ onEnter: () => {},
275
+ onLeave: () => {},
276
+ }
277
+
278
+ state.onEnter = () => {
279
+ playBurst(state)
280
+ }
281
+
282
+ state.onLeave = () => {
283
+ resetState(state)
284
+ }
285
+
286
+ state.container.addEventListener('mouseenter', state.onEnter)
287
+ state.container.addEventListener('mouseleave', state.onLeave)
288
+ state.container.classList.toggle(FALLBACK_CLASS, !state.supportsWAAPI)
289
+ stateMap.set(el, state)
290
+ }
291
+
292
+ export function destroy(el) {
293
+ const state = stateMap.get(el)
294
+ if (state) {
295
+ state.container.removeEventListener('mouseenter', state.onEnter)
296
+ state.container.removeEventListener('mouseleave', state.onLeave)
297
+ resetState(state)
298
+ releaseGooFilter()
299
+ stateMap.delete(el)
300
+ }
301
+
302
+ el.classList.remove(CSS_CLASS)
303
+
304
+ const container = el.parentElement?.classList.contains(CONTAINER_CLASS) ? el.parentElement : null
305
+ if (container) {
306
+ container.classList.remove(ACTIVE_CLASS)
307
+ container.classList.remove(HOVER_CLASS)
308
+ container.classList.remove(FALLBACK_CLASS)
309
+ container.style.removeProperty('--readdy-anim-bubble-accent')
310
+ if (container.parentNode) {
311
+ container.parentNode.insertBefore(el, container)
312
+ } else {
313
+ container.removeChild(el)
314
+ }
315
+ container.remove()
316
+ }
317
+ }
@@ -0,0 +1,19 @@
1
+ import React, { useEffect, useRef } from 'react'
2
+ import { init, destroy } from './index.js'
3
+ import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
4
+
5
+ export function AnimBubbleButton({ children }: { children: React.ReactElement }) {
6
+ const ref = useRef<HTMLElement>(null)
7
+
8
+ useEffect(() => {
9
+ const el = ref.current
10
+ if (!el || prefersReducedMotion()) return
11
+
12
+ init(el)
13
+ return () => {
14
+ destroy(el)
15
+ }
16
+ }, [])
17
+
18
+ return React.cloneElement(React.Children.only(children), { ref })
19
+ }
@@ -0,0 +1,245 @@
1
+ @keyframes readdy-anim-bubble-top-left-1 {
2
+ 0% {
3
+ transform: translate(0, 0) rotate(-45deg) scale(1);
4
+ opacity: 1;
5
+ }
6
+ 50% {
7
+ transform: translate(-25px, -25px) rotate(-45deg) scaleY(2);
8
+ opacity: 1;
9
+ }
10
+ 58% {
11
+ transform: translate(-19px, -27px) rotate(-45deg) scale(0.2);
12
+ opacity: 0.95;
13
+ }
14
+ 100% {
15
+ transform: translate(-24px, -42px) rotate(-45deg) scale(0);
16
+ opacity: 0;
17
+ }
18
+ }
19
+
20
+ @keyframes readdy-anim-bubble-top-left-2 {
21
+ 0% {
22
+ transform: translate(0, 0) rotate(-45deg) scale(1);
23
+ opacity: 1;
24
+ }
25
+ 50% {
26
+ transform: translate(-25px, -25px) rotate(-45deg) scaleY(2);
27
+ opacity: 1;
28
+ }
29
+ 58% {
30
+ transform: translate(-35px, -32px) rotate(-45deg) scale(1, 0.8);
31
+ opacity: 0.95;
32
+ }
33
+ 100% {
34
+ transform: translate(-45px, -42px) rotate(-45deg) scale(0.4);
35
+ opacity: 0;
36
+ }
37
+ }
38
+
39
+ @keyframes readdy-anim-bubble-top-left-3 {
40
+ 0% {
41
+ transform: translate(0, 0) rotate(-45deg) scale(1);
42
+ opacity: 1;
43
+ }
44
+ 50% {
45
+ transform: translate(-25px, -25px) rotate(-45deg) scaleY(2);
46
+ opacity: 1;
47
+ }
48
+ 58% {
49
+ transform: translate(-40px, -19px) rotate(-45deg) scale(0.2);
50
+ opacity: 0.95;
51
+ }
52
+ 100% {
53
+ transform: translate(-55px, -14px) rotate(-45deg) scale(0);
54
+ opacity: 0;
55
+ }
56
+ }
57
+
58
+ @keyframes readdy-anim-bubble-bottom-right-1 {
59
+ 0% {
60
+ transform: translate(0, 0) rotate(45deg) scale(1);
61
+ opacity: 1;
62
+ }
63
+ 48% {
64
+ transform: translate(30px, 30px) rotate(45deg) scale(1);
65
+ opacity: 1;
66
+ }
67
+ 56% {
68
+ transform: translate(24px, 33px) rotate(45deg) scale(0.2);
69
+ opacity: 0.95;
70
+ }
71
+ 100% {
72
+ transform: translate(29px, 48px) rotate(45deg) scale(0);
73
+ opacity: 0;
74
+ }
75
+ }
76
+
77
+ @keyframes readdy-anim-bubble-bottom-right-2 {
78
+ 0% {
79
+ transform: translate(0, 0) rotate(45deg) scale(1);
80
+ opacity: 1;
81
+ }
82
+ 48% {
83
+ transform: translate(30px, 30px) rotate(45deg) scale(1);
84
+ opacity: 1;
85
+ }
86
+ 56% {
87
+ transform: translate(37px, 33px) rotate(45deg) scale(0.8);
88
+ opacity: 0.95;
89
+ }
90
+ 100% {
91
+ transform: translate(44px, 40px) rotate(45deg) scale(0.4);
92
+ opacity: 0;
93
+ }
94
+ }
95
+
96
+ @keyframes readdy-anim-bubble-bottom-right-3 {
97
+ 0% {
98
+ transform: translate(0, 0) rotate(45deg) scale(1);
99
+ opacity: 1;
100
+ }
101
+ 48% {
102
+ transform: translate(30px, 30px) rotate(45deg) scale(1);
103
+ opacity: 1;
104
+ }
105
+ 56% {
106
+ transform: translate(45px, 24px) rotate(45deg) scale(0.2);
107
+ opacity: 0.95;
108
+ }
109
+ 100% {
110
+ transform: translate(60px, 19px) rotate(45deg) scale(0);
111
+ opacity: 0;
112
+ }
113
+ }
114
+
115
+ @keyframes readdy-anim-bubble-core {
116
+ 0% {
117
+ transform: translateY(-50%) scaleY(1);
118
+ opacity: 1;
119
+ }
120
+ 34% {
121
+ transform: translateY(-50%) scaleY(1.1);
122
+ opacity: 1;
123
+ }
124
+ 100% {
125
+ transform: translateY(-50%) scale(1);
126
+ opacity: 1;
127
+ }
128
+ }
129
+
130
+ .readdy-anim-bubble-button-container {
131
+ position: relative;
132
+ display: inline-block;
133
+ vertical-align: middle;
134
+ isolation: isolate;
135
+ --readdy-anim-bubble-accent: #4f6bff;
136
+ }
137
+
138
+ .readdy-anim-bubble-button-container > .readdy-anim-bubble-button {
139
+ position: relative;
140
+ z-index: 2;
141
+ }
142
+
143
+ .readdy-anim-bubble-button-container > .readdy-anim-bubble-button-effect-container {
144
+ position: absolute;
145
+ display: block;
146
+ width: 200%;
147
+ height: 400%;
148
+ top: -150%;
149
+ left: -50%;
150
+ pointer-events: none;
151
+ opacity: 0;
152
+ visibility: hidden;
153
+ transition: opacity 120ms ease, visibility 120ms ease, transform 100ms ease-out;
154
+ z-index: 1;
155
+ }
156
+
157
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-hover
158
+ > .readdy-anim-bubble-button-effect-container {
159
+ opacity: 1;
160
+ visibility: visible;
161
+ }
162
+
163
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-hover:active
164
+ > .readdy-anim-bubble-button-effect-container {
165
+ transform: scale(0.95);
166
+ }
167
+
168
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-effect-button,
169
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle {
170
+ position: absolute;
171
+ background: var(--readdy-anim-bubble-accent);
172
+ }
173
+
174
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle {
175
+ width: 14px;
176
+ height: 14px;
177
+ border-radius: 15px;
178
+ opacity: 0;
179
+ }
180
+
181
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle-top-left-1,
182
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle-top-left-2,
183
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle-top-left-3 {
184
+ top: 40%;
185
+ left: 27%;
186
+ }
187
+
188
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle-bottom-right-1,
189
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle-bottom-right-2,
190
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-circle-bottom-right-3 {
191
+ bottom: 40%;
192
+ right: 27%;
193
+ }
194
+
195
+ .readdy-anim-bubble-button-container .readdy-anim-bubble-button-effect-button {
196
+ width: 50%;
197
+ height: 25%;
198
+ top: 50%;
199
+ left: 25%;
200
+ z-index: 1;
201
+ transform: translateY(-50%);
202
+ border-radius: 999px;
203
+ opacity: 1;
204
+ }
205
+
206
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
207
+ .readdy-anim-bubble-button-effect-button {
208
+ animation: readdy-anim-bubble-core 1000ms cubic-bezier(0.22, 1, 0.36, 1) both;
209
+ }
210
+
211
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
212
+ .readdy-anim-bubble-button-circle-top-left-1 {
213
+ animation: readdy-anim-bubble-top-left-1 1200ms cubic-bezier(0.22, 1, 0.36, 1) both;
214
+ }
215
+
216
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
217
+ .readdy-anim-bubble-button-circle-top-left-2 {
218
+ animation: readdy-anim-bubble-top-left-2 1200ms cubic-bezier(0.22, 1, 0.36, 1) both;
219
+ }
220
+
221
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
222
+ .readdy-anim-bubble-button-circle-top-left-3 {
223
+ animation: readdy-anim-bubble-top-left-3 1200ms cubic-bezier(0.22, 1, 0.36, 1) both;
224
+ }
225
+
226
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
227
+ .readdy-anim-bubble-button-circle-bottom-right-1 {
228
+ animation: readdy-anim-bubble-bottom-right-1 1100ms cubic-bezier(0.22, 1, 0.36, 1) both;
229
+ }
230
+
231
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
232
+ .readdy-anim-bubble-button-circle-bottom-right-2 {
233
+ animation: readdy-anim-bubble-bottom-right-2 1100ms cubic-bezier(0.22, 1, 0.36, 1) both;
234
+ }
235
+
236
+ .readdy-anim-bubble-button-container.readdy-anim-bubble-button-fallback.readdy-anim-bubble-button-active
237
+ .readdy-anim-bubble-button-circle-bottom-right-3 {
238
+ animation: readdy-anim-bubble-bottom-right-3 1100ms cubic-bezier(0.22, 1, 0.36, 1) both;
239
+ }
240
+
241
+ @media (prefers-reduced-motion: reduce) {
242
+ .readdy-anim-bubble-button-container > .readdy-anim-bubble-button-effect-container {
243
+ display: none;
244
+ }
245
+ }
@@ -0,0 +1,66 @@
1
+ import './style.css'
2
+ import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
3
+ import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
4
+
5
+ export const ANIMATION_ID = buildAnimId('confetti-button')
6
+
7
+ const CSS_CLASS = buildAnimClass('confetti-button')
8
+ const LAYER_CLASS = buildAnimClass('confetti-layer')
9
+ const PIECE_CLASS = buildAnimClass('confetti-piece')
10
+ const stateMap = new WeakMap()
11
+
12
+ function createBurst(el, options) {
13
+ const layer = document.createElement('span')
14
+ layer.className = LAYER_CLASS
15
+ el.appendChild(layer)
16
+
17
+ const colors = options.colors ?? ['#22d3ee', '#a78bfa', '#f472b6', '#facc15', '#34d399']
18
+ const pieces = options.pieces ?? 18
19
+
20
+ for (let index = 0; index < pieces; index += 1) {
21
+ const piece = document.createElement('span')
22
+ piece.className = PIECE_CLASS
23
+ piece.style.setProperty('--readdy-anim-confetti-x', `${(Math.random() - 0.5) * 180}px`)
24
+ piece.style.setProperty('--readdy-anim-confetti-y', `${-40 - Math.random() * 90}px`)
25
+ piece.style.setProperty('--readdy-anim-confetti-rotate', `${Math.random() * 360}deg`)
26
+ piece.style.setProperty('--readdy-anim-confetti-delay', `${index * 14}ms`)
27
+ piece.style.background = colors[index % colors.length]
28
+ layer.appendChild(piece)
29
+ }
30
+
31
+ return window.setTimeout(() => {
32
+ layer.remove()
33
+ }, 1100)
34
+ }
35
+
36
+ export function init(el, options = {}) {
37
+ destroy(el)
38
+
39
+ el.classList.add(CSS_CLASS)
40
+
41
+ const onClick = () => {
42
+ if (prefersReducedMotion()) {
43
+ return
44
+ }
45
+ const timeoutId = createBurst(el, options)
46
+ const state = stateMap.get(el)
47
+ if (state) {
48
+ state.timeoutIds.push(timeoutId)
49
+ }
50
+ }
51
+
52
+ el.addEventListener('click', onClick)
53
+ stateMap.set(el, { onClick, timeoutIds: [] })
54
+ }
55
+
56
+ export function destroy(el) {
57
+ const state = stateMap.get(el)
58
+ if (state) {
59
+ el.removeEventListener('click', state.onClick)
60
+ state.timeoutIds.forEach((timeoutId) => window.clearTimeout(timeoutId))
61
+ stateMap.delete(el)
62
+ }
63
+
64
+ el.classList.remove(CSS_CLASS)
65
+ el.querySelectorAll(`.${LAYER_CLASS}`).forEach((node) => node.remove())
66
+ }
@@ -0,0 +1,30 @@
1
+ import React, { useEffect, useRef } from 'react'
2
+ import { init, destroy } from './index.js'
3
+ import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
4
+
5
+ type AnimConfettiButtonProps = {
6
+ children: React.ReactElement
7
+ pieces?: number
8
+ colors?: string[]
9
+ }
10
+
11
+ export function AnimConfettiButton({
12
+ children,
13
+ pieces,
14
+ colors,
15
+ }: AnimConfettiButtonProps) {
16
+ const ref = useRef<HTMLElement>(null)
17
+ const colorsKey = colors?.join('\u0001') ?? ''
18
+
19
+ useEffect(() => {
20
+ const el = ref.current
21
+ if (!el || prefersReducedMotion()) return
22
+
23
+ init(el, { pieces, colors })
24
+ return () => {
25
+ destroy(el)
26
+ }
27
+ }, [colorsKey, pieces])
28
+
29
+ return React.cloneElement(React.Children.only(children), { ref })
30
+ }