page-transition 0.1.0-beta.5 → 0.1.0-beta.50
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 +135 -30
- package/dist/components/TransitionLink.js +1 -1
- package/dist/context/CssTransitionProvider.d.ts +4 -3
- package/dist/context/CssTransitionProvider.js +29 -38
- package/dist/context/TransitionContext.d.ts +5 -5
- package/dist/context/TransitionContext.js +1 -1
- package/dist/functions/checkTransitionStart.d.ts +2 -0
- package/dist/functions/checkTransitionStart.js +10 -0
- package/dist/functions/pollTransitionStart.d.ts +9 -0
- package/dist/functions/pollTransitionStart.js +11 -0
- package/dist/functions/transitionEnd.d.ts +2 -15
- package/dist/functions/transitionEnd.js +8 -17
- package/dist/functions/transitionRunning.d.ts +2 -0
- package/dist/functions/transitionRunning.js +20 -0
- package/dist/hooks/manual/useHandleLinkClick.js +1 -0
- package/dist/hooks/useHandleLinkClick.d.ts +4 -14
- package/dist/hooks/useHandleLinkClick.js +66 -34
- package/dist/hooks/usePopState.d.ts +3 -14
- package/dist/hooks/usePopState.js +56 -32
- package/dist/hooks/useTransitionEndData.d.ts +5 -6
- package/dist/hooks/useTransitionEndData.js +5 -4
- package/dist/hooks/useTransitionEndHandler.d.ts +1 -5
- package/dist/hooks/useTransitionEndObj.d.ts +1 -9
- package/dist/hooks/useTransitionEndObj.js +4 -3
- package/dist/types/transitionEnd.types.d.ts +16 -0
- package/dist/types/transitionEnd.types.js +1 -0
- package/dist/types/transitionPropertys.types.d.ts +1 -0
- package/dist/types/transitionPropertys.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/parseClipPath.d.ts +0 -1
- package/dist/functions/parseClipPath.js +0 -9
- package/dist/functions/parseClipPathAll.d.ts +0 -1
- package/dist/functions/parseClipPathAll.js +0 -20
- package/dist/functions/parseDelay.d.ts +0 -1
- package/dist/functions/parseDelay.js +0 -10
- package/dist/functions/parseOpacity.d.ts +0 -1
- package/dist/functions/parseOpacity.js +0 -6
- package/dist/functions/parseOpacityAll.d.ts +0 -1
- package/dist/functions/parseOpacityAll.js +0 -13
- package/dist/functions/resetDelay.d.ts +0 -1
- package/dist/functions/resetDelay.js +0 -7
- package/dist/functions/transitionEndReverse.d.ts +0 -21
- package/dist/functions/transitionEndReverse.js +0 -36
- package/dist/functions/wait.d.ts +0 -2
- package/dist/functions/wait.js +0 -12
package/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
# page-transition
|
|
1
|
+
# <img src="./assets/logo.svg" width="32"/> page-transition
|
|
2
2
|
A page transition library for the Next.js App Router.
|
|
3
|
-
|
|
3
|
+
<br/>
|
|
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
|
|
@@ -43,10 +47,11 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
43
47
|
|
|
44
48
|
*Options*
|
|
45
49
|
|
|
46
|
-
| Option | Type | Default |
|
|
47
|
-
|
|
48
|
-
| transitionProperty | "opacity" \| "clip-path"
|
|
49
|
-
|
|
|
50
|
+
| Option | Type | Default | Required |
|
|
51
|
+
|---|---|---|---|
|
|
52
|
+
| transitionProperty | "opacity" \| "clip-path" \| "transform" | - | Yes |
|
|
53
|
+
| items | [number, number] | [0, 0] | - |
|
|
54
|
+
|
|
50
55
|
|
|
51
56
|
**Prop Descriptions**
|
|
52
57
|
|
|
@@ -54,13 +59,18 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
54
59
|
Select the transition mode.
|
|
55
60
|
|
|
56
61
|
**header**
|
|
57
|
-
The component rendered outside the
|
|
62
|
+
The component rendered outside the .page-wrapper.
|
|
58
63
|
|
|
59
64
|
**options.transitionProperty**
|
|
60
|
-
Defines which property transitionend waits for.
|
|
61
|
-
|
|
62
|
-
**options.
|
|
63
|
-
|
|
65
|
+
Defines which property transitionend waits for.
|
|
66
|
+
|
|
67
|
+
**options.items**
|
|
68
|
+
<br/>
|
|
69
|
+
`options.items[0]`
|
|
70
|
+
Number of items in the first group. Each item receives the `.overlay-item` class.
|
|
71
|
+
<br/>
|
|
72
|
+
`options.items[1]`
|
|
73
|
+
Number of items in the second group. Each item receives the `.second-item` class.
|
|
64
74
|
|
|
65
75
|
|
|
66
76
|
```tsx
|
|
@@ -68,7 +78,7 @@ Defines how many overlay items should be created.
|
|
|
68
78
|
header={<Header/>}
|
|
69
79
|
options={{
|
|
70
80
|
transitionProperty: "clip-path",
|
|
71
|
-
|
|
81
|
+
items: [1, 0]
|
|
72
82
|
}}
|
|
73
83
|
>
|
|
74
84
|
{children}
|
|
@@ -90,8 +100,9 @@ options={{
|
|
|
90
100
|
TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
|
|
91
101
|
|
|
92
102
|
**Description**
|
|
93
|
-
Triggers the transition.
|
|
103
|
+
Triggers the transition.
|
|
94
104
|
|
|
105
|
+
*Must be used within the TransitionProvider*
|
|
95
106
|
|
|
96
107
|
```tsx
|
|
97
108
|
<TransitionLink href={"/home"}>
|
|
@@ -101,20 +112,21 @@ Triggers the transition.
|
|
|
101
112
|
|
|
102
113
|
### CSS Mode
|
|
103
114
|
|
|
104
|
-
The `TransitionProvider` uses a container with a `data-transition` attribute. When navigation starts, it adds the
|
|
115
|
+
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. By default, this is the `.page-wrapper` containing the page's children. If options.items is configured, the event is instead tracked on the last item of the first group.
|
|
105
116
|
|
|
106
|
-
Once the transition ends,
|
|
117
|
+
Once the transition ends, the scroll position is restored and navigation is performed.
|
|
107
118
|
|
|
108
119
|
After navigation, the `exit` class is removed and the `enter` class is added. Once the next transitionend event fires, the enter class is removed.
|
|
109
120
|
|
|
110
|
-
For overlay animations,
|
|
111
|
-
|
|
121
|
+
For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array.
|
|
122
|
+
<br/>
|
|
123
|
+
<br/>
|
|
112
124
|
To access the overlay wrapper and its items, use `useTransitionContext`.
|
|
113
125
|
|
|
114
126
|
```ts
|
|
115
127
|
import { useTransitionContext } from "page-transition"
|
|
116
128
|
|
|
117
|
-
const {overlayWrapper, overlayItems} = useTransitionContext()
|
|
129
|
+
const { overlayWrapper, overlayItems } = useTransitionContext()
|
|
118
130
|
|
|
119
131
|
```
|
|
120
132
|
|
|
@@ -126,20 +138,20 @@ options
|
|
|
126
138
|
|
|
127
139
|
```ts
|
|
128
140
|
transitionProperty: "opacity"
|
|
129
|
-
|
|
141
|
+
|
|
130
142
|
```
|
|
131
143
|
|
|
132
144
|
```css
|
|
133
|
-
[data-transition]{
|
|
145
|
+
[data-transition] .page-wrapper{
|
|
134
146
|
will-change: opacity;
|
|
135
147
|
opacity: 1;
|
|
136
148
|
}
|
|
137
|
-
[data-transition].exit{
|
|
149
|
+
[data-transition].exit .page-wrapper{
|
|
138
150
|
opacity: 0;
|
|
139
151
|
transition: opacity 0.4s ease;
|
|
140
152
|
|
|
141
153
|
}
|
|
142
|
-
[data-transition].enter{
|
|
154
|
+
[data-transition].enter .page-wrapper{
|
|
143
155
|
opacity: 1;
|
|
144
156
|
transition: opacity 0.5s ease;
|
|
145
157
|
}
|
|
@@ -153,12 +165,24 @@ options
|
|
|
153
165
|
|
|
154
166
|
```ts
|
|
155
167
|
transitionProperty: "clip-path"
|
|
156
|
-
|
|
168
|
+
items: [1, 0]
|
|
157
169
|
```
|
|
158
170
|
|
|
159
171
|
```css
|
|
172
|
+
[data-transition] .page-wrapper{
|
|
173
|
+
opacity: 1;
|
|
174
|
+
transition: opacity 0.5s linear;
|
|
175
|
+
}
|
|
176
|
+
[data-transition].exit .page-wrapper{
|
|
177
|
+
opacity: 0;
|
|
178
|
+
}
|
|
179
|
+
[data-transition].enter .page-wrapper{
|
|
180
|
+
opacity: 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
160
183
|
[data-transition] .overlay-wrapper{
|
|
161
184
|
position: fixed;
|
|
185
|
+
z-index: 99;
|
|
162
186
|
inset: 0;
|
|
163
187
|
|
|
164
188
|
display: grid;
|
|
@@ -188,7 +212,7 @@ options
|
|
|
188
212
|
|
|
189
213
|
```ts
|
|
190
214
|
transitionProperty: "clip-path"
|
|
191
|
-
|
|
215
|
+
items: [10, 0]
|
|
192
216
|
```
|
|
193
217
|
|
|
194
218
|
```scss
|
|
@@ -226,11 +250,92 @@ overlayCount: 10
|
|
|
226
250
|
```
|
|
227
251
|
</details>
|
|
228
252
|
|
|
253
|
+
<details>
|
|
254
|
+
<summary>Mirrored Staggered Overlays</summary>
|
|
255
|
+
<br/>
|
|
256
|
+
options
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
transitionProperty: "clip-path"
|
|
260
|
+
items: [10, 10]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
```scss
|
|
264
|
+
[data-transition] .overlay-wrapper{
|
|
265
|
+
position: fixed;
|
|
266
|
+
inset: 0;
|
|
267
|
+
|
|
268
|
+
display: grid;
|
|
269
|
+
grid-template-columns: repeat(10, 1fr);
|
|
270
|
+
grid-template-rows: repeat(2, 1fr);
|
|
271
|
+
}
|
|
272
|
+
[data-transition] .overlay-item{
|
|
273
|
+
grid-row: 1;
|
|
274
|
+
background: black;
|
|
275
|
+
|
|
276
|
+
transition: none;
|
|
277
|
+
will-change: clip-path;
|
|
278
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
279
|
+
}
|
|
280
|
+
[data-transition].exit .overlay-item{
|
|
281
|
+
grid-row: 1;
|
|
282
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
283
|
+
transition: clip-path 1.2s ease;
|
|
284
|
+
@for $i from 0 to 10{
|
|
285
|
+
&:nth-child(#{$i+1}){
|
|
286
|
+
transition-delay: $i * 0.3s;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
[data-transition].enter .overlay-item{
|
|
291
|
+
grid-row: 1;
|
|
292
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
293
|
+
transition: clip-path 1.2s ease;
|
|
294
|
+
@for $i from 0 to 10{
|
|
295
|
+
&:nth-child(#{$i+1}){
|
|
296
|
+
transition-delay: $i * 0.3s;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// .second-item
|
|
301
|
+
[data-transition] .second-item{
|
|
302
|
+
grid-row: 2;
|
|
303
|
+
background: black;
|
|
304
|
+
|
|
305
|
+
transition: none;
|
|
306
|
+
will-change: clip-path;
|
|
307
|
+
clip-path: inset(100% 0 0 0);
|
|
308
|
+
}
|
|
309
|
+
[data-transition].exit .second-item{
|
|
310
|
+
grid-row: 2;
|
|
311
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
312
|
+
transition: clip-path 1.2s ease;
|
|
313
|
+
@for $i from 0 to 10{
|
|
314
|
+
&:nth-child(#{$i+11}){
|
|
315
|
+
transition-delay: $i * 0.3s;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
[data-transition].enter .second-item{
|
|
320
|
+
grid-row: 2;
|
|
321
|
+
clip-path: inset(100% -1px 0 -1px);
|
|
322
|
+
transition: clip-path 1.2s ease;
|
|
323
|
+
@for $i from 0 to 10{
|
|
324
|
+
&:nth-child(#{$i+11}){
|
|
325
|
+
transition-delay: $i * 0.3s;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
```
|
|
331
|
+
</details>
|
|
332
|
+
|
|
333
|
+
|
|
229
334
|
### Manual Mode
|
|
230
335
|
|
|
231
336
|
In manual mode, you can control the transition using `useTransitionContext`.
|
|
232
337
|
|
|
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
|
|
338
|
+
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
339
|
|
|
235
340
|
|
|
236
341
|
```ts
|
|
@@ -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
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import type { TransitionProperty } from "../types/transitionPropertys.types";
|
|
2
3
|
interface TransitionOptions {
|
|
3
|
-
transitionProperty
|
|
4
|
-
|
|
4
|
+
transitionProperty: TransitionProperty;
|
|
5
|
+
items?: [number, number];
|
|
5
6
|
}
|
|
6
7
|
interface ProviderProps {
|
|
7
8
|
header?: ReactNode;
|
|
8
|
-
options
|
|
9
|
+
options: TransitionOptions;
|
|
9
10
|
children: ReactNode;
|
|
10
11
|
}
|
|
11
12
|
export declare function CssTransitionProvider({ header, options, children }: ProviderProps): import("react").JSX.Element;
|
|
@@ -10,16 +10,17 @@ import { transitionEnd } from "../functions/transitionEnd";
|
|
|
10
10
|
import { useHandleLinkClick } from "../hooks/useHandleLinkClick";
|
|
11
11
|
import { useScrollRestoration } from "../hooks/useScrollRestoration";
|
|
12
12
|
import { usePopState } from "../hooks/usePopState";
|
|
13
|
-
import {
|
|
13
|
+
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
14
14
|
export function CssTransitionProvider({ header, options, children }) {
|
|
15
15
|
const defaultOptions = {
|
|
16
|
-
|
|
17
|
-
overlayCount: 0,
|
|
16
|
+
items: [0, 0],
|
|
18
17
|
...options
|
|
19
18
|
};
|
|
20
19
|
const container = useRef(null);
|
|
20
|
+
const pageWrapper = useRef(null);
|
|
21
21
|
const overlayWrapper = useRef(null);
|
|
22
22
|
const overlayItems = useRef([]);
|
|
23
|
+
const secondItems = useRef([]);
|
|
23
24
|
const pathname = usePathname();
|
|
24
25
|
const currentPathname = useRef(pathname);
|
|
25
26
|
const mount = useRef({
|
|
@@ -27,39 +28,26 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
27
28
|
initPathname: pathname
|
|
28
29
|
});
|
|
29
30
|
const state = useRef('idle');
|
|
31
|
+
const basePath = useRef(null);
|
|
30
32
|
const useUse = useRef(false);
|
|
31
33
|
const resolveUseFn = useRef(null);
|
|
32
|
-
const reverse = useRef({
|
|
33
|
-
_lock: true,
|
|
34
|
-
get lock() {
|
|
35
|
-
return this._lock;
|
|
36
|
-
},
|
|
37
|
-
set lock(value) {
|
|
38
|
-
if (delay.current === 0 || overlayItems.current.length < 2) {
|
|
39
|
-
if (this._lock === false)
|
|
40
|
-
this._lock = true;
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this._lock = value;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
const delay = useRef(null);
|
|
47
34
|
const handleLinkClick = useRef(() => { });
|
|
48
35
|
const transitionEndHandler = useTransitionEndHandler();
|
|
49
36
|
const transitionEndData = useTransitionEndData({
|
|
50
|
-
elArray: defaultOptions.
|
|
51
|
-
transitionProperty: defaultOptions.transitionProperty
|
|
37
|
+
elArray: defaultOptions.items[0] === 0 ? pageWrapper : overlayItems,
|
|
38
|
+
transitionProperty: defaultOptions.transitionProperty,
|
|
39
|
+
secondElArray: secondItems
|
|
52
40
|
});
|
|
41
|
+
const pollRafId = useRef(null);
|
|
53
42
|
usePopState({
|
|
54
43
|
container,
|
|
55
44
|
currentPathname,
|
|
56
45
|
transitionEndData,
|
|
57
46
|
transitionEndHandler,
|
|
58
47
|
state,
|
|
59
|
-
reverse,
|
|
60
|
-
delay,
|
|
61
48
|
useUse,
|
|
62
|
-
resolveUseFn
|
|
49
|
+
resolveUseFn,
|
|
50
|
+
pollRafId
|
|
63
51
|
});
|
|
64
52
|
useHandleLinkClick({
|
|
65
53
|
container,
|
|
@@ -68,10 +56,10 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
68
56
|
transitionEndData,
|
|
69
57
|
transitionEndHandler,
|
|
70
58
|
state,
|
|
71
|
-
reverse,
|
|
72
|
-
delay,
|
|
73
59
|
useUse,
|
|
74
|
-
resolveUseFn
|
|
60
|
+
resolveUseFn,
|
|
61
|
+
basePath,
|
|
62
|
+
pollRafId
|
|
75
63
|
});
|
|
76
64
|
useScrollRestoration();
|
|
77
65
|
const removeEnter = useTransitionEndObj({
|
|
@@ -79,34 +67,37 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
79
67
|
fn: () => {
|
|
80
68
|
container.current?.classList.remove('enter');
|
|
81
69
|
state.current = 'idle';
|
|
82
|
-
reverse.current.lock = true;
|
|
83
70
|
}
|
|
84
71
|
});
|
|
85
72
|
useEffect(() => {
|
|
86
73
|
if (mount.current.mounted === false &&
|
|
87
74
|
mount.current.initPathname === pathname) {
|
|
75
|
+
currentPathname.current = window.location.pathname;
|
|
76
|
+
basePath.current = window.location.pathname.slice(0, -pathname.length);
|
|
88
77
|
return;
|
|
89
78
|
}
|
|
90
79
|
mount.current.mounted = true;
|
|
91
|
-
if (delay.current === null) {
|
|
92
|
-
delay.current = parseDelay(transitionEndData.current.elArray);
|
|
93
|
-
}
|
|
94
80
|
if (!container.current)
|
|
95
81
|
return;
|
|
96
82
|
transitionEnd({
|
|
97
83
|
transitionEndObj: removeEnter,
|
|
98
|
-
transitionEndHandler
|
|
99
|
-
reverse,
|
|
100
|
-
delay
|
|
84
|
+
transitionEndHandler
|
|
101
85
|
});
|
|
102
86
|
container.current.classList.remove('exit');
|
|
103
87
|
container.current.classList.add('enter');
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
88
|
+
pollTransitionStart({
|
|
89
|
+
transitionEndData,
|
|
90
|
+
id: pollRafId,
|
|
91
|
+
fn: () => {
|
|
92
|
+
state.current = 'entering';
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
currentPathname.current = window.location.pathname;
|
|
107
96
|
}, [pathname]);
|
|
108
97
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
109
|
-
return (
|
|
98
|
+
return (_jsx(TransitionContext.Provider, { value: value, children: _jsxs("div", { ref: container, "data-transition": true, children: [header, _jsxs("div", { ref: overlayWrapper, className: "overlay-wrapper", children: [defaultOptions.items[0] > 0 && Array.from({ length: defaultOptions.items[0] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
110
99
|
overlayItems.current[i] = el;
|
|
111
|
-
}, className: "overlay-item" }, i)))
|
|
100
|
+
}, className: "overlay-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
101
|
+
secondItems.current[i] = el;
|
|
102
|
+
}, className: "second-item" }, `mirror${i}`)))] }), _jsx("div", { ref: pageWrapper, className: "page-wrapper", children: children })] }) }));
|
|
112
103
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode, RefObject } from "react";
|
|
2
|
+
import type { TransitionProperty } from "../types/transitionPropertys.types";
|
|
2
3
|
interface ContextProps {
|
|
3
4
|
handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
|
|
4
5
|
overlayWrapper?: RefObject<HTMLDivElement | null>;
|
|
@@ -9,16 +10,15 @@ interface ContextProps {
|
|
|
9
10
|
export declare const TransitionContext: import("react").Context<ContextProps | null>;
|
|
10
11
|
export declare function useTransitionContext(): ContextProps;
|
|
11
12
|
type Mode = 'css' | 'manual';
|
|
12
|
-
type TransitionProperty = 'opacity' | 'clip-path';
|
|
13
13
|
interface TransitionOptions {
|
|
14
|
-
transitionProperty
|
|
15
|
-
|
|
14
|
+
transitionProperty: TransitionProperty;
|
|
15
|
+
items?: [number, number];
|
|
16
16
|
}
|
|
17
17
|
interface ProviderProps {
|
|
18
18
|
header?: ReactNode;
|
|
19
19
|
mode?: Mode;
|
|
20
|
-
options
|
|
20
|
+
options: TransitionOptions;
|
|
21
21
|
children: ReactNode;
|
|
22
22
|
}
|
|
23
|
-
export declare function TransitionProvider({ header, mode, options, children
|
|
23
|
+
export declare function TransitionProvider({ header, mode, options, children }: ProviderProps): import("react").JSX.Element;
|
|
24
24
|
export {};
|
|
@@ -10,7 +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, children
|
|
13
|
+
export function TransitionProvider({ header, mode = 'css', options, children }) {
|
|
14
14
|
return (mode === 'css' ?
|
|
15
15
|
_jsx(CssTransitionProvider, { header: header, options: options, children: children }) :
|
|
16
16
|
_jsx(ManualTransitionProvider, { children: children }));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { transitionRunning } from "./transitionRunning";
|
|
2
|
+
export function checkTransitionStart(transitionEndData, fn) {
|
|
3
|
+
if (transitionRunning(transitionEndData.elArray, transitionEndData.transitionProperty)) {
|
|
4
|
+
fn?.();
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,21 +1,8 @@
|
|
|
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>;
|
|
14
|
-
reverse: RefObject<{
|
|
15
|
-
_lock: boolean;
|
|
16
|
-
lock: boolean;
|
|
17
|
-
}>;
|
|
18
|
-
delay: RefObject<number | null>;
|
|
19
6
|
}
|
|
20
|
-
export declare function transitionEnd({ transitionEndObj, transitionEndHandler
|
|
7
|
+
export declare function transitionEnd({ transitionEndObj, transitionEndHandler }: Props): void;
|
|
21
8
|
export {};
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delay }) {
|
|
1
|
+
export function transitionEnd({ transitionEndObj, transitionEndHandler }) {
|
|
3
2
|
const lastIndex = transitionEndObj.current.elArray.length - 1;
|
|
4
3
|
if (transitionEndHandler.current.handler &&
|
|
5
4
|
transitionEndHandler.current.handlerEl) {
|
|
6
5
|
transitionEndHandler.current.handlerEl.removeEventListener('transitionend', transitionEndHandler.current.handler);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
transtionEndReverse({
|
|
10
|
-
transitionEndObj,
|
|
11
|
-
transitionEndHandler,
|
|
12
|
-
reverse,
|
|
13
|
-
delay
|
|
14
|
-
});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
7
|
+
const endObj = transitionEndObj.current;
|
|
17
8
|
const handler = (e) => {
|
|
18
9
|
if (e.target !== e.currentTarget)
|
|
19
10
|
return;
|
|
20
|
-
if (
|
|
21
|
-
e.propertyName !==
|
|
11
|
+
if (endObj.transitionProperty &&
|
|
12
|
+
e.propertyName !== endObj.transitionProperty)
|
|
22
13
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
endObj.elArray[lastIndex]?.removeEventListener('transitionend', handler);
|
|
15
|
+
endObj.fn?.();
|
|
25
16
|
};
|
|
26
17
|
transitionEndHandler.current.handler = handler;
|
|
27
|
-
transitionEndHandler.current.handlerEl =
|
|
28
|
-
|
|
18
|
+
transitionEndHandler.current.handlerEl = endObj.elArray[lastIndex];
|
|
19
|
+
endObj.elArray[lastIndex]?.addEventListener('transitionend', transitionEndHandler.current.handler);
|
|
29
20
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function transitionRunning(elArray, transitionProperty) {
|
|
2
|
+
if (!elArray[0])
|
|
3
|
+
return null;
|
|
4
|
+
const property = {
|
|
5
|
+
opacity: 'opacity',
|
|
6
|
+
'clip-path': 'clipPath',
|
|
7
|
+
'transform': 'transform'
|
|
8
|
+
};
|
|
9
|
+
if (elArray[0].getAnimations().some((obj) => {
|
|
10
|
+
const progress = obj.effect?.getComputedTiming().progress;
|
|
11
|
+
return obj.playState === 'running' &&
|
|
12
|
+
obj.effect instanceof KeyframeEffect &&
|
|
13
|
+
obj.effect.getKeyframes().some(frame => {
|
|
14
|
+
return frame[property[transitionProperty]] !== undefined;
|
|
15
|
+
}) && progress != null && progress !== 0;
|
|
16
|
+
})) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
}
|
|
6
|
-
interface TransitionEndHandler {
|
|
7
|
-
handler: ((e: TransitionEvent) => void) | null;
|
|
8
|
-
handlerEl: HTMLDivElement | null;
|
|
9
|
-
}
|
|
2
|
+
import type { TransitionEndData, TransitionEndHandler } from "../types/transitionEnd.types";
|
|
10
3
|
interface Props {
|
|
11
4
|
container: RefObject<HTMLDivElement | null>;
|
|
12
5
|
handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
|
|
@@ -14,13 +7,10 @@ interface Props {
|
|
|
14
7
|
transitionEndData: RefObject<TransitionEndData>;
|
|
15
8
|
transitionEndHandler: RefObject<TransitionEndHandler>;
|
|
16
9
|
state: RefObject<'idle' | 'exiting' | 'entering' | 'navigating'>;
|
|
17
|
-
reverse: RefObject<{
|
|
18
|
-
_lock: boolean;
|
|
19
|
-
lock: boolean;
|
|
20
|
-
}>;
|
|
21
|
-
delay: RefObject<number | null>;
|
|
22
10
|
useUse: RefObject<boolean>;
|
|
23
11
|
resolveUseFn: RefObject<(() => void) | null>;
|
|
12
|
+
basePath: RefObject<string | null>;
|
|
13
|
+
pollRafId: RefObject<number | null>;
|
|
24
14
|
}
|
|
25
|
-
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler,
|
|
15
|
+
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, basePath, pollRafId }: Props): void;
|
|
26
16
|
export {};
|