@@ -373,93 +373,95 @@ export default class CropperSelection extends CropperElement {
373
373
protected $handleAction ( event : Event ) : void {
374
374
const { currentTarget, detail } = event as CustomEvent ;
375
375
376
- if ( currentTarget && detail ) {
377
- const { relatedEvent } = detail ;
378
- let { action } = detail ;
379
-
380
- // Switching to another selection
381
- if ( ! action && this . multiple ) {
382
- // Get the `action` property from the focusing in selection
383
- action = this . $action || relatedEvent ?. target . action ;
384
- this . $action = action ;
385
- }
386
-
387
- if ( ! action
388
- || ( this . hidden && action !== ACTION_SELECT )
389
- || ( this . multiple && ! this . active && action !== ACTION_SCALE ) ) {
390
- return ;
391
- }
376
+ if ( ! currentTarget || ! detail ) {
377
+ return ;
378
+ }
392
379
393
- const moveX = detail . endX - detail . startX ;
394
- const moveY = detail . endY - detail . startY ;
395
- const { width, height } = this ;
396
- let { aspectRatio } = this ;
380
+ const { relatedEvent } = detail ;
381
+ let { action } = detail ;
397
382
398
- // Locking aspect ratio by holding shift key
399
- if ( ! isPositiveNumber ( aspectRatio ) && ( event as PointerEvent ) . shiftKey ) {
400
- aspectRatio = isPositiveNumber ( width ) && isPositiveNumber ( height ) ? width / height : 1 ;
401
- }
383
+ // Switching to another selection
384
+ if ( ! action && this . multiple ) {
385
+ // Get the `action` property from the focusing in selection
386
+ action = this . $action || relatedEvent ?. target . action ;
387
+ this . $action = action ;
388
+ }
402
389
403
- switch ( action ) {
404
- case ACTION_SELECT : {
405
- const { $canvas } = this ;
406
- const offset = getOffset ( currentTarget as Element ) ;
390
+ if ( ! action
391
+ || ( this . hidden && action !== ACTION_SELECT )
392
+ || ( this . multiple && ! this . active && action !== ACTION_SCALE ) ) {
393
+ return ;
394
+ }
407
395
408
- ( this . multiple && ! this . hidden ? this . $createSelection ( ) : this ) . $change (
409
- detail . startX - offset . left ,
410
- detail . startY - offset . top ,
411
- moveX ,
412
- moveY ,
413
- aspectRatio ,
414
- ) ;
396
+ const moveX = detail . endX - detail . startX ;
397
+ const moveY = detail . endY - detail . startY ;
398
+ const { width, height } = this ;
399
+ let { aspectRatio } = this ;
415
400
416
- action = ACTION_RESIZE_SOUTHEAST ;
401
+ // Locking aspect ratio by holding shift key
402
+ if ( ! isPositiveNumber ( aspectRatio ) && ( event as PointerEvent ) . shiftKey ) {
403
+ aspectRatio = isPositiveNumber ( width ) && isPositiveNumber ( height ) ? width / height : 1 ;
404
+ }
417
405
418
- if ( moveX < 0 ) {
419
- if ( moveY > 0 ) {
420
- action = ACTION_RESIZE_SOUTHWEST ;
421
- } else if ( moveY < 0 ) {
422
- action = ACTION_RESIZE_NORTHWEST ;
423
- }
424
- } else if ( moveX > 0 ) {
425
- if ( moveY < 0 ) {
426
- action = ACTION_RESIZE_NORTHEAST ;
427
- }
406
+ switch ( action ) {
407
+ case ACTION_SELECT : {
408
+ const { $canvas } = this ;
409
+ const offset = getOffset ( currentTarget as Element ) ;
410
+
411
+ ( this . multiple && ! this . hidden ? this . $createSelection ( ) : this ) . $change (
412
+ detail . startX - offset . left ,
413
+ detail . startY - offset . top ,
414
+ moveX ,
415
+ moveY ,
416
+ aspectRatio ,
417
+ ) ;
418
+
419
+ if ( moveX < 0 ) {
420
+ if ( moveY > 0 ) {
421
+ action = ACTION_RESIZE_SOUTHWEST ;
422
+ } else {
423
+ action = ACTION_RESIZE_NORTHWEST ;
428
424
}
429
-
430
- if ( $canvas ) {
431
- ( $canvas as any ) . $action = action ;
425
+ } else if ( moveX > 0 ) {
426
+ if ( moveY < 0 ) {
427
+ action = ACTION_RESIZE_NORTHEAST ;
428
+ } else {
429
+ action = ACTION_RESIZE_SOUTHEAST ;
432
430
}
433
- break ;
434
431
}
435
432
436
- case ACTION_MOVE :
437
- if ( this . movable && (
438
- this . dynamic
439
- || ( this . $actionStartTarget && this . contains ( this . $actionStartTarget as Node ) )
440
- ) ) {
441
- this . $move ( moveX , moveY ) ;
442
- }
443
- break ;
444
-
445
- case ACTION_SCALE :
446
- if ( relatedEvent && this . zoomable && (
447
- this . dynamic
448
- || this . contains ( relatedEvent . target as Node )
449
- ) ) {
450
- const offset = getOffset ( currentTarget as Element ) ;
451
-
452
- this . $zoom (
453
- detail . scale ,
454
- relatedEvent . pageX - offset . left ,
455
- relatedEvent . pageY - offset . top ,
456
- ) ;
457
- }
458
- break ;
459
-
460
- default :
461
- this . $resize ( action , moveX , moveY , aspectRatio ) ;
433
+ if ( $canvas ) {
434
+ ( $canvas as any ) . $action = action ;
435
+ }
436
+ break ;
462
437
}
438
+
439
+ case ACTION_MOVE :
440
+ if ( this . movable && (
441
+ this . dynamic
442
+ || ( this . $actionStartTarget && this . contains ( this . $actionStartTarget as Node ) )
443
+ ) ) {
444
+ this . $move ( moveX , moveY ) ;
445
+ }
446
+ break ;
447
+
448
+ case ACTION_SCALE :
449
+ if ( relatedEvent && this . zoomable && (
450
+ this . dynamic
451
+ || this . contains ( relatedEvent . target as Node )
452
+ ) ) {
453
+ const offset = getOffset ( currentTarget as Element ) ;
454
+
455
+ this . $zoom (
456
+ detail . scale ,
457
+ relatedEvent . pageX - offset . left ,
458
+ relatedEvent . pageY - offset . top ,
459
+ ) ;
460
+ }
461
+ break ;
462
+
463
+ default :
464
+ this . $resize ( action , moveX , moveY , aspectRatio ) ;
463
465
}
464
466
}
465
467
0 commit comments