@sharadox/pointer-web-library 0.1.0 → 0.2.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/LICENSE.md CHANGED
@@ -1,40 +1,40 @@
1
- # Sharadox Open Source Licence
1
+ # Sharadox Open Source License
2
2
 
3
3
  Version 0.1.0
4
4
 
5
- This is an informative English translation. The Portuguese text (`LICENCA.md`) is the only original and binding text of this licence; if the two differ, the Portuguese text prevails.
5
+ This is an informative English translation. The Portuguese text (`LICENCA.md`) is the only original and binding text of this license; if the two differ, the Portuguese text prevails.
6
6
 
7
7
  ## 1. Definitions
8
8
 
9
- For the purposes of this licence:
9
+ For the purposes of this license:
10
10
 
11
- 1. **"Work"** — the computer program, its documentation and any other content made available by the Licensor under this licence, in source code or in any other form.
11
+ 1. **"Work"** — the computer program, its documentation and any other content made available by the Licensor under this license, in source code or in any other form.
12
12
  2. **"Licensor"** — the copyright holder identified in the copyright notice that accompanies the Work.
13
- 3. **"Licensee"** — any natural or legal person exercising the rights granted by this licence.
13
+ 3. **"Licensee"** — any natural or legal person exercising the rights granted by this license.
14
14
  4. **"Derivative Work"** — any work based on or incorporating the Work, in whole or in part, with or without modifications, including translations, adaptations and programs that integrate it.
15
- 5. **"Notice"** — the Licensor's copyright notice and the statement that the Work is licensed under this licence, including its version.
15
+ 5. **"Notice"** — the Licensor's copyright notice and the statement that the Work is licensed under this license, including its version.
16
16
 
17
17
  ## 2. Grant of rights
18
18
 
19
- 1. Under this licence, the Licensor grants the Licensee a worldwide, royalty-free, non-exclusive licence, for the whole term of copyright protection, to:
19
+ 1. Under this license, the Licensor grants the Licensee a worldwide, royalty-free, non-exclusive license, for the whole term of copyright protection, to:
20
20
  1. use the Work for any purpose, including commercial purposes;
21
21
  2. reproduce the Work, in whole or in part, by any means and in any form;
22
22
  3. modify, translate, adapt and transform the Work and create Derivative Works;
23
23
  4. distribute, publish, communicate to the public, make available, sell and sublicense the Work and Derivative Works.
24
- 2. To the extent the Licensor holds patents necessarily infringed by the Work as made available by it, the Licensor also grants the Licensee, on the same terms, a licence to use those patents in exercising the rights in the previous paragraph.
25
- 3. This licence does not transfer ownership of any rights, which remain with the Licensor.
24
+ 2. To the extent the Licensor holds patents necessarily infringed by the Work as made available by it, the Licensor also grants the Licensee, on the same terms, a license to use those patents in exercising the rights in the previous paragraph.
25
+ 3. This license does not transfer ownership of any rights, which remain with the Licensor.
26
26
 
27
27
  ## 3. Conditions
28
28
 
29
29
  The exercise of the rights granted is subject to the following conditions:
30
30
 
31
- 1. Every copy of the Work, or of substantial parts of it, and every distributed Derivative Work must include the Notice and a copy of this licence or a stable link to its text.
31
+ 1. Every copy of the Work, or of substantial parts of it, and every distributed Derivative Work must include the Notice and a copy of this license or a stable link to its text.
32
32
  2. Anyone distributing a modified version of the Work must state visibly that it has been modified and may not present it as the Licensor's original version.
33
- 3. The Licensee may license their own modifications under other terms, provided the part of the Work included in them remains subject to the conditions of this licence.
33
+ 3. The Licensee may license their own modifications under other terms, provided the part of the Work included in them remains subject to the conditions of this license.
34
34
 
35
35
  ## 4. Names and trademarks
36
36
 
37
- This licence grants no rights to the Licensor's name, trademarks, logos or other distinctive signs, including the name "Sharadox", except as strictly necessary to comply with the duty to include the Notice. Using them to promote or suggest the Licensor's endorsement of Derivative Works or of any products or services without prior written permission is prohibited.
37
+ This license grants no rights to the Licensor's name, trademarks, logos or other distinctive signs, including the name "Sharadox", except as strictly necessary to comply with the duty to include the Notice. Using them to promote or suggest the Licensor's endorsement of Derivative Works or of any products or services without prior written permission is prohibited.
38
38
 
39
39
  ## 5. Disclaimer of warranties
40
40
 
@@ -43,29 +43,29 @@ The Work is provided "as is" and "as available", without any warranty, express o
43
43
  ## 6. Limitation of liability
44
44
 
45
45
  1. To the maximum extent permitted by applicable law, the Licensor is not liable for any damages, direct or indirect, including loss of profits, loss of data or business interruption, arising from the use of or inability to use the Work, even if advised of the possibility of such damages.
46
- 2. Nothing in this licence excludes or limits the Licensor's liability where such exclusion or limitation is not permitted by law, in particular for acts committed with intent or gross negligence, under article 809 and article 800(2) of the Portuguese Civil Code, nor does it affect rights that the law mandatorily grants to consumers.
46
+ 2. Nothing in this license excludes or limits the Licensor's liability where such exclusion or limitation is not permitted by law, in particular for acts committed with intent or gross negligence, under article 809 and article 800(2) of the Portuguese Civil Code, nor does it affect rights that the law mandatorily grants to consumers.
47
47
 
48
48
  ## 7. Termination
49
49
 
50
- 1. The rights granted by this licence terminate automatically if the Licensee breaches any of its conditions.
50
+ 1. The rights granted by this license terminate automatically if the Licensee breaches any of its conditions.
51
51
  2. The rights are reinstated if the breach is remedied within 30 days of the Licensee becoming aware of it, unless the Licensor has meanwhile objected in writing.
52
- 3. Termination does not affect licences validly granted by the Licensee to third parties who comply with this licence.
52
+ 3. Termination does not affect licenses validly granted by the Licensee to third parties who comply with this license.
53
53
 
54
54
  ## 8. Governing law and jurisdiction
55
55
 
56
- 1. This licence is governed by Portuguese law, in particular the Code of Copyright and Related Rights, approved by Decree-Law no. 63/85 of 14 March, and Decree-Law no. 252/94 of 20 October on the legal protection of computer programs.
57
- 2. The Judicial Court of the District of Faro has jurisdiction over any dispute arising from this licence, without prejudice to applicable mandatory rules of jurisdiction, in particular those protecting consumers.
56
+ 1. This license is governed by Portuguese law, in particular the Code of Copyright and Related Rights, approved by Decree-Law no. 63/85 of 14 March, and Decree-Law no. 252/94 of 20 October on the legal protection of computer programs.
57
+ 2. The Judicial Court of the District of Faro has jurisdiction over any dispute arising from this license, without prejudice to applicable mandatory rules of jurisdiction, in particular those protecting consumers.
58
58
 
59
- ## 9. Licence versions
59
+ ## 9. License versions
60
60
 
61
- The Licensor may publish new versions of this licence, identified by a version number. The Work is subject to the version stated in the Notice. If the Notice allows it, the Licensee may choose any later version.
61
+ The Licensor may publish new versions of this license, identified by a version number. The Work is subject to the version stated in the Notice. If the Notice allows it, the Licensee may choose any later version.
62
62
 
63
63
  ## 10. Final provisions
64
64
 
65
- 1. If any provision of this licence is held invalid or unenforceable, the remaining provisions stay in force, and the affected provision shall be interpreted as closely as possible to its original intent.
66
- 2. Failure to enforce any provision of this licence at any time does not waive the right to enforce it later.
65
+ 1. If any provision of this license is held invalid or unenforceable, the remaining provisions stay in force, and the affected provision shall be interpreted as closely as possible to its original intent.
66
+ 2. Failure to enforce any provision of this license at any time does not waive the right to enforce it later.
67
67
 
68
- ## How to apply this licence
68
+ ## How to apply this license
69
69
 
70
70
  Include in the Work a `LICENCA.md` file with the Portuguese text, this translation as `LICENSE.md`, and the following notice, filling in the year and holder:
71
71
 
package/README.md CHANGED
@@ -4,6 +4,7 @@ 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
+ - **`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.
7
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
9
 
9
10
  ## Install
@@ -25,6 +26,11 @@ 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
  ```
@@ -35,12 +41,13 @@ const stage = useTilt<HTMLDivElement>(6);
35
41
  | ------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
36
42
  | `…/spotlight` | `useSpotlight<T>()` → reference |
37
43
  | `…/tilt` | `useTilt<T>(maximum = 8)` → reference |
44
+ | `…/parallax` | `useParallax<T>(ease = 0.1)` → reference; CSS variables `--parallax-x`, `--parallax-y`, `--parallax-hover` |
38
45
  | `…/cursor` | `<Cursor hotSelector? grabSelector? className?>`, `HOT_ELEMENTS`, `GRAB_ELEMENTS`; CSS variables `--cursor-color` and `--cursor-size` |
39
46
 
40
47
  ## Develop
41
48
 
42
49
  `pnpm verify` runs formatting, lint, type-check, tests with 100% coverage and the build. Branches follow `<feature>.development` → `development` → `index`, and releases are `v<version>` tags on `index`.
43
50
 
44
- ## Licence
51
+ ## License
45
52
 
46
53
  Licença Sharadox de Código Aberto, versão 0.1.0. See [português](LICENCA.md) (the binding text) and the [English translation](LICENSE.md).
@@ -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,EAAE,CAAC,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACzC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,IAAI,QAAQ,GAAG,CAAC,CAAC;YACjB,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAA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,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAChF,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAChF,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;YACjB,KAAK,EAAE,CAAC;QACV,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAChD,KAAK,EAAE,CAAC;QACV,CAAC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QAC9C,OAAO,CAAC,gBAAgB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;YACjD,OAAO,CAAC,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YACnD,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACX,OAAO,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
+ - /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
7
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
- - Peer: react. Licence: Sharadox Open Source Licence 0.1.0
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.1.0",
4
- "description": "Pointer effects for React: a spotlight that follows the pointer, 3D tilt towards it and a custom cursor.",
3
+ "version": "0.2.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>",
@@ -31,7 +31,7 @@
31
31
  "**/*.css"
32
32
  ],
33
33
  "engines": {
34
- "node": ">=24"
34
+ "node": ">=26"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"