react-simplikit 0.0.34 → 0.0.36

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 (56) hide show
  1. package/README.md +1 -1
  2. package/dist/components/ImpressionArea/index.cjs +17 -20
  3. package/dist/components/ImpressionArea/index.d.cts +2 -2
  4. package/dist/components/SwitchCase/index.d.cts +4 -4
  5. package/dist/hooks/useAsyncEffect/index.d.cts +1 -1
  6. package/dist/hooks/useCallbackOncePerRender/index.d.cts +2 -3
  7. package/dist/hooks/useControlledState/index.d.cts +1 -1
  8. package/dist/hooks/useCounter/index.cjs +1 -1
  9. package/dist/hooks/useCounter/index.d.cts +3 -5
  10. package/dist/hooks/useDebouncedCallback/index.cjs +144 -0
  11. package/dist/hooks/useDebouncedCallback/index.d.cts +32 -0
  12. package/dist/hooks/useDoubleClick/index.d.cts +4 -4
  13. package/dist/hooks/useGeolocation/index.cjs +153 -0
  14. package/dist/hooks/useGeolocation/index.d.cts +106 -0
  15. package/dist/hooks/useImpressionRef/index.d.cts +2 -2
  16. package/dist/hooks/useIntersectionObserver/index.d.cts +2 -2
  17. package/dist/hooks/useIsomorphicLayoutEffect/index.d.cts +3 -3
  18. package/dist/hooks/useLongPress/index.cjs +123 -0
  19. package/dist/hooks/useLongPress/index.d.cts +70 -0
  20. package/dist/hooks/useMap/index.cjs +77 -0
  21. package/dist/hooks/useMap/index.d.cts +46 -0
  22. package/dist/hooks/usePrevious/index.d.cts +2 -2
  23. package/dist/hooks/useRefEffect/index.d.cts +1 -1
  24. package/dist/hooks/useStorageState/index.d.cts +1 -1
  25. package/dist/hooks/useThrottle/index.d.cts +1 -1
  26. package/dist/hooks/useVisibilityEvent/index.d.cts +1 -1
  27. package/dist/index.cjs +453 -98
  28. package/dist/index.d.cts +9 -1
  29. package/esm/components/ImpressionArea/index.d.ts +2 -2
  30. package/esm/components/ImpressionArea/index.js +17 -20
  31. package/esm/components/SwitchCase/index.d.ts +4 -4
  32. package/esm/hooks/useAsyncEffect/index.d.ts +1 -1
  33. package/esm/hooks/useCallbackOncePerRender/index.d.ts +2 -3
  34. package/esm/hooks/useControlledState/index.d.ts +1 -1
  35. package/esm/hooks/useCounter/index.d.ts +3 -5
  36. package/esm/hooks/useCounter/index.js +1 -1
  37. package/esm/hooks/useDebouncedCallback/index.d.ts +32 -0
  38. package/esm/hooks/useDebouncedCallback/index.js +117 -0
  39. package/esm/hooks/useDoubleClick/index.d.ts +4 -4
  40. package/esm/hooks/useGeolocation/index.d.ts +106 -0
  41. package/esm/hooks/useGeolocation/index.js +126 -0
  42. package/esm/hooks/useImpressionRef/index.d.ts +2 -2
  43. package/esm/hooks/useIntersectionObserver/index.d.ts +2 -2
  44. package/esm/hooks/useIsomorphicLayoutEffect/index.d.ts +3 -3
  45. package/esm/hooks/useLongPress/index.d.ts +70 -0
  46. package/esm/hooks/useLongPress/index.js +96 -0
  47. package/esm/hooks/useMap/index.d.ts +46 -0
  48. package/esm/hooks/useMap/index.js +50 -0
  49. package/esm/hooks/usePrevious/index.d.ts +2 -2
  50. package/esm/hooks/useRefEffect/index.d.ts +1 -1
  51. package/esm/hooks/useStorageState/index.d.ts +1 -1
  52. package/esm/hooks/useThrottle/index.d.ts +1 -1
  53. package/esm/hooks/useVisibilityEvent/index.d.ts +1 -1
  54. package/esm/index.d.ts +9 -1
  55. package/esm/index.js +421 -74
  56. package/package.json +2 -3
package/dist/index.cjs CHANGED
@@ -24,17 +24,25 @@ __export(index_exports, {
24
24
  Separated: () => Separated,
25
25
  SwitchCase: () => SwitchCase,
26
26
  buildContext: () => buildContext,
27
+ mergeProps: () => mergeProps,
27
28
  mergeRefs: () => mergeRefs,
28
29
  useAsyncEffect: () => useAsyncEffect,
29
30
  useBooleanState: () => useBooleanState,
30
31
  useCallbackOncePerRender: () => useCallbackOncePerRender,
32
+ useControlledState: () => useControlledState,
31
33
  useCounter: () => useCounter,
32
34
  useDebounce: () => useDebounce,
35
+ useDebouncedCallback: () => useDebouncedCallback,
36
+ useDoubleClick: () => useDoubleClick,
37
+ useGeolocation: () => useGeolocation,
33
38
  useImpressionRef: () => useImpressionRef,
34
39
  useInputState: () => useInputState,
35
40
  useIntersectionObserver: () => useIntersectionObserver,
36
41
  useInterval: () => useInterval,
42
+ useIsomorphicLayoutEffect: () => useIsomorphicLayoutEffect,
37
43
  useLoading: () => useLoading,
44
+ useLongPress: () => useLongPress,
45
+ useMap: () => useMap,
38
46
  useOutsideClickEffect: () => useOutsideClickEffect,
39
47
  usePreservedCallback: () => usePreservedCallback,
40
48
  usePreservedReference: () => usePreservedReference,
@@ -48,6 +56,9 @@ __export(index_exports, {
48
56
  });
49
57
  module.exports = __toCommonJS(index_exports);
50
58
 
59
+ // src/components/ImpressionArea/ImpressionArea.tsx
60
+ var import_react7 = require("react");
61
+
51
62
  // src/hooks/useImpressionRef/useImpressionRef.ts
52
63
  var import_react6 = require("react");
53
64
 
@@ -291,33 +302,27 @@ function mergeRefs(...refs) {
291
302
 
292
303
  // src/components/ImpressionArea/ImpressionArea.tsx
293
304
  var import_jsx_runtime = require("react/jsx-runtime");
294
- function ImpressionArea({
295
- as,
296
- rootMargin,
297
- areaThreshold,
298
- timeThreshold,
299
- onImpressionStart,
300
- onImpressionEnd,
301
- ref,
302
- ...props
303
- }) {
304
- const Component = as ?? "div";
305
- const impressionRef = useImpressionRef({
306
- onImpressionStart,
307
- onImpressionEnd,
308
- areaThreshold,
309
- timeThreshold,
310
- rootMargin
311
- });
312
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: mergeRefs(ref, impressionRef), ...props });
313
- }
305
+ var ImpressionArea = (0, import_react7.forwardRef)(
306
+ ({ as, rootMargin, areaThreshold, timeThreshold, onImpressionStart, onImpressionEnd, ...props }, ref) => {
307
+ const Component = as ?? "div";
308
+ const impressionRef = useImpressionRef({
309
+ onImpressionStart,
310
+ onImpressionEnd,
311
+ areaThreshold,
312
+ timeThreshold,
313
+ rootMargin
314
+ });
315
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: mergeRefs(ref, impressionRef), ...props });
316
+ }
317
+ );
318
+ ImpressionArea.displayName = "ImpressionArea";
314
319
 
315
320
  // src/components/Separated/Separated.tsx
316
- var import_react7 = require("react");
321
+ var import_react8 = require("react");
317
322
  var import_jsx_runtime2 = require("react/jsx-runtime");
318
323
  function Separated({ children, by: separator }) {
319
- const childrenArray = import_react7.Children.toArray(children).filter(import_react7.isValidElement);
320
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react7.Fragment, { children: [
324
+ const childrenArray = import_react8.Children.toArray(children).filter(import_react8.isValidElement);
325
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react8.Fragment, { children: [
321
326
  child,
322
327
  i + 1 !== length && separator
323
328
  ] }, i)) });
@@ -330,9 +335,9 @@ function SwitchCase({ value, caseBy, defaultComponent = () => null }) {
330
335
  }
331
336
 
332
337
  // src/hooks/useAsyncEffect/useAsyncEffect.ts
333
- var import_react8 = require("react");
338
+ var import_react9 = require("react");
334
339
  function useAsyncEffect(effect, deps) {
335
- (0, import_react8.useEffect)(() => {
340
+ (0, import_react9.useEffect)(() => {
336
341
  let cleanup;
337
342
  effect().then((result) => {
338
343
  cleanup = result;
@@ -344,26 +349,26 @@ function useAsyncEffect(effect, deps) {
344
349
  }
345
350
 
346
351
  // src/hooks/useBooleanState/useBooleanState.ts
347
- var import_react9 = require("react");
352
+ var import_react10 = require("react");
348
353
  function useBooleanState(defaultValue = false) {
349
- const [bool, setBool] = (0, import_react9.useState)(defaultValue);
350
- const setTrue = (0, import_react9.useCallback)(() => {
354
+ const [bool, setBool] = (0, import_react10.useState)(defaultValue);
355
+ const setTrue = (0, import_react10.useCallback)(() => {
351
356
  setBool(true);
352
357
  }, []);
353
- const setFalse = (0, import_react9.useCallback)(() => {
358
+ const setFalse = (0, import_react10.useCallback)(() => {
354
359
  setBool(false);
355
360
  }, []);
356
- const toggle2 = (0, import_react9.useCallback)(() => {
361
+ const toggle2 = (0, import_react10.useCallback)(() => {
357
362
  setBool((prevBool) => !prevBool);
358
363
  }, []);
359
364
  return [bool, setTrue, setFalse, toggle2];
360
365
  }
361
366
 
362
367
  // src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
363
- var import_react10 = require("react");
368
+ var import_react11 = require("react");
364
369
  function useCallbackOncePerRender(callback, deps) {
365
- const hasFired = (0, import_react10.useRef)(false);
366
- (0, import_react10.useEffect)(() => {
370
+ const hasFired = (0, import_react11.useRef)(false);
371
+ (0, import_react11.useEffect)(() => {
367
372
  hasFired.current = false;
368
373
  }, deps);
369
374
  return usePreservedCallback((...args) => {
@@ -375,9 +380,36 @@ function useCallbackOncePerRender(callback, deps) {
375
380
  });
376
381
  }
377
382
 
383
+ // src/hooks/useControlledState/useControlledState.ts
384
+ var import_react12 = require("react");
385
+ function useControlledState({
386
+ value: valueProp,
387
+ defaultValue,
388
+ onChange,
389
+ equalityFn = Object.is
390
+ }) {
391
+ const [uncontrolledState, setUncontrolledState] = (0, import_react12.useState)(defaultValue);
392
+ const controlled = valueProp !== void 0;
393
+ const value = controlled ? valueProp : uncontrolledState;
394
+ const setValue = (0, import_react12.useCallback)(
395
+ (next) => {
396
+ const nextValue = isSetStateAction(next) ? next(value) : next;
397
+ if (equalityFn(value, nextValue) === true) return;
398
+ if (controlled === false) setUncontrolledState(nextValue);
399
+ if (controlled === true && nextValue === void 0) setUncontrolledState(nextValue);
400
+ onChange?.(nextValue);
401
+ },
402
+ [controlled, onChange, equalityFn, value]
403
+ );
404
+ return [value, setValue];
405
+ }
406
+ function isSetStateAction(next) {
407
+ return typeof next === "function";
408
+ }
409
+
378
410
  // src/hooks/useCounter/useCounter.ts
379
- var import_react11 = require("react");
380
- function useCounter({ initialValue = 0, min, max, step = 1 } = {}) {
411
+ var import_react13 = require("react");
412
+ function useCounter(initialValue = 0, { min, max, step = 1 } = {}) {
381
413
  const validateValue = (value) => {
382
414
  let validatedValue = value;
383
415
  if (min !== void 0 && validatedValue < min) {
@@ -388,9 +420,9 @@ function useCounter({ initialValue = 0, min, max, step = 1 } = {}) {
388
420
  }
389
421
  return validatedValue;
390
422
  };
391
- const [count, setCountState] = (0, import_react11.useState)(() => validateValue(initialValue));
392
- const validateValueMemoized = (0, import_react11.useCallback)(validateValue, [min, max]);
393
- const setCount = (0, import_react11.useCallback)(
423
+ const [count, setCountState] = (0, import_react13.useState)(() => validateValue(initialValue));
424
+ const validateValueMemoized = (0, import_react13.useCallback)(validateValue, [min, max]);
425
+ const setCount = (0, import_react13.useCallback)(
394
426
  (value) => {
395
427
  setCountState((prev) => {
396
428
  const nextValue = typeof value === "function" ? value(prev) : value;
@@ -399,13 +431,13 @@ function useCounter({ initialValue = 0, min, max, step = 1 } = {}) {
399
431
  },
400
432
  [validateValueMemoized]
401
433
  );
402
- const increment = (0, import_react11.useCallback)(() => {
434
+ const increment = (0, import_react13.useCallback)(() => {
403
435
  setCount((prev) => prev + step);
404
436
  }, [setCount, step]);
405
- const decrement = (0, import_react11.useCallback)(() => {
437
+ const decrement = (0, import_react13.useCallback)(() => {
406
438
  setCount((prev) => prev - step);
407
439
  }, [setCount, step]);
408
- const reset = (0, import_react11.useCallback)(() => {
440
+ const reset = (0, import_react13.useCallback)(() => {
409
441
  setCount(initialValue);
410
442
  }, [setCount, initialValue]);
411
443
  return {
@@ -418,12 +450,12 @@ function useCounter({ initialValue = 0, min, max, step = 1 } = {}) {
418
450
  }
419
451
 
420
452
  // src/hooks/useDebounce/useDebounce.ts
421
- var import_react12 = require("react");
422
- var import_react13 = require("react");
453
+ var import_react14 = require("react");
454
+ var import_react15 = require("react");
423
455
  function useDebounce(callback, wait, options = {}) {
424
456
  const preservedCallback = usePreservedCallback(callback);
425
457
  const { leading = false, trailing = true } = options;
426
- const edges = (0, import_react13.useMemo)(() => {
458
+ const edges = (0, import_react15.useMemo)(() => {
427
459
  const _edges = [];
428
460
  if (leading) {
429
461
  _edges.push("leading");
@@ -433,10 +465,10 @@ function useDebounce(callback, wait, options = {}) {
433
465
  }
434
466
  return _edges;
435
467
  }, [leading, trailing]);
436
- const debounced = (0, import_react13.useMemo)(() => {
468
+ const debounced = (0, import_react15.useMemo)(() => {
437
469
  return debounce(preservedCallback, wait, { edges });
438
470
  }, [preservedCallback, wait, edges]);
439
- (0, import_react12.useEffect)(() => {
471
+ (0, import_react14.useEffect)(() => {
440
472
  return () => {
441
473
  debounced.cancel();
442
474
  };
@@ -444,11 +476,167 @@ function useDebounce(callback, wait, options = {}) {
444
476
  return debounced;
445
477
  }
446
478
 
479
+ // src/hooks/useDoubleClick/useDoubleClick.ts
480
+ var import_react16 = require("react");
481
+ function useDoubleClick({
482
+ delay = 250,
483
+ click,
484
+ doubleClick
485
+ }) {
486
+ const clickTimeout = (0, import_react16.useRef)(null);
487
+ const clearClickTimeout = usePreservedCallback(() => {
488
+ if (clickTimeout.current != null) {
489
+ window.clearTimeout(clickTimeout.current);
490
+ clickTimeout.current = null;
491
+ }
492
+ });
493
+ (0, import_react16.useEffect)(() => () => clearClickTimeout(), [clearClickTimeout]);
494
+ const handleEvent = (0, import_react16.useCallback)(
495
+ (event) => {
496
+ clearClickTimeout();
497
+ if (click && event.detail === 1) {
498
+ clickTimeout.current = window.setTimeout(() => {
499
+ click(event);
500
+ }, delay);
501
+ }
502
+ if (event.detail === 2) {
503
+ doubleClick(event);
504
+ }
505
+ },
506
+ [click, doubleClick, delay, clearClickTimeout]
507
+ );
508
+ return handleEvent;
509
+ }
510
+
511
+ // src/hooks/useGeolocation/useGeolocation.ts
512
+ var import_react17 = require("react");
513
+ var CustomGeoLocationError = class extends Error {
514
+ code;
515
+ constructor({ code, message }) {
516
+ super(message);
517
+ this.name = "CustomGeoLocationError";
518
+ this.code = code;
519
+ }
520
+ };
521
+ var GeolocationMountBehavior = {
522
+ GET: "get",
523
+ WATCH: "watch"
524
+ };
525
+ function useGeolocation(options) {
526
+ const [state, setState] = (0, import_react17.useState)({
527
+ loading: !!options?.mountBehavior,
528
+ error: null,
529
+ data: null
530
+ });
531
+ const [isTracking, setIsTracking] = (0, import_react17.useState)(false);
532
+ const watchIdRef = (0, import_react17.useRef)(null);
533
+ const checkGeolocationSupport = (0, import_react17.useCallback)(() => {
534
+ if (typeof window === "undefined" || navigator.geolocation === void 0) {
535
+ setState((prev) => ({
536
+ ...prev,
537
+ loading: false,
538
+ error: new CustomGeoLocationError({
539
+ code: 0,
540
+ message: "Geolocation is not supported by this environment."
541
+ })
542
+ }));
543
+ return false;
544
+ }
545
+ return true;
546
+ }, []);
547
+ const handleSuccess = (0, import_react17.useCallback)((position) => {
548
+ const { coords } = position;
549
+ setState((prev) => ({
550
+ ...prev,
551
+ loading: false,
552
+ error: null,
553
+ data: {
554
+ latitude: coords.latitude,
555
+ longitude: coords.longitude,
556
+ accuracy: coords.accuracy,
557
+ altitude: coords.altitude,
558
+ altitudeAccuracy: coords.altitudeAccuracy,
559
+ heading: coords.heading,
560
+ speed: coords.speed,
561
+ timestamp: position.timestamp
562
+ }
563
+ }));
564
+ }, []);
565
+ const handleError = (0, import_react17.useCallback)((error) => {
566
+ const { code, message } = error;
567
+ setState((prev) => ({
568
+ ...prev,
569
+ loading: false,
570
+ error: new CustomGeoLocationError({ code, message })
571
+ }));
572
+ }, []);
573
+ const getGeolocationOptions = (0, import_react17.useCallback)(
574
+ () => ({
575
+ enableHighAccuracy: options?.enableHighAccuracy,
576
+ maximumAge: options?.maximumAge,
577
+ timeout: options?.timeout
578
+ }),
579
+ [options?.enableHighAccuracy, options?.maximumAge, options?.timeout]
580
+ );
581
+ const getCurrentPosition = (0, import_react17.useCallback)(() => {
582
+ if (!checkGeolocationSupport()) {
583
+ return;
584
+ }
585
+ setState((prev) => ({ ...prev, loading: true }));
586
+ navigator.geolocation.getCurrentPosition(handleSuccess, handleError, getGeolocationOptions());
587
+ }, [handleSuccess, handleError, getGeolocationOptions, checkGeolocationSupport]);
588
+ const startTracking = (0, import_react17.useCallback)(() => {
589
+ if (!checkGeolocationSupport()) {
590
+ return;
591
+ }
592
+ if (watchIdRef.current !== null) {
593
+ navigator.geolocation.clearWatch(watchIdRef.current);
594
+ }
595
+ setState((prev) => ({ ...prev, loading: true }));
596
+ watchIdRef.current = navigator.geolocation.watchPosition(
597
+ (position) => {
598
+ setIsTracking(true);
599
+ handleSuccess(position);
600
+ },
601
+ handleError,
602
+ getGeolocationOptions()
603
+ );
604
+ }, [handleSuccess, handleError, getGeolocationOptions, checkGeolocationSupport]);
605
+ const stopTracking = (0, import_react17.useCallback)(() => {
606
+ if (watchIdRef.current === null) {
607
+ return;
608
+ }
609
+ navigator.geolocation.clearWatch(watchIdRef.current);
610
+ watchIdRef.current = null;
611
+ setIsTracking(false);
612
+ }, []);
613
+ (0, import_react17.useEffect)(() => {
614
+ if (options?.mountBehavior === GeolocationMountBehavior.WATCH) {
615
+ startTracking();
616
+ } else if (options?.mountBehavior === GeolocationMountBehavior.GET) {
617
+ getCurrentPosition();
618
+ }
619
+ return () => {
620
+ if (watchIdRef.current !== null) {
621
+ navigator.geolocation.clearWatch(watchIdRef.current);
622
+ watchIdRef.current = null;
623
+ }
624
+ };
625
+ }, [options?.mountBehavior, getCurrentPosition, startTracking]);
626
+ return {
627
+ ...state,
628
+ getCurrentPosition,
629
+ startTracking,
630
+ stopTracking,
631
+ isTracking
632
+ };
633
+ }
634
+
447
635
  // src/hooks/useInputState/useInputState.ts
448
- var import_react14 = require("react");
636
+ var import_react18 = require("react");
449
637
  function useInputState(initialValue = "", transformValue = echo) {
450
- const [value, setValue] = (0, import_react14.useState)(initialValue);
451
- const handleValueChange = (0, import_react14.useCallback)(
638
+ const [value, setValue] = (0, import_react18.useState)(initialValue);
639
+ const handleValueChange = (0, import_react18.useCallback)(
452
640
  ({ target: { value: value2 } }) => {
453
641
  setValue(transformValue(value2));
454
642
  },
@@ -461,18 +649,18 @@ function echo(v) {
461
649
  }
462
650
 
463
651
  // src/hooks/useInterval/useInterval.ts
464
- var import_react15 = require("react");
652
+ var import_react19 = require("react");
465
653
  function useInterval(callback, options) {
466
654
  const delay = typeof options === "number" ? options : options.delay;
467
655
  const immediate = typeof options === "number" ? false : options.immediate;
468
656
  const enabled = typeof options === "number" ? true : options.enabled ?? true;
469
657
  const preservedCallback = usePreservedCallback(callback);
470
- (0, import_react15.useEffect)(() => {
658
+ (0, import_react19.useEffect)(() => {
471
659
  if (immediate === true && enabled) {
472
660
  preservedCallback();
473
661
  }
474
662
  }, [immediate, preservedCallback, enabled]);
475
- (0, import_react15.useEffect)(() => {
663
+ (0, import_react19.useEffect)(() => {
476
664
  if (!enabled) {
477
665
  return;
478
666
  }
@@ -481,12 +669,17 @@ function useInterval(callback, options) {
481
669
  }, [delay, preservedCallback, enabled]);
482
670
  }
483
671
 
672
+ // src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts
673
+ var import_react20 = require("react");
674
+ var isServer = typeof window === "undefined";
675
+ var useIsomorphicLayoutEffect = isServer ? import_react20.useEffect : import_react20.useLayoutEffect;
676
+
484
677
  // src/hooks/useLoading/useLoading.ts
485
- var import_react16 = require("react");
678
+ var import_react21 = require("react");
486
679
  function useLoading() {
487
- const [loading, setLoading] = (0, import_react16.useState)(false);
680
+ const [loading, setLoading] = (0, import_react21.useState)(false);
488
681
  const ref = useIsMountedRef();
489
- const startTransition = (0, import_react16.useCallback)(
682
+ const startTransition = (0, import_react21.useCallback)(
490
683
  async (promise) => {
491
684
  try {
492
685
  setLoading(true);
@@ -500,11 +693,11 @@ function useLoading() {
500
693
  },
501
694
  [ref.isMounted]
502
695
  );
503
- return (0, import_react16.useMemo)(() => [loading, startTransition], [loading, startTransition]);
696
+ return (0, import_react21.useMemo)(() => [loading, startTransition], [loading, startTransition]);
504
697
  }
505
698
  function useIsMountedRef() {
506
- const ref = (0, import_react16.useRef)({ isMounted: true }).current;
507
- (0, import_react16.useEffect)(() => {
699
+ const ref = (0, import_react21.useRef)({ isMounted: true }).current;
700
+ (0, import_react21.useEffect)(() => {
508
701
  ref.isMounted = true;
509
702
  return () => {
510
703
  ref.isMounted = false;
@@ -513,10 +706,138 @@ function useIsMountedRef() {
513
706
  return ref;
514
707
  }
515
708
 
709
+ // src/hooks/useLongPress/useLongPress.ts
710
+ var import_react22 = require("react");
711
+ function useLongPress(onLongPress, { delay = 500, moveThreshold, onClick, onLongPressEnd } = {}) {
712
+ const timeoutRef = (0, import_react22.useRef)(null);
713
+ const isLongPressActiveRef = (0, import_react22.useRef)(false);
714
+ const initialPositionRef = (0, import_react22.useRef)({ x: 0, y: 0 });
715
+ const preservedOnLongPress = usePreservedCallback(onLongPress);
716
+ const preservedOnClick = usePreservedCallback(onClick || (() => {
717
+ }));
718
+ const preservedOnLongPressEnd = usePreservedCallback(onLongPressEnd || (() => {
719
+ }));
720
+ const hasThreshold = moveThreshold?.x !== void 0 || moveThreshold?.y !== void 0;
721
+ const getClientPosition = (0, import_react22.useCallback)((event) => {
722
+ if ("touches" in event.nativeEvent) {
723
+ const touch = event.nativeEvent.touches[0];
724
+ return { x: touch.clientX, y: touch.clientY };
725
+ }
726
+ return {
727
+ x: event.nativeEvent.clientX,
728
+ y: event.nativeEvent.clientY
729
+ };
730
+ }, []);
731
+ const isMovedBeyondThreshold = (0, import_react22.useCallback)(
732
+ (event) => {
733
+ const { x, y } = getClientPosition(event);
734
+ const deltaX = Math.abs(x - initialPositionRef.current.x);
735
+ const deltaY = Math.abs(y - initialPositionRef.current.y);
736
+ return moveThreshold?.x !== void 0 && deltaX > moveThreshold.x || moveThreshold?.y !== void 0 && deltaY > moveThreshold.y;
737
+ },
738
+ [getClientPosition, moveThreshold]
739
+ );
740
+ const cancelLongPress = (0, import_react22.useCallback)(() => {
741
+ if (timeoutRef.current !== null) {
742
+ window.clearTimeout(timeoutRef.current);
743
+ timeoutRef.current = null;
744
+ }
745
+ }, []);
746
+ const handlePressStart = (0, import_react22.useCallback)(
747
+ (event) => {
748
+ cancelLongPress();
749
+ const position = getClientPosition(event);
750
+ initialPositionRef.current = position;
751
+ isLongPressActiveRef.current = false;
752
+ timeoutRef.current = window.setTimeout(() => {
753
+ isLongPressActiveRef.current = true;
754
+ preservedOnLongPress(event);
755
+ }, delay);
756
+ },
757
+ [cancelLongPress, delay, getClientPosition, preservedOnLongPress]
758
+ );
759
+ const handlePressEnd = (0, import_react22.useCallback)(
760
+ (event) => {
761
+ if (isLongPressActiveRef.current) {
762
+ preservedOnLongPressEnd(event);
763
+ } else if (timeoutRef.current !== null) {
764
+ preservedOnClick(event);
765
+ }
766
+ cancelLongPress();
767
+ isLongPressActiveRef.current = false;
768
+ },
769
+ [cancelLongPress, preservedOnClick, preservedOnLongPressEnd]
770
+ );
771
+ const handlePressMove = (0, import_react22.useCallback)(
772
+ (event) => {
773
+ if (timeoutRef.current !== null && isMovedBeyondThreshold(event)) {
774
+ cancelLongPress();
775
+ }
776
+ },
777
+ [cancelLongPress, isMovedBeyondThreshold]
778
+ );
779
+ return {
780
+ onMouseDown: handlePressStart,
781
+ onMouseUp: handlePressEnd,
782
+ onMouseLeave: cancelLongPress,
783
+ onTouchStart: handlePressStart,
784
+ onTouchEnd: handlePressEnd,
785
+ ...hasThreshold ? { onTouchMove: handlePressMove, onMouseMove: handlePressMove } : {}
786
+ };
787
+ }
788
+
789
+ // src/hooks/useMap/useMap.ts
790
+ var import_react24 = require("react");
791
+
792
+ // src/hooks/usePreservedReference/usePreservedReference.ts
793
+ var import_react23 = require("react");
794
+ function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
795
+ const ref = (0, import_react23.useRef)(value);
796
+ return (0, import_react23.useMemo)(() => {
797
+ if (!areValuesEqual(ref.current, value)) {
798
+ ref.current = value;
799
+ }
800
+ return ref.current;
801
+ }, [areValuesEqual, value]);
802
+ }
803
+ function areDeeplyEqual(x, y) {
804
+ return JSON.stringify(x) === JSON.stringify(y);
805
+ }
806
+
807
+ // src/hooks/useMap/useMap.ts
808
+ function useMap(initialState = /* @__PURE__ */ new Map()) {
809
+ const [map, setMap] = (0, import_react24.useState)(() => new Map(initialState));
810
+ const preservedInitialState = usePreservedReference(initialState);
811
+ const set = (0, import_react24.useCallback)((key, value) => {
812
+ setMap((prev) => {
813
+ const nextMap = new Map(prev);
814
+ nextMap.set(key, value);
815
+ return nextMap;
816
+ });
817
+ }, []);
818
+ const setAll = (0, import_react24.useCallback)((entries) => {
819
+ setMap(() => new Map(entries));
820
+ }, []);
821
+ const remove = (0, import_react24.useCallback)((key) => {
822
+ setMap((prev) => {
823
+ const nextMap = new Map(prev);
824
+ nextMap.delete(key);
825
+ return nextMap;
826
+ });
827
+ }, []);
828
+ const reset = (0, import_react24.useCallback)(() => {
829
+ setMap(() => new Map(preservedInitialState));
830
+ }, [preservedInitialState]);
831
+ const actions = (0, import_react24.useMemo)(() => {
832
+ return { set, setAll, remove, reset };
833
+ }, [set, setAll, remove, reset]);
834
+ return [map, actions];
835
+ }
836
+
516
837
  // src/hooks/useOutsideClickEffect/useOutsideClickEffect.ts
517
- var import_react17 = require("react");
838
+ var import_react25 = require("react");
518
839
  function useOutsideClickEffect(container, callback) {
519
- const containers = (0, import_react17.useRef)([]);
840
+ const containers = (0, import_react25.useRef)([]);
520
841
  const handleDocumentClick = usePreservedCallback(({ target }) => {
521
842
  if (target === null) {
522
843
  return;
@@ -529,10 +850,10 @@ function useOutsideClickEffect(container, callback) {
529
850
  }
530
851
  callback();
531
852
  });
532
- (0, import_react17.useEffect)(() => {
853
+ (0, import_react25.useEffect)(() => {
533
854
  containers.current = [container].flat(1).filter((item) => item != null);
534
855
  }, [container]);
535
- (0, import_react17.useEffect)(() => {
856
+ (0, import_react25.useEffect)(() => {
536
857
  document.addEventListener("click", handleDocumentClick);
537
858
  return () => {
538
859
  document.removeEventListener("click", handleDocumentClick);
@@ -540,28 +861,13 @@ function useOutsideClickEffect(container, callback) {
540
861
  }, [handleDocumentClick]);
541
862
  }
542
863
 
543
- // src/hooks/usePreservedReference/usePreservedReference.ts
544
- var import_react18 = require("react");
545
- function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
546
- const ref = (0, import_react18.useRef)(value);
547
- return (0, import_react18.useMemo)(() => {
548
- if (!areValuesEqual(ref.current, value)) {
549
- ref.current = value;
550
- }
551
- return ref.current;
552
- }, [areValuesEqual, value]);
553
- }
554
- function areDeeplyEqual(x, y) {
555
- return JSON.stringify(x) === JSON.stringify(y);
556
- }
557
-
558
864
  // src/hooks/usePrevious/usePrevious.ts
559
- var import_react19 = require("react");
865
+ var import_react26 = require("react");
560
866
  var strictEquals = (prev, next) => prev === next;
561
867
  function usePrevious(state, compare = strictEquals) {
562
- const prevRef = (0, import_react19.useRef)(state);
563
- const currentRef = (0, import_react19.useRef)(state);
564
- const isFirstRender = (0, import_react19.useRef)(true);
868
+ const prevRef = (0, import_react26.useRef)(state);
869
+ const currentRef = (0, import_react26.useRef)(state);
870
+ const isFirstRender = (0, import_react26.useRef)(true);
565
871
  if (isFirstRender.current) {
566
872
  isFirstRender.current = false;
567
873
  return prevRef.current;
@@ -574,7 +880,7 @@ function usePrevious(state, compare = strictEquals) {
574
880
  }
575
881
 
576
882
  // src/hooks/useStorageState/useStorageState.ts
577
- var import_react20 = require("react");
883
+ var import_react27 = require("react");
578
884
 
579
885
  // src/hooks/useStorageState/storage.ts
580
886
  var MemoStorage = class {
@@ -686,11 +992,11 @@ function useStorageState(key, {
686
992
  ...options
687
993
  } = {}) {
688
994
  const serializedDefaultValue = defaultValue;
689
- const cache = (0, import_react20.useRef)({
995
+ const cache = (0, import_react27.useRef)({
690
996
  data: null,
691
997
  parsed: serializedDefaultValue
692
998
  });
693
- const getSnapshot = (0, import_react20.useCallback)(() => {
999
+ const getSnapshot = (0, import_react27.useCallback)(() => {
694
1000
  const deserializer = "deserializer" in options ? options.deserializer : JSON.parse;
695
1001
  const data = storage.get(key);
696
1002
  if (data !== cache.current.data) {
@@ -703,7 +1009,7 @@ function useStorageState(key, {
703
1009
  }
704
1010
  return cache.current.parsed;
705
1011
  }, [defaultValue, key, storage]);
706
- const storageState = (0, import_react20.useSyncExternalStore)(
1012
+ const storageState = (0, import_react27.useSyncExternalStore)(
707
1013
  (onStoreChange) => {
708
1014
  listeners.add(onStoreChange);
709
1015
  const handler = (event) => {
@@ -720,7 +1026,7 @@ function useStorageState(key, {
720
1026
  () => getSnapshot(),
721
1027
  () => serializedDefaultValue
722
1028
  );
723
- const setStorageState = (0, import_react20.useCallback)(
1029
+ const setStorageState = (0, import_react27.useCallback)(
724
1030
  (value) => {
725
1031
  const serializer = "serializer" in options ? options.serializer : JSON.stringify;
726
1032
  const nextValue = typeof value === "function" ? value(getSnapshot()) : value;
@@ -733,14 +1039,14 @@ function useStorageState(key, {
733
1039
  },
734
1040
  [getSnapshot, key, storage]
735
1041
  );
736
- const refreshStorageState = (0, import_react20.useCallback)(() => {
1042
+ const refreshStorageState = (0, import_react27.useCallback)(() => {
737
1043
  setStorageState(getSnapshot());
738
1044
  }, [storage, getSnapshot, setStorageState]);
739
1045
  return ensureSerializable([storageState, setStorageState, refreshStorageState]);
740
1046
  }
741
1047
 
742
1048
  // src/hooks/useThrottle/useThrottle.ts
743
- var import_react21 = require("react");
1049
+ var import_react28 = require("react");
744
1050
 
745
1051
  // src/hooks/useThrottle/throttle.ts
746
1052
  function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
@@ -765,11 +1071,11 @@ function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
765
1071
  function useThrottle(callback, wait, options) {
766
1072
  const preservedCallback = usePreservedCallback(callback);
767
1073
  const preservedOptions = usePreservedReference(options ?? {});
768
- const throttledCallback = (0, import_react21.useMemo)(
1074
+ const throttledCallback = (0, import_react28.useMemo)(
769
1075
  () => throttle(preservedCallback, wait, preservedOptions),
770
1076
  [preservedOptions, preservedCallback, wait]
771
1077
  );
772
- (0, import_react21.useEffect)(() => {
1078
+ (0, import_react28.useEffect)(() => {
773
1079
  return () => {
774
1080
  throttledCallback.cancel();
775
1081
  };
@@ -778,29 +1084,29 @@ function useThrottle(callback, wait, options) {
778
1084
  }
779
1085
 
780
1086
  // src/hooks/useTimeout/useTimeout.ts
781
- var import_react22 = require("react");
1087
+ var import_react29 = require("react");
782
1088
  function useTimeout(callback, delay = 0) {
783
1089
  const preservedCallback = usePreservedCallback(callback);
784
- (0, import_react22.useEffect)(() => {
1090
+ (0, import_react29.useEffect)(() => {
785
1091
  const timeoutId = window.setTimeout(preservedCallback, delay);
786
1092
  return () => window.clearTimeout(timeoutId);
787
1093
  }, [delay, preservedCallback]);
788
1094
  }
789
1095
 
790
1096
  // src/hooks/useToggle/useToggle.ts
791
- var import_react23 = require("react");
1097
+ var import_react30 = require("react");
792
1098
  function useToggle(initialValue = false) {
793
- return (0, import_react23.useReducer)(toggle, initialValue);
1099
+ return (0, import_react30.useReducer)(toggle, initialValue);
794
1100
  }
795
1101
  var toggle = (state) => !state;
796
1102
 
797
1103
  // src/utils/buildContext/buildContext.tsx
798
- var import_react24 = require("react");
1104
+ var import_react31 = require("react");
799
1105
  var import_jsx_runtime3 = require("react/jsx-runtime");
800
1106
  function buildContext(contextName, defaultContextValues) {
801
- const Context = (0, import_react24.createContext)(defaultContextValues ?? void 0);
1107
+ const Context = (0, import_react31.createContext)(defaultContextValues ?? void 0);
802
1108
  function Provider({ children, ...contextValues }) {
803
- const value = (0, import_react24.useMemo)(
1109
+ const value = (0, import_react31.useMemo)(
804
1110
  () => Object.keys(contextValues).length > 0 ? contextValues : null,
805
1111
  // eslint-disable-next-line react-hooks/exhaustive-deps
806
1112
  [...Object.values(contextValues)]
@@ -808,7 +1114,7 @@ function buildContext(contextName, defaultContextValues) {
808
1114
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Context.Provider, { value, children });
809
1115
  }
810
1116
  function useInnerContext() {
811
- const context = (0, import_react24.useContext)(Context);
1117
+ const context = (0, import_react31.useContext)(Context);
812
1118
  if (context != null) {
813
1119
  return context;
814
1120
  }
@@ -819,23 +1125,72 @@ function buildContext(contextName, defaultContextValues) {
819
1125
  }
820
1126
  return [Provider, useInnerContext];
821
1127
  }
1128
+
1129
+ // src/utils/mergeProps/mergeProps.ts
1130
+ function mergeProps(...props) {
1131
+ return props.reduce(pushProp, {});
1132
+ }
1133
+ function pushProp(prev, curr) {
1134
+ for (const key in curr) {
1135
+ if (curr[key] === void 0) continue;
1136
+ switch (key) {
1137
+ case "className": {
1138
+ prev[key] = [prev[key], curr[key]].join(" ").trim();
1139
+ break;
1140
+ }
1141
+ case "style": {
1142
+ prev[key] = mergeStyle(prev[key], curr[key]);
1143
+ break;
1144
+ }
1145
+ default: {
1146
+ const mergedFunction = mergeFunction(prev[key], curr[key]);
1147
+ if (mergedFunction) {
1148
+ prev[key] = mergedFunction;
1149
+ } else if (curr[key] !== void 0) {
1150
+ prev[key] = curr[key];
1151
+ }
1152
+ }
1153
+ }
1154
+ }
1155
+ return prev;
1156
+ }
1157
+ function mergeStyle(a, b) {
1158
+ if (a == null) return b;
1159
+ return { ...a, ...b };
1160
+ }
1161
+ function mergeFunction(a, b) {
1162
+ if (typeof a === "function" && typeof b === "function") {
1163
+ return (...args) => {
1164
+ a(...args);
1165
+ b(...args);
1166
+ };
1167
+ }
1168
+ }
822
1169
  // Annotate the CommonJS export names for ESM import in node:
823
1170
  0 && (module.exports = {
824
1171
  ImpressionArea,
825
1172
  Separated,
826
1173
  SwitchCase,
827
1174
  buildContext,
1175
+ mergeProps,
828
1176
  mergeRefs,
829
1177
  useAsyncEffect,
830
1178
  useBooleanState,
831
1179
  useCallbackOncePerRender,
1180
+ useControlledState,
832
1181
  useCounter,
833
1182
  useDebounce,
1183
+ useDebouncedCallback,
1184
+ useDoubleClick,
1185
+ useGeolocation,
834
1186
  useImpressionRef,
835
1187
  useInputState,
836
1188
  useIntersectionObserver,
837
1189
  useInterval,
1190
+ useIsomorphicLayoutEffect,
838
1191
  useLoading,
1192
+ useLongPress,
1193
+ useMap,
839
1194
  useOutsideClickEffect,
840
1195
  usePreservedCallback,
841
1196
  usePreservedReference,