{"version":3,"sources":["TapGestureHandler.ts"],"names":["TapGestureHandler","DiscreteGestureHandler","ev","_getPendingGestures","length","_shouldFireEndEvent","eventType","Hammer","INPUT_END","sendEvent","INPUT_MOVE","isFinal","onGestureEnded","name","NativeGestureClass","Tap","maxDelayMs","config","simulateCancelEvent","inputData","isGestureRunning","cancelEvent","onGestureActivated","onSuccessfulTap","onRawEvent","hasGestureFailed","gesture","hammer","get","options","enable","clearTimeout","_multiTapTimer","onStart","maxPointers","setTimeout","_timer","getHammerConfig","event","taps","numberOfTaps","interval","time","maxDurationMs","updateGestureConfig","shouldCancelWhenOutside","maxDeltaX","Number","NaN","maxDeltaY","minDurationMs","maxDist","minPointers","props","onWaitingEnded","_gesture"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;;;AAEA,MAAMA,iBAAN,SAAgCC,+BAAhC,CAAuD;AAAA;AAAA;;AAAA,iDACA,IADA;;AAAA;;AAAA;;AAAA,6CA6BlCC,EAAD,IAAwB;AACxC,UAAI,KAAKC,mBAAL,GAA2BC,MAA/B,EAAuC;AACrC,aAAKC,mBAAL,GAA2BH,EAA3B;AACA;AACD;;AACD,UAAIA,EAAE,CAACI,SAAH,KAAiBC,kBAAOC,SAA5B,EAAuC;AACrC,aAAKC,SAAL,CAAe,EAAE,GAAGP,EAAL;AAASI,UAAAA,SAAS,EAAEC,kBAAOG;AAA3B,SAAf;AACD,OAPuC,CAQxC;;;AACA,WAAKD,SAAL,CAAe,EAAE,GAAGP,EAAL;AAASS,QAAAA,OAAO,EAAE;AAAlB,OAAf;AACA,WAAKC,cAAL,CAAoBV,EAApB;AACD,KAxCoD;AAAA;;AAGxB;AACrB,MAAJW,IAAI,GAAG;AACT,WAAO,KAAP;AACD;;AAEqB,MAAlBC,kBAAkB,GAAG;AACvB,WAAOP,kBAAOQ,GAAd;AACD;;AAEa,MAAVC,UAAU,GAAG;AACf;AACA,WAAO,kBAAM,KAAKC,MAAL,CAAYD,UAAlB,IAAgC,GAAhC,GAAsC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AAAA,SAAS,GAAGC,MAAM,CAACC,GAFD;AAGlBC,IAAAA,SAAS,GAAGF,MAAM,CAACC,GAHD;AAIlBR,IAAAA,YAAY,GAAG,CAJG;AAKlBU,IAAAA,aAAa,GAAG,GALE;AAMlBlC,IAAAA,UAAU,GAAG+B,MAAM,CAACC,GANF;AAOlB;AACAL,IAAAA,aAAa,GAAGI,MAAM,CAACC,GARL;AASlBG,IAAAA,OAAO,GAAG,CATQ;AAUlBC,IAAAA,WAAW,GAAG,CAVI;AAWlBlB,IAAAA,WAAW,GAAG,CAXI;AAYlB,OAAGmB;AAZe,GAAD,EAahB;AACD,WAAO,MAAMT,mBAAN,CAA0B;AAC/BC,MAAAA,uBAD+B;AAE/BL,MAAAA,YAF+B;AAG/BM,MAAAA,SAH+B;AAI/BG,MAAAA,SAJ+B;AAK/BC,MAAAA,aAL+B;AAM/BlC,MAAAA,UAN+B;AAO/BmC,MAAAA,OAP+B;AAQ/BC,MAAAA,WAR+B;AAS/BlB,MAAAA,WAT+B;AAU/B,SAAGmB;AAV4B,KAA1B,CAAP;AAYD;;AAEDzC,EAAAA,cAAc,CAAC,GAAGyC,KAAJ,EAAgB;AAC5BtB,IAAAA,YAAY,CAAC,KAAKK,MAAN,CAAZ,CAD4B,CAE5B;;AACA,UAAMxB,cAAN,CAAqB,GAAGyC,KAAxB;AACD;;AAEDC,EAAAA,cAAc,CAACC,QAAD,EAAgB;AAC5B,QAAI,KAAKlD,mBAAT,EAA8B;AAC5B,WAAKkB,eAAL,CAAqB,KAAKlB,mBAA1B;AACA,WAAKA,mBAAL,GAA2B,IAA3B;AACD;AACF;;AAnKoD;;eAqKxCL,iB","sourcesContent":["import Hammer from '@egjs/hammerjs';\n\nimport DiscreteGestureHandler from './DiscreteGestureHandler';\nimport { HammerInputExt } from './GestureHandler';\nimport { isnan } from './utils';\n\nclass TapGestureHandler extends DiscreteGestureHandler {\n private _shouldFireEndEvent: HammerInputExt | null = null;\n private _timer: any;\n private _multiTapTimer: any; // TODO unused?\n get name() {\n return 'tap';\n }\n\n get NativeGestureClass() {\n return Hammer.Tap;\n }\n\n get maxDelayMs() {\n // @ts-ignore TODO(TS) trace down config\n return isnan(this.config.maxDelayMs) ? 300 : this.config.maxDelayMs;\n }\n\n simulateCancelEvent(inputData: HammerInputExt) {\n if (this.isGestureRunning) {\n this.cancelEvent(inputData);\n }\n }\n\n onGestureActivated(ev: HammerInputExt) {\n if (this.isGestureRunning) {\n this.onSuccessfulTap(ev);\n }\n }\n\n onSuccessfulTap = (ev: HammerInputExt) => {\n if (this._getPendingGestures().length) {\n this._shouldFireEndEvent = ev;\n return;\n }\n if (ev.eventType === Hammer.INPUT_END) {\n this.sendEvent({ ...ev, eventType: Hammer.INPUT_MOVE });\n }\n // When handler gets activated it will turn into State.END immediately.\n this.sendEvent({ ...ev, isFinal: true });\n this.onGestureEnded(ev);\n };\n\n onRawEvent(ev: HammerInput) {\n super.onRawEvent(ev);\n\n // Attempt to create a touch-down event by checking if a valid tap hasn't started yet, then validating the input.\n if (\n !this.hasGestureFailed &&\n !this.isGestureRunning &&\n // Prevent multi-pointer events from misfiring.\n !ev.isFinal\n ) {\n // Tap Gesture start event\n const gesture = this.hammer!.get(this.name);\n // @ts-ignore TODO(TS) trace down config\n if (gesture.options.enable(gesture, ev)) {\n clearTimeout(this._multiTapTimer);\n\n this.onStart(ev);\n this.sendEvent(ev);\n }\n }\n if (ev.isFinal && ev.maxPointers > 1) {\n setTimeout(() => {\n // Handle case where one finger presses slightly\n // after the first finger on a multi-tap event\n if (this.isGestureRunning) {\n this.cancelEvent(ev);\n }\n });\n }\n\n if (this.hasGestureFailed) {\n return;\n }\n // Hammer doesn't send a `cancel` event for taps.\n // Manually fail the event.\n if (ev.isFinal) {\n // Handle case where one finger presses slightly\n // after the first finger on a multi-tap event\n if (ev.maxPointers > 1) {\n setTimeout(() => {\n if (this.isGestureRunning) {\n this.cancelEvent(ev);\n }\n });\n }\n\n // Clear last timer\n clearTimeout(this._timer);\n // Create time out for multi-taps.\n this._timer = setTimeout(() => {\n this.hasGestureFailed = true;\n this.cancelEvent(ev);\n }, this.maxDelayMs);\n } else if (!this.hasGestureFailed && !this.isGestureRunning) {\n // Tap Gesture start event\n const gesture = this.hammer!.get(this.name);\n // @ts-ignore TODO(TS) trace down config\n if (gesture.options.enable(gesture, ev)) {\n clearTimeout(this._multiTapTimer);\n\n this.onStart(ev);\n this.sendEvent(ev);\n }\n }\n }\n\n getHammerConfig() {\n return {\n ...super.getHammerConfig(),\n event: this.name,\n // @ts-ignore TODO(TS) trace down config\n taps: isnan(this.config.numberOfTaps) ? 1 : this.config.numberOfTaps,\n interval: this.maxDelayMs,\n time:\n // @ts-ignore TODO(TS) trace down config\n isnan(this.config.maxDurationMs) || this.config.maxDurationMs == null\n ? 250\n : // @ts-ignore TODO(TS) trace down config\n this.config.maxDurationMs,\n };\n }\n\n updateGestureConfig({\n shouldCancelWhenOutside = true,\n maxDeltaX = Number.NaN,\n maxDeltaY = Number.NaN,\n numberOfTaps = 1,\n minDurationMs = 525,\n maxDelayMs = Number.NaN,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO possibly forgotten to use in updateGestureConfig?\n maxDurationMs = Number.NaN,\n maxDist = 2,\n minPointers = 1,\n maxPointers = 1,\n ...props\n }) {\n return super.updateGestureConfig({\n shouldCancelWhenOutside,\n numberOfTaps,\n maxDeltaX,\n maxDeltaY,\n minDurationMs,\n maxDelayMs,\n maxDist,\n minPointers,\n maxPointers,\n ...props,\n });\n }\n\n onGestureEnded(...props: any) {\n clearTimeout(this._timer);\n // @ts-ignore TODO(TS) check how onGestureEnded works\n super.onGestureEnded(...props);\n }\n\n onWaitingEnded(_gesture: any) {\n if (this._shouldFireEndEvent) {\n this.onSuccessfulTap(this._shouldFireEndEvent);\n this._shouldFireEndEvent = null;\n }\n }\n}\nexport default TapGestureHandler;\n"]}