page-transition 0.1.0-beta.9 → 0.1.0
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 +223 -55
- package/dist/components/{TransitionLink.js → css/TransitionLink.js} +2 -2
- package/dist/components/manual/TransitionLink.d.ts +10 -0
- package/dist/components/manual/TransitionLink.js +10 -0
- package/dist/context/CssContext.d.ts +12 -0
- package/dist/context/CssContext.js +9 -0
- package/dist/context/CssTransitionProvider.d.ts +8 -5
- package/dist/context/CssTransitionProvider.js +45 -44
- package/dist/context/ManualContext.d.ts +9 -0
- package/dist/context/ManualContext.js +9 -0
- package/dist/context/ManualTransitionProvider.d.ts +2 -1
- package/dist/context/ManualTransitionProvider.js +14 -3
- package/dist/context/TransitionProvider.d.ts +23 -0
- package/dist/context/TransitionProvider.js +10 -0
- package/dist/css.d.ts +2 -0
- package/dist/css.js +3 -0
- package/dist/functions/checkTransitionStart.d.ts +1 -5
- package/dist/functions/checkTransitionStart.js +5 -10
- package/dist/functions/pollTransitionStart.d.ts +1 -4
- package/dist/functions/pollTransitionStart.js +2 -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 +29 -0
- package/dist/hooks/manual/useHandleLinkClick.d.ts +3 -1
- package/dist/hooks/manual/useHandleLinkClick.js +6 -1
- package/dist/hooks/manual/usePopState.d.ts +2 -1
- package/dist/hooks/manual/usePopState.js +7 -2
- package/dist/hooks/useHandleLinkClick.d.ts +4 -14
- package/dist/hooks/useHandleLinkClick.js +56 -36
- package/dist/hooks/usePopState.d.ts +3 -14
- package/dist/hooks/usePopState.js +51 -36
- package/dist/hooks/useScrollRestoration.d.ts +5 -1
- package/dist/hooks/useScrollRestoration.js +4 -1
- package/dist/hooks/useTransitionEndData.d.ts +5 -6
- package/dist/hooks/useTransitionEndData.js +4 -4
- package/dist/hooks/useTransitionEndHandler.d.ts +1 -5
- package/dist/hooks/useTransitionEndObj.d.ts +1 -9
- package/dist/hooks/useTransitionEndObj.js +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/manual.d.ts +2 -0
- package/dist/manual.js +3 -0
- package/dist/types/transitionEnd.types.d.ts +15 -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 +15 -3
- package/dist/context/TransitionContext.d.ts +0 -24
- package/dist/context/TransitionContext.js +0 -17
- 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/dist/components/{TransitionLink.d.ts → css/TransitionLink.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
# page-transition
|
|
2
|
-
A page transition library for the Next.js App Router.
|
|
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
|
## Features
|
|
7
8
|
|
|
8
9
|
- CSS & Manual mode
|
|
9
10
|
- Scroll restoration
|
|
10
11
|
|
|
11
|
-
## Install
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
## Install
|
|
13
|
+
 
|
|
14
|
+
|
|
15
|
+
`npm install page-transition@beta`
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
16
18
|
Import your page transition styles and wrap your page content with `TransitionProvider` in your root layout.
|
|
17
19
|
|
|
18
20
|
```tsx
|
|
19
21
|
import { TransitionProvider } from "page-transition"
|
|
20
|
-
import '
|
|
22
|
+
import './transition-styles.css'
|
|
21
23
|
|
|
22
24
|
export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
23
25
|
return (
|
|
@@ -40,37 +42,53 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
40
42
|
|Prop|Type|Default|Mode|
|
|
41
43
|
|---|---|---|---|
|
|
42
44
|
| mode | "css" \| "manual" | "css" | Both |
|
|
43
|
-
|
|
|
45
|
+
| scroll | "auto" \| "top" | "auto" | Both |
|
|
46
|
+
| outside | JSX | - | CSS |
|
|
44
47
|
| options | *Options* | {} | CSS |
|
|
45
48
|
|
|
46
49
|
*Options*
|
|
47
50
|
|
|
48
|
-
| Option | Type | Default |
|
|
49
|
-
|
|
50
|
-
| transitionProperty | "opacity" \| "clip-path"
|
|
51
|
-
|
|
|
51
|
+
| Option | Type | Default | Required |
|
|
52
|
+
|---|---|---|---|
|
|
53
|
+
| transitionProperty | "opacity" \| "clip-path" \| "transform" | - | Yes |
|
|
54
|
+
| overlays | number | 0 | - |
|
|
55
|
+
| items | [number, number] | [0, 0] | - |
|
|
56
|
+
|
|
52
57
|
|
|
53
58
|
**Prop Descriptions**
|
|
54
59
|
|
|
55
60
|
**mode**
|
|
56
61
|
Select the transition mode.
|
|
57
62
|
|
|
58
|
-
**
|
|
59
|
-
|
|
63
|
+
**scroll**
|
|
64
|
+
Controls browser scroll restoration during back and forward navigation.
|
|
65
|
+
`'auto'` Restores the previous scroll position.
|
|
66
|
+
`'top'` Scrolls to the top.
|
|
67
|
+
|
|
68
|
+
**outside**
|
|
69
|
+
Components rendered outside .page-wrapper, but still inside the transition container.
|
|
60
70
|
|
|
61
71
|
**options.transitionProperty**
|
|
62
|
-
Defines which property transitionend waits for.
|
|
72
|
+
Defines which property transitionend waits for.
|
|
73
|
+
|
|
63
74
|
|
|
64
|
-
**options.
|
|
65
|
-
|
|
75
|
+
**options.overlays**
|
|
76
|
+
Number of overlay elements to add to the transition container.
|
|
77
|
+
Each element receives the `.overlay` class.
|
|
78
|
+
|
|
79
|
+
**options.items**
|
|
80
|
+
`options.items[0]`
|
|
81
|
+
Number of items in the first group. Each item receives the `.first-item` class.
|
|
82
|
+
`options.items[1]`
|
|
83
|
+
Number of items in the second group. Each item receives the `.second-item` class.
|
|
66
84
|
|
|
67
85
|
|
|
68
86
|
```tsx
|
|
69
87
|
<TransitionProvider
|
|
70
|
-
|
|
88
|
+
outside={<Header/>}
|
|
71
89
|
options={{
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
overlays: 2,
|
|
91
|
+
transitionProperty: "clip-path",
|
|
74
92
|
}}
|
|
75
93
|
>
|
|
76
94
|
{children}
|
|
@@ -85,15 +103,26 @@ options={{
|
|
|
85
103
|
| href | string | - | Yes |
|
|
86
104
|
| className | string | - | - |
|
|
87
105
|
| scroll | boolean | true | - |
|
|
88
|
-
| prefetch | "auto" \| null | null | - |
|
|
106
|
+
| prefetch | boolean \| "auto" \| null | null | - |
|
|
89
107
|
| onClick | (e: React.MouseEvent)=>void | - | - |
|
|
90
108
|
|
|
91
109
|
**Prop Descriptions**
|
|
92
110
|
TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
|
|
93
111
|
|
|
94
112
|
**Description**
|
|
95
|
-
Triggers the transition.
|
|
113
|
+
Triggers the transition.
|
|
114
|
+
|
|
115
|
+
*Must be used within the TransitionProvider*
|
|
96
116
|
|
|
117
|
+
css
|
|
118
|
+
```tsx
|
|
119
|
+
import {TransitionLink} from "page-transition/css"
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
manual
|
|
123
|
+
```tsx
|
|
124
|
+
import {TransitionLink} from "page-transition/manual"
|
|
125
|
+
```
|
|
97
126
|
|
|
98
127
|
```tsx
|
|
99
128
|
<TransitionLink href={"/home"}>
|
|
@@ -103,21 +132,49 @@ Triggers the transition.
|
|
|
103
132
|
|
|
104
133
|
### CSS Mode
|
|
105
134
|
|
|
106
|
-
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
|
|
135
|
+
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`.
|
|
136
|
+
|
|
137
|
+
By default, the event is tracked on `.page-wrapper`, which contains the page's children.
|
|
138
|
+
|
|
139
|
+
If `options.overlays` is greater than 0, the transition event is tracked on the last element of the overlay group.
|
|
140
|
+
|
|
141
|
+
If `options.items` specifies one or more items, the transition event is tracked on the last item of the first group.
|
|
107
142
|
|
|
108
|
-
|
|
143
|
+
The `.item-wrapper` is provided to group and position transition items. It is primarily intended for transitions that require multiple grouped elements. The number of items in each group can be configured using the options.items array.
|
|
144
|
+
|
|
145
|
+
Once the transition ends, the scroll position is restored and navigation is performed.
|
|
109
146
|
|
|
110
147
|
After navigation, the `exit` class is removed and the `enter` class is added. Once the next transitionend event fires, the enter class is removed.
|
|
111
148
|
|
|
112
|
-
|
|
149
|
+
```tsx
|
|
150
|
+
<div data-transition>
|
|
151
|
+
<div className="overlay"/>
|
|
113
152
|
|
|
114
|
-
|
|
153
|
+
<div className="item-wrapper">
|
|
154
|
+
<div className="first-item"/>
|
|
155
|
+
<div className="second-item"/>
|
|
156
|
+
</div>
|
|
115
157
|
|
|
116
|
-
|
|
117
|
-
|
|
158
|
+
{outside}
|
|
159
|
+
|
|
160
|
+
<div className={"page-wrapper"}>
|
|
161
|
+
{children}
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
```
|
|
118
165
|
|
|
119
|
-
const {overlayWrapper, overlayItems} = useTransitionContext()
|
|
120
166
|
|
|
167
|
+
To access the page wrapper, overlays, item wrapper, and their respective items, use `useTransitionContext`.
|
|
168
|
+
```ts
|
|
169
|
+
import { useTransitionContext } from "page-transition/css"
|
|
170
|
+
|
|
171
|
+
const {
|
|
172
|
+
pageWrapper,
|
|
173
|
+
overlays,
|
|
174
|
+
itemWrapper,
|
|
175
|
+
firstItems,
|
|
176
|
+
secondItems
|
|
177
|
+
} = useTransitionContext()
|
|
121
178
|
```
|
|
122
179
|
|
|
123
180
|
#### CSS/SCSS Examples
|
|
@@ -128,55 +185,80 @@ options
|
|
|
128
185
|
|
|
129
186
|
```ts
|
|
130
187
|
transitionProperty: "opacity"
|
|
131
|
-
|
|
188
|
+
overlays: 1
|
|
189
|
+
|
|
132
190
|
```
|
|
133
191
|
|
|
134
192
|
```css
|
|
135
|
-
[data-transition]{
|
|
193
|
+
[data-transition] .overlay{
|
|
194
|
+
position: fixed;
|
|
195
|
+
z-index: 98;
|
|
196
|
+
inset: 0;
|
|
197
|
+
background: white;
|
|
198
|
+
|
|
199
|
+
opacity: 0;
|
|
200
|
+
pointer-events: none;
|
|
136
201
|
will-change: opacity;
|
|
137
|
-
opacity: 1;
|
|
138
202
|
}
|
|
139
|
-
[data-transition].exit{
|
|
140
|
-
opacity:
|
|
203
|
+
[data-transition].exit .overlay{
|
|
204
|
+
opacity: 1;
|
|
141
205
|
transition: opacity 0.4s ease;
|
|
142
206
|
|
|
143
207
|
}
|
|
144
|
-
[data-transition].enter{
|
|
145
|
-
opacity:
|
|
208
|
+
[data-transition].enter .overlay{
|
|
209
|
+
opacity: 0;
|
|
146
210
|
transition: opacity 0.5s ease;
|
|
147
211
|
}
|
|
148
212
|
```
|
|
149
213
|
</details>
|
|
150
214
|
|
|
151
215
|
<details>
|
|
152
|
-
<summary>
|
|
216
|
+
<summary>Combined Opacity and Clip-Path</summary>
|
|
153
217
|
<br/>
|
|
154
218
|
options
|
|
155
219
|
|
|
156
220
|
```ts
|
|
157
221
|
transitionProperty: "clip-path"
|
|
158
|
-
|
|
222
|
+
overlays: 2
|
|
223
|
+
|
|
159
224
|
```
|
|
160
225
|
|
|
161
226
|
```css
|
|
162
|
-
[data-transition] .overlay-
|
|
227
|
+
[data-transition] .overlay:nth-child(1){
|
|
163
228
|
position: fixed;
|
|
229
|
+
z-index: 98;
|
|
164
230
|
inset: 0;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
231
|
+
background: white;
|
|
232
|
+
|
|
233
|
+
opacity: 0;
|
|
234
|
+
pointer-events: none;
|
|
235
|
+
will-change: opacity;
|
|
168
236
|
}
|
|
169
|
-
[data-transition] .overlay-
|
|
237
|
+
[data-transition].exit .overlay:nth-child(1){
|
|
238
|
+
opacity: 1;
|
|
239
|
+
transition: opacity 0.4s ease;
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
[data-transition].enter .overlay:nth-child(1){
|
|
243
|
+
opacity: 0;
|
|
244
|
+
transition: opacity 0.5s ease;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
[data-transition] .overlay:nth-child(2){
|
|
248
|
+
position: fixed;
|
|
249
|
+
z-index: 99;
|
|
250
|
+
inset: 0;
|
|
251
|
+
|
|
170
252
|
background: black;
|
|
171
253
|
transition: none;
|
|
172
254
|
will-change: clip-path;
|
|
173
255
|
clip-path: inset(100% 0 0 0);
|
|
174
256
|
}
|
|
175
|
-
[data-transition].exit .overlay-
|
|
257
|
+
[data-transition].exit .overlay:nth-child(2){
|
|
176
258
|
clip-path: inset(0 0 0 0);
|
|
177
259
|
transition: clip-path 1.2s ease;
|
|
178
260
|
}
|
|
179
|
-
[data-transition].enter .overlay-
|
|
261
|
+
[data-transition].enter .overlay:nth-child(2){
|
|
180
262
|
clip-path: inset(0 0 100% 0);
|
|
181
263
|
transition: clip-path 1.2s ease;
|
|
182
264
|
}
|
|
@@ -190,24 +272,24 @@ options
|
|
|
190
272
|
|
|
191
273
|
```ts
|
|
192
274
|
transitionProperty: "clip-path"
|
|
193
|
-
|
|
275
|
+
items: [10, 0]
|
|
194
276
|
```
|
|
195
277
|
|
|
196
278
|
```scss
|
|
197
|
-
[data-transition] .
|
|
279
|
+
[data-transition] .item-wrapper{
|
|
198
280
|
position: fixed;
|
|
199
281
|
inset: 0;
|
|
200
282
|
|
|
201
283
|
display: grid;
|
|
202
284
|
grid-template-columns: repeat(10, 1fr);
|
|
203
285
|
}
|
|
204
|
-
[data-transition] .
|
|
286
|
+
[data-transition] .first-item{
|
|
205
287
|
background: black;
|
|
206
288
|
transition: none;
|
|
207
289
|
will-change: clip-path;
|
|
208
290
|
clip-path: inset(100% -1px 0 -1px);
|
|
209
291
|
}
|
|
210
|
-
[data-transition].exit .
|
|
292
|
+
[data-transition].exit .first-item{
|
|
211
293
|
clip-path: inset(0 -1px 0 -1px);
|
|
212
294
|
transition: clip-path 1.0s ease;
|
|
213
295
|
@for $i from 0 to 10{
|
|
@@ -216,7 +298,7 @@ overlayCount: 10
|
|
|
216
298
|
}
|
|
217
299
|
}
|
|
218
300
|
}
|
|
219
|
-
[data-transition].enter .
|
|
301
|
+
[data-transition].enter .first-item{
|
|
220
302
|
clip-path: inset(0 -1px 100% -1px);
|
|
221
303
|
transition: clip-path 1.0s ease;
|
|
222
304
|
@for $i from 0 to 10{
|
|
@@ -228,15 +310,101 @@ overlayCount: 10
|
|
|
228
310
|
```
|
|
229
311
|
</details>
|
|
230
312
|
|
|
231
|
-
|
|
313
|
+
<details>
|
|
314
|
+
<summary>Mirrored Staggered Overlays</summary>
|
|
315
|
+
<br/>
|
|
316
|
+
options
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
transitionProperty: "clip-path"
|
|
320
|
+
items: [10, 10]
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
```scss
|
|
324
|
+
[data-transition] .item-wrapper{
|
|
325
|
+
position: fixed;
|
|
326
|
+
inset: 0;
|
|
327
|
+
|
|
328
|
+
display: grid;
|
|
329
|
+
grid-template-columns: repeat(10, 1fr);
|
|
330
|
+
grid-template-rows: repeat(2, 1fr);
|
|
331
|
+
}
|
|
332
|
+
[data-transition] .first-item{
|
|
333
|
+
grid-row: 1;
|
|
334
|
+
background: black;
|
|
335
|
+
|
|
336
|
+
transition: none;
|
|
337
|
+
will-change: clip-path;
|
|
338
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
339
|
+
}
|
|
340
|
+
[data-transition].exit .first-item{
|
|
341
|
+
grid-row: 1;
|
|
342
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
343
|
+
transition: clip-path 1.2s ease;
|
|
344
|
+
@for $i from 0 to 10{
|
|
345
|
+
&:nth-child(#{$i+1}){
|
|
346
|
+
transition-delay: $i * 0.3s;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
[data-transition].enter .first-item{
|
|
351
|
+
grid-row: 1;
|
|
352
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
353
|
+
transition: clip-path 1.2s ease;
|
|
354
|
+
@for $i from 0 to 10{
|
|
355
|
+
&:nth-child(#{$i+1}){
|
|
356
|
+
transition-delay: $i * 0.3s;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// .second-item
|
|
361
|
+
[data-transition] .second-item{
|
|
362
|
+
grid-row: 2;
|
|
363
|
+
background: black;
|
|
364
|
+
|
|
365
|
+
transition: none;
|
|
366
|
+
will-change: clip-path;
|
|
367
|
+
clip-path: inset(100% 0 0 0);
|
|
368
|
+
}
|
|
369
|
+
[data-transition].exit .second-item{
|
|
370
|
+
grid-row: 2;
|
|
371
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
372
|
+
transition: clip-path 1.2s ease;
|
|
373
|
+
@for $i from 0 to 10{
|
|
374
|
+
&:nth-child(#{$i+11}){
|
|
375
|
+
transition-delay: $i * 0.3s;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
[data-transition].enter .second-item{
|
|
380
|
+
grid-row: 2;
|
|
381
|
+
clip-path: inset(100% -1px 0 -1px);
|
|
382
|
+
transition: clip-path 1.2s ease;
|
|
383
|
+
@for $i from 0 to 10{
|
|
384
|
+
&:nth-child(#{$i+11}){
|
|
385
|
+
transition-delay: $i * 0.3s;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
</details>
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
### Manual Mode
|
|
232
395
|
|
|
233
396
|
In manual mode, you can control the transition using `useTransitionContext`.
|
|
234
397
|
|
|
235
|
-
|
|
398
|
+
|
|
399
|
+
After triggering the navigation, `state.current` is set to `exiting`. You can then call `resolveFn.current()` to proceed with the navigation.
|
|
400
|
+
|
|
401
|
+
Before navigating, you should call `window.scrollTo(0, window.history.state.scrollY ?? 0)` to restore the previous scroll position.
|
|
402
|
+
|
|
403
|
+
Once `state.current` is set to `entering`, the navigation has occurred. After the animation finishes, `state.current` should be set to `idle`.
|
|
236
404
|
|
|
237
405
|
|
|
238
406
|
```ts
|
|
239
|
-
import { useTransitionContext } from "page-transition"
|
|
407
|
+
import { useTransitionContext } from "page-transition/manual"
|
|
240
408
|
|
|
241
409
|
const { resolveFn, state } = useTransitionContext()
|
|
242
410
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import Link from "next/link";
|
|
3
|
-
import { useTransitionContext } from "
|
|
3
|
+
import { useTransitionContext } from "../../context/CssContext";
|
|
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
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
href: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
prefetch?: boolean;
|
|
6
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function TransitionLink({ href, className, prefetch, onClick, children }: Props): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
import { useTransitionContext } from "../../context/ManualContext";
|
|
4
|
+
export function TransitionLink({ href, className, prefetch, onClick, children }) {
|
|
5
|
+
const { handleLinkClick } = useTransitionContext();
|
|
6
|
+
return (_jsx(Link, { href: href, onClick: (e) => {
|
|
7
|
+
onClick?.(e);
|
|
8
|
+
handleLinkClick.current(e, href);
|
|
9
|
+
}, className: className, prefetch: prefetch, children: children }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
interface ContextProps {
|
|
3
|
+
handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
|
|
4
|
+
pageWrapper?: RefObject<HTMLDivElement | null>;
|
|
5
|
+
overlays?: RefObject<(HTMLDivElement | null)[]>;
|
|
6
|
+
itemWrapper?: RefObject<HTMLDivElement | null>;
|
|
7
|
+
firstItems?: RefObject<(HTMLDivElement | null)[]>;
|
|
8
|
+
secondItems?: RefObject<(HTMLDivElement | null)[]>;
|
|
9
|
+
}
|
|
10
|
+
export declare const CssContext: import("react").Context<ContextProps | null>;
|
|
11
|
+
export declare function useTransitionContext(): ContextProps;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const CssContext = createContext(null);
|
|
4
|
+
export function useTransitionContext() {
|
|
5
|
+
const context = useContext(CssContext);
|
|
6
|
+
if (!context)
|
|
7
|
+
throw new Error('useCssContext in Provider!');
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
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
|
+
overlays?: number;
|
|
6
|
+
items?: [number, number];
|
|
5
7
|
}
|
|
6
8
|
interface ProviderProps {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
outside?: ReactNode;
|
|
10
|
+
scroll: 'auto' | 'top';
|
|
11
|
+
options: TransitionOptions;
|
|
9
12
|
children: ReactNode;
|
|
10
13
|
}
|
|
11
|
-
export declare function CssTransitionProvider({
|
|
14
|
+
export declare function CssTransitionProvider({ outside, scroll, options, children }: ProviderProps): import("react").JSX.Element;
|
|
12
15
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { CssContext } from "./CssContext";
|
|
4
4
|
import { useRef, useMemo, useEffect } from "react";
|
|
5
5
|
import { usePathname } from "next/navigation";
|
|
6
6
|
import { useTransitionEndHandler } from "../hooks/useTransitionEndHandler";
|
|
@@ -10,17 +10,20 @@ 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 { parseDelay } from "../functions/parseDelay";
|
|
14
13
|
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
15
|
-
export function CssTransitionProvider({
|
|
14
|
+
export function CssTransitionProvider({ outside, scroll, options, children }) {
|
|
16
15
|
const defaultOptions = {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
overlays: 0,
|
|
17
|
+
items: [0, 0],
|
|
19
18
|
...options
|
|
20
19
|
};
|
|
21
20
|
const container = useRef(null);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const pageWrapper = useRef(null);
|
|
22
|
+
const overlays = useRef([]);
|
|
23
|
+
const itemWrapper = useRef(null);
|
|
24
|
+
const firstItems = useRef([]);
|
|
25
|
+
const secondItems = useRef([]);
|
|
26
|
+
const group = useRef(null);
|
|
24
27
|
const pathname = usePathname();
|
|
25
28
|
const currentPathname = useRef(pathname);
|
|
26
29
|
const mount = useRef({
|
|
@@ -28,28 +31,21 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
28
31
|
initPathname: pathname
|
|
29
32
|
});
|
|
30
33
|
const state = useRef('idle');
|
|
34
|
+
const basePath = useRef(null);
|
|
31
35
|
const useUse = useRef(false);
|
|
32
36
|
const resolveUseFn = useRef(null);
|
|
33
|
-
const reverse = useRef({
|
|
34
|
-
_lock: true,
|
|
35
|
-
get lock() {
|
|
36
|
-
return this._lock;
|
|
37
|
-
},
|
|
38
|
-
set lock(value) {
|
|
39
|
-
if (delay.current === 0 || overlayItems.current.length < 2) {
|
|
40
|
-
if (this._lock === false)
|
|
41
|
-
this._lock = true;
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
this._lock = value;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const delay = useRef(null);
|
|
48
37
|
const handleLinkClick = useRef(() => { });
|
|
49
38
|
const transitionEndHandler = useTransitionEndHandler();
|
|
39
|
+
const elArray = defaultOptions.items[0] === 0 &&
|
|
40
|
+
defaultOptions.overlays === 0 ?
|
|
41
|
+
pageWrapper : defaultOptions.items[0] > 0 ? firstItems :
|
|
42
|
+
defaultOptions.overlays > 0 ? overlays : pageWrapper;
|
|
43
|
+
group.current = defaultOptions.overlays > 0 && defaultOptions.items[0] === 0 ?
|
|
44
|
+
'overlay' : null;
|
|
50
45
|
const transitionEndData = useTransitionEndData({
|
|
51
|
-
elArray
|
|
52
|
-
transitionProperty: defaultOptions.transitionProperty
|
|
46
|
+
elArray,
|
|
47
|
+
transitionProperty: defaultOptions.transitionProperty,
|
|
48
|
+
group: group
|
|
53
49
|
});
|
|
54
50
|
const pollRafId = useRef(null);
|
|
55
51
|
usePopState({
|
|
@@ -58,10 +54,9 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
58
54
|
transitionEndData,
|
|
59
55
|
transitionEndHandler,
|
|
60
56
|
state,
|
|
61
|
-
reverse,
|
|
62
|
-
delay,
|
|
63
57
|
useUse,
|
|
64
|
-
resolveUseFn
|
|
58
|
+
resolveUseFn,
|
|
59
|
+
pollRafId
|
|
65
60
|
});
|
|
66
61
|
useHandleLinkClick({
|
|
67
62
|
container,
|
|
@@ -70,36 +65,32 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
70
65
|
transitionEndData,
|
|
71
66
|
transitionEndHandler,
|
|
72
67
|
state,
|
|
73
|
-
reverse,
|
|
74
|
-
delay,
|
|
75
68
|
useUse,
|
|
76
|
-
resolveUseFn
|
|
69
|
+
resolveUseFn,
|
|
70
|
+
basePath,
|
|
71
|
+
pollRafId
|
|
77
72
|
});
|
|
78
|
-
useScrollRestoration();
|
|
73
|
+
useScrollRestoration({ scroll });
|
|
79
74
|
const removeEnter = useTransitionEndObj({
|
|
80
75
|
transitionEndData,
|
|
81
76
|
fn: () => {
|
|
82
77
|
container.current?.classList.remove('enter');
|
|
83
78
|
state.current = 'idle';
|
|
84
|
-
reverse.current.lock = true;
|
|
85
79
|
}
|
|
86
80
|
});
|
|
87
81
|
useEffect(() => {
|
|
88
82
|
if (mount.current.mounted === false &&
|
|
89
83
|
mount.current.initPathname === pathname) {
|
|
84
|
+
currentPathname.current = window.location.pathname;
|
|
85
|
+
basePath.current = window.location.pathname.slice(0, -pathname.length);
|
|
90
86
|
return;
|
|
91
87
|
}
|
|
92
88
|
mount.current.mounted = true;
|
|
93
|
-
if (delay.current === null) {
|
|
94
|
-
delay.current = parseDelay(transitionEndData.current.elArray);
|
|
95
|
-
}
|
|
96
89
|
if (!container.current)
|
|
97
90
|
return;
|
|
98
91
|
transitionEnd({
|
|
99
92
|
transitionEndObj: removeEnter,
|
|
100
|
-
transitionEndHandler
|
|
101
|
-
reverse,
|
|
102
|
-
delay
|
|
93
|
+
transitionEndHandler
|
|
103
94
|
});
|
|
104
95
|
container.current.classList.remove('exit');
|
|
105
96
|
container.current.classList.add('enter');
|
|
@@ -110,11 +101,21 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
110
101
|
state.current = 'entering';
|
|
111
102
|
}
|
|
112
103
|
});
|
|
113
|
-
currentPathname.current = pathname;
|
|
114
|
-
reverse.current.lock = false;
|
|
104
|
+
currentPathname.current = window.location.pathname;
|
|
115
105
|
}, [pathname]);
|
|
116
|
-
const value = useMemo(() => ({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
const value = useMemo(() => ({
|
|
107
|
+
handleLinkClick,
|
|
108
|
+
pageWrapper,
|
|
109
|
+
overlays,
|
|
110
|
+
itemWrapper,
|
|
111
|
+
firstItems,
|
|
112
|
+
secondItems
|
|
113
|
+
}), []);
|
|
114
|
+
return (_jsx(CssContext.Provider, { value: value, children: _jsxs("div", { ref: container, "data-transition": true, children: [defaultOptions.overlays > 0 &&
|
|
115
|
+
Array.from({ length: defaultOptions.overlays }).map((_, i) => (_jsx("div", { ref: (el) => { overlays.current[i] = el; }, className: "overlay" }, `overlay-${i}`))), (defaultOptions.items[0] > 0 || defaultOptions.items[1] > 0) &&
|
|
116
|
+
_jsxs("div", { ref: itemWrapper, className: "item-wrapper", children: [defaultOptions.items[0] > 0 && Array.from({ length: defaultOptions.items[0] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
117
|
+
firstItems.current[i] = el;
|
|
118
|
+
}, className: "first-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
119
|
+
secondItems.current[i] = el;
|
|
120
|
+
}, className: "second-item" }, `mirror${i}`)))] }), outside, _jsx("div", { ref: pageWrapper, className: "page-wrapper", children: children })] }) }));
|
|
120
121
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
interface ContextProps {
|
|
3
|
+
handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
|
|
4
|
+
resolveFn?: RefObject<(() => void) | null>;
|
|
5
|
+
state?: RefObject<'idle' | 'exiting' | 'entering'>;
|
|
6
|
+
}
|
|
7
|
+
export declare const ManualContext: import("react").Context<ContextProps | null>;
|
|
8
|
+
export declare function useTransitionContext(): ContextProps;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const ManualContext = createContext(null);
|
|
4
|
+
export function useTransitionContext() {
|
|
5
|
+
const context = useContext(ManualContext);
|
|
6
|
+
if (!context)
|
|
7
|
+
throw new Error('useManualContext in Provider!');
|
|
8
|
+
return context;
|
|
9
|
+
}
|