@zuzjs/ui 0.9.4 → 0.9.5
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/dist/cjs/comps/Form/index.js +1 -1
- package/dist/cjs/comps/Group/index.d.ts +6 -0
- package/dist/cjs/comps/Group/index.js +21 -0
- package/dist/cjs/comps/Image/index.js +5 -3
- package/dist/cjs/comps/Text/index.js +0 -2
- package/dist/cjs/comps/index.d.ts +1 -0
- package/dist/cjs/comps/index.js +2 -0
- package/dist/cjs/funs/index.d.ts +1 -1
- package/dist/cjs/funs/index.js +4 -3
- package/dist/cjs/hooks/useBase.js +52 -11
- package/dist/cjs/types/interfaces.d.ts +3 -2
- package/dist/esm/comps/Form/index.js +1 -1
- package/dist/esm/comps/Group/index.d.ts +6 -0
- package/dist/esm/comps/Group/index.js +21 -0
- package/dist/esm/comps/Image/index.js +5 -3
- package/dist/esm/comps/Text/index.js +0 -2
- package/dist/esm/comps/index.d.ts +1 -0
- package/dist/esm/comps/index.js +2 -0
- package/dist/esm/funs/index.d.ts +1 -1
- package/dist/esm/funs/index.js +4 -3
- package/dist/esm/hooks/useBase.js +52 -11
- package/dist/esm/types/interfaces.d.ts +3 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -267,7 +267,7 @@ const Form = forwardRef((props, ref) => {
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
}, [innerRef.current]);
|
|
270
|
-
const buildChildren = useMemo(() => addPropsToChildren(children, child => child.props.type == `submit`, { ref: submit }), [children]);
|
|
270
|
+
const buildChildren = useMemo(() => addPropsToChildren(children, child => child.props.type == `submit`, index => ({ ref: submit })), [children]);
|
|
271
271
|
useImperativeHandle(ref, () => ({
|
|
272
272
|
setLoading(mod) {
|
|
273
273
|
if (mod) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { useDelayed } from "../..";
|
|
4
|
+
import { addPropsToChildren } from "../../funs";
|
|
5
|
+
import Box from "../Box";
|
|
6
|
+
const Group = forwardRef((props, ref) => {
|
|
7
|
+
const { children, fx, fxDelay, fxStep, ...rest } = props;
|
|
8
|
+
const when = useDelayed();
|
|
9
|
+
const Children = useMemo(() => {
|
|
10
|
+
if (!fx)
|
|
11
|
+
return children;
|
|
12
|
+
return addPropsToChildren(children, child => !(`fx` in (child.props ?? {})), index => ({ fx: {
|
|
13
|
+
...fx,
|
|
14
|
+
delay: (fxDelay || 0) + index * (fxStep || .1), // how to increment per index ?
|
|
15
|
+
when
|
|
16
|
+
} }));
|
|
17
|
+
}, [children, when, fx]);
|
|
18
|
+
return _jsx(Box, { className: `--group`, ref: ref, ...rest, children: Children });
|
|
19
|
+
});
|
|
20
|
+
Group.displayName = `Zuz.Group`;
|
|
21
|
+
export default Group;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from 'react';
|
|
2
|
+
import { forwardRef, useMemo, useRef } from 'react';
|
|
3
3
|
import { useBase } from '../../hooks';
|
|
4
4
|
const Image = forwardRef((props, ref) => {
|
|
5
|
-
const
|
|
5
|
+
const innerRef = useRef(null);
|
|
6
|
+
const targetRef = useMemo(() => ref && typeof ref !== "function" && ref.current ? ref : innerRef, [ref]);
|
|
7
|
+
const { style, className, rest } = useBase(props, targetRef);
|
|
6
8
|
if (!rest.src || rest.src == ``)
|
|
7
9
|
return null;
|
|
8
|
-
return _jsx("img", { ref:
|
|
10
|
+
return _jsx("img", { ref: targetRef, style: style, className: `${className} flex`, ...rest });
|
|
9
11
|
});
|
|
10
12
|
Image.displayName = `Zuz.Image`;
|
|
11
13
|
export default Image;
|
|
@@ -5,8 +5,6 @@ import Span from '../Span';
|
|
|
5
5
|
const Text = forwardRef((props, ref) => {
|
|
6
6
|
const { h, html, children, lines, ...pops } = props;
|
|
7
7
|
const { style, className, rest } = useBase(pops);
|
|
8
|
-
// const textRef = useTruncateText(lines || 2)
|
|
9
|
-
// const mergedRef = useMergedRefs(ref, textRef)
|
|
10
8
|
const Tag = `h${props.h || 1}`;
|
|
11
9
|
return _jsx(Tag, { ref: ref, style: style, className: className, ...rest, children: html ? _jsx(Span, { dangerouslySetInnerHTML: { __html: html } }) : children });
|
|
12
10
|
});
|
|
@@ -36,6 +36,7 @@ export * from './Fab/types';
|
|
|
36
36
|
export { default as Filters, type FilterProps } from './Filters';
|
|
37
37
|
export { default as Form } from './Form';
|
|
38
38
|
export * from './Form/types';
|
|
39
|
+
export { default as Group } from './Group';
|
|
39
40
|
export { default as Icon, type IconProps } from './Icon';
|
|
40
41
|
export { default as Image, type ImageProps } from './Image';
|
|
41
42
|
export { default as Input, type InputProps } from './Input';
|
package/dist/cjs/comps/index.js
CHANGED
|
@@ -36,6 +36,8 @@ export * from './Fab/types';
|
|
|
36
36
|
export { default as Filters } from './Filters';
|
|
37
37
|
export { default as Form } from './Form';
|
|
38
38
|
export * from './Form/types';
|
|
39
|
+
export { default as Group } from './Group';
|
|
40
|
+
// export * from './Form/types';
|
|
39
41
|
export { default as Icon } from './Icon';
|
|
40
42
|
export { default as Image } from './Image';
|
|
41
43
|
export { default as Input } from './Input';
|
package/dist/cjs/funs/index.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export declare const bindKey: (key: KeyCode, fun: () => void, element?: HTMLElem
|
|
|
63
63
|
export declare const camelCase: (str: string, ucf?: boolean) => string;
|
|
64
64
|
export declare const camelCaseToDash: (str: string) => string;
|
|
65
65
|
export declare const pluralize: (word: string, count: number) => string;
|
|
66
|
-
export declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean,
|
|
66
|
+
export declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean, getProps: (index: number, element: ReactElement<any>) => object) => ReactNode;
|
|
67
67
|
export declare const getPositionAroundElement: (x: number, y: number, distance: number, childCount: number) => {
|
|
68
68
|
x: number;
|
|
69
69
|
y: number;
|
package/dist/cjs/funs/index.js
CHANGED
|
@@ -395,16 +395,17 @@ export const camelCase = (str, ucf = false) => {
|
|
|
395
395
|
};
|
|
396
396
|
export const camelCaseToDash = (str) => str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
397
397
|
export const pluralize = (word, count) => `${word}${count !== 1 ? 's' : ''}`;
|
|
398
|
-
export const addPropsToChildren = (children, conditions,
|
|
398
|
+
export const addPropsToChildren = (children, conditions, getProps) => {
|
|
399
|
+
let i = 0;
|
|
399
400
|
return Children.map(children, (child) => {
|
|
400
401
|
if (isValidElement(child)) {
|
|
401
402
|
const element = child;
|
|
402
403
|
const newChild = conditions(element)
|
|
403
|
-
? cloneElement(element,
|
|
404
|
+
? cloneElement(element, getProps(i++, element))
|
|
404
405
|
: element;
|
|
405
406
|
if (element.props.children) {
|
|
406
407
|
return cloneElement(newChild, {
|
|
407
|
-
children: addPropsToChildren(element.props.children, conditions,
|
|
408
|
+
children: addPropsToChildren(element.props.children, conditions, getProps)
|
|
408
409
|
});
|
|
409
410
|
}
|
|
410
411
|
return newChild;
|
|
@@ -57,6 +57,7 @@ const useBase = (props, ref) => {
|
|
|
57
57
|
// { transition: `all ${duration || `0.2`}s ${getAnimationCurve(curve)} ${delay || 0}s` }
|
|
58
58
|
const _curve = getAnimationCurve(curve);
|
|
59
59
|
const _transitionList = [];
|
|
60
|
+
const _willChangeList = [];
|
|
60
61
|
Object.keys(_style).forEach(ck => {
|
|
61
62
|
let prop = ck;
|
|
62
63
|
let _subTrans = ck;
|
|
@@ -68,11 +69,15 @@ const useBase = (props, ref) => {
|
|
|
68
69
|
else if (cssTransformKeys.includes(prop)) {
|
|
69
70
|
_subTrans = `transform`;
|
|
70
71
|
}
|
|
72
|
+
// will-change: ${_subTrans};
|
|
71
73
|
const _newTransition = `${_subTrans} ${duration || `0.2`}s ${_curve} ${delay || 0}s`;
|
|
74
|
+
if (!_willChangeList.includes(_subTrans))
|
|
75
|
+
_willChangeList.push(_subTrans);
|
|
72
76
|
if (!_transitionList.includes(_newTransition))
|
|
73
77
|
_transitionList.push(_newTransition);
|
|
74
78
|
});
|
|
75
79
|
_transition.transition = _transitionList.join(`, `);
|
|
80
|
+
_transition.willChange = _willChangeList.join(`, `);
|
|
76
81
|
}
|
|
77
82
|
// // console.log(_style, _transition)
|
|
78
83
|
const is = typeof window !== "undefined";
|
|
@@ -98,7 +103,7 @@ const useBase = (props, ref) => {
|
|
|
98
103
|
};
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
|
-
const
|
|
106
|
+
const handleScrollParallax = () => {
|
|
102
107
|
if (fx && fx.scroll && typeof window !== 'undefined') {
|
|
103
108
|
const now = performance.now();
|
|
104
109
|
const dt = (now - lastTime.current) / 1000;
|
|
@@ -110,22 +115,58 @@ const useBase = (props, ref) => {
|
|
|
110
115
|
if (ref?.current) {
|
|
111
116
|
const translateX = x ? currentScroll.current.x * x * (multiplier || xMultiplier || .25) : 0;
|
|
112
117
|
const translateY = y ? currentScroll.current.y * y * (multiplier || yMultiplier || .25) : 0;
|
|
113
|
-
// ref.current.style.setProperty(`--scroll-y`, `${translateY}px`)
|
|
114
|
-
// transform = `translate3d(${translateX}px, ${translateY}px, 0)`.trim()
|
|
115
118
|
animateCSSVar(ref, "--scroll-y", translateY);
|
|
119
|
+
animateCSSVar(ref, "--scroll-x", translateX);
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
};
|
|
123
|
+
const handleMouseParallax = (e) => {
|
|
124
|
+
if (!fx || !fx.mouse || typeof window === 'undefined')
|
|
125
|
+
return;
|
|
126
|
+
const now = performance.now();
|
|
127
|
+
const dt = (now - lastTime.current) / 1000;
|
|
128
|
+
lastTime.current = now;
|
|
129
|
+
const { lerpFactor, x, y, multiplier, xMultiplier, yMultiplier } = fx.mouse;
|
|
130
|
+
// Normalize mouse position to center (0) range (-1 to 1)
|
|
131
|
+
const vw = window.innerWidth;
|
|
132
|
+
const vh = window.innerHeight;
|
|
133
|
+
const nx = (e.clientX - vw / 2) / (vw / 2); // -1 to 1
|
|
134
|
+
const ny = (e.clientY - vh / 2) / (vh / 2); // -1 to 1
|
|
135
|
+
const dx = nx - currentScroll.current.x;
|
|
136
|
+
const dy = ny - currentScroll.current.y;
|
|
137
|
+
currentScroll.current.x += dx * (lerpFactor || 0.1);
|
|
138
|
+
currentScroll.current.y += dy * (lerpFactor || 0.1);
|
|
139
|
+
if (ref?.current) {
|
|
140
|
+
const translateX = x ? currentScroll.current.x * (multiplier || xMultiplier || 20) : 0;
|
|
141
|
+
const translateY = y ? currentScroll.current.y * (multiplier || yMultiplier || 20) : 0;
|
|
142
|
+
animateCSSVar(ref, '--mouse-x', translateX);
|
|
143
|
+
animateCSSVar(ref, '--mouse-y', translateY);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
119
146
|
useEffect(() => {
|
|
120
|
-
if (
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
147
|
+
if (typeof window !== 'undefined') {
|
|
148
|
+
if (fx && fx.scroll) {
|
|
149
|
+
if (ref) {
|
|
150
|
+
ref.current.style.willChange = `transform`;
|
|
151
|
+
ref.current.style.transform = `translate3d(0px, var(--scroll-y), 0)`;
|
|
152
|
+
ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
|
|
153
|
+
}
|
|
154
|
+
window.addEventListener('scroll', handleScrollParallax, { passive: true });
|
|
155
|
+
return () => {
|
|
156
|
+
window.removeEventListener('scroll', handleScrollParallax);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (fx && fx.mouse) {
|
|
160
|
+
if (ref) {
|
|
161
|
+
ref.current.style.willChange = `transform`;
|
|
162
|
+
ref.current.style.transform = `translate3d(0px, var(--mouse-y), 0)`;
|
|
163
|
+
ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
|
|
164
|
+
}
|
|
165
|
+
window.document.addEventListener('mousemove', handleMouseParallax, { passive: true });
|
|
166
|
+
return () => {
|
|
167
|
+
window.removeEventListener('mousemove', handleMouseParallax);
|
|
168
|
+
};
|
|
124
169
|
}
|
|
125
|
-
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
126
|
-
return () => {
|
|
127
|
-
window.removeEventListener('scroll', handleScroll);
|
|
128
|
-
};
|
|
129
170
|
}
|
|
130
171
|
}, [ref]);
|
|
131
172
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dynamicObject } from ".";
|
|
2
2
|
import { SKELETON, TRANSITION_CURVES, TRANSITIONS } from "./enums";
|
|
3
|
-
export interface
|
|
3
|
+
export interface parallaxEffectProps {
|
|
4
4
|
lerpFactor?: number;
|
|
5
5
|
x?: number;
|
|
6
6
|
y?: number;
|
|
@@ -34,7 +34,8 @@ export interface animationProps {
|
|
|
34
34
|
delay?: number;
|
|
35
35
|
/** Easing curve applied to the animation, as a string or {@link TRANSITION_CURVES} */
|
|
36
36
|
curve?: string | TRANSITION_CURVES;
|
|
37
|
-
scroll?:
|
|
37
|
+
scroll?: parallaxEffectProps;
|
|
38
|
+
mouse?: parallaxEffectProps;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* `Skeleton` defines properties for a skeleton loader, used to indicate
|
|
@@ -267,7 +267,7 @@ const Form = forwardRef((props, ref) => {
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
}, [innerRef.current]);
|
|
270
|
-
const buildChildren = useMemo(() => addPropsToChildren(children, child => child.props.type == `submit`, { ref: submit }), [children]);
|
|
270
|
+
const buildChildren = useMemo(() => addPropsToChildren(children, child => child.props.type == `submit`, index => ({ ref: submit })), [children]);
|
|
271
271
|
useImperativeHandle(ref, () => ({
|
|
272
272
|
setLoading(mod) {
|
|
273
273
|
if (mod) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { useDelayed } from "../..";
|
|
4
|
+
import { addPropsToChildren } from "../../funs";
|
|
5
|
+
import Box from "../Box";
|
|
6
|
+
const Group = forwardRef((props, ref) => {
|
|
7
|
+
const { children, fx, fxDelay, fxStep, ...rest } = props;
|
|
8
|
+
const when = useDelayed();
|
|
9
|
+
const Children = useMemo(() => {
|
|
10
|
+
if (!fx)
|
|
11
|
+
return children;
|
|
12
|
+
return addPropsToChildren(children, child => !(`fx` in (child.props ?? {})), index => ({ fx: {
|
|
13
|
+
...fx,
|
|
14
|
+
delay: (fxDelay || 0) + index * (fxStep || .1), // how to increment per index ?
|
|
15
|
+
when
|
|
16
|
+
} }));
|
|
17
|
+
}, [children, when, fx]);
|
|
18
|
+
return _jsx(Box, { className: `--group`, ref: ref, ...rest, children: Children });
|
|
19
|
+
});
|
|
20
|
+
Group.displayName = `Zuz.Group`;
|
|
21
|
+
export default Group;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from 'react';
|
|
2
|
+
import { forwardRef, useMemo, useRef } from 'react';
|
|
3
3
|
import { useBase } from '../../hooks';
|
|
4
4
|
const Image = forwardRef((props, ref) => {
|
|
5
|
-
const
|
|
5
|
+
const innerRef = useRef(null);
|
|
6
|
+
const targetRef = useMemo(() => ref && typeof ref !== "function" && ref.current ? ref : innerRef, [ref]);
|
|
7
|
+
const { style, className, rest } = useBase(props, targetRef);
|
|
6
8
|
if (!rest.src || rest.src == ``)
|
|
7
9
|
return null;
|
|
8
|
-
return _jsx("img", { ref:
|
|
10
|
+
return _jsx("img", { ref: targetRef, style: style, className: `${className} flex`, ...rest });
|
|
9
11
|
});
|
|
10
12
|
Image.displayName = `Zuz.Image`;
|
|
11
13
|
export default Image;
|
|
@@ -5,8 +5,6 @@ import Span from '../Span';
|
|
|
5
5
|
const Text = forwardRef((props, ref) => {
|
|
6
6
|
const { h, html, children, lines, ...pops } = props;
|
|
7
7
|
const { style, className, rest } = useBase(pops);
|
|
8
|
-
// const textRef = useTruncateText(lines || 2)
|
|
9
|
-
// const mergedRef = useMergedRefs(ref, textRef)
|
|
10
8
|
const Tag = `h${props.h || 1}`;
|
|
11
9
|
return _jsx(Tag, { ref: ref, style: style, className: className, ...rest, children: html ? _jsx(Span, { dangerouslySetInnerHTML: { __html: html } }) : children });
|
|
12
10
|
});
|
|
@@ -36,6 +36,7 @@ export * from './Fab/types';
|
|
|
36
36
|
export { default as Filters, type FilterProps } from './Filters';
|
|
37
37
|
export { default as Form } from './Form';
|
|
38
38
|
export * from './Form/types';
|
|
39
|
+
export { default as Group } from './Group';
|
|
39
40
|
export { default as Icon, type IconProps } from './Icon';
|
|
40
41
|
export { default as Image, type ImageProps } from './Image';
|
|
41
42
|
export { default as Input, type InputProps } from './Input';
|
package/dist/esm/comps/index.js
CHANGED
|
@@ -36,6 +36,8 @@ export * from './Fab/types';
|
|
|
36
36
|
export { default as Filters } from './Filters';
|
|
37
37
|
export { default as Form } from './Form';
|
|
38
38
|
export * from './Form/types';
|
|
39
|
+
export { default as Group } from './Group';
|
|
40
|
+
// export * from './Form/types';
|
|
39
41
|
export { default as Icon } from './Icon';
|
|
40
42
|
export { default as Image } from './Image';
|
|
41
43
|
export { default as Input } from './Input';
|
package/dist/esm/funs/index.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export declare const bindKey: (key: KeyCode, fun: () => void, element?: HTMLElem
|
|
|
63
63
|
export declare const camelCase: (str: string, ucf?: boolean) => string;
|
|
64
64
|
export declare const camelCaseToDash: (str: string) => string;
|
|
65
65
|
export declare const pluralize: (word: string, count: number) => string;
|
|
66
|
-
export declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean,
|
|
66
|
+
export declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean, getProps: (index: number, element: ReactElement<any>) => object) => ReactNode;
|
|
67
67
|
export declare const getPositionAroundElement: (x: number, y: number, distance: number, childCount: number) => {
|
|
68
68
|
x: number;
|
|
69
69
|
y: number;
|
package/dist/esm/funs/index.js
CHANGED
|
@@ -395,16 +395,17 @@ export const camelCase = (str, ucf = false) => {
|
|
|
395
395
|
};
|
|
396
396
|
export const camelCaseToDash = (str) => str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
397
397
|
export const pluralize = (word, count) => `${word}${count !== 1 ? 's' : ''}`;
|
|
398
|
-
export const addPropsToChildren = (children, conditions,
|
|
398
|
+
export const addPropsToChildren = (children, conditions, getProps) => {
|
|
399
|
+
let i = 0;
|
|
399
400
|
return Children.map(children, (child) => {
|
|
400
401
|
if (isValidElement(child)) {
|
|
401
402
|
const element = child;
|
|
402
403
|
const newChild = conditions(element)
|
|
403
|
-
? cloneElement(element,
|
|
404
|
+
? cloneElement(element, getProps(i++, element))
|
|
404
405
|
: element;
|
|
405
406
|
if (element.props.children) {
|
|
406
407
|
return cloneElement(newChild, {
|
|
407
|
-
children: addPropsToChildren(element.props.children, conditions,
|
|
408
|
+
children: addPropsToChildren(element.props.children, conditions, getProps)
|
|
408
409
|
});
|
|
409
410
|
}
|
|
410
411
|
return newChild;
|
|
@@ -57,6 +57,7 @@ const useBase = (props, ref) => {
|
|
|
57
57
|
// { transition: `all ${duration || `0.2`}s ${getAnimationCurve(curve)} ${delay || 0}s` }
|
|
58
58
|
const _curve = getAnimationCurve(curve);
|
|
59
59
|
const _transitionList = [];
|
|
60
|
+
const _willChangeList = [];
|
|
60
61
|
Object.keys(_style).forEach(ck => {
|
|
61
62
|
let prop = ck;
|
|
62
63
|
let _subTrans = ck;
|
|
@@ -68,11 +69,15 @@ const useBase = (props, ref) => {
|
|
|
68
69
|
else if (cssTransformKeys.includes(prop)) {
|
|
69
70
|
_subTrans = `transform`;
|
|
70
71
|
}
|
|
72
|
+
// will-change: ${_subTrans};
|
|
71
73
|
const _newTransition = `${_subTrans} ${duration || `0.2`}s ${_curve} ${delay || 0}s`;
|
|
74
|
+
if (!_willChangeList.includes(_subTrans))
|
|
75
|
+
_willChangeList.push(_subTrans);
|
|
72
76
|
if (!_transitionList.includes(_newTransition))
|
|
73
77
|
_transitionList.push(_newTransition);
|
|
74
78
|
});
|
|
75
79
|
_transition.transition = _transitionList.join(`, `);
|
|
80
|
+
_transition.willChange = _willChangeList.join(`, `);
|
|
76
81
|
}
|
|
77
82
|
// // console.log(_style, _transition)
|
|
78
83
|
const is = typeof window !== "undefined";
|
|
@@ -98,7 +103,7 @@ const useBase = (props, ref) => {
|
|
|
98
103
|
};
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
|
-
const
|
|
106
|
+
const handleScrollParallax = () => {
|
|
102
107
|
if (fx && fx.scroll && typeof window !== 'undefined') {
|
|
103
108
|
const now = performance.now();
|
|
104
109
|
const dt = (now - lastTime.current) / 1000;
|
|
@@ -110,22 +115,58 @@ const useBase = (props, ref) => {
|
|
|
110
115
|
if (ref?.current) {
|
|
111
116
|
const translateX = x ? currentScroll.current.x * x * (multiplier || xMultiplier || .25) : 0;
|
|
112
117
|
const translateY = y ? currentScroll.current.y * y * (multiplier || yMultiplier || .25) : 0;
|
|
113
|
-
// ref.current.style.setProperty(`--scroll-y`, `${translateY}px`)
|
|
114
|
-
// transform = `translate3d(${translateX}px, ${translateY}px, 0)`.trim()
|
|
115
118
|
animateCSSVar(ref, "--scroll-y", translateY);
|
|
119
|
+
animateCSSVar(ref, "--scroll-x", translateX);
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
};
|
|
123
|
+
const handleMouseParallax = (e) => {
|
|
124
|
+
if (!fx || !fx.mouse || typeof window === 'undefined')
|
|
125
|
+
return;
|
|
126
|
+
const now = performance.now();
|
|
127
|
+
const dt = (now - lastTime.current) / 1000;
|
|
128
|
+
lastTime.current = now;
|
|
129
|
+
const { lerpFactor, x, y, multiplier, xMultiplier, yMultiplier } = fx.mouse;
|
|
130
|
+
// Normalize mouse position to center (0) range (-1 to 1)
|
|
131
|
+
const vw = window.innerWidth;
|
|
132
|
+
const vh = window.innerHeight;
|
|
133
|
+
const nx = (e.clientX - vw / 2) / (vw / 2); // -1 to 1
|
|
134
|
+
const ny = (e.clientY - vh / 2) / (vh / 2); // -1 to 1
|
|
135
|
+
const dx = nx - currentScroll.current.x;
|
|
136
|
+
const dy = ny - currentScroll.current.y;
|
|
137
|
+
currentScroll.current.x += dx * (lerpFactor || 0.1);
|
|
138
|
+
currentScroll.current.y += dy * (lerpFactor || 0.1);
|
|
139
|
+
if (ref?.current) {
|
|
140
|
+
const translateX = x ? currentScroll.current.x * (multiplier || xMultiplier || 20) : 0;
|
|
141
|
+
const translateY = y ? currentScroll.current.y * (multiplier || yMultiplier || 20) : 0;
|
|
142
|
+
animateCSSVar(ref, '--mouse-x', translateX);
|
|
143
|
+
animateCSSVar(ref, '--mouse-y', translateY);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
119
146
|
useEffect(() => {
|
|
120
|
-
if (
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
147
|
+
if (typeof window !== 'undefined') {
|
|
148
|
+
if (fx && fx.scroll) {
|
|
149
|
+
if (ref) {
|
|
150
|
+
ref.current.style.willChange = `transform`;
|
|
151
|
+
ref.current.style.transform = `translate3d(0px, var(--scroll-y), 0)`;
|
|
152
|
+
ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
|
|
153
|
+
}
|
|
154
|
+
window.addEventListener('scroll', handleScrollParallax, { passive: true });
|
|
155
|
+
return () => {
|
|
156
|
+
window.removeEventListener('scroll', handleScrollParallax);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (fx && fx.mouse) {
|
|
160
|
+
if (ref) {
|
|
161
|
+
ref.current.style.willChange = `transform`;
|
|
162
|
+
ref.current.style.transform = `translate3d(0px, var(--mouse-y), 0)`;
|
|
163
|
+
ref.current.style.transition = `transform 0.1s ${fx.curve ? getAnimationCurve(fx.curve) : `var(--spring)`}`;
|
|
164
|
+
}
|
|
165
|
+
window.document.addEventListener('mousemove', handleMouseParallax, { passive: true });
|
|
166
|
+
return () => {
|
|
167
|
+
window.removeEventListener('mousemove', handleMouseParallax);
|
|
168
|
+
};
|
|
124
169
|
}
|
|
125
|
-
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
126
|
-
return () => {
|
|
127
|
-
window.removeEventListener('scroll', handleScroll);
|
|
128
|
-
};
|
|
129
170
|
}
|
|
130
171
|
}, [ref]);
|
|
131
172
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dynamicObject } from ".";
|
|
2
2
|
import { SKELETON, TRANSITION_CURVES, TRANSITIONS } from "./enums";
|
|
3
|
-
export interface
|
|
3
|
+
export interface parallaxEffectProps {
|
|
4
4
|
lerpFactor?: number;
|
|
5
5
|
x?: number;
|
|
6
6
|
y?: number;
|
|
@@ -34,7 +34,8 @@ export interface animationProps {
|
|
|
34
34
|
delay?: number;
|
|
35
35
|
/** Easing curve applied to the animation, as a string or {@link TRANSITION_CURVES} */
|
|
36
36
|
curve?: string | TRANSITION_CURVES;
|
|
37
|
-
scroll?:
|
|
37
|
+
scroll?: parallaxEffectProps;
|
|
38
|
+
mouse?: parallaxEffectProps;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* `Skeleton` defines properties for a skeleton loader, used to indicate
|