diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-04-20 11:31:17 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-04-20 11:31:17 +0200 |
| commit | 3e89d2998588f8e35c524e523ba2ee853f0f6475 (patch) | |
| tree | 57221f96c1259b3b07e3ddf8c1adefc502b9d8eb /apps/web/src/lib/timeline/zoom-utils.ts | |
| parent | 729d10592f4e802f91c555c309ff3ba4b119f843 (diff) | |
| download | opencut-3e89d2998588f8e35c524e523ba2ee853f0f6475.tar.gz | |
refactor: restructure files to their domains, new preview overlay system, and dep graph
Diffstat (limited to 'apps/web/src/lib/timeline/zoom-utils.ts')
| -rw-r--r-- | apps/web/src/lib/timeline/zoom-utils.ts | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/apps/web/src/lib/timeline/zoom-utils.ts b/apps/web/src/lib/timeline/zoom-utils.ts deleted file mode 100644 index 680f8d0d..00000000 --- a/apps/web/src/lib/timeline/zoom-utils.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { - BASE_TIMELINE_PIXELS_PER_SECOND, - TIMELINE_ZOOM_MAX, -} from "@/lib/timeline/scale"; -import { TICKS_PER_SECOND } from "@/lib/wasm"; - -const PADDING_MAX_RATIO = 0.75; -const PADDING_MIN_RATIO = 0.15; -const PADDING_MIN_AT_ZOOM_PERCENT = 0.2; - -export function getTimelineZoomMin({ - duration, - containerWidth, -}: { - duration: number; - containerWidth: number | null | undefined; -}): number { - const safeDurationSeconds = Math.max(duration / TICKS_PER_SECOND, 1); - const safeContainerWidth = containerWidth ?? 1000; - const contentRatioAtMinZoom = 1 - PADDING_MAX_RATIO; - const availableWidth = safeContainerWidth * contentRatioAtMinZoom; - const zoomToFit = - availableWidth / (safeDurationSeconds * BASE_TIMELINE_PIXELS_PER_SECOND); - - return Math.min(TIMELINE_ZOOM_MAX, zoomToFit); -} - -export function getTimelinePaddingPx({ - containerWidth, - zoomLevel, - minZoom, -}: { - containerWidth: number; - zoomLevel: number; - minZoom: number; -}): number { - const zoomPercent = getZoomPercent({ zoomLevel, minZoom }); - const paddingTransitionPercent = Math.min( - zoomPercent / PADDING_MIN_AT_ZOOM_PERCENT, - 1, - ); - const paddingRatio = - PADDING_MAX_RATIO - - (PADDING_MAX_RATIO - PADDING_MIN_RATIO) * paddingTransitionPercent; - - return containerWidth * paddingRatio; -} - -export function getZoomPercent({ - zoomLevel, - minZoom, -}: { - zoomLevel: number; - minZoom: number; -}): number { - return (zoomLevel - minZoom) / (TIMELINE_ZOOM_MAX - minZoom); -} - -/** - * convert linear slider position (0-1) to exponential zoom level. - * at low slider values, zoom changes are small. at high values, changes are large. - */ -export function sliderToZoom({ - sliderPosition, - minZoom, - maxZoom = TIMELINE_ZOOM_MAX, -}: { - sliderPosition: number; - minZoom: number; - maxZoom?: number; -}): number { - const clampedPosition = Math.max(0, Math.min(1, sliderPosition)); - return minZoom * (maxZoom / minZoom) ** clampedPosition; -} - -/** - * convert exponential zoom level to linear slider position (0-1). - */ -export function zoomToSlider({ - zoomLevel, - minZoom, - maxZoom = TIMELINE_ZOOM_MAX, -}: { - zoomLevel: number; - minZoom: number; - maxZoom?: number; -}): number { - const clampedZoom = Math.max(minZoom, Math.min(maxZoom, zoomLevel)); - return Math.log(clampedZoom / minZoom) / Math.log(maxZoom / minZoom); -} |
