@sharadox/web-library 0.2.0 → 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 +1 -1
- package/distribution/animation/marquee/index.d.ts +9 -0
- package/distribution/animation/marquee/index.d.ts.map +1 -0
- package/distribution/animation/marquee/index.js +78 -0
- package/distribution/animation/marquee/index.js.map +1 -0
- package/distribution/animation/marquee/type.d.ts +5 -0
- package/distribution/animation/marquee/type.d.ts.map +1 -0
- package/distribution/animation/marquee/type.js +2 -0
- package/distribution/animation/marquee/type.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Import each piece by its path:
|
|
|
12
12
|
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
13
|
| `internationalization/` | `locale` (`isLocale`, `languageTag`, `openGraphLocale`, `Translated`), `translate`, `locale-redirect` (next.config redirects: remembered language, then Accept-Language), `locale-preference` (`rememberLocale`) |
|
|
14
14
|
| `search-engine/` | `sitemap` (`localizedSitemap`), `robots`, `structured-data` (JSON-LD component) |
|
|
15
|
-
| `animation/` | `reveal`, `scroll-word` (text that lights up word by word), `in-view`, `count-up`, `smooth-scroll`
|
|
15
|
+
| `animation/` | `reveal`, `scroll-word` (text that lights up word by word), `in-view`, `count-up`, `marquee` (endless strip you can also drag), `smooth-scroll` |
|
|
16
16
|
| `style/` | `definition` (`resolveStyle`), `style-script` (`<StyleScript>` for `<head>`: every style's CSS variables and the no-flash script), `use-style` (picker hook), `apply`, `style-sheet` |
|
|
17
17
|
| `pointer/` | `spotlight` (pointer position as CSS variables), `tilt` (3D tilt towards the pointer) |
|
|
18
18
|
| `time/` | `zone-minute`, `format-time`, `sun-time` (sunrise and sunset), `sun-today` (React hook), `open-state` |
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MarqueeOptions } from "@sharadox/web-library/animation/marquee/type";
|
|
2
|
+
/**
|
|
3
|
+
* An endless strip that slides on its own and can be grabbed and flung by hand (mouse or touch), with inertia.
|
|
4
|
+
* Attach the returned reference to the track: an element holding two identical groups side by side, so moving it by
|
|
5
|
+
* one group's width (half the track) looks the same. It does not move by itself when the visitor prefers reduced
|
|
6
|
+
* motion, but can still be dragged.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useMarquee<Track extends HTMLElement>({ speed }?: MarqueeOptions): import("react").RefObject<Track | null>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/animation/marquee/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAEnF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,WAAW,EAAE,EAAE,KAAU,EAAE,GAAE,cAAmB,2CAgExF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* An endless strip that slides on its own and can be grabbed and flung by hand (mouse or touch), with inertia.
|
|
5
|
+
* Attach the returned reference to the track: an element holding two identical groups side by side, so moving it by
|
|
6
|
+
* one group's width (half the track) looks the same. It does not move by itself when the visitor prefers reduced
|
|
7
|
+
* motion, but can still be dragged.
|
|
8
|
+
*/
|
|
9
|
+
export function useMarquee({ speed = 40 } = {}) {
|
|
10
|
+
const reference = useRef(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const track = reference.current;
|
|
13
|
+
if (!track)
|
|
14
|
+
return;
|
|
15
|
+
const automatic = window.matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : speed;
|
|
16
|
+
let offset = 0;
|
|
17
|
+
let velocity = 0;
|
|
18
|
+
let dragging = false;
|
|
19
|
+
let lastX = 0;
|
|
20
|
+
let lastTime = 0;
|
|
21
|
+
let previous = performance.now();
|
|
22
|
+
let frame = 0;
|
|
23
|
+
const wrap = () => {
|
|
24
|
+
const half = track.scrollWidth / 2;
|
|
25
|
+
if (half > 0)
|
|
26
|
+
offset = ((offset % half) - half) % half || 0;
|
|
27
|
+
};
|
|
28
|
+
const tick = (now) => {
|
|
29
|
+
const seconds = Math.min(0.05, (now - previous) / 1000);
|
|
30
|
+
previous = now;
|
|
31
|
+
if (!dragging) {
|
|
32
|
+
// Inertia from a fling eases back into the automatic speed.
|
|
33
|
+
velocity += (-automatic - velocity) * Math.min(1, seconds * 2.5);
|
|
34
|
+
offset += velocity * seconds;
|
|
35
|
+
}
|
|
36
|
+
wrap();
|
|
37
|
+
track.style.transform = `translate3d(${offset}px, 0, 0)`;
|
|
38
|
+
frame = requestAnimationFrame(tick);
|
|
39
|
+
};
|
|
40
|
+
const down = (event) => {
|
|
41
|
+
dragging = true;
|
|
42
|
+
lastX = event.clientX;
|
|
43
|
+
lastTime = event.timeStamp;
|
|
44
|
+
velocity = 0;
|
|
45
|
+
track.setPointerCapture(event.pointerId);
|
|
46
|
+
};
|
|
47
|
+
const move = (event) => {
|
|
48
|
+
if (!dragging)
|
|
49
|
+
return;
|
|
50
|
+
const delta = event.clientX - lastX;
|
|
51
|
+
const elapsed = Math.max(1, event.timeStamp - lastTime) / 1000;
|
|
52
|
+
offset += delta;
|
|
53
|
+
velocity = delta / elapsed;
|
|
54
|
+
lastX = event.clientX;
|
|
55
|
+
lastTime = event.timeStamp;
|
|
56
|
+
};
|
|
57
|
+
const up = (event) => {
|
|
58
|
+
dragging = false;
|
|
59
|
+
if (track.hasPointerCapture(event.pointerId))
|
|
60
|
+
track.releasePointerCapture(event.pointerId);
|
|
61
|
+
};
|
|
62
|
+
velocity = -automatic;
|
|
63
|
+
track.addEventListener("pointerdown", down);
|
|
64
|
+
track.addEventListener("pointermove", move);
|
|
65
|
+
track.addEventListener("pointerup", up);
|
|
66
|
+
track.addEventListener("pointercancel", up);
|
|
67
|
+
frame = requestAnimationFrame(tick);
|
|
68
|
+
return () => {
|
|
69
|
+
cancelAnimationFrame(frame);
|
|
70
|
+
track.removeEventListener("pointerdown", down);
|
|
71
|
+
track.removeEventListener("pointermove", move);
|
|
72
|
+
track.removeEventListener("pointerup", up);
|
|
73
|
+
track.removeEventListener("pointercancel", up);
|
|
74
|
+
};
|
|
75
|
+
}, [speed]);
|
|
76
|
+
return reference;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/animation/marquee/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG1C;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAA4B,EAAE,KAAK,GAAG,EAAE,KAAqB,EAAE;IACvF,MAAM,SAAS,GAAG,MAAM,CAAQ,IAAI,CAAC,CAAC;IACtC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC5F,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACjC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;YACnC,IAAI,IAAI,GAA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
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/animation/marquee/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/animation/marquee/type.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Generic building blocks for web applications: internationalization, styles, search engine metadata, animation, time and forms.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|