@djangocfg/ui-core 2.1.101 → 2.1.103

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/hooks.mjs ADDED
@@ -0,0 +1,675 @@
1
+ import moment from 'moment';
2
+ import * as React from 'react';
3
+ import { useState, useEffect, useRef, useCallback, useDebugValue } from 'react';
4
+ import { toast } from 'sonner';
5
+ export { toast } from 'sonner';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
11
+ var useCountdown = /* @__PURE__ */ __name((targetDate) => {
12
+ const [countdown, setCountdown] = useState({
13
+ days: 0,
14
+ hours: 0,
15
+ minutes: 0,
16
+ seconds: 0,
17
+ isExpired: false,
18
+ totalSeconds: 0
19
+ });
20
+ useEffect(() => {
21
+ if (!targetDate) {
22
+ return;
23
+ }
24
+ const target = moment.utc(targetDate);
25
+ const updateCountdown = /* @__PURE__ */ __name(() => {
26
+ const now = moment.utc();
27
+ const diff = target.diff(now, "seconds");
28
+ if (diff <= 0) {
29
+ setCountdown({
30
+ days: 0,
31
+ hours: 0,
32
+ minutes: 0,
33
+ seconds: 0,
34
+ isExpired: true,
35
+ totalSeconds: 0
36
+ });
37
+ return;
38
+ }
39
+ const days = Math.floor(diff / (24 * 60 * 60));
40
+ const hours = Math.floor(diff % (24 * 60 * 60) / (60 * 60));
41
+ const minutes = Math.floor(diff % (60 * 60) / 60);
42
+ const seconds = diff % 60;
43
+ setCountdown({
44
+ days,
45
+ hours,
46
+ minutes,
47
+ seconds,
48
+ isExpired: false,
49
+ totalSeconds: diff
50
+ });
51
+ }, "updateCountdown");
52
+ updateCountdown();
53
+ const interval = setInterval(updateCountdown, 1e3);
54
+ return () => clearInterval(interval);
55
+ }, [targetDate]);
56
+ return countdown;
57
+ }, "useCountdown");
58
+ function useDebouncedCallback(callback, delay) {
59
+ const callbackRef = useRef(callback);
60
+ const timeoutRef = useRef(null);
61
+ useEffect(() => {
62
+ callbackRef.current = callback;
63
+ }, [callback]);
64
+ useEffect(() => {
65
+ return () => {
66
+ if (timeoutRef.current) {
67
+ clearTimeout(timeoutRef.current);
68
+ }
69
+ };
70
+ }, []);
71
+ const debouncedCallback = useCallback(
72
+ (...args) => {
73
+ if (timeoutRef.current) {
74
+ clearTimeout(timeoutRef.current);
75
+ }
76
+ timeoutRef.current = setTimeout(() => {
77
+ callbackRef.current(...args);
78
+ }, delay);
79
+ },
80
+ [delay]
81
+ );
82
+ debouncedCallback.cancel = useCallback(() => {
83
+ if (timeoutRef.current) {
84
+ clearTimeout(timeoutRef.current);
85
+ timeoutRef.current = null;
86
+ }
87
+ }, []);
88
+ return debouncedCallback;
89
+ }
90
+ __name(useDebouncedCallback, "useDebouncedCallback");
91
+ function useDebounce(value, delay = 300) {
92
+ const [debouncedValue, setDebouncedValue] = useState(value);
93
+ useEffect(() => {
94
+ const handler = setTimeout(() => {
95
+ setDebouncedValue(value);
96
+ }, delay);
97
+ return () => {
98
+ clearTimeout(handler);
99
+ };
100
+ }, [value, delay]);
101
+ return debouncedValue;
102
+ }
103
+ __name(useDebounce, "useDebounce");
104
+ function useDebugTools(values, prefix = "") {
105
+ if (values === null || values === void 0) {
106
+ useDebugValue(values, () => `${prefix}: ${values === null ? "null" : "undefined"}`);
107
+ return;
108
+ }
109
+ if (Array.isArray(values)) {
110
+ values.forEach((value, index) => {
111
+ useDebugValue(value, (v) => {
112
+ const label = prefix ? `${prefix}[${index}]` : `[${index}]`;
113
+ return `${label}: ${formatValue(v)}`;
114
+ });
115
+ });
116
+ return;
117
+ }
118
+ if (typeof values === "object") {
119
+ for (const [key, value] of Object.entries(values)) {
120
+ useDebugValue(value, (v) => {
121
+ const label = prefix ? `${prefix}.${key}` : key;
122
+ return `${label}: ${formatValue(v)}`;
123
+ });
124
+ }
125
+ return;
126
+ }
127
+ useDebugValue(values, (v) => `${prefix}: ${formatValue(v)}`);
128
+ }
129
+ __name(useDebugTools, "useDebugTools");
130
+ function formatValue(value) {
131
+ if (value === null) return "null";
132
+ if (value === void 0) return "undefined";
133
+ try {
134
+ if (typeof value === "object") {
135
+ if (Array.isArray(value)) {
136
+ return `Array(${value.length})`;
137
+ }
138
+ return JSON.stringify(value);
139
+ }
140
+ return String(value);
141
+ } catch {
142
+ return "[Unserializable]";
143
+ }
144
+ }
145
+ __name(formatValue, "formatValue");
146
+ var _EventBus = class _EventBus {
147
+ constructor() {
148
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
149
+ }
150
+ publish(event) {
151
+ this.listeners.forEach((listener) => listener({
152
+ ...event,
153
+ timestamp: event.timestamp || Date.now()
154
+ }));
155
+ }
156
+ subscribe(listener) {
157
+ this.listeners.add(listener);
158
+ return () => {
159
+ this.listeners.delete(listener);
160
+ };
161
+ }
162
+ };
163
+ __name(_EventBus, "EventBus");
164
+ var EventBus = _EventBus;
165
+ var events = new EventBus();
166
+ function useEventListener(eventType, handler) {
167
+ const savedHandler = useRef(handler);
168
+ useEffect(() => {
169
+ savedHandler.current = handler;
170
+ }, [handler]);
171
+ useEffect(() => {
172
+ const listener = /* @__PURE__ */ __name((event) => {
173
+ if (event.type === eventType) {
174
+ savedHandler.current(event.payload);
175
+ }
176
+ }, "listener");
177
+ const unsubscribe = events.subscribe(listener);
178
+ return () => unsubscribe();
179
+ }, [eventType]);
180
+ }
181
+ __name(useEventListener, "useEventListener");
182
+ var MOBILE_BREAKPOINT = 1024;
183
+ function useIsMobile() {
184
+ const [isMobile, setIsMobile] = React.useState(void 0);
185
+ React.useEffect(() => {
186
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
187
+ const onChange = /* @__PURE__ */ __name(() => {
188
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
189
+ }, "onChange");
190
+ mql.addEventListener("change", onChange);
191
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
192
+ return () => mql.removeEventListener("change", onChange);
193
+ }, []);
194
+ return !!isMobile;
195
+ }
196
+ __name(useIsMobile, "useIsMobile");
197
+ function useMediaQuery(query) {
198
+ const [matches, setMatches] = useState(false);
199
+ useEffect(() => {
200
+ const mediaQuery = window.matchMedia(query);
201
+ setMatches(mediaQuery.matches);
202
+ const handler = /* @__PURE__ */ __name((event) => {
203
+ setMatches(event.matches);
204
+ }, "handler");
205
+ mediaQuery.addEventListener("change", handler);
206
+ return () => {
207
+ mediaQuery.removeEventListener("change", handler);
208
+ };
209
+ }, [query]);
210
+ return matches;
211
+ }
212
+ __name(useMediaQuery, "useMediaQuery");
213
+ function useToast() {
214
+ return { toast, dismiss: toast.dismiss };
215
+ }
216
+ __name(useToast, "useToast");
217
+
218
+ // src/hooks/useCopy.ts
219
+ var useCopy = /* @__PURE__ */ __name((options = {}) => {
220
+ const { toast: toast3 } = useToast();
221
+ const {
222
+ successMessage = "Copied to clipboard",
223
+ errorMessage = "Failed to copy to clipboard"
224
+ } = options;
225
+ const copyToClipboard = useCallback(async (text, customSuccessMessage) => {
226
+ try {
227
+ await navigator.clipboard.writeText(text);
228
+ toast3.success(customSuccessMessage || successMessage);
229
+ return true;
230
+ } catch (error) {
231
+ console.error("Failed to copy:", error);
232
+ toast3.error(errorMessage);
233
+ return false;
234
+ }
235
+ }, [toast3, successMessage, errorMessage]);
236
+ return { copyToClipboard };
237
+ }, "useCopy");
238
+ var useImageLoader = /* @__PURE__ */ __name((src, callbacks) => {
239
+ const [state, setState] = useState({
240
+ isLoading: false,
241
+ isLoaded: false,
242
+ hasError: false
243
+ });
244
+ const handleLoad = useCallback((event) => {
245
+ setState({
246
+ isLoading: false,
247
+ isLoaded: true,
248
+ hasError: false
249
+ });
250
+ if (callbacks?.onLoad) {
251
+ callbacks.onLoad(event);
252
+ }
253
+ }, [callbacks?.onLoad]);
254
+ const handleError = useCallback((event) => {
255
+ setState({
256
+ isLoading: false,
257
+ isLoaded: false,
258
+ hasError: true
259
+ });
260
+ if (callbacks?.onError) {
261
+ callbacks.onError(event);
262
+ }
263
+ }, [callbacks?.onError]);
264
+ useEffect(() => {
265
+ if (!src) {
266
+ setState({
267
+ isLoading: false,
268
+ isLoaded: false,
269
+ hasError: true
270
+ });
271
+ return;
272
+ }
273
+ setState({
274
+ isLoading: true,
275
+ isLoaded: false,
276
+ hasError: false
277
+ });
278
+ if (callbacks?.onLoadStart) {
279
+ callbacks.onLoadStart();
280
+ }
281
+ const img = new Image();
282
+ img.addEventListener("load", handleLoad);
283
+ img.addEventListener("error", handleError);
284
+ img.src = src;
285
+ return () => {
286
+ img.removeEventListener("load", handleLoad);
287
+ img.removeEventListener("error", handleError);
288
+ };
289
+ }, [src, handleLoad, handleError, callbacks?.onLoadStart]);
290
+ return state;
291
+ }, "useImageLoader");
292
+ var useResolvedTheme = /* @__PURE__ */ __name(() => {
293
+ const [theme, setTheme] = useState("light");
294
+ useEffect(() => {
295
+ const checkTheme = /* @__PURE__ */ __name(() => {
296
+ if (document.documentElement.classList.contains("dark")) {
297
+ return "dark";
298
+ }
299
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
300
+ return "dark";
301
+ }
302
+ return "light";
303
+ }, "checkTheme");
304
+ setTheme(checkTheme());
305
+ const observer = new MutationObserver(() => {
306
+ setTheme(checkTheme());
307
+ });
308
+ observer.observe(document.documentElement, {
309
+ attributes: true,
310
+ attributeFilter: ["class"]
311
+ });
312
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
313
+ const handleMediaChange = /* @__PURE__ */ __name(() => {
314
+ setTheme(checkTheme());
315
+ }, "handleMediaChange");
316
+ mediaQuery.addEventListener("change", handleMediaChange);
317
+ return () => {
318
+ observer.disconnect();
319
+ mediaQuery.removeEventListener("change", handleMediaChange);
320
+ };
321
+ }, []);
322
+ return theme;
323
+ }, "useResolvedTheme");
324
+ function isWrappedFormat(data) {
325
+ return data !== null && typeof data === "object" && "_meta" in data && "_value" in data && typeof data._meta === "object" && typeof data._meta.createdAt === "number";
326
+ }
327
+ __name(isWrappedFormat, "isWrappedFormat");
328
+ function isExpired(wrapped) {
329
+ if (!wrapped._meta.ttl) return false;
330
+ const age = Date.now() - wrapped._meta.createdAt;
331
+ return age > wrapped._meta.ttl;
332
+ }
333
+ __name(isExpired, "isExpired");
334
+ function useLocalStorage(key, initialValue, options) {
335
+ const ttl = options?.ttl;
336
+ const [storedValue, setStoredValue] = useState(initialValue);
337
+ const [isHydrated, setIsHydrated] = useState(false);
338
+ const isInitialized = useRef(false);
339
+ useEffect(() => {
340
+ if (isInitialized.current) return;
341
+ isInitialized.current = true;
342
+ try {
343
+ const item = window.localStorage.getItem(key);
344
+ if (item !== null) {
345
+ try {
346
+ const parsed = JSON.parse(item);
347
+ if (isWrappedFormat(parsed)) {
348
+ if (isExpired(parsed)) {
349
+ window.localStorage.removeItem(key);
350
+ } else {
351
+ setStoredValue(parsed._value);
352
+ }
353
+ } else {
354
+ setStoredValue(parsed);
355
+ }
356
+ } catch {
357
+ setStoredValue(item);
358
+ }
359
+ }
360
+ } catch (error) {
361
+ console.error(`Error reading localStorage key "${key}":`, error);
362
+ }
363
+ setIsHydrated(true);
364
+ }, [key]);
365
+ const checkDataSize = /* @__PURE__ */ __name((data) => {
366
+ try {
367
+ const jsonString = JSON.stringify(data);
368
+ const sizeInBytes = new Blob([jsonString]).size;
369
+ const sizeInKB = sizeInBytes / 1024;
370
+ if (sizeInKB > 1024) {
371
+ console.warn(`Data size (${sizeInKB.toFixed(2)}KB) exceeds 1MB limit for key "${key}"`);
372
+ return false;
373
+ }
374
+ return true;
375
+ } catch (error) {
376
+ console.error(`Error checking data size for key "${key}":`, error);
377
+ return false;
378
+ }
379
+ }, "checkDataSize");
380
+ const clearOldData = /* @__PURE__ */ __name(() => {
381
+ try {
382
+ const keys = Object.keys(localStorage).filter((key2) => key2 && typeof key2 === "string");
383
+ if (keys.length > 50) {
384
+ const itemsToRemove = Math.ceil(keys.length * 0.2);
385
+ for (let i = 0; i < itemsToRemove; i++) {
386
+ try {
387
+ const key2 = keys[i];
388
+ if (key2) {
389
+ localStorage.removeItem(key2);
390
+ }
391
+ } catch {
392
+ }
393
+ }
394
+ }
395
+ } catch (error) {
396
+ console.error("Error clearing old localStorage data:", error);
397
+ }
398
+ }, "clearOldData");
399
+ const forceClearAll = /* @__PURE__ */ __name(() => {
400
+ try {
401
+ const keys = Object.keys(localStorage);
402
+ for (const key2 of keys) {
403
+ try {
404
+ localStorage.removeItem(key2);
405
+ } catch {
406
+ }
407
+ }
408
+ } catch (error) {
409
+ console.error("Error force clearing localStorage:", error);
410
+ }
411
+ }, "forceClearAll");
412
+ const prepareForStorage = /* @__PURE__ */ __name((value) => {
413
+ if (ttl) {
414
+ const wrapped = {
415
+ _meta: {
416
+ createdAt: Date.now(),
417
+ ttl
418
+ },
419
+ _value: value
420
+ };
421
+ return JSON.stringify(wrapped);
422
+ }
423
+ if (typeof value === "string") {
424
+ return value;
425
+ }
426
+ return JSON.stringify(value);
427
+ }, "prepareForStorage");
428
+ const setValue = /* @__PURE__ */ __name((value) => {
429
+ try {
430
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
431
+ if (!checkDataSize(valueToStore)) {
432
+ console.warn(`Data size too large for key "${key}", removing key`);
433
+ try {
434
+ window.localStorage.removeItem(key);
435
+ } catch {
436
+ }
437
+ setStoredValue(valueToStore);
438
+ return;
439
+ }
440
+ setStoredValue(valueToStore);
441
+ if (typeof window !== "undefined") {
442
+ const dataToStore = prepareForStorage(valueToStore);
443
+ try {
444
+ window.localStorage.setItem(key, dataToStore);
445
+ } catch (storageError) {
446
+ if (storageError.name === "QuotaExceededError" || storageError.code === 22 || storageError.message?.includes("quota")) {
447
+ console.warn("localStorage quota exceeded, clearing old data...");
448
+ clearOldData();
449
+ try {
450
+ window.localStorage.setItem(key, dataToStore);
451
+ } catch (retryError) {
452
+ console.error(`Failed to set localStorage key "${key}" after clearing old data:`, retryError);
453
+ try {
454
+ forceClearAll();
455
+ window.localStorage.setItem(key, dataToStore);
456
+ } catch (finalError) {
457
+ console.error(`Failed to set localStorage key "${key}" after force clearing:`, finalError);
458
+ setStoredValue(valueToStore);
459
+ }
460
+ }
461
+ } else {
462
+ throw storageError;
463
+ }
464
+ }
465
+ }
466
+ } catch (error) {
467
+ console.error(`Error setting localStorage key "${key}":`, error);
468
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
469
+ setStoredValue(valueToStore);
470
+ }
471
+ }, "setValue");
472
+ const removeValue = /* @__PURE__ */ __name(() => {
473
+ try {
474
+ setStoredValue(initialValue);
475
+ if (typeof window !== "undefined") {
476
+ try {
477
+ window.localStorage.removeItem(key);
478
+ } catch (removeError) {
479
+ if (removeError.name === "QuotaExceededError" || removeError.code === 22 || removeError.message?.includes("quota")) {
480
+ console.warn("localStorage quota exceeded during removal, clearing old data...");
481
+ clearOldData();
482
+ try {
483
+ window.localStorage.removeItem(key);
484
+ } catch (retryError) {
485
+ console.error(`Failed to remove localStorage key "${key}" after clearing:`, retryError);
486
+ forceClearAll();
487
+ }
488
+ } else {
489
+ throw removeError;
490
+ }
491
+ }
492
+ }
493
+ } catch (error) {
494
+ console.error(`Error removing localStorage key "${key}":`, error);
495
+ }
496
+ }, "removeValue");
497
+ return [storedValue, setValue, removeValue];
498
+ }
499
+ __name(useLocalStorage, "useLocalStorage");
500
+ function isWrappedFormat2(data) {
501
+ return data !== null && typeof data === "object" && "_meta" in data && "_value" in data && typeof data._meta === "object" && typeof data._meta.createdAt === "number";
502
+ }
503
+ __name(isWrappedFormat2, "isWrappedFormat");
504
+ function isExpired2(wrapped) {
505
+ if (!wrapped._meta.ttl) return false;
506
+ const age = Date.now() - wrapped._meta.createdAt;
507
+ return age > wrapped._meta.ttl;
508
+ }
509
+ __name(isExpired2, "isExpired");
510
+ function useSessionStorage(key, initialValue, options) {
511
+ const ttl = options?.ttl;
512
+ const [storedValue, setStoredValue] = useState(() => {
513
+ if (typeof window === "undefined") {
514
+ return initialValue;
515
+ }
516
+ try {
517
+ const item = window.sessionStorage.getItem(key);
518
+ if (item === null) return initialValue;
519
+ try {
520
+ const parsed = JSON.parse(item);
521
+ if (isWrappedFormat2(parsed)) {
522
+ if (isExpired2(parsed)) {
523
+ window.sessionStorage.removeItem(key);
524
+ return initialValue;
525
+ }
526
+ return parsed._value;
527
+ }
528
+ return parsed;
529
+ } catch {
530
+ return item;
531
+ }
532
+ } catch (error) {
533
+ console.error(`Error reading sessionStorage key "${key}":`, error);
534
+ return initialValue;
535
+ }
536
+ });
537
+ const checkDataSize = /* @__PURE__ */ __name((data) => {
538
+ try {
539
+ const jsonString = JSON.stringify(data);
540
+ const sizeInBytes = new Blob([jsonString]).size;
541
+ const sizeInKB = sizeInBytes / 1024;
542
+ if (sizeInKB > 1024) {
543
+ console.warn(`Data size (${sizeInKB.toFixed(2)}KB) exceeds 1MB limit for key "${key}"`);
544
+ return false;
545
+ }
546
+ return true;
547
+ } catch (error) {
548
+ console.error(`Error checking data size for key "${key}":`, error);
549
+ return false;
550
+ }
551
+ }, "checkDataSize");
552
+ const clearOldData = /* @__PURE__ */ __name(() => {
553
+ try {
554
+ const keys = Object.keys(sessionStorage).filter((k) => k && typeof k === "string");
555
+ if (keys.length > 50) {
556
+ const itemsToRemove = Math.ceil(keys.length * 0.2);
557
+ for (let i = 0; i < itemsToRemove; i++) {
558
+ try {
559
+ const k = keys[i];
560
+ if (k) {
561
+ sessionStorage.removeItem(k);
562
+ }
563
+ } catch {
564
+ }
565
+ }
566
+ }
567
+ } catch (error) {
568
+ console.error("Error clearing old sessionStorage data:", error);
569
+ }
570
+ }, "clearOldData");
571
+ const forceClearAll = /* @__PURE__ */ __name(() => {
572
+ try {
573
+ const keys = Object.keys(sessionStorage);
574
+ for (const k of keys) {
575
+ try {
576
+ sessionStorage.removeItem(k);
577
+ } catch {
578
+ }
579
+ }
580
+ } catch (error) {
581
+ console.error("Error force clearing sessionStorage:", error);
582
+ }
583
+ }, "forceClearAll");
584
+ const prepareForStorage = /* @__PURE__ */ __name((value) => {
585
+ if (ttl) {
586
+ const wrapped = {
587
+ _meta: {
588
+ createdAt: Date.now(),
589
+ ttl
590
+ },
591
+ _value: value
592
+ };
593
+ return JSON.stringify(wrapped);
594
+ }
595
+ if (typeof value === "string") {
596
+ return value;
597
+ }
598
+ return JSON.stringify(value);
599
+ }, "prepareForStorage");
600
+ const setValue = /* @__PURE__ */ __name((value) => {
601
+ try {
602
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
603
+ if (!checkDataSize(valueToStore)) {
604
+ console.warn(`Data size too large for key "${key}", removing key`);
605
+ try {
606
+ window.sessionStorage.removeItem(key);
607
+ } catch {
608
+ }
609
+ setStoredValue(valueToStore);
610
+ return;
611
+ }
612
+ setStoredValue(valueToStore);
613
+ if (typeof window !== "undefined") {
614
+ const dataToStore = prepareForStorage(valueToStore);
615
+ try {
616
+ window.sessionStorage.setItem(key, dataToStore);
617
+ } catch (storageError) {
618
+ if (storageError.name === "QuotaExceededError" || storageError.code === 22 || storageError.message?.includes("quota")) {
619
+ console.warn("sessionStorage quota exceeded, clearing old data...");
620
+ clearOldData();
621
+ try {
622
+ window.sessionStorage.setItem(key, dataToStore);
623
+ } catch (retryError) {
624
+ console.error(`Failed to set sessionStorage key "${key}" after clearing old data:`, retryError);
625
+ try {
626
+ forceClearAll();
627
+ window.sessionStorage.setItem(key, dataToStore);
628
+ } catch (finalError) {
629
+ console.error(`Failed to set sessionStorage key "${key}" after force clearing:`, finalError);
630
+ setStoredValue(valueToStore);
631
+ }
632
+ }
633
+ } else {
634
+ throw storageError;
635
+ }
636
+ }
637
+ }
638
+ } catch (error) {
639
+ console.error(`Error setting sessionStorage key "${key}":`, error);
640
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
641
+ setStoredValue(valueToStore);
642
+ }
643
+ }, "setValue");
644
+ const removeValue = /* @__PURE__ */ __name(() => {
645
+ try {
646
+ setStoredValue(initialValue);
647
+ if (typeof window !== "undefined") {
648
+ try {
649
+ window.sessionStorage.removeItem(key);
650
+ } catch (removeError) {
651
+ if (removeError.name === "QuotaExceededError" || removeError.code === 22 || removeError.message?.includes("quota")) {
652
+ console.warn("sessionStorage quota exceeded during removal, clearing old data...");
653
+ clearOldData();
654
+ try {
655
+ window.sessionStorage.removeItem(key);
656
+ } catch (retryError) {
657
+ console.error(`Failed to remove sessionStorage key "${key}" after clearing:`, retryError);
658
+ forceClearAll();
659
+ }
660
+ } else {
661
+ throw removeError;
662
+ }
663
+ }
664
+ }
665
+ } catch (error) {
666
+ console.error(`Error removing sessionStorage key "${key}":`, error);
667
+ }
668
+ }, "removeValue");
669
+ return [storedValue, setValue, removeValue];
670
+ }
671
+ __name(useSessionStorage, "useSessionStorage");
672
+
673
+ export { events, useCopy, useCountdown, useDebounce, useDebouncedCallback, useDebugTools, useEventListener, useImageLoader, useIsMobile, useLocalStorage, useMediaQuery, useResolvedTheme, useSessionStorage, useToast };
674
+ //# sourceMappingURL=hooks.mjs.map
675
+ //# sourceMappingURL=hooks.mjs.map