page-transition 0.1.0-beta.35 → 0.1.0-beta.37

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 CHANGED
@@ -10,7 +10,7 @@ A page transition library for the Next.js App Router.
10
10
  - Scroll restoration
11
11
 
12
12
  ## Install
13
- ![Version](https://img.shields.io/badge/v_0.1.0--beta.22-000000) ![68.7 KB](https://img.shields.io/badge/68.7_KB-1677FF)
13
+ ![Version](https://img.shields.io/badge/v_0.1.0--beta.35-000000) ![78.5 KB](https://img.shields.io/badge/78.5_KB-1677FF)
14
14
 
15
15
  `npm install page-transition@beta`
16
16
 
@@ -117,7 +117,9 @@ After navigation, the `exit` class is removed and the `enter` class is added. On
117
117
 
118
118
  For overlay animations, a `.overlay-wrapper` is available. You can add overlay items by setting the `overlayCount` option.
119
119
 
120
- If mirror is set to true, the same number of div elements specified by overlayCount are added to the `.overlaywrapper` with the class `mirror-item`. The transitionend dont wait for mirror items. This ideal for mirror effects.
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.*
121
123
 
122
124
  To access the overlay wrapper and its items, use `useTransitionContext`.
123
125
 
@@ -262,11 +264,11 @@ mirror: true
262
264
 
263
265
  transition: none;
264
266
  will-change: clip-path;
265
- clip-path: inset(0 0 100% 0);
267
+ clip-path: inset(0 -1px 100% -1px);
266
268
  }
267
269
  [data-transition].exit .overlay-item{
268
270
  grid-row: 1;
269
- clip-path: inset(0% 0 0 0);
271
+ clip-path: inset(0 -1px 0 -1px);
270
272
  transition: clip-path 1.2s ease;
271
273
  @for $i from 0 to 10{
272
274
  &:nth-child(#{$i+1}){
@@ -276,7 +278,7 @@ mirror: true
276
278
  }
277
279
  [data-transition].enter .overlay-item{
278
280
  grid-row: 1;
279
- clip-path: inset(0 0 100% 0);
281
+ clip-path: inset(0 -1px 100% -1px);
280
282
  transition: clip-path 1.2s ease;
281
283
  @for $i from 0 to 10{
282
284
  &:nth-child(#{$i+1}){
@@ -295,7 +297,7 @@ mirror: true
295
297
  }
296
298
  [data-transition].exit .mirror-item{
297
299
  grid-row: 2;
298
- clip-path: inset(0 0 0 0);
300
+ clip-path: inset(0 -1px 0 -1px);
299
301
  transition: clip-path 1.2s ease;
300
302
  @for $i from 0 to 10{
301
303
  &:nth-child(#{$i+11}){
@@ -305,7 +307,7 @@ mirror: true
305
307
  }
306
308
  [data-transition].enter .mirror-item{
307
309
  grid-row: 2;
308
- clip-path: inset(100% 0 0 0);
310
+ clip-path: inset(100% -1px 0 -1px);
309
311
  transition: clip-path 1.2s ease;
310
312
  @for $i from 0 to 10{
311
313
  &:nth-child(#{$i+11}){
@@ -72,7 +72,9 @@ export function CssTransitionProvider({ header, options, children }) {
72
72
  resolveUseFn,
73
73
  pollRafId,
74
74
  rafId,
75
- rejectFn
75
+ rejectFn,
76
+ delayStep,
77
+ duration
76
78
  });
77
79
  useHandleLinkClick({
78
80
  container,
@@ -87,7 +89,9 @@ export function CssTransitionProvider({ header, options, children }) {
87
89
  basePath,
88
90
  pollRafId,
89
91
  rafId,
90
- rejectFn
92
+ rejectFn,
93
+ delayStep,
94
+ duration
91
95
  });
92
96
  useScrollRestoration();
93
97
  const removeEnter = useTransitionEndObj({
@@ -108,18 +112,17 @@ export function CssTransitionProvider({ header, options, children }) {
108
112
  mount.current.mounted = true;
109
113
  if (delayStep.current === null && defaultOptions.overlayCount > 1) {
110
114
  delayStep.current = parseDelay(transitionEndData.current.elArray);
111
- transitionEndData.current.delayStep = delayStep.current ?? 0;
112
115
  }
113
116
  if (duration.current === null) {
114
117
  duration.current = parseDuration(transitionEndData.current.elArray[0]);
115
- transitionEndData.current.duration = duration.current ?? 0;
116
118
  }
117
119
  if (!container.current)
118
120
  return;
119
121
  transitionEnd({
120
122
  transitionEndObj: removeEnter,
121
123
  transitionEndHandler,
122
- reverse
124
+ reverse,
125
+ delayStep
123
126
  });
124
127
  container.current.classList.remove('exit');
125
128
  container.current.classList.add('enter');
@@ -4,8 +4,6 @@ interface TransitionEndObj {
4
4
  transitionProperty: 'opacity' | 'clip-path';
5
5
  mirror: boolean;
6
6
  mirrorElArray: (HTMLDivElement | null)[];
7
- delayStep: number;
8
- duration: number;
9
7
  fn: (() => void) | null;
10
8
  }
11
9
  interface TransitionEndHandler {
@@ -19,6 +17,7 @@ interface Props {
19
17
  _lock: boolean;
20
18
  lock: boolean;
21
19
  }>;
20
+ delayStep: RefObject<number | null>;
22
21
  }
23
- export declare function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, }: Props): void;
22
+ export declare function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
24
23
  export {};
@@ -1,5 +1,5 @@
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) {
@@ -10,7 +10,8 @@ export function transitionEnd({ transitionEndObj, transitionEndHandler, reverse,
10
10
  transtionEndReverse({
11
11
  transitionEndObj,
12
12
  transitionEndHandler,
13
- reverse
13
+ reverse,
14
+ delayStep
14
15
  });
15
16
  return;
16
17
  }
@@ -4,8 +4,6 @@ interface TransitionEndObj {
4
4
  transitionProperty: 'opacity' | 'clip-path';
5
5
  mirror: boolean;
6
6
  mirrorElArray: (HTMLDivElement | null)[];
7
- delayStep: number;
8
- duration: number;
9
7
  fn: (() => void) | null;
10
8
  }
11
9
  interface TransitionEndHandler {
@@ -19,6 +17,7 @@ interface Props {
19
17
  _lock: boolean;
20
18
  lock: boolean;
21
19
  }>;
20
+ delayStep: RefObject<number | null>;
22
21
  }
23
- export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse }: Props): void;
22
+ export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
24
23
  export {};
@@ -1,6 +1,6 @@
1
1
  import { setDelayReverse } from "./setDelayReverse";
2
2
  import { resetDelay } from "./resetDelay";
3
- export function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse }) {
3
+ export function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse, delayStep }) {
4
4
  if (transitionEndHandler.current.handler &&
5
5
  transitionEndHandler.current.handlerEl)
6
6
  transitionEndHandler.current.handlerEl.removeEventListener('transitionend', transitionEndHandler.current.handler);
@@ -8,13 +8,13 @@ export function transtionEndReverse({ transitionEndObj, transitionEndHandler, re
8
8
  setDelayReverse({
9
9
  elArray: endObj.elArray,
10
10
  transitionProperty: endObj.transitionProperty,
11
- delayStep: endObj.delayStep
11
+ delayStep: delayStep.current
12
12
  });
13
13
  if (endObj.mirror) {
14
14
  setDelayReverse({
15
15
  elArray: endObj.mirrorElArray,
16
16
  transitionProperty: endObj.transitionProperty,
17
- delayStep: endObj.delayStep
17
+ delayStep: delayStep.current
18
18
  });
19
19
  }
20
20
  const firstEl = endObj.elArray[0];
@@ -4,8 +4,6 @@ interface TransitionEndData {
4
4
  transitionProperty: 'opacity' | 'clip-path';
5
5
  mirror: boolean;
6
6
  mirrorElArray: (HTMLDivElement | null)[];
7
- delayStep: number;
8
- duration: number;
9
7
  }
10
8
  interface TransitionEndHandler {
11
9
  handler: ((e: TransitionEvent) => void) | null;
@@ -28,6 +26,8 @@ interface Props {
28
26
  pollRafId: RefObject<number | null>;
29
27
  rafId: RefObject<number | null>;
30
28
  rejectFn: RefObject<(() => void) | null>;
29
+ delayStep: RefObject<number | null>;
30
+ duration: RefObject<number | null>;
31
31
  }
32
- export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn }: Props): void;
32
+ export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration }: Props): void;
33
33
  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 }) {
9
+ export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration }) {
10
10
  const router = useRouter();
11
11
  const afterExitFn = useRef(null);
12
12
  const nextPage = useRef(null);
@@ -36,7 +36,8 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
36
36
  transitionEnd({
37
37
  transitionEndObj: removeEnter,
38
38
  transitionEndHandler,
39
- reverse
39
+ reverse,
40
+ delayStep
40
41
  });
41
42
  if (useUse.current) {
42
43
  resolveUseFn.current?.();
@@ -59,23 +60,19 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
59
60
  const afterEntering = useTransitionEndObj({
60
61
  transitionEndData,
61
62
  fn: () => {
62
- console.log('afterEntering transitionEnd');
63
63
  if (rafId.current) {
64
64
  cancelAnimationFrame(rafId.current);
65
65
  rafId.current = null;
66
66
  }
67
67
  rejectFn.current?.();
68
68
  container.current?.classList.remove('enter');
69
- requestAnimationFrame(() => {
70
- requestAnimationFrame(() => {
71
- container.current?.classList.add('exit');
72
- });
73
- });
69
+ container.current?.classList.add('exit');
74
70
  state.current = 'exiting';
75
71
  transitionEnd({
76
72
  transitionEndObj: push,
77
73
  transitionEndHandler,
78
- reverse
74
+ reverse,
75
+ delayStep
79
76
  });
80
77
  }
81
78
  });
@@ -107,7 +104,8 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
107
104
  transitionEnd({
108
105
  transitionEndObj: afterExit,
109
106
  transitionEndHandler,
110
- reverse
107
+ reverse,
108
+ delayStep
111
109
  });
112
110
  return;
113
111
  }
@@ -115,7 +113,8 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
115
113
  transitionEnd({
116
114
  transitionEndObj: afterEntering,
117
115
  transitionEndHandler,
118
- reverse
116
+ reverse,
117
+ delayStep
119
118
  });
120
119
  let elArray = [];
121
120
  if (transitionEndData.current.mirror) {
@@ -130,13 +129,24 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
130
129
  elArray,
131
130
  transitionProperty: transitionEndData.current.transitionProperty,
132
131
  target: 0,
133
- duration: transitionEndData.current.duration
132
+ duration: duration.current ?? 0
134
133
  }).then(() => {
135
- transitionEnd({
136
- transitionEndObj: push,
137
- transitionEndHandler,
138
- reverse
139
- });
134
+ if (basePathUrl === currentPathname.current) {
135
+ transitionEnd({
136
+ transitionEndObj: afterExit,
137
+ transitionEndHandler,
138
+ reverse,
139
+ delayStep
140
+ });
141
+ }
142
+ else {
143
+ transitionEnd({
144
+ transitionEndObj: push,
145
+ transitionEndHandler,
146
+ reverse,
147
+ delayStep
148
+ });
149
+ }
140
150
  container.current?.classList.remove('enter');
141
151
  container.current?.classList.add('exit');
142
152
  state.current = 'exiting';
@@ -151,7 +161,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
151
161
  elArray,
152
162
  transitionProperty: transitionEndData.current.transitionProperty,
153
163
  target: 1,
154
- duration: transitionEndData.current.duration
164
+ duration: duration.current ?? 0
155
165
  }).catch(() => { });
156
166
  }).catch(() => { });
157
167
  return;
@@ -159,7 +169,8 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
159
169
  transitionEnd({
160
170
  transitionEndObj: push,
161
171
  transitionEndHandler,
162
- reverse
172
+ reverse,
173
+ delayStep
163
174
  });
164
175
  container.current?.classList.remove('enter');
165
176
  container.current?.classList.add('exit');
@@ -4,8 +4,6 @@ interface TransitionEndData {
4
4
  transitionProperty: 'opacity' | 'clip-path';
5
5
  mirror: boolean;
6
6
  mirrorElArray: (HTMLDivElement | null)[];
7
- delayStep: number;
8
- duration: number;
9
7
  }
10
8
  interface TransitionEndHandler {
11
9
  handler: ((e: TransitionEvent) => void) | null;
@@ -26,6 +24,8 @@ interface Props {
26
24
  pollRafId: RefObject<number | null>;
27
25
  rafId: RefObject<number | null>;
28
26
  rejectFn: RefObject<(() => void) | null>;
27
+ delayStep: RefObject<number | null>;
28
+ duration: RefObject<number | null>;
29
29
  }
30
- export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn }: Props): void;
30
+ export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration }: Props): void;
31
31
  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 }) {
8
+ export function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration }) {
9
9
  const [promise, setPromise] = useState(null);
10
10
  if (promise) {
11
11
  useUse.current = true;
@@ -30,7 +30,8 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
30
30
  transitionEnd({
31
31
  transitionEndObj: removeEnter,
32
32
  transitionEndHandler,
33
- reverse
33
+ reverse,
34
+ delayStep
34
35
  });
35
36
  state.current = 'navigating';
36
37
  container.current?.classList.remove('exit');
@@ -76,7 +77,8 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
76
77
  transitionEnd({
77
78
  transitionEndObj: pop,
78
79
  transitionEndHandler,
79
- reverse
80
+ reverse,
81
+ delayStep
80
82
  });
81
83
  }
82
84
  });
@@ -101,12 +103,12 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
101
103
  resolveNavigating();
102
104
  }
103
105
  }).then(() => {
104
- console.log('not navigating');
105
106
  if (currentPathname.current === window.location.pathname) {
106
107
  transitionEnd({
107
108
  transitionEndObj: afterExit,
108
109
  transitionEndHandler,
109
- reverse
110
+ reverse,
111
+ delayStep
110
112
  });
111
113
  return;
112
114
  }
@@ -114,7 +116,8 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
114
116
  transitionEnd({
115
117
  transitionEndObj: afterEntering,
116
118
  transitionEndHandler,
117
- reverse
119
+ reverse,
120
+ delayStep
118
121
  });
119
122
  let elArray = [];
120
123
  if (transitionEndData.current.mirror) {
@@ -129,13 +132,24 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
129
132
  elArray,
130
133
  transitionProperty: transitionEndData.current.transitionProperty,
131
134
  target: 0,
132
- duration: transitionEndData.current.duration
135
+ duration: duration.current ?? 0
133
136
  }).then(() => {
134
- transitionEnd({
135
- transitionEndObj: pop,
136
- transitionEndHandler,
137
- reverse
138
- });
137
+ if (currentPathname.current === window.location.pathname) {
138
+ transitionEnd({
139
+ transitionEndObj: afterExit,
140
+ transitionEndHandler,
141
+ reverse,
142
+ delayStep
143
+ });
144
+ }
145
+ else {
146
+ transitionEnd({
147
+ transitionEndObj: pop,
148
+ transitionEndHandler,
149
+ reverse,
150
+ delayStep
151
+ });
152
+ }
139
153
  container.current?.classList.remove('enter');
140
154
  container.current?.classList.add('exit');
141
155
  state.current = 'exiting';
@@ -150,7 +164,7 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
150
164
  elArray,
151
165
  transitionProperty: transitionEndData.current.transitionProperty,
152
166
  target: 1,
153
- duration: transitionEndData.current.duration
167
+ duration: duration.current ?? 0
154
168
  }).catch(() => { });
155
169
  }).catch(() => { });
156
170
  return;
@@ -158,7 +172,8 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
158
172
  transitionEnd({
159
173
  transitionEndObj: pop,
160
174
  transitionEndHandler,
161
- reverse
175
+ reverse,
176
+ delayStep
162
177
  });
163
178
  container.current?.classList.remove('enter');
164
179
  container.current?.classList.add('exit');
@@ -4,8 +4,6 @@ interface TransitionEndData {
4
4
  transitionProperty: 'opacity' | 'clip-path';
5
5
  mirror: boolean;
6
6
  mirrorElArray: (HTMLDivElement | null)[];
7
- delayStep: number;
8
- duration: number;
9
7
  }
10
8
  interface Props {
11
9
  elArray: RefObject<HTMLDivElement | null | (HTMLDivElement | null)[]>;
@@ -6,8 +6,6 @@ export function useTransitionEndData({ elArray, transitionProperty, mirror, mirr
6
6
  transitionProperty,
7
7
  mirror,
8
8
  mirrorElArray: [],
9
- delayStep: 0,
10
- duration: 0
11
9
  });
12
10
  useEffect(() => {
13
11
  transitionEndData.current = {
@@ -4,8 +4,6 @@ interface TransitionEndData {
4
4
  transitionProperty: 'opacity' | 'clip-path';
5
5
  mirror: boolean;
6
6
  mirrorElArray: (HTMLDivElement | null)[];
7
- delayStep: number;
8
- duration: number;
9
7
  }
10
8
  interface Props {
11
9
  transitionEndData: RefObject<TransitionEndData>;
@@ -16,8 +14,6 @@ interface TransitionEndObj {
16
14
  transitionProperty: 'opacity' | 'clip-path';
17
15
  mirror: boolean;
18
16
  mirrorElArray: (HTMLDivElement | null)[];
19
- delayStep: number;
20
- duration: number;
21
17
  fn: (() => void) | null;
22
18
  }
23
19
  export declare function useTransitionEndObj({ transitionEndData, fn }: Props): RefObject<TransitionEndObj>;
@@ -5,9 +5,7 @@ export function useTransitionEndObj({ transitionEndData, fn }) {
5
5
  transitionProperty: transitionEndData.current.transitionProperty,
6
6
  mirror: transitionEndData.current.mirror,
7
7
  mirrorElArray: [],
8
- fn: null,
9
- delayStep: transitionEndData.current.delayStep,
10
- duration: transitionEndData.current.duration
8
+ fn: null
11
9
  });
12
10
  useEffect(() => {
13
11
  transitionEndObj.current = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-transition",
3
- "version": "0.1.0-beta.35",
3
+ "version": "0.1.0-beta.37",
4
4
  "description": "A page transition library for the Next.js App Router.",
5
5
  "license": "MIT",
6
6
  "files": [