@@ -8,7 +8,7 @@ import { CropperWrapper } from './components/service';
8
8
import { ResizeEvent , MoveEvent } from ' ./core/events' ;
9
9
import { isLocal , isCrossOriginURL , isUndefined , addTimestamp , getSettings , parseNumber } from ' ./core/utils' ;
10
10
import { arrayBufferToDataURL , getImageTransforms , getStyleTransforms , prepareSource , parseImage } from ' ./core/image' ;
11
- import { ALL_DIRECTIONS , MINIMAL_PERCENT_SIZE , IMAGE_RESTRICTIONS } from ' ./core/constants' ;
11
+ import { ALL_DIRECTIONS , MINIMAL_PERCENT_SIZE , IMAGE_RESTRICTIONS , DEFAULT_COORDINATES } from ' ./core/constants' ;
12
12
import * as algorithms from ' ./core/algorithms' ;
13
13
14
14
const cn = bem (' vue-advanced-cropper' );
@@ -169,17 +169,11 @@ export default {
169
169
width: null ,
170
170
height: null ,
171
171
},
172
- coordinates: {
173
- left: 0 ,
174
- top: 0 ,
175
- width: 0 ,
176
- height: 0 ,
172
+ coordinates: {
173
+ ... DEFAULT_COORDINATES
177
174
},
178
- stencilCoordinates: {
179
- left: 0 ,
180
- top: 0 ,
181
- width: 0 ,
182
- height: 0 ,
175
+ stencilCoordinates: {
176
+ ... DEFAULT_COORDINATES
183
177
},
184
178
frozenDirections: {
185
179
width: false ,
@@ -362,11 +356,7 @@ export default {
362
356
window .addEventListener (' resize' , this .onResizeWindow );
363
357
window .addEventListener (' orientationchange' , this .onResizeWindow );
364
358
this .$refs .image .addEventListener (' load' , () => {
365
- // After loading image the current component can be unmounted
366
- // Therefore there is a workaround to prevent processing the following code
367
- if (this .$refs .image ) {
368
- this .refreshImage ().then (this .resetCoordinates );
369
- }
359
+ this .onLoadImage ();
370
360
});
371
361
this .onChangeImage ();
372
362
},
@@ -485,6 +475,17 @@ export default {
485
475
this .clearImage ();
486
476
}
487
477
},
478
+ onLoadImage () {
479
+ // After loading image the current component can be unmounted
480
+ // Therefore there is a workaround to prevent processing the following code
481
+ if (this .$refs .image && ! this .imageLoaded ) {
482
+ this .imageLoaded = true ;
483
+ this .refreshImage ().then (() => {
484
+ this .resetCoordinates ();
485
+ this .$emit (' ready' );
486
+ });
487
+ }
488
+ },
488
489
onParseImage ({ arrayBuffer, orientation }) {
489
490
if (arrayBuffer && orientation && isLocal (this .src )) {
490
491
this .imageAttributes .src = arrayBufferToDataURL (arrayBuffer);
@@ -495,7 +496,7 @@ export default {
495
496
Vue .nextTick (() => {
496
497
const image = this .$refs .image ;
497
498
if (image && image .complete ) {
498
- this .refreshImage (). then ( this . resetCoordinates );
499
+ this .onLoadImage ( );
499
500
}
500
501
});
501
502
},
@@ -736,24 +737,22 @@ export default {
736
737
if (this .delayedTransforms ) {
737
738
transforms .push (... Array .isArray (this .delayedTransforms ) ? this .delayedTransforms : [this .delayedTransforms ]);
738
739
}
739
-
740
740
this .resetWorldTransforms ();
741
741
this .applyTransforms (transforms);
742
742
this .delayedTransforms = null ;
743
- this .imageLoaded = true ;
744
743
},
745
744
clearImage () {
746
745
const stretcher = this .$refs .stretcher ;
747
746
this .imageLoaded = false ;
748
- this .onChangeCoordinates ({
749
- left: 0 ,
750
- top: 0 ,
751
- width: 0 ,
752
- height: 0 ,
753
- }, false );
754
747
setTimeout (() => {
755
748
stretcher .style .height = ' auto' ;
756
749
stretcher .style .width = ' auto' ;
750
+ this .onChangeCoordinates ({ ... DEFAULT_COORDINATES }, false );
751
+ this .updateStencilCoordinates ({ ... DEFAULT_COORDINATES });
752
+ this .boundarySize = {
753
+ width: 0 ,
754
+ height: 0 ,
755
+ };
757
756
}, this .transitionTime );
758
757
},
759
758
refreshImage () {
0 commit comments