Skip to content

Commit b28e803

Browse files
committed
format with oxfmt
1 parent 8ddae23 commit b28e803

2 files changed

Lines changed: 39 additions & 27 deletions

File tree

packages/lib/src/__tests__/AvatarEditor.test.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,11 @@ describe('AvatarEditor', () => {
558558
touches: Array<{ pageX: number; pageY: number }>,
559559
opts: EventInit = {},
560560
) {
561-
const event = new Event(type, { bubbles: true, cancelable: true, ...opts })
561+
const event = new Event(type, {
562+
bubbles: true,
563+
cancelable: true,
564+
...opts,
565+
})
562566
Object.defineProperty(event, 'touches', { value: touches })
563567
if (type === 'touchmove') {
564568
Object.defineProperty(event, 'targetTouches', { value: touches })
@@ -689,7 +693,9 @@ describe('AvatarEditor', () => {
689693
)
690694
const canvas = container.querySelector('canvas')!
691695

692-
canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: -100, bubbles: true }))
696+
canvas.dispatchEvent(
697+
new WheelEvent('wheel', { deltaY: -100, bubbles: true }),
698+
)
693699

694700
expect(onRequestScaleChange).not.toHaveBeenCalled()
695701
})
@@ -707,7 +713,9 @@ describe('AvatarEditor', () => {
707713
)
708714
const canvas = container.querySelector('canvas')!
709715

710-
canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: -100, bubbles: true }))
716+
canvas.dispatchEvent(
717+
new WheelEvent('wheel', { deltaY: -100, bubbles: true }),
718+
)
711719

712720
expect(onRequestScaleChange).toHaveBeenCalled()
713721
const newScale = onRequestScaleChange.mock.calls[0][0]
@@ -727,7 +735,9 @@ describe('AvatarEditor', () => {
727735
)
728736
const canvas = container.querySelector('canvas')!
729737

730-
canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: 100, bubbles: true }))
738+
canvas.dispatchEvent(
739+
new WheelEvent('wheel', { deltaY: 100, bubbles: true }),
740+
)
731741

732742
expect(onRequestScaleChange).toHaveBeenCalled()
733743
const newScale = onRequestScaleChange.mock.calls[0][0]
@@ -747,7 +757,9 @@ describe('AvatarEditor', () => {
747757
)
748758
const canvas = container.querySelector('canvas')!
749759

750-
canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: 99999, bubbles: true }))
760+
canvas.dispatchEvent(
761+
new WheelEvent('wheel', { deltaY: 99999, bubbles: true }),
762+
)
751763

752764
expect(onRequestScaleChange).toHaveBeenCalled()
753765
const newScale = onRequestScaleChange.mock.calls[0][0]

packages/lib/src/index.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,26 @@ const AvatarEditor = forwardRef<AvatarEditorRef, Props>((props, ref) => {
254254
[],
255255
)
256256

257-
const handleTouchStart: TouchEventHandler<HTMLCanvasElement> =
258-
useCallback(
259-
(e) => {
260-
if (e.touches.length === 2) {
261-
// Start pinch-to-zoom
262-
pinchRef.current = true
263-
dragRef.current = false
264-
setDrag(false)
265-
const dx = e.touches[0].pageX - e.touches[1].pageX
266-
const dy = e.touches[0].pageY - e.touches[1].pageY
267-
pinchStartDistRef.current = Math.sqrt(dx * dx + dy * dy)
268-
pinchStartScaleRef.current = scale
269-
} else {
270-
dragRef.current = true
271-
mxRef.current = undefined
272-
myRef.current = undefined
273-
setDrag(true)
274-
}
275-
},
276-
[scale],
277-
)
257+
const handleTouchStart: TouchEventHandler<HTMLCanvasElement> = useCallback(
258+
(e) => {
259+
if (e.touches.length === 2) {
260+
// Start pinch-to-zoom
261+
pinchRef.current = true
262+
dragRef.current = false
263+
setDrag(false)
264+
const dx = e.touches[0].pageX - e.touches[1].pageX
265+
const dy = e.touches[0].pageY - e.touches[1].pageY
266+
pinchStartDistRef.current = Math.sqrt(dx * dx + dy * dy)
267+
pinchStartScaleRef.current = scale
268+
} else {
269+
dragRef.current = true
270+
mxRef.current = undefined
271+
myRef.current = undefined
272+
setDrag(true)
273+
}
274+
},
275+
[scale],
276+
)
278277

279278
const handleKeyDown: KeyboardEventHandler<HTMLCanvasElement> = useCallback(
280279
(e) => {
@@ -421,7 +420,8 @@ const AvatarEditor = forwardRef<AvatarEditorRef, Props>((props, ref) => {
421420
}
422421

423422
const handleWheel = (e: WheelEvent) => {
424-
if (!enableWheelZoomRef.current || !onRequestScaleChangeRef.current) return
423+
if (!enableWheelZoomRef.current || !onRequestScaleChangeRef.current)
424+
return
425425
e.preventDefault()
426426

427427
// ctrlKey is set for trackpad pinch gestures; use finer sensitivity

0 commit comments

Comments
 (0)