@xanui/core 1.3.0 → 1.3.2
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/Transition/index.cjs +22 -9
- package/Transition/index.cjs.map +1 -1
- package/Transition/index.d.ts +1 -1
- package/Transition/index.js +22 -9
- package/Transition/index.js.map +1 -1
- package/Transition/variants.cjs +30 -29
- package/Transition/variants.cjs.map +1 -1
- package/Transition/variants.d.ts +14 -14
- package/Transition/variants.js +30 -29
- package/Transition/variants.js.map +1 -1
- package/animate/index.cjs +2 -1
- package/animate/index.cjs.map +1 -1
- package/animate/index.d.ts +1 -1
- package/animate/index.js +2 -1
- package/animate/index.js.map +1 -1
- package/hooks/useTransition.cjs +3 -3
- package/hooks/useTransition.cjs.map +1 -1
- package/hooks/useTransition.js +3 -3
- package/hooks/useTransition.js.map +1 -1
- package/package.json +1 -1
package/Transition/index.cjs
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var tslib = require('tslib');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
var React = require('react');
|
|
6
7
|
var variants = require('./variants.cjs');
|
|
7
|
-
var useTransition = require('../hooks/useTransition.cjs');
|
|
8
8
|
var easing = require('../animate/easing.cjs');
|
|
9
|
+
var useTransition = require('../hooks/useTransition.cjs');
|
|
9
10
|
|
|
10
|
-
function
|
|
11
|
+
function TransitionBase(_a) {
|
|
11
12
|
var { children } = _a, options = tslib.__rest(_a, ["children"]);
|
|
12
|
-
let { open, variant = "fade", duration = 450, delay, easing: easing$1, exitOnUnmount = false, initialTransition =
|
|
13
|
+
let { open, variant = "fade", duration = 450, delay, easing: easing$1, exitOnUnmount = false, initialTransition = true, onEnter, onEntered, onExit, onExited, onUpdate, onDone, } = options;
|
|
13
14
|
easing$1 !== null && easing$1 !== void 0 ? easing$1 : (easing$1 = "default");
|
|
14
15
|
const variantCb = variants[variant];
|
|
15
16
|
const ref = React.useRef(null);
|
|
16
17
|
const init = React.useRef(false);
|
|
18
|
+
const rect = React.useRef(null);
|
|
17
19
|
const trans = useTransition({
|
|
18
20
|
delay,
|
|
19
21
|
duration,
|
|
@@ -24,20 +26,28 @@ function Transition(_a) {
|
|
|
24
26
|
onExited,
|
|
25
27
|
onDone,
|
|
26
28
|
from: () => {
|
|
27
|
-
|
|
29
|
+
var _a;
|
|
30
|
+
if (!rect.current) {
|
|
31
|
+
rect.current = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
32
|
+
}
|
|
33
|
+
const v = variantCb(ref.current, rect.current);
|
|
28
34
|
return v.from;
|
|
29
35
|
},
|
|
30
36
|
to: () => {
|
|
31
|
-
|
|
37
|
+
var _a;
|
|
38
|
+
if (!rect.current) {
|
|
39
|
+
rect.current = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
40
|
+
}
|
|
41
|
+
const v = variantCb(ref.current, rect.current);
|
|
32
42
|
return v.to;
|
|
33
43
|
},
|
|
34
44
|
onUpdate: (val, prograss) => {
|
|
35
|
-
if (!ref.current)
|
|
36
|
-
|
|
37
|
-
const vc = variantCb(ref.current);
|
|
45
|
+
if (!ref.current || !rect.current)
|
|
46
|
+
return;
|
|
47
|
+
const vc = variantCb(ref.current, rect.current);
|
|
38
48
|
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(val, prograss);
|
|
39
49
|
return vc.onUpdate(val);
|
|
40
|
-
}
|
|
50
|
+
},
|
|
41
51
|
});
|
|
42
52
|
React.useLayoutEffect(() => {
|
|
43
53
|
const isnot = !init.current && !initialTransition;
|
|
@@ -72,6 +82,9 @@ function Transition(_a) {
|
|
|
72
82
|
}
|
|
73
83
|
});
|
|
74
84
|
}
|
|
85
|
+
const Transition = (props) => {
|
|
86
|
+
return (jsxRuntime.jsx(TransitionBase, Object.assign({}, props), props.variant));
|
|
87
|
+
};
|
|
75
88
|
|
|
76
89
|
module.exports = Transition;
|
|
77
90
|
//# sourceMappingURL=index.cjs.map
|
package/Transition/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useRef, isValidElement, useLayoutEffect } from 'react';\nimport * as variants from './variants'\nimport
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useRef, isValidElement, useLayoutEffect } from 'react';\nimport * as variants from './variants'\nimport { Easing } from '../animate';\nimport useTransition from '../hooks/useTransition';\n\nexport type TransitionVariantTypes = keyof typeof variants\nexport type TransitionProps = {\n children: React.ReactElement;\n open: boolean;\n variant: TransitionVariantTypes\n easing?: keyof typeof Easing\n duration?: number;\n delay?: number;\n initialTransition?: boolean;\n\n exitOnUnmount?: boolean;\n\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n onUpdate?: (value: Record<string, number>, progress: number) => void;\n onDone?: () => void;\n}\n\n\nfunction TransitionBase({ children, ...options }: TransitionProps) {\n let {\n open,\n variant = \"fade\",\n duration = 450,\n delay,\n easing,\n exitOnUnmount = false,\n initialTransition = true,\n onEnter,\n onEntered,\n onExit,\n onExited,\n onUpdate,\n onDone,\n\n } = options\n\n easing ??= \"default\"\n\n const variantCb = variants[variant]\n const ref = useRef<HTMLElement>(null)\n const init = useRef(false)\n const rect = useRef<DOMRect>(null)\n\n const trans = useTransition({\n delay,\n duration,\n easing: Easing[easing],\n onEnter,\n onEntered,\n onExit,\n onExited,\n onDone,\n from: () => {\n if (!rect.current) {\n rect.current = ref.current?.getBoundingClientRect() as DOMRect\n }\n const v = variantCb(ref.current as HTMLElement, rect.current)\n return v.from\n },\n to: () => {\n if (!rect.current) {\n rect.current = ref.current?.getBoundingClientRect() as DOMRect\n }\n const v = variantCb(ref.current as HTMLElement, rect.current)\n return v.to\n },\n onUpdate: (val, prograss) => {\n if (!ref.current || !rect.current) return\n const vc = variantCb(ref.current, rect.current)\n onUpdate?.(val, prograss)\n return vc.onUpdate(val)\n },\n })\n\n\n useLayoutEffect(() => {\n const isnot = !init.current && !initialTransition\n init.current = true\n if (open) {\n trans.enter(isnot ? false : true)\n } else {\n trans.exit(isnot ? false : true)\n }\n }, [open])\n\n if (exitOnUnmount && trans.status === \"exited\") return\n\n const childs = Children.toArray(children)\n if (childs.length !== 1) {\n throw new Error(\"Transition expects exactly one child.\");\n }\n const child = childs[0]\n if (!isValidElement(child)) {\n throw new Error(\"Transition expects a valid React element.\");\n }\n\n return cloneElement(child, {\n ref: (node: HTMLElement) => {\n ref.current = node;\n\n const childRef = (child as any).ref;\n if (typeof childRef === \"function\") {\n childRef(node);\n } else if (childRef) {\n childRef.current = node;\n }\n }\n } as any);\n}\n\n\nconst Transition = (props: any) => {\n return (\n <TransitionBase\n key={props.variant}\n {...props}\n />\n )\n}\nexport default Transition"],"names":[],"mappings":";;;;;;;;;;AA2BA;AAAwB;AACpB;;AAmBA;AACA;AACA;AACA;;;;AAKI;;;;;;;;AAOI;;;AAGA;;;;;AAIA;;;AAGA;;;AAGJ;;;AAEI;;AAEA;;AAEP;;;AAKG;;AAEI;;;AAEA;;AAER;AAEA;;;AAGA;AACI;;AAEJ;AACA;AACI;;;AAIA;AACI;AAEA;AACA;;;;AAGI;;;AAGJ;AACZ;AAGA;;AAOA;;"}
|
package/Transition/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ type TransitionProps = {
|
|
|
19
19
|
onUpdate?: (value: Record<string, number>, progress: number) => void;
|
|
20
20
|
onDone?: () => void;
|
|
21
21
|
};
|
|
22
|
-
declare
|
|
22
|
+
declare const Transition: (props: any) => React__default.JSX.Element;
|
|
23
23
|
|
|
24
24
|
export { Transition as default };
|
|
25
25
|
export type { TransitionProps, TransitionVariantTypes };
|
package/Transition/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { __rest } from 'tslib';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
4
|
import { useRef, useLayoutEffect, Children, isValidElement, cloneElement } from 'react';
|
|
4
5
|
import * as variants from './variants.js';
|
|
5
|
-
import useTransition from '../hooks/useTransition.js';
|
|
6
6
|
import Easing from '../animate/easing.js';
|
|
7
|
+
import useTransition from '../hooks/useTransition.js';
|
|
7
8
|
|
|
8
|
-
function
|
|
9
|
+
function TransitionBase(_a) {
|
|
9
10
|
var { children } = _a, options = __rest(_a, ["children"]);
|
|
10
|
-
let { open, variant = "fade", duration = 450, delay, easing, exitOnUnmount = false, initialTransition =
|
|
11
|
+
let { open, variant = "fade", duration = 450, delay, easing, exitOnUnmount = false, initialTransition = true, onEnter, onEntered, onExit, onExited, onUpdate, onDone, } = options;
|
|
11
12
|
easing !== null && easing !== void 0 ? easing : (easing = "default");
|
|
12
13
|
const variantCb = variants[variant];
|
|
13
14
|
const ref = useRef(null);
|
|
14
15
|
const init = useRef(false);
|
|
16
|
+
const rect = useRef(null);
|
|
15
17
|
const trans = useTransition({
|
|
16
18
|
delay,
|
|
17
19
|
duration,
|
|
@@ -22,20 +24,28 @@ function Transition(_a) {
|
|
|
22
24
|
onExited,
|
|
23
25
|
onDone,
|
|
24
26
|
from: () => {
|
|
25
|
-
|
|
27
|
+
var _a;
|
|
28
|
+
if (!rect.current) {
|
|
29
|
+
rect.current = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
30
|
+
}
|
|
31
|
+
const v = variantCb(ref.current, rect.current);
|
|
26
32
|
return v.from;
|
|
27
33
|
},
|
|
28
34
|
to: () => {
|
|
29
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
if (!rect.current) {
|
|
37
|
+
rect.current = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
38
|
+
}
|
|
39
|
+
const v = variantCb(ref.current, rect.current);
|
|
30
40
|
return v.to;
|
|
31
41
|
},
|
|
32
42
|
onUpdate: (val, prograss) => {
|
|
33
|
-
if (!ref.current)
|
|
34
|
-
|
|
35
|
-
const vc = variantCb(ref.current);
|
|
43
|
+
if (!ref.current || !rect.current)
|
|
44
|
+
return;
|
|
45
|
+
const vc = variantCb(ref.current, rect.current);
|
|
36
46
|
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(val, prograss);
|
|
37
47
|
return vc.onUpdate(val);
|
|
38
|
-
}
|
|
48
|
+
},
|
|
39
49
|
});
|
|
40
50
|
useLayoutEffect(() => {
|
|
41
51
|
const isnot = !init.current && !initialTransition;
|
|
@@ -70,6 +80,9 @@ function Transition(_a) {
|
|
|
70
80
|
}
|
|
71
81
|
});
|
|
72
82
|
}
|
|
83
|
+
const Transition = (props) => {
|
|
84
|
+
return (jsx(TransitionBase, Object.assign({}, props), props.variant));
|
|
85
|
+
};
|
|
73
86
|
|
|
74
87
|
export { Transition as default };
|
|
75
88
|
//# sourceMappingURL=index.js.map
|
package/Transition/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useRef, isValidElement, useLayoutEffect } from 'react';\nimport * as variants from './variants'\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Transition/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { cloneElement, Children, useRef, isValidElement, useLayoutEffect } from 'react';\nimport * as variants from './variants'\nimport { Easing } from '../animate';\nimport useTransition from '../hooks/useTransition';\n\nexport type TransitionVariantTypes = keyof typeof variants\nexport type TransitionProps = {\n children: React.ReactElement;\n open: boolean;\n variant: TransitionVariantTypes\n easing?: keyof typeof Easing\n duration?: number;\n delay?: number;\n initialTransition?: boolean;\n\n exitOnUnmount?: boolean;\n\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n onUpdate?: (value: Record<string, number>, progress: number) => void;\n onDone?: () => void;\n}\n\n\nfunction TransitionBase({ children, ...options }: TransitionProps) {\n let {\n open,\n variant = \"fade\",\n duration = 450,\n delay,\n easing,\n exitOnUnmount = false,\n initialTransition = true,\n onEnter,\n onEntered,\n onExit,\n onExited,\n onUpdate,\n onDone,\n\n } = options\n\n easing ??= \"default\"\n\n const variantCb = variants[variant]\n const ref = useRef<HTMLElement>(null)\n const init = useRef(false)\n const rect = useRef<DOMRect>(null)\n\n const trans = useTransition({\n delay,\n duration,\n easing: Easing[easing],\n onEnter,\n onEntered,\n onExit,\n onExited,\n onDone,\n from: () => {\n if (!rect.current) {\n rect.current = ref.current?.getBoundingClientRect() as DOMRect\n }\n const v = variantCb(ref.current as HTMLElement, rect.current)\n return v.from\n },\n to: () => {\n if (!rect.current) {\n rect.current = ref.current?.getBoundingClientRect() as DOMRect\n }\n const v = variantCb(ref.current as HTMLElement, rect.current)\n return v.to\n },\n onUpdate: (val, prograss) => {\n if (!ref.current || !rect.current) return\n const vc = variantCb(ref.current, rect.current)\n onUpdate?.(val, prograss)\n return vc.onUpdate(val)\n },\n })\n\n\n useLayoutEffect(() => {\n const isnot = !init.current && !initialTransition\n init.current = true\n if (open) {\n trans.enter(isnot ? false : true)\n } else {\n trans.exit(isnot ? false : true)\n }\n }, [open])\n\n if (exitOnUnmount && trans.status === \"exited\") return\n\n const childs = Children.toArray(children)\n if (childs.length !== 1) {\n throw new Error(\"Transition expects exactly one child.\");\n }\n const child = childs[0]\n if (!isValidElement(child)) {\n throw new Error(\"Transition expects a valid React element.\");\n }\n\n return cloneElement(child, {\n ref: (node: HTMLElement) => {\n ref.current = node;\n\n const childRef = (child as any).ref;\n if (typeof childRef === \"function\") {\n childRef(node);\n } else if (childRef) {\n childRef.current = node;\n }\n }\n } as any);\n}\n\n\nconst Transition = (props: any) => {\n return (\n <TransitionBase\n key={props.variant}\n {...props}\n />\n )\n}\nexport default Transition"],"names":[],"mappings":";;;;;;;;AA2BA;AAAwB;AACpB;;AAmBA;AACA;AACA;AACA;;;;AAKI;;;;;;;;AAOI;;;AAGA;;;;;AAIA;;;AAGA;;;AAGJ;;;AAEI;;AAEA;;AAEP;;;AAKG;;AAEI;;;AAEA;;AAER;AAEA;;;AAGA;AACI;;AAEJ;AACA;AACI;;;AAIA;AACI;AAEA;AACA;;;;AAGI;;;AAGJ;AACZ;AAGA;;AAOA;;"}
|
package/Transition/variants.cjs
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const getY = (
|
|
5
|
-
const getX = (
|
|
4
|
+
const getY = (rect) => (rect.height / 2, 40);
|
|
5
|
+
const getX = (rect) => (rect.width / 2, 40);
|
|
6
6
|
// ------------------ Variants ------------------
|
|
7
|
-
const slideDown = (el) => {
|
|
8
|
-
|
|
7
|
+
const slideDown = (el, rect) => {
|
|
8
|
+
getY(rect);
|
|
9
9
|
return {
|
|
10
|
-
from: { y: -
|
|
10
|
+
from: { y: -40 },
|
|
11
11
|
to: { y: 0 },
|
|
12
12
|
onUpdate: ({ y }) => (el.style.transform = `translateY(${y}px)`),
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
const slideUp = (el) => {
|
|
16
|
-
const y = getY(
|
|
15
|
+
const slideUp = (el, rect) => {
|
|
16
|
+
const y = getY(rect);
|
|
17
17
|
return {
|
|
18
18
|
from: { y },
|
|
19
19
|
to: { y: 0 },
|
|
20
20
|
onUpdate: ({ y }) => (el.style.transform = `translateY(${y}px)`),
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
-
const slideRight = (el) => {
|
|
24
|
-
|
|
23
|
+
const slideRight = (el, rect) => {
|
|
24
|
+
getX(rect);
|
|
25
25
|
return {
|
|
26
|
-
from: { x: -
|
|
26
|
+
from: { x: -40 },
|
|
27
27
|
to: { x: 0 },
|
|
28
28
|
onUpdate: ({ x }) => (el.style.transform = `translateX(${x}px)`),
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
const slideLeft = (el) => {
|
|
32
|
-
const x = getX(
|
|
31
|
+
const slideLeft = (el, rect) => {
|
|
32
|
+
const x = getX(rect);
|
|
33
33
|
return {
|
|
34
34
|
from: { x },
|
|
35
35
|
to: { x: 0 },
|
|
36
36
|
onUpdate: ({ x }) => (el.style.transform = `translateX(${x}px)`),
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
-
const fade = (el) => ({
|
|
39
|
+
const fade = (el, rect) => ({
|
|
40
40
|
from: { opacity: 0 },
|
|
41
41
|
to: { opacity: 1 },
|
|
42
42
|
onUpdate: ({ opacity }) => (el.style.opacity = opacity),
|
|
43
43
|
});
|
|
44
|
-
const fadeDown = (el) => {
|
|
45
|
-
const y = getY(
|
|
44
|
+
const fadeDown = (el, rect) => {
|
|
45
|
+
const y = getY(rect);
|
|
46
|
+
console.log(y);
|
|
46
47
|
return {
|
|
47
48
|
from: { y: -y, scale: 0.98, opacity: 0 },
|
|
48
49
|
to: { y: 0, scale: 1, opacity: 1 },
|
|
@@ -52,8 +53,8 @@ const fadeDown = (el) => {
|
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
|
-
const fadeUp = (el) => {
|
|
56
|
-
const y = getY(
|
|
56
|
+
const fadeUp = (el, rect) => {
|
|
57
|
+
const y = getY(rect);
|
|
57
58
|
return {
|
|
58
59
|
from: { y, scale: 0.98, opacity: 0 },
|
|
59
60
|
to: { y: 0, scale: 1, opacity: 1 },
|
|
@@ -63,10 +64,10 @@ const fadeUp = (el) => {
|
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
66
|
};
|
|
66
|
-
const fadeRight = (el) => {
|
|
67
|
-
|
|
67
|
+
const fadeRight = (el, rect) => {
|
|
68
|
+
getX(rect);
|
|
68
69
|
return {
|
|
69
|
-
from: { x: -
|
|
70
|
+
from: { x: -40, scale: 0.98, opacity: 0 },
|
|
70
71
|
to: { x: 0, scale: 1, opacity: 1 },
|
|
71
72
|
onUpdate: ({ x, scale, opacity }) => {
|
|
72
73
|
el.style.transform = `translateX(${x}px) scale(${scale})`;
|
|
@@ -74,8 +75,8 @@ const fadeRight = (el) => {
|
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
};
|
|
77
|
-
const fadeLeft = (el) => {
|
|
78
|
-
const x = getX(
|
|
78
|
+
const fadeLeft = (el, rect) => {
|
|
79
|
+
const x = getX(rect);
|
|
79
80
|
return {
|
|
80
81
|
from: { x, scale: 0.98, opacity: 0 },
|
|
81
82
|
to: { x: 0, scale: 1, opacity: 1 },
|
|
@@ -85,7 +86,7 @@ const fadeLeft = (el) => {
|
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
88
|
};
|
|
88
|
-
const zoom = (el) => ({
|
|
89
|
+
const zoom = (el, rect) => ({
|
|
89
90
|
from: { scale: 0.8, opacity: 0 },
|
|
90
91
|
to: { scale: 1, opacity: 1 },
|
|
91
92
|
onUpdate: ({ scale, opacity }) => {
|
|
@@ -93,7 +94,7 @@ const zoom = (el) => ({
|
|
|
93
94
|
el.style.opacity = String(opacity);
|
|
94
95
|
},
|
|
95
96
|
});
|
|
96
|
-
const zoomOver = (el) => ({
|
|
97
|
+
const zoomOver = (el, rect) => ({
|
|
97
98
|
from: { scale: 1.2, opacity: 0 },
|
|
98
99
|
to: { scale: 1, opacity: 1 },
|
|
99
100
|
onUpdate: ({ scale, opacity }) => {
|
|
@@ -101,7 +102,7 @@ const zoomOver = (el) => ({
|
|
|
101
102
|
el.style.opacity = String(opacity);
|
|
102
103
|
},
|
|
103
104
|
});
|
|
104
|
-
const grow = (el) => ({
|
|
105
|
+
const grow = (el, rect) => ({
|
|
105
106
|
from: { scaleX: 0.8, scaleY: 0.6, opacity: 0 },
|
|
106
107
|
to: { scaleX: 1, scaleY: 1, opacity: 1 },
|
|
107
108
|
onUpdate: ({ scaleX, scaleY, opacity }) => {
|
|
@@ -109,8 +110,8 @@ const grow = (el) => ({
|
|
|
109
110
|
el.style.opacity = String(opacity);
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
|
-
const collapseVertical = (el) => {
|
|
113
|
-
const height =
|
|
113
|
+
const collapseVertical = (el, rect) => {
|
|
114
|
+
const height = rect.height;
|
|
114
115
|
return {
|
|
115
116
|
from: { maxHeight: 0 },
|
|
116
117
|
to: { maxHeight: height },
|
|
@@ -119,8 +120,8 @@ const collapseVertical = (el) => {
|
|
|
119
120
|
},
|
|
120
121
|
};
|
|
121
122
|
};
|
|
122
|
-
const collapseHorizontal = (el) => {
|
|
123
|
-
const width =
|
|
123
|
+
const collapseHorizontal = (el, rect) => {
|
|
124
|
+
const width = rect.width;
|
|
124
125
|
return {
|
|
125
126
|
from: { width: 0 },
|
|
126
127
|
to: { width },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.cjs","sources":["../../src/Transition/variants.ts"],"sourcesContent":["\"use client\"\nconst getY = (
|
|
1
|
+
{"version":3,"file":"variants.cjs","sources":["../../src/Transition/variants.ts"],"sourcesContent":["\"use client\"\nconst getY = (rect: DOMRect) => (rect.height / 2, 40)\nconst getX = (rect: DOMRect) => (rect.width / 2, 40)\n\n// ------------------ Variants ------------------\n\nexport const slideDown = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n return {\n from: { y: -y },\n to: { y: 0 },\n onUpdate: ({ y }: any) => (el.style.transform = `translateY(${y}px)`),\n }\n}\n\nexport const slideUp = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n return {\n from: { y },\n to: { y: 0 },\n onUpdate: ({ y }: any) => (el.style.transform = `translateY(${y}px)`),\n }\n}\n\nexport const slideRight = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x: -x },\n to: { x: 0 },\n onUpdate: ({ x }: any) => (el.style.transform = `translateX(${x}px)`),\n }\n}\n\nexport const slideLeft = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x },\n to: { x: 0 },\n onUpdate: ({ x }: any) => (el.style.transform = `translateX(${x}px)`),\n }\n}\n\nexport const fade = (el: HTMLElement, rect: DOMRect) => ({\n from: { opacity: 0 },\n to: { opacity: 1 },\n onUpdate: ({ opacity }: any) => (el.style.opacity = opacity),\n})\n\nexport const fadeDown = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n console.log(y);\n\n return {\n from: { y: -y, scale: 0.98, opacity: 0 },\n to: { y: 0, scale: 1, opacity: 1 },\n onUpdate: ({ y, scale, opacity }: any) => {\n el.style.transform = `translateY(${y}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeUp = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n return {\n from: { y, scale: 0.98, opacity: 0 },\n to: { y: 0, scale: 1, opacity: 1 },\n onUpdate: ({ y, scale, opacity }: any) => {\n el.style.transform = `translateY(${y}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeRight = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x: -x, scale: 0.98, opacity: 0 },\n to: { x: 0, scale: 1, opacity: 1 },\n onUpdate: ({ x, scale, opacity }: any) => {\n el.style.transform = `translateX(${x}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeLeft = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x, scale: 0.98, opacity: 0 },\n to: { x: 0, scale: 1, opacity: 1 },\n onUpdate: ({ x, scale, opacity }: any) => {\n el.style.transform = `translateX(${x}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const zoom = (el: HTMLElement, rect: DOMRect) => ({\n from: { scale: 0.8, opacity: 0 },\n to: { scale: 1, opacity: 1 },\n onUpdate: ({ scale, opacity }: any) => {\n el.style.transform = `scale(${scale})`\n el.style.opacity = String(opacity)\n },\n})\n\nexport const zoomOver = (el: HTMLElement, rect: DOMRect) => ({\n from: { scale: 1.2, opacity: 0 },\n to: { scale: 1, opacity: 1 },\n onUpdate: ({ scale, opacity }: any) => {\n el.style.transform = `scale(${scale})`\n el.style.opacity = String(opacity)\n },\n})\n\nexport const grow = (el: HTMLElement, rect: DOMRect) => ({\n from: { scaleX: 0.8, scaleY: 0.6, opacity: 0 },\n to: { scaleX: 1, scaleY: 1, opacity: 1 },\n onUpdate: ({ scaleX, scaleY, opacity }: any) => {\n el.style.transform = `scale(${scaleX}, ${scaleY})`\n el.style.opacity = String(opacity)\n }\n})\n\nexport const collapseVertical = (el: HTMLElement, rect: DOMRect) => {\n const height = rect.height\n return {\n from: { maxHeight: 0 },\n to: { maxHeight: height },\n onUpdate: ({ maxHeight }: any) => {\n el.style.maxHeight = `${maxHeight}px`\n },\n }\n}\n\nexport const collapseHorizontal = (el: HTMLElement, rect: DOMRect) => {\n const width = rect.width\n return {\n from: { width: 0 },\n to: { width },\n onUpdate: ({ width }: any) => {\n el.style.width = `${width}px`\n },\n }\n}"],"names":[],"mappings":";;;AACA;AACA;AAEA;;AAGI;;AAEI;AACA;AACA;;AAER;;AAGI;;;AAGI;AACA;;AAER;;AAGI;;AAEI;AACA;AACA;;AAER;;AAGI;;;AAGI;AACA;;AAER;AAEO;AACH;AACA;AACA;AACH;;AAGG;AACA;;AAGI;AACA;;;;;;AAMR;;AAGI;;;AAGI;;;;;;AAMR;;AAGI;;AAEI;AACA;;;;;;AAMR;;AAGI;;;AAGI;;;;;;AAMR;AAEO;;;;;;;AAON;AAEM;;;;;;;AAON;AAEM;AACH;AACA;;;;;AAKH;;AAGG;;AAEI;AACA;AACA;;;;AAIR;;AAGI;;AAEI;;AAEA;;;;AAIR;;;;;;;;;;;;;;;"}
|
package/Transition/variants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const slideDown: (el: HTMLElement) => {
|
|
1
|
+
declare const slideDown: (el: HTMLElement, rect: DOMRect) => {
|
|
2
2
|
from: {
|
|
3
3
|
y: number;
|
|
4
4
|
};
|
|
@@ -7,7 +7,7 @@ declare const slideDown: (el: HTMLElement) => {
|
|
|
7
7
|
};
|
|
8
8
|
onUpdate: ({ y }: any) => string;
|
|
9
9
|
};
|
|
10
|
-
declare const slideUp: (el: HTMLElement) => {
|
|
10
|
+
declare const slideUp: (el: HTMLElement, rect: DOMRect) => {
|
|
11
11
|
from: {
|
|
12
12
|
y: number;
|
|
13
13
|
};
|
|
@@ -16,7 +16,7 @@ declare const slideUp: (el: HTMLElement) => {
|
|
|
16
16
|
};
|
|
17
17
|
onUpdate: ({ y }: any) => string;
|
|
18
18
|
};
|
|
19
|
-
declare const slideRight: (el: HTMLElement) => {
|
|
19
|
+
declare const slideRight: (el: HTMLElement, rect: DOMRect) => {
|
|
20
20
|
from: {
|
|
21
21
|
x: number;
|
|
22
22
|
};
|
|
@@ -25,7 +25,7 @@ declare const slideRight: (el: HTMLElement) => {
|
|
|
25
25
|
};
|
|
26
26
|
onUpdate: ({ x }: any) => string;
|
|
27
27
|
};
|
|
28
|
-
declare const slideLeft: (el: HTMLElement) => {
|
|
28
|
+
declare const slideLeft: (el: HTMLElement, rect: DOMRect) => {
|
|
29
29
|
from: {
|
|
30
30
|
x: number;
|
|
31
31
|
};
|
|
@@ -34,7 +34,7 @@ declare const slideLeft: (el: HTMLElement) => {
|
|
|
34
34
|
};
|
|
35
35
|
onUpdate: ({ x }: any) => string;
|
|
36
36
|
};
|
|
37
|
-
declare const fade: (el: HTMLElement) => {
|
|
37
|
+
declare const fade: (el: HTMLElement, rect: DOMRect) => {
|
|
38
38
|
from: {
|
|
39
39
|
opacity: number;
|
|
40
40
|
};
|
|
@@ -43,7 +43,7 @@ declare const fade: (el: HTMLElement) => {
|
|
|
43
43
|
};
|
|
44
44
|
onUpdate: ({ opacity }: any) => any;
|
|
45
45
|
};
|
|
46
|
-
declare const fadeDown: (el: HTMLElement) => {
|
|
46
|
+
declare const fadeDown: (el: HTMLElement, rect: DOMRect) => {
|
|
47
47
|
from: {
|
|
48
48
|
y: number;
|
|
49
49
|
scale: number;
|
|
@@ -56,7 +56,7 @@ declare const fadeDown: (el: HTMLElement) => {
|
|
|
56
56
|
};
|
|
57
57
|
onUpdate: ({ y, scale, opacity }: any) => void;
|
|
58
58
|
};
|
|
59
|
-
declare const fadeUp: (el: HTMLElement) => {
|
|
59
|
+
declare const fadeUp: (el: HTMLElement, rect: DOMRect) => {
|
|
60
60
|
from: {
|
|
61
61
|
y: number;
|
|
62
62
|
scale: number;
|
|
@@ -69,7 +69,7 @@ declare const fadeUp: (el: HTMLElement) => {
|
|
|
69
69
|
};
|
|
70
70
|
onUpdate: ({ y, scale, opacity }: any) => void;
|
|
71
71
|
};
|
|
72
|
-
declare const fadeRight: (el: HTMLElement) => {
|
|
72
|
+
declare const fadeRight: (el: HTMLElement, rect: DOMRect) => {
|
|
73
73
|
from: {
|
|
74
74
|
x: number;
|
|
75
75
|
scale: number;
|
|
@@ -82,7 +82,7 @@ declare const fadeRight: (el: HTMLElement) => {
|
|
|
82
82
|
};
|
|
83
83
|
onUpdate: ({ x, scale, opacity }: any) => void;
|
|
84
84
|
};
|
|
85
|
-
declare const fadeLeft: (el: HTMLElement) => {
|
|
85
|
+
declare const fadeLeft: (el: HTMLElement, rect: DOMRect) => {
|
|
86
86
|
from: {
|
|
87
87
|
x: number;
|
|
88
88
|
scale: number;
|
|
@@ -95,7 +95,7 @@ declare const fadeLeft: (el: HTMLElement) => {
|
|
|
95
95
|
};
|
|
96
96
|
onUpdate: ({ x, scale, opacity }: any) => void;
|
|
97
97
|
};
|
|
98
|
-
declare const zoom: (el: HTMLElement) => {
|
|
98
|
+
declare const zoom: (el: HTMLElement, rect: DOMRect) => {
|
|
99
99
|
from: {
|
|
100
100
|
scale: number;
|
|
101
101
|
opacity: number;
|
|
@@ -106,7 +106,7 @@ declare const zoom: (el: HTMLElement) => {
|
|
|
106
106
|
};
|
|
107
107
|
onUpdate: ({ scale, opacity }: any) => void;
|
|
108
108
|
};
|
|
109
|
-
declare const zoomOver: (el: HTMLElement) => {
|
|
109
|
+
declare const zoomOver: (el: HTMLElement, rect: DOMRect) => {
|
|
110
110
|
from: {
|
|
111
111
|
scale: number;
|
|
112
112
|
opacity: number;
|
|
@@ -117,7 +117,7 @@ declare const zoomOver: (el: HTMLElement) => {
|
|
|
117
117
|
};
|
|
118
118
|
onUpdate: ({ scale, opacity }: any) => void;
|
|
119
119
|
};
|
|
120
|
-
declare const grow: (el: HTMLElement) => {
|
|
120
|
+
declare const grow: (el: HTMLElement, rect: DOMRect) => {
|
|
121
121
|
from: {
|
|
122
122
|
scaleX: number;
|
|
123
123
|
scaleY: number;
|
|
@@ -130,7 +130,7 @@ declare const grow: (el: HTMLElement) => {
|
|
|
130
130
|
};
|
|
131
131
|
onUpdate: ({ scaleX, scaleY, opacity }: any) => void;
|
|
132
132
|
};
|
|
133
|
-
declare const collapseVertical: (el: HTMLElement) => {
|
|
133
|
+
declare const collapseVertical: (el: HTMLElement, rect: DOMRect) => {
|
|
134
134
|
from: {
|
|
135
135
|
maxHeight: number;
|
|
136
136
|
};
|
|
@@ -139,7 +139,7 @@ declare const collapseVertical: (el: HTMLElement) => {
|
|
|
139
139
|
};
|
|
140
140
|
onUpdate: ({ maxHeight }: any) => void;
|
|
141
141
|
};
|
|
142
|
-
declare const collapseHorizontal: (el: HTMLElement) => {
|
|
142
|
+
declare const collapseHorizontal: (el: HTMLElement, rect: DOMRect) => {
|
|
143
143
|
from: {
|
|
144
144
|
width: number;
|
|
145
145
|
};
|
package/Transition/variants.js
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const getY = (
|
|
3
|
-
const getX = (
|
|
2
|
+
const getY = (rect) => (rect.height / 2, 40);
|
|
3
|
+
const getX = (rect) => (rect.width / 2, 40);
|
|
4
4
|
// ------------------ Variants ------------------
|
|
5
|
-
const slideDown = (el) => {
|
|
6
|
-
|
|
5
|
+
const slideDown = (el, rect) => {
|
|
6
|
+
getY(rect);
|
|
7
7
|
return {
|
|
8
|
-
from: { y: -
|
|
8
|
+
from: { y: -40 },
|
|
9
9
|
to: { y: 0 },
|
|
10
10
|
onUpdate: ({ y }) => (el.style.transform = `translateY(${y}px)`),
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
const slideUp = (el) => {
|
|
14
|
-
const y = getY(
|
|
13
|
+
const slideUp = (el, rect) => {
|
|
14
|
+
const y = getY(rect);
|
|
15
15
|
return {
|
|
16
16
|
from: { y },
|
|
17
17
|
to: { y: 0 },
|
|
18
18
|
onUpdate: ({ y }) => (el.style.transform = `translateY(${y}px)`),
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
const slideRight = (el) => {
|
|
22
|
-
|
|
21
|
+
const slideRight = (el, rect) => {
|
|
22
|
+
getX(rect);
|
|
23
23
|
return {
|
|
24
|
-
from: { x: -
|
|
24
|
+
from: { x: -40 },
|
|
25
25
|
to: { x: 0 },
|
|
26
26
|
onUpdate: ({ x }) => (el.style.transform = `translateX(${x}px)`),
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
const slideLeft = (el) => {
|
|
30
|
-
const x = getX(
|
|
29
|
+
const slideLeft = (el, rect) => {
|
|
30
|
+
const x = getX(rect);
|
|
31
31
|
return {
|
|
32
32
|
from: { x },
|
|
33
33
|
to: { x: 0 },
|
|
34
34
|
onUpdate: ({ x }) => (el.style.transform = `translateX(${x}px)`),
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
const fade = (el) => ({
|
|
37
|
+
const fade = (el, rect) => ({
|
|
38
38
|
from: { opacity: 0 },
|
|
39
39
|
to: { opacity: 1 },
|
|
40
40
|
onUpdate: ({ opacity }) => (el.style.opacity = opacity),
|
|
41
41
|
});
|
|
42
|
-
const fadeDown = (el) => {
|
|
43
|
-
const y = getY(
|
|
42
|
+
const fadeDown = (el, rect) => {
|
|
43
|
+
const y = getY(rect);
|
|
44
|
+
console.log(y);
|
|
44
45
|
return {
|
|
45
46
|
from: { y: -y, scale: 0.98, opacity: 0 },
|
|
46
47
|
to: { y: 0, scale: 1, opacity: 1 },
|
|
@@ -50,8 +51,8 @@ const fadeDown = (el) => {
|
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
};
|
|
53
|
-
const fadeUp = (el) => {
|
|
54
|
-
const y = getY(
|
|
54
|
+
const fadeUp = (el, rect) => {
|
|
55
|
+
const y = getY(rect);
|
|
55
56
|
return {
|
|
56
57
|
from: { y, scale: 0.98, opacity: 0 },
|
|
57
58
|
to: { y: 0, scale: 1, opacity: 1 },
|
|
@@ -61,10 +62,10 @@ const fadeUp = (el) => {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
};
|
|
64
|
-
const fadeRight = (el) => {
|
|
65
|
-
|
|
65
|
+
const fadeRight = (el, rect) => {
|
|
66
|
+
getX(rect);
|
|
66
67
|
return {
|
|
67
|
-
from: { x: -
|
|
68
|
+
from: { x: -40, scale: 0.98, opacity: 0 },
|
|
68
69
|
to: { x: 0, scale: 1, opacity: 1 },
|
|
69
70
|
onUpdate: ({ x, scale, opacity }) => {
|
|
70
71
|
el.style.transform = `translateX(${x}px) scale(${scale})`;
|
|
@@ -72,8 +73,8 @@ const fadeRight = (el) => {
|
|
|
72
73
|
}
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
|
-
const fadeLeft = (el) => {
|
|
76
|
-
const x = getX(
|
|
76
|
+
const fadeLeft = (el, rect) => {
|
|
77
|
+
const x = getX(rect);
|
|
77
78
|
return {
|
|
78
79
|
from: { x, scale: 0.98, opacity: 0 },
|
|
79
80
|
to: { x: 0, scale: 1, opacity: 1 },
|
|
@@ -83,7 +84,7 @@ const fadeLeft = (el) => {
|
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
};
|
|
86
|
-
const zoom = (el) => ({
|
|
87
|
+
const zoom = (el, rect) => ({
|
|
87
88
|
from: { scale: 0.8, opacity: 0 },
|
|
88
89
|
to: { scale: 1, opacity: 1 },
|
|
89
90
|
onUpdate: ({ scale, opacity }) => {
|
|
@@ -91,7 +92,7 @@ const zoom = (el) => ({
|
|
|
91
92
|
el.style.opacity = String(opacity);
|
|
92
93
|
},
|
|
93
94
|
});
|
|
94
|
-
const zoomOver = (el) => ({
|
|
95
|
+
const zoomOver = (el, rect) => ({
|
|
95
96
|
from: { scale: 1.2, opacity: 0 },
|
|
96
97
|
to: { scale: 1, opacity: 1 },
|
|
97
98
|
onUpdate: ({ scale, opacity }) => {
|
|
@@ -99,7 +100,7 @@ const zoomOver = (el) => ({
|
|
|
99
100
|
el.style.opacity = String(opacity);
|
|
100
101
|
},
|
|
101
102
|
});
|
|
102
|
-
const grow = (el) => ({
|
|
103
|
+
const grow = (el, rect) => ({
|
|
103
104
|
from: { scaleX: 0.8, scaleY: 0.6, opacity: 0 },
|
|
104
105
|
to: { scaleX: 1, scaleY: 1, opacity: 1 },
|
|
105
106
|
onUpdate: ({ scaleX, scaleY, opacity }) => {
|
|
@@ -107,8 +108,8 @@ const grow = (el) => ({
|
|
|
107
108
|
el.style.opacity = String(opacity);
|
|
108
109
|
}
|
|
109
110
|
});
|
|
110
|
-
const collapseVertical = (el) => {
|
|
111
|
-
const height =
|
|
111
|
+
const collapseVertical = (el, rect) => {
|
|
112
|
+
const height = rect.height;
|
|
112
113
|
return {
|
|
113
114
|
from: { maxHeight: 0 },
|
|
114
115
|
to: { maxHeight: height },
|
|
@@ -117,8 +118,8 @@ const collapseVertical = (el) => {
|
|
|
117
118
|
},
|
|
118
119
|
};
|
|
119
120
|
};
|
|
120
|
-
const collapseHorizontal = (el) => {
|
|
121
|
-
const width =
|
|
121
|
+
const collapseHorizontal = (el, rect) => {
|
|
122
|
+
const width = rect.width;
|
|
122
123
|
return {
|
|
123
124
|
from: { width: 0 },
|
|
124
125
|
to: { width },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.js","sources":["../../src/Transition/variants.ts"],"sourcesContent":["\"use client\"\nconst getY = (
|
|
1
|
+
{"version":3,"file":"variants.js","sources":["../../src/Transition/variants.ts"],"sourcesContent":["\"use client\"\nconst getY = (rect: DOMRect) => (rect.height / 2, 40)\nconst getX = (rect: DOMRect) => (rect.width / 2, 40)\n\n// ------------------ Variants ------------------\n\nexport const slideDown = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n return {\n from: { y: -y },\n to: { y: 0 },\n onUpdate: ({ y }: any) => (el.style.transform = `translateY(${y}px)`),\n }\n}\n\nexport const slideUp = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n return {\n from: { y },\n to: { y: 0 },\n onUpdate: ({ y }: any) => (el.style.transform = `translateY(${y}px)`),\n }\n}\n\nexport const slideRight = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x: -x },\n to: { x: 0 },\n onUpdate: ({ x }: any) => (el.style.transform = `translateX(${x}px)`),\n }\n}\n\nexport const slideLeft = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x },\n to: { x: 0 },\n onUpdate: ({ x }: any) => (el.style.transform = `translateX(${x}px)`),\n }\n}\n\nexport const fade = (el: HTMLElement, rect: DOMRect) => ({\n from: { opacity: 0 },\n to: { opacity: 1 },\n onUpdate: ({ opacity }: any) => (el.style.opacity = opacity),\n})\n\nexport const fadeDown = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n console.log(y);\n\n return {\n from: { y: -y, scale: 0.98, opacity: 0 },\n to: { y: 0, scale: 1, opacity: 1 },\n onUpdate: ({ y, scale, opacity }: any) => {\n el.style.transform = `translateY(${y}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeUp = (el: HTMLElement, rect: DOMRect) => {\n const y = getY(rect)\n return {\n from: { y, scale: 0.98, opacity: 0 },\n to: { y: 0, scale: 1, opacity: 1 },\n onUpdate: ({ y, scale, opacity }: any) => {\n el.style.transform = `translateY(${y}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeRight = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x: -x, scale: 0.98, opacity: 0 },\n to: { x: 0, scale: 1, opacity: 1 },\n onUpdate: ({ x, scale, opacity }: any) => {\n el.style.transform = `translateX(${x}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeLeft = (el: HTMLElement, rect: DOMRect) => {\n const x = getX(rect)\n return {\n from: { x, scale: 0.98, opacity: 0 },\n to: { x: 0, scale: 1, opacity: 1 },\n onUpdate: ({ x, scale, opacity }: any) => {\n el.style.transform = `translateX(${x}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const zoom = (el: HTMLElement, rect: DOMRect) => ({\n from: { scale: 0.8, opacity: 0 },\n to: { scale: 1, opacity: 1 },\n onUpdate: ({ scale, opacity }: any) => {\n el.style.transform = `scale(${scale})`\n el.style.opacity = String(opacity)\n },\n})\n\nexport const zoomOver = (el: HTMLElement, rect: DOMRect) => ({\n from: { scale: 1.2, opacity: 0 },\n to: { scale: 1, opacity: 1 },\n onUpdate: ({ scale, opacity }: any) => {\n el.style.transform = `scale(${scale})`\n el.style.opacity = String(opacity)\n },\n})\n\nexport const grow = (el: HTMLElement, rect: DOMRect) => ({\n from: { scaleX: 0.8, scaleY: 0.6, opacity: 0 },\n to: { scaleX: 1, scaleY: 1, opacity: 1 },\n onUpdate: ({ scaleX, scaleY, opacity }: any) => {\n el.style.transform = `scale(${scaleX}, ${scaleY})`\n el.style.opacity = String(opacity)\n }\n})\n\nexport const collapseVertical = (el: HTMLElement, rect: DOMRect) => {\n const height = rect.height\n return {\n from: { maxHeight: 0 },\n to: { maxHeight: height },\n onUpdate: ({ maxHeight }: any) => {\n el.style.maxHeight = `${maxHeight}px`\n },\n }\n}\n\nexport const collapseHorizontal = (el: HTMLElement, rect: DOMRect) => {\n const width = rect.width\n return {\n from: { width: 0 },\n to: { width },\n onUpdate: ({ width }: any) => {\n el.style.width = `${width}px`\n },\n }\n}"],"names":[],"mappings":";AACA;AACA;AAEA;;AAGI;;AAEI;AACA;AACA;;AAER;;AAGI;;;AAGI;AACA;;AAER;;AAGI;;AAEI;AACA;AACA;;AAER;;AAGI;;;AAGI;AACA;;AAER;AAEO;AACH;AACA;AACA;AACH;;AAGG;AACA;;AAGI;AACA;;;;;;AAMR;;AAGI;;;AAGI;;;;;;AAMR;;AAGI;;AAEI;AACA;;;;;;AAMR;;AAGI;;;AAGI;;;;;;AAMR;AAEO;;;;;;;AAON;AAEM;;;;;;;AAON;AAEM;AACH;AACA;;;;;AAKH;;AAGG;;AAEI;AACA;AACA;;;;AAIR;;AAGI;;AAEI;;AAEA;;;;AAIR;;"}
|
package/animate/index.cjs
CHANGED
|
@@ -80,7 +80,8 @@ const animate = ({ from, to, duration = 400, delay = 0, easing: easing$1 = easin
|
|
|
80
80
|
startAnimation(); // 🔁 re-run with fresh from/to if functions
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
|
|
83
|
+
const finalState = forward ? toVal : fromVal;
|
|
84
|
+
onDone === null || onDone === void 0 ? void 0 : onDone(finalState);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
};
|
package/animate/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/animate/index.ts"],"sourcesContent":["\"use client\"\nimport Easing from \"./easing\";\n\nexport { Easing };\n\nexport type AnimateOptions<T extends Record<string, number>> = {\n from: T | (() => T);\n to: T | (() => T);\n duration?: number;\n delay?: number;\n easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;\n onUpdate: (value: T, progress: number) => void;\n onDone?: () => void;\n breakpoints?: Partial<Record<keyof T, Array<{ value: number; callback: () => void }>>>;\n repeat?: number;\n repeatBack?: boolean;\n};\n\nconst animate = <T extends Record<string, number>>({\n from,\n to,\n duration = 400,\n delay = 0,\n easing = Easing.default,\n onUpdate,\n onDone,\n breakpoints,\n repeat = 0,\n repeatBack = false,\n}: AnimateOptions<T>) => {\n let rafId: number;\n let cycle = 0;\n let forward = true;\n\n // Track triggered breakpoints\n const triggered: Partial<Record<keyof T, Set<number>>> = {};\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val;\n\n const getEased = (key: keyof T, t: number) => {\n if (typeof easing === \"function\") return easing(t);\n if (easing[key]) return easing[key]!(t);\n return t;\n };\n\n const startAnimation = () => {\n const fromVal = resolve(from);\n const toVal = resolve(to);\n\n const keys = Object.keys(fromVal) as (keyof T)[];\n\n if (breakpoints) {\n for (const key of keys) triggered[key] = new Set();\n }\n\n const start = performance.now();\n\n const frame = (now: number) => {\n const progress =\n duration === 0 ? 1 : Math.min((now - start) / duration, 1);\n\n const current: any = {} as T;\n\n for (const key of keys) {\n const f = forward ? fromVal[key] : toVal[key];\n const t = forward ? toVal[key] : fromVal[key];\n\n const eased = getEased(key, progress);\n const val = f + (t - f) * eased;\n current[key] = val;\n\n // breakpoints\n const bps = breakpoints?.[key];\n if (bps) {\n for (let i = 0; i < bps.length; i++) {\n const triggeredSet = triggered[key]!;\n if (\n !triggeredSet.has(i) &&\n ((f < t && val >= bps[i].value) ||\n (f > t && val <= bps[i].value))\n ) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n onUpdate(current, progress);\n\n if (progress < 1) {\n rafId = requestAnimationFrame(frame);\n } else {\n const finalState = forward ? toVal : fromVal;\n onUpdate(finalState, 1);\n\n // fire remaining breakpoints\n if (breakpoints) {\n for (const key of keys) {\n const bps = breakpoints[key];\n if (!bps) continue;\n\n const triggeredSet = triggered[key]!;\n for (let i = 0; i < bps.length; i++) {\n if (!triggeredSet.has(i)) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n cycle++;\n\n if (cycle <= repeat) {\n if (repeatBack) forward = !forward;\n startAnimation(); // 🔁 re-run with fresh from/to if functions\n } else {\n onDone?.();\n }\n }\n };\n\n rafId = requestAnimationFrame(frame);\n };\n\n if (delay > 0) {\n const timeout = setTimeout(startAnimation, delay);\n return () => {\n clearTimeout(timeout);\n cancelAnimationFrame(rafId);\n };\n } else {\n startAnimation();\n return () => cancelAnimationFrame(rafId);\n }\n};\n\nexport default animate;"],"names":[],"mappings":";;;;;;;AAkBA;AAYG;;;;;;AAUA;;AACqC;;AACjB;AACjB;AACH;;AAGG;AACA;;;;AAK2B;;AAG3B;AAEA;;;AAMG;AACG;AACA;;;AAIA;;;;AAKG;AACG;AACA;AAEG;AACG;AAEH;AACA;;;;;AAMZ;AAEA;AACG;;;;AAGA;;;AAIG;AACG;AACA;;AAEA;AACA;;AAEM;AACA;;;;;AAMZ;AAEA;AACG
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/animate/index.ts"],"sourcesContent":["\"use client\"\nimport Easing from \"./easing\";\n\nexport { Easing };\n\nexport type AnimateOptions<T extends Record<string, number>> = {\n from: T | (() => T);\n to: T | (() => T);\n duration?: number;\n delay?: number;\n easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;\n onUpdate: (value: T, progress: number) => void;\n onDone?: (value: T) => void;\n breakpoints?: Partial<Record<keyof T, Array<{ value: number; callback: () => void }>>>;\n repeat?: number;\n repeatBack?: boolean;\n};\n\nconst animate = <T extends Record<string, number>>({\n from,\n to,\n duration = 400,\n delay = 0,\n easing = Easing.default,\n onUpdate,\n onDone,\n breakpoints,\n repeat = 0,\n repeatBack = false,\n}: AnimateOptions<T>) => {\n let rafId: number;\n let cycle = 0;\n let forward = true;\n\n // Track triggered breakpoints\n const triggered: Partial<Record<keyof T, Set<number>>> = {};\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val;\n\n const getEased = (key: keyof T, t: number) => {\n if (typeof easing === \"function\") return easing(t);\n if (easing[key]) return easing[key]!(t);\n return t;\n };\n\n const startAnimation = () => {\n const fromVal = resolve(from);\n const toVal = resolve(to);\n\n const keys = Object.keys(fromVal) as (keyof T)[];\n\n if (breakpoints) {\n for (const key of keys) triggered[key] = new Set();\n }\n\n const start = performance.now();\n\n const frame = (now: number) => {\n const progress =\n duration === 0 ? 1 : Math.min((now - start) / duration, 1);\n\n const current: any = {} as T;\n\n for (const key of keys) {\n const f = forward ? fromVal[key] : toVal[key];\n const t = forward ? toVal[key] : fromVal[key];\n\n const eased = getEased(key, progress);\n const val = f + (t - f) * eased;\n current[key] = val;\n\n // breakpoints\n const bps = breakpoints?.[key];\n if (bps) {\n for (let i = 0; i < bps.length; i++) {\n const triggeredSet = triggered[key]!;\n if (\n !triggeredSet.has(i) &&\n ((f < t && val >= bps[i].value) ||\n (f > t && val <= bps[i].value))\n ) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n onUpdate(current, progress);\n\n if (progress < 1) {\n rafId = requestAnimationFrame(frame);\n } else {\n const finalState = forward ? toVal : fromVal;\n onUpdate(finalState, 1);\n\n // fire remaining breakpoints\n if (breakpoints) {\n for (const key of keys) {\n const bps = breakpoints[key];\n if (!bps) continue;\n\n const triggeredSet = triggered[key]!;\n for (let i = 0; i < bps.length; i++) {\n if (!triggeredSet.has(i)) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n cycle++;\n\n if (cycle <= repeat) {\n if (repeatBack) forward = !forward;\n startAnimation(); // 🔁 re-run with fresh from/to if functions\n } else {\n const finalState = forward ? toVal : fromVal;\n onDone?.(finalState);\n }\n }\n };\n\n rafId = requestAnimationFrame(frame);\n };\n\n if (delay > 0) {\n const timeout = setTimeout(startAnimation, delay);\n return () => {\n clearTimeout(timeout);\n cancelAnimationFrame(rafId);\n };\n } else {\n startAnimation();\n return () => cancelAnimationFrame(rafId);\n }\n};\n\nexport default animate;"],"names":[],"mappings":";;;;;;;AAkBA;AAYG;;;;;;AAUA;;AACqC;;AACjB;AACjB;AACH;;AAGG;AACA;;;;AAK2B;;AAG3B;AAEA;;;AAMG;AACG;AACA;;;AAIA;;;;AAKG;AACG;AACA;AAEG;AACG;AAEH;AACA;;;;;AAMZ;AAEA;AACG;;;;AAGA;;;AAIG;AACG;AACA;;AAEA;AACA;;AAEM;AACA;;;;;AAMZ;AAEA;AACG;;;;;;AAIA;;;AAGT;AAEA;AACH;AAEA;;AAEG;;;AAGA;;;AAEA;AACA;;AAEN;;;"}
|
package/animate/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ type AnimateOptions<T extends Record<string, number>> = {
|
|
|
5
5
|
delay?: number;
|
|
6
6
|
easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;
|
|
7
7
|
onUpdate: (value: T, progress: number) => void;
|
|
8
|
-
onDone?: () => void;
|
|
8
|
+
onDone?: (value: T) => void;
|
|
9
9
|
breakpoints?: Partial<Record<keyof T, Array<{
|
|
10
10
|
value: number;
|
|
11
11
|
callback: () => void;
|
package/animate/index.js
CHANGED
|
@@ -76,7 +76,8 @@ const animate = ({ from, to, duration = 400, delay = 0, easing = Easing.default,
|
|
|
76
76
|
startAnimation(); // 🔁 re-run with fresh from/to if functions
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
|
|
79
|
+
const finalState = forward ? toVal : fromVal;
|
|
80
|
+
onDone === null || onDone === void 0 ? void 0 : onDone(finalState);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
};
|
package/animate/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/animate/index.ts"],"sourcesContent":["\"use client\"\nimport Easing from \"./easing\";\n\nexport { Easing };\n\nexport type AnimateOptions<T extends Record<string, number>> = {\n from: T | (() => T);\n to: T | (() => T);\n duration?: number;\n delay?: number;\n easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;\n onUpdate: (value: T, progress: number) => void;\n onDone?: () => void;\n breakpoints?: Partial<Record<keyof T, Array<{ value: number; callback: () => void }>>>;\n repeat?: number;\n repeatBack?: boolean;\n};\n\nconst animate = <T extends Record<string, number>>({\n from,\n to,\n duration = 400,\n delay = 0,\n easing = Easing.default,\n onUpdate,\n onDone,\n breakpoints,\n repeat = 0,\n repeatBack = false,\n}: AnimateOptions<T>) => {\n let rafId: number;\n let cycle = 0;\n let forward = true;\n\n // Track triggered breakpoints\n const triggered: Partial<Record<keyof T, Set<number>>> = {};\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val;\n\n const getEased = (key: keyof T, t: number) => {\n if (typeof easing === \"function\") return easing(t);\n if (easing[key]) return easing[key]!(t);\n return t;\n };\n\n const startAnimation = () => {\n const fromVal = resolve(from);\n const toVal = resolve(to);\n\n const keys = Object.keys(fromVal) as (keyof T)[];\n\n if (breakpoints) {\n for (const key of keys) triggered[key] = new Set();\n }\n\n const start = performance.now();\n\n const frame = (now: number) => {\n const progress =\n duration === 0 ? 1 : Math.min((now - start) / duration, 1);\n\n const current: any = {} as T;\n\n for (const key of keys) {\n const f = forward ? fromVal[key] : toVal[key];\n const t = forward ? toVal[key] : fromVal[key];\n\n const eased = getEased(key, progress);\n const val = f + (t - f) * eased;\n current[key] = val;\n\n // breakpoints\n const bps = breakpoints?.[key];\n if (bps) {\n for (let i = 0; i < bps.length; i++) {\n const triggeredSet = triggered[key]!;\n if (\n !triggeredSet.has(i) &&\n ((f < t && val >= bps[i].value) ||\n (f > t && val <= bps[i].value))\n ) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n onUpdate(current, progress);\n\n if (progress < 1) {\n rafId = requestAnimationFrame(frame);\n } else {\n const finalState = forward ? toVal : fromVal;\n onUpdate(finalState, 1);\n\n // fire remaining breakpoints\n if (breakpoints) {\n for (const key of keys) {\n const bps = breakpoints[key];\n if (!bps) continue;\n\n const triggeredSet = triggered[key]!;\n for (let i = 0; i < bps.length; i++) {\n if (!triggeredSet.has(i)) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n cycle++;\n\n if (cycle <= repeat) {\n if (repeatBack) forward = !forward;\n startAnimation(); // 🔁 re-run with fresh from/to if functions\n } else {\n onDone?.();\n }\n }\n };\n\n rafId = requestAnimationFrame(frame);\n };\n\n if (delay > 0) {\n const timeout = setTimeout(startAnimation, delay);\n return () => {\n clearTimeout(timeout);\n cancelAnimationFrame(rafId);\n };\n } else {\n startAnimation();\n return () => cancelAnimationFrame(rafId);\n }\n};\n\nexport default animate;"],"names":[],"mappings":";;;AAkBA;AAYG;;;;;;AAUA;;AACqC;;AACjB;AACjB;AACH;;AAGG;AACA;;;;AAK2B;;AAG3B;AAEA;;;AAMG;AACG;AACA;;;AAIA;;;;AAKG;AACG;AACA;AAEG;AACG;AAEH;AACA;;;;;AAMZ;AAEA;AACG;;;;AAGA;;;AAIG;AACG;AACA;;AAEA;AACA;;AAEM;AACA;;;;;AAMZ;AAEA;AACG
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/animate/index.ts"],"sourcesContent":["\"use client\"\nimport Easing from \"./easing\";\n\nexport { Easing };\n\nexport type AnimateOptions<T extends Record<string, number>> = {\n from: T | (() => T);\n to: T | (() => T);\n duration?: number;\n delay?: number;\n easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;\n onUpdate: (value: T, progress: number) => void;\n onDone?: (value: T) => void;\n breakpoints?: Partial<Record<keyof T, Array<{ value: number; callback: () => void }>>>;\n repeat?: number;\n repeatBack?: boolean;\n};\n\nconst animate = <T extends Record<string, number>>({\n from,\n to,\n duration = 400,\n delay = 0,\n easing = Easing.default,\n onUpdate,\n onDone,\n breakpoints,\n repeat = 0,\n repeatBack = false,\n}: AnimateOptions<T>) => {\n let rafId: number;\n let cycle = 0;\n let forward = true;\n\n // Track triggered breakpoints\n const triggered: Partial<Record<keyof T, Set<number>>> = {};\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val;\n\n const getEased = (key: keyof T, t: number) => {\n if (typeof easing === \"function\") return easing(t);\n if (easing[key]) return easing[key]!(t);\n return t;\n };\n\n const startAnimation = () => {\n const fromVal = resolve(from);\n const toVal = resolve(to);\n\n const keys = Object.keys(fromVal) as (keyof T)[];\n\n if (breakpoints) {\n for (const key of keys) triggered[key] = new Set();\n }\n\n const start = performance.now();\n\n const frame = (now: number) => {\n const progress =\n duration === 0 ? 1 : Math.min((now - start) / duration, 1);\n\n const current: any = {} as T;\n\n for (const key of keys) {\n const f = forward ? fromVal[key] : toVal[key];\n const t = forward ? toVal[key] : fromVal[key];\n\n const eased = getEased(key, progress);\n const val = f + (t - f) * eased;\n current[key] = val;\n\n // breakpoints\n const bps = breakpoints?.[key];\n if (bps) {\n for (let i = 0; i < bps.length; i++) {\n const triggeredSet = triggered[key]!;\n if (\n !triggeredSet.has(i) &&\n ((f < t && val >= bps[i].value) ||\n (f > t && val <= bps[i].value))\n ) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n onUpdate(current, progress);\n\n if (progress < 1) {\n rafId = requestAnimationFrame(frame);\n } else {\n const finalState = forward ? toVal : fromVal;\n onUpdate(finalState, 1);\n\n // fire remaining breakpoints\n if (breakpoints) {\n for (const key of keys) {\n const bps = breakpoints[key];\n if (!bps) continue;\n\n const triggeredSet = triggered[key]!;\n for (let i = 0; i < bps.length; i++) {\n if (!triggeredSet.has(i)) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n cycle++;\n\n if (cycle <= repeat) {\n if (repeatBack) forward = !forward;\n startAnimation(); // 🔁 re-run with fresh from/to if functions\n } else {\n const finalState = forward ? toVal : fromVal;\n onDone?.(finalState);\n }\n }\n };\n\n rafId = requestAnimationFrame(frame);\n };\n\n if (delay > 0) {\n const timeout = setTimeout(startAnimation, delay);\n return () => {\n clearTimeout(timeout);\n cancelAnimationFrame(rafId);\n };\n } else {\n startAnimation();\n return () => cancelAnimationFrame(rafId);\n }\n};\n\nexport default animate;"],"names":[],"mappings":";;;AAkBA;AAYG;;;;;;AAUA;;AACqC;;AACjB;AACjB;AACH;;AAGG;AACA;;;;AAK2B;;AAG3B;AAEA;;;AAMG;AACG;AACA;;;AAIA;;;;AAKG;AACG;AACA;AAEG;AACG;AAEH;AACA;;;;;AAMZ;AAEA;AACG;;;;AAGA;;;AAIG;AACG;AACA;;AAEA;AACA;;AAEM;AACA;;;;;AAMZ;AAEA;AACG;;;;;;AAIA;;;AAGT;AAEA;AACH;AAEA;;AAEG;;;AAGA;;;AAEA;AACA;;AAEN;;"}
|
package/hooks/useTransition.cjs
CHANGED
|
@@ -47,7 +47,7 @@ const useTransition = (props) => {
|
|
|
47
47
|
setStatus("exited");
|
|
48
48
|
onExited === null || onExited === void 0 ? void 0 : onExited();
|
|
49
49
|
}
|
|
50
|
-
(_c = options.onDone) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
50
|
+
(_c = options.onDone) === null || _c === void 0 ? void 0 : _c.call(options, stateRef.current);
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
animating.current = index.default(Object.assign(Object.assign({}, options), { from,
|
|
@@ -55,7 +55,7 @@ const useTransition = (props) => {
|
|
|
55
55
|
var _a;
|
|
56
56
|
stateRef.current = value;
|
|
57
57
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, value, progress);
|
|
58
|
-
}, onDone: () => {
|
|
58
|
+
}, onDone: (value) => {
|
|
59
59
|
var _a;
|
|
60
60
|
if (nextOpen) {
|
|
61
61
|
setStatus("entered");
|
|
@@ -65,7 +65,7 @@ const useTransition = (props) => {
|
|
|
65
65
|
setStatus("exited");
|
|
66
66
|
onExited === null || onExited === void 0 ? void 0 : onExited();
|
|
67
67
|
}
|
|
68
|
-
(_a = options.onDone) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
68
|
+
(_a = options.onDone) === null || _a === void 0 ? void 0 : _a.call(options, value);
|
|
69
69
|
} }));
|
|
70
70
|
}, [options, onEnter, onEntered, onExit, onExited]);
|
|
71
71
|
const enter = React.useCallback((withAnimation = true) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransition.cjs","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback, useLayoutEffect } from \"react\"\nimport animate, { AnimateOptions } from \"../animate\"\n\nexport type UseTransitionStatus =\n | \"entering\"\n | \"entered\"\n | \"exiting\"\n | \"exited\"\n\nexport type UseTransitionProps<T extends Record<string, number>> = AnimateOptions<T> & {\n initialStatus?: \"entered\" | \"exited\"\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n}\n\nconst useTransition = <T extends Record<string, number>>(props: UseTransitionProps<T>) => {\n const {\n initialStatus = \"exited\",\n onEnter,\n onEntered,\n onExit,\n onExited,\n ...options\n } = props\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val\n\n const [open, setOpen] = useState(initialStatus === \"entered\")\n const [status, setStatus] = useState<UseTransitionStatus>(initialStatus)\n\n const stateRef = useRef<T | null>(null)\n const readyRef = useRef(false)\n\n const animating = useRef<null | (() => void)>(null)\n\n useLayoutEffect(() => {\n const from = resolve(options.from)\n const to = resolve(options.to)\n stateRef.current = initialStatus === \"entered\" ? to : from\n readyRef.current = true\n }, [])\n\n const run = useCallback(\n (nextOpen: boolean, withAnimation = true) => {\n if (!readyRef.current || !stateRef.current) return\n\n animating.current?.()\n\n const resolvedFrom = resolve(options.from)\n const resolvedTo = resolve(options.to)\n const from = stateRef.current\n const to = nextOpen ? resolvedTo : resolvedFrom\n\n if (nextOpen) {\n setStatus(\"entering\")\n onEnter?.()\n } else {\n setStatus(\"exiting\")\n onExit?.()\n }\n\n if (!withAnimation) {\n stateRef.current = to\n options.onUpdate?.(to, 1)\n\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n\n options.onDone?.()\n return\n }\n\n animating.current = animate({\n ...options,\n from,\n to,\n duration: options.duration ?? 400,\n onUpdate: (value: T, progress: number) => {\n stateRef.current = value\n options.onUpdate?.(value, progress)\n },\n onDone: () => {\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n options.onDone?.()\n },\n })\n },\n [options, onEnter, onEntered, onExit, onExited]\n )\n\n const enter = useCallback((withAnimation = true) => {\n setOpen(true)\n run(true, withAnimation)\n }, [run])\n\n const exit = useCallback((withAnimation = true) => {\n setOpen(false)\n run(false, withAnimation)\n }, [run])\n\n const toggle = useCallback((withAnimation = true) => {\n setOpen((prev) => {\n const next = !prev\n run(next, withAnimation)\n return next\n })\n }, [run])\n\n return {\n isEntered: open,\n status,\n state: stateRef,\n enter,\n exit,\n toggle,\n isReady: readyRef.current\n }\n}\n\nexport default useTransition"],"names":[],"mappings":";;;;;;;AAkBA;;;AAaG;;AAGA;AACA;AAEA;;;;AAKG;AACA;;;;;;AAOG;;;AAIA;;;;AAKG;;;;AAGA;;;AAIA;;;;AAKG;;;;AAGA
|
|
1
|
+
{"version":3,"file":"useTransition.cjs","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback, useLayoutEffect } from \"react\"\nimport animate, { AnimateOptions } from \"../animate\"\n\nexport type UseTransitionStatus =\n | \"entering\"\n | \"entered\"\n | \"exiting\"\n | \"exited\"\n\nexport type UseTransitionProps<T extends Record<string, number>> = AnimateOptions<T> & {\n initialStatus?: \"entered\" | \"exited\"\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n}\n\nconst useTransition = <T extends Record<string, number>>(props: UseTransitionProps<T>) => {\n const {\n initialStatus = \"exited\",\n onEnter,\n onEntered,\n onExit,\n onExited,\n ...options\n } = props\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val\n\n const [open, setOpen] = useState(initialStatus === \"entered\")\n const [status, setStatus] = useState<UseTransitionStatus>(initialStatus)\n\n const stateRef = useRef<T | null>(null)\n const readyRef = useRef(false)\n\n const animating = useRef<null | (() => void)>(null)\n\n useLayoutEffect(() => {\n const from = resolve(options.from)\n const to = resolve(options.to)\n stateRef.current = initialStatus === \"entered\" ? to : from\n readyRef.current = true\n }, [])\n\n const run = useCallback(\n (nextOpen: boolean, withAnimation = true) => {\n if (!readyRef.current || !stateRef.current) return\n\n animating.current?.()\n\n const resolvedFrom = resolve(options.from)\n const resolvedTo = resolve(options.to)\n const from = stateRef.current\n const to = nextOpen ? resolvedTo : resolvedFrom\n\n if (nextOpen) {\n setStatus(\"entering\")\n onEnter?.()\n } else {\n setStatus(\"exiting\")\n onExit?.()\n }\n\n if (!withAnimation) {\n stateRef.current = to\n options.onUpdate?.(to, 1)\n\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n\n options.onDone?.(stateRef.current)\n return\n }\n\n animating.current = animate({\n ...options,\n from,\n to,\n duration: options.duration ?? 400,\n onUpdate: (value: T, progress: number) => {\n stateRef.current = value\n options.onUpdate?.(value, progress)\n },\n onDone: (value) => {\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n options.onDone?.(value)\n },\n })\n },\n [options, onEnter, onEntered, onExit, onExited]\n )\n\n const enter = useCallback((withAnimation = true) => {\n setOpen(true)\n run(true, withAnimation)\n }, [run])\n\n const exit = useCallback((withAnimation = true) => {\n setOpen(false)\n run(false, withAnimation)\n }, [run])\n\n const toggle = useCallback((withAnimation = true) => {\n setOpen((prev) => {\n const next = !prev\n run(next, withAnimation)\n return next\n })\n }, [run])\n\n return {\n isEntered: open,\n status,\n state: stateRef,\n enter,\n exit,\n toggle,\n isReady: readyRef.current\n }\n}\n\nexport default useTransition"],"names":[],"mappings":";;;;;;;AAkBA;;;AAaG;;AAGA;AACA;AAEA;;;;AAKG;AACA;;;;;;AAOG;;;AAIA;;;;AAKG;;;;AAGA;;;AAIA;;;;AAKG;;;;AAGA;;;;;AAON;AAGG;;AAGG;;AAEH;;;;AAIM;;;;AAGA;;AAEH;AACH;AAEN;;;AAMA;AACH;;;AAIG;AACH;;AAGG;AACG;AACA;AACA;AACH;AACH;;AAGG;;AAEA;;;;;;AAMN;;"}
|
package/hooks/useTransition.js
CHANGED
|
@@ -45,7 +45,7 @@ const useTransition = (props) => {
|
|
|
45
45
|
setStatus("exited");
|
|
46
46
|
onExited === null || onExited === void 0 ? void 0 : onExited();
|
|
47
47
|
}
|
|
48
|
-
(_c = options.onDone) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
48
|
+
(_c = options.onDone) === null || _c === void 0 ? void 0 : _c.call(options, stateRef.current);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
animating.current = animate(Object.assign(Object.assign({}, options), { from,
|
|
@@ -53,7 +53,7 @@ const useTransition = (props) => {
|
|
|
53
53
|
var _a;
|
|
54
54
|
stateRef.current = value;
|
|
55
55
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, value, progress);
|
|
56
|
-
}, onDone: () => {
|
|
56
|
+
}, onDone: (value) => {
|
|
57
57
|
var _a;
|
|
58
58
|
if (nextOpen) {
|
|
59
59
|
setStatus("entered");
|
|
@@ -63,7 +63,7 @@ const useTransition = (props) => {
|
|
|
63
63
|
setStatus("exited");
|
|
64
64
|
onExited === null || onExited === void 0 ? void 0 : onExited();
|
|
65
65
|
}
|
|
66
|
-
(_a = options.onDone) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
66
|
+
(_a = options.onDone) === null || _a === void 0 ? void 0 : _a.call(options, value);
|
|
67
67
|
} }));
|
|
68
68
|
}, [options, onEnter, onEntered, onExit, onExited]);
|
|
69
69
|
const enter = useCallback((withAnimation = true) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransition.js","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback, useLayoutEffect } from \"react\"\nimport animate, { AnimateOptions } from \"../animate\"\n\nexport type UseTransitionStatus =\n | \"entering\"\n | \"entered\"\n | \"exiting\"\n | \"exited\"\n\nexport type UseTransitionProps<T extends Record<string, number>> = AnimateOptions<T> & {\n initialStatus?: \"entered\" | \"exited\"\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n}\n\nconst useTransition = <T extends Record<string, number>>(props: UseTransitionProps<T>) => {\n const {\n initialStatus = \"exited\",\n onEnter,\n onEntered,\n onExit,\n onExited,\n ...options\n } = props\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val\n\n const [open, setOpen] = useState(initialStatus === \"entered\")\n const [status, setStatus] = useState<UseTransitionStatus>(initialStatus)\n\n const stateRef = useRef<T | null>(null)\n const readyRef = useRef(false)\n\n const animating = useRef<null | (() => void)>(null)\n\n useLayoutEffect(() => {\n const from = resolve(options.from)\n const to = resolve(options.to)\n stateRef.current = initialStatus === \"entered\" ? to : from\n readyRef.current = true\n }, [])\n\n const run = useCallback(\n (nextOpen: boolean, withAnimation = true) => {\n if (!readyRef.current || !stateRef.current) return\n\n animating.current?.()\n\n const resolvedFrom = resolve(options.from)\n const resolvedTo = resolve(options.to)\n const from = stateRef.current\n const to = nextOpen ? resolvedTo : resolvedFrom\n\n if (nextOpen) {\n setStatus(\"entering\")\n onEnter?.()\n } else {\n setStatus(\"exiting\")\n onExit?.()\n }\n\n if (!withAnimation) {\n stateRef.current = to\n options.onUpdate?.(to, 1)\n\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n\n options.onDone?.()\n return\n }\n\n animating.current = animate({\n ...options,\n from,\n to,\n duration: options.duration ?? 400,\n onUpdate: (value: T, progress: number) => {\n stateRef.current = value\n options.onUpdate?.(value, progress)\n },\n onDone: () => {\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n options.onDone?.()\n },\n })\n },\n [options, onEnter, onEntered, onExit, onExited]\n )\n\n const enter = useCallback((withAnimation = true) => {\n setOpen(true)\n run(true, withAnimation)\n }, [run])\n\n const exit = useCallback((withAnimation = true) => {\n setOpen(false)\n run(false, withAnimation)\n }, [run])\n\n const toggle = useCallback((withAnimation = true) => {\n setOpen((prev) => {\n const next = !prev\n run(next, withAnimation)\n return next\n })\n }, [run])\n\n return {\n isEntered: open,\n status,\n state: stateRef,\n enter,\n exit,\n toggle,\n isReady: readyRef.current\n }\n}\n\nexport default useTransition"],"names":[],"mappings":";;;;;AAkBA;;;AAaG;;AAGA;AACA;AAEA;;;;AAKG;AACA;;;;;;AAOG;;;AAIA;;;;AAKG;;;;AAGA;;;AAIA;;;;AAKG;;;;AAGA
|
|
1
|
+
{"version":3,"file":"useTransition.js","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback, useLayoutEffect } from \"react\"\nimport animate, { AnimateOptions } from \"../animate\"\n\nexport type UseTransitionStatus =\n | \"entering\"\n | \"entered\"\n | \"exiting\"\n | \"exited\"\n\nexport type UseTransitionProps<T extends Record<string, number>> = AnimateOptions<T> & {\n initialStatus?: \"entered\" | \"exited\"\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n}\n\nconst useTransition = <T extends Record<string, number>>(props: UseTransitionProps<T>) => {\n const {\n initialStatus = \"exited\",\n onEnter,\n onEntered,\n onExit,\n onExited,\n ...options\n } = props\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val\n\n const [open, setOpen] = useState(initialStatus === \"entered\")\n const [status, setStatus] = useState<UseTransitionStatus>(initialStatus)\n\n const stateRef = useRef<T | null>(null)\n const readyRef = useRef(false)\n\n const animating = useRef<null | (() => void)>(null)\n\n useLayoutEffect(() => {\n const from = resolve(options.from)\n const to = resolve(options.to)\n stateRef.current = initialStatus === \"entered\" ? to : from\n readyRef.current = true\n }, [])\n\n const run = useCallback(\n (nextOpen: boolean, withAnimation = true) => {\n if (!readyRef.current || !stateRef.current) return\n\n animating.current?.()\n\n const resolvedFrom = resolve(options.from)\n const resolvedTo = resolve(options.to)\n const from = stateRef.current\n const to = nextOpen ? resolvedTo : resolvedFrom\n\n if (nextOpen) {\n setStatus(\"entering\")\n onEnter?.()\n } else {\n setStatus(\"exiting\")\n onExit?.()\n }\n\n if (!withAnimation) {\n stateRef.current = to\n options.onUpdate?.(to, 1)\n\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n\n options.onDone?.(stateRef.current)\n return\n }\n\n animating.current = animate({\n ...options,\n from,\n to,\n duration: options.duration ?? 400,\n onUpdate: (value: T, progress: number) => {\n stateRef.current = value\n options.onUpdate?.(value, progress)\n },\n onDone: (value) => {\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n options.onDone?.(value)\n },\n })\n },\n [options, onEnter, onEntered, onExit, onExited]\n )\n\n const enter = useCallback((withAnimation = true) => {\n setOpen(true)\n run(true, withAnimation)\n }, [run])\n\n const exit = useCallback((withAnimation = true) => {\n setOpen(false)\n run(false, withAnimation)\n }, [run])\n\n const toggle = useCallback((withAnimation = true) => {\n setOpen((prev) => {\n const next = !prev\n run(next, withAnimation)\n return next\n })\n }, [run])\n\n return {\n isEntered: open,\n status,\n state: stateRef,\n enter,\n exit,\n toggle,\n isReady: readyRef.current\n }\n}\n\nexport default useTransition"],"names":[],"mappings":";;;;;AAkBA;;;AAaG;;AAGA;AACA;AAEA;;;;AAKG;AACA;;;;;;AAOG;;;AAIA;;;;AAKG;;;;AAGA;;;AAIA;;;;AAKG;;;;AAGA;;;;;AAON;AAGG;;AAGG;;AAEH;;;;AAIM;;;;AAGA;;AAEH;AACH;AAEN;;;AAMA;AACH;;;AAIG;AACH;;AAGG;AACG;AACA;AACA;AACH;AACH;;AAGG;;AAEA;;;;;;AAMN;;"}
|