page-transition 0.1.0-beta.45 → 0.1.0-beta.47

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 (43) hide show
  1. package/README.md +17 -24
  2. package/dist/context/CssTransitionProvider.d.ts +3 -3
  3. package/dist/context/CssTransitionProvider.js +10 -56
  4. package/dist/context/TransitionContext.d.ts +4 -5
  5. package/dist/context/TransitionContext.js +1 -1
  6. package/dist/functions/checkTransitionStart.js +2 -7
  7. package/dist/functions/transitionEnd.d.ts +1 -6
  8. package/dist/functions/transitionEnd.js +1 -11
  9. package/dist/functions/transitionRunning.d.ts +2 -0
  10. package/dist/functions/transitionRunning.js +19 -0
  11. package/dist/hooks/useHandleLinkClick.d.ts +1 -10
  12. package/dist/hooks/useHandleLinkClick.js +28 -128
  13. package/dist/hooks/usePopState.d.ts +1 -10
  14. package/dist/hooks/usePopState.js +25 -123
  15. package/dist/hooks/useTransitionEndData.d.ts +2 -1
  16. package/dist/types/transitionEnd.types.d.ts +3 -2
  17. package/dist/types/transitionPropertys.types.d.ts +1 -0
  18. package/dist/types/transitionPropertys.types.js +1 -0
  19. package/package.json +1 -1
  20. package/dist/functions/parseClipPath.d.ts +0 -1
  21. package/dist/functions/parseClipPath.js +0 -9
  22. package/dist/functions/parseDelay.d.ts +0 -1
  23. package/dist/functions/parseDelay.js +0 -10
  24. package/dist/functions/parseDuration.d.ts +0 -1
  25. package/dist/functions/parseDuration.js +0 -5
  26. package/dist/functions/parseFirstClipPath.d.ts +0 -1
  27. package/dist/functions/parseFirstClipPath.js +0 -12
  28. package/dist/functions/parseFirstOpacity.d.ts +0 -1
  29. package/dist/functions/parseFirstOpacity.js +0 -8
  30. package/dist/functions/parseOpacity.d.ts +0 -1
  31. package/dist/functions/parseOpacity.js +0 -6
  32. package/dist/functions/parseProperty.d.ts +0 -1
  33. package/dist/functions/parseProperty.js +0 -11
  34. package/dist/functions/resetDelay.d.ts +0 -1
  35. package/dist/functions/resetDelay.js +0 -7
  36. package/dist/functions/setDelayReverse.d.ts +0 -7
  37. package/dist/functions/setDelayReverse.js +0 -13
  38. package/dist/functions/setPlaybackRate.d.ts +0 -7
  39. package/dist/functions/setPlaybackRate.js +0 -10
  40. package/dist/functions/transitionEndReverse.d.ts +0 -13
  41. package/dist/functions/transitionEndReverse.js +0 -36
  42. package/dist/functions/updatePlaybackRate.d.ts +0 -11
  43. package/dist/functions/updatePlaybackRate.js +0 -53
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.44-000000) ![86.9 KB](https://img.shields.io/badge/86.9_KB-1677FF)
13
+ ![Version](https://img.shields.io/badge/v_0.1.0--beta.47-000000) ![68.0 KB](https://img.shields.io/badge/68.0_KB-1677FF)
14
14
 
15
15
  `npm install page-transition@beta`
16
16
 
@@ -47,11 +47,10 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
47
47
 
48
48
  *Options*
49
49
 
50
- | Option | Type | Default |
51
- |---|---|---|
52
- | transitionProperty | "opacity" \| "clip-path" | "opacity" |
53
- | wait | boolean | false |
54
- | items | [number, number] | [0, 0] |
50
+ | Option | Type | Default | Required |
51
+ |---|---|---|---|
52
+ | transitionProperty | "opacity" \| "clip-path" \| "transform" | - | Yes |
53
+ | items | [number, number] | [0, 0] | - |
55
54
 
56
55
 
57
56
  **Prop Descriptions**
@@ -60,21 +59,17 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
60
59
  Select the transition mode.
61
60
 
62
61
  **header**
63
- The component rendered outside the transition container.
62
+ The component rendered outside the .page-wrapper.
64
63
 
65
64
  **options.transitionProperty**
66
65
  Defines which property transitionend waits for.
67
66
 
68
- **options.wait**
69
- false: Reverses the current enter transition.
70
- true: Waits for the current enter transition to finish before starting the new transition.
71
-
72
67
  **options.items**
73
68
  <br/>
74
- options.items[0]
69
+ `options.items[0]`
75
70
  Number of items in the first group. Each item receives the `.overlay-item` class.
76
71
  <br/>
77
- options.items[1]
72
+ `options.items[1]`
78
73
  Number of items in the second group. Each item receives the `.second-item` class.
79
74
 
80
75
 
@@ -105,8 +100,9 @@ options={{
105
100
  TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
106
101
 
107
102
  **Description**
108
- Triggers the transition.
103
+ Triggers the transition.
109
104
 
105
+ *Must be used within the TransitionProvider*
110
106
 
111
107
  ```tsx
112
108
  <TransitionLink href={"/home"}>
@@ -116,19 +112,15 @@ Triggers the transition.
116
112
 
117
113
  ### CSS Mode
118
114
 
119
- 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.
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.
120
116
 
121
117
  Once the transition ends, the scroll position is restored and navigation is performed.
122
118
 
123
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.
124
120
 
125
- For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array. The transition waits for the first item group to finish its transition.
121
+ For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array.
122
+ <br/>
126
123
  <br/>
127
- When `wait` is `false`, both item groups must contain the same number of items for reverse delays to work correctly. Both groups will then receive the same delay durations when reversing a staggered enter transition.
128
-
129
-
130
- *At the moment, it only supports duration and delay in seconds.*
131
-
132
124
  To access the overlay wrapper and its items, use `useTransitionContext`.
133
125
 
134
126
  ```ts
@@ -150,16 +142,16 @@ transitionProperty: "opacity"
150
142
  ```
151
143
 
152
144
  ```css
153
- [data-transition]{
145
+ [data-transition] .page-wrapper{
154
146
  will-change: opacity;
155
147
  opacity: 1;
156
148
  }
157
- [data-transition].exit{
149
+ [data-transition].exit .page-wrapper{
158
150
  opacity: 0;
159
151
  transition: opacity 0.4s ease;
160
152
 
161
153
  }
162
- [data-transition].enter{
154
+ [data-transition].enter .page-wrapper{
163
155
  opacity: 1;
164
156
  transition: opacity 0.5s ease;
165
157
  }
@@ -326,6 +318,7 @@ items: [10, 10]
326
318
  ```
327
319
  </details>
328
320
 
321
+
329
322
  ### Manual Mode
330
323
 
331
324
  In manual mode, you can control the transition using `useTransitionContext`.
@@ -1,12 +1,12 @@
1
1
  import type { ReactNode } from "react";
2
+ import type { TransitionProperty } from "../types/transitionPropertys.types";
2
3
  interface TransitionOptions {
3
- transitionProperty?: 'opacity' | 'clip-path';
4
- wait?: boolean;
4
+ transitionProperty: TransitionProperty;
5
5
  items?: [number, number];
6
6
  }
7
7
  interface ProviderProps {
8
8
  header?: ReactNode;
9
- options?: TransitionOptions;
9
+ options: TransitionOptions;
10
10
  children: ReactNode;
11
11
  }
12
12
  export declare function CssTransitionProvider({ header, options, children }: ProviderProps): import("react").JSX.Element;
@@ -10,17 +10,14 @@ 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
- import { parseDuration } from "../functions/parseDuration";
15
13
  import { pollTransitionStart } from "../functions/pollTransitionStart";
16
14
  export function CssTransitionProvider({ header, options, children }) {
17
15
  const defaultOptions = {
18
- transitionProperty: 'opacity',
19
- wait: false,
20
16
  items: [0, 0],
21
17
  ...options
22
18
  };
23
19
  const container = useRef(null);
20
+ const pageWrapper = useRef(null);
24
21
  const overlayWrapper = useRef(null);
25
22
  const overlayItems = useRef([]);
26
23
  const secondItems = useRef([]);
@@ -34,49 +31,23 @@ export function CssTransitionProvider({ header, options, children }) {
34
31
  const basePath = useRef(null);
35
32
  const useUse = useRef(false);
36
33
  const resolveUseFn = useRef(null);
37
- const reverse = useRef({
38
- _lock: true,
39
- get lock() {
40
- return this._lock;
41
- },
42
- set lock(value) {
43
- if (delayStep.current === 0 ||
44
- overlayItems.current.length < 2 ||
45
- defaultOptions.wait === true) {
46
- if (this._lock === false)
47
- this._lock = true;
48
- return;
49
- }
50
- this._lock = value;
51
- }
52
- });
53
- const delayStep = useRef(null);
54
- const duration = useRef(null);
55
34
  const handleLinkClick = useRef(() => { });
56
35
  const transitionEndHandler = useTransitionEndHandler();
57
36
  const transitionEndData = useTransitionEndData({
58
- elArray: defaultOptions.items[0] === 0 ? container : overlayItems,
37
+ elArray: defaultOptions.items[0] === 0 ? pageWrapper : overlayItems,
59
38
  transitionProperty: defaultOptions.transitionProperty,
60
39
  secondElArray: secondItems
61
40
  });
62
41
  const pollRafId = useRef(null);
63
- const rafId = useRef(null);
64
- const rejectFn = useRef(null);
65
42
  usePopState({
66
43
  container,
67
44
  currentPathname,
68
45
  transitionEndData,
69
46
  transitionEndHandler,
70
47
  state,
71
- reverse,
72
48
  useUse,
73
49
  resolveUseFn,
74
- pollRafId,
75
- rafId,
76
- rejectFn,
77
- delayStep,
78
- duration,
79
- wait: defaultOptions.wait
50
+ pollRafId
80
51
  });
81
52
  useHandleLinkClick({
82
53
  container,
@@ -85,16 +56,10 @@ export function CssTransitionProvider({ header, options, children }) {
85
56
  transitionEndData,
86
57
  transitionEndHandler,
87
58
  state,
88
- reverse,
89
59
  useUse,
90
60
  resolveUseFn,
91
61
  basePath,
92
- pollRafId,
93
- rafId,
94
- rejectFn,
95
- delayStep,
96
- duration,
97
- wait: defaultOptions.wait
62
+ pollRafId
98
63
  });
99
64
  useScrollRestoration();
100
65
  const removeEnter = useTransitionEndObj({
@@ -102,7 +67,6 @@ export function CssTransitionProvider({ header, options, children }) {
102
67
  fn: () => {
103
68
  container.current?.classList.remove('enter');
104
69
  state.current = 'idle';
105
- reverse.current.lock = true;
106
70
  }
107
71
  });
108
72
  useEffect(() => {
@@ -117,9 +81,7 @@ export function CssTransitionProvider({ header, options, children }) {
117
81
  return;
118
82
  transitionEnd({
119
83
  transitionEndObj: removeEnter,
120
- transitionEndHandler,
121
- reverse,
122
- delayStep
84
+ transitionEndHandler
123
85
  });
124
86
  container.current.classList.remove('exit');
125
87
  container.current.classList.add('enter');
@@ -131,19 +93,11 @@ export function CssTransitionProvider({ header, options, children }) {
131
93
  }
132
94
  });
133
95
  currentPathname.current = window.location.pathname;
134
- reverse.current.lock = false;
135
- if (delayStep.current === null && defaultOptions.items[0] > 1) {
136
- delayStep.current = defaultOptions.wait ? 0 :
137
- parseDelay(transitionEndData.current.elArray);
138
- }
139
- if (duration.current === null && !defaultOptions.wait) {
140
- duration.current = parseDuration(transitionEndData.current.elArray[0]) * 1000 / 3;
141
- }
142
96
  }, [pathname]);
143
97
  const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
144
- 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.items[0] > 0 && Array.from({ length: defaultOptions.items[0] }).map((_, i) => (_jsx("div", { ref: (el) => {
145
- overlayItems.current[i] = el;
146
- }, className: "overlay-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
147
- secondItems.current[i] = el;
148
- }, className: "second-item" }, `mirror${i}`)))] }), children] })] }));
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) => {
99
+ overlayItems.current[i] = el;
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 })] }) }));
149
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,17 +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?: TransitionProperty;
15
- wait?: boolean;
14
+ transitionProperty: TransitionProperty;
16
15
  items?: [number, number];
17
16
  }
18
17
  interface ProviderProps {
19
18
  header?: ReactNode;
20
19
  mode?: Mode;
21
- options?: TransitionOptions;
20
+ options: TransitionOptions;
22
21
  children: ReactNode;
23
22
  }
24
- export declare function TransitionProvider({ header, mode, options, children, }: ProviderProps): import("react").JSX.Element;
23
+ export declare function TransitionProvider({ header, mode, options, children }: ProviderProps): import("react").JSX.Element;
25
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 }));
@@ -1,11 +1,6 @@
1
- import { parseFirstOpacity } from "./parseFirstOpacity";
2
- import { parseFirstClipPath } from "./parseFirstClipPath";
1
+ import { transitionRunning } from "./transitionRunning";
3
2
  export function checkTransitionStart(transitionEndData, fn) {
4
- const parse = {
5
- 'opacity': () => parseFirstOpacity(transitionEndData.elArray),
6
- 'clip-path': () => parseFirstClipPath(transitionEndData.elArray)
7
- };
8
- if (parse[transitionEndData.transitionProperty]()) {
3
+ if (transitionRunning(transitionEndData.elArray, transitionEndData.transitionProperty)) {
9
4
  fn?.();
10
5
  return true;
11
6
  }
@@ -3,11 +3,6 @@ import type { TransitionEndObj, TransitionEndHandler } from "../types/transition
3
3
  interface Props {
4
4
  transitionEndObj: RefObject<TransitionEndObj>;
5
5
  transitionEndHandler: RefObject<TransitionEndHandler>;
6
- reverse: RefObject<{
7
- _lock: boolean;
8
- lock: boolean;
9
- }>;
10
- delayStep: RefObject<number | null>;
11
6
  }
12
- export declare function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
7
+ export declare function transitionEnd({ transitionEndObj, transitionEndHandler }: Props): void;
13
8
  export {};
@@ -1,20 +1,10 @@
1
- import { transtionEndReverse } from "./transitionEndReverse";
2
- export function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delayStep }) {
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
7
  const endObj = transitionEndObj.current;
9
- if (!reverse.current.lock) {
10
- transtionEndReverse({
11
- transitionEndObj,
12
- transitionEndHandler,
13
- reverse,
14
- delayStep
15
- });
16
- return;
17
- }
18
8
  const handler = (e) => {
19
9
  if (e.target !== e.currentTarget)
20
10
  return;
@@ -0,0 +1,2 @@
1
+ import type { TransitionProperty } from "../types/transitionPropertys.types";
2
+ export declare function transitionRunning(elArray: (HTMLDivElement | null)[], transitionProperty: TransitionProperty): null | boolean;
@@ -0,0 +1,19 @@
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
+ return obj.playState === 'running' &&
11
+ obj.effect instanceof KeyframeEffect &&
12
+ obj.effect.getKeyframes().some(frame => {
13
+ return frame[property[transitionProperty]] !== undefined;
14
+ });
15
+ })) {
16
+ return true;
17
+ }
18
+ return false;
19
+ }
@@ -7,19 +7,10 @@ interface Props {
7
7
  transitionEndData: RefObject<TransitionEndData>;
8
8
  transitionEndHandler: RefObject<TransitionEndHandler>;
9
9
  state: RefObject<'idle' | 'exiting' | 'entering' | 'navigating'>;
10
- reverse: RefObject<{
11
- _lock: boolean;
12
- lock: boolean;
13
- }>;
14
10
  useUse: RefObject<boolean>;
15
11
  resolveUseFn: RefObject<(() => void) | null>;
16
12
  basePath: RefObject<string | null>;
17
13
  pollRafId: RefObject<number | null>;
18
- rafId: RefObject<number | null>;
19
- rejectFn: RefObject<(() => void) | null>;
20
- delayStep: RefObject<number | null>;
21
- duration: RefObject<number | null>;
22
- wait: boolean;
23
14
  }
24
- export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration, wait }: Props): void;
15
+ export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, basePath, pollRafId }: Props): void;
25
16
  export {};
@@ -4,9 +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
- import { updatePlaybackRate } from "../functions/updatePlaybackRate";
8
- import { setPlaybackRate } from "../functions/setPlaybackRate";
9
- export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, basePath, pollRafId, rafId, rejectFn, delayStep, duration, wait }) {
7
+ export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, basePath, pollRafId }) {
10
8
  const router = useRouter();
11
9
  const afterExitFn = useRef(null);
12
10
  const nextPage = useRef(null);
@@ -27,7 +25,6 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
27
25
  fn: () => {
28
26
  container.current?.classList.remove('enter');
29
27
  state.current = 'idle';
30
- reverse.current.lock = true;
31
28
  }
32
29
  });
33
30
  const afterExit = useTransitionEndObj({
@@ -35,9 +32,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
35
32
  fn: afterExitFn.current = () => {
36
33
  transitionEnd({
37
34
  transitionEndObj: removeEnter,
38
- transitionEndHandler,
39
- reverse,
40
- delayStep
35
+ transitionEndHandler
41
36
  });
42
37
  if (useUse.current) {
43
38
  resolveUseFn.current?.();
@@ -46,13 +41,13 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
46
41
  }
47
42
  state.current = 'navigating';
48
43
  container.current?.classList.remove('exit');
44
+ void container.current?.offsetWidth;
49
45
  container.current?.classList.add('enter');
50
46
  pollTransitionStart({
51
47
  id: pollRafId,
52
48
  transitionEndData,
53
49
  fn: () => {
54
50
  state.current = 'entering';
55
- reverse.current.lock = false;
56
51
  }
57
52
  });
58
53
  }
@@ -60,20 +55,13 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
60
55
  const afterEntering = useTransitionEndObj({
61
56
  transitionEndData,
62
57
  fn: () => {
63
- if (rafId.current) {
64
- cancelAnimationFrame(rafId.current);
65
- rafId.current = null;
66
- }
67
- rejectFn.current?.();
68
58
  container.current?.classList.remove('enter');
69
59
  void container.current?.offsetWidth;
70
60
  container.current?.classList.add('exit');
71
61
  state.current = 'exiting';
72
62
  transitionEnd({
73
63
  transitionEndObj: push,
74
- transitionEndHandler,
75
- reverse,
76
- delayStep
64
+ transitionEndHandler
77
65
  });
78
66
  }
79
67
  });
@@ -99,128 +87,40 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
99
87
  resolve();
100
88
  }
101
89
  }).then(() => {
102
- if (wait) {
103
- if (state.current === 'idle' &&
104
- currentPathname.current === basePathUrl)
105
- return;
106
- if (currentPathname.current === basePathUrl
107
- && state.current === 'exiting') {
108
- transitionEnd({
109
- transitionEndObj: afterExit,
110
- transitionEndHandler,
111
- reverse,
112
- delayStep
113
- });
114
- return;
115
- }
116
- if (state.current === 'entering' &&
117
- currentPathname.current === basePathUrl) {
118
- transitionEnd({
119
- transitionEndObj: removeEnter,
120
- transitionEndHandler,
121
- reverse,
122
- delayStep
123
- });
124
- return;
125
- }
126
- if (state.current === 'idle' || state.current === 'exiting') {
127
- transitionEnd({
128
- transitionEndObj: push,
129
- transitionEndHandler,
130
- reverse,
131
- delayStep
132
- });
133
- container.current?.classList.remove('enter');
134
- container.current?.classList.add('exit');
135
- state.current = 'exiting';
136
- }
137
- else {
138
- transitionEnd({
139
- transitionEndObj: afterEntering,
140
- transitionEndHandler,
141
- reverse,
142
- delayStep
143
- });
144
- }
90
+ if (state.current === 'idle' &&
91
+ currentPathname.current === basePathUrl)
145
92
  return;
146
- }
147
- if (basePathUrl === currentPathname.current) {
148
- if (state.current !== 'exiting')
149
- return;
93
+ if (currentPathname.current === basePathUrl
94
+ && state.current === 'exiting') {
150
95
  transitionEnd({
151
96
  transitionEndObj: afterExit,
152
- transitionEndHandler,
153
- reverse,
154
- delayStep
97
+ transitionEndHandler
155
98
  });
156
99
  return;
157
100
  }
158
- if (state.current === 'entering') {
101
+ if (state.current === 'entering' &&
102
+ currentPathname.current === basePathUrl) {
159
103
  transitionEnd({
160
- transitionEndObj: afterEntering,
161
- transitionEndHandler,
162
- reverse,
163
- delayStep
104
+ transitionEndObj: removeEnter,
105
+ transitionEndHandler
164
106
  });
165
- let elArray = [];
166
- if (transitionEndData.current.secondElArray.length > 0) {
167
- elArray = [...transitionEndData.current.secondElArray, ...transitionEndData.current.elArray];
168
- }
169
- else {
170
- elArray = [...transitionEndData.current.elArray];
171
- }
172
- updatePlaybackRate({
173
- rafId,
174
- rejectFn,
175
- elArray,
176
- transitionProperty: transitionEndData.current.transitionProperty,
177
- target: 0,
178
- duration: duration.current ?? 0
179
- }).then(() => {
180
- if (nextPage.current === currentPathname.current) {
181
- transitionEnd({
182
- transitionEndObj: afterExit,
183
- transitionEndHandler,
184
- reverse,
185
- delayStep
186
- });
187
- }
188
- else {
189
- transitionEnd({
190
- transitionEndObj: push,
191
- transitionEndHandler,
192
- reverse,
193
- delayStep
194
- });
195
- }
196
- container.current?.classList.remove('enter');
197
- container.current?.classList.add('exit');
198
- state.current = 'exiting';
199
- setPlaybackRate({
200
- elArray,
201
- transitionProperty: transitionEndData.current.transitionProperty,
202
- value: 0
203
- });
204
- updatePlaybackRate({
205
- rafId,
206
- rejectFn,
207
- elArray,
208
- transitionProperty: transitionEndData.current.transitionProperty,
209
- target: 1,
210
- duration: duration.current ?? 0
211
- }).catch(() => { });
212
- }).catch(() => { });
213
107
  return;
214
108
  }
215
- transitionEnd({
216
- transitionEndObj: push,
217
- transitionEndHandler,
218
- reverse,
219
- delayStep
220
- });
221
- container.current?.classList.remove('enter');
222
- container.current?.classList.add('exit');
223
- state.current = 'exiting';
109
+ if (state.current === 'idle' || state.current === 'exiting') {
110
+ transitionEnd({
111
+ transitionEndObj: push,
112
+ transitionEndHandler
113
+ });
114
+ container.current?.classList.remove('enter');
115
+ container.current?.classList.add('exit');
116
+ state.current = 'exiting';
117
+ }
118
+ else {
119
+ transitionEnd({
120
+ transitionEndObj: afterEntering,
121
+ transitionEndHandler
122
+ });
123
+ }
224
124
  });
225
125
  }, [router]);
226
126
  }
@@ -5,19 +5,10 @@ interface Props {
5
5
  currentPathname: RefObject<string>;
6
6
  transitionEndData: RefObject<TransitionEndData>;
7
7
  transitionEndHandler: RefObject<TransitionEndHandler>;
8
- reverse: RefObject<{
9
- _lock: boolean;
10
- lock: boolean;
11
- }>;
12
8
  state: RefObject<'idle' | 'exiting' | 'entering' | 'navigating'>;
13
9
  useUse: RefObject<boolean>;
14
10
  resolveUseFn: RefObject<(() => void) | null>;
15
11
  pollRafId: RefObject<number | null>;
16
- rafId: RefObject<number | null>;
17
- rejectFn: RefObject<(() => void) | null>;
18
- delayStep: RefObject<number | null>;
19
- duration: RefObject<number | null>;
20
- wait: boolean;
21
12
  }
22
- export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration, wait }: Props): void;
13
+ export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, pollRafId }: Props): void;
23
14
  export {};
@@ -3,9 +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
- import { updatePlaybackRate } from "../functions/updatePlaybackRate";
7
- import { setPlaybackRate } from "../functions/setPlaybackRate";
8
- export function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, state, useUse, resolveUseFn, pollRafId, rafId, rejectFn, delayStep, duration, wait }) {
6
+ export function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, pollRafId }) {
9
7
  const [promise, setPromise] = useState(null);
10
8
  if (promise) {
11
9
  useUse.current = true;
@@ -21,7 +19,6 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
21
19
  fn: () => {
22
20
  container.current?.classList.remove('enter');
23
21
  state.current = 'idle';
24
- reverse.current.lock = true;
25
22
  }
26
23
  });
27
24
  const afterExit = useTransitionEndObj({
@@ -29,9 +26,7 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
29
26
  fn: afterExitFn.current = () => {
30
27
  transitionEnd({
31
28
  transitionEndObj: removeEnter,
32
- transitionEndHandler,
33
- reverse,
34
- delayStep
29
+ transitionEndHandler
35
30
  });
36
31
  state.current = 'navigating';
37
32
  container.current?.classList.remove('exit');
@@ -44,7 +39,6 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
44
39
  transitionEndData,
45
40
  fn: () => {
46
41
  state.current = 'entering';
47
- reverse.current.lock = false;
48
42
  }
49
43
  });
50
44
  }
@@ -62,20 +56,13 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
62
56
  const afterEntering = useTransitionEndObj({
63
57
  transitionEndData,
64
58
  fn: () => {
65
- if (rafId.current) {
66
- cancelAnimationFrame(rafId.current);
67
- rafId.current = null;
68
- }
69
- rejectFn.current?.();
70
59
  container.current?.classList.remove('enter');
71
60
  void container.current?.offsetWidth;
72
61
  container.current?.classList.add('exit');
73
62
  state.current = 'exiting';
74
63
  transitionEnd({
75
64
  transitionEndObj: pop,
76
- transitionEndHandler,
77
- reverse,
78
- delayStep
65
+ transitionEndHandler
79
66
  });
80
67
  }
81
68
  });
@@ -87,6 +74,7 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
87
74
  new Promise((resolveNavigating) => {
88
75
  if (state.current === "navigating") {
89
76
  if (currentPathname.current !== window.location.pathname) {
77
+ state.current = 'navigating';
90
78
  resolveFn.current?.();
91
79
  setPromise(null);
92
80
  return;
@@ -99,123 +87,37 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
99
87
  resolveNavigating();
100
88
  }
101
89
  }).then(() => {
102
- if (wait) {
103
- if (currentPathname.current === window.location.pathname
104
- && state.current === 'exiting') {
105
- transitionEnd({
106
- transitionEndObj: afterExit,
107
- transitionEndHandler,
108
- reverse,
109
- delayStep
110
- });
111
- return;
112
- }
113
- if (state.current === 'entering' &&
114
- currentPathname.current === window.location.pathname) {
115
- transitionEnd({
116
- transitionEndObj: removeEnter,
117
- transitionEndHandler,
118
- reverse,
119
- delayStep
120
- });
121
- return;
122
- }
123
- if (state.current === 'idle' || state.current === 'exiting') {
124
- transitionEnd({
125
- transitionEndObj: pop,
126
- transitionEndHandler,
127
- reverse,
128
- delayStep
129
- });
130
- container.current?.classList.remove('enter');
131
- container.current?.classList.add('exit');
132
- state.current = 'exiting';
133
- }
134
- else {
135
- transitionEnd({
136
- transitionEndObj: afterEntering,
137
- transitionEndHandler,
138
- reverse,
139
- delayStep
140
- });
141
- }
90
+ if (currentPathname.current === window.location.pathname
91
+ && state.current === 'exiting') {
92
+ transitionEnd({
93
+ transitionEndObj: afterExit,
94
+ transitionEndHandler
95
+ });
142
96
  return;
143
97
  }
144
- if (currentPathname.current === window.location.pathname) {
98
+ if (state.current === 'entering' &&
99
+ currentPathname.current === window.location.pathname) {
145
100
  transitionEnd({
146
- transitionEndObj: afterExit,
147
- transitionEndHandler,
148
- reverse,
149
- delayStep
101
+ transitionEndObj: removeEnter,
102
+ transitionEndHandler
150
103
  });
151
104
  return;
152
105
  }
153
- if (state.current === 'entering') {
106
+ if (state.current === 'idle' || state.current === 'exiting') {
107
+ transitionEnd({
108
+ transitionEndObj: pop,
109
+ transitionEndHandler
110
+ });
111
+ container.current?.classList.remove('enter');
112
+ container.current?.classList.add('exit');
113
+ state.current = 'exiting';
114
+ }
115
+ else {
154
116
  transitionEnd({
155
117
  transitionEndObj: afterEntering,
156
- transitionEndHandler,
157
- reverse,
158
- delayStep
118
+ transitionEndHandler
159
119
  });
160
- let elArray = [];
161
- if (transitionEndData.current.secondElArray.length > 0) {
162
- elArray = [...transitionEndData.current.secondElArray, ...transitionEndData.current.elArray];
163
- }
164
- else {
165
- elArray = [...transitionEndData.current.elArray];
166
- }
167
- updatePlaybackRate({
168
- rafId,
169
- rejectFn,
170
- elArray,
171
- transitionProperty: transitionEndData.current.transitionProperty,
172
- target: 0,
173
- duration: duration.current ?? 0
174
- }).then(() => {
175
- if (currentPathname.current === window.location.pathname) {
176
- transitionEnd({
177
- transitionEndObj: afterExit,
178
- transitionEndHandler,
179
- reverse,
180
- delayStep
181
- });
182
- }
183
- else {
184
- transitionEnd({
185
- transitionEndObj: pop,
186
- transitionEndHandler,
187
- reverse,
188
- delayStep
189
- });
190
- }
191
- container.current?.classList.remove('enter');
192
- container.current?.classList.add('exit');
193
- state.current = 'exiting';
194
- setPlaybackRate({
195
- elArray,
196
- transitionProperty: transitionEndData.current.transitionProperty,
197
- value: 0
198
- });
199
- updatePlaybackRate({
200
- rafId,
201
- rejectFn,
202
- elArray,
203
- transitionProperty: transitionEndData.current.transitionProperty,
204
- target: 1,
205
- duration: duration.current ?? 0
206
- }).catch(() => { });
207
- }).catch(() => { });
208
- return;
209
120
  }
210
- transitionEnd({
211
- transitionEndObj: pop,
212
- transitionEndHandler,
213
- reverse,
214
- delayStep
215
- });
216
- container.current?.classList.remove('enter');
217
- container.current?.classList.add('exit');
218
- state.current = 'exiting';
219
121
  });
220
122
  }).catch(() => setPromise(null)));
221
123
  };
@@ -1,8 +1,9 @@
1
1
  import type { RefObject } from "react";
2
2
  import type { TransitionEndData } from "../types/transitionEnd.types";
3
+ import type { TransitionProperty } from "../types/transitionPropertys.types";
3
4
  interface Props {
4
5
  elArray: RefObject<HTMLDivElement | null | (HTMLDivElement | null)[]>;
5
- transitionProperty: 'opacity' | 'clip-path';
6
+ transitionProperty: TransitionProperty;
6
7
  secondElArray: RefObject<(HTMLDivElement | null)[]>;
7
8
  }
8
9
  export declare function useTransitionEndData({ elArray, transitionProperty, secondElArray }: Props): RefObject<TransitionEndData>;
@@ -1,11 +1,12 @@
1
+ import type { TransitionProperty } from "./transitionPropertys.types";
1
2
  export interface TransitionEndData {
2
3
  elArray: (HTMLDivElement | null)[];
3
- transitionProperty: 'opacity' | 'clip-path';
4
+ transitionProperty: TransitionProperty;
4
5
  secondElArray: (HTMLDivElement | null)[];
5
6
  }
6
7
  export interface TransitionEndObj {
7
8
  elArray: (HTMLDivElement | null)[];
8
- transitionProperty: 'opacity' | 'clip-path';
9
+ transitionProperty: TransitionProperty;
9
10
  secondElArray: (HTMLDivElement | null)[];
10
11
  fn: (() => void) | null;
11
12
  }
@@ -0,0 +1 @@
1
+ export type TransitionProperty = 'opacity' | 'clip-path' | 'transform';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-transition",
3
- "version": "0.1.0-beta.45",
3
+ "version": "0.1.0-beta.47",
4
4
  "description": "A page transition library for the Next.js App Router.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1 +0,0 @@
1
- export declare function parseClipPath(el: HTMLDivElement | null): number | null;
@@ -1,9 +0,0 @@
1
- export function parseClipPath(el) {
2
- if (!el)
3
- return null;
4
- const clipPath = getComputedStyle(el).clipPath;
5
- const match = clipPath.match(/inset\(([^)]+)\)/);
6
- const result = match?.[1]?.split(/\s+/) ?? null;
7
- const number = result?.map(value => parseFloat(value)).find(value => value > 0) ?? 0;
8
- return number / 100;
9
- }
@@ -1 +0,0 @@
1
- export declare function parseDelay(elArray: (HTMLDivElement | null)[]): number | null;
@@ -1,10 +0,0 @@
1
- export function parseDelay(elArray) {
2
- if (elArray.length === 0)
3
- return null;
4
- const lastIndex = elArray.length - 1;
5
- const lastEl = elArray[lastIndex];
6
- if (!lastEl)
7
- return null;
8
- const lastDelay = parseFloat(getComputedStyle(lastEl).transitionDelay);
9
- return lastDelay / lastIndex;
10
- }
@@ -1 +0,0 @@
1
- export declare function parseDuration(el: HTMLElement | null): number;
@@ -1,5 +0,0 @@
1
- export function parseDuration(el) {
2
- if (!el)
3
- return 0;
4
- return parseFloat(getComputedStyle(el).transitionDuration);
5
- }
@@ -1 +0,0 @@
1
- export declare function parseFirstClipPath(elArray: (HTMLDivElement | null)[]): null | boolean;
@@ -1,12 +0,0 @@
1
- export function parseFirstClipPath(elArray) {
2
- if (!elArray[0])
3
- return null;
4
- const clipPath = getComputedStyle(elArray[0]).clipPath;
5
- const m = clipPath.match(/inset\(([^)]+)\)/) ?? null;
6
- const arr = m?.[1].split(/\s+/) ?? [];
7
- for (const string of arr) {
8
- if (parseFloat(string) < 100)
9
- return true;
10
- }
11
- return false;
12
- }
@@ -1 +0,0 @@
1
- export declare function parseFirstOpacity(elArray: (HTMLDivElement | null)[]): null | boolean;
@@ -1,8 +0,0 @@
1
- export function parseFirstOpacity(elArray) {
2
- if (!elArray[0])
3
- return null;
4
- const opacity = parseFloat(getComputedStyle(elArray[0]).opacity);
5
- if (opacity > 0)
6
- return true;
7
- return false;
8
- }
@@ -1 +0,0 @@
1
- export declare function parseOpacity(el: HTMLDivElement | null): number | null;
@@ -1,6 +0,0 @@
1
- export function parseOpacity(el) {
2
- if (!el)
3
- return null;
4
- const opacity = getComputedStyle(el).opacity;
5
- return parseFloat(opacity);
6
- }
@@ -1 +0,0 @@
1
- export declare function parseProperty(transitionProperty: 'opacity' | 'clip-path', el: HTMLDivElement | null): number | null;
@@ -1,11 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export declare function resetDelay(elArray: (HTMLDivElement | null)[]): void;
@@ -1,7 +0,0 @@
1
- export function resetDelay(elArray) {
2
- elArray.forEach((el) => {
3
- if (!el)
4
- return;
5
- el.style.transitionDelay = "";
6
- });
7
- }
@@ -1,7 +0,0 @@
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 {};
@@ -1,13 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
1
- interface Props {
2
- elArray: (HTMLDivElement | null)[];
3
- transitionProperty: 'opacity' | 'clip-path';
4
- value: number;
5
- }
6
- export declare function setPlaybackRate({ elArray, transitionProperty, value }: Props): void;
7
- export {};
@@ -1,10 +0,0 @@
1
- export function setPlaybackRate({ elArray, transitionProperty, value }) {
2
- elArray.forEach((el) => {
3
- el?.getAnimations().forEach((obj) => {
4
- if (obj instanceof CSSTransition &&
5
- obj.transitionProperty === transitionProperty) {
6
- obj.playbackRate = value;
7
- }
8
- });
9
- });
10
- }
@@ -1,13 +0,0 @@
1
- import type { RefObject } from "react";
2
- import type { TransitionEndObj, TransitionEndHandler } from "../types/transitionEnd.types";
3
- interface Props {
4
- transitionEndObj: RefObject<TransitionEndObj>;
5
- transitionEndHandler: RefObject<TransitionEndHandler>;
6
- reverse: RefObject<{
7
- _lock: boolean;
8
- lock: boolean;
9
- }>;
10
- delayStep: RefObject<number | null>;
11
- }
12
- export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
13
- export {};
@@ -1,36 +0,0 @@
1
- import { setDelayReverse } from "./setDelayReverse";
2
- import { resetDelay } from "./resetDelay";
3
- export function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse, delayStep }) {
4
- if (transitionEndHandler.current.handler &&
5
- transitionEndHandler.current.handlerEl)
6
- transitionEndHandler.current.handlerEl.removeEventListener('transitionend', transitionEndHandler.current.handler);
7
- const endObj = transitionEndObj.current;
8
- setDelayReverse({
9
- elArray: endObj.elArray,
10
- transitionProperty: endObj.transitionProperty,
11
- delayStep: delayStep.current
12
- });
13
- if (endObj.secondElArray.length === endObj.elArray.length) {
14
- setDelayReverse({
15
- elArray: endObj.secondElArray,
16
- transitionProperty: endObj.transitionProperty,
17
- delayStep: delayStep.current
18
- });
19
- }
20
- const firstEl = endObj.elArray[0];
21
- const handler = (e) => {
22
- if (e.propertyName !== endObj.transitionProperty ||
23
- e.target !== e.currentTarget)
24
- return;
25
- resetDelay(endObj.elArray);
26
- if (endObj.secondElArray.length === endObj.elArray.length) {
27
- resetDelay(endObj.secondElArray);
28
- }
29
- reverse.current.lock = true;
30
- firstEl?.removeEventListener('transitionend', handler);
31
- endObj.fn?.();
32
- };
33
- transitionEndHandler.current.handler = handler;
34
- transitionEndHandler.current.handlerEl = firstEl;
35
- firstEl?.addEventListener('transitionend', handler);
36
- }
@@ -1,11 +0,0 @@
1
- import type { RefObject } from "react";
2
- interface Props {
3
- rafId: RefObject<number | null>;
4
- rejectFn: RefObject<(() => void) | null>;
5
- elArray: (HTMLDivElement | null)[];
6
- transitionProperty: 'opacity' | 'clip-path';
7
- target: number;
8
- duration: number;
9
- }
10
- export declare function updatePlaybackRate({ rafId, rejectFn, elArray, transitionProperty, target, duration }: Props): Promise<void>;
11
- export {};
@@ -1,53 +0,0 @@
1
- export function updatePlaybackRate({ rafId, rejectFn, elArray, transitionProperty, target, duration }) {
2
- if (rafId.current !== null)
3
- cancelAnimationFrame(rafId.current);
4
- if (duration === 0)
5
- return Promise.resolve();
6
- let progress = 0;
7
- let summ = target ? 0 : duration;
8
- let animationArray = [];
9
- let start = false;
10
- elArray.forEach((el) => {
11
- el?.getAnimations().forEach((obj) => {
12
- if (obj instanceof CSSTransition &&
13
- obj.transitionProperty === transitionProperty) {
14
- animationArray.push(obj);
15
- }
16
- });
17
- });
18
- let before = null;
19
- return new Promise((resolve, reject) => {
20
- rejectFn.current?.();
21
- rejectFn.current = reject;
22
- const step = (now) => {
23
- if (before === null) {
24
- before = now;
25
- }
26
- const dt = Math.min(now - before, 30);
27
- before = now;
28
- summ = target ? Math.min(summ + dt, duration) : Math.max(summ - dt, 0);
29
- progress = summ / duration;
30
- animationArray.forEach((obj) => {
31
- const currentTime = obj.currentTime;
32
- if (target && typeof currentTime === 'number' && currentTime > 0)
33
- start = true;
34
- if (obj.playState !== "running" ||
35
- typeof currentTime !== "number" ||
36
- currentTime <= 0 && start)
37
- return;
38
- obj.updatePlaybackRate(progress);
39
- });
40
- if (target && progress >= 1 || !target && progress <= 0) {
41
- if (rafId.current !== null) {
42
- cancelAnimationFrame(rafId.current);
43
- rafId.current = null;
44
- }
45
- rejectFn.current = null;
46
- resolve();
47
- return;
48
- }
49
- rafId.current = requestAnimationFrame(step);
50
- };
51
- rafId.current = requestAnimationFrame(step);
52
- });
53
- }