@motionstudies/web 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +231 -2
- package/components/AirportBoard.d.ts +27 -0
- package/components/AirportBoard.js +28 -0
- package/components/AirportHeroCard.d.ts +60 -0
- package/components/AirportHeroCard.js +31 -0
- package/components/BusStopHeroCard.d.ts +37 -0
- package/components/BusStopHeroCard.js +14 -0
- package/components/DotMatrixBoard.d.ts +31 -0
- package/components/DotMatrixBoard.js +84 -0
- package/components/LazyButtonTooltips.d.ts +2 -0
- package/components/LazyButtonTooltips.js +8 -0
- package/components/NetworkVehicleHeroCard.d.ts +13 -0
- package/components/NetworkVehicleHeroCard.js +13 -0
- package/components/RailStationHeroCard.d.ts +46 -0
- package/components/RailStationHeroCard.js +20 -0
- package/components/SbbDepartureBoard.d.ts +26 -0
- package/components/SbbDepartureBoard.js +29 -0
- package/components/SplitFlapBoard.d.ts +25 -0
- package/components/SplitFlapBoard.js +58 -0
- package/components/TransportHeroBoard.d.ts +28 -0
- package/components/TransportHeroBoard.js +15 -0
- package/components/VehicleHeroCard.d.ts +51 -0
- package/components/VehicleHeroCard.js +21 -0
- package/components/airport-hero-card.css +68 -0
- package/components/dot-matrix-board.css +49 -0
- package/components/dot-matrix-font.d.ts +2 -0
- package/components/dot-matrix-font.js +61 -0
- package/components/sbb-departure-board.css +49 -0
- package/components/split-flap-board.css +45 -0
- package/components/transport-hero-cards.css +39 -0
- package/components/vehicle-hero-card.css +64 -0
- package/fonts/DM-Mono-OFL.txt +93 -0
- package/fonts/Inter-OFL.txt +93 -0
- package/fonts/dm-mono-latin-300.woff2 +0 -0
- package/fonts/dm-mono-latin-400.woff2 +0 -0
- package/fonts/dm-mono-latin-500.woff2 +0 -0
- package/fonts/dm-mono-latin-ext-300.woff2 +0 -0
- package/fonts/dm-mono-latin-ext-400.woff2 +0 -0
- package/fonts/dm-mono-latin-ext-500.woff2 +0 -0
- package/fonts/inter-cyrillic-400-600.woff2 +0 -0
- package/fonts/inter-cyrillic-ext-400-600.woff2 +0 -0
- package/fonts/inter-greek-400-600.woff2 +0 -0
- package/fonts/inter-greek-ext-400-600.woff2 +0 -0
- package/fonts/inter-latin-400-600.woff2 +0 -0
- package/fonts/inter-latin-ext-400-600.woff2 +0 -0
- package/fonts/inter-vietnamese-400-600.woff2 +0 -0
- package/fonts.css +105 -0
- package/mount-motion-study.d.ts +7 -2
- package/mount-motion-study.js +2 -2
- package/package.json +82 -3
- package/study-layout.css +65 -0
- package/use-airport-feed.d.ts +9 -0
- package/use-airport-feed.js +72 -0
- package/use-browser-location.d.ts +13 -0
- package/use-browser-location.js +39 -0
- package/use-json-asset.d.ts +9 -0
- package/use-json-asset.js +45 -0
- package/use-now-clock.d.ts +11 -0
- package/use-now-clock.js +45 -0
- package/use-pattern-network-day.d.ts +17 -0
- package/use-pattern-network-day.js +41 -0
- package/use-progressive-air-day.d.ts +1 -0
- package/use-progressive-chunks.d.ts +3 -0
- package/use-progressive-chunks.js +13 -4
- package/use-progressive-network-day.d.ts +1 -0
- package/use-progressive-road-study.d.ts +1 -0
- package/use-transition-value.d.ts +12 -0
- package/use-transition-value.js +46 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
export const smoothTransition = (progress) => progress * progress * (3 - 2 * progress);
|
|
3
|
+
export const cosineTransition = (progress) => 0.5 - Math.cos(progress * Math.PI) / 2;
|
|
4
|
+
/** Animate a scalar from its current value; interruptions reverse from the last frame.
|
|
5
|
+
* Reduced-motion changes settle immediately, including during an active transition. */
|
|
6
|
+
export function useTransitionValue(target, { durationMs = 1600, easing = smoothTransition, steps, } = {}) {
|
|
7
|
+
const current = useRef(target);
|
|
8
|
+
const [value, setValue] = useState(target);
|
|
9
|
+
const [transitioning, setTransitioning] = useState(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const from = current.current;
|
|
12
|
+
const motion = matchMedia('(prefers-reduced-motion: reduce)');
|
|
13
|
+
let frame = 0;
|
|
14
|
+
const finish = () => {
|
|
15
|
+
cancelAnimationFrame(frame);
|
|
16
|
+
current.current = target;
|
|
17
|
+
setValue(target);
|
|
18
|
+
setTransitioning(false);
|
|
19
|
+
};
|
|
20
|
+
if (!Number.isFinite(target) || !Number.isFinite(from))
|
|
21
|
+
return;
|
|
22
|
+
if (motion.matches || from === target || !(durationMs > 0) || !Number.isFinite(durationMs)) {
|
|
23
|
+
finish();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const started = performance.now();
|
|
27
|
+
setTransitioning(true);
|
|
28
|
+
const tick = (now) => {
|
|
29
|
+
const progress = Math.min(1, (now - started) / durationMs);
|
|
30
|
+
const eased = easing(progress);
|
|
31
|
+
const fraction = steps && Number.isFinite(steps) && steps > 0 ? Math.round(eased * steps) / steps : eased;
|
|
32
|
+
current.current = from + (target - from) * fraction;
|
|
33
|
+
setValue(current.current);
|
|
34
|
+
if (progress < 1)
|
|
35
|
+
frame = requestAnimationFrame(tick);
|
|
36
|
+
else
|
|
37
|
+
finish();
|
|
38
|
+
};
|
|
39
|
+
frame = requestAnimationFrame(tick);
|
|
40
|
+
const changed = () => { if (motion.matches)
|
|
41
|
+
finish(); };
|
|
42
|
+
motion.addEventListener('change', changed);
|
|
43
|
+
return () => { cancelAnimationFrame(frame); motion.removeEventListener('change', changed); };
|
|
44
|
+
}, [target, durationMs, easing, steps]);
|
|
45
|
+
return { value, transitioning };
|
|
46
|
+
}
|