@exyconn/common 2.1.0 → 2.3.3

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 (142) hide show
  1. package/README.md +969 -261
  2. package/dist/client/hooks/index.d.mts +1042 -0
  3. package/dist/client/hooks/index.d.ts +1042 -0
  4. package/dist/client/hooks/index.js +2276 -0
  5. package/dist/client/hooks/index.js.map +1 -0
  6. package/dist/client/hooks/index.mjs +2217 -0
  7. package/dist/client/hooks/index.mjs.map +1 -0
  8. package/dist/client/http/index.d.mts +217 -49
  9. package/dist/client/http/index.d.ts +217 -49
  10. package/dist/client/http/index.js +473 -94
  11. package/dist/client/http/index.js.map +1 -1
  12. package/dist/client/http/index.mjs +441 -84
  13. package/dist/client/http/index.mjs.map +1 -1
  14. package/dist/client/index.d.mts +6 -4
  15. package/dist/client/index.d.ts +6 -4
  16. package/dist/client/index.js +481 -319
  17. package/dist/client/index.js.map +1 -1
  18. package/dist/client/index.mjs +449 -290
  19. package/dist/client/index.mjs.map +1 -1
  20. package/dist/client/utils/index.d.mts +3 -279
  21. package/dist/client/utils/index.d.ts +3 -279
  22. package/dist/client/web/index.d.mts +1461 -0
  23. package/dist/client/web/index.d.ts +1461 -0
  24. package/dist/client/web/index.js +2681 -0
  25. package/dist/client/web/index.js.map +1 -0
  26. package/dist/client/web/index.mjs +2618 -0
  27. package/dist/client/web/index.mjs.map +1 -0
  28. package/dist/data/brand-identity.d.mts +149 -0
  29. package/dist/data/brand-identity.d.ts +149 -0
  30. package/dist/data/brand-identity.js +235 -0
  31. package/dist/data/brand-identity.js.map +1 -0
  32. package/dist/data/brand-identity.mjs +220 -0
  33. package/dist/data/brand-identity.mjs.map +1 -0
  34. package/dist/data/countries.d.mts +61 -0
  35. package/dist/data/countries.d.ts +61 -0
  36. package/dist/data/countries.js +987 -0
  37. package/dist/data/countries.js.map +1 -0
  38. package/dist/data/countries.mjs +971 -0
  39. package/dist/data/countries.mjs.map +1 -0
  40. package/dist/data/currencies.d.mts +19 -0
  41. package/dist/data/currencies.d.ts +19 -0
  42. package/dist/data/currencies.js +162 -0
  43. package/dist/data/currencies.js.map +1 -0
  44. package/dist/data/currencies.mjs +153 -0
  45. package/dist/data/currencies.mjs.map +1 -0
  46. package/dist/data/index.d.mts +7 -0
  47. package/dist/data/index.d.ts +7 -0
  48. package/dist/data/index.js +2087 -0
  49. package/dist/data/index.js.map +1 -0
  50. package/dist/data/index.mjs +1948 -0
  51. package/dist/data/index.mjs.map +1 -0
  52. package/dist/data/phone-codes.d.mts +15 -0
  53. package/dist/data/phone-codes.d.ts +15 -0
  54. package/dist/data/phone-codes.js +219 -0
  55. package/dist/data/phone-codes.js.map +1 -0
  56. package/dist/data/phone-codes.mjs +211 -0
  57. package/dist/data/phone-codes.mjs.map +1 -0
  58. package/dist/data/regex.d.mts +287 -0
  59. package/dist/data/regex.d.ts +287 -0
  60. package/dist/data/regex.js +306 -0
  61. package/dist/data/regex.js.map +1 -0
  62. package/dist/data/regex.mjs +208 -0
  63. package/dist/data/regex.mjs.map +1 -0
  64. package/dist/data/timezones.d.mts +16 -0
  65. package/dist/data/timezones.d.ts +16 -0
  66. package/dist/data/timezones.js +98 -0
  67. package/dist/data/timezones.js.map +1 -0
  68. package/dist/data/timezones.mjs +89 -0
  69. package/dist/data/timezones.mjs.map +1 -0
  70. package/dist/index-BZf42T3R.d.mts +305 -0
  71. package/dist/index-CF0D8PGE.d.ts +305 -0
  72. package/dist/index-Ckhm_HaX.d.mts +138 -0
  73. package/dist/index-DKn4raO7.d.ts +222 -0
  74. package/dist/index-NS8dS0p9.d.mts +222 -0
  75. package/dist/index-Nqm5_lwT.d.ts +188 -0
  76. package/dist/index-br6POSyA.d.ts +138 -0
  77. package/dist/index-jBi3V6e5.d.mts +188 -0
  78. package/dist/index.d.mts +21 -580
  79. package/dist/index.d.ts +21 -580
  80. package/dist/index.js +1839 -347
  81. package/dist/index.js.map +1 -1
  82. package/dist/index.mjs +1850 -359
  83. package/dist/index.mjs.map +1 -1
  84. package/dist/packageCheck-B_qfsD6R.d.ts +280 -0
  85. package/dist/packageCheck-C2_FT_Rl.d.mts +280 -0
  86. package/dist/server/configs/index.d.mts +602 -0
  87. package/dist/server/configs/index.d.ts +602 -0
  88. package/dist/server/configs/index.js +707 -0
  89. package/dist/server/configs/index.js.map +1 -0
  90. package/dist/server/configs/index.mjs +665 -0
  91. package/dist/server/configs/index.mjs.map +1 -0
  92. package/dist/server/index.d.mts +4 -1
  93. package/dist/server/index.d.ts +4 -1
  94. package/dist/server/index.js +1330 -0
  95. package/dist/server/index.js.map +1 -1
  96. package/dist/server/index.mjs +1286 -2
  97. package/dist/server/index.mjs.map +1 -1
  98. package/dist/server/middleware/index.d.mts +283 -2
  99. package/dist/server/middleware/index.d.ts +283 -2
  100. package/dist/server/middleware/index.js +761 -0
  101. package/dist/server/middleware/index.js.map +1 -1
  102. package/dist/server/middleware/index.mjs +751 -1
  103. package/dist/server/middleware/index.mjs.map +1 -1
  104. package/dist/shared/config/index.d.mts +40 -0
  105. package/dist/shared/config/index.d.ts +40 -0
  106. package/dist/shared/config/index.js +58 -0
  107. package/dist/shared/config/index.js.map +1 -0
  108. package/dist/shared/config/index.mjs +51 -0
  109. package/dist/shared/config/index.mjs.map +1 -0
  110. package/dist/shared/constants/index.d.mts +593 -0
  111. package/dist/shared/constants/index.d.ts +593 -0
  112. package/dist/shared/constants/index.js +391 -0
  113. package/dist/shared/constants/index.js.map +1 -0
  114. package/dist/shared/constants/index.mjs +360 -0
  115. package/dist/shared/constants/index.mjs.map +1 -0
  116. package/dist/shared/index.d.mts +5 -1
  117. package/dist/shared/index.d.ts +5 -1
  118. package/dist/shared/types/index.d.mts +140 -0
  119. package/dist/shared/types/index.d.ts +140 -0
  120. package/dist/shared/types/index.js +4 -0
  121. package/dist/shared/types/index.js.map +1 -0
  122. package/dist/shared/types/index.mjs +3 -0
  123. package/dist/shared/types/index.mjs.map +1 -0
  124. package/dist/shared/utils/index.d.mts +255 -0
  125. package/dist/shared/utils/index.d.ts +255 -0
  126. package/dist/shared/utils/index.js +623 -0
  127. package/dist/shared/utils/index.js.map +1 -0
  128. package/dist/shared/utils/index.mjs +324 -0
  129. package/dist/shared/utils/index.mjs.map +1 -0
  130. package/dist/shared/validation/index.d.mts +258 -0
  131. package/dist/shared/validation/index.d.ts +258 -0
  132. package/dist/shared/validation/index.js +185 -0
  133. package/dist/shared/validation/index.js.map +1 -0
  134. package/dist/shared/validation/index.mjs +172 -0
  135. package/dist/shared/validation/index.mjs.map +1 -0
  136. package/package.json +127 -62
  137. package/dist/index-BcxL4_V4.d.ts +0 -2946
  138. package/dist/index-DEzgM15j.d.ts +0 -67
  139. package/dist/index-DNFVgQx8.d.ts +0 -1375
  140. package/dist/index-DbV04Dx8.d.mts +0 -67
  141. package/dist/index-DfqEP6Oe.d.mts +0 -1375
  142. package/dist/index-bvvCev9Q.d.mts +0 -2946
@@ -0,0 +1,2217 @@
1
+ import { useState, useCallback, useMemo, useRef, useEffect } from 'react';
2
+
3
+ // src/client/hooks/useToggle.ts
4
+ function useToggle(initialValue = false) {
5
+ const [value, setValue] = useState(initialValue);
6
+ const toggle = useCallback(() => setValue((v) => !v), []);
7
+ const setTrue = useCallback(() => setValue(true), []);
8
+ const setFalse = useCallback(() => setValue(false), []);
9
+ return {
10
+ value,
11
+ toggle,
12
+ setTrue,
13
+ setFalse,
14
+ setValue
15
+ };
16
+ }
17
+ var useToggle_default = useToggle;
18
+ function useCounter(initialValue = 0, options = {}) {
19
+ const { min = -Infinity, max = Infinity, step = 1 } = options;
20
+ const clamp = useCallback(
21
+ (value) => Math.min(Math.max(value, min), max),
22
+ [min, max]
23
+ );
24
+ const [count, setCount] = useState(clamp(initialValue));
25
+ const increment = useCallback(() => {
26
+ setCount((c) => clamp(c + step));
27
+ }, [clamp, step]);
28
+ const decrement = useCallback(() => {
29
+ setCount((c) => clamp(c - step));
30
+ }, [clamp, step]);
31
+ const set = useCallback(
32
+ (value) => {
33
+ setCount(clamp(value));
34
+ },
35
+ [clamp]
36
+ );
37
+ const reset = useCallback(() => {
38
+ setCount(clamp(initialValue));
39
+ }, [clamp, initialValue]);
40
+ return { count, increment, decrement, set, reset };
41
+ }
42
+ var useCounter_default = useCounter;
43
+ function useDefault(initialValue, defaultValue) {
44
+ const [state, setState] = useState(initialValue);
45
+ const value = useMemo(() => {
46
+ return state === null || state === void 0 ? defaultValue : state;
47
+ }, [state, defaultValue]);
48
+ const setValue = useCallback((newValue) => {
49
+ setState(newValue);
50
+ }, []);
51
+ return [value, setValue];
52
+ }
53
+ var useDefault_default = useDefault;
54
+ function usePrevious(value, initialValue) {
55
+ const ref = useRef(initialValue);
56
+ useEffect(() => {
57
+ ref.current = value;
58
+ }, [value]);
59
+ return ref.current;
60
+ }
61
+ var usePrevious_default = usePrevious;
62
+ function useObjectState(initialState) {
63
+ const [state, setStateInternal] = useState(initialState);
64
+ const setState = useCallback((update) => {
65
+ setStateInternal((prev) => {
66
+ const newState = typeof update === "function" ? update(prev) : update;
67
+ return { ...prev, ...newState };
68
+ });
69
+ }, []);
70
+ const resetState = useCallback(() => {
71
+ setStateInternal(initialState);
72
+ }, [initialState]);
73
+ const setProperty = useCallback((key, value) => {
74
+ setStateInternal((prev) => ({ ...prev, [key]: value }));
75
+ }, []);
76
+ const removeProperty = useCallback((key) => {
77
+ setStateInternal((prev) => {
78
+ const newState = { ...prev };
79
+ delete newState[key];
80
+ return newState;
81
+ });
82
+ }, []);
83
+ return { state, setState, resetState, setProperty, removeProperty };
84
+ }
85
+ var useObjectState_default = useObjectState;
86
+ function useHistoryState(initialValue, options = {}) {
87
+ const { maxLength = 100 } = options;
88
+ const [history, setHistory] = useState([initialValue]);
89
+ const [pointer, setPointer] = useState(0);
90
+ const state = useMemo(() => history[pointer], [history, pointer]);
91
+ const setState = useCallback(
92
+ (value) => {
93
+ setHistory((prev) => {
94
+ const currentValue = prev[pointer];
95
+ const newValue = typeof value === "function" ? value(currentValue) : value;
96
+ const newHistory = prev.slice(0, pointer + 1);
97
+ newHistory.push(newValue);
98
+ if (newHistory.length > maxLength) {
99
+ newHistory.shift();
100
+ return newHistory;
101
+ }
102
+ return newHistory;
103
+ });
104
+ setPointer((prev) => Math.min(prev + 1, maxLength - 1));
105
+ },
106
+ [pointer, maxLength]
107
+ );
108
+ const undo = useCallback(() => {
109
+ setPointer((prev) => Math.max(0, prev - 1));
110
+ }, []);
111
+ const redo = useCallback(() => {
112
+ setPointer((prev) => Math.min(history.length - 1, prev + 1));
113
+ }, [history.length]);
114
+ const go = useCallback(
115
+ (index) => {
116
+ const targetIndex = Math.max(0, Math.min(history.length - 1, index));
117
+ setPointer(targetIndex);
118
+ },
119
+ [history.length]
120
+ );
121
+ const clear = useCallback(
122
+ (value) => {
123
+ const resetValue = value ?? initialValue;
124
+ setHistory([resetValue]);
125
+ setPointer(0);
126
+ },
127
+ [initialValue]
128
+ );
129
+ const canUndo = pointer > 0;
130
+ const canRedo = pointer < history.length - 1;
131
+ return {
132
+ state,
133
+ setState,
134
+ undo,
135
+ redo,
136
+ clear,
137
+ canUndo,
138
+ canRedo,
139
+ history,
140
+ pointer,
141
+ go
142
+ };
143
+ }
144
+ var useHistoryState_default = useHistoryState;
145
+ function useQueue(initialValue = []) {
146
+ const [queue, setQueue] = useState(initialValue);
147
+ const enqueue = useCallback((item) => {
148
+ setQueue((prev) => [...prev, item]);
149
+ }, []);
150
+ const enqueueAll = useCallback((items) => {
151
+ setQueue((prev) => [...prev, ...items]);
152
+ }, []);
153
+ const dequeue = useCallback(() => {
154
+ let dequeuedItem;
155
+ setQueue((prev) => {
156
+ if (prev.length === 0) return prev;
157
+ dequeuedItem = prev[0];
158
+ return prev.slice(1);
159
+ });
160
+ return dequeuedItem;
161
+ }, []);
162
+ const peek = useCallback(() => {
163
+ return queue[0];
164
+ }, [queue]);
165
+ const clear = useCallback(() => {
166
+ setQueue([]);
167
+ }, []);
168
+ const size = queue.length;
169
+ const isEmpty = size === 0;
170
+ const first = queue[0];
171
+ const last = queue[queue.length - 1];
172
+ return {
173
+ queue,
174
+ enqueue,
175
+ enqueueAll,
176
+ dequeue,
177
+ peek,
178
+ clear,
179
+ size,
180
+ isEmpty,
181
+ first,
182
+ last
183
+ };
184
+ }
185
+ var useQueue_default = useQueue;
186
+ function useList(initialValue = []) {
187
+ const [list, setList] = useState(initialValue);
188
+ const set = useCallback((newList) => {
189
+ setList(newList);
190
+ }, []);
191
+ const push = useCallback((item) => {
192
+ setList((prev) => [...prev, item]);
193
+ }, []);
194
+ const unshift = useCallback((item) => {
195
+ setList((prev) => [item, ...prev]);
196
+ }, []);
197
+ const removeAt = useCallback((index) => {
198
+ setList((prev) => prev.filter((_, i) => i !== index));
199
+ }, []);
200
+ const remove = useCallback((item) => {
201
+ setList((prev) => {
202
+ const index = prev.indexOf(item);
203
+ if (index === -1) return prev;
204
+ return prev.filter((_, i) => i !== index);
205
+ });
206
+ }, []);
207
+ const removeWhere = useCallback((predicate) => {
208
+ setList((prev) => prev.filter((item) => !predicate(item)));
209
+ }, []);
210
+ const updateAt = useCallback((index, item) => {
211
+ setList((prev) => prev.map((v, i) => i === index ? item : v));
212
+ }, []);
213
+ const updateWhere = useCallback(
214
+ (predicate, updater) => {
215
+ setList((prev) => prev.map((item) => predicate(item) ? updater(item) : item));
216
+ },
217
+ []
218
+ );
219
+ const insertAt = useCallback((index, item) => {
220
+ setList((prev) => [...prev.slice(0, index), item, ...prev.slice(index)]);
221
+ }, []);
222
+ const move = useCallback((fromIndex, toIndex) => {
223
+ setList((prev) => {
224
+ const newList = [...prev];
225
+ const [item] = newList.splice(fromIndex, 1);
226
+ newList.splice(toIndex, 0, item);
227
+ return newList;
228
+ });
229
+ }, []);
230
+ const clear = useCallback(() => {
231
+ setList([]);
232
+ }, []);
233
+ const reset = useCallback(() => {
234
+ setList(initialValue);
235
+ }, [initialValue]);
236
+ const filter = useCallback((predicate) => {
237
+ setList((prev) => prev.filter(predicate));
238
+ }, []);
239
+ const sort = useCallback((compareFn) => {
240
+ setList((prev) => [...prev].sort(compareFn));
241
+ }, []);
242
+ const reverse = useCallback(() => {
243
+ setList((prev) => [...prev].reverse());
244
+ }, []);
245
+ const size = list.length;
246
+ const isEmpty = size === 0;
247
+ const first = list[0];
248
+ const last = list[list.length - 1];
249
+ return {
250
+ list,
251
+ set,
252
+ push,
253
+ unshift,
254
+ removeAt,
255
+ remove,
256
+ removeWhere,
257
+ updateAt,
258
+ updateWhere,
259
+ insertAt,
260
+ move,
261
+ clear,
262
+ reset,
263
+ filter,
264
+ sort,
265
+ reverse,
266
+ size,
267
+ isEmpty,
268
+ first,
269
+ last
270
+ };
271
+ }
272
+ var useList_default = useList;
273
+ function useMap(initialValue = []) {
274
+ const [map, setMap] = useState(() => new Map(initialValue));
275
+ const get = useCallback((key) => {
276
+ return map.get(key);
277
+ }, [map]);
278
+ const set = useCallback((key, value) => {
279
+ setMap((prev) => {
280
+ const newMap = new Map(prev);
281
+ newMap.set(key, value);
282
+ return newMap;
283
+ });
284
+ }, []);
285
+ const setAll = useCallback((entries2) => {
286
+ setMap((prev) => {
287
+ const newMap = new Map(prev);
288
+ for (const [key, value] of entries2) {
289
+ newMap.set(key, value);
290
+ }
291
+ return newMap;
292
+ });
293
+ }, []);
294
+ const has = useCallback((key) => {
295
+ return map.has(key);
296
+ }, [map]);
297
+ const remove = useCallback((key) => {
298
+ setMap((prev) => {
299
+ const newMap = new Map(prev);
300
+ newMap.delete(key);
301
+ return newMap;
302
+ });
303
+ }, []);
304
+ const removeAll = useCallback((keys2) => {
305
+ setMap((prev) => {
306
+ const newMap = new Map(prev);
307
+ keys2.forEach((key) => newMap.delete(key));
308
+ return newMap;
309
+ });
310
+ }, []);
311
+ const clear = useCallback(() => {
312
+ setMap(/* @__PURE__ */ new Map());
313
+ }, []);
314
+ const reset = useCallback(() => {
315
+ setMap(new Map(initialValue));
316
+ }, [initialValue]);
317
+ const size = map.size;
318
+ const keys = useMemo(() => Array.from(map.keys()), [map]);
319
+ const values = useMemo(() => Array.from(map.values()), [map]);
320
+ const entries = useMemo(() => Array.from(map.entries()), [map]);
321
+ const isEmpty = size === 0;
322
+ return {
323
+ map,
324
+ get,
325
+ set,
326
+ setAll,
327
+ has,
328
+ remove,
329
+ removeAll,
330
+ clear,
331
+ reset,
332
+ size,
333
+ keys,
334
+ values,
335
+ entries,
336
+ isEmpty
337
+ };
338
+ }
339
+ var useMap_default = useMap;
340
+ function useSet(initialValue = []) {
341
+ const [set, setSet] = useState(() => new Set(initialValue));
342
+ const add = useCallback((item) => {
343
+ setSet((prev) => /* @__PURE__ */ new Set([...prev, item]));
344
+ }, []);
345
+ const addAll = useCallback((items) => {
346
+ setSet((prev) => /* @__PURE__ */ new Set([...prev, ...items]));
347
+ }, []);
348
+ const has = useCallback((item) => {
349
+ return set.has(item);
350
+ }, [set]);
351
+ const remove = useCallback((item) => {
352
+ setSet((prev) => {
353
+ const newSet = new Set(prev);
354
+ newSet.delete(item);
355
+ return newSet;
356
+ });
357
+ }, []);
358
+ const removeAll = useCallback((items) => {
359
+ setSet((prev) => {
360
+ const newSet = new Set(prev);
361
+ for (const item of items) {
362
+ newSet.delete(item);
363
+ }
364
+ return newSet;
365
+ });
366
+ }, []);
367
+ const toggle = useCallback((item) => {
368
+ setSet((prev) => {
369
+ const newSet = new Set(prev);
370
+ if (newSet.has(item)) {
371
+ newSet.delete(item);
372
+ } else {
373
+ newSet.add(item);
374
+ }
375
+ return newSet;
376
+ });
377
+ }, []);
378
+ const clear = useCallback(() => {
379
+ setSet(/* @__PURE__ */ new Set());
380
+ }, []);
381
+ const reset = useCallback(() => {
382
+ setSet(new Set(initialValue));
383
+ }, [initialValue]);
384
+ const size = set.size;
385
+ const values = useMemo(() => Array.from(set), [set]);
386
+ const isEmpty = size === 0;
387
+ return {
388
+ set,
389
+ add,
390
+ addAll,
391
+ has,
392
+ remove,
393
+ removeAll,
394
+ toggle,
395
+ clear,
396
+ reset,
397
+ size,
398
+ values,
399
+ isEmpty
400
+ };
401
+ }
402
+ var useSet_default = useSet;
403
+ function useDebounce(value, delay = 500) {
404
+ const [debouncedValue, setDebouncedValue] = useState(value);
405
+ useEffect(() => {
406
+ const timer = setTimeout(() => {
407
+ setDebouncedValue(value);
408
+ }, delay);
409
+ return () => {
410
+ clearTimeout(timer);
411
+ };
412
+ }, [value, delay]);
413
+ return debouncedValue;
414
+ }
415
+ var useDebounce_default = useDebounce;
416
+ function useThrottle(value, interval = 500) {
417
+ const [throttledValue, setThrottledValue] = useState(value);
418
+ const lastUpdated = useRef(Date.now());
419
+ useEffect(() => {
420
+ const now = Date.now();
421
+ const timeSinceLastUpdate = now - lastUpdated.current;
422
+ if (timeSinceLastUpdate >= interval) {
423
+ lastUpdated.current = now;
424
+ setThrottledValue(value);
425
+ return;
426
+ } else {
427
+ const timeoutId = setTimeout(() => {
428
+ lastUpdated.current = Date.now();
429
+ setThrottledValue(value);
430
+ }, interval - timeSinceLastUpdate);
431
+ return () => clearTimeout(timeoutId);
432
+ }
433
+ }, [value, interval]);
434
+ return throttledValue;
435
+ }
436
+ var useThrottle_default = useThrottle;
437
+ function useTimeout(callback, delay) {
438
+ const savedCallback = useRef(callback);
439
+ const timeoutId = useRef(null);
440
+ useEffect(() => {
441
+ savedCallback.current = callback;
442
+ }, [callback]);
443
+ const clear = useCallback(() => {
444
+ if (timeoutId.current) {
445
+ clearTimeout(timeoutId.current);
446
+ timeoutId.current = null;
447
+ }
448
+ }, []);
449
+ const reset = useCallback(() => {
450
+ clear();
451
+ if (delay !== null) {
452
+ timeoutId.current = setTimeout(() => {
453
+ savedCallback.current();
454
+ }, delay);
455
+ }
456
+ }, [delay, clear]);
457
+ useEffect(() => {
458
+ if (delay === null) {
459
+ return;
460
+ }
461
+ timeoutId.current = setTimeout(() => {
462
+ savedCallback.current();
463
+ }, delay);
464
+ return clear;
465
+ }, [delay, clear]);
466
+ return { reset, clear };
467
+ }
468
+ var useTimeout_default = useTimeout;
469
+ function useInterval(callback, delay) {
470
+ const savedCallback = useRef(callback);
471
+ useEffect(() => {
472
+ savedCallback.current = callback;
473
+ }, [callback]);
474
+ useEffect(() => {
475
+ if (delay === null) {
476
+ return;
477
+ }
478
+ const tick = () => savedCallback.current();
479
+ const id = setInterval(tick, delay);
480
+ return () => clearInterval(id);
481
+ }, [delay]);
482
+ }
483
+ var useInterval_default = useInterval;
484
+ function useIntervalWhen(callback, delay, when, immediate = false) {
485
+ const savedCallback = useRef(callback);
486
+ const hasRunImmediate = useRef(false);
487
+ useEffect(() => {
488
+ savedCallback.current = callback;
489
+ }, [callback]);
490
+ useEffect(() => {
491
+ if (!when) {
492
+ hasRunImmediate.current = false;
493
+ return;
494
+ }
495
+ if (immediate && !hasRunImmediate.current) {
496
+ hasRunImmediate.current = true;
497
+ savedCallback.current();
498
+ }
499
+ const id = setInterval(() => {
500
+ savedCallback.current();
501
+ }, delay);
502
+ return () => clearInterval(id);
503
+ }, [delay, when, immediate]);
504
+ }
505
+ var useIntervalWhen_default = useIntervalWhen;
506
+ function useRandomInterval(callback, minDelay, maxDelay, enabled = true) {
507
+ const savedCallback = useRef(callback);
508
+ const timeoutId = useRef(null);
509
+ useEffect(() => {
510
+ savedCallback.current = callback;
511
+ }, [callback]);
512
+ const getRandomDelay = useCallback(() => {
513
+ return Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay;
514
+ }, [minDelay, maxDelay]);
515
+ useEffect(() => {
516
+ if (!enabled) {
517
+ return;
518
+ }
519
+ const tick = () => {
520
+ savedCallback.current();
521
+ timeoutId.current = setTimeout(tick, getRandomDelay());
522
+ };
523
+ timeoutId.current = setTimeout(tick, getRandomDelay());
524
+ return () => {
525
+ if (timeoutId.current) {
526
+ clearTimeout(timeoutId.current);
527
+ }
528
+ };
529
+ }, [enabled, getRandomDelay]);
530
+ }
531
+ var useRandomInterval_default = useRandomInterval;
532
+ function useCountdown(initialCount, options = {}) {
533
+ const { interval = 1e3, onComplete, autoStart = false } = options;
534
+ const [count, setCount] = useState(initialCount);
535
+ const [isRunning, setIsRunning] = useState(autoStart);
536
+ const intervalRef = useRef(null);
537
+ const onCompleteRef = useRef(onComplete);
538
+ useEffect(() => {
539
+ onCompleteRef.current = onComplete;
540
+ }, [onComplete]);
541
+ const isComplete = count <= 0;
542
+ const clear = useCallback(() => {
543
+ if (intervalRef.current) {
544
+ clearInterval(intervalRef.current);
545
+ intervalRef.current = null;
546
+ }
547
+ }, []);
548
+ const start = useCallback(() => {
549
+ if (count <= 0) return;
550
+ setIsRunning(true);
551
+ }, [count]);
552
+ const pause = useCallback(() => {
553
+ setIsRunning(false);
554
+ clear();
555
+ }, [clear]);
556
+ const resume = useCallback(() => {
557
+ if (count > 0) {
558
+ setIsRunning(true);
559
+ }
560
+ }, [count]);
561
+ const reset = useCallback(
562
+ (newCount) => {
563
+ clear();
564
+ setCount(newCount ?? initialCount);
565
+ setIsRunning(false);
566
+ },
567
+ [clear, initialCount]
568
+ );
569
+ useEffect(() => {
570
+ if (!isRunning || count <= 0) {
571
+ clear();
572
+ return;
573
+ }
574
+ intervalRef.current = setInterval(() => {
575
+ setCount((prev) => {
576
+ const newCount = prev - interval;
577
+ if (newCount <= 0) {
578
+ setIsRunning(false);
579
+ onCompleteRef.current?.();
580
+ return 0;
581
+ }
582
+ return newCount;
583
+ });
584
+ }, interval);
585
+ return clear;
586
+ }, [isRunning, interval, clear, count]);
587
+ const formatted = {
588
+ days: Math.floor(count / (1e3 * 60 * 60 * 24)),
589
+ hours: Math.floor(count % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)),
590
+ minutes: Math.floor(count % (1e3 * 60 * 60) / (1e3 * 60)),
591
+ seconds: Math.floor(count % (1e3 * 60) / 1e3)
592
+ };
593
+ return {
594
+ count,
595
+ start,
596
+ pause,
597
+ resume,
598
+ reset,
599
+ isRunning,
600
+ isComplete,
601
+ formatted
602
+ };
603
+ }
604
+ var useCountdown_default = useCountdown;
605
+ function useContinuousRetry(callback, options = {}) {
606
+ const {
607
+ maxAttempts = Infinity,
608
+ delay = 1e3,
609
+ exponentialBackoff = false,
610
+ maxDelay = 3e4,
611
+ autoStart = true
612
+ } = options;
613
+ const [attempts, setAttempts] = useState(0);
614
+ const [error, setError] = useState(null);
615
+ const [isRetrying, setIsRetrying] = useState(autoStart);
616
+ const [isSuccess, setIsSuccess] = useState(false);
617
+ const callbackRef = useRef(callback);
618
+ const timeoutRef = useRef(null);
619
+ useEffect(() => {
620
+ callbackRef.current = callback;
621
+ }, [callback]);
622
+ const isMaxAttempts = attempts >= maxAttempts;
623
+ const calculateDelay = useCallback(
624
+ (attempt) => {
625
+ if (!exponentialBackoff) return delay;
626
+ const exponentialDelay = delay * Math.pow(2, attempt);
627
+ return Math.min(exponentialDelay, maxDelay);
628
+ },
629
+ [delay, exponentialBackoff, maxDelay]
630
+ );
631
+ const clear = useCallback(() => {
632
+ if (timeoutRef.current) {
633
+ clearTimeout(timeoutRef.current);
634
+ timeoutRef.current = null;
635
+ }
636
+ }, []);
637
+ const stop = useCallback(() => {
638
+ clear();
639
+ setIsRetrying(false);
640
+ }, [clear]);
641
+ const reset = useCallback(() => {
642
+ clear();
643
+ setAttempts(0);
644
+ setError(null);
645
+ setIsRetrying(false);
646
+ setIsSuccess(false);
647
+ }, [clear]);
648
+ const start = useCallback(() => {
649
+ reset();
650
+ setIsRetrying(true);
651
+ }, [reset]);
652
+ useEffect(() => {
653
+ if (!isRetrying || isSuccess || isMaxAttempts) {
654
+ return;
655
+ }
656
+ const attemptCallback = async () => {
657
+ try {
658
+ setAttempts((prev) => prev + 1);
659
+ const result = await callbackRef.current();
660
+ if (result) {
661
+ setIsSuccess(true);
662
+ setIsRetrying(false);
663
+ } else {
664
+ const currentDelay = calculateDelay(attempts);
665
+ timeoutRef.current = setTimeout(attemptCallback, currentDelay);
666
+ }
667
+ } catch (err) {
668
+ setError(err instanceof Error ? err : new Error(String(err)));
669
+ const currentDelay = calculateDelay(attempts);
670
+ timeoutRef.current = setTimeout(attemptCallback, currentDelay);
671
+ }
672
+ };
673
+ if (attempts === 0) {
674
+ attemptCallback();
675
+ }
676
+ return clear;
677
+ }, [isRetrying, isSuccess, isMaxAttempts, attempts, calculateDelay, clear]);
678
+ return {
679
+ attempts,
680
+ error,
681
+ isRetrying,
682
+ isSuccess,
683
+ isMaxAttempts,
684
+ start,
685
+ stop,
686
+ reset
687
+ };
688
+ }
689
+ var useContinuousRetry_default = useContinuousRetry;
690
+ function useWindowSize(debounceMs = 100) {
691
+ const getSize = () => ({
692
+ width: typeof window !== "undefined" ? window.innerWidth : 0,
693
+ height: typeof window !== "undefined" ? window.innerHeight : 0
694
+ });
695
+ const [windowSize, setWindowSize] = useState(getSize);
696
+ useEffect(() => {
697
+ if (typeof window === "undefined") return;
698
+ let timeoutId;
699
+ const handleResize = () => {
700
+ clearTimeout(timeoutId);
701
+ timeoutId = setTimeout(() => {
702
+ setWindowSize(getSize());
703
+ }, debounceMs);
704
+ };
705
+ setWindowSize(getSize());
706
+ window.addEventListener("resize", handleResize);
707
+ return () => {
708
+ clearTimeout(timeoutId);
709
+ window.removeEventListener("resize", handleResize);
710
+ };
711
+ }, [debounceMs]);
712
+ return windowSize;
713
+ }
714
+ var useWindowSize_default = useWindowSize;
715
+ function useWindowScroll() {
716
+ const [scroll, setScroll] = useState({
717
+ x: typeof window !== "undefined" ? window.scrollX : 0,
718
+ y: typeof window !== "undefined" ? window.scrollY : 0,
719
+ direction: null,
720
+ isScrolling: false
721
+ });
722
+ useEffect(() => {
723
+ if (typeof window === "undefined") return;
724
+ let prevX = window.scrollX;
725
+ let prevY = window.scrollY;
726
+ let scrollTimeout;
727
+ const handleScroll = () => {
728
+ const x = window.scrollX;
729
+ const y = window.scrollY;
730
+ let direction = null;
731
+ if (y > prevY) direction = "down";
732
+ else if (y < prevY) direction = "up";
733
+ else if (x > prevX) direction = "right";
734
+ else if (x < prevX) direction = "left";
735
+ prevX = x;
736
+ prevY = y;
737
+ setScroll({ x, y, direction, isScrolling: true });
738
+ clearTimeout(scrollTimeout);
739
+ scrollTimeout = setTimeout(() => {
740
+ setScroll((prev) => ({ ...prev, isScrolling: false }));
741
+ }, 150);
742
+ };
743
+ window.addEventListener("scroll", handleScroll, { passive: true });
744
+ return () => {
745
+ window.removeEventListener("scroll", handleScroll);
746
+ clearTimeout(scrollTimeout);
747
+ };
748
+ }, []);
749
+ const scrollTo = useCallback((options) => {
750
+ if (typeof window !== "undefined") {
751
+ window.scrollTo(options);
752
+ }
753
+ }, []);
754
+ const scrollToTop = useCallback((behavior = "smooth") => {
755
+ if (typeof window !== "undefined") {
756
+ window.scrollTo({ top: 0, behavior });
757
+ }
758
+ }, []);
759
+ const scrollToBottom = useCallback((behavior = "smooth") => {
760
+ if (typeof window !== "undefined") {
761
+ window.scrollTo({
762
+ top: document.documentElement.scrollHeight,
763
+ behavior
764
+ });
765
+ }
766
+ }, []);
767
+ return {
768
+ ...scroll,
769
+ scrollTo,
770
+ scrollToTop,
771
+ scrollToBottom
772
+ };
773
+ }
774
+ var useWindowScroll_default = useWindowScroll;
775
+ function useDocumentTitle(title, options = {}) {
776
+ const { restoreOnUnmount = true, template } = options;
777
+ const previousTitle = useRef(null);
778
+ useEffect(() => {
779
+ if (typeof document === "undefined") return;
780
+ if (previousTitle.current === null) {
781
+ previousTitle.current = document.title;
782
+ }
783
+ const finalTitle = template ? template.replace("%s", title) : title;
784
+ document.title = finalTitle;
785
+ return () => {
786
+ if (restoreOnUnmount && previousTitle.current !== null) {
787
+ document.title = previousTitle.current;
788
+ }
789
+ };
790
+ }, [title, template, restoreOnUnmount]);
791
+ }
792
+ var useDocumentTitle_default = useDocumentTitle;
793
+ function usePageTitle(title, options = {}) {
794
+ const { suffix, separator = " | ", restoreOnUnmount = true } = options;
795
+ useEffect(() => {
796
+ const originalTitle = document.title;
797
+ const newTitle = suffix ? `${title}${separator}${suffix}` : title;
798
+ document.title = newTitle;
799
+ return () => {
800
+ if (restoreOnUnmount) {
801
+ document.title = originalTitle;
802
+ }
803
+ };
804
+ }, [title, suffix, separator, restoreOnUnmount]);
805
+ }
806
+ var usePageTitle_default = usePageTitle;
807
+ function useFavicon(href, restoreOnUnmount = true) {
808
+ const originalHref = useRef(null);
809
+ useEffect(() => {
810
+ if (typeof document === "undefined") return;
811
+ const link = document.querySelector("link[rel*='icon']") || document.createElement("link");
812
+ if (originalHref.current === null) {
813
+ originalHref.current = link.href;
814
+ }
815
+ link.type = "image/x-icon";
816
+ link.rel = "shortcut icon";
817
+ link.href = href;
818
+ document.head.appendChild(link);
819
+ return () => {
820
+ if (restoreOnUnmount && originalHref.current) {
821
+ link.href = originalHref.current;
822
+ }
823
+ };
824
+ }, [href, restoreOnUnmount]);
825
+ }
826
+ var useFavicon_default = useFavicon;
827
+ function useVisibilityChange(onVisibilityChange) {
828
+ const [state, setState] = useState(() => ({
829
+ isVisible: typeof document !== "undefined" ? !document.hidden : true,
830
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : "visible",
831
+ lastChanged: null
832
+ }));
833
+ const handleVisibilityChange = useCallback(() => {
834
+ const isVisible = !document.hidden;
835
+ const visibilityState = document.visibilityState;
836
+ setState({
837
+ isVisible,
838
+ visibilityState,
839
+ lastChanged: /* @__PURE__ */ new Date()
840
+ });
841
+ onVisibilityChange?.(isVisible);
842
+ }, [onVisibilityChange]);
843
+ useEffect(() => {
844
+ if (typeof document === "undefined") return;
845
+ document.addEventListener("visibilitychange", handleVisibilityChange);
846
+ return () => {
847
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
848
+ };
849
+ }, [handleVisibilityChange]);
850
+ return state;
851
+ }
852
+ var useVisibilityChange_default = useVisibilityChange;
853
+ function usePageLeave(onLeave, options = {}) {
854
+ const { showConfirmation = false, confirmationMessage = "" } = options;
855
+ const onLeaveRef = useRef(onLeave);
856
+ useEffect(() => {
857
+ onLeaveRef.current = onLeave;
858
+ }, [onLeave]);
859
+ const handleMouseLeave = useCallback((e) => {
860
+ if (e.clientY <= 0) {
861
+ onLeaveRef.current?.();
862
+ }
863
+ }, []);
864
+ const handleBeforeUnload = useCallback(
865
+ (e) => {
866
+ onLeaveRef.current?.();
867
+ if (showConfirmation) {
868
+ e.preventDefault();
869
+ e.returnValue = confirmationMessage;
870
+ return confirmationMessage;
871
+ }
872
+ },
873
+ [showConfirmation, confirmationMessage]
874
+ );
875
+ useEffect(() => {
876
+ if (typeof window === "undefined") return;
877
+ document.addEventListener("mouseleave", handleMouseLeave);
878
+ window.addEventListener("beforeunload", handleBeforeUnload);
879
+ return () => {
880
+ document.removeEventListener("mouseleave", handleMouseLeave);
881
+ window.removeEventListener("beforeunload", handleBeforeUnload);
882
+ };
883
+ }, [handleMouseLeave, handleBeforeUnload]);
884
+ }
885
+ var usePageLeave_default = usePageLeave;
886
+ function useLockBodyScroll(locked = true) {
887
+ useEffect(() => {
888
+ if (typeof document === "undefined" || !locked) return;
889
+ const originalStyle = window.getComputedStyle(document.body).overflow;
890
+ const originalPaddingRight = window.getComputedStyle(document.body).paddingRight;
891
+ const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
892
+ document.body.style.overflow = "hidden";
893
+ if (scrollbarWidth > 0) {
894
+ document.body.style.paddingRight = `${scrollbarWidth}px`;
895
+ }
896
+ return () => {
897
+ document.body.style.overflow = originalStyle;
898
+ document.body.style.paddingRight = originalPaddingRight;
899
+ };
900
+ }, [locked]);
901
+ }
902
+ var useLockBodyScroll_default = useLockBodyScroll;
903
+ function useIsClient() {
904
+ const [isClient, setIsClient] = useState(false);
905
+ useEffect(() => {
906
+ setIsClient(true);
907
+ }, []);
908
+ return isClient;
909
+ }
910
+ var useIsClient_default = useIsClient;
911
+ function useIsFirstRender() {
912
+ const isFirst = useRef(true);
913
+ if (isFirst.current) {
914
+ isFirst.current = false;
915
+ return true;
916
+ }
917
+ return isFirst.current;
918
+ }
919
+ var useIsFirstRender_default = useIsFirstRender;
920
+ function useEventListener(eventName, handler, element, options) {
921
+ const savedHandler = useRef(handler);
922
+ useEffect(() => {
923
+ savedHandler.current = handler;
924
+ }, [handler]);
925
+ useEffect(() => {
926
+ const targetElement = element ?? (typeof window !== "undefined" ? window : null);
927
+ if (!targetElement?.addEventListener) {
928
+ return;
929
+ }
930
+ const eventListener = (event) => {
931
+ savedHandler.current(event);
932
+ };
933
+ targetElement.addEventListener(eventName, eventListener, options);
934
+ return () => {
935
+ targetElement.removeEventListener(eventName, eventListener, options);
936
+ };
937
+ }, [eventName, element, options]);
938
+ }
939
+ var useEventListener_default = useEventListener;
940
+ function useKeyPress(targetKey, callback, options = {}) {
941
+ const {
942
+ target,
943
+ event: eventType = "keydown",
944
+ preventDefault = false,
945
+ stopPropagation = false
946
+ } = options;
947
+ const [pressed, setPressed] = useState(false);
948
+ const [event, setEvent] = useState(null);
949
+ const keys = Array.isArray(targetKey) ? targetKey : [targetKey];
950
+ const downHandler = useCallback(
951
+ (e) => {
952
+ if (keys.includes(e.key)) {
953
+ if (preventDefault) e.preventDefault();
954
+ if (stopPropagation) e.stopPropagation();
955
+ setPressed(true);
956
+ setEvent(e);
957
+ callback?.(e);
958
+ }
959
+ },
960
+ [keys, callback, preventDefault, stopPropagation]
961
+ );
962
+ const upHandler = useCallback(
963
+ (e) => {
964
+ if (keys.includes(e.key)) {
965
+ setPressed(false);
966
+ }
967
+ },
968
+ [keys]
969
+ );
970
+ useEffect(() => {
971
+ const targetElement = target ?? (typeof document !== "undefined" ? document : null);
972
+ if (!targetElement) return;
973
+ targetElement.addEventListener(eventType, downHandler);
974
+ targetElement.addEventListener("keyup", upHandler);
975
+ return () => {
976
+ targetElement.removeEventListener(eventType, downHandler);
977
+ targetElement.removeEventListener("keyup", upHandler);
978
+ };
979
+ }, [target, eventType, downHandler, upHandler]);
980
+ return { pressed, event };
981
+ }
982
+ var useKeyPress_default = useKeyPress;
983
+ function useHover(onHoverChange) {
984
+ const [isHovered, setIsHovered] = useState(false);
985
+ const ref = useRef(null);
986
+ const onMouseEnter = useCallback(() => {
987
+ setIsHovered(true);
988
+ onHoverChange?.(true);
989
+ }, [onHoverChange]);
990
+ const onMouseLeave = useCallback(() => {
991
+ setIsHovered(false);
992
+ onHoverChange?.(false);
993
+ }, [onHoverChange]);
994
+ return {
995
+ ref,
996
+ isHovered,
997
+ bind: {
998
+ onMouseEnter,
999
+ onMouseLeave
1000
+ }
1001
+ };
1002
+ }
1003
+ var useHover_default = useHover;
1004
+ function useClickAway(callback, events = ["mousedown", "touchstart"]) {
1005
+ const ref = useRef(null);
1006
+ const savedCallback = useRef(callback);
1007
+ useEffect(() => {
1008
+ savedCallback.current = callback;
1009
+ }, [callback]);
1010
+ const handleClickAway = useCallback((event) => {
1011
+ const el = ref.current;
1012
+ if (!el || el.contains(event.target)) {
1013
+ return;
1014
+ }
1015
+ savedCallback.current(event);
1016
+ }, []);
1017
+ useEffect(() => {
1018
+ if (typeof document === "undefined") return;
1019
+ events.forEach((eventType) => {
1020
+ document.addEventListener(eventType, handleClickAway);
1021
+ });
1022
+ return () => {
1023
+ events.forEach((eventType) => {
1024
+ document.removeEventListener(eventType, handleClickAway);
1025
+ });
1026
+ };
1027
+ }, [events, handleClickAway]);
1028
+ return ref;
1029
+ }
1030
+ var useClickAway_default = useClickAway;
1031
+ function useOnClickOutside(ref, handler, enabled = true) {
1032
+ useEffect(() => {
1033
+ if (!enabled) return;
1034
+ const listener = (event) => {
1035
+ const el = ref?.current;
1036
+ if (!el || el.contains(event.target)) {
1037
+ return;
1038
+ }
1039
+ handler(event);
1040
+ };
1041
+ document.addEventListener("mousedown", listener);
1042
+ document.addEventListener("touchstart", listener);
1043
+ return () => {
1044
+ document.removeEventListener("mousedown", listener);
1045
+ document.removeEventListener("touchstart", listener);
1046
+ };
1047
+ }, [ref, handler, enabled]);
1048
+ }
1049
+ var useOnClickOutside_default = useOnClickOutside;
1050
+ function useLongPress(options = {}) {
1051
+ const {
1052
+ threshold = 400,
1053
+ onLongPress,
1054
+ onClick,
1055
+ onStart,
1056
+ onFinish,
1057
+ onCancel
1058
+ } = options;
1059
+ const [isPressed, setIsPressed] = useState(false);
1060
+ const [isLongPress, setIsLongPress] = useState(false);
1061
+ const timerRef = useRef(null);
1062
+ const isLongPressRef = useRef(false);
1063
+ const start = useCallback(
1064
+ (event) => {
1065
+ setIsPressed(true);
1066
+ setIsLongPress(false);
1067
+ isLongPressRef.current = false;
1068
+ onStart?.(event);
1069
+ timerRef.current = setTimeout(() => {
1070
+ isLongPressRef.current = true;
1071
+ setIsLongPress(true);
1072
+ onLongPress?.(event);
1073
+ }, threshold);
1074
+ },
1075
+ [threshold, onLongPress, onStart]
1076
+ );
1077
+ const cancel = useCallback(
1078
+ (event) => {
1079
+ setIsPressed(false);
1080
+ if (timerRef.current) {
1081
+ clearTimeout(timerRef.current);
1082
+ timerRef.current = null;
1083
+ }
1084
+ if (!isLongPressRef.current) {
1085
+ onCancel?.(event);
1086
+ }
1087
+ },
1088
+ [onCancel]
1089
+ );
1090
+ const end = useCallback(
1091
+ (event) => {
1092
+ setIsPressed(false);
1093
+ if (timerRef.current) {
1094
+ clearTimeout(timerRef.current);
1095
+ timerRef.current = null;
1096
+ }
1097
+ if (isLongPressRef.current) {
1098
+ onFinish?.(event);
1099
+ } else {
1100
+ onClick?.(event);
1101
+ }
1102
+ },
1103
+ [onClick, onFinish]
1104
+ );
1105
+ return {
1106
+ isPressed,
1107
+ isLongPress,
1108
+ bind: {
1109
+ onMouseDown: start,
1110
+ onMouseUp: end,
1111
+ onMouseLeave: cancel,
1112
+ onTouchStart: start,
1113
+ onTouchEnd: end
1114
+ }
1115
+ };
1116
+ }
1117
+ var useLongPress_default = useLongPress;
1118
+ function useMouse(options = {}) {
1119
+ const { enabled = true } = options;
1120
+ const ref = useRef(null);
1121
+ const [position, setPosition] = useState({
1122
+ x: 0,
1123
+ y: 0,
1124
+ pageX: 0,
1125
+ pageY: 0,
1126
+ elementX: 0,
1127
+ elementY: 0,
1128
+ isInElement: false
1129
+ });
1130
+ const handleMouseMove = useCallback((event) => {
1131
+ let elementX = 0;
1132
+ let elementY = 0;
1133
+ let isInElement = false;
1134
+ if (ref.current) {
1135
+ const rect = ref.current.getBoundingClientRect();
1136
+ elementX = event.clientX - rect.left;
1137
+ elementY = event.clientY - rect.top;
1138
+ isInElement = elementX >= 0 && elementX <= rect.width && elementY >= 0 && elementY <= rect.height;
1139
+ }
1140
+ setPosition({
1141
+ x: event.clientX,
1142
+ y: event.clientY,
1143
+ pageX: event.pageX,
1144
+ pageY: event.pageY,
1145
+ elementX,
1146
+ elementY,
1147
+ isInElement
1148
+ });
1149
+ }, []);
1150
+ useEffect(() => {
1151
+ if (!enabled || typeof window === "undefined") return;
1152
+ window.addEventListener("mousemove", handleMouseMove);
1153
+ return () => {
1154
+ window.removeEventListener("mousemove", handleMouseMove);
1155
+ };
1156
+ }, [enabled, handleMouseMove]);
1157
+ return {
1158
+ ref,
1159
+ ...position
1160
+ };
1161
+ }
1162
+ var useMouse_default = useMouse;
1163
+ function useCopyToClipboard(resetDelay = 2e3) {
1164
+ const [copied, setCopied] = useState(false);
1165
+ const [error, setError] = useState(null);
1166
+ const reset = useCallback(() => {
1167
+ setCopied(false);
1168
+ setError(null);
1169
+ }, []);
1170
+ const copy = useCallback(
1171
+ async (text) => {
1172
+ if (!navigator?.clipboard) {
1173
+ try {
1174
+ const textarea = document.createElement("textarea");
1175
+ textarea.value = text;
1176
+ textarea.style.position = "fixed";
1177
+ textarea.style.left = "-999999px";
1178
+ textarea.style.top = "-999999px";
1179
+ document.body.appendChild(textarea);
1180
+ textarea.focus();
1181
+ textarea.select();
1182
+ const successful = document.execCommand("copy");
1183
+ document.body.removeChild(textarea);
1184
+ if (successful) {
1185
+ setCopied(true);
1186
+ setError(null);
1187
+ setTimeout(reset, resetDelay);
1188
+ return true;
1189
+ } else {
1190
+ throw new Error("execCommand failed");
1191
+ }
1192
+ } catch (err) {
1193
+ const message = err instanceof Error ? err.message : "Failed to copy to clipboard";
1194
+ setError(message);
1195
+ setCopied(false);
1196
+ return false;
1197
+ }
1198
+ }
1199
+ try {
1200
+ await navigator.clipboard.writeText(text);
1201
+ setCopied(true);
1202
+ setError(null);
1203
+ setTimeout(reset, resetDelay);
1204
+ return true;
1205
+ } catch (err) {
1206
+ const message = err instanceof Error ? err.message : "Failed to copy to clipboard";
1207
+ setError(message);
1208
+ setCopied(false);
1209
+ return false;
1210
+ }
1211
+ },
1212
+ [resetDelay, reset]
1213
+ );
1214
+ return { copy, copied, error, reset };
1215
+ }
1216
+ var useCopyToClipboard_default = useCopyToClipboard;
1217
+ function useMediaQuery(query) {
1218
+ const getMatches = (query2) => {
1219
+ if (typeof window === "undefined") return false;
1220
+ return window.matchMedia(query2).matches;
1221
+ };
1222
+ const [matches, setMatches] = useState(getMatches(query));
1223
+ useEffect(() => {
1224
+ if (typeof window === "undefined") return;
1225
+ const mediaQuery = window.matchMedia(query);
1226
+ const handleChange = () => setMatches(mediaQuery.matches);
1227
+ handleChange();
1228
+ mediaQuery.addEventListener("change", handleChange);
1229
+ return () => mediaQuery.removeEventListener("change", handleChange);
1230
+ }, [query]);
1231
+ return matches;
1232
+ }
1233
+ var useIsMobile = () => useMediaQuery("(max-width: 767px)");
1234
+ var useIsTablet = () => useMediaQuery("(min-width: 768px) and (max-width: 1023px)");
1235
+ var useIsDesktop = () => useMediaQuery("(min-width: 1024px)");
1236
+ var useIsMobileOrTablet = () => useMediaQuery("(max-width: 1023px)");
1237
+ var useMediaQuery_default = useMediaQuery;
1238
+ function useOrientation() {
1239
+ const getOrientation = () => {
1240
+ if (typeof window === "undefined" || !window.screen?.orientation) {
1241
+ return {
1242
+ angle: 0,
1243
+ type: "portrait-primary",
1244
+ isPortrait: true,
1245
+ isLandscape: false
1246
+ };
1247
+ }
1248
+ const { angle, type } = window.screen.orientation;
1249
+ const isPortrait = type.includes("portrait");
1250
+ const isLandscape = type.includes("landscape");
1251
+ return { angle, type, isPortrait, isLandscape };
1252
+ };
1253
+ const [orientation, setOrientation] = useState(getOrientation);
1254
+ useEffect(() => {
1255
+ if (typeof window === "undefined") return;
1256
+ const handleOrientationChange = () => {
1257
+ setOrientation(getOrientation());
1258
+ };
1259
+ if (window.screen?.orientation) {
1260
+ window.screen.orientation.addEventListener("change", handleOrientationChange);
1261
+ }
1262
+ window.addEventListener("orientationchange", handleOrientationChange);
1263
+ window.addEventListener("resize", handleOrientationChange);
1264
+ return () => {
1265
+ if (window.screen?.orientation) {
1266
+ window.screen.orientation.removeEventListener("change", handleOrientationChange);
1267
+ }
1268
+ window.removeEventListener("orientationchange", handleOrientationChange);
1269
+ window.removeEventListener("resize", handleOrientationChange);
1270
+ };
1271
+ }, []);
1272
+ return orientation;
1273
+ }
1274
+ var useOrientation_default = useOrientation;
1275
+ function useBattery() {
1276
+ const [battery, setBattery] = useState({
1277
+ isSupported: false,
1278
+ charging: false,
1279
+ chargingTime: Infinity,
1280
+ dischargingTime: Infinity,
1281
+ level: 1,
1282
+ percentage: 100
1283
+ });
1284
+ useEffect(() => {
1285
+ if (typeof navigator === "undefined") return;
1286
+ const nav = navigator;
1287
+ if (!nav.getBattery) {
1288
+ setBattery((prev) => ({ ...prev, isSupported: false }));
1289
+ return;
1290
+ }
1291
+ let batteryManager = null;
1292
+ const updateBattery = (battery2) => {
1293
+ setBattery({
1294
+ isSupported: true,
1295
+ charging: battery2.charging,
1296
+ chargingTime: battery2.chargingTime,
1297
+ dischargingTime: battery2.dischargingTime,
1298
+ level: battery2.level,
1299
+ percentage: Math.round(battery2.level * 100)
1300
+ });
1301
+ };
1302
+ const handleChange = () => {
1303
+ if (batteryManager) {
1304
+ updateBattery(batteryManager);
1305
+ }
1306
+ };
1307
+ nav.getBattery().then((battery2) => {
1308
+ batteryManager = battery2;
1309
+ updateBattery(battery2);
1310
+ battery2.addEventListener("chargingchange", handleChange);
1311
+ battery2.addEventListener("chargingtimechange", handleChange);
1312
+ battery2.addEventListener("dischargingtimechange", handleChange);
1313
+ battery2.addEventListener("levelchange", handleChange);
1314
+ });
1315
+ return () => {
1316
+ if (batteryManager) {
1317
+ batteryManager.removeEventListener("chargingchange", handleChange);
1318
+ batteryManager.removeEventListener("chargingtimechange", handleChange);
1319
+ batteryManager.removeEventListener("dischargingtimechange", handleChange);
1320
+ batteryManager.removeEventListener("levelchange", handleChange);
1321
+ }
1322
+ };
1323
+ }, []);
1324
+ return battery;
1325
+ }
1326
+ var useBattery_default = useBattery;
1327
+ function useNetworkState() {
1328
+ const getConnection = () => {
1329
+ if (typeof navigator === "undefined") return void 0;
1330
+ const nav = navigator;
1331
+ return nav.connection || nav.mozConnection || nav.webkitConnection;
1332
+ };
1333
+ const getNetworkState = () => {
1334
+ const online = typeof navigator !== "undefined" ? navigator.onLine : true;
1335
+ const connection = getConnection();
1336
+ return {
1337
+ online,
1338
+ offline: !online,
1339
+ downlink: connection?.downlink,
1340
+ effectiveType: connection?.effectiveType,
1341
+ rtt: connection?.rtt,
1342
+ saveData: connection?.saveData,
1343
+ type: connection?.type,
1344
+ since: /* @__PURE__ */ new Date()
1345
+ };
1346
+ };
1347
+ const [state, setState] = useState(getNetworkState);
1348
+ useEffect(() => {
1349
+ if (typeof window === "undefined") return;
1350
+ const handleOnline = () => {
1351
+ setState((prev) => ({ ...prev, online: true, offline: false, since: /* @__PURE__ */ new Date() }));
1352
+ };
1353
+ const handleOffline = () => {
1354
+ setState((prev) => ({ ...prev, online: false, offline: true, since: /* @__PURE__ */ new Date() }));
1355
+ };
1356
+ const handleConnectionChange = () => {
1357
+ setState(getNetworkState());
1358
+ };
1359
+ window.addEventListener("online", handleOnline);
1360
+ window.addEventListener("offline", handleOffline);
1361
+ const connection = getConnection();
1362
+ if (connection) {
1363
+ connection.addEventListener("change", handleConnectionChange);
1364
+ }
1365
+ return () => {
1366
+ window.removeEventListener("online", handleOnline);
1367
+ window.removeEventListener("offline", handleOffline);
1368
+ if (connection) {
1369
+ connection.removeEventListener("change", handleConnectionChange);
1370
+ }
1371
+ };
1372
+ }, []);
1373
+ return state;
1374
+ }
1375
+ var useNetworkState_default = useNetworkState;
1376
+ var DEFAULT_EVENTS = [
1377
+ "mousemove",
1378
+ "mousedown",
1379
+ "keydown",
1380
+ "touchstart",
1381
+ "scroll",
1382
+ "wheel"
1383
+ ];
1384
+ function useIdle(options = {}) {
1385
+ const {
1386
+ timeout = 6e4,
1387
+ events = DEFAULT_EVENTS,
1388
+ initialState = false,
1389
+ onIdle,
1390
+ onActive
1391
+ } = options;
1392
+ const [isIdle, setIsIdle] = useState(initialState);
1393
+ const [lastActive, setLastActive] = useState(/* @__PURE__ */ new Date());
1394
+ const [isTracking, setIsTracking] = useState(true);
1395
+ const timeoutRef = useRef(null);
1396
+ const onIdleRef = useRef(onIdle);
1397
+ const onActiveRef = useRef(onActive);
1398
+ useEffect(() => {
1399
+ onIdleRef.current = onIdle;
1400
+ onActiveRef.current = onActive;
1401
+ }, [onIdle, onActive]);
1402
+ const handleActivity = useCallback(() => {
1403
+ if (!isTracking) return;
1404
+ setLastActive(/* @__PURE__ */ new Date());
1405
+ if (isIdle) {
1406
+ setIsIdle(false);
1407
+ onActiveRef.current?.();
1408
+ }
1409
+ if (timeoutRef.current) {
1410
+ clearTimeout(timeoutRef.current);
1411
+ }
1412
+ timeoutRef.current = setTimeout(() => {
1413
+ setIsIdle(true);
1414
+ onIdleRef.current?.();
1415
+ }, timeout);
1416
+ }, [isIdle, isTracking, timeout]);
1417
+ const reset = useCallback(() => {
1418
+ handleActivity();
1419
+ }, [handleActivity]);
1420
+ const start = useCallback(() => {
1421
+ setIsTracking(true);
1422
+ handleActivity();
1423
+ }, [handleActivity]);
1424
+ const stop = useCallback(() => {
1425
+ setIsTracking(false);
1426
+ if (timeoutRef.current) {
1427
+ clearTimeout(timeoutRef.current);
1428
+ timeoutRef.current = null;
1429
+ }
1430
+ }, []);
1431
+ useEffect(() => {
1432
+ if (typeof window === "undefined" || !isTracking) return;
1433
+ timeoutRef.current = setTimeout(() => {
1434
+ setIsIdle(true);
1435
+ onIdleRef.current?.();
1436
+ }, timeout);
1437
+ events.forEach((event) => {
1438
+ window.addEventListener(event, handleActivity, { passive: true });
1439
+ });
1440
+ return () => {
1441
+ if (timeoutRef.current) {
1442
+ clearTimeout(timeoutRef.current);
1443
+ }
1444
+ events.forEach((event) => {
1445
+ window.removeEventListener(event, handleActivity);
1446
+ });
1447
+ };
1448
+ }, [events, handleActivity, isTracking, timeout]);
1449
+ return {
1450
+ isIdle,
1451
+ lastActive,
1452
+ reset,
1453
+ start,
1454
+ stop
1455
+ };
1456
+ }
1457
+ var useIdle_default = useIdle;
1458
+ function useGeolocation(options = {}) {
1459
+ const {
1460
+ enableHighAccuracy = false,
1461
+ maximumAge = 0,
1462
+ timeout = Infinity,
1463
+ watch = false
1464
+ } = options;
1465
+ const isSupported = typeof navigator !== "undefined" && "geolocation" in navigator;
1466
+ const [state, setState] = useState({
1467
+ loading: true,
1468
+ error: null,
1469
+ latitude: null,
1470
+ longitude: null,
1471
+ accuracy: null,
1472
+ altitude: null,
1473
+ altitudeAccuracy: null,
1474
+ heading: null,
1475
+ speed: null,
1476
+ timestamp: null
1477
+ });
1478
+ const handleSuccess = useCallback((position) => {
1479
+ setState({
1480
+ loading: false,
1481
+ error: null,
1482
+ latitude: position.coords.latitude,
1483
+ longitude: position.coords.longitude,
1484
+ accuracy: position.coords.accuracy,
1485
+ altitude: position.coords.altitude,
1486
+ altitudeAccuracy: position.coords.altitudeAccuracy,
1487
+ heading: position.coords.heading,
1488
+ speed: position.coords.speed,
1489
+ timestamp: position.timestamp
1490
+ });
1491
+ }, []);
1492
+ const handleError = useCallback((error) => {
1493
+ setState((prev) => ({
1494
+ ...prev,
1495
+ loading: false,
1496
+ error: error.message
1497
+ }));
1498
+ }, []);
1499
+ const refresh = useCallback(() => {
1500
+ if (!isSupported) return;
1501
+ setState((prev) => ({ ...prev, loading: true }));
1502
+ navigator.geolocation.getCurrentPosition(handleSuccess, handleError, {
1503
+ enableHighAccuracy,
1504
+ maximumAge,
1505
+ timeout
1506
+ });
1507
+ }, [isSupported, enableHighAccuracy, maximumAge, timeout, handleSuccess, handleError]);
1508
+ useEffect(() => {
1509
+ if (!isSupported) {
1510
+ setState((prev) => ({
1511
+ ...prev,
1512
+ loading: false,
1513
+ error: "Geolocation is not supported"
1514
+ }));
1515
+ return;
1516
+ }
1517
+ const positionOptions = {
1518
+ enableHighAccuracy,
1519
+ maximumAge,
1520
+ timeout
1521
+ };
1522
+ navigator.geolocation.getCurrentPosition(
1523
+ handleSuccess,
1524
+ handleError,
1525
+ positionOptions
1526
+ );
1527
+ let watchId = null;
1528
+ if (watch) {
1529
+ watchId = navigator.geolocation.watchPosition(
1530
+ handleSuccess,
1531
+ handleError,
1532
+ positionOptions
1533
+ );
1534
+ }
1535
+ return () => {
1536
+ if (watchId !== null) {
1537
+ navigator.geolocation.clearWatch(watchId);
1538
+ }
1539
+ };
1540
+ }, [isSupported, enableHighAccuracy, maximumAge, timeout, watch, handleSuccess, handleError]);
1541
+ return {
1542
+ ...state,
1543
+ refresh,
1544
+ isSupported
1545
+ };
1546
+ }
1547
+ var useGeolocation_default = useGeolocation;
1548
+ function usePreferredLanguage() {
1549
+ const getLanguageState = () => {
1550
+ if (typeof navigator === "undefined") {
1551
+ return { language: "en", languages: ["en"] };
1552
+ }
1553
+ return {
1554
+ language: navigator.language || "en",
1555
+ languages: navigator.languages || [navigator.language || "en"]
1556
+ };
1557
+ };
1558
+ const [state, setState] = useState(getLanguageState);
1559
+ useEffect(() => {
1560
+ if (typeof window === "undefined") return;
1561
+ const handleLanguageChange = () => {
1562
+ setState(getLanguageState());
1563
+ };
1564
+ window.addEventListener("languagechange", handleLanguageChange);
1565
+ return () => {
1566
+ window.removeEventListener("languagechange", handleLanguageChange);
1567
+ };
1568
+ }, []);
1569
+ return state;
1570
+ }
1571
+ var usePreferredLanguage_default = usePreferredLanguage;
1572
+ function useThemeDetector() {
1573
+ const getCurrentTheme = () => {
1574
+ if (typeof window === "undefined") return "light";
1575
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1576
+ };
1577
+ const [theme, setTheme] = useState(getCurrentTheme);
1578
+ useEffect(() => {
1579
+ if (typeof window === "undefined") return;
1580
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
1581
+ const handleChange = (e) => {
1582
+ setTheme(e.matches ? "dark" : "light");
1583
+ };
1584
+ mediaQuery.addEventListener("change", handleChange);
1585
+ return () => mediaQuery.removeEventListener("change", handleChange);
1586
+ }, []);
1587
+ return theme;
1588
+ }
1589
+ var useThemeDetector_default = useThemeDetector;
1590
+ function useLocalStorage(key, initialValue, options = {}) {
1591
+ const {
1592
+ serializer = JSON.stringify,
1593
+ deserializer = JSON.parse,
1594
+ syncTabs = true,
1595
+ debug = false
1596
+ } = options;
1597
+ const log = useCallback(
1598
+ (...args) => {
1599
+ if (debug) console.log(`[useLocalStorage:${key}]`, ...args);
1600
+ },
1601
+ [debug, key]
1602
+ );
1603
+ const readValue = useCallback(() => {
1604
+ if (typeof window === "undefined") {
1605
+ return initialValue;
1606
+ }
1607
+ try {
1608
+ const item = window.localStorage.getItem(key);
1609
+ if (item === null) {
1610
+ return initialValue;
1611
+ }
1612
+ const parsed = deserializer(item);
1613
+ log("Read value:", parsed);
1614
+ return parsed;
1615
+ } catch (error) {
1616
+ console.warn(`Error reading localStorage key "${key}":`, error);
1617
+ return initialValue;
1618
+ }
1619
+ }, [key, initialValue, deserializer, log]);
1620
+ const [storedValue, setStoredValue] = useState(readValue);
1621
+ const setValue = useCallback(
1622
+ (value) => {
1623
+ if (typeof window === "undefined") {
1624
+ console.warn(`Cannot set localStorage key "${key}" in non-browser environment`);
1625
+ return;
1626
+ }
1627
+ try {
1628
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
1629
+ setStoredValue(valueToStore);
1630
+ window.localStorage.setItem(key, serializer(valueToStore));
1631
+ log("Set value:", valueToStore);
1632
+ window.dispatchEvent(new StorageEvent("storage", { key, newValue: serializer(valueToStore) }));
1633
+ } catch (error) {
1634
+ console.warn(`Error setting localStorage key "${key}":`, error);
1635
+ }
1636
+ },
1637
+ [key, storedValue, serializer, log]
1638
+ );
1639
+ const removeValue = useCallback(() => {
1640
+ if (typeof window === "undefined") {
1641
+ return;
1642
+ }
1643
+ try {
1644
+ window.localStorage.removeItem(key);
1645
+ setStoredValue(initialValue);
1646
+ log("Removed value");
1647
+ window.dispatchEvent(new StorageEvent("storage", { key, newValue: null }));
1648
+ } catch (error) {
1649
+ console.warn(`Error removing localStorage key "${key}":`, error);
1650
+ }
1651
+ }, [key, initialValue, log]);
1652
+ useEffect(() => {
1653
+ if (!syncTabs || typeof window === "undefined") {
1654
+ return;
1655
+ }
1656
+ const handleStorageChange = (event) => {
1657
+ if (event.key !== key) {
1658
+ return;
1659
+ }
1660
+ log("Storage event received:", event.newValue);
1661
+ if (event.newValue === null) {
1662
+ setStoredValue(initialValue);
1663
+ } else {
1664
+ try {
1665
+ setStoredValue(deserializer(event.newValue));
1666
+ } catch {
1667
+ console.warn(`Error parsing localStorage change for key "${key}"`);
1668
+ }
1669
+ }
1670
+ };
1671
+ window.addEventListener("storage", handleStorageChange);
1672
+ return () => window.removeEventListener("storage", handleStorageChange);
1673
+ }, [key, initialValue, syncTabs, deserializer, log]);
1674
+ return [storedValue, setValue, removeValue];
1675
+ }
1676
+ var useLocalStorage_default = useLocalStorage;
1677
+ function useSessionStorage(key, initialValue, options = {}) {
1678
+ const {
1679
+ serializer = JSON.stringify,
1680
+ deserializer = JSON.parse,
1681
+ debug = false
1682
+ } = options;
1683
+ const log = useCallback(
1684
+ (...args) => {
1685
+ if (debug) console.log(`[useSessionStorage:${key}]`, ...args);
1686
+ },
1687
+ [debug, key]
1688
+ );
1689
+ const readValue = useCallback(() => {
1690
+ if (typeof window === "undefined") {
1691
+ return initialValue;
1692
+ }
1693
+ try {
1694
+ const item = window.sessionStorage.getItem(key);
1695
+ if (item === null) {
1696
+ return initialValue;
1697
+ }
1698
+ const parsed = deserializer(item);
1699
+ log("Read value:", parsed);
1700
+ return parsed;
1701
+ } catch (error) {
1702
+ console.warn(`Error reading sessionStorage key "${key}":`, error);
1703
+ return initialValue;
1704
+ }
1705
+ }, [key, initialValue, deserializer, log]);
1706
+ const [storedValue, setStoredValue] = useState(readValue);
1707
+ const setValue = useCallback(
1708
+ (value) => {
1709
+ if (typeof window === "undefined") {
1710
+ console.warn(`Cannot set sessionStorage key "${key}" in non-browser environment`);
1711
+ return;
1712
+ }
1713
+ try {
1714
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
1715
+ setStoredValue(valueToStore);
1716
+ window.sessionStorage.setItem(key, serializer(valueToStore));
1717
+ log("Set value:", valueToStore);
1718
+ } catch (error) {
1719
+ console.warn(`Error setting sessionStorage key "${key}":`, error);
1720
+ }
1721
+ },
1722
+ [key, storedValue, serializer, log]
1723
+ );
1724
+ const removeValue = useCallback(() => {
1725
+ if (typeof window === "undefined") {
1726
+ return;
1727
+ }
1728
+ try {
1729
+ window.sessionStorage.removeItem(key);
1730
+ setStoredValue(initialValue);
1731
+ log("Removed value");
1732
+ } catch (error) {
1733
+ console.warn(`Error removing sessionStorage key "${key}":`, error);
1734
+ }
1735
+ }, [key, initialValue, log]);
1736
+ useEffect(() => {
1737
+ if (typeof window === "undefined") return;
1738
+ const handleStorageChange = (e) => {
1739
+ if (e.storageArea !== sessionStorage || e.key !== key) {
1740
+ return;
1741
+ }
1742
+ try {
1743
+ if (e.newValue === null) {
1744
+ setStoredValue(initialValue);
1745
+ } else {
1746
+ setStoredValue(deserializer(e.newValue));
1747
+ }
1748
+ } catch (error) {
1749
+ console.warn(`Error handling storage event for key "${key}":`, error);
1750
+ }
1751
+ };
1752
+ window.addEventListener("storage", handleStorageChange);
1753
+ return () => {
1754
+ window.removeEventListener("storage", handleStorageChange);
1755
+ };
1756
+ }, [key, initialValue, deserializer]);
1757
+ return [storedValue, setValue, removeValue];
1758
+ }
1759
+ var useSessionStorage_default = useSessionStorage;
1760
+ var cache = /* @__PURE__ */ new Map();
1761
+ function useFetch(url, options = {}) {
1762
+ const {
1763
+ skip = false,
1764
+ transform,
1765
+ retries = 0,
1766
+ retryDelay = 1e3,
1767
+ cacheKey,
1768
+ cacheTime = 0,
1769
+ onSuccess,
1770
+ onError,
1771
+ body,
1772
+ ...fetchOptions
1773
+ } = options;
1774
+ const [data, setData] = useState(null);
1775
+ const [loading, setLoading] = useState(!skip && !!url);
1776
+ const [isFetching, setIsFetching] = useState(!skip && !!url);
1777
+ const [error, setError] = useState(null);
1778
+ const [status, setStatus] = useState(null);
1779
+ const abortControllerRef = useRef(null);
1780
+ const retriesRef = useRef(0);
1781
+ const fetchData = useCallback(async () => {
1782
+ if (!url) return null;
1783
+ const key = cacheKey || url;
1784
+ if (cacheTime > 0) {
1785
+ const cached = cache.get(key);
1786
+ if (cached && Date.now() - cached.timestamp < cacheTime) {
1787
+ const cachedData = cached.data;
1788
+ setData(cachedData);
1789
+ setLoading(false);
1790
+ setIsFetching(false);
1791
+ return cachedData;
1792
+ }
1793
+ }
1794
+ if (abortControllerRef.current) {
1795
+ abortControllerRef.current.abort();
1796
+ }
1797
+ abortControllerRef.current = new AbortController();
1798
+ setIsFetching(true);
1799
+ setError(null);
1800
+ try {
1801
+ let processedBody;
1802
+ if (body !== null && body !== void 0) {
1803
+ if (typeof body === "object" && !(body instanceof FormData) && !(body instanceof Blob)) {
1804
+ processedBody = JSON.stringify(body);
1805
+ fetchOptions.headers = {
1806
+ "Content-Type": "application/json",
1807
+ ...fetchOptions.headers
1808
+ };
1809
+ } else {
1810
+ processedBody = body;
1811
+ }
1812
+ }
1813
+ const response = await fetch(url, {
1814
+ ...fetchOptions,
1815
+ body: processedBody,
1816
+ signal: abortControllerRef.current.signal
1817
+ });
1818
+ setStatus(response.status);
1819
+ if (!response.ok) {
1820
+ throw new Error(`HTTP error! status: ${response.status}`);
1821
+ }
1822
+ const responseData = await response.json();
1823
+ const transformedData = transform ? transform(responseData) : responseData;
1824
+ if (cacheTime > 0) {
1825
+ cache.set(key, { data: transformedData, timestamp: Date.now() });
1826
+ }
1827
+ setData(transformedData);
1828
+ setError(null);
1829
+ setLoading(false);
1830
+ setIsFetching(false);
1831
+ retriesRef.current = 0;
1832
+ onSuccess?.(transformedData);
1833
+ return transformedData;
1834
+ } catch (err) {
1835
+ if (err.name === "AbortError") {
1836
+ return null;
1837
+ }
1838
+ const fetchError = err instanceof Error ? err : new Error(String(err));
1839
+ if (retriesRef.current < retries) {
1840
+ retriesRef.current++;
1841
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
1842
+ return fetchData();
1843
+ }
1844
+ setError(fetchError);
1845
+ setLoading(false);
1846
+ setIsFetching(false);
1847
+ retriesRef.current = 0;
1848
+ onError?.(fetchError);
1849
+ return null;
1850
+ }
1851
+ }, [url, cacheKey, cacheTime, transform, retries, retryDelay, body, fetchOptions, onSuccess, onError]);
1852
+ const abort = useCallback(() => {
1853
+ if (abortControllerRef.current) {
1854
+ abortControllerRef.current.abort();
1855
+ }
1856
+ }, []);
1857
+ const refetch = useCallback(async () => {
1858
+ const key = cacheKey || url || "";
1859
+ cache.delete(key);
1860
+ setLoading(true);
1861
+ return fetchData();
1862
+ }, [fetchData, cacheKey, url]);
1863
+ useEffect(() => {
1864
+ if (skip || !url) {
1865
+ setLoading(false);
1866
+ setIsFetching(false);
1867
+ return;
1868
+ }
1869
+ fetchData();
1870
+ return () => {
1871
+ abort();
1872
+ };
1873
+ }, [url, skip]);
1874
+ return {
1875
+ data,
1876
+ loading,
1877
+ error,
1878
+ refetch,
1879
+ abort,
1880
+ isFetching,
1881
+ status
1882
+ };
1883
+ }
1884
+ var useFetch_default = useFetch;
1885
+ var scriptCache = /* @__PURE__ */ new Map();
1886
+ function useScript(src, options = {}) {
1887
+ const { shouldLoad = true, removeOnUnmount = false, attributes = {} } = options;
1888
+ const [status, setStatus] = useState(() => {
1889
+ if (!src) return "idle";
1890
+ if (typeof window === "undefined") return "idle";
1891
+ const existingScript = document.querySelector(`script[src="${src}"]`);
1892
+ if (existingScript) {
1893
+ return scriptCache.get(src) || "ready";
1894
+ }
1895
+ return "idle";
1896
+ });
1897
+ const load = useCallback(() => {
1898
+ if (!src || typeof document === "undefined") return;
1899
+ const existingScript = document.querySelector(`script[src="${src}"]`);
1900
+ if (existingScript) {
1901
+ const cachedStatus = scriptCache.get(src);
1902
+ if (cachedStatus) {
1903
+ setStatus(cachedStatus);
1904
+ }
1905
+ return;
1906
+ }
1907
+ setStatus("loading");
1908
+ scriptCache.set(src, "loading");
1909
+ const script = document.createElement("script");
1910
+ script.src = src;
1911
+ script.async = true;
1912
+ Object.entries(attributes).forEach(([key, value]) => {
1913
+ script.setAttribute(key, value);
1914
+ });
1915
+ const handleLoad = () => {
1916
+ setStatus("ready");
1917
+ scriptCache.set(src, "ready");
1918
+ };
1919
+ const handleError = () => {
1920
+ setStatus("error");
1921
+ scriptCache.set(src, "error");
1922
+ };
1923
+ script.addEventListener("load", handleLoad);
1924
+ script.addEventListener("error", handleError);
1925
+ document.body.appendChild(script);
1926
+ }, [src, attributes]);
1927
+ const remove = useCallback(() => {
1928
+ if (!src || typeof document === "undefined") return;
1929
+ const existingScript = document.querySelector(`script[src="${src}"]`);
1930
+ if (existingScript) {
1931
+ document.body.removeChild(existingScript);
1932
+ scriptCache.delete(src);
1933
+ setStatus("idle");
1934
+ }
1935
+ }, [src]);
1936
+ useEffect(() => {
1937
+ if (shouldLoad && status === "idle") {
1938
+ load();
1939
+ }
1940
+ }, [shouldLoad, status, load]);
1941
+ useEffect(() => {
1942
+ return () => {
1943
+ if (removeOnUnmount) {
1944
+ remove();
1945
+ }
1946
+ };
1947
+ }, [removeOnUnmount, remove]);
1948
+ return {
1949
+ status,
1950
+ ready: status === "ready",
1951
+ loading: status === "loading",
1952
+ error: status === "error",
1953
+ load,
1954
+ remove
1955
+ };
1956
+ }
1957
+ var useScript_default = useScript;
1958
+ function useRenderInfo(componentName = "Component") {
1959
+ const renderCount = useRef(0);
1960
+ const lastRenderTime = useRef(Date.now());
1961
+ const currentTime = Date.now();
1962
+ const sinceLastRender = currentTime - lastRenderTime.current;
1963
+ renderCount.current++;
1964
+ const renders = renderCount.current;
1965
+ useEffect(() => {
1966
+ lastRenderTime.current = currentTime;
1967
+ });
1968
+ const info = {
1969
+ name: componentName,
1970
+ renders,
1971
+ sinceLastRender,
1972
+ timestamp: currentTime
1973
+ };
1974
+ if (process.env.NODE_ENV === "development") {
1975
+ console.log(`[${componentName}] Render #${renders} (${sinceLastRender}ms since last)`);
1976
+ }
1977
+ return info;
1978
+ }
1979
+ var useRenderInfo_default = useRenderInfo;
1980
+ function useRenderCount() {
1981
+ const renderCount = useRef(0);
1982
+ renderCount.current++;
1983
+ return renderCount.current;
1984
+ }
1985
+ var useRenderCount_default = useRenderCount;
1986
+ function useLogger(componentName, props, options = {}) {
1987
+ const {
1988
+ logProps = true,
1989
+ logLifecycle = true,
1990
+ logger = console.log
1991
+ } = options;
1992
+ const previousProps = useRef(props);
1993
+ const renderCount = useRef(0);
1994
+ renderCount.current++;
1995
+ useEffect(() => {
1996
+ if (logLifecycle) {
1997
+ logger(`[${componentName}] Mounted`);
1998
+ }
1999
+ return () => {
2000
+ if (logLifecycle) {
2001
+ logger(`[${componentName}] Unmounted (rendered ${renderCount.current} times)`);
2002
+ }
2003
+ };
2004
+ }, []);
2005
+ useEffect(() => {
2006
+ if (!logProps || !props || !previousProps.current) {
2007
+ previousProps.current = props;
2008
+ return;
2009
+ }
2010
+ const changedProps = {};
2011
+ let hasChanges = false;
2012
+ Object.keys(props).forEach((key) => {
2013
+ if (previousProps.current?.[key] !== props[key]) {
2014
+ changedProps[key] = {
2015
+ from: previousProps.current?.[key],
2016
+ to: props[key]
2017
+ };
2018
+ hasChanges = true;
2019
+ }
2020
+ });
2021
+ if (previousProps.current) {
2022
+ Object.keys(previousProps.current).forEach((key) => {
2023
+ if (!(key in props)) {
2024
+ changedProps[key] = {
2025
+ from: previousProps.current?.[key],
2026
+ to: void 0
2027
+ };
2028
+ hasChanges = true;
2029
+ }
2030
+ });
2031
+ }
2032
+ if (hasChanges) {
2033
+ logger(`[${componentName}] Props changed:`, changedProps);
2034
+ }
2035
+ previousProps.current = props;
2036
+ }, [componentName, props, logProps, logger]);
2037
+ if (process.env.NODE_ENV === "development") {
2038
+ logger(`[${componentName}] Render #${renderCount.current}`);
2039
+ }
2040
+ }
2041
+ var useLogger_default = useLogger;
2042
+ var defaultDimensions = {
2043
+ width: 0,
2044
+ height: 0,
2045
+ top: 0,
2046
+ left: 0,
2047
+ bottom: 0,
2048
+ right: 0,
2049
+ x: 0,
2050
+ y: 0
2051
+ };
2052
+ function useMeasure() {
2053
+ const [dimensions, setDimensions] = useState(defaultDimensions);
2054
+ const elementRef = useRef(null);
2055
+ const observerRef = useRef(null);
2056
+ const measure = useCallback(() => {
2057
+ if (!elementRef.current) return;
2058
+ const rect = elementRef.current.getBoundingClientRect();
2059
+ setDimensions({
2060
+ width: rect.width,
2061
+ height: rect.height,
2062
+ top: rect.top,
2063
+ left: rect.left,
2064
+ bottom: rect.bottom,
2065
+ right: rect.right,
2066
+ x: rect.x,
2067
+ y: rect.y
2068
+ });
2069
+ }, []);
2070
+ const ref = useCallback((node) => {
2071
+ if (observerRef.current) {
2072
+ observerRef.current.disconnect();
2073
+ observerRef.current = null;
2074
+ }
2075
+ if (node) {
2076
+ elementRef.current = node;
2077
+ if (typeof ResizeObserver !== "undefined") {
2078
+ observerRef.current = new ResizeObserver((entries) => {
2079
+ if (entries[0]) {
2080
+ const rect2 = entries[0].target.getBoundingClientRect();
2081
+ setDimensions({
2082
+ width: rect2.width,
2083
+ height: rect2.height,
2084
+ top: rect2.top,
2085
+ left: rect2.left,
2086
+ bottom: rect2.bottom,
2087
+ right: rect2.right,
2088
+ x: rect2.x,
2089
+ y: rect2.y
2090
+ });
2091
+ }
2092
+ });
2093
+ observerRef.current.observe(node);
2094
+ }
2095
+ const rect = node.getBoundingClientRect();
2096
+ setDimensions({
2097
+ width: rect.width,
2098
+ height: rect.height,
2099
+ top: rect.top,
2100
+ left: rect.left,
2101
+ bottom: rect.bottom,
2102
+ right: rect.right,
2103
+ x: rect.x,
2104
+ y: rect.y
2105
+ });
2106
+ } else {
2107
+ elementRef.current = null;
2108
+ }
2109
+ }, []);
2110
+ useEffect(() => {
2111
+ return () => {
2112
+ if (observerRef.current) {
2113
+ observerRef.current.disconnect();
2114
+ }
2115
+ };
2116
+ }, []);
2117
+ return { ref, dimensions, measure };
2118
+ }
2119
+ var useMeasure_default = useMeasure;
2120
+ function useIntersectionObserver(options = {}) {
2121
+ const {
2122
+ root = null,
2123
+ rootMargin = "0px",
2124
+ threshold = 0,
2125
+ freezeOnceVisible = false,
2126
+ initialIsIntersecting = false,
2127
+ onChange
2128
+ } = options;
2129
+ const [entry, setEntry] = useState(null);
2130
+ const [isIntersecting, setIsIntersecting] = useState(initialIsIntersecting);
2131
+ const elementRef = useRef(null);
2132
+ const observerRef = useRef(null);
2133
+ const frozen = useRef(false);
2134
+ const ref = useCallback(
2135
+ (node) => {
2136
+ if (observerRef.current) {
2137
+ observerRef.current.disconnect();
2138
+ observerRef.current = null;
2139
+ }
2140
+ if (frozen.current) return;
2141
+ if (node && typeof IntersectionObserver !== "undefined") {
2142
+ elementRef.current = node;
2143
+ observerRef.current = new IntersectionObserver(
2144
+ ([observerEntry]) => {
2145
+ const newIsIntersecting = observerEntry.isIntersecting;
2146
+ setEntry(observerEntry);
2147
+ setIsIntersecting(newIsIntersecting);
2148
+ onChange?.(newIsIntersecting, observerEntry);
2149
+ if (freezeOnceVisible && newIsIntersecting) {
2150
+ frozen.current = true;
2151
+ observerRef.current?.disconnect();
2152
+ }
2153
+ },
2154
+ { root, rootMargin, threshold }
2155
+ );
2156
+ observerRef.current.observe(node);
2157
+ } else {
2158
+ elementRef.current = null;
2159
+ }
2160
+ },
2161
+ [root, rootMargin, threshold, freezeOnceVisible, onChange]
2162
+ );
2163
+ useEffect(() => {
2164
+ return () => {
2165
+ if (observerRef.current) {
2166
+ observerRef.current.disconnect();
2167
+ }
2168
+ };
2169
+ }, []);
2170
+ return { ref, isIntersecting, entry };
2171
+ }
2172
+ var useIntersectionObserver_default = useIntersectionObserver;
2173
+ var DEFAULT_DURATION = 4e3;
2174
+ function useSnackbar(defaultDuration = DEFAULT_DURATION) {
2175
+ const [state, setState] = useState({
2176
+ open: false,
2177
+ message: "",
2178
+ severity: "info",
2179
+ autoHideDuration: defaultDuration
2180
+ });
2181
+ const show = useCallback(
2182
+ (message, severity = "info", duration) => {
2183
+ setState({
2184
+ open: true,
2185
+ message,
2186
+ severity,
2187
+ autoHideDuration: duration ?? defaultDuration
2188
+ });
2189
+ },
2190
+ [defaultDuration]
2191
+ );
2192
+ const success = useCallback(
2193
+ (message, duration) => show(message, "success", duration),
2194
+ [show]
2195
+ );
2196
+ const error = useCallback(
2197
+ (message, duration) => show(message, "error", duration),
2198
+ [show]
2199
+ );
2200
+ const warning = useCallback(
2201
+ (message, duration) => show(message, "warning", duration),
2202
+ [show]
2203
+ );
2204
+ const info = useCallback(
2205
+ (message, duration) => show(message, "info", duration),
2206
+ [show]
2207
+ );
2208
+ const close = useCallback(() => {
2209
+ setState((prev) => ({ ...prev, open: false }));
2210
+ }, []);
2211
+ return { state, show, success, error, warning, info, close };
2212
+ }
2213
+ var useSnackbar_default = useSnackbar;
2214
+
2215
+ export { useBattery_default as useBattery, useClickAway_default as useClickAway, useContinuousRetry_default as useContinuousRetry, useCopyToClipboard_default as useCopyToClipboard, useCountdown_default as useCountdown, useCounter_default as useCounter, useDebounce_default as useDebounce, useDefault_default as useDefault, useDocumentTitle_default as useDocumentTitle, useEventListener_default as useEventListener, useFavicon_default as useFavicon, useFetch_default as useFetch, useGeolocation_default as useGeolocation, useHistoryState_default as useHistoryState, useHover_default as useHover, useIdle_default as useIdle, useIntersectionObserver_default as useIntersectionObserver, useInterval_default as useInterval, useIntervalWhen_default as useIntervalWhen, useIsClient_default as useIsClient, useIsDesktop, useIsFirstRender_default as useIsFirstRender, useIsMobile, useIsMobileOrTablet, useIsTablet, useKeyPress_default as useKeyPress, useList_default as useList, useLocalStorage_default as useLocalStorage, useLockBodyScroll_default as useLockBodyScroll, useLogger_default as useLogger, useLongPress_default as useLongPress, useMap_default as useMap, useMeasure_default as useMeasure, useMediaQuery_default as useMediaQuery, useMouse_default as useMouse, useNetworkState_default as useNetworkState, useObjectState_default as useObjectState, useOnClickOutside_default as useOnClickOutside, useOrientation_default as useOrientation, usePageLeave_default as usePageLeave, usePageTitle_default as usePageTitle, usePreferredLanguage_default as usePreferredLanguage, usePrevious_default as usePrevious, useQueue_default as useQueue, useRandomInterval_default as useRandomInterval, useRenderCount_default as useRenderCount, useRenderInfo_default as useRenderInfo, useScript_default as useScript, useSessionStorage_default as useSessionStorage, useSet_default as useSet, useSnackbar_default as useSnackbar, useThemeDetector_default as useThemeDetector, useThrottle_default as useThrottle, useTimeout_default as useTimeout, useToggle_default as useToggle, useVisibilityChange_default as useVisibilityChange, useWindowScroll_default as useWindowScroll, useWindowSize_default as useWindowSize };
2216
+ //# sourceMappingURL=index.mjs.map
2217
+ //# sourceMappingURL=index.mjs.map