page-transition 0.1.0-beta.4 → 0.1.0-beta.41
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/README.md +103 -10
- package/dist/components/TransitionLink.d.ts +7 -2
- package/dist/components/TransitionLink.js +3 -2
- package/dist/context/CssTransitionProvider.d.ts +3 -2
- package/dist/context/CssTransitionProvider.js +58 -22
- package/dist/context/TransitionContext.d.ts +3 -2
- package/dist/context/TransitionContext.js +1 -4
- package/dist/functions/checkTransitionStart.d.ts +2 -0
- package/dist/functions/checkTransitionStart.js +15 -0
- package/dist/functions/parseDelay.js +1 -1
- package/dist/functions/parseDuration.d.ts +1 -0
- package/dist/functions/parseDuration.js +6 -0
- package/dist/functions/parseFirstClipPath.d.ts +1 -0
- package/dist/functions/parseFirstClipPath.js +12 -0
- package/dist/functions/parseFirstOpacity.d.ts +1 -0
- package/dist/functions/parseFirstOpacity.js +8 -0
- package/dist/functions/parseOpacity.js +1 -1
- package/dist/functions/parseProperty.d.ts +1 -0
- package/dist/functions/parseProperty.js +11 -0
- package/dist/functions/pollTransitionStart.d.ts +9 -0
- package/dist/functions/pollTransitionStart.js +11 -0
- package/dist/functions/setDelayReverse.d.ts +7 -0
- package/dist/functions/setDelayReverse.js +13 -0
- package/dist/functions/setPlaybackRate.d.ts +7 -0
- package/dist/functions/setPlaybackRate.js +10 -0
- package/dist/functions/transitionEnd.d.ts +3 -11
- package/dist/functions/transitionEnd.js +9 -8
- package/dist/functions/transitionEndReverse.d.ts +3 -11
- package/dist/functions/transitionEndReverse.js +20 -21
- package/dist/functions/updatePlaybackRate.d.ts +11 -0
- package/dist/functions/updatePlaybackRate.js +57 -0
- package/dist/hooks/manual/useHandleLinkClick.js +1 -0
- package/dist/hooks/useHandleLinkClick.d.ts +8 -10
- package/dist/hooks/useHandleLinkClick.js +101 -18
- package/dist/hooks/usePopState.d.ts +7 -10
- package/dist/hooks/usePopState.js +97 -18
- package/dist/hooks/useTransitionEndData.d.ts +4 -5
- package/dist/hooks/useTransitionEndData.js +6 -4
- package/dist/hooks/useTransitionEndHandler.d.ts +1 -5
- package/dist/hooks/useTransitionEndObj.d.ts +1 -9
- package/dist/hooks/useTransitionEndObj.js +5 -3
- package/dist/types/transitionEnd.types.d.ts +17 -0
- package/dist/types/transitionEnd.types.js +1 -0
- package/package.json +1 -1
- package/dist/functions/checkTransitionFinish.d.ts +0 -6
- package/dist/functions/checkTransitionFinish.js +0 -13
- package/dist/functions/parseClipPathAll.d.ts +0 -1
- package/dist/functions/parseClipPathAll.js +0 -20
- package/dist/functions/parseOpacityAll.d.ts +0 -1
- package/dist/functions/parseOpacityAll.js +0 -13
- package/dist/functions/wait.d.ts +0 -2
- package/dist/functions/wait.js +0 -12
package/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
# page-transition
|
|
2
|
-
A page transition library for the Next.js App Router.
|
|
3
|
-
|
|
2
|
+
A page transition library for the Next.js App Router.
|
|
3
|
+
|
|
4
|
+
[](https://simon-schindler.github.io/page-transition-demo/)
|
|
5
|
+
|
|
6
|
+
|
|
4
7
|
## Features
|
|
5
8
|
|
|
6
9
|
- CSS & Manual mode
|
|
7
10
|
- Scroll restoration
|
|
8
11
|
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
## Install
|
|
13
|
+
 
|
|
14
|
+
|
|
15
|
+
`npm install page-transition@beta`
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
14
18
|
Import your page transition styles and wrap your page content with `TransitionProvider` in your root layout.
|
|
15
19
|
|
|
16
20
|
```tsx
|
|
@@ -47,6 +51,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
47
51
|
|---|---|---|
|
|
48
52
|
| transitionProperty | "opacity" \| "clip-path" | "opacity" |
|
|
49
53
|
| overlayCount | number | 0 |
|
|
54
|
+
| mirror | boolean | false |
|
|
50
55
|
|
|
51
56
|
**Prop Descriptions**
|
|
52
57
|
|
|
@@ -57,11 +62,14 @@ Select the transition mode.
|
|
|
57
62
|
The component rendered outside the transition container.
|
|
58
63
|
|
|
59
64
|
**options.transitionProperty**
|
|
60
|
-
Defines which property transitionend waits for.
|
|
61
|
-
|
|
65
|
+
Defines which property transitionend waits for.
|
|
66
|
+
|
|
62
67
|
**options.overlayCount**
|
|
63
68
|
Defines how many overlay items should be created.
|
|
64
69
|
|
|
70
|
+
**options.mirror**
|
|
71
|
+
Creates the same number of items as specified by overlayCount.
|
|
72
|
+
|
|
65
73
|
|
|
66
74
|
```tsx
|
|
67
75
|
<TransitionProvider
|
|
@@ -109,6 +117,10 @@ After navigation, the `exit` class is removed and the `enter` class is added. On
|
|
|
109
117
|
|
|
110
118
|
For overlay animations, a `.overlay-wrapper` is available. You can add overlay items by setting the `overlayCount` option.
|
|
111
119
|
|
|
120
|
+
If mirror is set to true, the same number of div elements specified by `overlayCount` are added to the `.overlay-wrapper` with the class `mirror-item`. The transitionend dont wait for mirror items. This ideal for mirror effects.
|
|
121
|
+
|
|
122
|
+
*At the moment, it only supports duration and delay in seconds.*
|
|
123
|
+
|
|
112
124
|
To access the overlay wrapper and its items, use `useTransitionContext`.
|
|
113
125
|
|
|
114
126
|
```ts
|
|
@@ -226,11 +238,92 @@ overlayCount: 10
|
|
|
226
238
|
```
|
|
227
239
|
</details>
|
|
228
240
|
|
|
241
|
+
<details>
|
|
242
|
+
<summary>Mirrored Staggered Overlays</summary>
|
|
243
|
+
<br/>
|
|
244
|
+
options
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
transitionProperty: "clip-path"
|
|
248
|
+
overlayCount: 10
|
|
249
|
+
mirror: true
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
```scss
|
|
253
|
+
[data-transition] .overlay-wrapper{
|
|
254
|
+
position: fixed;
|
|
255
|
+
inset: 0;
|
|
256
|
+
|
|
257
|
+
display: grid;
|
|
258
|
+
grid-template-columns: repeat(10, 1fr);
|
|
259
|
+
grid-template-rows: repeat(2, 1fr);
|
|
260
|
+
}
|
|
261
|
+
[data-transition] .overlay-item{
|
|
262
|
+
grid-row: 1;
|
|
263
|
+
background: black;
|
|
264
|
+
|
|
265
|
+
transition: none;
|
|
266
|
+
will-change: clip-path;
|
|
267
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
268
|
+
}
|
|
269
|
+
[data-transition].exit .overlay-item{
|
|
270
|
+
grid-row: 1;
|
|
271
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
272
|
+
transition: clip-path 1.2s ease;
|
|
273
|
+
@for $i from 0 to 10{
|
|
274
|
+
&:nth-child(#{$i+1}){
|
|
275
|
+
transition-delay: $i * 0.3s;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
[data-transition].enter .overlay-item{
|
|
280
|
+
grid-row: 1;
|
|
281
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
282
|
+
transition: clip-path 1.2s ease;
|
|
283
|
+
@for $i from 0 to 10{
|
|
284
|
+
&:nth-child(#{$i+1}){
|
|
285
|
+
transition-delay: $i * 0.3s;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// .mirror-item
|
|
290
|
+
[data-transition] .mirror-item{
|
|
291
|
+
grid-row: 2;
|
|
292
|
+
background: black;
|
|
293
|
+
|
|
294
|
+
transition: none;
|
|
295
|
+
will-change: clip-path;
|
|
296
|
+
clip-path: inset(100% 0 0 0);
|
|
297
|
+
}
|
|
298
|
+
[data-transition].exit .mirror-item{
|
|
299
|
+
grid-row: 2;
|
|
300
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
301
|
+
transition: clip-path 1.2s ease;
|
|
302
|
+
@for $i from 0 to 10{
|
|
303
|
+
&:nth-child(#{$i+11}){
|
|
304
|
+
transition-delay: $i * 0.3s;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
[data-transition].enter .mirror-item{
|
|
309
|
+
grid-row: 2;
|
|
310
|
+
clip-path: inset(100% -1px 0 -1px);
|
|
311
|
+
transition: clip-path 1.2s ease;
|
|
312
|
+
@for $i from 0 to 10{
|
|
313
|
+
&:nth-child(#{$i+11}){
|
|
314
|
+
transition-delay: $i * 0.3s;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
</details>
|
|
321
|
+
|
|
229
322
|
### Manual Mode
|
|
230
323
|
|
|
231
324
|
In manual mode, you can control the transition using `useTransitionContext`.
|
|
232
325
|
|
|
233
|
-
After triggering the navigation, `state.current` is set to `exiting`. You can then call `resolveFn.current()` to proceed with the navigation. Once `state.current` is set to `entering`, the
|
|
326
|
+
After triggering the navigation, `state.current` is set to `exiting`. You can then call `resolveFn.current()` to proceed with the navigation. Once `state.current` is set to `entering`, the navigation has occurred. After the animation finishes, `state.current` should be set to `idle`.
|
|
234
327
|
|
|
235
328
|
|
|
236
329
|
```ts
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
interface Props {
|
|
3
3
|
href: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
prefetch?: boolean;
|
|
6
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
4
7
|
children: ReactNode;
|
|
5
|
-
}
|
|
8
|
+
}
|
|
9
|
+
export declare function TransitionLink({ href, className, prefetch, onClick, children }: Props): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import Link from "next/link";
|
|
3
3
|
import { useTransitionContext } from "../context/TransitionContext";
|
|
4
|
-
export function TransitionLink({ href, children }) {
|
|
4
|
+
export function TransitionLink({ href, className, prefetch, onClick, children }) {
|
|
5
5
|
const { handleLinkClick } = useTransitionContext();
|
|
6
6
|
return (_jsx(Link, { href: href, onClick: (e) => {
|
|
7
7
|
handleLinkClick.current(e, href);
|
|
8
|
-
|
|
8
|
+
onClick?.(e);
|
|
9
|
+
}, className: className, prefetch: prefetch, children: children }));
|
|
9
10
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
interface TransitionOptions {
|
|
3
|
-
transitionProperty
|
|
4
|
-
overlayCount
|
|
3
|
+
transitionProperty?: 'opacity' | 'clip-path';
|
|
4
|
+
overlayCount?: number;
|
|
5
|
+
mirror?: boolean;
|
|
5
6
|
}
|
|
6
7
|
interface ProviderProps {
|
|
7
8
|
header?: ReactNode;
|
|
@@ -11,29 +11,36 @@ import { useHandleLinkClick } from "../hooks/useHandleLinkClick";
|
|
|
11
11
|
import { useScrollRestoration } from "../hooks/useScrollRestoration";
|
|
12
12
|
import { usePopState } from "../hooks/usePopState";
|
|
13
13
|
import { parseDelay } from "../functions/parseDelay";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import { parseDuration } from "../functions/parseDuration";
|
|
15
|
+
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
16
|
+
export function CssTransitionProvider({ header, options, children }) {
|
|
17
|
+
const defaultOptions = {
|
|
18
|
+
transitionProperty: 'opacity',
|
|
19
|
+
overlayCount: 0,
|
|
20
|
+
mirror: false,
|
|
21
|
+
...options
|
|
22
|
+
};
|
|
18
23
|
const container = useRef(null);
|
|
19
24
|
const overlayWrapper = useRef(null);
|
|
20
25
|
const overlayItems = useRef([]);
|
|
26
|
+
const mirrorItems = useRef([]);
|
|
21
27
|
const pathname = usePathname();
|
|
22
28
|
const currentPathname = useRef(pathname);
|
|
23
|
-
const resolveUseFn = useRef(null);
|
|
24
29
|
const mount = useRef({
|
|
25
30
|
mounted: false,
|
|
26
31
|
initPathname: pathname
|
|
27
32
|
});
|
|
28
33
|
const state = useRef('idle');
|
|
34
|
+
const basePath = useRef(null);
|
|
29
35
|
const useUse = useRef(false);
|
|
36
|
+
const resolveUseFn = useRef(null);
|
|
30
37
|
const reverse = useRef({
|
|
31
38
|
_lock: true,
|
|
32
39
|
get lock() {
|
|
33
40
|
return this._lock;
|
|
34
41
|
},
|
|
35
42
|
set lock(value) {
|
|
36
|
-
if (
|
|
43
|
+
if (delayStep.current === 0 || overlayItems.current.length < 2) {
|
|
37
44
|
if (this._lock === false)
|
|
38
45
|
this._lock = true;
|
|
39
46
|
return;
|
|
@@ -41,13 +48,19 @@ export function CssTransitionProvider({ header, options = {
|
|
|
41
48
|
this._lock = value;
|
|
42
49
|
}
|
|
43
50
|
});
|
|
44
|
-
const
|
|
51
|
+
const delayStep = useRef(null);
|
|
52
|
+
const duration = useRef(null);
|
|
45
53
|
const handleLinkClick = useRef(() => { });
|
|
46
54
|
const transitionEndHandler = useTransitionEndHandler();
|
|
47
55
|
const transitionEndData = useTransitionEndData({
|
|
48
|
-
elArray:
|
|
49
|
-
transitionProperty:
|
|
56
|
+
elArray: defaultOptions.overlayCount === 0 ? container : overlayItems,
|
|
57
|
+
transitionProperty: defaultOptions.transitionProperty,
|
|
58
|
+
mirror: defaultOptions.mirror,
|
|
59
|
+
mirrorElArray: mirrorItems
|
|
50
60
|
});
|
|
61
|
+
const pollRafId = useRef(null);
|
|
62
|
+
const rafId = useRef(null);
|
|
63
|
+
const rejectFn = useRef(null);
|
|
51
64
|
usePopState({
|
|
52
65
|
container,
|
|
53
66
|
currentPathname,
|
|
@@ -55,9 +68,13 @@ export function CssTransitionProvider({ header, options = {
|
|
|
55
68
|
transitionEndHandler,
|
|
56
69
|
state,
|
|
57
70
|
reverse,
|
|
58
|
-
delay,
|
|
59
71
|
useUse,
|
|
60
|
-
resolveUseFn
|
|
72
|
+
resolveUseFn,
|
|
73
|
+
pollRafId,
|
|
74
|
+
rafId,
|
|
75
|
+
rejectFn,
|
|
76
|
+
delayStep,
|
|
77
|
+
duration
|
|
61
78
|
});
|
|
62
79
|
useHandleLinkClick({
|
|
63
80
|
container,
|
|
@@ -67,9 +84,14 @@ export function CssTransitionProvider({ header, options = {
|
|
|
67
84
|
transitionEndHandler,
|
|
68
85
|
state,
|
|
69
86
|
reverse,
|
|
70
|
-
delay,
|
|
71
87
|
useUse,
|
|
72
|
-
resolveUseFn
|
|
88
|
+
resolveUseFn,
|
|
89
|
+
basePath,
|
|
90
|
+
pollRafId,
|
|
91
|
+
rafId,
|
|
92
|
+
rejectFn,
|
|
93
|
+
delayStep,
|
|
94
|
+
duration
|
|
73
95
|
});
|
|
74
96
|
useScrollRestoration();
|
|
75
97
|
const removeEnter = useTransitionEndObj({
|
|
@@ -83,28 +105,42 @@ export function CssTransitionProvider({ header, options = {
|
|
|
83
105
|
useEffect(() => {
|
|
84
106
|
if (mount.current.mounted === false &&
|
|
85
107
|
mount.current.initPathname === pathname) {
|
|
108
|
+
currentPathname.current = window.location.pathname;
|
|
109
|
+
basePath.current = window.location.pathname.slice(0, -pathname.length);
|
|
86
110
|
return;
|
|
87
111
|
}
|
|
88
112
|
mount.current.mounted = true;
|
|
89
|
-
if (delay.current === null) {
|
|
90
|
-
delay.current = parseDelay(transitionEndData.current.elArray);
|
|
91
|
-
}
|
|
92
113
|
if (!container.current)
|
|
93
114
|
return;
|
|
94
115
|
transitionEnd({
|
|
95
116
|
transitionEndObj: removeEnter,
|
|
96
117
|
transitionEndHandler,
|
|
97
118
|
reverse,
|
|
98
|
-
|
|
119
|
+
delayStep
|
|
99
120
|
});
|
|
100
121
|
container.current.classList.remove('exit');
|
|
101
122
|
container.current.classList.add('enter');
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
pollTransitionStart({
|
|
124
|
+
transitionEndData,
|
|
125
|
+
id: pollRafId,
|
|
126
|
+
fn: () => {
|
|
127
|
+
state.current = 'entering';
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
currentPathname.current = window.location.pathname;
|
|
104
131
|
reverse.current.lock = false;
|
|
132
|
+
if (delayStep.current === null && defaultOptions.overlayCount > 1) {
|
|
133
|
+
delayStep.current = parseDelay(transitionEndData.current.elArray);
|
|
134
|
+
}
|
|
135
|
+
if (duration.current === null) {
|
|
136
|
+
duration.current = parseDuration(transitionEndData.current.elArray[0]);
|
|
137
|
+
duration.current = (duration.current ?? 0) * 1000 / 2;
|
|
138
|
+
}
|
|
105
139
|
}, [pathname]);
|
|
106
140
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
107
|
-
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [
|
|
108
|
-
|
|
109
|
-
|
|
141
|
+
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [_jsxs("div", { ref: overlayWrapper, className: "overlay-wrapper", children: [defaultOptions.overlayCount > 0 && Array.from({ length: defaultOptions.overlayCount }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
142
|
+
overlayItems.current[i] = el;
|
|
143
|
+
}, className: "overlay-item" }, i))), defaultOptions.mirror && Array.from({ length: defaultOptions.overlayCount }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
144
|
+
mirrorItems.current[i] = el;
|
|
145
|
+
}, className: "mirror-item" }, `mirror${i}`)))] }), children] })] }));
|
|
110
146
|
}
|
|
@@ -11,8 +11,9 @@ export declare function useTransitionContext(): ContextProps;
|
|
|
11
11
|
type Mode = 'css' | 'manual';
|
|
12
12
|
type TransitionProperty = 'opacity' | 'clip-path';
|
|
13
13
|
interface TransitionOptions {
|
|
14
|
-
transitionProperty
|
|
15
|
-
overlayCount
|
|
14
|
+
transitionProperty?: TransitionProperty;
|
|
15
|
+
overlayCount?: number;
|
|
16
|
+
mirror?: boolean;
|
|
16
17
|
}
|
|
17
18
|
interface ProviderProps {
|
|
18
19
|
header?: ReactNode;
|
|
@@ -10,10 +10,7 @@ export function useTransitionContext() {
|
|
|
10
10
|
throw new Error('useTransitionContext in Provider!');
|
|
11
11
|
return context;
|
|
12
12
|
}
|
|
13
|
-
export function TransitionProvider({ header, mode = 'css', options
|
|
14
|
-
transitionProperty: 'opacity',
|
|
15
|
-
overlayCount: 0
|
|
16
|
-
}, children, }) {
|
|
13
|
+
export function TransitionProvider({ header, mode = 'css', options, children, }) {
|
|
17
14
|
return (mode === 'css' ?
|
|
18
15
|
_jsx(CssTransitionProvider, { header: header, options: options, children: children }) :
|
|
19
16
|
_jsx(ManualTransitionProvider, { children: children }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseFirstOpacity } from "./parseFirstOpacity";
|
|
2
|
+
import { parseFirstClipPath } from "./parseFirstClipPath";
|
|
3
|
+
export function checkTransitionStart(transitionEndData, fn) {
|
|
4
|
+
const parse = {
|
|
5
|
+
'opacity': () => parseFirstOpacity(transitionEndData.elArray),
|
|
6
|
+
'clip-path': () => parseFirstClipPath(transitionEndData.elArray)
|
|
7
|
+
};
|
|
8
|
+
if (parse[transitionEndData.transitionProperty]()) {
|
|
9
|
+
fn?.();
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseDuration(el: HTMLElement | null): number | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseFirstClipPath(elArray: (HTMLDivElement | null)[]): null | boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function parseFirstClipPath(elArray) {
|
|
2
|
+
if (!elArray[0])
|
|
3
|
+
return null;
|
|
4
|
+
const clipPath = getComputedStyle(elArray[0]).clipPath;
|
|
5
|
+
const m = clipPath.match(/inset\(([^)]+)\)/) ?? null;
|
|
6
|
+
const arr = m?.[1].split(/\s+/) ?? [];
|
|
7
|
+
for (const string of arr) {
|
|
8
|
+
if (parseFloat(string) < 100)
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseFirstOpacity(elArray: (HTMLDivElement | null)[]): null | boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseProperty(transitionProperty: 'opacity' | 'clip-path', el: HTMLDivElement | null): number | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { parseOpacity } from "./parseOpacity";
|
|
2
|
+
import { parseClipPath } from "./parseClipPath";
|
|
3
|
+
export function parseProperty(transitionProperty, el) {
|
|
4
|
+
if (!el)
|
|
5
|
+
return null;
|
|
6
|
+
const parse = {
|
|
7
|
+
'opacity': parseOpacity,
|
|
8
|
+
'clip-path': parseClipPath
|
|
9
|
+
};
|
|
10
|
+
return parse[transitionProperty](el);
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { TransitionEndData } from "../types/transitionEnd.types";
|
|
3
|
+
interface Props {
|
|
4
|
+
id: RefObject<number | null>;
|
|
5
|
+
fn: () => void;
|
|
6
|
+
transitionEndData: RefObject<TransitionEndData>;
|
|
7
|
+
}
|
|
8
|
+
export declare function pollTransitionStart({ id, fn, transitionEndData }: Props): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { checkTransitionStart } from "./checkTransitionStart";
|
|
2
|
+
export function pollTransitionStart({ id, fn, transitionEndData }) {
|
|
3
|
+
if (id.current !== null)
|
|
4
|
+
cancelAnimationFrame(id.current);
|
|
5
|
+
id.current = requestAnimationFrame(() => {
|
|
6
|
+
if (checkTransitionStart(transitionEndData.current, fn)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
pollTransitionStart({ id, fn, transitionEndData });
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parseProperty } from "./parseProperty";
|
|
2
|
+
export function setDelayReverse({ elArray, transitionProperty, delayStep }) {
|
|
3
|
+
if (elArray.length < 2 || !delayStep)
|
|
4
|
+
return;
|
|
5
|
+
let summ = 0;
|
|
6
|
+
elArray.toReversed().forEach((el, i) => {
|
|
7
|
+
if (!el)
|
|
8
|
+
return;
|
|
9
|
+
el.style.transitionDelay = `${summ}s`;
|
|
10
|
+
const progress = parseProperty(transitionProperty, el) ?? 0;
|
|
11
|
+
summ += (delayStep * progress);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function setPlaybackRate({ elArray, transitionProperty, value }) {
|
|
2
|
+
elArray.forEach((el) => {
|
|
3
|
+
el?.getAnimations().forEach((obj) => {
|
|
4
|
+
if (obj instanceof CSSTransition &&
|
|
5
|
+
obj.transitionProperty === transitionProperty) {
|
|
6
|
+
obj.playbackRate = value;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
fn: (() => void) | null;
|
|
6
|
-
}
|
|
7
|
-
interface TransitionEndHandler {
|
|
8
|
-
handler: ((e: TransitionEvent) => void) | null;
|
|
9
|
-
handlerEl: HTMLDivElement | null;
|
|
10
|
-
}
|
|
2
|
+
import type { TransitionEndObj, TransitionEndHandler } from "../types/transitionEnd.types";
|
|
11
3
|
interface Props {
|
|
12
4
|
transitionEndObj: RefObject<TransitionEndObj>;
|
|
13
5
|
transitionEndHandler: RefObject<TransitionEndHandler>;
|
|
@@ -15,7 +7,7 @@ interface Props {
|
|
|
15
7
|
_lock: boolean;
|
|
16
8
|
lock: boolean;
|
|
17
9
|
}>;
|
|
18
|
-
|
|
10
|
+
delayStep: RefObject<number | null>;
|
|
19
11
|
}
|
|
20
|
-
export declare function transitionEnd({ transitionEndObj, transitionEndHandler, reverse,
|
|
12
|
+
export declare function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
|
|
21
13
|
export {};
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { transtionEndReverse } from "./transitionEndReverse";
|
|
2
|
-
export function transitionEnd({ transitionEndObj, transitionEndHandler, reverse,
|
|
2
|
+
export function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delayStep }) {
|
|
3
3
|
const lastIndex = transitionEndObj.current.elArray.length - 1;
|
|
4
4
|
if (transitionEndHandler.current.handler &&
|
|
5
5
|
transitionEndHandler.current.handlerEl) {
|
|
6
6
|
transitionEndHandler.current.handlerEl.removeEventListener('transitionend', transitionEndHandler.current.handler);
|
|
7
7
|
}
|
|
8
|
+
const endObj = transitionEndObj.current;
|
|
8
9
|
if (!reverse.current.lock) {
|
|
9
10
|
transtionEndReverse({
|
|
10
11
|
transitionEndObj,
|
|
11
12
|
transitionEndHandler,
|
|
12
13
|
reverse,
|
|
13
|
-
|
|
14
|
+
delayStep
|
|
14
15
|
});
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
const handler = (e) => {
|
|
18
19
|
if (e.target !== e.currentTarget)
|
|
19
20
|
return;
|
|
20
|
-
if (
|
|
21
|
-
e.propertyName !==
|
|
21
|
+
if (endObj.transitionProperty &&
|
|
22
|
+
e.propertyName !== endObj.transitionProperty)
|
|
22
23
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
endObj.elArray[lastIndex]?.removeEventListener('transitionend', handler);
|
|
25
|
+
endObj.fn?.();
|
|
25
26
|
};
|
|
26
27
|
transitionEndHandler.current.handler = handler;
|
|
27
|
-
transitionEndHandler.current.handlerEl =
|
|
28
|
-
|
|
28
|
+
transitionEndHandler.current.handlerEl = endObj.elArray[lastIndex];
|
|
29
|
+
endObj.elArray[lastIndex]?.addEventListener('transitionend', transitionEndHandler.current.handler);
|
|
29
30
|
}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
fn: (() => void) | null;
|
|
6
|
-
}
|
|
7
|
-
interface TransitionEndHandler {
|
|
8
|
-
handler: ((e: TransitionEvent) => void) | null;
|
|
9
|
-
handlerEl: HTMLDivElement | null;
|
|
10
|
-
}
|
|
2
|
+
import type { TransitionEndObj, TransitionEndHandler } from "../types/transitionEnd.types";
|
|
11
3
|
interface Props {
|
|
12
4
|
transitionEndObj: RefObject<TransitionEndObj>;
|
|
13
5
|
transitionEndHandler: RefObject<TransitionEndHandler>;
|
|
@@ -15,7 +7,7 @@ interface Props {
|
|
|
15
7
|
_lock: boolean;
|
|
16
8
|
lock: boolean;
|
|
17
9
|
}>;
|
|
18
|
-
|
|
10
|
+
delayStep: RefObject<number | null>;
|
|
19
11
|
}
|
|
20
|
-
export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse,
|
|
12
|
+
export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
|
|
21
13
|
export {};
|