@sharadox/pointer-web-library 0.1.1 → 0.3.0
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 +13 -6
- package/distribution/cursor/index.d.ts +5 -2
- package/distribution/cursor/index.d.ts.map +1 -1
- package/distribution/cursor/index.js +8 -4
- package/distribution/cursor/index.js.map +1 -1
- package/distribution/cursor/index.module.css +5 -5
- package/distribution/cursor/type.d.ts +2 -0
- package/distribution/cursor/type.d.ts.map +1 -1
- package/distribution/parallax/index.d.ts +11 -0
- package/distribution/parallax/index.d.ts.map +1 -0
- package/distribution/parallax/index.js +62 -0
- package/distribution/parallax/index.js.map +1 -0
- package/llms.txt +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ Pointer effects for React websites:
|
|
|
4
4
|
|
|
5
5
|
- **`useSpotlight`:** the pointer's position inside an element as `--pointer-x` and `--pointer-y`, for lights that follow it.
|
|
6
6
|
- **`useTilt(maximum)`:** `--tilt-x` and `--tilt-y` in degrees, for a 3D tilt towards the pointer. It eases back when the pointer leaves, and is off on touch screens.
|
|
7
|
-
-
|
|
7
|
+
- **`useParallax(ease)`:** where the pointer is over an element as `--parallax-x` and `--parallax-y` (-1 to 1) and `--parallax-hover` (0 to 1), eased every frame and back to 0 when it leaves, for scenes with depth. It is off on touch screens and with reduced motion.
|
|
8
|
+
- **`<Cursor>`:** a dot and a lagging ring. The ring grows over clickable elements and turns dashed over draggable ones. Over native zones (`[data-guest]`: another site's components shown on yours) it steps aside and the system cursor shows. It uses blend mode `difference`, so it shows on any background, and only runs on fine pointers.
|
|
8
9
|
|
|
9
10
|
## Install
|
|
10
11
|
|
|
@@ -25,17 +26,23 @@ const stage = useTilt<HTMLDivElement>(6);
|
|
|
25
26
|
// .stage { transform: perspective(900px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y)) }
|
|
26
27
|
```
|
|
27
28
|
|
|
29
|
+
```tsx
|
|
30
|
+
const scene = useParallax<HTMLDivElement>(0.08);
|
|
31
|
+
// .phone { transform: translate3d(calc(var(--parallax-x, 0) * 14px), calc(var(--parallax-y, 0) * 10px), 60px) }
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
```tsx
|
|
29
35
|
<Cursor grabSelector="canvas, [data-grab]" />
|
|
30
36
|
```
|
|
31
37
|
|
|
32
38
|
## API
|
|
33
39
|
|
|
34
|
-
| Import | Export
|
|
35
|
-
| ------------- |
|
|
36
|
-
| `…/spotlight` | `useSpotlight<T>()` → reference
|
|
37
|
-
| `…/tilt` | `useTilt<T>(maximum = 8)` → reference
|
|
38
|
-
| `…/
|
|
40
|
+
| Import | Export |
|
|
41
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
42
|
+
| `…/spotlight` | `useSpotlight<T>()` → reference |
|
|
43
|
+
| `…/tilt` | `useTilt<T>(maximum = 8)` → reference |
|
|
44
|
+
| `…/parallax` | `useParallax<T>(ease = 0.1)` → reference; CSS variables `--parallax-x`, `--parallax-y`, `--parallax-hover` |
|
|
45
|
+
| `…/cursor` | `<Cursor hotSelector? grabSelector? nativeSelector? className?>`, `HOT_ELEMENTS`, `GRAB_ELEMENTS`, `NATIVE_ELEMENTS`; CSS variables `--cursor-color` and `--cursor-size` |
|
|
39
46
|
|
|
40
47
|
## Develop
|
|
41
48
|
|
|
@@ -3,13 +3,16 @@ import type { CursorProperties } from "@sharadox/pointer-web-library/cursor/type
|
|
|
3
3
|
export declare const HOT_ELEMENTS = "a, button, input, textarea, select, label, [data-hot]";
|
|
4
4
|
/** Where the ring shows "drag" by default. */
|
|
5
5
|
export declare const GRAB_ELEMENTS = "canvas, [data-grab]";
|
|
6
|
+
/** Where the system cursor comes back by default: another site's components shown here, with their own cursors. */
|
|
7
|
+
export declare const NATIVE_ELEMENTS = "[data-guest], [data-native-cursor]";
|
|
6
8
|
/**
|
|
7
9
|
* A custom cursor on fine pointers (mice, trackpads): a dot and a ring that follows with a slight lag, grows over
|
|
8
10
|
* clickable elements and turns dashed over draggable ones. White with `mix-blend-mode: difference`, so it shows on
|
|
9
|
-
* any background; restyle it with `--cursor-color`, `--cursor-size` and `className`.
|
|
11
|
+
* any background; restyle it with `--cursor-color`, `--cursor-size` and `className`. Over `nativeSelector` it steps
|
|
12
|
+
* aside and the system cursor shows, with whatever those elements ask for (zoom-in, grab). Touch screens keep their own.
|
|
10
13
|
*
|
|
11
14
|
* @example
|
|
12
15
|
* <Cursor grabSelector="canvas, [data-grab], .gallery" />
|
|
13
16
|
*/
|
|
14
|
-
export declare function Cursor({ hotSelector, grabSelector, className }: CursorProperties): import("react").JSX.Element;
|
|
17
|
+
export declare function Cursor({ hotSelector, grabSelector, nativeSelector, className, }: CursorProperties): import("react").JSX.Element;
|
|
15
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/cursor/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAElF,yEAAyE;AACzE,eAAO,MAAM,YAAY,0DAA0D,CAAC;AACpF,8CAA8C;AAC9C,eAAO,MAAM,aAAa,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/cursor/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAElF,yEAAyE;AACzE,eAAO,MAAM,YAAY,0DAA0D,CAAC;AACpF,8CAA8C;AAC9C,eAAO,MAAM,aAAa,wBAAwB,CAAC;AACnD,mHAAmH;AACnH,eAAO,MAAM,eAAe,uCAAuC,CAAC;AAEpE;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,EACrB,WAA0B,EAC1B,YAA4B,EAC5B,cAAgC,EAChC,SAAS,GACV,EAAE,gBAAgB,+BAyClB"}
|
|
@@ -7,15 +7,18 @@ import styles from "./index.module.css";
|
|
|
7
7
|
export const HOT_ELEMENTS = "a, button, input, textarea, select, label, [data-hot]";
|
|
8
8
|
/** Where the ring shows "drag" by default. */
|
|
9
9
|
export const GRAB_ELEMENTS = "canvas, [data-grab]";
|
|
10
|
+
/** Where the system cursor comes back by default: another site's components shown here, with their own cursors. */
|
|
11
|
+
export const NATIVE_ELEMENTS = "[data-guest], [data-native-cursor]";
|
|
10
12
|
/**
|
|
11
13
|
* A custom cursor on fine pointers (mice, trackpads): a dot and a ring that follows with a slight lag, grows over
|
|
12
14
|
* clickable elements and turns dashed over draggable ones. White with `mix-blend-mode: difference`, so it shows on
|
|
13
|
-
* any background; restyle it with `--cursor-color`, `--cursor-size` and `className`.
|
|
15
|
+
* any background; restyle it with `--cursor-color`, `--cursor-size` and `className`. Over `nativeSelector` it steps
|
|
16
|
+
* aside and the system cursor shows, with whatever those elements ask for (zoom-in, grab). Touch screens keep their own.
|
|
14
17
|
*
|
|
15
18
|
* @example
|
|
16
19
|
* <Cursor grabSelector="canvas, [data-grab], .gallery" />
|
|
17
20
|
*/
|
|
18
|
-
export function Cursor({ hotSelector = HOT_ELEMENTS, grabSelector = GRAB_ELEMENTS, className }) {
|
|
21
|
+
export function Cursor({ hotSelector = HOT_ELEMENTS, grabSelector = GRAB_ELEMENTS, nativeSelector = NATIVE_ELEMENTS, className, }) {
|
|
19
22
|
const dot = useRef(null);
|
|
20
23
|
const ring = useRef(null);
|
|
21
24
|
useEffect(() => {
|
|
@@ -32,6 +35,7 @@ export function Cursor({ hotSelector = HOT_ELEMENTS, grabSelector = GRAB_ELEMENT
|
|
|
32
35
|
x = event.clientX;
|
|
33
36
|
y = event.clientY;
|
|
34
37
|
const target = event.target;
|
|
38
|
+
root.classList.toggle(styles.native, !!target.closest?.(nativeSelector));
|
|
35
39
|
ring.current?.classList.toggle(styles.hot, !!target.closest?.(hotSelector));
|
|
36
40
|
ring.current?.classList.toggle(styles.grab, !!target.closest?.(grabSelector));
|
|
37
41
|
};
|
|
@@ -47,9 +51,9 @@ export function Cursor({ hotSelector = HOT_ELEMENTS, grabSelector = GRAB_ELEMENT
|
|
|
47
51
|
return () => {
|
|
48
52
|
removeEventListener("pointermove", move);
|
|
49
53
|
cancelAnimationFrame(frame);
|
|
50
|
-
root.classList.remove(styles.active);
|
|
54
|
+
root.classList.remove(styles.active, styles.native);
|
|
51
55
|
};
|
|
52
|
-
}, [hotSelector, grabSelector]);
|
|
56
|
+
}, [hotSelector, grabSelector, nativeSelector]);
|
|
53
57
|
return (_jsxs(_Fragment, { children: [_jsx("div", { ref: ring, className: classNames(styles.ring, className), "aria-hidden": true }), _jsx("div", { ref: dot, className: classNames(styles.dot, className), "aria-hidden": true })] }));
|
|
54
58
|
}
|
|
55
59
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/cursor/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAGxC,yEAAyE;AACzE,MAAM,CAAC,MAAM,YAAY,GAAG,uDAAuD,CAAC;AACpF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/cursor/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAGxC,yEAAyE;AACzE,MAAM,CAAC,MAAM,YAAY,GAAG,uDAAuD,CAAC;AACpF,8CAA8C;AAC9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C,wBAAgB,IAC1E,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* The system cursor hides only while the custom one is running (fine pointers). */
|
|
2
|
-
:global(html).active,
|
|
3
|
-
:global(html).active * {
|
|
1
|
+
/* The system cursor hides only while the custom one is running (fine pointers), and comes back over native zones. */
|
|
2
|
+
:global(html).active:not(.native),
|
|
3
|
+
:global(html).active:not(.native) * {
|
|
4
4
|
cursor: none !important;
|
|
5
5
|
}
|
|
6
6
|
.dot,
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
mix-blend-mode: difference;
|
|
17
17
|
display: none;
|
|
18
18
|
}
|
|
19
|
-
:global(html).active .dot,
|
|
20
|
-
:global(html).active .ring {
|
|
19
|
+
:global(html).active:not(.native) .dot,
|
|
20
|
+
:global(html).active:not(.native) .ring {
|
|
21
21
|
display: block;
|
|
22
22
|
}
|
|
23
23
|
.dot {
|
|
@@ -3,6 +3,8 @@ export interface CursorProperties {
|
|
|
3
3
|
hotSelector?: string;
|
|
4
4
|
/** Elements that show the "drag" ring (canvases, draggable strips…). */
|
|
5
5
|
grabSelector?: string;
|
|
6
|
+
/** Where the system cursor shows instead (another site's components, with cursors of their own). */
|
|
7
|
+
nativeSelector?: string;
|
|
6
8
|
/** Extra class for the dot and the ring, to restyle them. */
|
|
7
9
|
className?: string;
|
|
8
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/cursor/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/cursor/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oGAAoG;IACpG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the pointer is over an element, eased, for depth that follows it. Sets three unitless CSS variables on the
|
|
3
|
+
* element, each eased towards its target every frame (`ease` is the share of the distance covered per frame):
|
|
4
|
+
* `--parallax-x` and `--parallax-y` (-1 at the left or top edge, 0 in the middle, 1 at the right or bottom edge) and
|
|
5
|
+
* `--parallax-hover` (1 while the pointer is over it, 0 once it has left). All three ease back to 0 when the pointer
|
|
6
|
+
* leaves. Use them with `calc()`, for example
|
|
7
|
+
* `transform: rotateY(calc(var(--parallax-x, 0) * 8deg)) translateX(calc(var(--parallax-x, 0) * 12px))`.
|
|
8
|
+
* Off on touch screens and when less motion is asked for, so the variables stay unset there.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useParallax<Target extends HTMLElement>(ease?: number): import("react").RefObject<Target | null>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/parallax/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,WAAW,EAAE,IAAI,SAAM,4CA8CjE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { clamp } from "@sharadox/web-library/math/clamp";
|
|
4
|
+
/**
|
|
5
|
+
* Where the pointer is over an element, eased, for depth that follows it. Sets three unitless CSS variables on the
|
|
6
|
+
* element, each eased towards its target every frame (`ease` is the share of the distance covered per frame):
|
|
7
|
+
* `--parallax-x` and `--parallax-y` (-1 at the left or top edge, 0 in the middle, 1 at the right or bottom edge) and
|
|
8
|
+
* `--parallax-hover` (1 while the pointer is over it, 0 once it has left). All three ease back to 0 when the pointer
|
|
9
|
+
* leaves. Use them with `calc()`, for example
|
|
10
|
+
* `transform: rotateY(calc(var(--parallax-x, 0) * 8deg)) translateX(calc(var(--parallax-x, 0) * 12px))`.
|
|
11
|
+
* Off on touch screens and when less motion is asked for, so the variables stay unset there.
|
|
12
|
+
*/
|
|
13
|
+
export function useParallax(ease = 0.1) {
|
|
14
|
+
const reference = useRef(null);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const element = reference.current;
|
|
17
|
+
if (!element || !matchMedia("(pointer: fine)").matches || matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const target = { x: 0, y: 0, hover: 0 };
|
|
21
|
+
const current = { x: 0, y: 0, hover: 0 };
|
|
22
|
+
let frame = 0;
|
|
23
|
+
const step = () => {
|
|
24
|
+
let distance = 0;
|
|
25
|
+
for (const key of ["x", "y", "hover"]) {
|
|
26
|
+
current[key] += (target[key] - current[key]) * ease;
|
|
27
|
+
distance += Math.abs(target[key] - current[key]);
|
|
28
|
+
}
|
|
29
|
+
// Close enough: land exactly on the target and stop asking for frames.
|
|
30
|
+
if (distance < 0.001)
|
|
31
|
+
Object.assign(current, target);
|
|
32
|
+
element.style.setProperty("--parallax-x", current.x.toFixed(4));
|
|
33
|
+
element.style.setProperty("--parallax-y", current.y.toFixed(4));
|
|
34
|
+
element.style.setProperty("--parallax-hover", current.hover.toFixed(4));
|
|
35
|
+
frame = distance < 0.001 ? 0 : requestAnimationFrame(step);
|
|
36
|
+
};
|
|
37
|
+
const start = () => {
|
|
38
|
+
if (!frame)
|
|
39
|
+
frame = requestAnimationFrame(step);
|
|
40
|
+
};
|
|
41
|
+
const move = (event) => {
|
|
42
|
+
const bounds = element.getBoundingClientRect();
|
|
43
|
+
target.x = clamp(((event.clientX - bounds.left) / bounds.width) * 2 - 1, -1, 1);
|
|
44
|
+
target.y = clamp(((event.clientY - bounds.top) / bounds.height) * 2 - 1, -1, 1);
|
|
45
|
+
target.hover = 1;
|
|
46
|
+
start();
|
|
47
|
+
};
|
|
48
|
+
const leave = () => {
|
|
49
|
+
Object.assign(target, { x: 0, y: 0, hover: 0 });
|
|
50
|
+
start();
|
|
51
|
+
};
|
|
52
|
+
element.addEventListener("pointermove", move);
|
|
53
|
+
element.addEventListener("pointerleave", leave);
|
|
54
|
+
return () => {
|
|
55
|
+
element.removeEventListener("pointermove", move);
|
|
56
|
+
element.removeEventListener("pointerleave", leave);
|
|
57
|
+
cancelAnimationFrame(frame);
|
|
58
|
+
};
|
|
59
|
+
}, [ease]);
|
|
60
|
+
return reference;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/parallax/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAA6B,IAAI,GAAG,GAAG;IAChE,MAAM,SAAS,GAAG,MAAM,CAAS,IAAI,CAAC,CAAC;IACvC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,OAAO,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,EAAE,CAAC;YACjH,OAAO;QACT,CAAC;QACD,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,E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SAAS,CAAC;AACnB,CAAC"}
|
package/llms.txt
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
- /spotlight: useSpotlight<T>() → ref; sets --pointer-x/--pointer-y (px) on pointermove
|
|
6
6
|
- /tilt: useTilt<T>(maximum=8) → ref; sets --tilt-x/--tilt-y (deg); resets on leave; fine pointers only
|
|
7
|
-
- /
|
|
7
|
+
- /parallax: useParallax<T>(ease=0.1) → ref; sets unitless --parallax-x/--parallax-y (-1..1) and --parallax-hover (0..1), eased per animation frame, back to 0 on leave; fine pointers without reduced motion only
|
|
8
|
+
- /cursor: <Cursor hotSelector grabSelector nativeSelector className /> dot + lagging ring, mix-blend difference; --cursor-color, --cursor-size; html gets class while active (hides system cursor); over nativeSelector (NATIVE_ELEMENTS: [data-guest], [data-native-cursor]) html gets a second class, the ring and dot hide and the system cursor shows
|
|
8
9
|
- Peer: react. License: Sharadox Open Source License 0.1.0
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/pointer-web-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Pointer effects for React: a spotlight that follows the pointer, 3D tilt towards it and a custom cursor.",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Pointer effects for React: a spotlight that follows the pointer, 3D tilt towards it, eased parallax and a custom cursor.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|
|
7
7
|
"author": "Sharadox <contact@sharadox.com>",
|