@@ -32,7 +32,16 @@ const HANDLE_STYLES_OVERRIDE = {
3232 left : undefined ,
3333} ;
3434
35- const MIN_FRAME_SIZE = 340 ;
35+ // The minimum width of the frame (in px) while resizing.
36+ const FRAME_MIN_WIDTH = 340 ;
37+ // The reference width of the frame (in px) used to calculate the aspect ratio.
38+ const FRAME_REFERENCE_WIDTH = 1300 ;
39+ // 9 : 19.5 is the target aspect ratio enforced (when possible) while resizing.
40+ const FRAME_TARGET_ASPECT_RATIO = 9 / 19.5 ;
41+ // The minimum distance (in px) between the frame resize handle and the
42+ // viewport's edge. If the frame is resized to be closer to the viewport's edge
43+ // than this distance, then "canvas mode" will be enabled.
44+ const SNAP_TO_EDIT_CANVAS_MODE_THRESHOLD = 200 ;
3645
3746function calculateNewHeight ( width , initialAspectRatio ) {
3847 const lerp = ( a , b , amount ) => {
@@ -46,15 +55,16 @@ function calculateNewHeight( width, initialAspectRatio ) {
4655 0 ,
4756 Math . min (
4857 1 ,
49- ( width - MIN_FRAME_SIZE ) / ( 1300 - MIN_FRAME_SIZE )
58+ ( width - FRAME_MIN_WIDTH ) /
59+ ( FRAME_REFERENCE_WIDTH - FRAME_MIN_WIDTH )
5060 )
5161 ) ;
5262
5363 // Calculate the height based on the intermediate aspect ratio
54- // ensuring the frame arrives at a 9:19.5 aspect ratio.
64+ // ensuring the frame arrives at the target aspect ratio.
5565 const intermediateAspectRatio = lerp (
5666 initialAspectRatio ,
57- 9 / 19.5 ,
67+ FRAME_TARGET_ASPECT_RATIO ,
5868 lerpFactor
5969 ) ;
6070
@@ -140,7 +150,7 @@ function ResizableFrame( {
140150 const remainingWidth =
141151 ref . ownerDocument . documentElement . offsetWidth - ref . offsetWidth ;
142152
143- if ( remainingWidth > 200 ) {
153+ if ( remainingWidth > SNAP_TO_EDIT_CANVAS_MODE_THRESHOLD ) {
144154 // Reset the initial aspect ratio if the frame is resized slightly
145155 // above the sidebar but not far enough to trigger full screen.
146156 setFrameSize ( { width : '100%' , height : '100%' } ) ;
@@ -191,7 +201,7 @@ function ResizableFrame( {
191201 left : HANDLE_STYLES_OVERRIDE ,
192202 right : HANDLE_STYLES_OVERRIDE ,
193203 } }
194- minWidth = { MIN_FRAME_SIZE }
204+ minWidth = { FRAME_MIN_WIDTH }
195205 maxWidth = { isFullWidth ? '100%' : '150%' }
196206 maxHeight = { '100%' }
197207 onMouseOver = { ( ) => setIsHovering ( true ) }
0 commit comments