constrain progress display 0-1

This commit is contained in:
Sudev Kiyada 2025-07-29 09:44:46 +05:30
parent 770a7d1c22
commit 86d84173a4
Failed to extract signature
2 changed files with 6 additions and 4 deletions

View file

@ -1,6 +1,6 @@
import { UAParser } from 'ua-parser-js';
import videoDecoder from './videoDecoder';
import { debounce, isScrollPositionAtTarget, map } from './utils';
import { debounce, isScrollPositionAtTarget, map, constrain } from './utils';
import { createComponentState, type ScrollerVideoState } from './state.svelte';
interface ScrollerVideoArgs {
@ -954,8 +954,10 @@ class ScrollerVideo {
*/
updateDebugInfo() {
this.componentState.generalData.src = this.src;
this.componentState.generalData.videoPercentage = parseFloat(
this.videoPercentage.toFixed(4)
this.componentState.generalData.videoPercentage = constrain(
parseFloat(this.videoPercentage.toFixed(4)),
0,
1
);
this.componentState.generalData.frameRate = parseFloat(
this.frameRate.toFixed(2)

View file

@ -73,7 +73,7 @@ export const isScrollPositionAtTarget = (
* @param {number} high - The upper bound.
* @returns {number} The constrained value.
*/
function constrain(n: number, low: number, high: number): number {
export function constrain(n: number, low: number, high: number): number {
return Math.max(Math.min(n, high), low);
}