react-simplikit 0.0.35 → 0.0.37

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