@zuzjs/ui 0.9.3 → 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/Crumb/index.d.ts +1 -1
- package/dist/cjs/comps/Drawer/index.js +4 -0
- package/dist/cjs/comps/Form/index.js +4 -1
- package/dist/cjs/comps/Form/types.d.ts +1 -0
- 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/List/index.d.ts +1 -1
- package/dist/cjs/comps/ScrollView/index.js +1 -2
- 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/hooks/useScrollbar.d.ts +1 -1
- package/dist/cjs/hooks/useScrollbar.js +12 -5
- package/dist/cjs/types/interfaces.d.ts +3 -2
- package/dist/css/styles.css +1 -1
- package/dist/esm/comps/Crumb/index.d.ts +1 -1
- package/dist/esm/comps/Drawer/index.js +4 -0
- package/dist/esm/comps/Form/index.js +4 -1
- package/dist/esm/comps/Form/types.d.ts +1 -0
- 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/List/index.d.ts +1 -1
- package/dist/esm/comps/ScrollView/index.js +1 -2
- 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/hooks/useScrollbar.d.ts +1 -1
- package/dist/esm/hooks/useScrollbar.js +12 -5
- 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
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
export interface ScrollBreakpoint {
|
|
2
2
|
[key: number]: () => void;
|
|
3
3
|
}
|
|
4
|
-
declare const useScrollbar: (breakpoints?: ScrollBreakpoint) => {
|
|
4
|
+
declare const useScrollbar: (speed: number, breakpoints?: ScrollBreakpoint) => {
|
|
5
5
|
rootRef: import("react").RefObject<HTMLDivElement | null>;
|
|
6
6
|
containerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
7
7
|
thumbY: import("react").RefObject<HTMLDivElement | null>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { useMutationObserver } from "..";
|
|
4
|
-
const useScrollbar = (breakpoints = {}) => {
|
|
4
|
+
const useScrollbar = (speed, breakpoints = {}) => {
|
|
5
5
|
const rootRef = useRef(null);
|
|
6
6
|
const containerRef = useRef(null);
|
|
7
7
|
const thumbY = useRef(null);
|
|
8
8
|
const thumbX = useRef(null);
|
|
9
|
+
const SCROLL_SPEED = useMemo(() => speed ?? 1, [speed]); // default to 1x multiplier
|
|
9
10
|
const isDraggingY = useRef(false);
|
|
10
11
|
const isDraggingX = useRef(false);
|
|
11
12
|
const dragStartX = useRef(0);
|
|
@@ -52,7 +53,13 @@ const useScrollbar = (breakpoints = {}) => {
|
|
|
52
53
|
});
|
|
53
54
|
};
|
|
54
55
|
const handleScroll = useCallback(() => {
|
|
55
|
-
if (!containerRef.current
|
|
56
|
+
if (!containerRef.current
|
|
57
|
+
// ||
|
|
58
|
+
// (
|
|
59
|
+
// typeof window !== `undefined` &&
|
|
60
|
+
// window.document.body.classList.contains(`--no-scroll`)
|
|
61
|
+
// )
|
|
62
|
+
)
|
|
56
63
|
return;
|
|
57
64
|
const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
|
|
58
65
|
const scrollPercentY = (scrollTop / (scrollHeight - clientHeight)) * 100;
|
|
@@ -122,13 +129,13 @@ const useScrollbar = (breakpoints = {}) => {
|
|
|
122
129
|
const maxScrollY = scrollHeight - clientHeight;
|
|
123
130
|
let newScrollTop = scrollTop + e.deltaY;
|
|
124
131
|
newScrollTop = Math.max(0, Math.min(newScrollTop, maxScrollY));
|
|
125
|
-
containerRef.current.scrollTop = newScrollTop;
|
|
132
|
+
containerRef.current.scrollTop = newScrollTop * SCROLL_SPEED;
|
|
126
133
|
}
|
|
127
134
|
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
|
|
128
135
|
const maxScrollX = scrollWidth - clientWidth;
|
|
129
136
|
let newScrollLeft = scrollLeft + e.deltaX;
|
|
130
137
|
newScrollLeft = Math.max(0, Math.min(newScrollLeft, maxScrollX));
|
|
131
|
-
containerRef.current.scrollLeft = newScrollLeft;
|
|
138
|
+
containerRef.current.scrollLeft = newScrollLeft * SCROLL_SPEED;
|
|
132
139
|
}
|
|
133
140
|
const scrollPercentY = (containerRef.current.scrollTop / (containerRef.current.scrollHeight - clientHeight)) * 100;
|
|
134
141
|
const scrollPercentX = (containerRef.current.scrollLeft / (containerRef.current.scrollWidth - clientWidth)) * 100;
|
|
@@ -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
|