@@ -38,7 +38,8 @@ type RegionConvertParams = {
3838} ;
3939
4040class TransformManager implements EditToolManager {
41- hasChanges : boolean = $derived . by ( ( ) => this . checkEdits ( ) ) ;
41+ canReset : boolean = $derived . by ( ( ) => this . checkEdits ( ) ) ;
42+ hasChanges : boolean = $state ( false ) ;
4243
4344 darkenLevel = $state ( 0.65 ) ;
4445 isInteracting = $state ( false ) ;
@@ -56,7 +57,7 @@ class TransformManager implements EditToolManager {
5657 cropAspectRatio = $state ( 'free' ) ;
5758 originalImageSize = $state < ImageDimensions > ( { width : 1000 , height : 1000 } ) ;
5859 region = $state ( { x : 0 , y : 0 , width : 100 , height : 100 } ) ;
59- preveiwImgSize = $derived ( {
60+ previewImageSize = $derived ( {
6061 width : this . cropImageSize . width * this . cropImageScale ,
6162 height : this . cropImageSize . height * this . cropImageScale ,
6263 } ) ;
@@ -73,6 +74,7 @@ class TransformManager implements EditToolManager {
7374 edits = $derived . by ( ( ) => this . getEdits ( ) ) ;
7475
7576 setAspectRatio ( aspectRatio : string ) {
77+ this . hasChanges = true ;
7678 this . cropAspectRatio = aspectRatio ;
7779
7880 if ( ! this . imgElement || ! this . cropAreaEl ) {
@@ -88,8 +90,8 @@ class TransformManager implements EditToolManager {
8890
8991 checkEdits ( ) {
9092 return (
91- Math . abs ( this . preveiwImgSize . width - this . region . width ) > 2 ||
92- Math . abs ( this . preveiwImgSize . height - this . region . height ) > 2 ||
93+ Math . abs ( this . previewImageSize . width - this . region . width ) > 2 ||
94+ Math . abs ( this . previewImageSize . height - this . region . height ) > 2 ||
9395 this . mirrorHorizontal ||
9496 this . mirrorVertical ||
9597 this . normalizedRotation !== 0
@@ -98,8 +100,8 @@ class TransformManager implements EditToolManager {
98100
99101 checkCropEdits ( ) {
100102 return (
101- Math . abs ( this . preveiwImgSize . width - this . region . width ) > 2 ||
102- Math . abs ( this . preveiwImgSize . height - this . region . height ) > 2
103+ Math . abs ( this . previewImageSize . width - this . region . width ) > 2 ||
104+ Math . abs ( this . previewImageSize . height - this . region . height ) > 2
103105 ) ;
104106 }
105107
@@ -232,9 +234,12 @@ class TransformManager implements EditToolManager {
232234 this . originalImageSize = { width : 1000 , height : 1000 } ;
233235 this . cropImageScale = 1 ;
234236 this . cropAspectRatio = 'free' ;
237+ this . hasChanges = false ;
235238 }
236239
237240 mirror ( axis : 'horizontal' | 'vertical' ) {
241+ this . hasChanges = true ;
242+
238243 if ( this . imageRotation % 180 !== 0 ) {
239244 axis = axis === 'horizontal' ? 'vertical' : 'horizontal' ;
240245 }
@@ -247,6 +252,8 @@ class TransformManager implements EditToolManager {
247252 }
248253
249254 async rotate ( angle : number ) {
255+ this . hasChanges = true ;
256+
250257 this . imageRotation += angle ;
251258 await tick ( ) ;
252259 this . onImageLoad ( ) ;
@@ -760,6 +767,7 @@ class TransformManager implements EditToolManager {
760767 return ;
761768 }
762769
770+ this . hasChanges = true ;
763771 const newX = Math . max ( 0 , Math . min ( mouseX - this . dragOffset . x , cropArea . clientWidth - this . region . width ) ) ;
764772 const newY = Math . max ( 0 , Math . min ( mouseY - this . dragOffset . y , cropArea . clientHeight - this . region . height ) ) ;
765773
@@ -781,6 +789,7 @@ class TransformManager implements EditToolManager {
781789 }
782790 this . fadeOverlay ( false ) ;
783791
792+ this . hasChanges = true ;
784793 const { x, y, width, height } = crop ;
785794 const minSize = 50 ;
786795 let newRegion = { ...crop } ;
0 commit comments