@reactuses/core 6.1.1 → 6.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,11 @@
1
- # reactuse
1
+ <p align="center">
2
+ <a href="https://github.com/your-username/your-repo#gh-light-mode-only">
3
+ <img src="https://reactuse.com/img/og.png#gh-light-mode-only" alt="ReactUse - Collection of essential React Hooks" width="300">
4
+ </a>
5
+ <a href="https://github.com/your-username/your-repo#gh-dark-mode-only">
6
+ <img src="https://reactuse.com/img/og-dark.png#gh-dark-mode-only" alt="ReactUse - Collection of essential React Hooks" width="300">
7
+ </a>
8
+ </p>
2
9
 
3
10
  <p align="center">
4
11
  <img alt="NPM Version" src="https://img.shields.io/npm/v/@reactuses/core?style=for-the-badge&labelColor=24292e">
@@ -8,14 +15,6 @@
8
15
  <img alt="TypeScript Support" src="https://img.shields.io/badge/TypeScript-Support-blue?style=for-the-badge&labelColor=24292e">
9
16
  </p>
10
17
 
11
- ```bash
12
- npm i @reactuses/core
13
- ```
14
-
15
- **Collection of essential React Hooks Utilities.**
16
-
17
- ---
18
-
19
18
  ## MCP Support
20
19
 
21
20
  If you want to use the MCP (Model Context Protocol) integration with reactuse, you can easily set it up with the following configuration. This allows you to run the `@reactuses/mcp` utility via `npx` for enhanced command-line support and automation.
package/dist/index.cjs CHANGED
@@ -1401,8 +1401,8 @@ function _async_to_generator$5(fn) {
1401
1401
  });
1402
1402
  };
1403
1403
  }
1404
- function _extends$3() {
1405
- _extends$3 = Object.assign || function(target) {
1404
+ function _extends$4() {
1405
+ _extends$4 = Object.assign || function(target) {
1406
1406
  for(var i = 1; i < arguments.length; i++){
1407
1407
  var source = arguments[i];
1408
1408
  for(var key in source){
@@ -1413,7 +1413,7 @@ function _extends$3() {
1413
1413
  }
1414
1414
  return target;
1415
1415
  };
1416
- return _extends$3.apply(this, arguments);
1416
+ return _extends$4.apply(this, arguments);
1417
1417
  }
1418
1418
  const DEFAULT_OPTIONS = {
1419
1419
  multiple: true,
@@ -1442,7 +1442,7 @@ const useFileDialog = (options = defaultOptions$1)=>{
1442
1442
  if (!inputRef.current) {
1443
1443
  return;
1444
1444
  }
1445
- const _options = _extends$3({}, DEFAULT_OPTIONS, options, localOptions);
1445
+ const _options = _extends$4({}, DEFAULT_OPTIONS, options, localOptions);
1446
1446
  inputRef.current.multiple = _options.multiple;
1447
1447
  inputRef.current.accept = _options.accept;
1448
1448
  // Only set capture attribute if it's explicitly provided
@@ -1880,8 +1880,8 @@ function _async_to_generator$4(fn) {
1880
1880
  });
1881
1881
  };
1882
1882
  }
1883
- function _extends$2() {
1884
- _extends$2 = Object.assign || function(target) {
1883
+ function _extends$3() {
1884
+ _extends$3 = Object.assign || function(target) {
1885
1885
  for(var i = 1; i < arguments.length; i++){
1886
1886
  var source = arguments[i];
1887
1887
  for(var key in source){
@@ -1892,15 +1892,15 @@ function _extends$2() {
1892
1892
  }
1893
1893
  return target;
1894
1894
  };
1895
- return _extends$2.apply(this, arguments);
1895
+ return _extends$3.apply(this, arguments);
1896
1896
  }
1897
1897
  const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
1898
1898
  const savedLoadMore = useLatest(onLoadMore);
1899
1899
  var _options_direction;
1900
1900
  const direction = (_options_direction = options.direction) != null ? _options_direction : 'bottom';
1901
1901
  var _options_distance;
1902
- const state = useScroll(target, _extends$2({}, options, {
1903
- offset: _extends$2({
1902
+ const state = useScroll(target, _extends$3({}, options, {
1903
+ offset: _extends$3({
1904
1904
  [direction]: (_options_distance = options.distance) != null ? _options_distance : 0
1905
1905
  }, options.offset)
1906
1906
  }));
@@ -2627,6 +2627,131 @@ function getValue(position) {
2627
2627
  return getComputedStyle(document.documentElement).getPropertyValue(position);
2628
2628
  }
2629
2629
 
2630
+ function _extends$2() {
2631
+ _extends$2 = Object.assign || function(target) {
2632
+ for(var i = 1; i < arguments.length; i++){
2633
+ var source = arguments[i];
2634
+ for(var key in source){
2635
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2636
+ target[key] = source[key];
2637
+ }
2638
+ }
2639
+ }
2640
+ return target;
2641
+ };
2642
+ return _extends$2.apply(this, arguments);
2643
+ }
2644
+ const initialState = {
2645
+ isScratching: false
2646
+ };
2647
+ const useScratch = (target, options = {})=>{
2648
+ const { disabled = false } = options;
2649
+ const [state, setState] = useRafState(initialState);
2650
+ const optionsRef = useLatest(options);
2651
+ const refState = React.useRef(state);
2652
+ const refScratching = React.useRef(false);
2653
+ const refAnimationFrame = React.useRef(null);
2654
+ const onMoveEvent = (docX, docY)=>{
2655
+ if (!refScratching.current) {
2656
+ return;
2657
+ }
2658
+ const el = getTargetElement(target);
2659
+ if (!el) {
2660
+ return;
2661
+ }
2662
+ if (refAnimationFrame.current !== null) {
2663
+ cancelAnimationFrame(refAnimationFrame.current);
2664
+ }
2665
+ refAnimationFrame.current = requestAnimationFrame(()=>{
2666
+ const { left, top } = el.getBoundingClientRect();
2667
+ const elX = left + window.scrollX;
2668
+ const elY = top + window.scrollY;
2669
+ const x = docX - elX;
2670
+ const y = docY - elY;
2671
+ setState((oldState)=>{
2672
+ const newState = _extends$2({}, oldState, {
2673
+ x,
2674
+ y,
2675
+ dx: x - (oldState.x || 0),
2676
+ dy: y - (oldState.y || 0),
2677
+ end: Date.now(),
2678
+ isScratching: true
2679
+ });
2680
+ refState.current = newState;
2681
+ (optionsRef.current.onScratch || noop)(newState);
2682
+ return newState;
2683
+ });
2684
+ });
2685
+ };
2686
+ const stopScratching = ()=>{
2687
+ if (!refScratching.current) {
2688
+ return;
2689
+ }
2690
+ refScratching.current = false;
2691
+ const endState = _extends$2({}, refState.current, {
2692
+ isScratching: false
2693
+ });
2694
+ refState.current = endState;
2695
+ (optionsRef.current.onScratchEnd || noop)(endState);
2696
+ setState(endState);
2697
+ };
2698
+ const startScratching = (docX, docY)=>{
2699
+ const el = getTargetElement(target);
2700
+ if (disabled || !el) {
2701
+ return;
2702
+ }
2703
+ refScratching.current = true;
2704
+ const { left, top } = el.getBoundingClientRect();
2705
+ const elX = left + window.scrollX;
2706
+ const elY = top + window.scrollY;
2707
+ const x = docX - elX;
2708
+ const y = docY - elY;
2709
+ const time = Date.now();
2710
+ const newState = {
2711
+ isScratching: true,
2712
+ start: time,
2713
+ end: time,
2714
+ docX,
2715
+ docY,
2716
+ x,
2717
+ y,
2718
+ dx: 0,
2719
+ dy: 0,
2720
+ elH: el.offsetHeight,
2721
+ elW: el.offsetWidth,
2722
+ elX,
2723
+ elY,
2724
+ posX: elX,
2725
+ posY: elY
2726
+ };
2727
+ refState.current = newState;
2728
+ (optionsRef.current.onScratchStart || noop)(newState);
2729
+ setState(newState);
2730
+ };
2731
+ useEventListener('mousedown', (event)=>{
2732
+ event.preventDefault();
2733
+ startScratching(event.pageX || event.clientX, event.pageY || event.clientY);
2734
+ }, target);
2735
+ useEventListener('touchstart', (event)=>{
2736
+ event.preventDefault();
2737
+ startScratching(event.changedTouches[0].pageX || event.changedTouches[0].clientX, event.changedTouches[0].pageY || event.changedTouches[0].clientY);
2738
+ }, target);
2739
+ useEventListener('mousemove', (event)=>{
2740
+ onMoveEvent(event.pageX || event.clientX, event.pageY || event.clientY);
2741
+ }, defaultWindow);
2742
+ useEventListener('touchmove', (event)=>{
2743
+ onMoveEvent(event.changedTouches[0].pageX || event.changedTouches[0].clientX, event.changedTouches[0].pageY || event.changedTouches[0].clientY);
2744
+ }, defaultWindow);
2745
+ useEventListener('mouseup', stopScratching, defaultWindow);
2746
+ useEventListener('touchend', stopScratching, defaultWindow);
2747
+ useUnmount(()=>{
2748
+ if (refAnimationFrame.current !== null) {
2749
+ cancelAnimationFrame(refAnimationFrame.current);
2750
+ }
2751
+ });
2752
+ return state;
2753
+ };
2754
+
2630
2755
  const useScriptTag = (src, onLoaded = noop, options = defaultOptions$1)=>{
2631
2756
  const { immediate = true, manual = false, type = 'text/javascript', async = true, crossOrigin, referrerPolicy, noModule, defer, attrs = {} } = options;
2632
2757
  const scriptTag = React.useRef(null);
@@ -4397,6 +4522,7 @@ exports.useRafFn = useRafFn;
4397
4522
  exports.useRafState = useRafState;
4398
4523
  exports.useReducedMotion = useReducedMotion;
4399
4524
  exports.useResizeObserver = useResizeObserver;
4525
+ exports.useScratch = useScratch;
4400
4526
  exports.useScreenSafeArea = useScreenSafeArea;
4401
4527
  exports.useScriptTag = useScriptTag;
4402
4528
  exports.useScroll = useScroll;