File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed
extensions-builtin/canvas-zoom-and-pan/javascript Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -475,6 +475,14 @@ onUiLoaded(async() => {
475475 input . click ( ) ;
476476 if ( ! withoutValue ) {
477477 const maxValue = parseFloat ( input . getAttribute ( "max" ) ) || 100 ;
478+ // allow brush size up to 1/2 diagonal of the image, beyond gradio's arbitrary limit
479+ const canvasImg = gradioApp ( ) . querySelector ( `${ elemId } img` ) ;
480+ if ( canvasImg ) {
481+ const maxDiameter = Math . sqrt ( canvasImg . naturalWidth ** 2 + canvasImg . naturalHeight ** 2 ) / 2 ;
482+ if ( maxDiameter > maxValue ) {
483+ input . setAttribute ( "max" , maxDiameter ) ;
484+ }
485+ }
478486 const brush_factor = deltaY > 0 ? 1 - opts . canvas_hotkey_brush_factor : 1 + opts . canvas_hotkey_brush_factor ;
479487 const currentRadius = parseFloat ( input . value ) ;
480488 let delta = Math . sqrt ( currentRadius ** 2 * brush_factor ) - currentRadius ;
@@ -483,16 +491,7 @@ onUiLoaded(async() => {
483491 delta = deltaY > 0 ? - 1 : 1 ;
484492 }
485493 const newValue = currentRadius + delta ;
486- // allow increasing the brush size beyond what's limited by gradio up to 1/2 diagonal of the image
487- if ( newValue > maxValue ) {
488- const canvasImg = gradioApp ( ) . querySelector ( `${ elemId } img` ) ;
489- if ( canvasImg ) {
490- const maxDiameter = Math . sqrt ( canvasImg . naturalWidth ** 2 + canvasImg . naturalHeight ** 2 ) / 2 ;
491- if ( newValue < maxDiameter ) {
492- input . setAttribute ( "max" , newValue ) ;
493- }
494- }
495- }
494+
496495 input . value = Math . max ( newValue , 1 ) ;
497496 input . dispatchEvent ( new Event ( "change" ) ) ;
498497 }
You can’t perform that action at this time.
0 commit comments