@aiszlab/relax 1.2.44 → 1.2.45
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/dist/__test__/is/is-null.test.d.ts +1 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js +4 -1
- package/dist/hooks/use-device-pixel-ratio.d.ts +6 -0
- package/dist/hooks/use-device-pixel-ratio.js +16 -0
- package/dist/hooks/use-mutate-observer.d.ts +1 -0
- package/dist/hooks/use-mutate-observer.js +28 -0
- package/dist/hooks/use-raf.d.ts +7 -0
- package/dist/hooks/use-raf.js +25 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -56,7 +56,10 @@ function _iterableToArrayLimit(r, l) {
|
|
|
56
56
|
f = !0,
|
|
57
57
|
o = !1;
|
|
58
58
|
try {
|
|
59
|
-
if (i = (t = t.call(r)).next, 0 === l)
|
|
59
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
60
|
+
if (Object(t) !== t) return;
|
|
61
|
+
f = !1;
|
|
62
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
60
63
|
} catch (r) {
|
|
61
64
|
o = !0, n = r;
|
|
62
65
|
} finally {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* devicePixelRatio
|
|
7
|
+
* in different device, ratio
|
|
8
|
+
*/
|
|
9
|
+
var useDevicePixelRatio = function useDevicePixelRatio() {
|
|
10
|
+
var _useState = useState(window.devicePixelRatio),
|
|
11
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
12
|
+
devicePixelRatio = _useState2[0];
|
|
13
|
+
return devicePixelRatio;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useDevicePixelRatio };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useMutateObserver: (_elements: HTMLElement | HTMLElement[] | null, _callback: MutationCallback) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 };
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
!timely && callback();
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { useRaf };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export { useCounter } from './hooks/use-counter';
|
|
|
22
22
|
export { useHover } from './hooks/use-hover';
|
|
23
23
|
export { useFocus } from './hooks/use-focus';
|
|
24
24
|
export { useMemorable } from './hooks/use-memorable';
|
|
25
|
+
export { useMutateObserver } from './hooks/use-mutate-observer';
|
|
26
|
+
export { useRaf } from './hooks/use-raf';
|
|
27
|
+
export { useDevicePixelRatio } from './hooks/use-device-pixel-ratio';
|
|
25
28
|
/**
|
|
26
29
|
* @description
|
|
27
30
|
* is
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,9 @@ export { useCounter } from './hooks/use-counter.js';
|
|
|
18
18
|
export { useHover } from './hooks/use-hover.js';
|
|
19
19
|
export { useFocus } from './hooks/use-focus.js';
|
|
20
20
|
export { useMemorable } from './hooks/use-memorable.js';
|
|
21
|
+
export { useMutateObserver } from './hooks/use-mutate-observer.js';
|
|
22
|
+
export { useRaf } from './hooks/use-raf.js';
|
|
23
|
+
export { useDevicePixelRatio } from './hooks/use-device-pixel-ratio.js';
|
|
21
24
|
export { isRefable } from './is/is-refable.js';
|
|
22
25
|
export { isUndefined } from './is/is-undefined.js';
|
|
23
26
|
export { isStateGetter } from './is/is-state-getter.js';
|