From d204b6b1fd2f646da1a375fba26c042665d45706 Mon Sep 17 00:00:00 2001 From: Tuur Martens Date: Sun, 5 Feb 2023 09:46:23 +0100 Subject: [PATCH] chore: remove dead gesture code (#1632) --- composables/gestures/index.ts | 76 ----------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 composables/gestures/index.ts diff --git a/composables/gestures/index.ts b/composables/gestures/index.ts deleted file mode 100644 index 5cb2b747..00000000 --- a/composables/gestures/index.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { PermissiveMotionProperties } from '@vueuse/motion' -import type { Handlers } from '@vueuse/gesture' -import { useMotionProperties, useSpring } from '@vueuse/motion' -import { useGesture } from '@vueuse/gesture' -import type { MaybeRef } from '@vueuse/core' - -export interface CarouselOptions { - hasNext: MaybeRef - hasPrev: MaybeRef - onPrev: () => void - onNext: () => void -} - -export const useImageGesture = ( - domTarget: MaybeRef, - carouselOptions?: CarouselOptions, -) => { - const { motionProperties } = useMotionProperties(domTarget, { - cursor: 'grab', - scale: 1, - x: 0, - y: 0, - }) - - const { set } = useSpring(motionProperties as Partial) - - const handlers: Handlers = { - onPinch({ offset: [d] }) { - set({ scale: 1 + d / 200 }) - }, - onDragStart() { - set({ cursor: 'grabbing' }) - }, - onDrag({ movement: [x, y], pinching }) { - if (!pinching) - set({ x, y, cursor: 'grabbing' }) - }, - onDragEnd({ vxvy: [vx], pinching }) { - if (pinching) - return - - set({ cursor: 'grab' }) - if (carouselOptions) { - const isSwipe = Math.abs(vx) > 0.25 - if (isSwipe) { - if (vx > 0 && unref(carouselOptions.hasPrev)) - carouselOptions.onPrev() - - else if (vx < 0 && unref(carouselOptions.hasNext)) - carouselOptions.onNext() - } - } - set({ x: 0, y: 0 }) - }, - onMove({ movement: [x, y], dragging, pinching }) { - if (dragging && !pinching) - set({ x, y }) - }, - onWheel({ event, dragging, pinching }) { - if (!dragging && !pinching && event.altKey) { - event.preventDefault() - // @ts-expect-error why is ts complaining here (motionProperties.scale)? - set({ scale: motionProperties.scale + event.deltaY * 0.001 }) - } - }, - onDblclick() { - set({ scale: 1 }) - }, - onTouchstart(event) { - if (event.touches === 2) - set({ scale: 1 }) - }, - } - - useGesture(handlers, { domTarget }) -}