@aiszlab/relax 1.2.55 → 1.2.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/package.json +8 -8
  2. package/dist/__test__/hooks/use-boolean.test.d.ts +0 -4
  3. package/dist/__test__/hooks/use-identity.test.d.ts +0 -4
  4. package/dist/__test__/hooks/use-mount.test.d.ts +0 -4
  5. package/dist/__test__/hooks/use-mounted.test.d.ts +0 -4
  6. package/dist/__test__/hooks/use-timeout.test.d.ts +0 -4
  7. package/dist/__test__/is/is-null.test.d.ts +0 -1
  8. package/dist/__test__/is/is-thenable.test.d.ts +0 -1
  9. package/dist/__test__/utils/chain.test.d.ts +0 -1
  10. package/dist/__test__/utils/clamp.test.d.ts +0 -1
  11. package/dist/__test__/utils/clone.test.d.ts +0 -1
  12. package/dist/__test__/utils/debounce.test.d.ts +0 -1
  13. package/dist/__test__/utils/effect.test.d.ts +0 -1
  14. package/dist/__test__/utils/exclude.test.d.ts +0 -1
  15. package/dist/__test__/utils/throttle.test.d.ts +0 -1
  16. package/dist/__test__/utils/to-array.test.d.ts +0 -1
  17. package/dist/__test__/utils/to-form-data.test.d.ts +0 -1
  18. package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -138
  19. package/dist/dom/contains.d.ts +0 -1
  20. package/dist/dom/contains.js +0 -20
  21. package/dist/dom/index.d.ts +0 -3
  22. package/dist/dom/index.js +0 -2
  23. package/dist/dom/scroll-to.d.ts +0 -19
  24. package/dist/dom/scroll-to.js +0 -69
  25. package/dist/hooks/use-boolean.d.ts +0 -19
  26. package/dist/hooks/use-boolean.js +0 -34
  27. package/dist/hooks/use-controlled-state.d.ts +0 -17
  28. package/dist/hooks/use-controlled-state.js +0 -40
  29. package/dist/hooks/use-counter.d.ts +0 -33
  30. package/dist/hooks/use-counter.js +0 -59
  31. package/dist/hooks/use-debounce-callback.d.ts +0 -18
  32. package/dist/hooks/use-debounce-callback.js +0 -81
  33. package/dist/hooks/use-default.d.ts +0 -8
  34. package/dist/hooks/use-default.js +0 -14
  35. package/dist/hooks/use-device-pixel-ratio.d.ts +0 -6
  36. package/dist/hooks/use-device-pixel-ratio.js +0 -20
  37. package/dist/hooks/use-event.d.ts +0 -2
  38. package/dist/hooks/use-event.js +0 -12
  39. package/dist/hooks/use-focus.d.ts +0 -15
  40. package/dist/hooks/use-focus.js +0 -31
  41. package/dist/hooks/use-force-update.d.ts +0 -7
  42. package/dist/hooks/use-force-update.js +0 -21
  43. package/dist/hooks/use-hover.d.ts +0 -8
  44. package/dist/hooks/use-hover.js +0 -25
  45. package/dist/hooks/use-identity.d.ts +0 -5
  46. package/dist/hooks/use-identity.js +0 -20
  47. package/dist/hooks/use-image-loader.d.ts +0 -12
  48. package/dist/hooks/use-image-loader.js +0 -54
  49. package/dist/hooks/use-media-query.d.ts +0 -7
  50. package/dist/hooks/use-memorable.d.ts +0 -1
  51. package/dist/hooks/use-memorable.js +0 -14
  52. package/dist/hooks/use-mount.d.ts +0 -8
  53. package/dist/hooks/use-mount.js +0 -16
  54. package/dist/hooks/use-mounted.d.ts +0 -8
  55. package/dist/hooks/use-mounted.js +0 -16
  56. package/dist/hooks/use-mutate-observer.d.ts +0 -1
  57. package/dist/hooks/use-mutate-observer.js +0 -28
  58. package/dist/hooks/use-raf.d.ts +0 -7
  59. package/dist/hooks/use-raf.js +0 -26
  60. package/dist/hooks/use-reactive.d.ts +0 -6
  61. package/dist/hooks/use-refs.d.ts +0 -5
  62. package/dist/hooks/use-refs.js +0 -31
  63. package/dist/hooks/use-scroll-locker.d.ts +0 -5
  64. package/dist/hooks/use-scroll-locker.js +0 -92
  65. package/dist/hooks/use-scrollable.d.ts +0 -17
  66. package/dist/hooks/use-scrollable.js +0 -43
  67. package/dist/hooks/use-throttle-callback.d.ts +0 -18
  68. package/dist/hooks/use-throttle-callback.js +0 -83
  69. package/dist/hooks/use-timeout.d.ts +0 -10
  70. package/dist/hooks/use-timeout.js +0 -68
  71. package/dist/hooks/use-toggleable.d.ts +0 -48
  72. package/dist/hooks/use-toggleable.js +0 -186
  73. package/dist/hooks/use-update-effect.d.ts +0 -3
  74. package/dist/hooks/use-update-effect.js +0 -19
  75. package/dist/index.d.ts +0 -61
  76. package/dist/index.js +0 -49
  77. package/dist/is/is-array.d.ts +0 -5
  78. package/dist/is/is-array.js +0 -9
  79. package/dist/is/is-complex.d.ts +0 -5
  80. package/dist/is/is-complex.js +0 -11
  81. package/dist/is/is-dom-usable.d.ts +0 -5
  82. package/dist/is/is-dom-usable.js +0 -9
  83. package/dist/is/is-empty.d.ts +0 -7
  84. package/dist/is/is-empty.js +0 -25
  85. package/dist/is/is-function.d.ts +0 -5
  86. package/dist/is/is-function.js +0 -9
  87. package/dist/is/is-mobile.d.ts +0 -5
  88. package/dist/is/is-mobile.js +0 -13
  89. package/dist/is/is-null.d.ts +0 -5
  90. package/dist/is/is-null.js +0 -9
  91. package/dist/is/is-overflow.d.ts +0 -5
  92. package/dist/is/is-overflow.js +0 -14
  93. package/dist/is/is-pointer-usable.d.ts +0 -5
  94. package/dist/is/is-primitive.d.ts +0 -5
  95. package/dist/is/is-refable.d.ts +0 -5
  96. package/dist/is/is-refable.js +0 -34
  97. package/dist/is/is-state-getter.d.ts +0 -6
  98. package/dist/is/is-state-getter.js +0 -9
  99. package/dist/is/is-style-element.d.ts +0 -5
  100. package/dist/is/is-style-element.js +0 -9
  101. package/dist/is/is-thenable.d.ts +0 -5
  102. package/dist/is/is-thenable.js +0 -9
  103. package/dist/is/is-undefined.d.ts +0 -5
  104. package/dist/is/is-undefined.js +0 -9
  105. package/dist/is/is-void.d.ts +0 -5
  106. package/dist/is/is-void.js +0 -12
  107. package/dist/types/first.d.ts +0 -1
  108. package/dist/types/index.d.ts +0 -8
  109. package/dist/types/last.d.ts +0 -1
  110. package/dist/types/nullable.d.ts +0 -5
  111. package/dist/types/partialable.d.ts +0 -5
  112. package/dist/types/required-in.d.ts +0 -5
  113. package/dist/types/state.d.ts +0 -10
  114. package/dist/types/thenable-effect-callback.d.ts +0 -6
  115. package/dist/types/voidable.d.ts +0 -7
  116. package/dist/utils/chain.d.ts +0 -2
  117. package/dist/utils/chain.js +0 -15
  118. package/dist/utils/clamp.d.ts +0 -9
  119. package/dist/utils/clamp.js +0 -13
  120. package/dist/utils/clone.d.ts +0 -6
  121. package/dist/utils/debounce.d.ts +0 -23
  122. package/dist/utils/debounce.js +0 -32
  123. package/dist/utils/effect.d.ts +0 -7
  124. package/dist/utils/effect.js +0 -16
  125. package/dist/utils/exclude.d.ts +0 -10
  126. package/dist/utils/exclude.js +0 -18
  127. package/dist/utils/range.d.ts +0 -7
  128. package/dist/utils/range.js +0 -16
  129. package/dist/utils/set-style.d.ts +0 -6
  130. package/dist/utils/set-style.js +0 -21
  131. package/dist/utils/throttle.d.ts +0 -5
  132. package/dist/utils/throttle.js +0 -32
  133. package/dist/utils/to-array.d.ts +0 -18
  134. package/dist/utils/to-array.js +0 -25
  135. package/dist/utils/to-form-data.d.ts +0 -5
  136. package/dist/utils/to-form-data.js +0 -27
  137. package/dist/utils/to-function.d.ts +0 -1
  138. package/dist/utils/to-function.js +0 -13
  139. package/dist/utils/unique.d.ts +0 -10
  140. package/dist/utils/unique.js +0 -16
  141. package/dist/utils/waitable.d.ts +0 -36
  142. package/dist/utils/waitable.js +0 -90
@@ -1,81 +0,0 @@
1
- import { useRef, useEffect, useMemo } from 'react';
2
- import { debounce } from '../utils/debounce.js';
3
- import { useEvent } from './use-event.js';
4
- import { isFunction } from '../is/is-function.js';
5
- import { useDefault } from './use-default.js';
6
-
7
- var useDebouncer = function useDebouncer(debouncer) {
8
- var _debouncer = useMemo(function () {
9
- return isFunction(debouncer) ? {
10
- callback: debouncer,
11
- pipe: null
12
- } : debouncer;
13
- }, [debouncer]);
14
- return {
15
- callback: useEvent(function () {
16
- return _debouncer.callback.apply(_debouncer, arguments);
17
- }),
18
- pipe: useEvent(function () {
19
- var _debouncer$pipe, _debouncer$pipe2;
20
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
21
- args[_key] = arguments[_key];
22
- }
23
- return (_debouncer$pipe = (_debouncer$pipe2 = _debouncer.pipe) === null || _debouncer$pipe2 === void 0 ? void 0 : _debouncer$pipe2.call.apply(_debouncer$pipe2, [_debouncer].concat(args))) !== null && _debouncer$pipe !== void 0 ? _debouncer$pipe : args;
24
- })
25
- };
26
- };
27
- /**
28
- * @author murukal
29
- *
30
- * @description
31
- * debounce callback
32
- *
33
- * @param callback
34
- * @param wait number
35
- * @description
36
- * The delay time (in milliseconds) until the debounce function is called.
37
- * default 1000
38
- *
39
- * @example
40
- * 1000
41
- */
42
- var useDebounceCallback = function useDebounceCallback(debouncer) {
43
- var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
44
- var debounced = useRef(null);
45
- var _useDebouncer = useDebouncer(debouncer),
46
- callback = _useDebouncer.callback,
47
- pipe = _useDebouncer.pipe;
48
- useEffect(function () {
49
- var _debounced = debounce({
50
- callback: callback,
51
- pipe: pipe
52
- }, wait);
53
- debounced.current = _debounced;
54
- // dispose
55
- return function () {
56
- _debounced.abort();
57
- debounced.current = null;
58
- };
59
- }, [wait]);
60
- return useDefault(function () {
61
- return {
62
- next: function next() {
63
- var _debounced$current;
64
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
65
- args[_key2] = arguments[_key2];
66
- }
67
- return (_debounced$current = debounced.current) === null || _debounced$current === void 0 ? void 0 : _debounced$current.next.apply(_debounced$current, args);
68
- },
69
- flush: function flush() {
70
- var _debounced$current2;
71
- return (_debounced$current2 = debounced.current) === null || _debounced$current2 === void 0 ? void 0 : _debounced$current2.flush();
72
- },
73
- abort: function abort() {
74
- var _debounced$current3;
75
- return (_debounced$current3 = debounced.current) === null || _debounced$current3 === void 0 ? void 0 : _debounced$current3.abort();
76
- }
77
- };
78
- });
79
- };
80
-
81
- export { useDebounceCallback };
@@ -1,8 +0,0 @@
1
- import type { State } from '../types';
2
- /**
3
- * @author murukal
4
- *
5
- * @description
6
- * state always be same after first render
7
- */
8
- export declare const useDefault: <T>(initialState: State<T>) => T;
@@ -1,14 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { toFunction } from '../utils/to-function.js';
3
-
4
- /**
5
- * @author murukal
6
- *
7
- * @description
8
- * state always be same after first render
9
- */
10
- var useDefault = function useDefault(initialState) {
11
- return useMemo(toFunction(initialState), []);
12
- };
13
-
14
- export { useDefault };
@@ -1,6 +0,0 @@
1
- /**
2
- * @description
3
- * devicePixelRatio
4
- * in different device, ratio
5
- */
6
- export declare const useDevicePixelRatio: () => number;
@@ -1,20 +0,0 @@
1
- import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useState } from 'react';
3
- import { isDomUsable } from '../is/is-dom-usable.js';
4
-
5
- /**
6
- * @description
7
- * devicePixelRatio
8
- * in different device, ratio
9
- */
10
- var useDevicePixelRatio = function useDevicePixelRatio() {
11
- var _useState = useState(function () {
12
- if (!isDomUsable()) return 1;
13
- return window.devicePixelRatio;
14
- }),
15
- _useState2 = _slicedToArray(_useState, 1),
16
- devicePixelRatio = _useState2[0];
17
- return devicePixelRatio;
18
- };
19
-
20
- export { useDevicePixelRatio };
@@ -1,2 +0,0 @@
1
- export type Callable = (...args: any) => any;
2
- export declare const useEvent: <T extends Function | Callable>(callback: T) => T;
@@ -1,12 +0,0 @@
1
- import { useRef, useCallback } from 'react';
2
-
3
- var useEvent = function useEvent(callback) {
4
- var ref = useRef(callback);
5
- ref.current = callback;
6
- // @ts-ignore
7
- return useCallback(function () {
8
- return ref.current.apply(ref, arguments);
9
- }, []);
10
- };
11
-
12
- export { useEvent };
@@ -1,15 +0,0 @@
1
- import { type DOMAttributes } from 'react';
2
- /**
3
- * @description
4
- * hooks for focus
5
- */
6
- type Props<T> = Pick<DOMAttributes<T>, 'onFocus' | 'onBlur'> & {
7
- onFocusChange?: (isFocused: boolean) => void;
8
- };
9
- /**
10
- * @description
11
- * dom attributes
12
- */
13
- type UsedFocus<T> = [boolean, Required<Pick<DOMAttributes<T>, 'onFocus' | 'onBlur'>>];
14
- export declare const useFocus: <T extends Element = Element>(props?: Props<T> | undefined) => UsedFocus<T>;
15
- export {};
@@ -1,31 +0,0 @@
1
- import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useCallback } from 'react';
3
- import { useBoolean } from './use-boolean.js';
4
- import { chain } from '../utils/chain.js';
5
-
6
- var useFocus = function useFocus(props) {
7
- var _useBoolean = useBoolean(false),
8
- _useBoolean2 = _slicedToArray(_useBoolean, 2),
9
- isFocused = _useBoolean2[0],
10
- _useBoolean2$ = _useBoolean2[1],
11
- turnOn = _useBoolean2$.turnOn,
12
- turnOff = _useBoolean2$.turnOff;
13
- var onFocus = useCallback(function (e) {
14
- chain(props === null || props === void 0 ? void 0 : props.onFocus, turnOn, function () {
15
- var _props$onFocusChange;
16
- return props === null || props === void 0 || (_props$onFocusChange = props.onFocusChange) === null || _props$onFocusChange === void 0 ? void 0 : _props$onFocusChange.call(props, true);
17
- })(e);
18
- }, [props === null || props === void 0 ? void 0 : props.onFocus, props === null || props === void 0 ? void 0 : props.onFocusChange]);
19
- var onBlur = useCallback(function (e) {
20
- chain(props === null || props === void 0 ? void 0 : props.onBlur, turnOff, function () {
21
- var _props$onFocusChange2;
22
- return props === null || props === void 0 || (_props$onFocusChange2 = props.onFocusChange) === null || _props$onFocusChange2 === void 0 ? void 0 : _props$onFocusChange2.call(props, false);
23
- })(e);
24
- }, [props === null || props === void 0 ? void 0 : props.onBlur, props === null || props === void 0 ? void 0 : props.onFocusChange]);
25
- return [isFocused, {
26
- onFocus: onFocus,
27
- onBlur: onBlur
28
- }];
29
- };
30
-
31
- export { useFocus };
@@ -1,7 +0,0 @@
1
- type UsedForceUpdate = [number, () => void];
2
- /**
3
- * @description
4
- * force update
5
- */
6
- export declare const useForceUpdate: () => UsedForceUpdate;
7
- export {};
@@ -1,21 +0,0 @@
1
- import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useState, useCallback } from 'react';
3
-
4
- /**
5
- * @description
6
- * force update
7
- */
8
- var useForceUpdate = function useForceUpdate() {
9
- var _useState = useState(1),
10
- _useState2 = _slicedToArray(_useState, 2),
11
- times = _useState2[0],
12
- setTimes = _useState2[1];
13
- var forceUpdate = useCallback(function () {
14
- setTimes(function (prev) {
15
- return prev + 1;
16
- });
17
- }, []);
18
- return [times, forceUpdate];
19
- };
20
-
21
- export { useForceUpdate };
@@ -1,8 +0,0 @@
1
- import { type DOMAttributes } from 'react';
2
- type UseHoverBy<T> = {
3
- onEnter?: DOMAttributes<T>['onPointerEnter'];
4
- onLeave?: DOMAttributes<T>['onPointerLeave'];
5
- };
6
- type UsedHover<T> = [boolean, Required<Pick<DOMAttributes<T>, 'onPointerEnter' | 'onPointerLeave'>>];
7
- export declare const useHover: <T extends Element = Element>(props?: UseHoverBy<T> | undefined) => UsedHover<T>;
8
- export {};
@@ -1,25 +0,0 @@
1
- import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useCallback } from 'react';
3
- import { useBoolean } from './use-boolean.js';
4
- import { chain } from '../utils/chain.js';
5
-
6
- var useHover = function useHover(props) {
7
- var _useBoolean = useBoolean(false),
8
- _useBoolean2 = _slicedToArray(_useBoolean, 2),
9
- isHovered = _useBoolean2[0],
10
- _useBoolean2$ = _useBoolean2[1],
11
- turnOn = _useBoolean2$.turnOn,
12
- turnOff = _useBoolean2$.turnOff;
13
- var onPointerEnter = useCallback(function (e) {
14
- chain(props === null || props === void 0 ? void 0 : props.onEnter, turnOn)(e);
15
- }, [props === null || props === void 0 ? void 0 : props.onEnter]);
16
- var onPointerLeave = useCallback(function (e) {
17
- chain(props === null || props === void 0 ? void 0 : props.onLeave, turnOff)(e);
18
- }, [props === null || props === void 0 ? void 0 : props.onLeave]);
19
- return [isHovered, {
20
- onPointerEnter: onPointerEnter,
21
- onPointerLeave: onPointerLeave
22
- }];
23
- };
24
-
25
- export { useHover };
@@ -1,5 +0,0 @@
1
- /**
2
- * @description
3
- * extends from react `useId`
4
- */
5
- export declare const useIdentity: (signal?: string) => [string, () => string];
@@ -1,20 +0,0 @@
1
- import { useId, useRef, useCallback } from 'react';
2
-
3
- /**
4
- * @description
5
- * extends from react `useId`
6
- */
7
- var useIdentity = function useIdentity() {
8
- var signal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
9
- var id = useId();
10
- var count = useRef(0);
11
- var unique = useCallback(function () {
12
- if (!signal) {
13
- return "".concat(id).concat(count.current++);
14
- }
15
- return "".concat(id).concat(signal, ":").concat(count.current++);
16
- }, []);
17
- return [id, unique];
18
- };
19
-
20
- export { useIdentity };
@@ -1,12 +0,0 @@
1
- type Status = 'none' | 'loading' | 'error' | 'loaded';
2
- interface Props {
3
- src: string;
4
- }
5
- /**
6
- * @author murukal
7
- *
8
- * @description
9
- * image loader
10
- */
11
- export declare const useImageLoader: ({ src }: Props) => Status;
12
- export {};
@@ -1,54 +0,0 @@
1
- import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useRef, useState, useEffect } from 'react';
3
- import { Observable } from 'rxjs';
4
-
5
- /**
6
- * @author murukal
7
- *
8
- * @description
9
- * image loader
10
- */
11
- var useImageLoader = function useImageLoader(_ref) {
12
- var src = _ref.src;
13
- var loader = useRef();
14
- var _useState = useState('none'),
15
- _useState2 = _slicedToArray(_useState, 2),
16
- status = _useState2[0],
17
- setStatus = _useState2[1];
18
- useEffect(function () {
19
- if (!src) {
20
- return setStatus('none');
21
- }
22
- // create observable to listen img status
23
- new Observable(function (subscriber) {
24
- loader.current = subscriber;
25
- subscriber.next();
26
- }).subscribe({
27
- next: function next() {
28
- return setStatus('loading');
29
- },
30
- complete: function complete() {
31
- return setStatus('loaded');
32
- },
33
- error: function error() {
34
- return setStatus('error');
35
- }
36
- });
37
- var image = new Image();
38
- image.addEventListener('load', function () {
39
- var _loader$current;
40
- (_loader$current = loader.current) === null || _loader$current === void 0 || _loader$current.complete();
41
- });
42
- image.addEventListener('error', function () {
43
- var _loader$current2;
44
- (_loader$current2 = loader.current) === null || _loader$current2 === void 0 || _loader$current2.error(null);
45
- });
46
- image.src = src;
47
- return function () {
48
- image.remove();
49
- };
50
- }, [src]);
51
- return status;
52
- };
53
-
54
- export { useImageLoader };
@@ -1,7 +0,0 @@
1
- /**
2
- * @author murukal
3
- * @description 监听浏览器 media 变化,控制状态
4
- *
5
- * media 规则 @media not|only mediatype and (mediafeature and|or|not mediafeature)
6
- */
7
- export declare const useMediaQuery: () => void;
@@ -1 +0,0 @@
1
- export declare const useMemorable: <Value, Condition = unknown[]>(getter: () => Value, condition: Condition, shouldUpdate: (prev: Condition, next: Condition) => boolean) => Value;
@@ -1,14 +0,0 @@
1
- import { useRef } from 'react';
2
-
3
- var useMemorable = function useMemorable(getter, condition, shouldUpdate) {
4
- var cacheRef = useRef(null);
5
- if (cacheRef.current === null || shouldUpdate(cacheRef.current.condition, condition)) {
6
- cacheRef.current = {
7
- value: getter(),
8
- condition: condition
9
- };
10
- }
11
- return cacheRef.current.value;
12
- };
13
-
14
- export { useMemorable };
@@ -1,8 +0,0 @@
1
- import type { ThenableEffectCallback } from '../types';
2
- /**
3
- * @author murukal
4
- *
5
- * @description
6
- * when components will mount
7
- */
8
- export declare const useMount: (callback: ThenableEffectCallback) => void;
@@ -1,16 +0,0 @@
1
- import { useLayoutEffect } from 'react';
2
- import { effect } from '../utils/effect.js';
3
-
4
- /**
5
- * @author murukal
6
- *
7
- * @description
8
- * when components will mount
9
- */
10
- var useMount = function useMount(callback) {
11
- useLayoutEffect(function () {
12
- return effect(callback);
13
- }, []);
14
- };
15
-
16
- export { useMount };
@@ -1,8 +0,0 @@
1
- import type { ThenableEffectCallback } from '../types';
2
- /**
3
- * @author murukal
4
- *
5
- * @description
6
- * when components mounted
7
- */
8
- export declare const useMounted: (callback: ThenableEffectCallback) => void;
@@ -1,16 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { effect } from '../utils/effect.js';
3
-
4
- /**
5
- * @author murukal
6
- *
7
- * @description
8
- * when components mounted
9
- */
10
- var useMounted = function useMounted(callback) {
11
- useEffect(function () {
12
- return effect(callback);
13
- }, []);
14
- };
15
-
16
- export { useMounted };
@@ -1 +0,0 @@
1
- export declare const useMutateObserver: (_elements: HTMLElement | HTMLElement[] | null, _callback: MutationCallback) => void;
@@ -1,28 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { useEvent } from './use-event.js';
3
- import { isDomUsable } from '../is/is-dom-usable.js';
4
- import { toArray } from '../utils/to-array.js';
5
-
6
- var useMutateObserver = function useMutateObserver(_elements, _callback) {
7
- var callback = useEvent(_callback);
8
- useEffect(function () {
9
- if (!isDomUsable() || !_elements) {
10
- return;
11
- }
12
- var elements = toArray(_elements);
13
- var listener = new MutationObserver(callback);
14
- elements.forEach(function (element) {
15
- listener.observe(element, {
16
- subtree: true,
17
- childList: true,
18
- attributeFilter: ['style', 'class']
19
- });
20
- });
21
- return function () {
22
- listener.takeRecords();
23
- listener.disconnect();
24
- };
25
- }, [_elements, callback]);
26
- };
27
-
28
- export { useMutateObserver };
@@ -1,7 +0,0 @@
1
- /**
2
- * @description
3
- * raf
4
- */
5
- export declare const useRaf: (_callback: Function, { timely }?: {
6
- timely?: boolean | undefined;
7
- }) => () => void;
@@ -1,26 +0,0 @@
1
- import { useRef } from 'react';
2
- import { useEvent } from './use-event.js';
3
-
4
- /**
5
- * @description
6
- * raf
7
- */
8
- var useRaf = function useRaf(_callback) {
9
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
10
- _ref$timely = _ref.timely,
11
- timely = _ref$timely === void 0 ? false : _ref$timely;
12
- var callback = useEvent(_callback);
13
- var timed = useRef(null);
14
- var isTimed = useRef(false);
15
- return function () {
16
- if (isTimed.current) return;
17
- isTimed.current = true;
18
- timely && callback();
19
- timed.current = requestAnimationFrame(function () {
20
- isTimed.current = false;
21
- !timely && callback();
22
- });
23
- };
24
- };
25
-
26
- export { useRaf };
@@ -1,6 +0,0 @@
1
- import type { State } from '../types';
2
- /**
3
- * @description
4
- * use reactive
5
- */
6
- export declare const useReactive: <T>(initialState: State<T>) => void;
@@ -1,5 +0,0 @@
1
- import { type MutableRefObject, type RefCallback } from 'react';
2
- import type { Nullable, Voidable } from '../types';
3
- type Refable<T> = RefCallback<T> | MutableRefObject<T> | string;
4
- export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (trigger: T) => void;
5
- export {};
@@ -1,31 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { isFunction } from '../is/is-function.js';
3
-
4
- var mount = function mount(ref, trigger) {
5
- if (isFunction(ref)) {
6
- ref(trigger);
7
- return;
8
- }
9
- // in deprecated react, class component can use string ref
10
- // but there are many problems, in relax, we just make it not work
11
- // issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
12
- if (typeof ref === 'string') {
13
- return;
14
- }
15
- ref.current = trigger;
16
- };
17
- var useRefs = function useRefs() {
18
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
19
- refs[_key] = arguments[_key];
20
- }
21
- return useMemo(function () {
22
- return function (trigger) {
23
- refs.forEach(function (ref) {
24
- if (!ref) return;
25
- mount(ref, trigger);
26
- });
27
- };
28
- }, refs);
29
- };
30
-
31
- export { useRefs };
@@ -1,5 +0,0 @@
1
- /**
2
- * @description
3
- * hooks
4
- */
5
- export declare const useScrollLocker: (isLock?: boolean) => void;
@@ -1,92 +0,0 @@
1
- import { createClass as _createClass, classPrivateFieldGet2 as _classPrivateFieldGet2, classPrivateFieldSet2 as _classPrivateFieldSet2, classCallCheck as _classCallCheck, classPrivateFieldInitSpec as _classPrivateFieldInitSpec } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useLayoutEffect } from 'react';
3
- import { isOverflow } from '../is/is-overflow.js';
4
- import { setStyle } from '../utils/set-style.js';
5
-
6
- var _barSize = /*#__PURE__*/new WeakMap();
7
- var _locked = /*#__PURE__*/new WeakMap();
8
- var ScrollLocker = /*#__PURE__*/function () {
9
- function ScrollLocker() {
10
- var _scrollLocker$_;
11
- _classCallCheck(this, ScrollLocker);
12
- // bar size
13
- _classPrivateFieldInitSpec(this, _barSize, null);
14
- // locked elements, with previous styles
15
- _classPrivateFieldInitSpec(this, _locked, new Map());
16
- return (_scrollLocker$_ = _scrollLocker._) !== null && _scrollLocker$_ !== void 0 ? _scrollLocker$_ : _scrollLocker._ = this;
17
- }
18
- return _createClass(ScrollLocker, [{
19
- key: "barSize",
20
- get: function get() {
21
- if (_classPrivateFieldGet2(_barSize, this)) return _classPrivateFieldGet2(_barSize, this);
22
- // how to calculate dom scroll bar size
23
- // create a backend dom element, set force scrollable
24
- var _target = document.createElement('div');
25
- _target.attributeStyleMap.set('position', 'absolute');
26
- _target.attributeStyleMap.set('left', '0');
27
- _target.attributeStyleMap.set('top', '0');
28
- _target.attributeStyleMap.set('width', '100vw');
29
- _target.attributeStyleMap.set('height', '100vh');
30
- _target.attributeStyleMap.set('overflow', 'scroll');
31
- // calculate, then clear
32
- document.body.appendChild(_target);
33
- _classPrivateFieldSet2(_barSize, this, {
34
- width: _target.offsetWidth - _target.clientWidth,
35
- height: _target.offsetHeight - _target.clientHeight
36
- });
37
- document.body.removeChild(_target);
38
- return _classPrivateFieldGet2(_barSize, this);
39
- }
40
- }, {
41
- key: "isOverflow",
42
- get: function get() {
43
- return isOverflow();
44
- }
45
- }, {
46
- key: "lock",
47
- value: function lock() {
48
- var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body;
49
- // if locked, do not lock again
50
- if (_classPrivateFieldGet2(_locked, this).has(element)) return;
51
- // if target is not scrollable, do not lock
52
- if (!isOverflow(element)) return;
53
- _classPrivateFieldGet2(_locked, this).set(element, setStyle(element, {
54
- overflow: 'hidden',
55
- width: "calc(100% - ".concat(this.barSize.width, "px)")
56
- }));
57
- }
58
- }, {
59
- key: "unlock",
60
- value: function unlock() {
61
- var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body;
62
- // not locked, no need to unlock
63
- if (!_classPrivateFieldGet2(_locked, this).has(element)) return;
64
- // reset style, in lock, some styled are setted
65
- setStyle(element, _classPrivateFieldGet2(_locked, this).get(element));
66
- _classPrivateFieldGet2(_locked, this)["delete"](element);
67
- }
68
- }]);
69
- }();
70
- /**
71
- * @description
72
- * hooks
73
- */
74
- // singleton mode
75
- var _scrollLocker = {
76
- _: null
77
- };
78
- var useScrollLocker = function useScrollLocker(isLock) {
79
- useLayoutEffect(function () {
80
- var scrollLocker = new ScrollLocker();
81
- if (!!isLock) {
82
- scrollLocker.lock(document.body);
83
- } else {
84
- scrollLocker.unlock(document.body);
85
- }
86
- return function () {
87
- scrollLocker.unlock(document.body);
88
- };
89
- }, [!!isLock]);
90
- };
91
-
92
- export { useScrollLocker };