page-transition 0.1.0-beta.20 → 0.1.0-beta.21

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