@sharadox/pointer-web-library 0.2.0 → 0.3.0-development.6
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 +7 -7
- 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/llms.txt +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Pointer effects for React websites:
|
|
|
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. It uses blend mode `difference`, so it shows on any background, and only runs on fine pointers.
|
|
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.
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
@@ -37,12 +37,12 @@ const scene = useParallax<HTMLDivElement>(0.08);
|
|
|
37
37
|
|
|
38
38
|
## API
|
|
39
39
|
|
|
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? className?>`, `HOT_ELEMENTS`, `GRAB_ELEMENTS`; CSS variables `--cursor-color` and `--cursor-size` |
|
|
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` |
|
|
46
46
|
|
|
47
47
|
## Develop
|
|
48
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;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,CAAC;AACnD,mHAAmH;AACnH,MAAM,CAAC,MAAM,eAAe,GAAG,oCAAoC,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAC,EACrB,WAA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* 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"}
|
package/llms.txt
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
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 className /> dot + lagging ring, mix-blend difference; --cursor-color, --cursor-size; html gets class while active (hides system cursor)
|
|
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
|
|
9
9
|
- Peer: react. License: Sharadox Open Source License 0.1.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/pointer-web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-development.6",
|
|
4
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",
|