@@ -344,7 +344,6 @@ function ppom_set_croppie_options(file_name, viewport, image_id) {
344344 option = get_responsive_croppie_options ( option , file_list_preview_containers [ file_name ] [ 'container_width' ] ) ;
345345 // console.log($filelist_DIV[file_name]['croppie'][image_id]);
346346 file_list_preview_containers [ file_name ] [ 'croppie' ] [ image_id ] . croppie ( option ) ;
347- file_list_preview_containers [ file_name ] [ 'croppie' ] [ image_id ] . find ( '.ppom-cropping-size' ) . css ( 'width' , '100%' ) ;
348347 }
349348 } ) ;
350349}
@@ -746,31 +745,45 @@ function ppom_generate_cropper_data_for_cart(field_name) {
746745function get_responsive_croppie_options ( baseOptions , max_width ) {
747746 const boundary = baseOptions . boundary || { } ;
748747
749- if ( boundary . width && boundary . height && max_width >= boundary . width ) {
748+ const boundaryWidthOriginal = Number ( boundary . width ) ;
749+ const boundaryHeightOriginal = Number ( boundary . height ) ;
750+ if ( ! Number . isFinite ( boundaryWidthOriginal ) || ! Number . isFinite ( boundaryHeightOriginal ) || boundaryWidthOriginal <= 0 || boundaryHeightOriginal <= 0 ) {
751+ return baseOptions ;
752+ }
753+ if ( max_width >= boundaryWidthOriginal ) {
754+ return baseOptions ;
755+ }
756+ if ( ! Number . isFinite ( max_width ) ) {
750757 return baseOptions ;
751758 }
752-
753759 // Use container width as the boundary.
754- const aspectRatio = boundary . height / boundary . width || 1 ; // original height/width ratio
760+ const aspectRatio = boundaryHeightOriginal / boundaryWidthOriginal || 1 ; // original height/width ratio
755761 const boundaryWidth = Math . floor ( max_width ) ;
756762 const boundaryHeight = Math . floor ( boundaryWidth * aspectRatio ) ;
757763
758- if ( baseOptions . viewport && baseOptions . viewport . width && baseOptions . viewport . height ) {
759- const scale = boundaryWidth / boundary . width ;
760- const viewportWidth = Math . floor ( baseOptions . viewport . width * scale ) ;
761- const viewportHeight = Math . floor ( baseOptions . viewport . height * scale ) ;
762-
763- // Scale viewport proportionally and ensure it fits within the new boundary.
764- baseOptions . viewport . width = Math . min ( viewportWidth , boundaryWidth - 2 ) ;
765- baseOptions . viewport . height = Math . min ( viewportHeight , boundaryHeight - 2 ) ;
766- }
767-
768- return {
764+ // Build the result as a new object so baseOptions (and its nested viewport,
765+ // which is a live reference into ppom_file_vars.croppie_options) is never mutated.
766+ const result = {
769767 ...baseOptions ,
770768 boundary : {
771769 ...baseOptions . boundary ,
772770 width : boundaryWidth ,
773771 height : boundaryHeight ,
774772 } ,
775773 } ;
774+
775+ if ( baseOptions . viewport && baseOptions . viewport . width && baseOptions . viewport . height ) {
776+ const scale = boundaryWidth / boundaryWidthOriginal ;
777+ const viewportWidth = Math . floor ( baseOptions . viewport . width * scale ) ;
778+ const viewportHeight = Math . floor ( baseOptions . viewport . height * scale ) ;
779+
780+ // Scale viewport proportionally and ensure it fits within the new boundary.
781+ result . viewport = {
782+ ...baseOptions . viewport ,
783+ width : Math . min ( viewportWidth , boundaryWidth - 2 ) ,
784+ height : Math . min ( viewportHeight , boundaryHeight - 2 ) ,
785+ } ;
786+ }
787+
788+ return result ;
776789}
0 commit comments