Moved from private git forge to gitlab

This commit is contained in:
2025-03-07 18:43:08 -06:00
parent 4e40e31f15
commit 0ad8ca09c2
39 changed files with 3643 additions and 688 deletions

24
src/utils/interaction.ts Normal file
View File

@ -0,0 +1,24 @@
import { ViewportOffset, CONSTANTS } from '../types';
import { clamp, calculateDistance } from './math';
// Zoom-related functions
export const calculateZoomDelta = (
wheelDelta: number,
accelerationFactor: number,
baseMultiplier = 0.001
): number => clamp(wheelDelta * baseMultiplier * accelerationFactor, -0.5, 0.5);
export const calculateInitialViewport = (initialZoom: number): ViewportOffset => ({
x: (CONSTANTS.VIRTUAL_CANVAS_SIZE - window.innerWidth / initialZoom) / 2,
y: (CONSTANTS.VIRTUAL_CANVAS_SIZE - window.innerHeight / initialZoom) / 2,
});
export const clampZoom = (zoom: number): number =>
clamp(zoom, CONSTANTS.ZOOM_LEVELS.min, CONSTANTS.ZOOM_LEVELS.max);
// Touch-related functions
export const calculateTouchDistance = (touch1: React.Touch | Touch, touch2: React.Touch | Touch): number =>
calculateDistance(touch1.clientX, touch1.clientY, touch2.clientX, touch2.clientY);
export const calculateZoomFactor = (currentDistance: number, startDistance: number): number =>
startDistance > 0 ? currentDistance / startDistance : 1;