@moontra/moonui 2.1.9 → 2.2.1
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/dist/index.d.mts +1656 -0
- package/dist/index.d.ts +1656 -0
- package/dist/index.js +1847 -469
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1679 -471
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/components/ui/accordion.tsx +1 -1
- package/src/components/ui/alert.tsx +123 -93
- package/src/components/ui/aspect-ratio.tsx +1 -1
- package/src/components/ui/avatar.tsx +8 -6
- package/src/components/ui/badge.tsx +20 -18
- package/src/components/ui/breadcrumb.tsx +12 -10
- package/src/components/ui/button.stories.tsx +4 -2
- package/src/components/ui/button.tsx +71 -68
- package/src/components/ui/calendar.tsx +2 -2
- package/src/components/ui/card-input.tsx +231 -0
- package/src/components/ui/card.stories.tsx +2 -0
- package/src/components/ui/card.tsx +9 -7
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/collapsible.tsx +3 -3
- package/src/components/ui/color-picker.tsx +2 -2
- package/src/components/ui/command.tsx +4 -4
- package/src/components/ui/data-table.stories.tsx +4 -2
- package/src/components/ui/data-table.tsx +8 -8
- package/src/components/ui/date-picker.stories.tsx +2 -0
- package/src/components/ui/date-picker.tsx +25 -15
- package/src/components/ui/dialog.tsx +2 -2
- package/src/components/ui/draggable-list.tsx +3 -1
- package/src/components/ui/dropdown-menu.tsx +2 -2
- package/src/components/ui/file-upload.tsx +2 -2
- package/src/components/ui/github-stars.tsx +1 -1
- package/src/components/ui/index.ts +357 -45
- package/src/components/ui/input.stories.tsx +2 -0
- package/src/components/ui/input.tsx +3 -1
- package/src/components/ui/locked-component.tsx +222 -0
- package/src/components/ui/moon-logo.tsx +1 -1
- package/src/components/ui/pagination.tsx +10 -8
- package/src/components/ui/phone-input.tsx +172 -0
- package/src/components/ui/popover-pro.tsx +424 -0
- package/src/components/ui/popover.tsx +3 -3
- package/src/components/ui/progress.tsx +1 -1
- package/src/components/ui/radio-group.tsx +1 -1
- package/src/components/ui/rich-text-editor/index.tsx +2 -1
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/select.tsx +7 -3
- package/src/components/ui/separator.tsx +2 -2
- package/src/components/ui/skeleton.tsx +19 -7
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/ui/swipeable-card.tsx +2 -0
- package/src/components/ui/switch.tsx +1 -1
- package/src/components/ui/table.tsx +7 -5
- package/src/components/ui/tabs.tsx +6 -1
- package/src/components/ui/tags-input.tsx +130 -0
- package/src/components/ui/textarea.tsx +3 -1
- package/src/components/ui/toast.tsx +5 -3
- package/src/components/ui/toggle.tsx +2 -3
- package/src/components/ui/tooltip.tsx +2 -5
- package/src/index.tsx +4 -46
- package/src/lib/micro-interactions.ts +2 -1
- package/src/lib/performance-profiler.ts +79 -0
- package/src/styles/index.css +315 -2
- package/src/use-performance-optimizer.ts +26 -26
- package/src/use-scroll-animation.ts +5 -7
package/src/styles/index.css
CHANGED
|
@@ -1,4 +1,317 @@
|
|
|
1
1
|
/* MoonUI - Complete CSS System */
|
|
2
|
-
@
|
|
2
|
+
@tailwind base;
|
|
3
|
+
@tailwind components;
|
|
4
|
+
@tailwind utilities;
|
|
5
|
+
|
|
3
6
|
@import "./tokens.css";
|
|
4
|
-
@import "./design-system.css";
|
|
7
|
+
@import "./design-system.css";
|
|
8
|
+
|
|
9
|
+
/* ======================
|
|
10
|
+
MOONUI COMPONENT STYLES
|
|
11
|
+
====================== */
|
|
12
|
+
|
|
13
|
+
@layer components {
|
|
14
|
+
/* ======================
|
|
15
|
+
BUTTON COMPONENT
|
|
16
|
+
====================== */
|
|
17
|
+
.moonui-button-base {
|
|
18
|
+
@apply inline-flex items-center justify-center rounded-md text-sm font-medium;
|
|
19
|
+
@apply ring-offset-background transition-colors duration-200;
|
|
20
|
+
@apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
21
|
+
@apply disabled:pointer-events-none disabled:opacity-50;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* ======================
|
|
25
|
+
CARD COMPONENT
|
|
26
|
+
====================== */
|
|
27
|
+
.moonui-card-base {
|
|
28
|
+
@apply rounded-lg border bg-card text-card-foreground shadow-sm;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.moonui-card-header {
|
|
32
|
+
@apply flex flex-col space-y-1.5 p-6;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.moonui-card-title {
|
|
36
|
+
@apply text-2xl font-semibold leading-none tracking-tight;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.moonui-card-description {
|
|
40
|
+
@apply text-sm text-muted-foreground;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.moonui-card-content {
|
|
44
|
+
@apply p-6 pt-0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.moonui-card-footer {
|
|
48
|
+
@apply flex items-center p-6 pt-0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* ======================
|
|
52
|
+
INPUT COMPONENT
|
|
53
|
+
====================== */
|
|
54
|
+
.moonui-input-base {
|
|
55
|
+
@apply flex h-10 w-full rounded-md border border-input bg-background px-3 py-2;
|
|
56
|
+
@apply text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium;
|
|
57
|
+
@apply placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2;
|
|
58
|
+
@apply focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* ======================
|
|
62
|
+
LABEL COMPONENT
|
|
63
|
+
====================== */
|
|
64
|
+
.moonui-label-base {
|
|
65
|
+
@apply text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* ======================
|
|
69
|
+
DIALOG COMPONENT
|
|
70
|
+
====================== */
|
|
71
|
+
.moonui-dialog-overlay {
|
|
72
|
+
@apply fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out;
|
|
73
|
+
@apply data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.moonui-dialog-content {
|
|
77
|
+
@apply fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%];
|
|
78
|
+
@apply gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in;
|
|
79
|
+
@apply data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0;
|
|
80
|
+
@apply data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2;
|
|
81
|
+
@apply data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2;
|
|
82
|
+
@apply data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ======================
|
|
86
|
+
ALERT COMPONENT
|
|
87
|
+
====================== */
|
|
88
|
+
.moonui-alert-base {
|
|
89
|
+
@apply relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute;
|
|
90
|
+
@apply [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.moonui-alert-destructive {
|
|
94
|
+
@apply border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* ======================
|
|
98
|
+
BADGE COMPONENT
|
|
99
|
+
====================== */
|
|
100
|
+
.moonui-badge-base {
|
|
101
|
+
@apply inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold;
|
|
102
|
+
@apply transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.moonui-badge-default {
|
|
106
|
+
@apply border-transparent bg-primary text-primary-foreground hover:bg-primary/80;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.moonui-badge-secondary {
|
|
110
|
+
@apply border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.moonui-badge-destructive {
|
|
114
|
+
@apply border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.moonui-badge-outline {
|
|
118
|
+
@apply text-foreground;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* ======================
|
|
122
|
+
TABLE COMPONENT
|
|
123
|
+
====================== */
|
|
124
|
+
.moonui-table-base {
|
|
125
|
+
@apply w-full caption-bottom text-sm;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.moonui-table-header {
|
|
129
|
+
@apply [&_tr]:border-b;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.moonui-table-body {
|
|
133
|
+
@apply [&_tr:last-child]:border-0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.moonui-table-footer {
|
|
137
|
+
@apply border-t bg-muted/50 font-medium [&>tr]:last:border-b-0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.moonui-table-row {
|
|
141
|
+
@apply border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.moonui-table-head {
|
|
145
|
+
@apply h-12 px-4 text-left align-middle font-medium text-muted-foreground;
|
|
146
|
+
@apply [&:has([role=checkbox])]:pr-0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.moonui-table-cell {
|
|
150
|
+
@apply p-4 align-middle [&:has([role=checkbox])]:pr-0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* ======================
|
|
154
|
+
TOGGLE COMPONENT
|
|
155
|
+
====================== */
|
|
156
|
+
.moonui-toggle-base {
|
|
157
|
+
@apply inline-flex items-center justify-center rounded-md text-sm font-medium;
|
|
158
|
+
@apply ring-offset-background transition-all duration-200;
|
|
159
|
+
@apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
160
|
+
@apply disabled:pointer-events-none disabled:opacity-50;
|
|
161
|
+
color: hsl(var(--foreground));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* ======================
|
|
165
|
+
SWITCH COMPONENT
|
|
166
|
+
====================== */
|
|
167
|
+
.moonui-switch-base {
|
|
168
|
+
@apply peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2;
|
|
169
|
+
@apply border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2;
|
|
170
|
+
@apply focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background;
|
|
171
|
+
@apply disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary;
|
|
172
|
+
@apply data-[state=unchecked]:bg-input;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.moonui-switch-thumb {
|
|
176
|
+
@apply pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0;
|
|
177
|
+
@apply transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* ======================
|
|
181
|
+
CHECKBOX COMPONENT
|
|
182
|
+
====================== */
|
|
183
|
+
.moonui-checkbox-base {
|
|
184
|
+
@apply peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background;
|
|
185
|
+
@apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
186
|
+
@apply disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary;
|
|
187
|
+
@apply data-[state=checked]:text-primary-foreground;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* ======================
|
|
191
|
+
RADIO GROUP COMPONENT
|
|
192
|
+
====================== */
|
|
193
|
+
.moonui-radio-base {
|
|
194
|
+
@apply aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background;
|
|
195
|
+
@apply focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
196
|
+
@apply disabled:cursor-not-allowed disabled:opacity-50;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* ======================
|
|
200
|
+
SELECT COMPONENT
|
|
201
|
+
====================== */
|
|
202
|
+
.moonui-select-trigger {
|
|
203
|
+
@apply flex h-10 w-full items-center justify-between rounded-md border border-input;
|
|
204
|
+
@apply bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground;
|
|
205
|
+
@apply focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2;
|
|
206
|
+
@apply disabled:cursor-not-allowed disabled:opacity-50;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.moonui-select-content {
|
|
210
|
+
@apply relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover;
|
|
211
|
+
@apply text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out;
|
|
212
|
+
@apply data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95;
|
|
213
|
+
@apply data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/* ======================
|
|
217
|
+
TOOLTIP COMPONENT
|
|
218
|
+
====================== */
|
|
219
|
+
.moonui-tooltip-content {
|
|
220
|
+
@apply z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground;
|
|
221
|
+
@apply shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out;
|
|
222
|
+
@apply data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95;
|
|
223
|
+
@apply data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2;
|
|
224
|
+
@apply data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* ======================
|
|
228
|
+
SKELETON COMPONENT
|
|
229
|
+
====================== */
|
|
230
|
+
.moonui-skeleton-base {
|
|
231
|
+
@apply animate-pulse rounded-md bg-muted;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* ======================
|
|
235
|
+
AVATAR COMPONENT
|
|
236
|
+
====================== */
|
|
237
|
+
.moonui-avatar-base {
|
|
238
|
+
@apply relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.moonui-avatar-image {
|
|
242
|
+
@apply aspect-square h-full w-full;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.moonui-avatar-fallback {
|
|
246
|
+
@apply flex h-full w-full items-center justify-center rounded-full bg-muted;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* ======================
|
|
250
|
+
ACCORDION COMPONENT
|
|
251
|
+
====================== */
|
|
252
|
+
.moonui-accordion-item {
|
|
253
|
+
@apply border-b;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.moonui-accordion-trigger {
|
|
257
|
+
@apply flex flex-1 items-center justify-between py-4 font-medium transition-all;
|
|
258
|
+
@apply hover:underline [&[data-state=open]>svg]:rotate-180;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.moonui-accordion-content {
|
|
262
|
+
@apply overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up;
|
|
263
|
+
@apply data-[state=open]:animate-accordion-down;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/* ======================
|
|
267
|
+
TABS COMPONENT
|
|
268
|
+
====================== */
|
|
269
|
+
.moonui-tabs-list {
|
|
270
|
+
@apply inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.moonui-tabs-trigger {
|
|
274
|
+
@apply inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5;
|
|
275
|
+
@apply text-sm font-medium ring-offset-background transition-all focus-visible:outline-none;
|
|
276
|
+
@apply focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
277
|
+
@apply disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background;
|
|
278
|
+
@apply data-[state=active]:text-foreground data-[state=active]:shadow-sm;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.moonui-tabs-content {
|
|
282
|
+
@apply mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2;
|
|
283
|
+
@apply focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* ======================
|
|
287
|
+
PROGRESS COMPONENT
|
|
288
|
+
====================== */
|
|
289
|
+
.moonui-progress-base {
|
|
290
|
+
@apply relative h-4 w-full overflow-hidden rounded-full bg-secondary;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.moonui-progress-indicator {
|
|
294
|
+
@apply h-full w-full flex-1 bg-primary transition-all;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/* ======================
|
|
298
|
+
SLIDER COMPONENT
|
|
299
|
+
====================== */
|
|
300
|
+
.moonui-slider-base {
|
|
301
|
+
@apply relative flex w-full touch-none select-none items-center;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.moonui-slider-track {
|
|
305
|
+
@apply relative h-2 w-full grow overflow-hidden rounded-full bg-secondary;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.moonui-slider-range {
|
|
309
|
+
@apply absolute h-full bg-primary;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.moonui-slider-thumb {
|
|
313
|
+
@apply block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background;
|
|
314
|
+
@apply transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring;
|
|
315
|
+
@apply focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -19,11 +19,11 @@ export function usePerformanceOptimizer() {
|
|
|
19
19
|
const componentMetrics = performanceProfiler.getMeasurements('component');
|
|
20
20
|
if (componentMetrics.length > 0) {
|
|
21
21
|
const slowComponents = componentMetrics
|
|
22
|
-
.filter(m => m.duration > 16.67) // Slower than 60fps
|
|
23
|
-
.sort((a, b) => b.duration - a.duration)
|
|
22
|
+
.filter((m: any) => m.duration > 16.67) // Slower than 60fps
|
|
23
|
+
.sort((a: any, b: any) => b.duration - a.duration)
|
|
24
24
|
.slice(0, 5);
|
|
25
25
|
|
|
26
|
-
slowComponents.forEach(component => {
|
|
26
|
+
slowComponents.forEach((component: any) => {
|
|
27
27
|
suggestions.push({
|
|
28
28
|
type: 'component',
|
|
29
29
|
severity: component.duration > 50 ? 'high' : 'medium',
|
|
@@ -55,7 +55,7 @@ export function usePerformanceOptimizer() {
|
|
|
55
55
|
// Analyze layout shifts
|
|
56
56
|
const layoutShifts = performanceProfiler.getMeasurements('layout-shift');
|
|
57
57
|
if (layoutShifts.length > 0) {
|
|
58
|
-
const totalShift = layoutShifts.reduce((sum, shift) => sum + (shift.value || 0), 0);
|
|
58
|
+
const totalShift = layoutShifts.reduce((sum: any, shift: any) => sum + (shift.value || 0), 0);
|
|
59
59
|
|
|
60
60
|
if (totalShift > 0.1) {
|
|
61
61
|
suggestions.push({
|
|
@@ -112,9 +112,9 @@ export function useRenderOptimization<T>(
|
|
|
112
112
|
React.useEffect(() => {
|
|
113
113
|
if (process.env.NODE_ENV === 'development') {
|
|
114
114
|
const componentName = 'useRenderOptimization';
|
|
115
|
-
performanceProfiler.measureComponent(componentName
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const endMeasure = performanceProfiler.measureComponent(componentName);
|
|
116
|
+
// Measure the impact of memoization
|
|
117
|
+
endMeasure();
|
|
118
118
|
}
|
|
119
119
|
}, dependencies);
|
|
120
120
|
|
|
@@ -126,7 +126,7 @@ export function useDebouncePerformance<T extends (...args: any[]) => void>(
|
|
|
126
126
|
callback: T,
|
|
127
127
|
delay: number = 300
|
|
128
128
|
): T {
|
|
129
|
-
const timeoutRef = React.useRef<NodeJS.Timeout>();
|
|
129
|
+
const timeoutRef = React.useRef<NodeJS.Timeout | undefined>(undefined);
|
|
130
130
|
|
|
131
131
|
const debouncedCallback = React.useCallback(
|
|
132
132
|
(...args: Parameters<T>) => {
|
|
@@ -135,9 +135,9 @@ export function useDebouncePerformance<T extends (...args: any[]) => void>(
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
timeoutRef.current = setTimeout(() => {
|
|
138
|
-
performanceProfiler.measureComponent('debounced-callback'
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const endMeasure = performanceProfiler.measureComponent('debounced-callback');
|
|
139
|
+
callback(...args);
|
|
140
|
+
endMeasure();
|
|
141
141
|
}, delay);
|
|
142
142
|
},
|
|
143
143
|
[callback, delay]
|
|
@@ -167,9 +167,9 @@ export function useThrottlePerformance<T extends (...args: any[]) => void>(
|
|
|
167
167
|
|
|
168
168
|
if (now - lastCallRef.current >= delay) {
|
|
169
169
|
lastCallRef.current = now;
|
|
170
|
-
performanceProfiler.measureComponent('throttled-callback'
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
const endMeasure = performanceProfiler.measureComponent('throttled-callback');
|
|
171
|
+
callback(...args);
|
|
172
|
+
endMeasure();
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
[callback, delay]
|
|
@@ -187,16 +187,16 @@ export function useComponentLifecycleTracking(componentName: string) {
|
|
|
187
187
|
// Component mount
|
|
188
188
|
mountTime.current = performance.now();
|
|
189
189
|
|
|
190
|
-
performanceProfiler.measureComponent(`${componentName}-mount
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
const endMountMeasure = performanceProfiler.measureComponent(`${componentName}-mount`);
|
|
191
|
+
// Measure mount time
|
|
192
|
+
endMountMeasure();
|
|
193
193
|
|
|
194
194
|
return () => {
|
|
195
195
|
// Component unmount
|
|
196
196
|
const lifetime = performance.now() - mountTime.current;
|
|
197
|
-
performanceProfiler.measureComponent(`${componentName}-unmount
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
const endUnmountMeasure = performanceProfiler.measureComponent(`${componentName}-unmount`);
|
|
198
|
+
// Record component lifetime
|
|
199
|
+
endUnmountMeasure();
|
|
200
200
|
};
|
|
201
201
|
}, [componentName]);
|
|
202
202
|
|
|
@@ -205,9 +205,9 @@ export function useComponentLifecycleTracking(componentName: string) {
|
|
|
205
205
|
updateCount.current++;
|
|
206
206
|
|
|
207
207
|
if (updateCount.current > 1) {
|
|
208
|
-
performanceProfiler.measureComponent(`${componentName}-update
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
const endUpdateMeasure = performanceProfiler.measureComponent(`${componentName}-update`);
|
|
209
|
+
// Measure update time
|
|
210
|
+
endUpdateMeasure();
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
213
|
|
|
@@ -271,9 +271,9 @@ export function useLazyImageOptimization(src: string, threshold: number = 0.1) {
|
|
|
271
271
|
|
|
272
272
|
img.onload = () => {
|
|
273
273
|
const loadTime = performance.now() - startTime;
|
|
274
|
-
performanceProfiler.measureComponent('image-load'
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
const endImageMeasure = performanceProfiler.measureComponent('image-load');
|
|
275
|
+
// Record image load time
|
|
276
|
+
endImageMeasure();
|
|
277
277
|
setIsLoaded(true);
|
|
278
278
|
};
|
|
279
279
|
|
|
@@ -12,10 +12,9 @@ interface UseScrollAnimationOptions {
|
|
|
12
12
|
export function useScrollAnimation(options: UseScrollAnimationOptions = {}) {
|
|
13
13
|
const ref = useRef<HTMLElement>(null)
|
|
14
14
|
const isInView = useInView(ref, {
|
|
15
|
-
|
|
15
|
+
amount: options.threshold || 0.1,
|
|
16
16
|
once: options.triggerOnce ?? true,
|
|
17
|
-
|
|
18
|
-
})
|
|
17
|
+
} as any)
|
|
19
18
|
|
|
20
19
|
return { ref, isInView }
|
|
21
20
|
}
|
|
@@ -106,9 +105,8 @@ export function useInfiniteScroll(
|
|
|
106
105
|
) {
|
|
107
106
|
const ref = useRef<HTMLElement>(null)
|
|
108
107
|
const isInView = useInView(ref, {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
})
|
|
108
|
+
amount: options.threshold || 0.1,
|
|
109
|
+
} as any)
|
|
112
110
|
|
|
113
111
|
useEffect(() => {
|
|
114
112
|
if (isInView) {
|
|
@@ -153,7 +151,7 @@ export function useScrollTriggeredCounter(
|
|
|
153
151
|
const ref = useRef<HTMLElement>(null)
|
|
154
152
|
|
|
155
153
|
const isInView = useInView(ref, {
|
|
156
|
-
|
|
154
|
+
amount: 0.5,
|
|
157
155
|
once: true
|
|
158
156
|
})
|
|
159
157
|
|