From 379cf6164d125007ba305b29b760b91b7097f7e5 Mon Sep 17 00:00:00 2001 From: Tuomas Kuosmanen Date: Wed, 10 Jun 2026 17:00:23 +0300 Subject: [PATCH] Add smoothing function to core, to allow simulating inertia on gauge pointers etc. Simulator flight model data might give you instant values, while physical gauges have delay and inertia. New files: -index.ts, useSmoothedValue.ts in packages/core/src/animation: Use Vue's transition to return a smoothed change of the value over time. Duration of 0 means no smoothing happens.. - packages/core/src/index.ts: export useSmoothedValue from core. --- packages/core/src/animation/index.ts | 1 + .../core/src/animation/useSmoothedValue.ts | 19 +++++++++++++++++++ packages/core/src/index.ts | 1 + 3 files changed, 21 insertions(+) create mode 100644 packages/core/src/animation/index.ts create mode 100644 packages/core/src/animation/useSmoothedValue.ts 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';