@aiszlab/relax 1.2.37 → 1.2.39

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 (122) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -0
  2. package/dist/dom/contains.js +20 -0
  3. package/dist/dom/index.js +2 -0
  4. package/dist/dom/scroll-to.js +69 -0
  5. package/dist/hooks/use-boolean.js +34 -0
  6. package/dist/hooks/use-controlled-state.js +40 -0
  7. package/dist/hooks/use-counter.js +60 -0
  8. package/dist/hooks/use-debounce-callback.js +81 -0
  9. package/dist/hooks/use-default.js +14 -0
  10. package/dist/hooks/use-event.js +12 -0
  11. package/dist/hooks/use-focus.js +31 -0
  12. package/dist/hooks/use-force-update.js +21 -0
  13. package/dist/hooks/use-hover.js +25 -0
  14. package/dist/hooks/use-image-loader.js +54 -0
  15. package/dist/hooks/use-memorable.js +14 -0
  16. package/dist/hooks/use-mount.js +16 -0
  17. package/dist/hooks/use-mounted.js +16 -0
  18. package/dist/hooks/use-refs.js +25 -0
  19. package/dist/hooks/use-scroll-locker.js +92 -0
  20. package/dist/hooks/use-scrollable.js +43 -0
  21. package/dist/hooks/use-throttle-callback.d.ts +3 -3
  22. package/dist/hooks/use-throttle-callback.js +83 -0
  23. package/dist/hooks/use-timeout.js +19 -0
  24. package/dist/hooks/use-toggleable.js +186 -0
  25. package/dist/hooks/use-update-effect.js +19 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +43 -0
  28. package/dist/is/is-array.js +9 -0
  29. package/dist/is/is-complex.js +11 -0
  30. package/dist/is/is-dom-usable.js +9 -0
  31. package/dist/is/is-empty.js +25 -0
  32. package/dist/is/is-function.js +9 -0
  33. package/dist/is/is-mobile.js +13 -0
  34. package/dist/is/is-null.js +9 -0
  35. package/dist/is/is-overflow.js +14 -0
  36. package/dist/is/is-refable.js +34 -0
  37. package/dist/is/is-state-getter.js +9 -0
  38. package/dist/is/is-style-element.js +9 -0
  39. package/dist/is/is-thenable/index.js +9 -0
  40. package/dist/is/is-thenable/index.test.d.ts +1 -0
  41. package/dist/is/is-undefined.js +9 -0
  42. package/dist/is/is-void.js +12 -0
  43. package/dist/utils/{chain.d.ts → chain/index.d.ts} +1 -1
  44. package/dist/utils/chain/index.js +15 -0
  45. package/dist/utils/chain/index.test.d.ts +1 -0
  46. package/dist/utils/{clamp.mjs → clamp/index.js} +2 -2
  47. package/dist/utils/clamp/index.test.d.ts +1 -0
  48. package/dist/utils/clone/index.test.d.ts +1 -0
  49. package/dist/utils/debounce/index.d.ts +23 -0
  50. package/dist/utils/debounce/index.js +32 -0
  51. package/dist/utils/debounce/index.test.d.ts +1 -0
  52. package/dist/utils/{effect.d.ts → effect/index.d.ts} +1 -1
  53. package/dist/utils/effect/index.js +16 -0
  54. package/dist/utils/effect/index.test.d.ts +1 -0
  55. package/dist/utils/exclude/index.d.ts +7 -0
  56. package/dist/utils/exclude/index.js +14 -0
  57. package/dist/utils/exclude/index.test.d.ts +1 -0
  58. package/dist/utils/range.js +16 -0
  59. package/dist/utils/set-style.js +21 -0
  60. package/dist/utils/{throttle.d.ts → throttle/index.d.ts} +3 -3
  61. package/dist/utils/throttle/index.js +32 -0
  62. package/dist/utils/throttle/index.test.d.ts +1 -0
  63. package/dist/utils/to-array/index.d.ts +18 -0
  64. package/dist/utils/to-array/index.js +25 -0
  65. package/dist/utils/to-array/index.test.d.ts +1 -0
  66. package/dist/utils/to-function.js +13 -0
  67. package/dist/utils/unique.js +16 -0
  68. package/dist/utils/waitable/index.d.ts +36 -0
  69. package/dist/utils/waitable/index.js +90 -0
  70. package/package.json +9 -6
  71. package/dist/dom/contains.mjs +0 -20
  72. package/dist/dom/index.mjs +0 -2
  73. package/dist/dom/scroll-to.mjs +0 -53
  74. package/dist/hooks/use-boolean.mjs +0 -22
  75. package/dist/hooks/use-controlled-state.mjs +0 -37
  76. package/dist/hooks/use-counter.mjs +0 -33
  77. package/dist/hooks/use-debounce-callback.mjs +0 -57
  78. package/dist/hooks/use-default.mjs +0 -14
  79. package/dist/hooks/use-event.mjs +0 -10
  80. package/dist/hooks/use-focus.mjs +0 -16
  81. package/dist/hooks/use-force-update.mjs +0 -15
  82. package/dist/hooks/use-hover.mjs +0 -16
  83. package/dist/hooks/use-image-loader.mjs +0 -41
  84. package/dist/hooks/use-memorable.mjs +0 -14
  85. package/dist/hooks/use-mount.mjs +0 -16
  86. package/dist/hooks/use-mounted.mjs +0 -16
  87. package/dist/hooks/use-refs.mjs +0 -23
  88. package/dist/hooks/use-scroll-locker.mjs +0 -79
  89. package/dist/hooks/use-scrollable.mjs +0 -41
  90. package/dist/hooks/use-throttle-callback.mjs +0 -57
  91. package/dist/hooks/use-timeout.mjs +0 -20
  92. package/dist/hooks/use-toggleable.mjs +0 -145
  93. package/dist/hooks/use-update-effect.mjs +0 -20
  94. package/dist/index.mjs +0 -42
  95. package/dist/is/is-array.mjs +0 -9
  96. package/dist/is/is-complex.mjs +0 -9
  97. package/dist/is/is-dom-usable.mjs +0 -9
  98. package/dist/is/is-empty.mjs +0 -25
  99. package/dist/is/is-function.mjs +0 -9
  100. package/dist/is/is-mobile.mjs +0 -16
  101. package/dist/is/is-null.mjs +0 -9
  102. package/dist/is/is-overflow.mjs +0 -14
  103. package/dist/is/is-refable.mjs +0 -33
  104. package/dist/is/is-state-getter.mjs +0 -9
  105. package/dist/is/is-style-element.mjs +0 -9
  106. package/dist/is/is-thenable.mjs +0 -9
  107. package/dist/is/is-undefined.mjs +0 -9
  108. package/dist/is/is-void.mjs +0 -12
  109. package/dist/utils/chain.mjs +0 -9
  110. package/dist/utils/debounce.d.ts +0 -56
  111. package/dist/utils/debounce.mjs +0 -77
  112. package/dist/utils/effect.mjs +0 -18
  113. package/dist/utils/range.mjs +0 -12
  114. package/dist/utils/set-style.mjs +0 -17
  115. package/dist/utils/throttle.mjs +0 -17
  116. package/dist/utils/to-array.d.ts +0 -5
  117. package/dist/utils/to-array.mjs +0 -12
  118. package/dist/utils/to-function.mjs +0 -11
  119. package/dist/utils/unique.mjs +0 -16
  120. /package/dist/is/{is-thenable.d.ts → is-thenable/index.d.ts} +0 -0
  121. /package/dist/utils/{clamp.d.ts → clamp/index.d.ts} +0 -0
  122. /package/dist/utils/{clone.d.ts → clone/index.d.ts} +0 -0
@@ -0,0 +1,25 @@
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
+ ref.current = trigger;
10
+ };
11
+ var useRefs = function useRefs() {
12
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
13
+ refs[_key] = arguments[_key];
14
+ }
15
+ return useMemo(function () {
16
+ return function (trigger) {
17
+ refs.forEach(function (ref) {
18
+ if (!ref) return;
19
+ mount(ref, trigger);
20
+ });
21
+ };
22
+ }, refs);
23
+ };
24
+
25
+ export { useRefs };
@@ -0,0 +1,92 @@
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 };
@@ -0,0 +1,43 @@
1
+ import { useRef, useCallback } from 'react';
2
+ import { scrollTo } from '../dom/scroll-to.js';
3
+
4
+ /**
5
+ * @description
6
+ * scrollable hook
7
+ */
8
+ var useScrollable = function useScrollable() {
9
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
10
+ _ref$direction = _ref.direction,
11
+ direction = _ref$direction === void 0 ? 'vertical' : _ref$direction;
12
+ var targetRef = useRef(null);
13
+ var triggerRefs = useRef(new Map());
14
+ var scrollTo$1 = useCallback(function (to) {
15
+ var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
16
+ var target = targetRef.current;
17
+ if (!target) return;
18
+ // use animated scroll
19
+ scrollTo(target, to, {
20
+ duration: duration,
21
+ direction: direction
22
+ });
23
+ }, [direction]);
24
+ var to = useCallback(function (key) {
25
+ var trigger = triggerRefs.current.get(key);
26
+ if (!trigger) return 0;
27
+ // different direction, use different property
28
+ return direction === 'vertical' ? trigger.offsetTop : trigger.offsetLeft;
29
+ }, [direction]);
30
+ /// set trigger
31
+ var setTrigger = useCallback(function (key, trigger) {
32
+ triggerRefs.current.set(key, trigger);
33
+ }, []);
34
+ return {
35
+ targetRef: targetRef,
36
+ triggerRefs: triggerRefs,
37
+ scrollTo: scrollTo$1,
38
+ to: to,
39
+ setTrigger: setTrigger
40
+ };
41
+ };
42
+
43
+ export { useScrollable };
@@ -7,12 +7,12 @@ import { type Callable } from './use-event';
7
7
  * throttle callback
8
8
  *
9
9
  * @param callback
10
- * @param duration number
10
+ * @param wait number
11
11
  * @description
12
- * The duration time (in milliseconds) until the throttle function is called.
12
+ * The wait time (in milliseconds) until the throttle function is called.
13
13
  * default 1000
14
14
  *
15
15
  * @example
16
16
  * 1000
17
17
  */
18
- export declare const useThrottleCallback: <T extends Callable, R extends unknown[] = Parameters<T>>(throttler: T | Throttler<T, R>, duration?: number) => Throttled<T>;
18
+ export declare const useThrottleCallback: <T extends Callable, R extends unknown[] = Parameters<T>>(throttler: T | Throttler<T, R>, wait?: number) => Throttled<T>;
@@ -0,0 +1,83 @@
1
+ import { useRef, useEffect, useMemo } from 'react';
2
+ import { throttle } from '../utils/throttle/index.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 useThrottler = function useThrottler(throttler) {
8
+ var _useMemo = useMemo(function () {
9
+ return isFunction(throttler) ? {
10
+ callback: throttler,
11
+ pipe: null
12
+ } : throttler;
13
+ }, [throttler]),
14
+ callback = _useMemo.callback,
15
+ pipe = _useMemo.pipe;
16
+ return {
17
+ callback: useEvent(function () {
18
+ return callback.apply(void 0, arguments);
19
+ }),
20
+ pipe: useEvent(function () {
21
+ var _pipe;
22
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
23
+ args[_key] = arguments[_key];
24
+ }
25
+ return (_pipe = pipe === null || pipe === void 0 ? void 0 : pipe.apply(void 0, args)) !== null && _pipe !== void 0 ? _pipe : args;
26
+ })
27
+ };
28
+ };
29
+ /**
30
+ * @author murukal
31
+ *
32
+ * @description
33
+ * throttle callback
34
+ *
35
+ * @param callback
36
+ * @param wait number
37
+ * @description
38
+ * The wait time (in milliseconds) until the throttle function is called.
39
+ * default 1000
40
+ *
41
+ * @example
42
+ * 1000
43
+ */
44
+ var useThrottleCallback = function useThrottleCallback(throttler) {
45
+ var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
46
+ var throttled = useRef(null);
47
+ var _useThrottler = useThrottler(throttler),
48
+ callback = _useThrottler.callback,
49
+ pipe = _useThrottler.pipe;
50
+ useEffect(function () {
51
+ var _throttled = throttle({
52
+ callback: callback,
53
+ pipe: pipe
54
+ }, wait);
55
+ throttled.current = _throttled;
56
+ // dispose
57
+ return function () {
58
+ _throttled.abort();
59
+ throttled.current = null;
60
+ };
61
+ }, [wait]);
62
+ return useDefault(function () {
63
+ return {
64
+ next: function next() {
65
+ var _throttled$current;
66
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
67
+ args[_key2] = arguments[_key2];
68
+ }
69
+ return (_throttled$current = throttled.current) === null || _throttled$current === void 0 ? void 0 : _throttled$current.next.apply(_throttled$current, args);
70
+ },
71
+ flush: function flush() {
72
+ var _throttled$current2;
73
+ return (_throttled$current2 = throttled.current) === null || _throttled$current2 === void 0 ? void 0 : _throttled$current2.flush();
74
+ },
75
+ abort: function abort() {
76
+ var _throttled$current3;
77
+ return (_throttled$current3 = throttled.current) === null || _throttled$current3 === void 0 ? void 0 : _throttled$current3.abort();
78
+ }
79
+ };
80
+ });
81
+ };
82
+
83
+ export { useThrottleCallback };
@@ -0,0 +1,19 @@
1
+ import { useEffect } from 'react';
2
+
3
+ /**
4
+ * @author murukal
5
+ *
6
+ * @description
7
+ * timeout effect
8
+ */
9
+ var useTimeout = function useTimeout(handler, wait) {
10
+ useEffect(function () {
11
+ var timer = setTimeout(handler, wait);
12
+ return function () {
13
+ if (!timer) return;
14
+ clearTimeout(timer);
15
+ };
16
+ }, [wait]);
17
+ };
18
+
19
+ export { useTimeout };
@@ -0,0 +1,186 @@
1
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, createClass as _createClass, classPrivateFieldGet2 as _classPrivateFieldGet2, classCallCheck as _classCallCheck, classPrivateFieldInitSpec as _classPrivateFieldInitSpec, classPrivateFieldSet2 as _classPrivateFieldSet2 } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { useMemo, useCallback } from 'react';
3
+ import { useControlledState } from './use-controlled-state.js';
4
+
5
+ var _excluded = ["onToggle"];
6
+ var _groupedLeaves = /*#__PURE__*/new WeakMap();
7
+ var Tree = /*#__PURE__*/function () {
8
+ function Tree() {
9
+ _classCallCheck(this, Tree);
10
+ _classPrivateFieldInitSpec(this, _groupedLeaves, void 0);
11
+ _classPrivateFieldSet2(_groupedLeaves, this, new Map());
12
+ }
13
+ return _createClass(Tree, [{
14
+ key: "groupedLeaves",
15
+ get: function get() {
16
+ return _classPrivateFieldGet2(_groupedLeaves, this);
17
+ }
18
+ }, {
19
+ key: "grow",
20
+ value: function grow(toggleableKey) {
21
+ // create leaf, leaf will auto trigger tree collect callback
22
+ new Leaf({
23
+ key: toggleableKey.key,
24
+ parent: null,
25
+ belongTo: this
26
+ }).grow(toggleableKey.children);
27
+ return this;
28
+ }
29
+ }, {
30
+ key: "collect",
31
+ value: function collect(leaf) {
32
+ _classPrivateFieldGet2(_groupedLeaves, this).has(leaf.key) ? _classPrivateFieldGet2(_groupedLeaves, this).get(leaf.key).add(leaf) : _classPrivateFieldGet2(_groupedLeaves, this).set(leaf.key, new Set([leaf]));
33
+ }
34
+ }, {
35
+ key: "toggle",
36
+ value: function toggle(key, toggledKeys) {
37
+ var hasToggled = toggledKeys.has(key);
38
+ var _isToggled = !hasToggled;
39
+ return this.toggleBy(key, _isToggled, toggledKeys);
40
+ }
41
+ }, {
42
+ key: "toggleBy",
43
+ value: function toggleBy(key, isToggled, toggledKeys) {
44
+ var _classPrivateFieldGet2$1;
45
+ return Array.from((_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_groupedLeaves, this).get(key)) !== null && _classPrivateFieldGet2$1 !== void 0 ? _classPrivateFieldGet2$1 : []).reduce(function (prev, leaf) {
46
+ // deep fall, add or remove child key
47
+ var fell = leaf.fall(isToggled, prev);
48
+ // deep rise, add or remove parent key
49
+ var rised = leaf.rise(fell);
50
+ return rised;
51
+ }, new Set(toggledKeys));
52
+ }
53
+ }]);
54
+ }();
55
+ var _key = /*#__PURE__*/new WeakMap();
56
+ var _belongTo = /*#__PURE__*/new WeakMap();
57
+ var _parent = /*#__PURE__*/new WeakMap();
58
+ var _children = /*#__PURE__*/new WeakMap();
59
+ var Leaf = /*#__PURE__*/function () {
60
+ function Leaf(props) {
61
+ _classCallCheck(this, Leaf);
62
+ _classPrivateFieldInitSpec(this, _key, void 0);
63
+ _classPrivateFieldInitSpec(this, _belongTo, void 0);
64
+ _classPrivateFieldInitSpec(this, _parent, void 0);
65
+ _classPrivateFieldInitSpec(this, _children, void 0);
66
+ _classPrivateFieldSet2(_key, this, props.key);
67
+ _classPrivateFieldSet2(_parent, this, props.parent);
68
+ _classPrivateFieldSet2(_belongTo, this, props.belongTo);
69
+ _classPrivateFieldSet2(_children, this, []);
70
+ // when leaf has grew, let tree collect leaf
71
+ _classPrivateFieldGet2(_belongTo, this).collect(this);
72
+ }
73
+ return _createClass(Leaf, [{
74
+ key: "key",
75
+ get: function get() {
76
+ return _classPrivateFieldGet2(_key, this);
77
+ }
78
+ }, {
79
+ key: "grow",
80
+ value: function grow() {
81
+ var _this = this;
82
+ var toggleableKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
83
+ if (toggleableKeys.length > 0) {
84
+ toggleableKeys.forEach(function (_toggleableKey) {
85
+ var child = new Leaf({
86
+ key: _toggleableKey.key,
87
+ parent: _this,
88
+ belongTo: _classPrivateFieldGet2(_belongTo, _this)
89
+ }).grow(_toggleableKey.children);
90
+ _classPrivateFieldGet2(_children, _this).push(child);
91
+ });
92
+ }
93
+ return this;
94
+ }
95
+ }, {
96
+ key: "rise",
97
+ value: function rise(toggledKeys) {
98
+ // if current key is toggled or children is all toggled
99
+ // just add current key into toggled keys
100
+ // else remove current key
101
+ var isToggled = toggledKeys.has(_classPrivateFieldGet2(_key, this)) || _classPrivateFieldGet2(_children, this).every(function (child) {
102
+ return toggledKeys.has(child.key);
103
+ });
104
+ var rised = new Set(toggledKeys);
105
+ if (isToggled) {
106
+ rised.add(_classPrivateFieldGet2(_key, this));
107
+ } else {
108
+ rised["delete"](_classPrivateFieldGet2(_key, this));
109
+ }
110
+ if (_classPrivateFieldGet2(_parent, this)) {
111
+ return _classPrivateFieldGet2(_parent, this).rise(rised);
112
+ }
113
+ return rised;
114
+ }
115
+ }, {
116
+ key: "fall",
117
+ value: function fall(isToggled, toggledKeys) {
118
+ var _this2 = this;
119
+ return _classPrivateFieldGet2(_children, this).reduce(function (prev, leaf) {
120
+ // deep loop, remove or add key
121
+ var fell = leaf.fall(isToggled, prev);
122
+ // toggle true, add key
123
+ // toggle false, remove key
124
+ if (isToggled) {
125
+ fell.add(_classPrivateFieldGet2(_key, _this2));
126
+ } else {
127
+ fell["delete"](_classPrivateFieldGet2(_key, _this2));
128
+ }
129
+ return fell;
130
+ }, new Set(toggledKeys));
131
+ }
132
+ }]);
133
+ }();
134
+ /**
135
+ * @description
136
+ * toggle able
137
+ */
138
+ var useToggleable = function useToggleable(toggleableKeys) {
139
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
140
+ onToggle = _ref.onToggle,
141
+ options = _objectWithoutProperties(_ref, _excluded);
142
+ /// re-create tree when toggleable keys changed
143
+ var tree = useMemo(function () {
144
+ return toggleableKeys.reduce(function (_tree, toggleable) {
145
+ return _tree.grow(toggleable);
146
+ }, new Tree());
147
+ }, [toggleableKeys]);
148
+ /// use controlled state to record toggled keys
149
+ var _useControlledState = useControlledState(options.toggledKeys, {
150
+ defaultState: function defaultState() {
151
+ return options.isDefaultToggled ? Array.from(Array.from(tree.groupedLeaves.values()).reduce(function (prev, leaves) {
152
+ leaves.forEach(function (leaf) {
153
+ return prev.add(leaf.key);
154
+ });
155
+ return prev;
156
+ }, new Set())) : [];
157
+ }
158
+ }),
159
+ _useControlledState2 = _slicedToArray(_useControlledState, 2),
160
+ _toggledKeys = _useControlledState2[0],
161
+ _setToggledKeys = _useControlledState2[1];
162
+ /// use set for toggled keys to make it read-only
163
+ var readableToggledKeys = useMemo(function () {
164
+ return new Set(_toggledKeys);
165
+ }, [_toggledKeys]);
166
+ /// check current key is toggled
167
+ var isToggled = useCallback(function (key) {
168
+ return !readableToggledKeys || readableToggledKeys.has(key);
169
+ }, [readableToggledKeys]);
170
+ /// toggle one key
171
+ var toggle = useCallback(function (key) {
172
+ // get new toggled keys by toggle current key
173
+ var _toggledKeys = Array.from(tree.toggle(key, readableToggledKeys));
174
+ // set state
175
+ _setToggledKeys(_toggledKeys);
176
+ // trigger on toggle callback
177
+ onToggle === null || onToggle === void 0 || onToggle(_toggledKeys);
178
+ }, [tree, readableToggledKeys, _setToggledKeys, onToggle]);
179
+ return {
180
+ toggledKeys: readableToggledKeys,
181
+ isToggled: isToggled,
182
+ toggle: toggle
183
+ };
184
+ };
185
+
186
+ export { useToggleable };
@@ -0,0 +1,19 @@
1
+ import { useRef, useEffect } from 'react';
2
+ import { useMounted } from './use-mounted.js';
3
+ import { effect } from '../utils/effect/index.js';
4
+
5
+ var useUpdateEffect = function useUpdateEffect(callback, deps) {
6
+ var isMounted = useRef(false);
7
+ useEffect(function () {
8
+ if (!isMounted.current) return;
9
+ return effect(callback);
10
+ }, deps);
11
+ useMounted(function () {
12
+ isMounted.current = true;
13
+ return function () {
14
+ isMounted.current = false;
15
+ };
16
+ });
17
+ };
18
+
19
+ export { useUpdateEffect };
package/dist/index.d.ts CHANGED
@@ -52,3 +52,4 @@ export { chain } from './utils/chain';
52
52
  export { debounce } from './utils/debounce';
53
53
  export { toArray } from './utils/to-array';
54
54
  export { toFunction } from './utils/to-function';
55
+ export { exclude } from './utils/exclude';
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ export { useBoolean } from './hooks/use-boolean.js';
2
+ export { useDebounceCallback } from './hooks/use-debounce-callback.js';
3
+ export { useThrottleCallback } from './hooks/use-throttle-callback.js';
4
+ export { useImageLoader } from './hooks/use-image-loader.js';
5
+ export { useMount } from './hooks/use-mount.js';
6
+ export { useMounted } from './hooks/use-mounted.js';
7
+ export { useTimeout } from './hooks/use-timeout.js';
8
+ export { useControlledState } from './hooks/use-controlled-state.js';
9
+ export { useDefault } from './hooks/use-default.js';
10
+ export { useScrollLocker } from './hooks/use-scroll-locker.js';
11
+ export { useForceUpdate } from './hooks/use-force-update.js';
12
+ export { useScrollable } from './hooks/use-scrollable.js';
13
+ export { useRefs } from './hooks/use-refs.js';
14
+ export { useToggleable } from './hooks/use-toggleable.js';
15
+ export { useEvent } from './hooks/use-event.js';
16
+ export { useUpdateEffect } from './hooks/use-update-effect.js';
17
+ export { useCounter } from './hooks/use-counter.js';
18
+ export { useHover } from './hooks/use-hover.js';
19
+ export { useFocus } from './hooks/use-focus.js';
20
+ export { useMemorable } from './hooks/use-memorable.js';
21
+ export { isRefable } from './is/is-refable.js';
22
+ export { isUndefined } from './is/is-undefined.js';
23
+ export { isStateGetter } from './is/is-state-getter.js';
24
+ export { isNull } from './is/is-null.js';
25
+ export { isVoid } from './is/is-void.js';
26
+ export { isArray } from './is/is-array.js';
27
+ export { isComplex } from './is/is-complex.js';
28
+ export { isEmpty } from './is/is-empty.js';
29
+ export { isDomUsable } from './is/is-dom-usable.js';
30
+ export { isMobile } from './is/is-mobile.js';
31
+ export { isOverflow } from './is/is-overflow.js';
32
+ export { isStyleElement } from './is/is-style-element.js';
33
+ export { isFunction } from './is/is-function.js';
34
+ export { isThenable } from './is/is-thenable/index.js';
35
+ export { effect } from './utils/effect/index.js';
36
+ export { unique, uniqueBy } from './utils/unique.js';
37
+ export { range } from './utils/range.js';
38
+ export { clamp } from './utils/clamp/index.js';
39
+ export { chain } from './utils/chain/index.js';
40
+ export { debounce } from './utils/debounce/index.js';
41
+ export { toArray } from './utils/to-array/index.js';
42
+ export { toFunction } from './utils/to-function.js';
43
+ export { exclude } from './utils/exclude/index.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is array
4
+ */
5
+ var isArray = function isArray(value) {
6
+ return Array.isArray(value);
7
+ };
8
+
9
+ export { isArray };
@@ -0,0 +1,11 @@
1
+ import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+
3
+ /**
4
+ * @description
5
+ * complex
6
+ */
7
+ var isComplex = function isComplex(value) {
8
+ return _typeof(value) === 'object' || typeof value === 'function';
9
+ };
10
+
11
+ export { isComplex };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * if there is dom
4
+ */
5
+ var isDomUsable = function isDomUsable() {
6
+ return !!(typeof window !== 'undefined' && window.document && window.document.createElement);
7
+ };
8
+
9
+ export { isDomUsable };
@@ -0,0 +1,25 @@
1
+ import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { isVoid } from './is-void.js';
3
+ import { isArray } from './is-array.js';
4
+
5
+ /**
6
+ * @author murukal
7
+ *
8
+ * @description
9
+ * is empty
10
+ */
11
+ var isEmpty = function isEmpty(value) {
12
+ // null or undefined
13
+ if (isVoid(value)) return true;
14
+ // object
15
+ if (_typeof(value) === 'object') {
16
+ return Object.keys(value).length === 0;
17
+ }
18
+ // array
19
+ if (isArray(value)) {
20
+ return value.length === 0;
21
+ }
22
+ return !!value;
23
+ };
24
+
25
+ export { isEmpty };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * if is function
4
+ */
5
+ var isFunction = function isFunction(value) {
6
+ return typeof value === 'function';
7
+ };
8
+
9
+ export { isFunction };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @description
3
+ * is mobile
4
+ */
5
+ var isMobile = function isMobile() {
6
+ if (typeof navigator === 'undefined' || typeof window === 'undefined') {
7
+ return false;
8
+ }
9
+ var agent = navigator.userAgent || navigator.vendor || window.opera;
10
+ return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substring(0, 4));
11
+ };
12
+
13
+ export { isMobile };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is null
4
+ */
5
+ var isNull = function isNull(value) {
6
+ return value === null;
7
+ };
8
+
9
+ export { isNull };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @description
3
+ * if is overflow
4
+ */
5
+ function isOverflow() {
6
+ var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body;
7
+ if (element === document.body) {
8
+ return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
9
+ }
10
+ // not body
11
+ return element.scrollHeight > element.clientHeight;
12
+ }
13
+
14
+ export { isOverflow };