page-transition 0.1.0-beta.3 → 0.1.0-beta.31
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 +114 -16
- package/dist/components/TransitionLink.d.ts +7 -2
- package/dist/components/TransitionLink.js +3 -2
- package/dist/context/CssTransitionProvider.d.ts +3 -2
- package/dist/context/CssTransitionProvider.js +49 -21
- package/dist/context/TransitionContext.d.ts +3 -2
- package/dist/context/TransitionContext.js +1 -4
- package/dist/functions/checkTransitionStart.d.ts +6 -0
- package/dist/functions/checkTransitionStart.js +15 -0
- package/dist/functions/parseDelay.js +1 -1
- package/dist/functions/parseFirstClipPath.d.ts +1 -0
- package/dist/functions/parseFirstClipPath.js +12 -0
- package/dist/functions/parseFirstOpacity.d.ts +1 -0
- package/dist/functions/parseFirstOpacity.js +8 -0
- package/dist/functions/parseOpacity.js +1 -1
- package/dist/functions/parseProperty.d.ts +1 -0
- package/dist/functions/parseProperty.js +11 -0
- package/dist/functions/pollTransitionStart.d.ts +12 -0
- package/dist/functions/pollTransitionStart.js +11 -0
- package/dist/functions/setDelayReverse.d.ts +7 -0
- package/dist/functions/setDelayReverse.js +13 -0
- package/dist/functions/setPlaybackRate.d.ts +7 -0
- package/dist/functions/setPlaybackRate.js +10 -0
- package/dist/functions/transitionEnd.d.ts +5 -3
- package/dist/functions/transitionEnd.js +9 -8
- package/dist/functions/transitionEndReverse.d.ts +5 -3
- package/dist/functions/transitionEndReverse.js +21 -21
- package/dist/functions/updatePlaybackRate.d.ts +10 -0
- package/dist/functions/updatePlaybackRate.js +51 -0
- package/dist/hooks/useHandleLinkClick.d.ts +9 -3
- package/dist/hooks/useHandleLinkClick.js +70 -18
- package/dist/hooks/usePopState.d.ts +8 -3
- package/dist/hooks/usePopState.js +96 -18
- package/dist/hooks/useTransitionEndData.d.ts +6 -2
- package/dist/hooks/useTransitionEndData.js +6 -4
- package/dist/hooks/useTransitionEndObj.d.ts +6 -2
- package/dist/hooks/useTransitionEndObj.js +4 -2
- package/package.json +1 -1
- package/dist/functions/checkTransitionFinish.d.ts +0 -6
- package/dist/functions/checkTransitionFinish.js +0 -13
- package/dist/functions/parseClipPathAll.d.ts +0 -1
- package/dist/functions/parseClipPathAll.js +0 -20
- package/dist/functions/parseOpacityAll.d.ts +0 -1
- package/dist/functions/parseOpacityAll.js +0 -13
- package/dist/functions/wait.d.ts +0 -2
- package/dist/functions/wait.js +0 -12
package/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
# page-transition
|
|
2
|
-
A page transition library for the Next.js App Router.
|
|
3
|
-
|
|
2
|
+
A page transition library for the Next.js App Router.
|
|
3
|
+
|
|
4
|
+
[](https://simon-schindler.github.io/page-transition-demo/)
|
|
5
|
+
|
|
6
|
+
|
|
4
7
|
## Features
|
|
5
8
|
|
|
6
9
|
- CSS & Manual mode
|
|
7
10
|
- Scroll restoration
|
|
8
11
|
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
## Install
|
|
13
|
+
 
|
|
14
|
+
|
|
15
|
+
`npm install page-transition@beta`
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
14
18
|
Import your page transition styles and wrap your page content with `TransitionProvider` in your root layout.
|
|
15
19
|
|
|
16
20
|
```tsx
|
|
@@ -47,6 +51,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
47
51
|
|---|---|---|
|
|
48
52
|
| transitionProperty | "opacity" \| "clip-path" | "opacity" |
|
|
49
53
|
| overlayCount | number | 0 |
|
|
54
|
+
| mirror | boolean | false |
|
|
50
55
|
|
|
51
56
|
**Prop Descriptions**
|
|
52
57
|
|
|
@@ -57,11 +62,14 @@ Select the transition mode.
|
|
|
57
62
|
The component rendered outside the transition container.
|
|
58
63
|
|
|
59
64
|
**options.transitionProperty**
|
|
60
|
-
Defines which property transitionend waits for.
|
|
61
|
-
|
|
65
|
+
Defines which property transitionend waits for.
|
|
66
|
+
|
|
62
67
|
**options.overlayCount**
|
|
63
68
|
Defines how many overlay items should be created.
|
|
64
69
|
|
|
70
|
+
**options.mirror**
|
|
71
|
+
Creates the same number of items as specified by overlayCount.
|
|
72
|
+
|
|
65
73
|
|
|
66
74
|
```tsx
|
|
67
75
|
<TransitionProvider
|
|
@@ -78,9 +86,16 @@ options={{
|
|
|
78
86
|
### `TransitionLink`
|
|
79
87
|
#### Props
|
|
80
88
|
|
|
81
|
-
|Prop|
|
|
82
|
-
|
|
83
|
-
| href | string | - |
|
|
89
|
+
|Prop|Type|Default|Required
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| href | string | - | Yes |
|
|
92
|
+
| className | string | - | - |
|
|
93
|
+
| scroll | boolean | true | - |
|
|
94
|
+
| prefetch | "auto" \| null | null | - |
|
|
95
|
+
| onClick | (e: React.MouseEvent)=>void | - | - |
|
|
96
|
+
|
|
97
|
+
**Prop Descriptions**
|
|
98
|
+
TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
|
|
84
99
|
|
|
85
100
|
**Description**
|
|
86
101
|
Triggers the transition.
|
|
@@ -102,6 +117,8 @@ After navigation, the `exit` class is removed and the `enter` class is added. On
|
|
|
102
117
|
|
|
103
118
|
For overlay animations, a `.overlay-wrapper` is available. You can add overlay items by setting the `overlayCount` option.
|
|
104
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
|
+
|
|
105
122
|
To access the overlay wrapper and its items, use `useTransitionContext`.
|
|
106
123
|
|
|
107
124
|
```ts
|
|
@@ -196,10 +213,10 @@ overlayCount: 10
|
|
|
196
213
|
background: black;
|
|
197
214
|
transition: none;
|
|
198
215
|
will-change: clip-path;
|
|
199
|
-
clip-path: inset(100%
|
|
216
|
+
clip-path: inset(100% -1px 0 -1px);
|
|
200
217
|
}
|
|
201
218
|
[data-transition].exit .overlay-item{
|
|
202
|
-
clip-path: inset(0
|
|
219
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
203
220
|
transition: clip-path 1.0s ease;
|
|
204
221
|
@for $i from 0 to 10{
|
|
205
222
|
&:nth-child(#{$i+1}){
|
|
@@ -208,7 +225,7 @@ overlayCount: 10
|
|
|
208
225
|
}
|
|
209
226
|
}
|
|
210
227
|
[data-transition].enter .overlay-item{
|
|
211
|
-
clip-path: inset(0
|
|
228
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
212
229
|
transition: clip-path 1.0s ease;
|
|
213
230
|
@for $i from 0 to 10{
|
|
214
231
|
&:nth-child(#{$i+1}){
|
|
@@ -219,11 +236,92 @@ overlayCount: 10
|
|
|
219
236
|
```
|
|
220
237
|
</details>
|
|
221
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
|
+
|
|
222
320
|
### Manual Mode
|
|
223
321
|
|
|
224
322
|
In manual mode, you can control the transition using `useTransitionContext`.
|
|
225
323
|
|
|
226
|
-
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
|
|
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`.
|
|
227
325
|
|
|
228
326
|
|
|
229
327
|
```ts
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
interface Props {
|
|
3
3
|
href: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
prefetch?: boolean;
|
|
6
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
4
7
|
children: ReactNode;
|
|
5
|
-
}
|
|
8
|
+
}
|
|
9
|
+
export declare function TransitionLink({ href, className, prefetch, onClick, children }: Props): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import Link from "next/link";
|
|
3
3
|
import { useTransitionContext } from "../context/TransitionContext";
|
|
4
|
-
export function TransitionLink({ href, children }) {
|
|
4
|
+
export function TransitionLink({ href, className, prefetch, onClick, children }) {
|
|
5
5
|
const { handleLinkClick } = useTransitionContext();
|
|
6
6
|
return (_jsx(Link, { href: href, onClick: (e) => {
|
|
7
7
|
handleLinkClick.current(e, href);
|
|
8
|
-
|
|
8
|
+
onClick?.(e);
|
|
9
|
+
}, className: className, prefetch: prefetch, children: children }));
|
|
9
10
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
interface TransitionOptions {
|
|
3
|
-
transitionProperty
|
|
4
|
-
overlayCount
|
|
3
|
+
transitionProperty?: 'opacity' | 'clip-path';
|
|
4
|
+
overlayCount?: number;
|
|
5
|
+
mirror?: boolean;
|
|
5
6
|
}
|
|
6
7
|
interface ProviderProps {
|
|
7
8
|
header?: ReactNode;
|
|
@@ -11,29 +11,35 @@ import { useHandleLinkClick } from "../hooks/useHandleLinkClick";
|
|
|
11
11
|
import { useScrollRestoration } from "../hooks/useScrollRestoration";
|
|
12
12
|
import { usePopState } from "../hooks/usePopState";
|
|
13
13
|
import { parseDelay } from "../functions/parseDelay";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
15
|
+
export function CssTransitionProvider({ header, options, children }) {
|
|
16
|
+
const defaultOptions = {
|
|
17
|
+
transitionProperty: 'opacity',
|
|
18
|
+
overlayCount: 0,
|
|
19
|
+
mirror: false,
|
|
20
|
+
...options
|
|
21
|
+
};
|
|
18
22
|
const container = useRef(null);
|
|
19
23
|
const overlayWrapper = useRef(null);
|
|
20
24
|
const overlayItems = useRef([]);
|
|
25
|
+
const mirrorItems = useRef([]);
|
|
21
26
|
const pathname = usePathname();
|
|
22
27
|
const currentPathname = useRef(pathname);
|
|
23
|
-
const resolveUseFn = useRef(null);
|
|
24
28
|
const mount = useRef({
|
|
25
29
|
mounted: false,
|
|
26
30
|
initPathname: pathname
|
|
27
31
|
});
|
|
28
32
|
const state = useRef('idle');
|
|
33
|
+
const basePath = useRef(null);
|
|
29
34
|
const useUse = useRef(false);
|
|
35
|
+
const resolveUseFn = useRef(null);
|
|
30
36
|
const reverse = useRef({
|
|
31
37
|
_lock: true,
|
|
32
38
|
get lock() {
|
|
33
39
|
return this._lock;
|
|
34
40
|
},
|
|
35
41
|
set lock(value) {
|
|
36
|
-
if (
|
|
42
|
+
if (delayStep.current === 0 || overlayItems.current.length < 2) {
|
|
37
43
|
if (this._lock === false)
|
|
38
44
|
this._lock = true;
|
|
39
45
|
return;
|
|
@@ -41,13 +47,18 @@ export function CssTransitionProvider({ header, options = {
|
|
|
41
47
|
this._lock = value;
|
|
42
48
|
}
|
|
43
49
|
});
|
|
44
|
-
const
|
|
50
|
+
const delayStep = useRef(null);
|
|
45
51
|
const handleLinkClick = useRef(() => { });
|
|
46
52
|
const transitionEndHandler = useTransitionEndHandler();
|
|
47
53
|
const transitionEndData = useTransitionEndData({
|
|
48
|
-
elArray:
|
|
49
|
-
transitionProperty:
|
|
54
|
+
elArray: defaultOptions.overlayCount === 0 ? container : overlayItems,
|
|
55
|
+
transitionProperty: defaultOptions.transitionProperty,
|
|
56
|
+
mirror: defaultOptions.mirror,
|
|
57
|
+
mirrorElArray: mirrorItems
|
|
50
58
|
});
|
|
59
|
+
const pollRafId = useRef(null);
|
|
60
|
+
const rafId = useRef(null);
|
|
61
|
+
const rejectFn = useRef(null);
|
|
51
62
|
usePopState({
|
|
52
63
|
container,
|
|
53
64
|
currentPathname,
|
|
@@ -55,9 +66,12 @@ export function CssTransitionProvider({ header, options = {
|
|
|
55
66
|
transitionEndHandler,
|
|
56
67
|
state,
|
|
57
68
|
reverse,
|
|
58
|
-
|
|
69
|
+
delayStep,
|
|
59
70
|
useUse,
|
|
60
|
-
resolveUseFn
|
|
71
|
+
resolveUseFn,
|
|
72
|
+
pollRafId,
|
|
73
|
+
rafId,
|
|
74
|
+
rejectFn
|
|
61
75
|
});
|
|
62
76
|
useHandleLinkClick({
|
|
63
77
|
container,
|
|
@@ -67,9 +81,13 @@ export function CssTransitionProvider({ header, options = {
|
|
|
67
81
|
transitionEndHandler,
|
|
68
82
|
state,
|
|
69
83
|
reverse,
|
|
70
|
-
|
|
84
|
+
delayStep,
|
|
71
85
|
useUse,
|
|
72
|
-
resolveUseFn
|
|
86
|
+
resolveUseFn,
|
|
87
|
+
basePath,
|
|
88
|
+
pollRafId,
|
|
89
|
+
rafId,
|
|
90
|
+
rejectFn
|
|
73
91
|
});
|
|
74
92
|
useScrollRestoration();
|
|
75
93
|
const removeEnter = useTransitionEndObj({
|
|
@@ -83,11 +101,13 @@ export function CssTransitionProvider({ header, options = {
|
|
|
83
101
|
useEffect(() => {
|
|
84
102
|
if (mount.current.mounted === false &&
|
|
85
103
|
mount.current.initPathname === pathname) {
|
|
104
|
+
currentPathname.current = window.location.pathname;
|
|
105
|
+
basePath.current = window.location.pathname.slice(0, -pathname.length);
|
|
86
106
|
return;
|
|
87
107
|
}
|
|
88
108
|
mount.current.mounted = true;
|
|
89
|
-
if (
|
|
90
|
-
|
|
109
|
+
if (delayStep.current === null && defaultOptions.overlayCount > 1) {
|
|
110
|
+
delayStep.current = parseDelay(transitionEndData.current.elArray);
|
|
91
111
|
}
|
|
92
112
|
if (!container.current)
|
|
93
113
|
return;
|
|
@@ -95,16 +115,24 @@ export function CssTransitionProvider({ header, options = {
|
|
|
95
115
|
transitionEndObj: removeEnter,
|
|
96
116
|
transitionEndHandler,
|
|
97
117
|
reverse,
|
|
98
|
-
|
|
118
|
+
delayStep
|
|
99
119
|
});
|
|
100
120
|
container.current.classList.remove('exit');
|
|
101
121
|
container.current.classList.add('enter');
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
pollTransitionStart({
|
|
123
|
+
transitionEndData,
|
|
124
|
+
id: pollRafId,
|
|
125
|
+
fn: () => {
|
|
126
|
+
state.current = 'entering';
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
currentPathname.current = window.location.pathname;
|
|
104
130
|
reverse.current.lock = false;
|
|
105
131
|
}, [pathname]);
|
|
106
132
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
107
|
-
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [
|
|
108
|
-
|
|
109
|
-
|
|
133
|
+
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 > 0 && Array.from({ length: defaultOptions.overlayCount }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
134
|
+
overlayItems.current[i] = el;
|
|
135
|
+
}, className: "overlay-item" }, i))), defaultOptions.mirror && Array.from({ length: defaultOptions.overlayCount }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
136
|
+
mirrorItems.current[i] = el;
|
|
137
|
+
}, className: "mirror-item" }, `mirror${i}`)))] }), children] })] }));
|
|
110
138
|
}
|
|
@@ -11,8 +11,9 @@ export declare function useTransitionContext(): ContextProps;
|
|
|
11
11
|
type Mode = 'css' | 'manual';
|
|
12
12
|
type TransitionProperty = 'opacity' | 'clip-path';
|
|
13
13
|
interface TransitionOptions {
|
|
14
|
-
transitionProperty
|
|
15
|
-
overlayCount
|
|
14
|
+
transitionProperty?: TransitionProperty;
|
|
15
|
+
overlayCount?: number;
|
|
16
|
+
mirror?: boolean;
|
|
16
17
|
}
|
|
17
18
|
interface ProviderProps {
|
|
18
19
|
header?: ReactNode;
|
|
@@ -10,10 +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
|
|
14
|
-
transitionProperty: 'opacity',
|
|
15
|
-
overlayCount: 0
|
|
16
|
-
}, children, }) {
|
|
13
|
+
export function TransitionProvider({ header, mode = 'css', options, children, }) {
|
|
17
14
|
return (mode === 'css' ?
|
|
18
15
|
_jsx(CssTransitionProvider, { header: header, options: options, children: children }) :
|
|
19
16
|
_jsx(ManualTransitionProvider, { children: children }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseFirstOpacity } from "./parseFirstOpacity";
|
|
2
|
+
import { parseFirstClipPath } from "./parseFirstClipPath";
|
|
3
|
+
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]()) {
|
|
9
|
+
fn?.();
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseFirstClipPath(elArray: (HTMLDivElement | null)[]): null | boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseFirstOpacity(elArray: (HTMLDivElement | null)[]): null | boolean;
|
|
@@ -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,12 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
interface TransitionEndData {
|
|
3
|
+
elArray: (HTMLDivElement | null)[];
|
|
4
|
+
transitionProperty: 'opacity' | 'clip-path';
|
|
5
|
+
}
|
|
6
|
+
interface Props {
|
|
7
|
+
id: RefObject<number | null>;
|
|
8
|
+
fn: () => void;
|
|
9
|
+
transitionEndData: RefObject<TransitionEndData>;
|
|
10
|
+
}
|
|
11
|
+
export declare function pollTransitionStart({ id, fn, transitionEndData }: Props): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { checkTransitionStart } from "./checkTransitionStart";
|
|
2
|
+
export function pollTransitionStart({ id, fn, transitionEndData }) {
|
|
3
|
+
if (id.current !== null)
|
|
4
|
+
cancelAnimationFrame(id.current);
|
|
5
|
+
id.current = requestAnimationFrame(() => {
|
|
6
|
+
if (checkTransitionStart(transitionEndData.current, fn)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
pollTransitionStart({ id, fn, transitionEndData });
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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.updatePlaybackRate(value);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
2
|
interface TransitionEndObj {
|
|
3
3
|
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
|
|
4
|
+
transitionProperty: '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
|
-
|
|
20
|
+
delayStep: RefObject<number | null>;
|
|
19
21
|
}
|
|
20
|
-
export declare function transitionEnd({ transitionEndObj, transitionEndHandler, reverse,
|
|
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,
|
|
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
|
-
|
|
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 (
|
|
21
|
-
e.propertyName !==
|
|
21
|
+
if (endObj.transitionProperty &&
|
|
22
|
+
e.propertyName !== endObj.transitionProperty)
|
|
22
23
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
endObj.elArray[lastIndex]?.removeEventListener('transitionend', handler);
|
|
25
|
+
endObj.fn?.();
|
|
25
26
|
};
|
|
26
27
|
transitionEndHandler.current.handler = handler;
|
|
27
|
-
transitionEndHandler.current.handlerEl =
|
|
28
|
-
|
|
28
|
+
transitionEndHandler.current.handlerEl = endObj.elArray[lastIndex];
|
|
29
|
+
endObj.elArray[lastIndex]?.addEventListener('transitionend', transitionEndHandler.current.handler);
|
|
29
30
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
2
|
interface TransitionEndObj {
|
|
3
3
|
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
|
|
4
|
+
transitionProperty: '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
|
-
|
|
20
|
+
delayStep: RefObject<number | null>;
|
|
19
21
|
}
|
|
20
|
-
export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse,
|
|
22
|
+
export declare function transtionEndReverse({ transitionEndObj, transitionEndHandler, reverse, delayStep }: Props): void;
|
|
21
23
|
export {};
|