@@ -3,6 +3,11 @@ import { useItem, useTimelineContext } from "dnd-timeline";
33import { Gauge , MessageSquare , Scissors , ZoomIn } from "lucide-react" ;
44import { useMemo } from "react" ;
55import { cn } from "@/lib/utils" ;
6+ import {
7+ DEFAULT_ZOOM_IN_MS ,
8+ DEFAULT_ZOOM_OUT_MS ,
9+ getDurations ,
10+ } from "../videoPlayback/zoomRegionUtils" ;
611import glassStyles from "./ItemGlass.module.css" ;
712
813interface ItemProps {
@@ -86,6 +91,16 @@ export default function Item({
8691 const MIN_ITEM_PX = 6 ;
8792 const safeItemStyle = { ...itemStyle , minWidth : MIN_ITEM_PX } ;
8893
94+ const { zoomIn, zoomOut } = useMemo ( ( ) => {
95+ if ( ! isZoom ) return { zoomIn : 0 , zoomOut : 0 } ;
96+ return getDurations ( {
97+ startMs : span . start ,
98+ endMs : span . end ,
99+ zoomInDurationMs,
100+ zoomOutDurationMs,
101+ } ) ;
102+ } , [ isZoom , span . start , span . end , zoomInDurationMs , zoomOutDurationMs ] ) ;
103+
89104 return (
90105 < div
91106 ref = { setNodeRef }
@@ -114,14 +129,14 @@ export default function Item({
114129 < div
115130 className = "absolute top-0 bottom-0 left-0 bg-white/10 border-r border-white/20 pointer-events-none"
116131 style = { {
117- width : `${ ( ( zoomInDurationMs ?? 1522.575 ) / ( span . end - span . start ) ) * 100 } %` ,
132+ width : `${ ( zoomIn / ( span . end - span . start ) ) * 100 } %` ,
118133 } }
119134 />
120135 { /* Draggable handle for Transition In */ }
121136 < div
122137 className = "absolute top-0 bottom-0 w-2 cursor-col-resize z-20 group-hover:bg-white/5 transition-colors"
123138 style = { {
124- left : `${ ( ( zoomInDurationMs ?? 1522.575 ) / ( span . end - span . start ) ) * 100 } %` ,
139+ left : `${ ( zoomIn / ( span . end - span . start ) ) * 100 } %` ,
125140 transform : "translateX(-50%)" ,
126141 } }
127142 onPointerDown = { ( e ) => {
@@ -130,17 +145,18 @@ export default function Item({
130145 const target = e . currentTarget ;
131146 target . setPointerCapture ( e . pointerId ) ;
132147
148+ const startX = e . clientX ;
149+ const initialZoomIn = zoomInDurationMs ?? DEFAULT_ZOOM_IN_MS ;
150+ const initialZoomOut = zoomOutDurationMs ?? DEFAULT_ZOOM_OUT_MS ;
151+
133152 const onPointerMove = ( moveEvent : PointerEvent ) => {
134- const deltaPx = moveEvent . clientX - e . clientX ;
153+ const deltaPx = moveEvent . clientX - startX ;
135154 const deltaMs = pixelsToValue ( deltaPx ) ;
136155 const newDuration = Math . max (
137156 0 ,
138- Math . min (
139- ( zoomInDurationMs ?? 1522.575 ) + deltaMs ,
140- span . end - span . start - ( zoomOutDurationMs ?? 1015.05 ) ,
141- ) ,
157+ Math . min ( initialZoomIn + deltaMs , span . end - span . start - initialZoomOut ) ,
142158 ) ;
143- onZoomDurationChange ?.( id , newDuration , zoomOutDurationMs ?? 1015.05 ) ;
159+ onZoomDurationChange ?.( id , newDuration , initialZoomOut ) ;
144160 } ;
145161
146162 const onPointerUp = ( ) => {
@@ -157,14 +173,14 @@ export default function Item({
157173 < div
158174 className = "absolute top-0 bottom-0 right-0 bg-white/10 border-l border-white/20 pointer-events-none"
159175 style = { {
160- width : `${ ( ( zoomOutDurationMs ?? 1015.05 ) / ( span . end - span . start ) ) * 100 } %` ,
176+ width : `${ ( zoomOut / ( span . end - span . start ) ) * 100 } %` ,
161177 } }
162178 />
163179 { /* Draggable handle for Transition Out */ }
164180 < div
165181 className = "absolute top-0 bottom-0 w-2 cursor-col-resize z-20 group-hover:bg-white/5 transition-colors"
166182 style = { {
167- right : `${ ( ( zoomOutDurationMs ?? 1015.05 ) / ( span . end - span . start ) ) * 100 } %` ,
183+ right : `${ ( zoomOut / ( span . end - span . start ) ) * 100 } %` ,
168184 transform : "translateX(50%)" ,
169185 } }
170186 onPointerDown = { ( e ) => {
@@ -173,17 +189,18 @@ export default function Item({
173189 const target = e . currentTarget ;
174190 target . setPointerCapture ( e . pointerId ) ;
175191
192+ const startX = e . clientX ;
193+ const initialZoomIn = zoomInDurationMs ?? DEFAULT_ZOOM_IN_MS ;
194+ const initialZoomOut = zoomOutDurationMs ?? DEFAULT_ZOOM_OUT_MS ;
195+
176196 const onPointerMove = ( moveEvent : PointerEvent ) => {
177- const deltaPx = e . clientX - moveEvent . clientX ; // Inverted because right-anchored
197+ const deltaPx = startX - moveEvent . clientX ; // Inverted because right-anchored
178198 const deltaMs = pixelsToValue ( deltaPx ) ;
179199 const newDuration = Math . max (
180200 0 ,
181- Math . min (
182- ( zoomOutDurationMs ?? 1015.05 ) + deltaMs ,
183- span . end - span . start - ( zoomInDurationMs ?? 1522.575 ) ,
184- ) ,
201+ Math . min ( initialZoomOut + deltaMs , span . end - span . start - initialZoomIn ) ,
185202 ) ;
186- onZoomDurationChange ?.( id , zoomInDurationMs ?? 1522.575 , newDuration ) ;
203+ onZoomDurationChange ?.( id , initialZoomIn , newDuration ) ;
187204 } ;
188205
189206 const onPointerUp = ( ) => {
0 commit comments