Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
package.lib.directives.touch.index.mjs.map Maven / Gradle / Ivy
{"version":3,"file":"index.mjs","names":["keys","handleGesture","wrapper","touchstartX","touchendX","touchstartY","touchendY","dirRatio","minDistance","offsetX","offsetY","Math","abs","left","right","up","down","touchstart","event","touch","changedTouches","clientX","clientY","start","originalEvent","touchend","end","touchmove","touchmoveX","touchmoveY","move","createHandlers","value","arguments","length","undefined","e","mounted","el","binding","target","parent","parentElement","options","passive","uid","instance","$","handlers","_touchHandlers","Object","create","forEach","eventName","addEventListener","unmounted","removeEventListener","Touch"],"sources":["../../../src/directives/touch/index.ts"],"sourcesContent":["// Utilities\nimport { keys } from '@/util'\n\n// Types\nimport type {\n DirectiveBinding,\n} from 'vue'\n\nexport interface TouchHandlers {\n start?: (wrapperEvent: { originalEvent: TouchEvent } & TouchData) => void\n end?: (wrapperEvent: { originalEvent: TouchEvent } & TouchData) => void\n move?: (wrapperEvent: { originalEvent: TouchEvent } & TouchData) => void\n left?: (wrapper: TouchData) => void\n right?: (wrapper: TouchData) => void\n up?: (wrapper: TouchData) => void\n down?: (wrapper: TouchData) => void\n}\n\nexport interface TouchData {\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\nexport type TouchWrapper = TouchHandlers & TouchData\n\nexport interface TouchValue extends TouchHandlers {\n parent?: boolean\n options?: AddEventListenerOptions\n}\n\nexport interface TouchStoredHandlers {\n touchstart: (e: TouchEvent) => void\n touchend: (e: TouchEvent) => void\n touchmove: (e: TouchEvent) => void\n}\n\nexport interface TouchDirectiveBinding extends Omit {\n value?: TouchValue\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?.({ originalEvent: 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?.({ originalEvent: 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?.({ originalEvent: 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 mounted (el: HTMLElement, binding: TouchDirectiveBinding) {\n const value = binding.value\n const target = value?.parent ? el.parentElement : el\n const options = value?.options ?? { passive: true }\n const uid = binding.instance?.$.uid // TODO: use custom uid generator\n\n if (!target || !uid) return\n\n const handlers = createHandlers(binding.value)\n\n target._touchHandlers = target._touchHandlers ?? Object.create(null)\n target._touchHandlers![uid] = handlers\n\n keys(handlers).forEach(eventName => {\n target.addEventListener(eventName, handlers[eventName], options)\n })\n}\n\nfunction unmounted (el: HTMLElement, binding: TouchDirectiveBinding) {\n const target = binding.value?.parent ? el.parentElement : el\n const uid = binding.instance?.$.uid\n\n if (!target?._touchHandlers || !uid) return\n\n const handlers = target._touchHandlers[uid]\n\n keys(handlers).forEach(eventName => {\n target.removeEventListener(eventName, handlers[eventName])\n })\n\n delete target._touchHandlers[uid]\n}\n\nexport const Touch = {\n mounted,\n unmounted,\n}\n\nexport default Touch\n"],"mappings":"AAAA;AAAA,SACSA,IAAI,gCAEb;AA2CA,MAAMC,aAAa,GAAIC,OAAqB,IAAK;EAC/C,MAAM;IAAEC,WAAW;IAAEC,SAAS;IAAEC,WAAW;IAAEC;EAAU,CAAC,GAAGJ,OAAO;EAClE,MAAMK,QAAQ,GAAG,GAAG;EACpB,MAAMC,WAAW,GAAG,EAAE;EACtBN,OAAO,CAACO,OAAO,GAAGL,SAAS,GAAGD,WAAW;EACzCD,OAAO,CAACQ,OAAO,GAAGJ,SAAS,GAAGD,WAAW;EAEzC,IAAIM,IAAI,CAACC,GAAG,CAACV,OAAO,CAACQ,OAAO,CAAC,GAAGH,QAAQ,GAAGI,IAAI,CAACC,GAAG,CAACV,OAAO,CAACO,OAAO,CAAC,EAAE;IACpEP,OAAO,CAACW,IAAI,IAAKT,SAAS,GAAGD,WAAW,GAAGK,WAAY,IAAIN,OAAO,CAACW,IAAI,CAACX,OAAO,CAAC;IAChFA,OAAO,CAACY,KAAK,IAAKV,SAAS,GAAGD,WAAW,GAAGK,WAAY,IAAIN,OAAO,CAACY,KAAK,CAACZ,OAAO,CAAC;EACpF;EAEA,IAAIS,IAAI,CAACC,GAAG,CAACV,OAAO,CAACO,OA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