@aiszlab/relax 1.2.68 → 1.2.70

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.
@@ -31,7 +31,7 @@ var Scroller = /*#__PURE__*/function () {
31
31
  var _scroller = {
32
32
  _: null
33
33
  };
34
- var scrollTo = function scrollTo(target, to) {
34
+ var _scrollTo = function scrollTo(target, to) {
35
35
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
36
36
  duration: 0,
37
37
  direction: "vertical"
@@ -62,11 +62,11 @@ var scrollTo = function scrollTo(target, to) {
62
62
  target[currentAtProperty] = currentAt + step;
63
63
  // over end, stop any animation
64
64
  if (target[currentAtProperty] === to) return;
65
- scrollTo(target, to, {
65
+ _scrollTo(target, to, {
66
66
  duration: duration - 10,
67
67
  direction: direction
68
68
  });
69
69
  }));
70
70
  };
71
71
 
72
- export { scrollTo };
72
+ export { _scrollTo as scrollTo };
@@ -1,17 +1,18 @@
1
1
  import { type Dispatch, type SetStateAction } from "react";
2
- import type { State } from "../types";
3
- interface Props<T> {
2
+ import type { State, RequiredTo } from "../types";
3
+ type UseControlledStateBy<T> = {
4
4
  /**
5
5
  * @description
6
6
  * default value
7
7
  */
8
8
  defaultState?: State<T>;
9
- }
9
+ };
10
+ type UsedControlledState<T, R> = R extends undefined ? [T, Dispatch<SetStateAction<T>>] : [RequiredTo<T>, Dispatch<SetStateAction<RequiredTo<T>>>];
10
11
  /**
11
12
  * @author murukal
12
13
  *
13
14
  * @description
14
15
  * controlled state
15
16
  */
16
- export declare const useControlledState: <T>(controlledState: T, { defaultState }?: Props<T>) => [T, Dispatch<SetStateAction<T>>];
17
+ export declare const useControlledState: <T, R extends T>(controlledState: T, { defaultState }?: UseControlledStateBy<R>) => UsedControlledState<T, R>;
17
18
  export {};
@@ -34,6 +34,7 @@ var useControlledState = function useControlledState(controlledState) {
34
34
  }, [controlledState]);
35
35
  /// use controlled
36
36
  var state = !isUndefined(controlledState) ? controlledState : _state;
37
+ // @ts-ignore
37
38
  return [state, _setState];
38
39
  };
39
40
 
@@ -1,6 +1,9 @@
1
+ import { type HTMLAttributeReferrerPolicy } from "react";
1
2
  type Status = "none" | "loading" | "error" | "loaded";
2
3
  interface Props {
3
- src: string;
4
+ src?: string;
5
+ crossOrigin?: string;
6
+ referrerPolicy?: HTMLAttributeReferrerPolicy;
4
7
  }
5
8
  /**
6
9
  * @author murukal
@@ -8,5 +11,5 @@ interface Props {
8
11
  * @description
9
12
  * image loader
10
13
  */
11
- export declare const useImageLoader: ({ src }: Props) => Status;
14
+ export declare const useImageLoader: ({ src, crossOrigin, referrerPolicy }: Props) => Status;
12
15
  export {};
@@ -9,7 +9,10 @@ import { Observable } from 'rxjs';
9
9
  * image loader
10
10
  */
11
11
  var useImageLoader = function useImageLoader(_ref) {
12
- var src = _ref.src;
12
+ var src = _ref.src,
13
+ crossOrigin = _ref.crossOrigin,
14
+ _ref$referrerPolicy = _ref.referrerPolicy,
15
+ referrerPolicy = _ref$referrerPolicy === void 0 ? "no-referrer" : _ref$referrerPolicy;
13
16
  var loader = useRef();
14
17
  var _useState = useState("none"),
15
18
  _useState2 = _slicedToArray(_useState, 2),
@@ -34,20 +37,26 @@ var useImageLoader = function useImageLoader(_ref) {
34
37
  return setStatus("error");
35
38
  }
36
39
  });
37
- var image = new Image();
38
- image.addEventListener("load", function () {
40
+ var load = function load() {
39
41
  var _loader$current;
40
42
  (_loader$current = loader.current) === null || _loader$current === void 0 || _loader$current.complete();
41
- });
42
- image.addEventListener("error", function () {
43
+ };
44
+ var error = function error() {
43
45
  var _loader$current2;
44
46
  (_loader$current2 = loader.current) === null || _loader$current2 === void 0 || _loader$current2.error(null);
45
- });
47
+ };
48
+ var image = new Image();
49
+ image.addEventListener("load", load);
50
+ image.addEventListener("error", error);
51
+ image.crossOrigin = crossOrigin !== null && crossOrigin !== void 0 ? crossOrigin : null;
52
+ image.referrerPolicy = referrerPolicy;
46
53
  image.src = src;
47
54
  return function () {
55
+ image.removeEventListener("load", load);
56
+ image.removeEventListener("error", error);
48
57
  image.remove();
49
58
  };
50
- }, [src]);
59
+ }, [src, crossOrigin, referrerPolicy]);
51
60
  return status;
52
61
  };
53
62
 
@@ -1,5 +1,5 @@
1
1
  import { useRef, useCallback } from 'react';
2
- import { scrollTo } from '../dom/scroll-to.js';
2
+ import { scrollTo as _scrollTo } from '../dom/scroll-to.js';
3
3
 
4
4
  /**
5
5
  * @description
@@ -11,12 +11,12 @@ var useScrollable = function useScrollable() {
11
11
  direction = _ref$direction === void 0 ? "vertical" : _ref$direction;
12
12
  var targetRef = useRef(null);
13
13
  var triggerRefs = useRef(new Map());
14
- var scrollTo$1 = useCallback(function (to) {
14
+ var scrollTo = useCallback(function (to) {
15
15
  var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
16
16
  var target = targetRef.current;
17
17
  if (!target) return;
18
18
  // use animated scroll
19
- scrollTo(target, to, {
19
+ _scrollTo(target, to, {
20
20
  duration: duration,
21
21
  direction: direction
22
22
  });
@@ -34,7 +34,7 @@ var useScrollable = function useScrollable() {
34
34
  return {
35
35
  targetRef: targetRef,
36
36
  triggerRefs: triggerRefs,
37
- scrollTo: scrollTo$1,
37
+ scrollTo: scrollTo,
38
38
  to: to,
39
39
  setTrigger: setTrigger
40
40
  };
@@ -7,3 +7,4 @@ export type { First } from "./first";
7
7
  export type { Last } from "./last";
8
8
  export type { State, StateGetter } from "./state";
9
9
  export type { Arrayable } from "./arrayable";
10
+ export type { RequiredTo } from "./required-to";
@@ -0,0 +1 @@
1
+ export type RequiredTo<T> = Exclude<T, undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.68",
3
+ "version": "1.2.70",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,30 +22,30 @@
22
22
  "test": "jest"
23
23
  },
24
24
  "dependencies": {
25
- "@babel/runtime": "^7.24.8",
26
- "react-is": "^18.2.0",
25
+ "@babel/runtime": "^7.25.0",
26
+ "react-is": "^18.3.1",
27
27
  "rxjs": "^7.8.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@babel/core": "^7.24.9",
30
+ "@babel/core": "^7.25.2",
31
31
  "@babel/plugin-transform-runtime": "^7.24.7",
32
- "@babel/preset-env": "^7.24.8",
32
+ "@babel/preset-env": "^7.25.3",
33
33
  "@babel/preset-react": "^7.24.7",
34
34
  "@babel/preset-typescript": "^7.24.7",
35
35
  "@jest/globals": "^29.7.0",
36
36
  "@rollup/plugin-babel": "^6.0.4",
37
- "@rollup/plugin-node-resolve": "^15.1.0",
37
+ "@rollup/plugin-node-resolve": "^15.2.3",
38
38
  "@rollup/plugin-typescript": "^11.1.6",
39
39
  "@testing-library/react": "^16.0.0",
40
- "@types/react": "^18",
41
- "@types/react-dom": "^18",
42
- "@types/react-is": "^18",
40
+ "@types/react": "^18.3.3",
41
+ "@types/react-dom": "^18.3.0",
42
+ "@types/react-is": "^18.3.0",
43
43
  "jest": "^29.7.0",
44
44
  "jest-environment-jsdom": "^29.7.0",
45
- "react": "18",
46
- "react-dom": "18",
47
- "rollup": "^4.19.0",
48
- "typescript": "5.5.3"
45
+ "react": "^18.3.1",
46
+ "react-dom": "^18.3.1",
47
+ "rollup": "^4.20.0",
48
+ "typescript": "5.5.4"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "react": "18",