1- /* eslint-disable max-lines */
1+ import type { FeedbackInternalOptions } from '@sentry/core' ;
22import type { VNode , h as hType } from 'preact' ;
33import type * as Hooks from 'preact/hooks' ;
44import { DOCUMENT , WINDOW } from '../../constants' ;
5- import type { FeedbackInternalOptions } from '@sentry/core' ;
65import CropCornerFactory from './CropCorner' ;
76
87const CROP_BUTTON_SIZE = 30 ;
@@ -31,7 +30,7 @@ const constructRect = (box: Box): Rect => ({
3130 height : Math . abs ( box . startY - box . endY ) ,
3231} ) ;
3332
34- const getContainedSize = ( img : HTMLCanvasElement ) : Box => {
33+ const getContainedSize = ( img : HTMLCanvasElement ) : Rect => {
3534 const imgClientHeight = img . clientHeight ;
3635 const imgClientWidth = img . clientWidth ;
3736 const ratio = img . width / img . height ;
@@ -43,7 +42,7 @@ const getContainedSize = (img: HTMLCanvasElement): Box => {
4342 }
4443 const x = ( imgClientWidth - width ) / 2 ;
4544 const y = ( imgClientHeight - height ) / 2 ;
46- return { startX : x , startY : y , endX : width + x , endY : height + y } ;
45+ return { x : x , y : y , width : width , height : height } ;
4746} ;
4847
4948interface FactoryParams {
@@ -53,7 +52,7 @@ interface FactoryParams {
5352}
5453
5554export default function CropFactory ( {
56- h, // eslint-disable-line @typescript-eslint/no-unused-vars
55+ h,
5756 hooks,
5857 options,
5958} : FactoryParams ) : ( props : {
@@ -99,7 +98,7 @@ export default function CropFactory({
9998 return ;
10099 }
101100
102- const imageDimensions = constructRect ( getContainedSize ( imageBuffer ) ) ;
101+ const imageDimensions = getContainedSize ( imageBuffer ) ;
103102 const croppingBox = constructRect ( croppingRect ) ;
104103 ctx . clearRect ( 0 , 0 , imageDimensions . width , imageDimensions . height ) ;
105104
@@ -124,7 +123,9 @@ export default function CropFactory({
124123 // Resizing logic
125124 const makeHandleMouseMove = hooks . useCallback ( ( corner : string ) => {
126125 return ( e : MouseEvent ) => {
127- if ( ! croppingRef . current ) return ;
126+ if ( ! croppingRef . current ) {
127+ return ;
128+ }
128129
129130 const cropCanvas = croppingRef . current ;
130131 const cropBoundingRect = cropCanvas . getBoundingClientRect ( ) ;
@@ -166,13 +167,17 @@ export default function CropFactory({
166167
167168 // Dragging logic
168169 const onDragStart = ( e : MouseEvent ) : void => {
169- if ( isResizing ) return ;
170+ if ( isResizing ) {
171+ return ;
172+ }
170173
171174 initialPositionRef . current = { initialX : e . clientX , initialY : e . clientY } ;
172175
173176 const handleMouseMove = ( moveEvent : MouseEvent ) : void => {
174177 const cropCanvas = croppingRef . current ;
175- if ( ! cropCanvas ) return ;
178+ if ( ! cropCanvas ) {
179+ return ;
180+ }
176181
177182 const deltaX = moveEvent . clientX - initialPositionRef . current . initialX ;
178183 const deltaY = moveEvent . clientY - initialPositionRef . current . initialY ;
@@ -222,7 +227,7 @@ export default function CropFactory({
222227
223228 function applyCrop ( ) : void {
224229 const cutoutCanvas = DOCUMENT . createElement ( 'canvas' ) ;
225- const imageBox = constructRect ( getContainedSize ( imageBuffer ) ) ;
230+ const imageBox = getContainedSize ( imageBuffer ) ;
226231 const croppingBox = constructRect ( croppingRect ) ;
227232 cutoutCanvas . width = croppingBox . width * DPI ;
228233 cutoutCanvas . height = croppingBox . height * DPI ;
@@ -269,25 +274,25 @@ export default function CropFactory({
269274 top = { croppingRect . startY - CROP_BUTTON_BORDER }
270275 onGrabButton = { onGrabButton }
271276 corner = "top-left"
272- > </ CropCorner >
277+ / >
273278 < CropCorner
274279 left = { croppingRect . endX - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER }
275280 top = { croppingRect . startY - CROP_BUTTON_BORDER }
276281 onGrabButton = { onGrabButton }
277282 corner = "top-right"
278- > </ CropCorner >
283+ / >
279284 < CropCorner
280285 left = { croppingRect . startX - CROP_BUTTON_BORDER }
281286 top = { croppingRect . endY - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER }
282287 onGrabButton = { onGrabButton }
283288 corner = "bottom-left"
284- > </ CropCorner >
289+ / >
285290 < CropCorner
286291 left = { croppingRect . endX - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER }
287292 top = { croppingRect . endY - CROP_BUTTON_SIZE + CROP_BUTTON_BORDER }
288293 onGrabButton = { onGrabButton }
289294 corner = "bottom-right"
290- > </ CropCorner >
295+ / >
291296 </ div >
292297 ) }
293298 { action === 'crop' && (
0 commit comments