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AAuB,SAAS,IAAG;AACjC,IAAA,MAAM,CAAC,gBAAP,CAAwB,SAAxB,EAAmC,QAAQ,CAAC,SAAD,CAA3C,EAAyE,OAAzE;AACD,GAFD;AAGD;;AAED,SAAS,MAAT,CAAiB,EAAjB,EAAkC,OAAlC,EAAgE,KAAhE,EAA4E;AAC1E,QAAM,MAAM,GAAG,OAAO,CAAC,KAAR,CAAe,MAAf,GAAwB,EAAE,CAAC,aAA3B,GAA2C,EAA1D;AACA,MAAI,CAAC,MAAD,IAAW,CAAC,MAAM,CAAC,cAAvB,EAAuC;AAEvC,QAAM,QAAQ,GAAG,MAAM,CAAC,cAAP,CAAsB,KAAK,CAAC,OAAN,CAAe,IAArC,CAAjB;AACA,EAAA,IAAI,CAAC,QAAD,CAAJ,CAAe,OAAf,CAAuB,SAAS,IAAG;AACjC,IAAA,MAAM,CAAC,mBAAP,CAA2B,SAA3B,EAAsC,QAAQ,CAAC,SAAD,CAA9C;AACD,GAFD;AAGA,SAAO,MAAM,CAAC,cAAP,CAAsB,KAAK,CAAC,OAAN,CAAe,IAArC,CAAP;AACD;;AAED,OAAO,MAAM,KAAK,GAAG;AACnB,EAAA,QADmB;AAEnB,EAAA;AAFmB,CAAd;AAKP,eAAe,KAAf","sourcesContent":["import { VNodeDirective, VNode } from 'vue/types/vnode'\nimport { keys } from '../../util/helpers'\n\nexport interface TouchStoredHandlers {\n touchstart: (e: TouchEvent) => void\n touchend: (e: TouchEvent) => void\n touchmove: (e: TouchEvent) => void\n}\n\ninterface TouchHandlers {\n start?: (wrapperEvent: TouchEvent & TouchWrapper) => void\n end?: (wrapperEvent: TouchEvent & TouchWrapper) => void\n move?: (wrapperEvent: TouchEvent & TouchWrapper) => void\n left?: (wrapper: TouchWrapper) => void\n right?: (wrapper: TouchWrapper) => void\n up?: (wrapper: TouchWrapper) => void\n down?: (wrapper: TouchWrapper) => void\n}\n\nexport interface TouchWrapper extends TouchHandlers {\n touchstartX: number\n touchstartY: number\n touchmoveX: number\n touchmoveY: number\n touchendX: number\n touchendY: number\n offsetX: number\n offsetY: number\n}\n\ninterface TouchVNodeDirective extends VNodeDirective {\n value?: TouchHandlers & {\n parent?: boolean\n options?: AddEventListenerOptions\n }\n}\n\nconst handleGesture = (wrapper: TouchWrapper) => {\n const { touchstartX, touchendX, touchstartY, touchendY } = wrapper\n const dirRatio = 0.5\n const minDistance = 16\n wrapper.offsetX = touchendX - touchstartX\n wrapper.offsetY = touchendY - touchstartY\n\n if (Math.abs(wrapper.offsetY) < dirRatio * Math.abs(wrapper.offsetX)) {\n wrapper.left && (touchendX < touchstartX - minDistance) && wrapper.left(wrapper)\n wrapper.right && (touchendX > touchstartX + minDistance) && wrapper.right(wrapper)\n }\n\n if (Math.abs(wrapper.offsetX) < dirRatio * Math.abs(wrapper.offsetY)) {\n wrapper.up && (touchendY < touchstartY - minDistance) && wrapper.up(wrapper)\n wrapper.down && (touchendY > touchstartY + minDistance) && wrapper.down(wrapper)\n }\n}\n\nfunction touchstart (event: TouchEvent, wrapper: TouchWrapper) {\n const touch = event.changedTouches[0]\n wrapper.touchstartX = touch.clientX\n wrapper.touchstartY = touch.clientY\n\n wrapper.start &&\n wrapper.start(Object.assign(event, wrapper))\n}\n\nfunction touchend (event: TouchEvent, wrapper: TouchWrapper) {\n const touch = event.changedTouches[0]\n wrapper.touchendX = touch.clientX\n wrapper.touchendY = touch.clientY\n\n wrapper.end &&\n wrapper.end(Object.assign(event, wrapper))\n\n handleGesture(wrapper)\n}\n\nfunction touchmove (event: TouchEvent, wrapper: TouchWrapper) {\n const touch = event.changedTouches[0]\n wrapper.touchmoveX = touch.clientX\n wrapper.touchmoveY = touch.clientY\n\n wrapper.move && wrapper.move(Object.assign(event, wrapper))\n}\n\nfunction createHandlers (value: TouchHandlers): TouchStoredHandlers {\n const wrapper = {\n touchstartX: 0,\n touchstartY: 0,\n touchendX: 0,\n touchendY: 0,\n touchmoveX: 0,\n touchmoveY: 0,\n offsetX: 0,\n offsetY: 0,\n left: value.left,\n right: value.right,\n up: value.up,\n down: value.down,\n start: value.start,\n move: value.move,\n end: value.end,\n }\n\n return {\n touchstart: (e: TouchEvent) => touchstart(e, wrapper),\n touchend: (e: TouchEvent) => touchend(e, wrapper),\n touchmove: (e: TouchEvent) => touchmove(e, wrapper),\n }\n}\n\nfunction inserted (el: HTMLElement, binding: TouchVNodeDirective, vnode: VNode) {\n const value = binding.value!\n const target = value.parent ? el.parentElement : el\n const options = value.options || { passive: true }\n\n // Needed to pass unit tests\n if (!target) return\n\n const handlers = createHandlers(binding.value!)\n target._touchHandlers = Object(target._touchHandlers)\n target._touchHandlers![vnode.context!._uid] = handlers\n\n keys(handlers).forEach(eventName => {\n target.addEventListener(eventName, handlers[eventName] as EventListener, options)\n })\n}\n\nfunction unbind (el: HTMLElement, binding: TouchVNodeDirective, vnode: VNode) {\n const target = binding.value!.parent ? el.parentElement : el\n if (!target || !target._touchHandlers) return\n\n const handlers = target._touchHandlers[vnode.context!._uid]\n keys(handlers).forEach(eventName => {\n target.removeEventListener(eventName, handlers[eventName])\n })\n delete target._touchHandlers[vnode.context!._uid]\n}\n\nexport const Touch = {\n inserted,\n unbind,\n}\n\nexport default Touch\n"],"sourceRoot":"","file":"index.js"} |