page-transition 0.0.0-stage → 0.1.0-beta.10

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -2
  3. package/dist/components/TransitionLink.d.ts +10 -0
  4. package/dist/components/TransitionLink.js +10 -0
  5. package/dist/context/CssTransitionProvider.d.ts +12 -0
  6. package/dist/context/CssTransitionProvider.js +120 -0
  7. package/dist/context/ManualTransitionProvider.d.ts +6 -0
  8. package/dist/context/ManualTransitionProvider.js +33 -0
  9. package/dist/context/TransitionContext.d.ts +24 -0
  10. package/dist/context/TransitionContext.js +17 -0
  11. package/dist/functions/checkTransitionFinish.d.ts +6 -0
  12. package/dist/functions/checkTransitionFinish.js +13 -0
  13. package/dist/functions/checkTransitionStart.d.ts +6 -0
  14. package/dist/functions/checkTransitionStart.js +15 -0
  15. package/dist/functions/debounce.d.ts +11 -0
  16. package/dist/functions/debounce.js +8 -0
  17. package/dist/functions/parseClipPath.d.ts +1 -0
  18. package/dist/functions/parseClipPath.js +9 -0
  19. package/dist/functions/parseClipPathAll.d.ts +1 -0
  20. package/dist/functions/parseClipPathAll.js +20 -0
  21. package/dist/functions/parseDelay.d.ts +1 -0
  22. package/dist/functions/parseDelay.js +10 -0
  23. package/dist/functions/parseOpacity.d.ts +1 -0
  24. package/dist/functions/parseOpacity.js +6 -0
  25. package/dist/functions/parseOpacityAll.d.ts +1 -0
  26. package/dist/functions/parseOpacityAll.js +13 -0
  27. package/dist/functions/pollTransitionStart.d.ts +12 -0
  28. package/dist/functions/pollTransitionStart.js +9 -0
  29. package/dist/functions/resetDelay.d.ts +1 -0
  30. package/dist/functions/resetDelay.js +7 -0
  31. package/dist/functions/transitionEnd.d.ts +21 -0
  32. package/dist/functions/transitionEnd.js +29 -0
  33. package/dist/functions/transitionEndReverse.d.ts +21 -0
  34. package/dist/functions/transitionEndReverse.js +36 -0
  35. package/dist/functions/wait.d.ts +2 -0
  36. package/dist/functions/wait.js +12 -0
  37. package/dist/hooks/manual/useHandleLinkClick.d.ts +10 -0
  38. package/dist/hooks/manual/useHandleLinkClick.js +17 -0
  39. package/dist/hooks/manual/usePopState.d.ts +9 -0
  40. package/dist/hooks/manual/usePopState.js +23 -0
  41. package/dist/hooks/useHandleLinkClick.d.ts +26 -0
  42. package/dist/hooks/useHandleLinkClick.js +99 -0
  43. package/dist/hooks/usePopState.d.ts +25 -0
  44. package/dist/hooks/usePopState.js +107 -0
  45. package/dist/hooks/useScrollRestoration.d.ts +1 -0
  46. package/dist/hooks/useScrollRestoration.js +26 -0
  47. package/dist/hooks/useTransitionEndData.d.ts +11 -0
  48. package/dist/hooks/useTransitionEndData.js +17 -0
  49. package/dist/hooks/useTransitionEndHandler.d.ts +7 -0
  50. package/dist/hooks/useTransitionEndHandler.js +9 -0
  51. package/dist/hooks/useTransitionEndObj.d.ts +16 -0
  52. package/dist/hooks/useTransitionEndObj.js +15 -0
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.js +3 -0
  55. package/package.json +23 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Simon Schindler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,243 @@
1
- # Temporary Holding Version
1
+ # page-transition
2
+ A page transition library for the Next.js App Router.
3
+
4
+ [🌐 Live Demo](https://simon-schindler.github.io/page-transition-demo/)
2
5
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
6
+ ## Features
7
+
8
+ - CSS & Manual mode
9
+ - Scroll restoration
10
+
11
+ ## Install
12
+
13
+ `npm install page-transition@beta`
14
+
15
+ ## Usage
16
+ Import your page transition styles and wrap your page content with `TransitionProvider` in your root layout.
17
+
18
+ ```tsx
19
+ import { TransitionProvider } from "page-transition"
20
+ import '.../your-page-transition-styles.css'
21
+
22
+ export default function RootLayout({ children }: LayoutProps<"/">) {
23
+ return (
24
+ <html lang="en">
25
+ <body>
26
+ <TransitionProvider>
27
+ {children}
28
+ </TransitionProvider>
29
+ </body>
30
+ </html>
31
+ );
32
+ }
33
+ ```
34
+
35
+ ## Components
36
+
37
+ ### `TransitionProvider`
38
+ #### Props
39
+
40
+ |Prop|Type|Default|Mode|
41
+ |---|---|---|---|
42
+ | mode | "css" \| "manual" | "css" | Both |
43
+ | header | JSX | - | CSS |
44
+ | options | *Options* | {} | CSS |
45
+
46
+ *Options*
47
+
48
+ | Option | Type | Default |
49
+ |---|---|---|
50
+ | transitionProperty | "opacity" \| "clip-path" | "opacity" |
51
+ | overlayCount | number | 0 |
52
+
53
+ **Prop Descriptions**
54
+
55
+ **mode**
56
+ Select the transition mode.
57
+
58
+ **header**
59
+ The component rendered outside the transition container.
60
+
61
+ **options.transitionProperty**
62
+ Defines which property transitionend waits for.
63
+
64
+ **options.overlayCount**
65
+ Defines how many overlay items should be created.
66
+
67
+
68
+ ```tsx
69
+ <TransitionProvider
70
+ header={<Header/>}
71
+ options={{
72
+ transitionProperty: "clip-path",
73
+ overlayCount: 1
74
+ }}
75
+ >
76
+ {children}
77
+ </TransitionProvider>
78
+ ```
79
+
80
+ ### `TransitionLink`
81
+ #### Props
82
+
83
+ |Prop|Type|Default|Required
84
+ |---|---|---|---|
85
+ | href | string | - | Yes |
86
+ | className | string | - | - |
87
+ | scroll | boolean | true | - |
88
+ | prefetch | "auto" \| null | null | - |
89
+ | onClick | (e: React.MouseEvent)=>void | - | - |
90
+
91
+ **Prop Descriptions**
92
+ TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
93
+
94
+ **Description**
95
+ Triggers the transition.
96
+
97
+
98
+ ```tsx
99
+ <TransitionLink href={"/home"}>
100
+ Home
101
+ </TransitionLink>
102
+ ```
103
+
104
+ ### CSS Mode
105
+
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.
107
+
108
+ Once the transition ends, navigation is performed and the scroll position is restored using window.history.state.scrollY.
109
+
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.
111
+
112
+ For overlay animations, a `.overlay-wrapper` is available. You can add overlay items by setting the `overlayCount` option.
113
+
114
+ To access the overlay wrapper and its items, use `useTransitionContext`.
115
+
116
+ ```ts
117
+ import { useTransitionContext } from "page-transition"
118
+
119
+ const {overlayWrapper, overlayItems} = useTransitionContext()
120
+
121
+ ```
122
+
123
+ #### CSS/SCSS Examples
124
+ <details>
125
+ <summary>Opacity</summary>
126
+ <br/>
127
+ options
128
+
129
+ ```ts
130
+ transitionProperty: "opacity"
131
+ overlayCount: 0
132
+ ```
133
+
134
+ ```css
135
+ [data-transition]{
136
+ will-change: opacity;
137
+ opacity: 1;
138
+ }
139
+ [data-transition].exit{
140
+ opacity: 0;
141
+ transition: opacity 0.4s ease;
142
+
143
+ }
144
+ [data-transition].enter{
145
+ opacity: 1;
146
+ transition: opacity 0.5s ease;
147
+ }
148
+ ```
149
+ </details>
150
+
151
+ <details>
152
+ <summary>Single Overlay</summary>
153
+ <br/>
154
+ options
155
+
156
+ ```ts
157
+ transitionProperty: "clip-path"
158
+ overlayCount: 1
159
+ ```
160
+
161
+ ```css
162
+ [data-transition] .overlay-wrapper{
163
+ position: fixed;
164
+ inset: 0;
165
+
166
+ display: grid;
167
+ grid-template-columns: 1fr;
168
+ }
169
+ [data-transition] .overlay-item{
170
+ background: black;
171
+ transition: none;
172
+ will-change: clip-path;
173
+ clip-path: inset(100% 0 0 0);
174
+ }
175
+ [data-transition].exit .overlay-item{
176
+ clip-path: inset(0 0 0 0);
177
+ transition: clip-path 1.2s ease;
178
+ }
179
+ [data-transition].enter .overlay-item{
180
+ clip-path: inset(0 0 100% 0);
181
+ transition: clip-path 1.2s ease;
182
+ }
183
+ ```
184
+ </details>
185
+
186
+ <details>
187
+ <summary>Staggered Overlays</summary>
188
+ <br/>
189
+ options
190
+
191
+ ```ts
192
+ transitionProperty: "clip-path"
193
+ overlayCount: 10
194
+ ```
195
+
196
+ ```scss
197
+ [data-transition] .overlay-wrapper{
198
+ position: fixed;
199
+ inset: 0;
200
+
201
+ display: grid;
202
+ grid-template-columns: repeat(10, 1fr);
203
+ }
204
+ [data-transition] .overlay-item{
205
+ background: black;
206
+ transition: none;
207
+ will-change: clip-path;
208
+ clip-path: inset(100% -1px 0 -1px);
209
+ }
210
+ [data-transition].exit .overlay-item{
211
+ clip-path: inset(0 -1px 0 -1px);
212
+ transition: clip-path 1.0s ease;
213
+ @for $i from 0 to 10{
214
+ &:nth-child(#{$i+1}){
215
+ transition-delay: $i * 0.2s;
216
+ }
217
+ }
218
+ }
219
+ [data-transition].enter .overlay-item{
220
+ clip-path: inset(0 -1px 100% -1px);
221
+ transition: clip-path 1.0s ease;
222
+ @for $i from 0 to 10{
223
+ &:nth-child(#{$i+1}){
224
+ transition-delay: $i * 0.2s;
225
+ }
226
+ }
227
+ }
228
+ ```
229
+ </details>
230
+
231
+ ### Manual Mode
232
+
233
+ In manual mode, you can control the transition using `useTransitionContext`.
234
+
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`.
236
+
237
+
238
+ ```ts
239
+ import { useTransitionContext } from "page-transition"
240
+
241
+ const { resolveFn, state } = useTransitionContext()
242
+
243
+ ```
@@ -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/TransitionContext";
4
+ export function TransitionLink({ href, className, prefetch, onClick, children }) {
5
+ const { handleLinkClick } = useTransitionContext();
6
+ return (_jsx(Link, { href: href, onClick: (e) => {
7
+ handleLinkClick.current(e, href);
8
+ onClick?.(e);
9
+ }, className: className, prefetch: prefetch, children: children }));
10
+ }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from "react";
2
+ interface TransitionOptions {
3
+ transitionProperty?: 'opacity' | 'clip-path';
4
+ overlayCount?: number;
5
+ }
6
+ interface ProviderProps {
7
+ header?: ReactNode;
8
+ options?: TransitionOptions;
9
+ children: ReactNode;
10
+ }
11
+ export declare function CssTransitionProvider({ header, options, children }: ProviderProps): import("react").JSX.Element;
12
+ export {};
@@ -0,0 +1,120 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { TransitionContext } from "./TransitionContext";
4
+ import { useRef, useMemo, useEffect } from "react";
5
+ import { usePathname } from "next/navigation";
6
+ import { useTransitionEndHandler } from "../hooks/useTransitionEndHandler";
7
+ import { useTransitionEndData } from "../hooks/useTransitionEndData";
8
+ import { useTransitionEndObj } from "../hooks/useTransitionEndObj";
9
+ import { transitionEnd } from "../functions/transitionEnd";
10
+ import { useHandleLinkClick } from "../hooks/useHandleLinkClick";
11
+ import { useScrollRestoration } from "../hooks/useScrollRestoration";
12
+ import { usePopState } from "../hooks/usePopState";
13
+ import { parseDelay } from "../functions/parseDelay";
14
+ import { pollTransitionStart } from "../functions/pollTransitionStart";
15
+ export function CssTransitionProvider({ header, options, children }) {
16
+ const defaultOptions = {
17
+ transitionProperty: 'opacity',
18
+ overlayCount: 0,
19
+ ...options
20
+ };
21
+ const container = useRef(null);
22
+ const overlayWrapper = useRef(null);
23
+ const overlayItems = useRef([]);
24
+ const pathname = usePathname();
25
+ const currentPathname = useRef(pathname);
26
+ const mount = useRef({
27
+ mounted: false,
28
+ initPathname: pathname
29
+ });
30
+ const state = useRef('idle');
31
+ const useUse = useRef(false);
32
+ 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
+ const handleLinkClick = useRef(() => { });
49
+ const transitionEndHandler = useTransitionEndHandler();
50
+ const transitionEndData = useTransitionEndData({
51
+ elArray: defaultOptions.overlayCount === 0 ? container : overlayItems,
52
+ transitionProperty: defaultOptions.transitionProperty
53
+ });
54
+ const pollRafId = useRef(null);
55
+ usePopState({
56
+ container,
57
+ currentPathname,
58
+ transitionEndData,
59
+ transitionEndHandler,
60
+ state,
61
+ reverse,
62
+ delay,
63
+ useUse,
64
+ resolveUseFn
65
+ });
66
+ useHandleLinkClick({
67
+ container,
68
+ handleLinkClick,
69
+ currentPathname,
70
+ transitionEndData,
71
+ transitionEndHandler,
72
+ state,
73
+ reverse,
74
+ delay,
75
+ useUse,
76
+ resolveUseFn
77
+ });
78
+ useScrollRestoration();
79
+ const removeEnter = useTransitionEndObj({
80
+ transitionEndData,
81
+ fn: () => {
82
+ container.current?.classList.remove('enter');
83
+ state.current = 'idle';
84
+ reverse.current.lock = true;
85
+ }
86
+ });
87
+ useEffect(() => {
88
+ if (mount.current.mounted === false &&
89
+ mount.current.initPathname === pathname) {
90
+ return;
91
+ }
92
+ mount.current.mounted = true;
93
+ if (delay.current === null) {
94
+ delay.current = parseDelay(transitionEndData.current.elArray);
95
+ }
96
+ if (!container.current)
97
+ return;
98
+ transitionEnd({
99
+ transitionEndObj: removeEnter,
100
+ transitionEndHandler,
101
+ reverse,
102
+ delay
103
+ });
104
+ container.current.classList.remove('exit');
105
+ container.current.classList.add('enter');
106
+ pollTransitionStart({
107
+ transitionEndData,
108
+ id: pollRafId,
109
+ fn: () => {
110
+ state.current = 'entering';
111
+ }
112
+ });
113
+ currentPathname.current = pathname;
114
+ reverse.current.lock = false;
115
+ }, [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] })] }));
120
+ }
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from "react";
2
+ interface ProviderProps {
3
+ children: ReactNode;
4
+ }
5
+ export declare function ManualTransitionProvider({ children }: ProviderProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { TransitionContext } from "./TransitionContext";
4
+ import { useEffect, useRef, useMemo } from "react";
5
+ import { usePathname } from "next/navigation";
6
+ import { usePopState } from "../hooks/manual/usePopState";
7
+ import { useHandleLinkClick } from "../hooks/manual/useHandleLinkClick";
8
+ export function ManualTransitionProvider({ children }) {
9
+ const pathname = usePathname();
10
+ const handleLinkClick = useRef(() => { });
11
+ const resolveFn = useRef(null);
12
+ const state = useRef('idle');
13
+ const useUse = useRef(false);
14
+ const resolveUseFn = useRef(null);
15
+ usePopState({
16
+ resolveFn,
17
+ state,
18
+ useUse,
19
+ resolveUseFn
20
+ });
21
+ useHandleLinkClick({
22
+ handleLinkClick,
23
+ resolveFn,
24
+ state,
25
+ useUse,
26
+ resolveUseFn
27
+ });
28
+ useEffect(() => {
29
+ state.current = 'entering';
30
+ }, [pathname]);
31
+ const value = useMemo(() => ({ handleLinkClick, resolveFn, state }), []);
32
+ return (_jsx(TransitionContext.Provider, { value: value, children: children }));
33
+ }
@@ -0,0 +1,24 @@
1
+ import type { ReactNode, RefObject } from "react";
2
+ interface ContextProps {
3
+ handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
4
+ overlayWrapper?: RefObject<HTMLDivElement | null>;
5
+ overlayItems?: RefObject<(HTMLDivElement | null)[]>;
6
+ resolveFn?: RefObject<(() => void) | null>;
7
+ state?: RefObject<'idle' | 'exiting' | 'entering'>;
8
+ }
9
+ export declare const TransitionContext: import("react").Context<ContextProps | null>;
10
+ export declare function useTransitionContext(): ContextProps;
11
+ type Mode = 'css' | 'manual';
12
+ type TransitionProperty = 'opacity' | 'clip-path';
13
+ interface TransitionOptions {
14
+ transitionProperty?: TransitionProperty;
15
+ overlayCount?: number;
16
+ }
17
+ interface ProviderProps {
18
+ header?: ReactNode;
19
+ mode?: Mode;
20
+ options?: TransitionOptions;
21
+ children: ReactNode;
22
+ }
23
+ export declare function TransitionProvider({ header, mode, options, children, }: ProviderProps): import("react").JSX.Element;
24
+ export {};
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext } from "react";
4
+ import { CssTransitionProvider } from "./CssTransitionProvider";
5
+ import { ManualTransitionProvider } from "./ManualTransitionProvider";
6
+ export const TransitionContext = createContext(null);
7
+ export function useTransitionContext() {
8
+ const context = useContext(TransitionContext);
9
+ if (!context)
10
+ throw new Error('useTransitionContext in Provider!');
11
+ return context;
12
+ }
13
+ export function TransitionProvider({ header, mode = 'css', options, children, }) {
14
+ return (mode === 'css' ?
15
+ _jsx(CssTransitionProvider, { header: header, options: options, children: children }) :
16
+ _jsx(ManualTransitionProvider, { children: children }));
17
+ }
@@ -0,0 +1,6 @@
1
+ interface TransitionEndData {
2
+ elArray: (HTMLDivElement | null)[];
3
+ propertyName: 'opacity' | 'clip-path';
4
+ }
5
+ export declare function checkTransitionFinish(transitionEndData: TransitionEndData, fn: (() => void) | null): boolean;
6
+ export {};
@@ -0,0 +1,13 @@
1
+ import { parseOpacityAll } from "./parseOpacityAll";
2
+ import { parseClipPathAll } from "./parseClipPathAll";
3
+ export function checkTransitionFinish(transitionEndData, fn) {
4
+ const parse = {
5
+ 'opacity': () => parseOpacityAll(transitionEndData.elArray),
6
+ 'clip-path': () => parseClipPathAll(transitionEndData.elArray)
7
+ };
8
+ if (parse[transitionEndData.propertyName]()) {
9
+ fn?.();
10
+ return true;
11
+ }
12
+ return false;
13
+ }
@@ -0,0 +1,6 @@
1
+ interface TransitionEndData {
2
+ elArray: (HTMLDivElement | null)[];
3
+ propertyName: 'opacity' | 'clip-path';
4
+ }
5
+ export declare function checkTransitionStart(transitionEndData: TransitionEndData, fn: (() => void) | null): boolean;
6
+ export {};
@@ -0,0 +1,15 @@
1
+ import { parseOpacityAll } from "./parseOpacityAll";
2
+ import { parseClipPathAll } from "./parseClipPathAll";
3
+ export function checkTransitionStart(transitionEndData, fn) {
4
+ const parse = {
5
+ 'opacity': () => parseOpacityAll(transitionEndData.elArray),
6
+ 'clip-path': () => parseClipPathAll(transitionEndData.elArray)
7
+ };
8
+ if (parse[transitionEndData.propertyName]()) {
9
+ return false;
10
+ }
11
+ else {
12
+ fn?.();
13
+ return true;
14
+ }
15
+ }
@@ -0,0 +1,11 @@
1
+ import type { RefObject } from "react";
2
+ interface Obj {
3
+ timeOutId: number | null;
4
+ fn: () => void;
5
+ ms?: number;
6
+ }
7
+ interface Props {
8
+ ref: RefObject<Obj>;
9
+ }
10
+ export declare function debounce({ ref }: Props): void;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ export function debounce({ ref }) {
2
+ if (ref.current.timeOutId !== null) {
3
+ window.clearTimeout(ref.current.timeOutId);
4
+ }
5
+ ref.current.timeOutId = window.setTimeout(() => {
6
+ ref.current.fn();
7
+ }, ref.current.ms ?? 200);
8
+ }
@@ -0,0 +1 @@
1
+ export declare function parseClipPath(el: HTMLDivElement | null): number | null;
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1 @@
1
+ export declare function parseClipPathAll(elArray: (HTMLDivElement | null)[]): null | boolean;
@@ -0,0 +1,20 @@
1
+ export function parseClipPathAll(elArray) {
2
+ if (elArray.length === 0)
3
+ return null;
4
+ const array = [];
5
+ elArray.forEach((el) => {
6
+ if (!el)
7
+ return;
8
+ const clipPath = getComputedStyle(el).clipPath;
9
+ const m = clipPath.match(/inset\(([^)]+)\)/);
10
+ const result = m?.[1]?.split(/\s+/) ?? null;
11
+ const number = result?.map((string) => parseFloat(string)).find(n => n > 0) ?? 0;
12
+ array.push(number);
13
+ });
14
+ for (const number of array) {
15
+ if (number < 100) {
16
+ return false;
17
+ }
18
+ }
19
+ return true;
20
+ }
@@ -0,0 +1 @@
1
+ export declare function parseDelay(elArray: (HTMLDivElement | null)[]): number | null;
@@ -0,0 +1,10 @@
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 || 1);
10
+ }
@@ -0,0 +1 @@
1
+ export declare function parseOpacity(el: HTMLDivElement | null): number | null;
@@ -0,0 +1,6 @@
1
+ export function parseOpacity(el) {
2
+ if (!el)
3
+ return null;
4
+ const opacity = getComputedStyle(el).opacity;
5
+ return 1 - parseFloat(opacity);
6
+ }
@@ -0,0 +1 @@
1
+ export declare function parseOpacityAll(elArray: (HTMLDivElement | null)[]): boolean | null;
@@ -0,0 +1,13 @@
1
+ export function parseOpacityAll(elArray) {
2
+ if (elArray.length === 0)
3
+ return null;
4
+ for (const el of elArray) {
5
+ if (!el)
6
+ continue;
7
+ const opacity = parseFloat(getComputedStyle(el).opacity);
8
+ if (opacity > 0) {
9
+ return false;
10
+ }
11
+ }
12
+ return true;
13
+ }
@@ -0,0 +1,12 @@
1
+ import type { RefObject } from "react";
2
+ interface TransitionEndData {
3
+ elArray: (HTMLDivElement | null)[];
4
+ propertyName: '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 {};