diff --git a/packages/core/src/animation/index.ts b/packages/core/src/animation/index.ts new file mode 100644 index 0000000..98308e2 --- /dev/null +++ b/packages/core/src/animation/index.ts @@ -0,0 +1 @@ +export { useSmoothedValue } from './useSmoothedValue'; diff --git a/packages/core/src/animation/useSmoothedValue.ts b/packages/core/src/animation/useSmoothedValue.ts new file mode 100644 index 0000000..2370aa8 --- /dev/null +++ b/packages/core/src/animation/useSmoothedValue.ts @@ -0,0 +1,19 @@ +import { useTransition, TransitionPresets } from '@vueuse/core'; +import type { MaybeRefOrGetter } from 'vue'; + +/** + * Returns a smoothed version of a numeric value using easeOutExpo easing. + * Works for any continuously-updating number: gauge needles, digital readouts, etc. + * + * @param source Reactive numeric source (ref, computed, or getter) + * @param duration Transition duration in ms; 0 = instant (no easing) + */ +export function useSmoothedValue( + source: MaybeRefOrGetter, + duration: MaybeRefOrGetter, +) { + return useTransition(source, { + duration, + transition: TransitionPresets.easeOutExpo, + }); +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8225e5b..8b904d5 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,6 +1,7 @@ import './math'; export { PrerenderedSvgImage } from './components'; +export * from './animation'; export * from './flightgear-properties'; export * from './flightgear-http'; export { clamp, installPanelMath, interpolate, panelMathMixin } from './math';