page-transition 0.1.0-beta.42 → 0.1.0-beta.43
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 +12 -8
- package/dist/components/TransitionLink.js +1 -1
- package/dist/context/CssTransitionProvider.d.ts +1 -0
- package/dist/context/CssTransitionProvider.js +8 -4
- package/dist/context/TransitionContext.d.ts +1 -0
- package/dist/functions/updatePlaybackRate.js +0 -7
- package/dist/hooks/useHandleLinkClick.d.ts +2 -1
- package/dist/hooks/useHandleLinkClick.js +44 -1
- package/dist/hooks/usePopState.d.ts +2 -1
- package/dist/hooks/usePopState.js +44 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# page-transition
|
|
2
|
-
A page transition library for the Next.js App Router.
|
|
1
|
+
# <img src="./assets/logo.svg" width="32"/> page-transition
|
|
2
|
+
A page transition library for the Next.js App Router.
|
|
3
|
+
<br/>
|
|
4
|
+
[](https://simon-schindler.github.io/page-transition-demo/)
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- CSS & Manual mode
|
|
10
10
|
- Scroll restoration
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
|
-
 
|
|
14
14
|
|
|
15
15
|
`npm install page-transition@beta`
|
|
16
16
|
|
|
@@ -50,6 +50,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
50
50
|
| Option | Type | Default |
|
|
51
51
|
|---|---|---|
|
|
52
52
|
| transitionProperty | "opacity" \| "clip-path" | "opacity" |
|
|
53
|
+
| wait | boolean | false |
|
|
53
54
|
| overlayCount | number | 0 |
|
|
54
55
|
| mirror | boolean | false |
|
|
55
56
|
|
|
@@ -64,6 +65,9 @@ The component rendered outside the transition container.
|
|
|
64
65
|
**options.transitionProperty**
|
|
65
66
|
Defines which property transitionend waits for.
|
|
66
67
|
|
|
68
|
+
**options.wait**
|
|
69
|
+
Starts a new transition after the current transition has finished.
|
|
70
|
+
|
|
67
71
|
**options.overlayCount**
|
|
68
72
|
Defines how many overlay items should be created.
|
|
69
73
|
|
|
@@ -111,13 +115,13 @@ Triggers the transition.
|
|
|
111
115
|
|
|
112
116
|
The `TransitionProvider` uses a container with a `data-transition` attribute. When navigation starts, it adds the `exit` class and waits for the transitionend event of the configured transition property.
|
|
113
117
|
|
|
114
|
-
Once the transition ends,
|
|
118
|
+
Once the transition ends, the scroll position is restored and navigation is performed.
|
|
115
119
|
|
|
116
120
|
After navigation, the `exit` class is removed and the `enter` class is added. Once the next transitionend event fires, the enter class is removed.
|
|
117
121
|
|
|
118
122
|
For overlay animations, a `.overlay-wrapper` is available. You can add overlay items by setting the `overlayCount` option.
|
|
119
123
|
|
|
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.
|
|
124
|
+
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.
|
|
121
125
|
|
|
122
126
|
*At the moment, it only supports duration and delay in seconds.*
|
|
123
127
|
|
|
@@ -4,7 +4,7 @@ import { useTransitionContext } from "../context/TransitionContext";
|
|
|
4
4
|
export function TransitionLink({ href, className, prefetch, onClick, children }) {
|
|
5
5
|
const { handleLinkClick } = useTransitionContext();
|
|
6
6
|
return (_jsx(Link, { href: href, onClick: (e) => {
|
|
7
|
-
handleLinkClick.current(e, href);
|
|
8
7
|
onClick?.(e);
|
|
8
|
+
handleLinkClick.current(e, href);
|
|
9
9
|
}, className: className, prefetch: prefetch, children: children }));
|
|
10
10
|
}
|
|
@@ -16,6 +16,7 @@ import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
|
16
16
|
export function CssTransitionProvider({ header, options, children }) {
|
|
17
17
|
const defaultOptions = {
|
|
18
18
|
transitionProperty: 'opacity',
|
|
19
|
+
wait: false,
|
|
19
20
|
overlayCount: 0,
|
|
20
21
|
mirror: false,
|
|
21
22
|
...options
|
|
@@ -74,7 +75,8 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
74
75
|
rafId,
|
|
75
76
|
rejectFn,
|
|
76
77
|
delayStep,
|
|
77
|
-
duration
|
|
78
|
+
duration,
|
|
79
|
+
wait: defaultOptions.wait
|
|
78
80
|
});
|
|
79
81
|
useHandleLinkClick({
|
|
80
82
|
container,
|
|
@@ -91,7 +93,8 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
91
93
|
rafId,
|
|
92
94
|
rejectFn,
|
|
93
95
|
delayStep,
|
|
94
|
-
duration
|
|
96
|
+
duration,
|
|
97
|
+
wait: defaultOptions.wait
|
|
95
98
|
});
|
|
96
99
|
useScrollRestoration();
|
|
97
100
|
const removeEnter = useTransitionEndObj({
|
|
@@ -130,9 +133,10 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
130
133
|
currentPathname.current = window.location.pathname;
|
|
131
134
|
reverse.current.lock = false;
|
|
132
135
|
if (delayStep.current === null && defaultOptions.overlayCount > 1) {
|
|
133
|
-
delayStep.current =
|
|
136
|
+
delayStep.current = defaultOptions.wait ? 0 :
|
|
137
|
+
parseDelay(transitionEndData.current.elArray);
|
|
134
138
|
}
|
|
135
|
-
if (duration.current === null) {
|
|
139
|
+
if (duration.current === null && !defaultOptions.wait) {
|
|
136
140
|
duration.current = parseDuration(transitionEndData.current.elArray[0]);
|
|
137
141
|
duration.current = (duration.current ?? 0) * 1000 / 2;
|
|
138
142
|
}
|
|
@@ -36,13 +36,6 @@ export function updatePlaybackRate({ rafId, rejectFn, elArray, transitionPropert
|
|
|
36
36
|
currentTime <= 0 && start)
|
|
37
37
|
return;
|
|
38
38
|
obj.updatePlaybackRate(progress);
|
|
39
|
-
console.log("AFTER", {
|
|
40
|
-
meinProg: progress,
|
|
41
|
-
rate: obj.playbackRate,
|
|
42
|
-
currentTime: obj.currentTime,
|
|
43
|
-
playState: obj.playState,
|
|
44
|
-
startTime: obj.startTime,
|
|
45
|
-
});
|
|
46
39
|
});
|
|
47
40
|
if (target && progress >= 1 || !target && progress <= 0) {
|
|
48
41
|
if (rafId.current !== null) {
|
|
@@ -19,6 +19,7 @@ interface Props {
|
|
|
19
19
|
rejectFn: RefObject<(() => void) | null>;
|
|
20
20
|
delayStep: RefObject<number | null>;
|
|
21
21
|
duration: RefObject<number | null>;
|
|
22
|
+
wait: boolean;
|
|
22
23
|
}
|
|
23
|
-
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration }: Props): void;
|
|
24
|
+
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration, wait }: Props): void;
|
|
24
25
|
export {};
|
|
@@ -6,7 +6,7 @@ import { transitionEnd } from "../functions/transitionEnd";
|
|
|
6
6
|
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
7
7
|
import { updatePlaybackRate } from "../functions/updatePlaybackRate";
|
|
8
8
|
import { setPlaybackRate } from "../functions/setPlaybackRate";
|
|
9
|
-
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration }) {
|
|
9
|
+
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration, wait }) {
|
|
10
10
|
const router = useRouter();
|
|
11
11
|
const afterExitFn = useRef(null);
|
|
12
12
|
const nextPage = useRef(null);
|
|
@@ -66,6 +66,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
66
66
|
}
|
|
67
67
|
rejectFn.current?.();
|
|
68
68
|
container.current?.classList.remove('enter');
|
|
69
|
+
void container.current?.offsetWidth;
|
|
69
70
|
container.current?.classList.add('exit');
|
|
70
71
|
state.current = 'exiting';
|
|
71
72
|
transitionEnd({
|
|
@@ -98,6 +99,48 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
98
99
|
resolve();
|
|
99
100
|
}
|
|
100
101
|
}).then(() => {
|
|
102
|
+
if (wait) {
|
|
103
|
+
if (currentPathname.current === basePathUrl
|
|
104
|
+
&& state.current === 'exiting') {
|
|
105
|
+
transitionEnd({
|
|
106
|
+
transitionEndObj: afterExit,
|
|
107
|
+
transitionEndHandler,
|
|
108
|
+
reverse,
|
|
109
|
+
delayStep
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (state.current === 'entering' &&
|
|
114
|
+
currentPathname.current === basePathUrl) {
|
|
115
|
+
transitionEnd({
|
|
116
|
+
transitionEndObj: removeEnter,
|
|
117
|
+
transitionEndHandler,
|
|
118
|
+
reverse,
|
|
119
|
+
delayStep
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (state.current === 'idle' || state.current === 'exiting') {
|
|
124
|
+
transitionEnd({
|
|
125
|
+
transitionEndObj: push,
|
|
126
|
+
transitionEndHandler,
|
|
127
|
+
reverse,
|
|
128
|
+
delayStep
|
|
129
|
+
});
|
|
130
|
+
container.current?.classList.remove('enter');
|
|
131
|
+
container.current?.classList.add('exit');
|
|
132
|
+
state.current = 'exiting';
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
transitionEnd({
|
|
136
|
+
transitionEndObj: afterEntering,
|
|
137
|
+
transitionEndHandler,
|
|
138
|
+
reverse,
|
|
139
|
+
delayStep
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
101
144
|
if (basePathUrl === currentPathname.current) {
|
|
102
145
|
if (state.current !== 'exiting')
|
|
103
146
|
return;
|
|
@@ -17,6 +17,7 @@ interface Props {
|
|
|
17
17
|
rejectFn: RefObject<(() => void) | null>;
|
|
18
18
|
delayStep: RefObject<number | null>;
|
|
19
19
|
duration: RefObject<number | null>;
|
|
20
|
+
wait: boolean;
|
|
20
21
|
}
|
|
21
|
-
export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration }: Props): void;
|
|
22
|
+
export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration, wait }: Props): void;
|
|
22
23
|
export {};
|
|
@@ -5,7 +5,7 @@ import { transitionEnd } from "../functions/transitionEnd";
|
|
|
5
5
|
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
6
6
|
import { updatePlaybackRate } from "../functions/updatePlaybackRate";
|
|
7
7
|
import { setPlaybackRate } from "../functions/setPlaybackRate";
|
|
8
|
-
export function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration }) {
|
|
8
|
+
export function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration, wait }) {
|
|
9
9
|
const [promise, setPromise] = useState(null);
|
|
10
10
|
if (promise) {
|
|
11
11
|
useUse.current = true;
|
|
@@ -68,6 +68,7 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
68
68
|
}
|
|
69
69
|
rejectFn.current?.();
|
|
70
70
|
container.current?.classList.remove('enter');
|
|
71
|
+
void container.current?.offsetWidth;
|
|
71
72
|
container.current?.classList.add('exit');
|
|
72
73
|
state.current = 'exiting';
|
|
73
74
|
transitionEnd({
|
|
@@ -98,6 +99,48 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
98
99
|
resolveNavigating();
|
|
99
100
|
}
|
|
100
101
|
}).then(() => {
|
|
102
|
+
if (wait) {
|
|
103
|
+
if (currentPathname.current === window.location.pathname
|
|
104
|
+
&& state.current === 'exiting') {
|
|
105
|
+
transitionEnd({
|
|
106
|
+
transitionEndObj: afterExit,
|
|
107
|
+
transitionEndHandler,
|
|
108
|
+
reverse,
|
|
109
|
+
delayStep
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (state.current === 'entering' &&
|
|
114
|
+
currentPathname.current === window.location.pathname) {
|
|
115
|
+
transitionEnd({
|
|
116
|
+
transitionEndObj: removeEnter,
|
|
117
|
+
transitionEndHandler,
|
|
118
|
+
reverse,
|
|
119
|
+
delayStep
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (state.current === 'idle' || state.current === 'exiting') {
|
|
124
|
+
transitionEnd({
|
|
125
|
+
transitionEndObj: pop,
|
|
126
|
+
transitionEndHandler,
|
|
127
|
+
reverse,
|
|
128
|
+
delayStep
|
|
129
|
+
});
|
|
130
|
+
container.current?.classList.remove('enter');
|
|
131
|
+
container.current?.classList.add('exit');
|
|
132
|
+
state.current = 'exiting';
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
transitionEnd({
|
|
136
|
+
transitionEndObj: afterEntering,
|
|
137
|
+
transitionEndHandler,
|
|
138
|
+
reverse,
|
|
139
|
+
delayStep
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
101
144
|
if (currentPathname.current === window.location.pathname) {
|
|
102
145
|
transitionEnd({
|
|
103
146
|
transitionEndObj: afterExit,
|