page-transition 0.1.0-beta.46 → 0.1.0-beta.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@ A page transition library for the Next.js App Router.
10
10
  - Scroll restoration
11
11
 
12
12
  ## Install
13
- ![Version](https://img.shields.io/badge/v_0.1.0--beta.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
 
@@ -59,7 +59,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
59
59
  Select the transition mode.
60
60
 
61
61
  **header**
62
- The component rendered outside the transition container.
62
+ The component rendered outside the .page-wrapper.
63
63
 
64
64
  **options.transitionProperty**
65
65
  Defines which property transitionend waits for.
@@ -100,8 +100,9 @@ options={{
100
100
  TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
101
101
 
102
102
  **Description**
103
- Triggers the transition.
103
+ Triggers the transition.
104
104
 
105
+ *Must be used within the TransitionProvider*
105
106
 
106
107
  ```tsx
107
108
  <TransitionLink href={"/home"}>
@@ -111,13 +112,14 @@ Triggers the transition.
111
112
 
112
113
  ### CSS Mode
113
114
 
114
- 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.
115
116
 
116
117
  Once the transition ends, the scroll position is restored and navigation is performed.
117
118
 
118
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.
119
120
 
120
- 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/>
121
123
  <br/>
122
124
  To access the overlay wrapper and its items, use `useTransitionContext`.
123
125
 
@@ -140,16 +142,16 @@ transitionProperty: "opacity"
140
142
  ```
141
143
 
142
144
  ```css
143
- [data-transition]{
145
+ [data-transition] .page-wrapper{
144
146
  will-change: opacity;
145
147
  opacity: 1;
146
148
  }
147
- [data-transition].exit{
149
+ [data-transition].exit .page-wrapper{
148
150
  opacity: 0;
149
151
  transition: opacity 0.4s ease;
150
152
 
151
153
  }
152
- [data-transition].enter{
154
+ [data-transition].enter .page-wrapper{
153
155
  opacity: 1;
154
156
  transition: opacity 0.5s ease;
155
157
  }
@@ -167,8 +169,20 @@ items: [1, 0]
167
169
  ```
168
170
 
169
171
  ```css
172
+ [data-transition] .page-wrapper{
173
+ opacity: 1;
174
+ transition: opacity 0.5s linear;
175
+ }
176
+ [data-transition].exit .page-wrapper{
177
+ opacity: 0;
178
+ }
179
+ [data-transition].enter .page-wrapper{
180
+ opacity: 1;
181
+ }
182
+
170
183
  [data-transition] .overlay-wrapper{
171
184
  position: fixed;
185
+ z-index: 99;
172
186
  inset: 0;
173
187
 
174
188
  display: grid;
@@ -316,6 +330,7 @@ items: [10, 10]
316
330
  ```
317
331
  </details>
318
332
 
333
+
319
334
  ### Manual Mode
320
335
 
321
336
  In manual mode, you can control the transition using `useTransitionContext`.
@@ -17,6 +17,7 @@ export function CssTransitionProvider({ header, options, children }) {
17
17
  ...options
18
18
  };
19
19
  const container = useRef(null);
20
+ const pageWrapper = useRef(null);
20
21
  const overlayWrapper = useRef(null);
21
22
  const overlayItems = useRef([]);
22
23
  const secondItems = useRef([]);
@@ -33,7 +34,7 @@ export function CssTransitionProvider({ header, options, children }) {
33
34
  const handleLinkClick = useRef(() => { });
34
35
  const transitionEndHandler = useTransitionEndHandler();
35
36
  const transitionEndData = useTransitionEndData({
36
- elArray: defaultOptions.items[0] === 0 ? container : overlayItems,
37
+ elArray: defaultOptions.items[0] === 0 ? pageWrapper : overlayItems,
37
38
  transitionProperty: defaultOptions.transitionProperty,
38
39
  secondElArray: secondItems
39
40
  });
@@ -94,9 +95,9 @@ export function CssTransitionProvider({ header, options, children }) {
94
95
  currentPathname.current = window.location.pathname;
95
96
  }, [pathname]);
96
97
  const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
97
- 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) => {
98
- overlayItems.current[i] = el;
99
- }, className: "overlay-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
100
- secondItems.current[i] = el;
101
- }, 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 })] }) }));
102
103
  }
@@ -20,5 +20,5 @@ interface ProviderProps {
20
20
  options: TransitionOptions;
21
21
  children: ReactNode;
22
22
  }
23
- 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;
24
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 }));
@@ -7,11 +7,12 @@ export function transitionRunning(elArray, transitionProperty) {
7
7
  'transform': 'transform'
8
8
  };
9
9
  if (elArray[0].getAnimations().some((obj) => {
10
+ const progress = obj.effect?.getComputedTiming().progress;
10
11
  return obj.playState === 'running' &&
11
12
  obj.effect instanceof KeyframeEffect &&
12
13
  obj.effect.getKeyframes().some(frame => {
13
14
  return frame[property[transitionProperty]] !== undefined;
14
- });
15
+ }) && progress != null && progress !== 0;
15
16
  })) {
16
17
  return true;
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-transition",
3
- "version": "0.1.0-beta.46",
3
+ "version": "0.1.0-beta.48",
4
4
  "description": "A page transition library for the Next.js App Router.",
5
5
  "license": "MIT",
6
6
  "files": [