{"version":3,"sources":["PanGestureHandler.ts"],"names":["Hammer","MULTI_FINGER_PAN_MAX_PINCH_THRESHOLD","MULTI_FINGER_PAN_MAX_ROTATION_THRESHOLD","DraggingGestureHandler","isValidNumber","isnan","TEST_MIN_IF_NOT_NAN","VEC_LEN_SQ","State","PanGestureHandler","name","NativeGestureClass","Pan","getHammerConfig","direction","getDirection","getState","type","nextState","previousState","UNDETERMINED","ACTIVE","BEGAN","config","getConfig","activeOffsetXStart","activeOffsetXEnd","activeOffsetYStart","activeOffsetYEnd","minDist","directions","horizontalDirections","DIRECTION_ALL","push","DIRECTION_LEFT","DIRECTION_RIGHT","length","DIRECTION_HORIZONTAL","concat","verticalDirections","DIRECTION_UP","DIRECTION_DOWN","DIRECTION_VERTICAL","DIRECTION_NONE","hasCustomActivationCriteria","minDistSq","shouldFailUnderCustomCriteria","deltaX","deltaY","criteria","failOffsetXStart","failOffsetXEnd","failOffsetYStart","failOffsetYEnd","shouldActivateUnderCustomCriteria","velocity","x","y","minVelocityX","minVelocityY","minVelocitySq","shouldMultiFingerPanFail","pointerLength","scale","deltaRotation","deltaScale","Math","abs","absDeltaRotation","updateHasCustomActivationCriteria","isGestureEnabledForEvent","props","_recognizer","inputData","failed","velocityX","velocityY","maxPointers","success"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,gBAAnB;AAEA,SAEEC,oCAFF,EAGEC,uCAHF,QAIO,aAJP;AAKA,OAAOC,sBAAP,MAAmC,0BAAnC;AACA,SAASC,aAAT,EAAwBC,KAAxB,EAA+BC,mBAA/B,EAAoDC,UAApD,QAAsE,SAAtE;AACA,SAASC,KAAT,QAAsB,UAAtB;;AAGA,MAAMC,iBAAN,SAAgCN,sBAAhC,CAAuD;AAC7C,MAAJO,IAAI,GAAG;AACT,WAAO,KAAP;AACD;;AAEqB,MAAlBC,kBAAkB,GAAG;AACvB,WAAOX,MAAM,CAACY,GAAd;AACD;;AAEDC,EAAAA,eAAe,GAAG;AAChB,WAAO,EACL,GAAG,MAA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sDO,MAAAA;AAAtD,KADF,EAEEgB,KAFF,CAFF,EAME;AACA,UACE,KAAKV,wBAAL,CAA8B;AAC5BC,QAAAA,aAAa,EAAEW,SAAS,CAACI,WADG;AAE5Bd,QAAAA,KAAK,EAAEU,SAAS,CAACV,KAFW;AAG5BC,QAAAA,aAAa,EAAES,SAAS,CAACT;AAHG,OAA9B,CADF,EAME;AACA,eAAO;AACLU,UAAAA,MAAM,EAAE;AADH,SAAP;AAGD;;AACD,aAAO;AAAEI,QAAAA,OAAO,EAAE;AAAX,OAAP;AACD;;AACD,WAAO;AAAEA,MAAAA,OAAO,EAAE;AAAX,KAAP;AACD;;AA5MoD;;AA+MvD,eAAerE,iBAAf","sourcesContent":["import Hammer from '@egjs/hammerjs';\n\nimport {\n EventMap,\n MULTI_FINGER_PAN_MAX_PINCH_THRESHOLD,\n MULTI_FINGER_PAN_MAX_ROTATION_THRESHOLD,\n} from './constants';\nimport DraggingGestureHandler from './DraggingGestureHandler';\nimport { isValidNumber, isnan, TEST_MIN_IF_NOT_NAN, VEC_LEN_SQ } from './utils';\nimport { State } from '../State';\n\nimport { Config, HammerInputExt } from './GestureHandler';\nclass PanGestureHandler extends DraggingGestureHandler {\n get name() {\n return 'pan';\n }\n\n get NativeGestureClass() {\n return Hammer.Pan;\n }\n\n getHammerConfig() {\n return {\n ...super.getHammerConfig(),\n direction: this.getDirection(),\n };\n }\n\n getState(type: keyof typeof EventMap) {\n const nextState = super.getState(type);\n // Ensure that the first state sent is `BEGAN` and not `ACTIVE`\n if (\n this.previousState === State.UNDETERMINED &&\n nextState === State.ACTIVE\n ) {\n return State.BEGAN;\n }\n return nextState;\n }\n\n getDirection() {\n const config = this.getConfig();\n const {\n activeOffsetXStart,\n activeOffsetXEnd,\n activeOffsetYStart,\n activeOffsetYEnd,\n minDist,\n } = config;\n let directions: number[] = [];\n let horizontalDirections = [];\n\n if (!isnan(minDist)) {\n return Hammer.DIRECTION_ALL;\n }\n\n if (!isnan(activeOffsetXStart))\n horizontalDirections.push(Hammer.DIRECTION_LEFT);\n if (!isnan(activeOffsetXEnd))\n horizontalDirections.push(Hammer.DIRECTION_RIGHT);\n if (horizontalDirections.length === 2)\n horizontalDirections = [Hammer.DIRECTION_HORIZONTAL];\n\n directions = directions.concat(horizontalDirections);\n let verticalDirections = [];\n\n if (!isnan(activeOffsetYStart))\n verticalDirections.push(Hammer.DIRECTION_UP);\n if (!isnan(activeOffsetYEnd))\n verticalDirections.push(Hammer.DIRECTION_DOWN);\n\n if (verticalDirections.length === 2)\n verticalDirections = [Hammer.DIRECTION_VERTICAL];\n\n directions = directions.concat(verticalDirections);\n\n if (!directions.length) {\n return Hammer.DIRECTION_NONE;\n }\n if (\n directions[0] === Hammer.DIRECTION_HORIZONTAL &&\n directions[1] === Hammer.DIRECTION_VERTICAL\n ) {\n return Hammer.DIRECTION_ALL;\n }\n if (horizontalDirections.length && verticalDirections.length) {\n return Hammer.DIRECTION_ALL;\n }\n\n return directions[0];\n }\n\n getConfig() {\n if (!this.hasCustomActivationCriteria) {\n // Default config\n // If no params have been defined then this config should emulate the native gesture as closely as possible.\n return {\n minDistSq: 10,\n };\n }\n return this.config;\n }\n\n shouldFailUnderCustomCriteria(\n { deltaX, deltaY }: HammerInputExt,\n criteria: any\n ) {\n return (\n (!isnan(criteria.failOffsetXStart) &&\n deltaX < criteria.failOffsetXStart) ||\n (!isnan(criteria.failOffsetXEnd) && deltaX > criteria.failOffsetXEnd) ||\n (!isnan(criteria.failOffsetYStart) &&\n deltaY < criteria.failOffsetYStart) ||\n (!isnan(criteria.failOffsetYEnd) && deltaY > criteria.failOffsetYEnd)\n );\n }\n\n shouldActivateUnderCustomCriteria(\n { deltaX, deltaY, velocity }: any,\n criteria: any\n ) {\n return (\n (!isnan(criteria.activeOffsetXStart) &&\n deltaX < criteria.activeOffsetXStart) ||\n (!isnan(criteria.activeOffsetXEnd) &&\n deltaX > criteria.activeOffsetXEnd) ||\n (!isnan(criteria.activeOffsetYStart) &&\n deltaY < criteria.activeOffsetYStart) ||\n (!isnan(criteria.activeOffsetYEnd) &&\n deltaY > criteria.activeOffsetYEnd) ||\n TEST_MIN_IF_NOT_NAN(\n VEC_LEN_SQ({ x: deltaX, y: deltaY }),\n criteria.minDistSq\n ) ||\n TEST_MIN_IF_NOT_NAN(velocity.x, criteria.minVelocityX) ||\n TEST_MIN_IF_NOT_NAN(velocity.y, criteria.minVelocityY) ||\n TEST_MIN_IF_NOT_NAN(VEC_LEN_SQ(velocity), criteria.minVelocitySq)\n );\n }\n\n shouldMultiFingerPanFail({\n pointerLength,\n scale,\n deltaRotation,\n }: {\n deltaRotation: number;\n pointerLength: number;\n scale: number;\n }) {\n if (pointerLength <= 1) {\n return false;\n }\n\n // Test if the pan had too much pinching or rotating.\n const deltaScale = Math.abs(scale - 1);\n const absDeltaRotation = Math.abs(deltaRotation);\n if (deltaScale > MULTI_FINGER_PAN_MAX_PINCH_THRESHOLD) {\n // > If the threshold doesn't seem right.\n // You can log the value which it failed at here:\n return true;\n }\n if (absDeltaRotation > MULTI_FINGER_PAN_MAX_ROTATION_THRESHOLD) {\n // > If the threshold doesn't seem right.\n // You can log the value which it failed at here:\n return true;\n }\n\n return false;\n }\n\n updateHasCustomActivationCriteria(\n criteria: Config & { minVelocityX?: number; minVelocityY?: number }\n ) {\n return (\n isValidNumber(criteria.minDistSq) ||\n isValidNumber(criteria.minVelocityX) ||\n isValidNumber(criteria.minVelocityY) ||\n isValidNumber(criteria.minVelocitySq) ||\n isValidNumber(criteria.activeOffsetXStart) ||\n isValidNumber(criteria.activeOffsetXEnd) ||\n isValidNumber(criteria.activeOffsetYStart) ||\n isValidNumber(criteria.activeOffsetYEnd)\n );\n }\n\n isGestureEnabledForEvent(\n props: any,\n _recognizer: any,\n inputData: HammerInputExt & { deltaRotation: number }\n ) {\n if (this.shouldFailUnderCustomCriteria(inputData, props)) {\n return { failed: true };\n }\n\n const velocity = { x: inputData.velocityX, y: inputData.velocityY };\n if (\n this.hasCustomActivationCriteria &&\n this.shouldActivateUnderCustomCriteria(\n { deltaX: inputData.deltaX, deltaY: inputData.deltaY, velocity },\n props\n )\n ) {\n if (\n this.shouldMultiFingerPanFail({\n pointerLength: inputData.maxPointers,\n scale: inputData.scale,\n deltaRotation: inputData.deltaRotation,\n })\n ) {\n return {\n failed: true,\n };\n }\n return { success: true };\n }\n return { success: false };\n }\n}\n\nexport default PanGestureHandler;\n"]}