page-transition 0.1.0-beta.6 → 0.1.0-beta.60

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