@arolariu/components 0.1.2 → 0.2.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.
- package/DEBUGGING.md +396 -396
- package/LICENSE.md +21 -21
- package/changelog.md +109 -118
- package/dist/components/ui/accordion.d.ts +2 -2
- package/dist/components/ui/accordion.d.ts.map +1 -1
- package/dist/components/ui/accordion.js +4 -4
- package/dist/components/ui/accordion.js.map +1 -1
- package/dist/components/ui/alert-dialog.d.ts +13 -13
- package/dist/components/ui/alert-dialog.d.ts.map +1 -1
- package/dist/components/ui/alert-dialog.js +4 -4
- package/dist/components/ui/alert-dialog.js.map +1 -1
- package/dist/components/ui/alert.d.ts +5 -5
- package/dist/components/ui/alert.d.ts.map +1 -1
- package/dist/components/ui/alert.js +3 -3
- package/dist/components/ui/alert.js.map +1 -1
- package/dist/components/ui/aspect-ratio.d.ts +1 -1
- package/dist/components/ui/aspect-ratio.d.ts.map +1 -1
- package/dist/components/ui/aspect-ratio.js +1 -1
- package/dist/components/ui/aspect-ratio.js.map +1 -1
- package/dist/components/ui/avatar.d.ts +2 -2
- package/dist/components/ui/avatar.d.ts.map +1 -1
- package/dist/components/ui/avatar.js +3 -3
- package/dist/components/ui/avatar.js.map +1 -1
- package/dist/components/ui/background-beams.d.ts.map +1 -1
- package/dist/components/ui/background-beams.js +6 -6
- package/dist/components/ui/background-beams.js.map +1 -1
- package/dist/components/ui/badge.d.ts +4 -4
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/badge.js +2 -2
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/breadcrumb.d.ts +6 -6
- package/dist/components/ui/breadcrumb.d.ts.map +1 -1
- package/dist/components/ui/breadcrumb.js +5 -5
- package/dist/components/ui/breadcrumb.js.map +1 -1
- package/dist/components/ui/bubble-background.d.ts +1 -1
- package/dist/components/ui/bubble-background.d.ts.map +1 -1
- package/dist/components/ui/bubble-background.js +13 -13
- package/dist/components/ui/bubble-background.js.map +1 -1
- package/dist/components/ui/button.d.ts +5 -5
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +2 -2
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/calendar.d.ts.map +1 -1
- package/dist/components/ui/calendar.js +4 -4
- package/dist/components/ui/calendar.js.map +1 -1
- package/dist/components/ui/card.d.ts +1 -1
- package/dist/components/ui/card.d.ts.map +1 -1
- package/dist/components/ui/card.js +3 -3
- package/dist/components/ui/card.js.map +1 -1
- package/dist/components/ui/carousel.d.ts +2 -2
- package/dist/components/ui/carousel.d.ts.map +1 -1
- package/dist/components/ui/carousel.js +3 -3
- package/dist/components/ui/carousel.js.map +1 -1
- package/dist/components/ui/chart.d.ts +4 -4
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/chart.js +1 -1
- package/dist/components/ui/chart.js.map +1 -1
- package/dist/components/ui/checkbox.d.ts +1 -1
- package/dist/components/ui/checkbox.d.ts.map +1 -1
- package/dist/components/ui/checkbox.js +3 -3
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/collapsible.d.ts +2 -2
- package/dist/components/ui/collapsible.d.ts.map +1 -1
- package/dist/components/ui/collapsible.js +1 -1
- package/dist/components/ui/collapsible.js.map +1 -1
- package/dist/components/ui/command.d.ts +2 -2
- package/dist/components/ui/command.d.ts.map +1 -1
- package/dist/components/ui/command.js +9 -9
- package/dist/components/ui/command.js.map +1 -1
- package/dist/components/ui/context-menu.d.ts +2 -2
- package/dist/components/ui/context-menu.d.ts.map +1 -1
- package/dist/components/ui/context-menu.js +11 -11
- package/dist/components/ui/context-menu.js.map +1 -1
- package/dist/components/ui/counting-number.d.ts +1 -1
- package/dist/components/ui/counting-number.d.ts.map +1 -1
- package/dist/components/ui/counting-number.js +4 -3
- package/dist/components/ui/counting-number.js.map +1 -1
- package/dist/components/ui/dialog.d.ts +1 -1
- package/dist/components/ui/dialog.d.ts.map +1 -1
- package/dist/components/ui/dialog.js +6 -6
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/dot-background.d.ts +10 -17
- package/dist/components/ui/dot-background.d.ts.map +1 -1
- package/dist/components/ui/dot-background.js +2 -2
- package/dist/components/ui/dot-background.js.map +1 -1
- package/dist/components/ui/drawer.d.ts +1 -1
- package/dist/components/ui/drawer.d.ts.map +1 -1
- package/dist/components/ui/drawer.js +5 -5
- package/dist/components/ui/drawer.js.map +1 -1
- package/dist/components/ui/dropdown-menu.d.ts +2 -2
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.js +10 -10
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/dropdrawer.d.ts +2 -2
- package/dist/components/ui/dropdrawer.d.ts.map +1 -1
- package/dist/components/ui/dropdrawer.js +12 -12
- package/dist/components/ui/dropdrawer.js.map +1 -1
- package/dist/components/ui/fireworks-background.d.ts.map +1 -1
- package/dist/components/ui/fireworks-background.js +1 -1
- package/dist/components/ui/fireworks-background.js.map +1 -1
- package/dist/components/ui/flip-button.d.ts +1 -1
- package/dist/components/ui/flip-button.d.ts.map +1 -1
- package/dist/components/ui/flip-button.js +3 -3
- package/dist/components/ui/flip-button.js.map +1 -1
- package/dist/components/ui/form.d.ts +3 -3
- package/dist/components/ui/form.d.ts.map +1 -1
- package/dist/components/ui/form.js +4 -4
- package/dist/components/ui/form.js.map +1 -1
- package/dist/components/ui/gradient-background.d.ts +1 -1
- package/dist/components/ui/gradient-background.d.ts.map +1 -1
- package/dist/components/ui/gradient-background.js +2 -2
- package/dist/components/ui/gradient-background.js.map +1 -1
- package/dist/components/ui/gradient-text.d.ts +1 -1
- package/dist/components/ui/gradient-text.d.ts.map +1 -1
- package/dist/components/ui/gradient-text.js +5 -5
- package/dist/components/ui/gradient-text.js.map +1 -1
- package/dist/components/ui/highlight-text.d.ts +1 -1
- package/dist/components/ui/highlight-text.d.ts.map +1 -1
- package/dist/components/ui/highlight-text.js +3 -3
- package/dist/components/ui/highlight-text.js.map +1 -1
- package/dist/components/ui/hole-background.d.ts.map +1 -1
- package/dist/components/ui/hole-background.js +11 -10
- package/dist/components/ui/hole-background.js.map +1 -1
- package/dist/components/ui/hover-card.d.ts +2 -2
- package/dist/components/ui/hover-card.d.ts.map +1 -1
- package/dist/components/ui/hover-card.js +3 -3
- package/dist/components/ui/hover-card.js.map +1 -1
- package/dist/components/ui/input-otp.d.ts +2 -2
- package/dist/components/ui/input-otp.d.ts.map +1 -1
- package/dist/components/ui/input-otp.js +5 -5
- package/dist/components/ui/input-otp.js.map +1 -1
- package/dist/components/ui/input.d.ts.map +1 -1
- package/dist/components/ui/input.js +2 -2
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/label.d.ts +1 -1
- package/dist/components/ui/label.d.ts.map +1 -1
- package/dist/components/ui/label.js +2 -2
- package/dist/components/ui/label.js.map +1 -1
- package/dist/components/ui/menubar.d.ts +2 -2
- package/dist/components/ui/menubar.d.ts.map +1 -1
- package/dist/components/ui/menubar.js +12 -12
- package/dist/components/ui/menubar.js.map +1 -1
- package/dist/components/ui/navigation-menu.d.ts +3 -3
- package/dist/components/ui/navigation-menu.d.ts.map +1 -1
- package/dist/components/ui/navigation-menu.js +6 -7
- package/dist/components/ui/navigation-menu.js.map +1 -1
- package/dist/components/ui/pagination.d.ts +2 -2
- package/dist/components/ui/pagination.d.ts.map +1 -1
- package/dist/components/ui/pagination.js +8 -4
- package/dist/components/ui/pagination.js.map +1 -1
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/popover.d.ts.map +1 -1
- package/dist/components/ui/popover.js +3 -3
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/progress.d.ts +1 -1
- package/dist/components/ui/progress.d.ts.map +1 -1
- package/dist/components/ui/progress.js +4 -4
- package/dist/components/ui/progress.js.map +1 -1
- package/dist/components/ui/radio-group.d.ts +1 -1
- package/dist/components/ui/radio-group.d.ts.map +1 -1
- package/dist/components/ui/radio-group.js +3 -3
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/resizable.d.ts +1 -1
- package/dist/components/ui/resizable.d.ts.map +1 -1
- package/dist/components/ui/resizable.js +5 -5
- package/dist/components/ui/resizable.js.map +1 -1
- package/dist/components/ui/ripple-button.d.ts +1 -1
- package/dist/components/ui/ripple-button.d.ts.map +1 -1
- package/dist/components/ui/ripple-button.js +4 -4
- package/dist/components/ui/ripple-button.js.map +1 -1
- package/dist/components/ui/scratcher.d.ts.map +1 -1
- package/dist/components/ui/scratcher.js +7 -5
- package/dist/components/ui/scratcher.js.map +1 -1
- package/dist/components/ui/scroll-area.d.ts +1 -1
- package/dist/components/ui/scroll-area.d.ts.map +1 -1
- package/dist/components/ui/scroll-area.js +4 -4
- package/dist/components/ui/scroll-area.js.map +1 -1
- package/dist/components/ui/select.d.ts +1 -1
- package/dist/components/ui/select.d.ts.map +1 -1
- package/dist/components/ui/select.js +7 -7
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/separator.d.ts +1 -1
- package/dist/components/ui/separator.d.ts.map +1 -1
- package/dist/components/ui/separator.js +3 -3
- package/dist/components/ui/separator.js.map +1 -1
- package/dist/components/ui/sheet.d.ts +2 -2
- package/dist/components/ui/sheet.d.ts.map +1 -1
- package/dist/components/ui/sheet.js +6 -6
- package/dist/components/ui/sheet.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +5 -5
- package/dist/components/ui/sidebar.d.ts.map +1 -1
- package/dist/components/ui/sidebar.js +5 -5
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/skeleton.d.ts.map +1 -1
- package/dist/components/ui/skeleton.js +2 -2
- package/dist/components/ui/skeleton.js.map +1 -1
- package/dist/components/ui/slider.d.ts +1 -1
- package/dist/components/ui/slider.d.ts.map +1 -1
- package/dist/components/ui/slider.js +5 -5
- package/dist/components/ui/slider.js.map +1 -1
- package/dist/components/ui/sonner.d.ts +1 -1
- package/dist/components/ui/sonner.d.ts.map +1 -1
- package/dist/components/ui/sonner.js +1 -1
- package/dist/components/ui/sonner.js.map +1 -1
- package/dist/components/ui/switch.d.ts +1 -1
- package/dist/components/ui/switch.d.ts.map +1 -1
- package/dist/components/ui/switch.js +4 -4
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/table.d.ts +1 -1
- package/dist/components/ui/table.d.ts.map +1 -1
- package/dist/components/ui/table.js +5 -5
- package/dist/components/ui/table.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +2 -2
- package/dist/components/ui/tabs.d.ts.map +1 -1
- package/dist/components/ui/tabs.js +4 -4
- package/dist/components/ui/tabs.js.map +1 -1
- package/dist/components/ui/textarea.d.ts +1 -1
- package/dist/components/ui/textarea.d.ts.map +1 -1
- package/dist/components/ui/textarea.js +2 -2
- package/dist/components/ui/textarea.js.map +1 -1
- package/dist/components/ui/toggle-group.d.ts +3 -3
- package/dist/components/ui/toggle-group.d.ts.map +1 -1
- package/dist/components/ui/toggle-group.js +2 -2
- package/dist/components/ui/toggle-group.js.map +1 -1
- package/dist/components/ui/toggle.d.ts +6 -6
- package/dist/components/ui/toggle.d.ts.map +1 -1
- package/dist/components/ui/toggle.js +2 -2
- package/dist/components/ui/toggle.js.map +1 -1
- package/dist/components/ui/tooltip.d.ts +6 -6
- package/dist/components/ui/tooltip.d.ts.map +1 -1
- package/dist/components/ui/tooltip.js +4 -4
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/components/ui/typewriter.d.ts.map +1 -1
- package/dist/components/ui/typewriter.js +15 -11
- package/dist/components/ui/typewriter.js.map +1 -1
- package/dist/hooks/useIsMobile.d.ts +2 -5
- package/dist/hooks/useIsMobile.d.ts.map +1 -1
- package/dist/hooks/useIsMobile.js +1 -1
- package/dist/hooks/useIsMobile.js.map +1 -1
- package/dist/hooks/useWindowSize.d.ts +0 -1
- package/dist/hooks/useWindowSize.d.ts.map +1 -1
- package/dist/hooks/useWindowSize.js +1 -1
- package/dist/hooks/useWindowSize.js.map +1 -1
- package/dist/index.css +2 -2
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +37 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/utilities.d.ts +9 -0
- package/dist/lib/utilities.d.ts.map +1 -0
- package/dist/lib/{utils.js → utilities.js} +1 -1
- package/dist/lib/utilities.js.map +1 -0
- package/package.json +85 -89
- package/{README.md → readme.md} +627 -627
- package/src/components/ui/accordion.tsx +56 -66
- package/src/components/ui/alert-dialog.tsx +135 -160
- package/src/components/ui/alert.tsx +58 -69
- package/src/components/ui/aspect-ratio.tsx +15 -12
- package/src/components/ui/avatar.tsx +38 -53
- package/src/components/ui/background-beams.tsx +145 -142
- package/src/components/ui/badge.tsx +47 -48
- package/src/components/ui/breadcrumb.tsx +97 -117
- package/src/components/ui/bubble-background.tsx +170 -189
- package/src/components/ui/button.tsx +61 -61
- package/src/components/ui/calendar.tsx +177 -216
- package/src/components/ui/card.tsx +83 -97
- package/src/components/ui/carousel.tsx +204 -241
- package/src/components/ui/chart.tsx +303 -385
- package/src/components/ui/checkbox.tsx +27 -32
- package/src/components/ui/collapsible.tsx +33 -34
- package/src/components/ui/command.tsx +137 -184
- package/src/components/ui/context-menu.tsx +229 -255
- package/src/components/ui/counting-number.tsx +92 -108
- package/src/components/ui/dialog.tsx +141 -146
- package/src/components/ui/dot-background.tsx +153 -158
- package/src/components/ui/drawer.tsx +133 -141
- package/src/components/ui/dropdown-menu.tsx +235 -260
- package/src/components/ui/dropdrawer.tsx +870 -973
- package/src/components/ui/fireworks-background.tsx +325 -378
- package/src/components/ui/flip-button.tsx +89 -110
- package/src/components/ui/form.tsx +145 -174
- package/src/components/ui/gradient-background.tsx +30 -43
- package/src/components/ui/gradient-text.tsx +62 -65
- package/src/components/ui/highlight-text.tsx +54 -71
- package/src/components/ui/hole-background.tsx +326 -361
- package/src/components/ui/hover-card.tsx +48 -44
- package/src/components/ui/input-otp.tsx +76 -77
- package/src/components/ui/input.tsx +22 -22
- package/src/components/ui/label.tsx +21 -24
- package/src/components/ui/menubar.tsx +256 -279
- package/src/components/ui/navigation-menu.tsx +135 -171
- package/src/components/ui/pagination.tsx +103 -129
- package/src/components/ui/popover.tsx +52 -48
- package/src/components/ui/progress.tsx +23 -31
- package/src/components/ui/radio-group.tsx +37 -45
- package/src/components/ui/resizable.tsx +52 -56
- package/src/components/ui/ripple-button.tsx +90 -111
- package/src/components/ui/scratcher.tsx +167 -171
- package/src/components/ui/scroll-area.tsx +45 -58
- package/src/components/ui/select.tsx +160 -191
- package/src/components/ui/separator.tsx +28 -28
- package/src/components/ui/sheet.tsx +133 -145
- package/src/components/ui/sidebar.tsx +673 -729
- package/src/components/ui/skeleton.tsx +16 -19
- package/src/components/ui/slider.tsx +49 -63
- package/src/components/ui/sonner.tsx +30 -26
- package/src/components/ui/switch.tsx +27 -31
- package/src/components/ui/table.tsx +98 -119
- package/src/components/ui/tabs.tsx +54 -66
- package/src/components/ui/textarea.tsx +20 -20
- package/src/components/ui/toggle-group.tsx +66 -73
- package/src/components/ui/toggle.tsx +46 -47
- package/src/components/ui/tooltip.tsx +56 -61
- package/src/components/ui/typewriter.tsx +174 -188
- package/src/hooks/useIsMobile.tsx +42 -45
- package/src/hooks/useWindowSize.tsx +66 -72
- package/src/index.css +73 -73
- package/src/index.ts +303 -408
- package/src/lib/utilities.ts +12 -0
- package/dist/lib/utils.d.ts +0 -7
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js.map +0 -1
- package/src/lib/utils.ts +0 -10
|
@@ -1,171 +1,167 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import React, {
|
|
6
|
-
|
|
7
|
-
interface ScratcherProps {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
width: number;
|
|
10
|
-
height: number;
|
|
11
|
-
minScratchPercentage?: number;
|
|
12
|
-
className?: string;
|
|
13
|
-
onComplete?: () => void;
|
|
14
|
-
gradientColors?: [string, string, string];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
document.addEventListener("
|
|
75
|
-
document.addEventListener("
|
|
76
|
-
document.addEventListener("
|
|
77
|
-
document.addEventListener("
|
|
78
|
-
document.addEventListener("
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
document.removeEventListener("
|
|
84
|
-
document.removeEventListener("
|
|
85
|
-
document.removeEventListener("
|
|
86
|
-
document.removeEventListener("
|
|
87
|
-
document.removeEventListener("
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
ctx.
|
|
105
|
-
ctx.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
let
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
{children}
|
|
169
|
-
</motion.div>
|
|
170
|
-
);
|
|
171
|
-
};
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {cn} from "@/lib/utilities";
|
|
4
|
+
import {motion, useAnimation} from "motion/react";
|
|
5
|
+
import React, {useEffect, useRef, useState} from "react";
|
|
6
|
+
|
|
7
|
+
interface ScratcherProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
minScratchPercentage?: number;
|
|
12
|
+
className?: string;
|
|
13
|
+
onComplete?: () => void;
|
|
14
|
+
gradientColors?: [string, string, string];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const defaultGradientColors: [string, string, string] = ["#A97CF8", "#F38CB8", "#FDCC92"];
|
|
18
|
+
|
|
19
|
+
export const Scratcher: React.FC<ScratcherProps> = ({
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
minScratchPercentage = 50,
|
|
23
|
+
onComplete,
|
|
24
|
+
children,
|
|
25
|
+
className,
|
|
26
|
+
gradientColors = defaultGradientColors,
|
|
27
|
+
}) => {
|
|
28
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
29
|
+
const [isScratching, setIsScratching] = useState(false);
|
|
30
|
+
const [isComplete, setIsComplete] = useState(false);
|
|
31
|
+
|
|
32
|
+
const controls = useAnimation();
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const canvas = canvasRef.current;
|
|
36
|
+
const ctx = canvas?.getContext("2d");
|
|
37
|
+
if (canvas && ctx) {
|
|
38
|
+
ctx.fillStyle = "#ccc";
|
|
39
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
40
|
+
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
|
|
41
|
+
gradient.addColorStop(0, gradientColors[0]);
|
|
42
|
+
gradient.addColorStop(0.5, gradientColors[1]);
|
|
43
|
+
gradient.addColorStop(1, gradientColors[2]);
|
|
44
|
+
ctx.fillStyle = gradient;
|
|
45
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
46
|
+
}
|
|
47
|
+
}, [gradientColors]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const handleDocumentMouseMove = (event: MouseEvent) => {
|
|
51
|
+
if (!isScratching) return;
|
|
52
|
+
scratch(event.clientX, event.clientY);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleDocumentTouchMove = (event: TouchEvent) => {
|
|
56
|
+
if (!isScratching) return;
|
|
57
|
+
const [touch] = event.touches;
|
|
58
|
+
if (!touch) return;
|
|
59
|
+
scratch(touch.clientX, touch.clientY);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const handleDocumentMouseUp = () => {
|
|
63
|
+
setIsScratching(false);
|
|
64
|
+
checkCompletion();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleDocumentTouchEnd = () => {
|
|
68
|
+
setIsScratching(false);
|
|
69
|
+
checkCompletion();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
document.addEventListener("mousedown", handleDocumentMouseMove);
|
|
73
|
+
document.addEventListener("mousemove", handleDocumentMouseMove);
|
|
74
|
+
document.addEventListener("touchstart", handleDocumentTouchMove);
|
|
75
|
+
document.addEventListener("touchmove", handleDocumentTouchMove);
|
|
76
|
+
document.addEventListener("mouseup", handleDocumentMouseUp);
|
|
77
|
+
document.addEventListener("touchend", handleDocumentTouchEnd);
|
|
78
|
+
document.addEventListener("touchcancel", handleDocumentTouchEnd);
|
|
79
|
+
|
|
80
|
+
return () => {
|
|
81
|
+
document.removeEventListener("mousedown", handleDocumentMouseMove);
|
|
82
|
+
document.removeEventListener("mousemove", handleDocumentMouseMove);
|
|
83
|
+
document.removeEventListener("touchstart", handleDocumentTouchMove);
|
|
84
|
+
document.removeEventListener("touchmove", handleDocumentTouchMove);
|
|
85
|
+
document.removeEventListener("mouseup", handleDocumentMouseUp);
|
|
86
|
+
document.removeEventListener("touchend", handleDocumentTouchEnd);
|
|
87
|
+
document.removeEventListener("touchcancel", handleDocumentTouchEnd);
|
|
88
|
+
};
|
|
89
|
+
}, [isScratching]);
|
|
90
|
+
|
|
91
|
+
const handleMouseDown = () => setIsScratching(true);
|
|
92
|
+
|
|
93
|
+
const handleTouchStart = () => setIsScratching(true);
|
|
94
|
+
|
|
95
|
+
const scratch = (clientX: number, clientY: number) => {
|
|
96
|
+
const canvas = canvasRef.current;
|
|
97
|
+
const ctx = canvas?.getContext("2d");
|
|
98
|
+
if (canvas && ctx) {
|
|
99
|
+
const rect = canvas.getBoundingClientRect();
|
|
100
|
+
const x = clientX - rect.left + 16;
|
|
101
|
+
const y = clientY - rect.top + 16;
|
|
102
|
+
ctx.globalCompositeOperation = "destination-out";
|
|
103
|
+
ctx.beginPath();
|
|
104
|
+
ctx.arc(x, y, 30, 0, Math.PI * 2);
|
|
105
|
+
ctx.fill();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const startAnimation = async () => {
|
|
110
|
+
await controls.start({
|
|
111
|
+
scale: [1, 1.5, 1],
|
|
112
|
+
rotate: [0, 10, -10, 10, -10, 0],
|
|
113
|
+
transition: {duration: 0.5},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Call onComplete after animation finishes
|
|
117
|
+
if (onComplete) {
|
|
118
|
+
onComplete();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const checkCompletion = () => {
|
|
123
|
+
if (isComplete) return;
|
|
124
|
+
|
|
125
|
+
const canvas = canvasRef.current;
|
|
126
|
+
const ctx = canvas?.getContext("2d");
|
|
127
|
+
if (canvas && ctx) {
|
|
128
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
129
|
+
const pixels = imageData.data;
|
|
130
|
+
const totalPixels = pixels.length / 4;
|
|
131
|
+
let clearPixels = 0;
|
|
132
|
+
|
|
133
|
+
for (let i = 3; i < pixels.length; i += 4) {
|
|
134
|
+
if (pixels[i] === 0) clearPixels++;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const percentage = (clearPixels / totalPixels) * 100;
|
|
138
|
+
|
|
139
|
+
if (percentage >= minScratchPercentage) {
|
|
140
|
+
setIsComplete(true);
|
|
141
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
142
|
+
startAnimation();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<motion.div
|
|
149
|
+
className={cn("relative select-none", className)}
|
|
150
|
+
style={{
|
|
151
|
+
width,
|
|
152
|
+
height,
|
|
153
|
+
cursor:
|
|
154
|
+
"url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8Y2lyY2xlIGN4PSIxNiIgY3k9IjE2IiByPSIxNSIgc3R5bGU9ImZpbGw6I2ZmZjtzdHJva2U6IzAwMDtzdHJva2Utd2lkdGg6MXB4OyIgLz4KPC9zdmc+'), auto",
|
|
155
|
+
}}
|
|
156
|
+
animate={controls}>
|
|
157
|
+
<canvas
|
|
158
|
+
ref={canvasRef}
|
|
159
|
+
width={width}
|
|
160
|
+
height={height}
|
|
161
|
+
className='absolute top-0 left-0'
|
|
162
|
+
onMouseDown={handleMouseDown}
|
|
163
|
+
onTouchStart={handleTouchStart}></canvas>
|
|
164
|
+
{children}
|
|
165
|
+
</motion.div>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
@@ -1,58 +1,45 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
function ScrollArea({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
className,
|
|
47
|
-
)}
|
|
48
|
-
{...props}
|
|
49
|
-
>
|
|
50
|
-
<ScrollAreaPrimitive.ScrollAreaThumb
|
|
51
|
-
data-slot="scroll-area-thumb"
|
|
52
|
-
className="bg-neutral-200 relative flex-1 rounded-full dark:bg-neutral-800"
|
|
53
|
-
/>
|
|
54
|
-
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { ScrollArea, ScrollBar };
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import {cn} from "@/lib/utilities";
|
|
7
|
+
|
|
8
|
+
function ScrollArea({className, children, ...props}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
|
9
|
+
return (
|
|
10
|
+
<ScrollAreaPrimitive.Root
|
|
11
|
+
data-slot='scroll-area'
|
|
12
|
+
className={cn("relative", className)}
|
|
13
|
+
{...props}>
|
|
14
|
+
<ScrollAreaPrimitive.Viewport
|
|
15
|
+
data-slot='scroll-area-viewport'
|
|
16
|
+
className='size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-neutral-950/50 focus-visible:outline-1 dark:focus-visible:ring-neutral-300/50'>
|
|
17
|
+
{children}
|
|
18
|
+
</ScrollAreaPrimitive.Viewport>
|
|
19
|
+
<ScrollBar />
|
|
20
|
+
<ScrollAreaPrimitive.Corner />
|
|
21
|
+
</ScrollAreaPrimitive.Root>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function ScrollBar({className, orientation = "vertical", ...props}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
|
26
|
+
return (
|
|
27
|
+
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
|
28
|
+
data-slot='scroll-area-scrollbar'
|
|
29
|
+
orientation={orientation}
|
|
30
|
+
className={cn(
|
|
31
|
+
"flex touch-none p-px transition-colors select-none",
|
|
32
|
+
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent",
|
|
33
|
+
orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent",
|
|
34
|
+
className,
|
|
35
|
+
)}
|
|
36
|
+
{...props}>
|
|
37
|
+
<ScrollAreaPrimitive.ScrollAreaThumb
|
|
38
|
+
data-slot='scroll-area-thumb'
|
|
39
|
+
className='relative flex-1 rounded-full bg-neutral-200 dark:bg-neutral-800'
|
|
40
|
+
/>
|
|
41
|
+
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {ScrollArea, ScrollBar};
|