react-native-gesture-handler 2.18.1 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. package/README.md +1 -0
  2. package/android/build.gradle +11 -29
  3. package/android/fabric/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
  4. package/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
  5. package/android/src/main/AndroidManifest.xml +1 -3
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +21 -21
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +2 -2
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureUtils.kt +1 -0
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +16 -0
  10. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +80 -4
  11. package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +8 -0
  12. package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +2 -1
  13. package/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +10 -0
  14. package/android/src/main/java/com/swmansion/gesturehandler/core/StylusData.kt +103 -0
  15. package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +2 -2
  16. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +24 -15
  17. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +3 -0
  18. package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/HoverGestureHandlerEventDataBuilder.kt +7 -0
  19. package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/PanGestureHandlerEventDataBuilder.kt +7 -0
  20. package/android/src/main/jni/CMakeLists.txt +18 -9
  21. package/apple/Handlers/RNFlingHandler.h +1 -0
  22. package/apple/Handlers/RNFlingHandler.m +153 -19
  23. package/apple/Handlers/RNHoverHandler.m +44 -2
  24. package/apple/Handlers/RNLongPressHandler.m +111 -20
  25. package/apple/Handlers/RNManualHandler.m +53 -29
  26. package/apple/Handlers/RNNativeViewHandler.mm +22 -15
  27. package/apple/Handlers/RNPanHandler.m +57 -7
  28. package/apple/Handlers/RNRotationHandler.m +1 -1
  29. package/apple/RNGHStylusData.h +77 -0
  30. package/apple/RNGHStylusData.m +37 -0
  31. package/apple/RNGHUIKit.h +2 -0
  32. package/apple/RNGHVector.h +31 -0
  33. package/apple/RNGHVector.m +67 -0
  34. package/apple/RNGestureHandler.h +7 -0
  35. package/apple/{RNGestureHandler.m → RNGestureHandler.mm} +63 -1
  36. package/apple/RNGestureHandlerButtonComponentView.mm +41 -0
  37. package/apple/RNGestureHandlerDirection.h +25 -0
  38. package/apple/RNGestureHandlerEvents.h +3 -1
  39. package/apple/RNGestureHandlerEvents.m +11 -3
  40. package/lib/commonjs/PointerType.js +2 -1
  41. package/lib/commonjs/PointerType.js.map +1 -1
  42. package/lib/commonjs/components/GestureButtons.js +5 -1
  43. package/lib/commonjs/components/GestureButtons.js.map +1 -1
  44. package/lib/commonjs/components/GestureComponents.js.map +1 -1
  45. package/lib/commonjs/components/Pressable/Pressable.js +66 -78
  46. package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
  47. package/lib/commonjs/components/Pressable/index.js +0 -8
  48. package/lib/commonjs/components/Pressable/index.js.map +1 -1
  49. package/lib/commonjs/components/Pressable/utils.js +1 -23
  50. package/lib/commonjs/components/Pressable/utils.js.map +1 -1
  51. package/lib/commonjs/components/ReanimatedSwipeable.js +60 -41
  52. package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
  53. package/lib/commonjs/handlers/GestureHandlerEventPayload.js +4 -0
  54. package/lib/commonjs/handlers/LongPressGestureHandler.js +1 -1
  55. package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
  56. package/lib/commonjs/handlers/createHandler.js +2 -1
  57. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  58. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +1 -1
  59. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
  60. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  61. package/lib/commonjs/handlers/gestures/hoverGesture.js.map +1 -1
  62. package/lib/commonjs/handlers/gestures/longPressGesture.js +10 -0
  63. package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
  64. package/lib/commonjs/jestUtils/jestUtils.js +12 -4
  65. package/lib/commonjs/jestUtils/jestUtils.js.map +1 -1
  66. package/lib/commonjs/mocks.js +16 -3
  67. package/lib/commonjs/mocks.js.map +1 -1
  68. package/lib/commonjs/utils.js +4 -0
  69. package/lib/commonjs/utils.js.map +1 -1
  70. package/lib/commonjs/web/constants.js +3 -3
  71. package/lib/commonjs/web/constants.js.map +1 -1
  72. package/lib/commonjs/web/handlers/GestureHandler.js +2 -3
  73. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  74. package/lib/commonjs/web/handlers/HoverGestureHandler.js +18 -1
  75. package/lib/commonjs/web/handlers/HoverGestureHandler.js.map +1 -1
  76. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +43 -9
  77. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  78. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +14 -3
  79. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  80. package/lib/commonjs/web/handlers/PanGestureHandler.js +12 -1
  81. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  82. package/lib/commonjs/web/interfaces.js.map +1 -1
  83. package/lib/commonjs/web/tools/EventManager.js.map +1 -1
  84. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +55 -11
  85. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  86. package/lib/commonjs/web/tools/KeyboardEventManager.js +110 -0
  87. package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -0
  88. package/lib/commonjs/web/tools/PointerEventManager.js +3 -37
  89. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  90. package/lib/commonjs/web/tools/Vector.js +4 -2
  91. package/lib/commonjs/web/tools/Vector.js.map +1 -1
  92. package/lib/commonjs/web/utils.js +187 -13
  93. package/lib/commonjs/web/utils.js.map +1 -1
  94. package/lib/module/PointerType.js +2 -1
  95. package/lib/module/PointerType.js.map +1 -1
  96. package/lib/module/components/GestureButtons.js +5 -1
  97. package/lib/module/components/GestureButtons.js.map +1 -1
  98. package/lib/module/components/GestureComponents.js.map +1 -1
  99. package/lib/module/components/Pressable/Pressable.js +67 -78
  100. package/lib/module/components/Pressable/Pressable.js.map +1 -1
  101. package/lib/module/components/Pressable/index.js +0 -1
  102. package/lib/module/components/Pressable/index.js.map +1 -1
  103. package/lib/module/components/Pressable/utils.js +1 -22
  104. package/lib/module/components/Pressable/utils.js.map +1 -1
  105. package/lib/module/components/ReanimatedSwipeable.js +58 -37
  106. package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
  107. package/lib/module/handlers/GestureHandlerEventPayload.js +1 -1
  108. package/lib/module/handlers/LongPressGestureHandler.js +1 -1
  109. package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
  110. package/lib/module/handlers/createHandler.js +2 -1
  111. package/lib/module/handlers/createHandler.js.map +1 -1
  112. package/lib/module/handlers/gestures/GestureDetector/utils.js +2 -2
  113. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
  114. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  115. package/lib/module/handlers/gestures/hoverGesture.js.map +1 -1
  116. package/lib/module/handlers/gestures/longPressGesture.js +10 -0
  117. package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
  118. package/lib/module/jestUtils/jestUtils.js +12 -4
  119. package/lib/module/jestUtils/jestUtils.js.map +1 -1
  120. package/lib/module/mocks.js +13 -3
  121. package/lib/module/mocks.js.map +1 -1
  122. package/lib/module/utils.js +1 -0
  123. package/lib/module/utils.js.map +1 -1
  124. package/lib/module/web/constants.js +1 -1
  125. package/lib/module/web/constants.js.map +1 -1
  126. package/lib/module/web/handlers/GestureHandler.js +2 -3
  127. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  128. package/lib/module/web/handlers/HoverGestureHandler.js +18 -1
  129. package/lib/module/web/handlers/HoverGestureHandler.js.map +1 -1
  130. package/lib/module/web/handlers/LongPressGestureHandler.js +43 -9
  131. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  132. package/lib/module/web/handlers/NativeViewGestureHandler.js +14 -3
  133. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  134. package/lib/module/web/handlers/PanGestureHandler.js +12 -1
  135. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  136. package/lib/module/web/interfaces.js.map +1 -1
  137. package/lib/module/web/tools/EventManager.js.map +1 -1
  138. package/lib/module/web/tools/GestureHandlerWebDelegate.js +54 -10
  139. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  140. package/lib/module/web/tools/KeyboardEventManager.js +96 -0
  141. package/lib/module/web/tools/KeyboardEventManager.js.map +1 -0
  142. package/lib/module/web/tools/PointerEventManager.js +4 -38
  143. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  144. package/lib/module/web/tools/Vector.js +5 -3
  145. package/lib/module/web/tools/Vector.js.map +1 -1
  146. package/lib/module/web/utils.js +184 -13
  147. package/lib/module/web/utils.js.map +1 -1
  148. package/lib/typescript/PointerType.d.ts +2 -1
  149. package/lib/typescript/components/GestureComponents.d.ts +1 -1
  150. package/lib/typescript/components/Pressable/index.d.ts +1 -1
  151. package/lib/typescript/components/Pressable/utils.d.ts +3 -5
  152. package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +35 -0
  153. package/lib/typescript/handlers/LongPressGestureHandler.d.ts +5 -1
  154. package/lib/typescript/handlers/gestures/gesture.d.ts +2 -2
  155. package/lib/typescript/handlers/gestures/hoverGesture.d.ts +1 -6
  156. package/lib/typescript/handlers/gestures/longPressGesture.d.ts +5 -0
  157. package/lib/typescript/handlers/handlersRegistry.d.ts +1 -1
  158. package/lib/typescript/jestUtils/jestUtils.d.ts +1 -1
  159. package/lib/typescript/mocks.d.ts +4 -3
  160. package/lib/typescript/utils.d.ts +1 -0
  161. package/lib/typescript/web/constants.d.ts +1 -1
  162. package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -1
  163. package/lib/typescript/web/handlers/HoverGestureHandler.d.ts +2 -0
  164. package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +3 -0
  165. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
  166. package/lib/typescript/web/handlers/PanGestureHandler.d.ts +3 -1
  167. package/lib/typescript/web/interfaces.d.ts +9 -4
  168. package/lib/typescript/web/tools/EventManager.d.ts +2 -2
  169. package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
  170. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +6 -0
  171. package/lib/typescript/web/tools/KeyboardEventManager.d.ts +13 -0
  172. package/lib/typescript/web/utils.d.ts +2 -1
  173. package/package.json +3 -3
  174. package/src/PointerType.ts +1 -0
  175. package/src/components/GestureButtons.tsx +2 -1
  176. package/src/components/GestureComponents.tsx +1 -1
  177. package/src/components/Pressable/Pressable.tsx +77 -70
  178. package/src/components/Pressable/index.ts +1 -1
  179. package/src/components/Pressable/utils.ts +5 -49
  180. package/src/components/ReanimatedSwipeable.tsx +70 -47
  181. package/src/handlers/GestureHandlerEventPayload.ts +42 -0
  182. package/src/handlers/LongPressGestureHandler.ts +6 -0
  183. package/src/handlers/createHandler.tsx +1 -0
  184. package/src/handlers/gestures/GestureDetector/utils.ts +2 -2
  185. package/src/handlers/gestures/gesture.ts +3 -1
  186. package/src/handlers/gestures/hoverGesture.ts +1 -7
  187. package/src/handlers/gestures/longPressGesture.ts +9 -0
  188. package/src/jestUtils/jestUtils.ts +9 -1
  189. package/src/{mocks.ts → mocks.tsx} +8 -3
  190. package/src/utils.ts +2 -0
  191. package/src/web/constants.ts +1 -1
  192. package/src/web/handlers/GestureHandler.ts +4 -2
  193. package/src/web/handlers/HoverGestureHandler.ts +16 -2
  194. package/src/web/handlers/LongPressGestureHandler.ts +49 -10
  195. package/src/web/handlers/NativeViewGestureHandler.ts +14 -4
  196. package/src/web/handlers/PanGestureHandler.ts +14 -1
  197. package/src/web/interfaces.ts +10 -4
  198. package/src/web/tools/EventManager.ts +2 -4
  199. package/src/web/tools/GestureHandlerDelegate.ts +1 -0
  200. package/src/web/tools/GestureHandlerWebDelegate.ts +67 -10
  201. package/src/web/tools/KeyboardEventManager.ts +91 -0
  202. package/src/web/tools/PointerEventManager.ts +2 -38
  203. package/src/web/tools/Vector.ts +4 -3
  204. package/src/web/utils.ts +188 -13
  205. package/lib/commonjs/web/tools/TouchEventManager.js +0 -164
  206. package/lib/commonjs/web/tools/TouchEventManager.js.map +0 -1
  207. package/lib/module/web/tools/TouchEventManager.js +0 -149
  208. package/lib/module/web/tools/TouchEventManager.js.map +0 -1
  209. package/lib/typescript/web/tools/TouchEventManager.d.ts +0 -11
  210. package/src/web/tools/TouchEventManager.ts +0 -175
@@ -1 +1 @@
1
- {"version":3,"sources":["PointerEventManager.ts"],"names":["EventManager","MouseButton","EventTypes","PointerTypeMapping","calculateViewScale","isPointerInBounds","PointerType","POINTER_CAPTURE_EXCLUDE_LIST","Set","PointerTypes","Touch","Stylus","PointerEventManager","constructor","view","Map","event","pointerType","x","clientX","y","clientY","adaptedEvent","mapEvent","DOWN","target","has","tagName","setPointerCapture","pointerId","markAsInBounds","trackedPointers","add","activePointersCounter","eventType","ADDITIONAL_POINTER_DOWN","onPointerAdd","onPointerDown","UP","releasePointerCapture","markAsOutOfBounds","delete","ADDITIONAL_POINTER_UP","onPointerRemove","onPointerUp","lastPosition","MOVE","hasPointerCapture","inBounds","pointerIndex","pointersInBounds","indexOf","ENTER","onPointerEnter","onPointerMove","LEAVE","onPointerLeave","onPointerOutOfBounds","CANCEL","onPointerCancel","clear","onPointerMoveOver","onPointerMoveOut","mouseButtonsMapper","set","LEFT","MIDDLE","RIGHT","BUTTON_4","BUTTON_5","Infinity","registerListeners","addEventListener","pointerDownCallback","pointerUpCallback","pointerMoveCallback","pointerCancelCallback","pointerEnterCallback","pointerLeaveCallback","lostPointerCaptureCallback","unregisterListeners","removeEventListener","rect","getBoundingClientRect","scaleX","scaleY","offsetX","left","offsetY","top","get","OTHER","button","time","timeStamp","resetManager"],"mappings":";;AAAA,OAAOA,YAAP,MAAyB,gBAAzB;AACA,SAASC,WAAT,QAA4B,qCAA5B;AACA,SAAuBC,UAAvB,QAAgD,eAAhD;AACA,SACEC,kBADF,EAEEC,kBAFF,EAGEC,iBAHF,QAIO,UAJP;AAKA,SAASC,WAAT,QAA4B,mBAA5B;AAEA,MAAMC,4BAA4B,GAAG,IAAIC,GAAJ,CAAgB,CAAC,QAAD,EAAW,OAAX,CAAhB,CAArC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,OADY;AAEnBC,EAAAA,MAAM,EAAE;AAFW,CAArB;AAKA,eAAe,MAAMC,mBAAN,SAAkCZ,YAAlC,CAA4D;AAKzEa,EAAAA,WAAW,CAACC,IAAD,EAAoB;AAC7B,UAAMA,IAAN;;AAD6B,6CAJL,IAAIN,GAAJ,EAIK;;AAAA,gDAHO,IAAIO,GAAJ,EAGP;;AAAA;;AAAA,iDAeAC,KAAD,IAAyB;AACrD,UAAIA,KAAK,CAACC,WAAN,KAAsBR,YAAY,CAACC,KAAvC,EAA8C;AAC5C;AACD;;AACD,UAAI,CAACL,iBAAiB,CAAC,KAAKS,IAAN,EAAY;AAAEI,QAAAA,CAAC,EAAEF,KAAK,CAACG,OAAX;AAAoBC,QAAAA,CAAC,EAAEJ,KAAK,CAACK;AAA7B,OAAZ,CAAtB,EAA2E;AACzE;AACD;;AAED,YAAMC,YAA0B,GAAG,KAAKC,QAAL,CAAcP,KAAd,EAAqBd,UAAU,CAACsB,IAAhC,CAAnC;AAC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K,OAFJ;AAGLiE,MAAAA,OAAO,EAAE,CAACtE,KAAK,CAACG,OAAN,GAAgB+D,IAAI,CAACK,IAAtB,IAA8BH,MAHlC;AAILI,MAAAA,OAAO,EAAE,CAACxE,KAAK,CAACK,OAAN,GAAgB6D,IAAI,CAACO,GAAtB,IAA6BJ,MAJjC;AAKLxD,MAAAA,SAAS,EAAEb,KAAK,CAACa,SALZ;AAMLK,MAAAA,SAAS,EAAEA,SANN;AAOLjB,MAAAA,WAAW,2BACTd,kBAAkB,CAACuF,GAAnB,CAAuB1E,KAAK,CAACC,WAA7B,CADS,yEACoCX,WAAW,CAACqF,KARtD;AASLC,MAAAA,MAAM,EAAE,KAAK7B,kBAAL,CAAwB2B,GAAxB,CAA4B1E,KAAK,CAAC4E,MAAlC,CATH;AAULC,MAAAA,IAAI,EAAE7E,KAAK,CAAC8E;AAVP,KAAP;AAYD;;AAEMC,EAAAA,YAAY,GAAS;AAC1B,UAAMA,YAAN;AACA,SAAKhE,eAAL,CAAqB6B,KAArB;AACD;;AApPwE","sourcesContent":["import EventManager from './EventManager';\nimport { MouseButton } from '../../handlers/gestureHandlerCommon';\nimport { AdaptedEvent, EventTypes, Point } from '../interfaces';\nimport {\n PointerTypeMapping,\n calculateViewScale,\n isPointerInBounds,\n} from '../utils';\nimport { PointerType } from '../../PointerType';\n\nconst POINTER_CAPTURE_EXCLUDE_LIST = new Set<string>(['SELECT', 'INPUT']);\nconst PointerTypes = {\n Touch: 'touch',\n Stylus: 'pen',\n};\n\nexport default class PointerEventManager extends EventManager<HTMLElement> {\n private trackedPointers = new Set<number>();\n private readonly mouseButtonsMapper = new Map<number, MouseButton>();\n private lastPosition: Point;\n\n constructor(view: HTMLElement) {\n super(view);\n\n this.mouseButtonsMapper.set(0, MouseButton.LEFT);\n this.mouseButtonsMapper.set(1, MouseButton.MIDDLE);\n this.mouseButtonsMapper.set(2, MouseButton.RIGHT);\n this.mouseButtonsMapper.set(3, MouseButton.BUTTON_4);\n this.mouseButtonsMapper.set(4, MouseButton.BUTTON_5);\n\n this.lastPosition = {\n x: -Infinity,\n y: -Infinity,\n };\n }\n\n private pointerDownCallback = (event: PointerEvent) => {\n if (event.pointerType === PointerTypes.Touch) {\n return;\n }\n if (!isPointerInBounds(this.view, { x: event.clientX, y: event.clientY })) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.DOWN);\n const target = event.target as HTMLElement;\n\n if (!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)) {\n target.setPointerCapture(adaptedEvent.pointerId);\n }\n\n this.markAsInBounds(adaptedEvent.pointerId);\n this.trackedPointers.add(adaptedEvent.pointerId);\n\n if (++this.activePointersCounter > 1) {\n adaptedEvent.eventType = EventTypes.ADDITIONAL_POINTER_DOWN;\n this.onPointerAdd(adaptedEvent);\n } else {\n this.onPointerDown(adaptedEvent);\n }\n };\n\n private pointerUpCallback = (event: PointerEvent) => {\n if (event.pointerType === PointerTypes.Touch) {\n return;\n }\n\n // When we call reset on gesture handlers, it also resets their event managers\n // In some handlers (like RotationGestureHandler) reset is called before all pointers leave view\n // This means, that activePointersCounter will be set to 0, while there are still remaining pointers on view\n // Removing them will end in activePointersCounter going below 0, therefore handlers won't behave properly\n if (this.activePointersCounter === 0) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.UP);\n const target = event.target as HTMLElement;\n\n if (!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)) {\n target.releasePointerCapture(adaptedEvent.pointerId);\n }\n\n this.markAsOutOfBounds(adaptedEvent.pointerId);\n this.trackedPointers.delete(adaptedEvent.pointerId);\n\n if (--this.activePointersCounter > 0) {\n adaptedEvent.eventType = EventTypes.ADDITIONAL_POINTER_UP;\n this.onPointerRemove(adaptedEvent);\n } else {\n this.onPointerUp(adaptedEvent);\n }\n };\n\n private pointerMoveCallback = (event: PointerEvent) => {\n if (event.pointerType === PointerTypes.Touch) {\n return;\n }\n\n // Stylus triggers `pointermove` event when it detects changes in pressure. Since it is very sensitive to those changes,\n // it constantly sends events, even though there was no change in position. To fix that we check whether\n // pointer has actually moved and if not, we do not send event.\n if (\n event.pointerType === PointerTypes.Stylus &&\n event.x === this.lastPosition.x &&\n event.y === this.lastPosition.y\n ) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.MOVE);\n const target = event.target as HTMLElement;\n\n // You may be wondering why are we setting pointer capture here, when we\n // already set it in `pointerdown` handler. Well, that's a great question,\n // for which I don't have an answer. Specification (https://www.w3.org/TR/pointerevents2/#dom-element-setpointercapture)\n // says that the requirement for `setPointerCapture` to work is that pointer\n // must be in 'active buttons state`, otherwise it will fail silently, which\n // is lovely. Obviously, when `pointerdown` is fired, one of the buttons\n // (when using mouse) is pressed, but that doesn't mean that `setPointerCapture`\n // will succeed, for some reason. Since it fails silently, we don't actually know\n // if it worked or not (there's `gotpointercapture` event, but the complexity of\n // incorporating it here seems stupid), so we just call it again here, every time\n // pointer moves until it succeeds.\n // God, I do love web development.\n if (\n !target.hasPointerCapture(event.pointerId) &&\n !POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)\n ) {\n target.setPointerCapture(event.pointerId);\n }\n\n const inBounds: boolean = isPointerInBounds(this.view, {\n x: adaptedEvent.x,\n y: adaptedEvent.y,\n });\n\n const pointerIndex: number = this.pointersInBounds.indexOf(\n adaptedEvent.pointerId\n );\n\n if (inBounds) {\n if (pointerIndex < 0) {\n adaptedEvent.eventType = EventTypes.ENTER;\n this.onPointerEnter(adaptedEvent);\n this.markAsInBounds(adaptedEvent.pointerId);\n } else {\n this.onPointerMove(adaptedEvent);\n }\n } else {\n if (pointerIndex >= 0) {\n adaptedEvent.eventType = EventTypes.LEAVE;\n this.onPointerLeave(adaptedEvent);\n this.markAsOutOfBounds(adaptedEvent.pointerId);\n } else {\n this.onPointerOutOfBounds(adaptedEvent);\n }\n }\n\n this.lastPosition.x = event.x;\n this.lastPosition.y = event.y;\n };\n\n private pointerCancelCallback = (event: PointerEvent) => {\n if (event.pointerType === PointerTypes.Touch) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.CANCEL);\n\n this.onPointerCancel(adaptedEvent);\n this.markAsOutOfBounds(adaptedEvent.pointerId);\n this.activePointersCounter = 0;\n this.trackedPointers.clear();\n };\n\n private pointerEnterCallback = (event: PointerEvent) => {\n if (event.pointerType === PointerTypes.Touch) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.ENTER);\n\n this.onPointerMoveOver(adaptedEvent);\n };\n\n private pointerLeaveCallback = (event: PointerEvent) => {\n if (event.pointerType === PointerTypes.Touch) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.LEAVE);\n\n this.onPointerMoveOut(adaptedEvent);\n };\n\n private lostPointerCaptureCallback = (event: PointerEvent) => {\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.CANCEL);\n\n if (this.trackedPointers.has(adaptedEvent.pointerId)) {\n // In some cases the `pointerup` event is not fired, but `lostpointercapture` is.\n // Here we simulate the `pointercancel` event to make sure the gesture handler stops tracking it.\n this.onPointerCancel(adaptedEvent);\n\n this.activePointersCounter = 0;\n this.trackedPointers.clear();\n }\n };\n\n public registerListeners(): void {\n this.view.addEventListener('pointerdown', this.pointerDownCallback);\n this.view.addEventListener('pointerup', this.pointerUpCallback);\n this.view.addEventListener('pointermove', this.pointerMoveCallback);\n this.view.addEventListener('pointercancel', this.pointerCancelCallback);\n\n // onPointerEnter and onPointerLeave are triggered by a custom logic responsible for\n // handling shouldCancelWhenOutside flag, and are unreliable unless the pointer is down.\n // We therefore use pointerenter and pointerleave events to handle the hover gesture,\n // mapping them to onPointerMoveOver and onPointerMoveOut respectively.\n this.view.addEventListener('pointerenter', this.pointerEnterCallback);\n this.view.addEventListener('pointerleave', this.pointerLeaveCallback);\n this.view.addEventListener(\n 'lostpointercapture',\n this.lostPointerCaptureCallback\n );\n }\n\n public unregisterListeners(): void {\n this.view.removeEventListener('pointerdown', this.pointerDownCallback);\n this.view.removeEventListener('pointerup', this.pointerUpCallback);\n this.view.removeEventListener('pointermove', this.pointerMoveCallback);\n this.view.removeEventListener('pointercancel', this.pointerCancelCallback);\n this.view.removeEventListener('pointerenter', this.pointerEnterCallback);\n this.view.removeEventListener('pointerleave', this.pointerLeaveCallback);\n this.view.removeEventListener(\n 'lostpointercapture',\n this.lostPointerCaptureCallback\n );\n }\n\n protected mapEvent(event: PointerEvent, eventType: EventTypes): AdaptedEvent {\n const rect = this.view.getBoundingClientRect();\n const { scaleX, scaleY } = calculateViewScale(this.view);\n\n return {\n x: event.clientX,\n y: event.clientY,\n offsetX: (event.clientX - rect.left) / scaleX,\n offsetY: (event.clientY - rect.top) / scaleY,\n pointerId: event.pointerId,\n eventType: eventType,\n pointerType:\n PointerTypeMapping.get(event.pointerType) ?? PointerType.OTHER,\n button: this.mouseButtonsMapper.get(event.button),\n time: event.timeStamp,\n };\n }\n\n public resetManager(): void {\n super.resetManager();\n this.trackedPointers.clear();\n }\n}\n"]}
1
+ {"version":3,"sources":["PointerEventManager.ts"],"names":["EventManager","MouseButton","EventTypes","PointerTypeMapping","calculateViewScale","tryExtractStylusData","isPointerInBounds","PointerType","POINTER_CAPTURE_EXCLUDE_LIST","Set","PointerEventManager","constructor","view","Map","event","x","clientX","y","clientY","adaptedEvent","mapEvent","DOWN","target","has","tagName","setPointerCapture","pointerId","markAsInBounds","trackedPointers","add","activePointersCounter","eventType","ADDITIONAL_POINTER_DOWN","onPointerAdd","onPointerDown","UP","releasePointerCapture","markAsOutOfBounds","delete","ADDITIONAL_POINTER_UP","onPointerRemove","onPointerUp","MOVE","hasPointerCapture","inBounds","pointerIndex","pointersInBounds","indexOf","ENTER","onPointerEnter","onPointerMove","LEAVE","onPointerLeave","onPointerOutOfBounds","lastPosition","CANCEL","onPointerCancel","clear","onPointerMoveOver","onPointerMoveOut","mouseButtonsMapper","set","LEFT","MIDDLE","RIGHT","BUTTON_4","BUTTON_5","Infinity","registerListeners","addEventListener","pointerDownCallback","pointerUpCallback","pointerMoveCallback","pointerCancelCallback","pointerEnterCallback","pointerLeaveCallback","lostPointerCaptureCallback","unregisterListeners","removeEventListener","rect","getBoundingClientRect","scaleX","scaleY","offsetX","left","offsetY","top","pointerType","get","OTHER","button","time","timeStamp","stylusData","resetManager"],"mappings":";;AAAA,OAAOA,YAAP,MAAyB,gBAAzB;AACA,SAASC,WAAT,QAA4B,qCAA5B;AACA,SAAuBC,UAAvB,QAAgD,eAAhD;AACA,SACEC,kBADF,EAEEC,kBAFF,EAGEC,oBAHF,EAIEC,iBAJF,QAKO,UALP;AAMA,SAASC,WAAT,QAA4B,mBAA5B;AAEA,MAAMC,4BAA4B,GAAG,IAAIC,GAAJ,CAAgB,CAAC,QAAD,EAAW,OAAX,CAAhB,CAArC;AAEA,eAAe,MAAMC,mBAAN,SAAkCV,YAAlC,CAA4D;AAKzEW,EAAAA,WAAW,CAACC,IAAD,EAAoB;AAC7B,UAAMA,IAAN;;AAD6B,6CAJL,IAAIH,GAAJ,EAIK;;AAAA,gDAHO,IAAII,GAAJ,EAGP;;AAAA;;AAAA,iDAeAC,KAAD,IAAyB;AACrD,UAAI,CAACR,iBAAiB,CAAC,KAAKM,IAAN,EAAY;AAAEG,QAAAA,CAAC,EAAED,KAAK,CAACE,OAAX;AAAoBC,QAAAA,CAAC,EAAEH,KAAK,CAACI;AAA7B,OAAZ,CAAtB,EAA2E;AACzE;AACD;;AAED,YAAMC,YAA0B,GAAG,KAAKC,QAAL,CAAcN,KAAd,EAAqBZ,UAAU,CAACmB,IAAhC,CAAnC;AACA,YAAMC,MAAM,GAAGR,KAAK,CAACQ,MAArB;;AAEA,UAAI,CAACd,4BAA4B,CAACe,GAA7B,CAAiCD,MAAM,CAACE,OAAxC,CAAL,EAAuD;AACrDF,QAAAA,MAAM,CAACG,iBAAP,CAAyBN,YAAY,CAACO,SAAtC;AACD;;AAED,WAAKC,cA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KAAKH,oBAAnD;AACA,SAAK/D,IAAL,CAAUkE,mBAAV,CACE,oBADF,EAEE,KAAKF,0BAFP;AAID;;AAESxD,EAAAA,QAAQ,CAACN,KAAD,EAAsBiB,SAAtB,EAA2D;AAAA;;AAC3E,UAAMgD,IAAI,GAAG,KAAKnE,IAAL,CAAUoE,qBAAV,EAAb;AACA,UAAM;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAqB9E,kBAAkB,CAAC,KAAKQ,IAAN,CAA7C;AAEA,WAAO;AACLG,MAAAA,CAAC,EAAED,KAAK,CAACE,OADJ;AAELC,MAAAA,CAAC,EAAEH,KAAK,CAACI,OAFJ;AAGLiE,MAAAA,OAAO,EAAE,CAACrE,KAAK,CAACE,OAAN,GAAgB+D,IAAI,CAACK,IAAtB,IAA8BH,MAHlC;AAILI,MAAAA,OAAO,EAAE,CAACvE,KAAK,CAACI,OAAN,GAAgB6D,IAAI,CAACO,GAAtB,IAA6BJ,MAJjC;AAKLxD,MAAAA,SAAS,EAAEZ,KAAK,CAACY,SALZ;AAMLK,MAAAA,SAAS,EAAEA,SANN;AAOLwD,MAAAA,WAAW,2BACTpF,kBAAkB,CAACqF,GAAnB,CAAuB1E,KAAK,CAACyE,WAA7B,CADS,yEACoChF,WAAW,CAACkF,KARtD;AASLC,MAAAA,MAAM,EAAE,KAAK9B,kBAAL,CAAwB4B,GAAxB,CAA4B1E,KAAK,CAAC4E,MAAlC,CATH;AAULC,MAAAA,IAAI,EAAE7E,KAAK,CAAC8E,SAVP;AAWLC,MAAAA,UAAU,EAAExF,oBAAoB,CAACS,KAAD;AAX3B,KAAP;AAaD;;AAEMgF,EAAAA,YAAY,GAAS;AAC1B,UAAMA,YAAN;AACA,SAAKlE,eAAL,CAAqB6B,KAArB;AACD;;AAnNwE","sourcesContent":["import EventManager from './EventManager';\nimport { MouseButton } from '../../handlers/gestureHandlerCommon';\nimport { AdaptedEvent, EventTypes, Point } from '../interfaces';\nimport {\n PointerTypeMapping,\n calculateViewScale,\n tryExtractStylusData,\n isPointerInBounds,\n} from '../utils';\nimport { PointerType } from '../../PointerType';\n\nconst POINTER_CAPTURE_EXCLUDE_LIST = new Set<string>(['SELECT', 'INPUT']);\n\nexport default class PointerEventManager extends EventManager<HTMLElement> {\n private trackedPointers = new Set<number>();\n private readonly mouseButtonsMapper = new Map<number, MouseButton>();\n private lastPosition: Point;\n\n constructor(view: HTMLElement) {\n super(view);\n\n this.mouseButtonsMapper.set(0, MouseButton.LEFT);\n this.mouseButtonsMapper.set(1, MouseButton.MIDDLE);\n this.mouseButtonsMapper.set(2, MouseButton.RIGHT);\n this.mouseButtonsMapper.set(3, MouseButton.BUTTON_4);\n this.mouseButtonsMapper.set(4, MouseButton.BUTTON_5);\n\n this.lastPosition = {\n x: -Infinity,\n y: -Infinity,\n };\n }\n\n private pointerDownCallback = (event: PointerEvent) => {\n if (!isPointerInBounds(this.view, { x: event.clientX, y: event.clientY })) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.DOWN);\n const target = event.target as HTMLElement;\n\n if (!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)) {\n target.setPointerCapture(adaptedEvent.pointerId);\n }\n\n this.markAsInBounds(adaptedEvent.pointerId);\n this.trackedPointers.add(adaptedEvent.pointerId);\n\n if (++this.activePointersCounter > 1) {\n adaptedEvent.eventType = EventTypes.ADDITIONAL_POINTER_DOWN;\n this.onPointerAdd(adaptedEvent);\n } else {\n this.onPointerDown(adaptedEvent);\n }\n };\n\n private pointerUpCallback = (event: PointerEvent) => {\n // When we call reset on gesture handlers, it also resets their event managers\n // In some handlers (like RotationGestureHandler) reset is called before all pointers leave view\n // This means, that activePointersCounter will be set to 0, while there are still remaining pointers on view\n // Removing them will end in activePointersCounter going below 0, therefore handlers won't behave properly\n if (this.activePointersCounter === 0) {\n return;\n }\n\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.UP);\n const target = event.target as HTMLElement;\n\n if (!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)) {\n target.releasePointerCapture(adaptedEvent.pointerId);\n }\n\n this.markAsOutOfBounds(adaptedEvent.pointerId);\n this.trackedPointers.delete(adaptedEvent.pointerId);\n\n if (--this.activePointersCounter > 0) {\n adaptedEvent.eventType = EventTypes.ADDITIONAL_POINTER_UP;\n this.onPointerRemove(adaptedEvent);\n } else {\n this.onPointerUp(adaptedEvent);\n }\n };\n\n private pointerMoveCallback = (event: PointerEvent) => {\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.MOVE);\n const target = event.target as HTMLElement;\n\n // You may be wondering why are we setting pointer capture here, when we\n // already set it in `pointerdown` handler. Well, that's a great question,\n // for which I don't have an answer. Specification (https://www.w3.org/TR/pointerevents2/#dom-element-setpointercapture)\n // says that the requirement for `setPointerCapture` to work is that pointer\n // must be in 'active buttons state`, otherwise it will fail silently, which\n // is lovely. Obviously, when `pointerdown` is fired, one of the buttons\n // (when using mouse) is pressed, but that doesn't mean that `setPointerCapture`\n // will succeed, for some reason. Since it fails silently, we don't actually know\n // if it worked or not (there's `gotpointercapture` event, but the complexity of\n // incorporating it here seems stupid), so we just call it again here, every time\n // pointer moves until it succeeds.\n // God, I do love web development.\n if (\n !target.hasPointerCapture(event.pointerId) &&\n !POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)\n ) {\n target.setPointerCapture(event.pointerId);\n }\n\n const inBounds: boolean = isPointerInBounds(this.view, {\n x: adaptedEvent.x,\n y: adaptedEvent.y,\n });\n\n const pointerIndex: number = this.pointersInBounds.indexOf(\n adaptedEvent.pointerId\n );\n\n if (inBounds) {\n if (pointerIndex < 0) {\n adaptedEvent.eventType = EventTypes.ENTER;\n this.onPointerEnter(adaptedEvent);\n this.markAsInBounds(adaptedEvent.pointerId);\n } else {\n this.onPointerMove(adaptedEvent);\n }\n } else {\n if (pointerIndex >= 0) {\n adaptedEvent.eventType = EventTypes.LEAVE;\n this.onPointerLeave(adaptedEvent);\n this.markAsOutOfBounds(adaptedEvent.pointerId);\n } else {\n this.onPointerOutOfBounds(adaptedEvent);\n }\n }\n\n this.lastPosition.x = event.x;\n this.lastPosition.y = event.y;\n };\n\n private pointerCancelCallback = (event: PointerEvent) => {\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.CANCEL);\n\n this.onPointerCancel(adaptedEvent);\n this.markAsOutOfBounds(adaptedEvent.pointerId);\n this.activePointersCounter = 0;\n this.trackedPointers.clear();\n };\n\n private pointerEnterCallback = (event: PointerEvent) => {\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.ENTER);\n\n this.onPointerMoveOver(adaptedEvent);\n };\n\n private pointerLeaveCallback = (event: PointerEvent) => {\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.LEAVE);\n\n this.onPointerMoveOut(adaptedEvent);\n };\n\n private lostPointerCaptureCallback = (event: PointerEvent) => {\n const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.CANCEL);\n\n if (this.trackedPointers.has(adaptedEvent.pointerId)) {\n // In some cases the `pointerup` event is not fired, but `lostpointercapture` is.\n // Here we simulate the `pointercancel` event to make sure the gesture handler stops tracking it.\n this.onPointerCancel(adaptedEvent);\n\n this.activePointersCounter = 0;\n this.trackedPointers.clear();\n }\n };\n\n public registerListeners(): void {\n this.view.addEventListener('pointerdown', this.pointerDownCallback);\n this.view.addEventListener('pointerup', this.pointerUpCallback);\n this.view.addEventListener('pointermove', this.pointerMoveCallback);\n this.view.addEventListener('pointercancel', this.pointerCancelCallback);\n\n // onPointerEnter and onPointerLeave are triggered by a custom logic responsible for\n // handling shouldCancelWhenOutside flag, and are unreliable unless the pointer is down.\n // We therefore use pointerenter and pointerleave events to handle the hover gesture,\n // mapping them to onPointerMoveOver and onPointerMoveOut respectively.\n this.view.addEventListener('pointerenter', this.pointerEnterCallback);\n this.view.addEventListener('pointerleave', this.pointerLeaveCallback);\n this.view.addEventListener(\n 'lostpointercapture',\n this.lostPointerCaptureCallback\n );\n }\n\n public unregisterListeners(): void {\n this.view.removeEventListener('pointerdown', this.pointerDownCallback);\n this.view.removeEventListener('pointerup', this.pointerUpCallback);\n this.view.removeEventListener('pointermove', this.pointerMoveCallback);\n this.view.removeEventListener('pointercancel', this.pointerCancelCallback);\n this.view.removeEventListener('pointerenter', this.pointerEnterCallback);\n this.view.removeEventListener('pointerleave', this.pointerLeaveCallback);\n this.view.removeEventListener(\n 'lostpointercapture',\n this.lostPointerCaptureCallback\n );\n }\n\n protected mapEvent(event: PointerEvent, eventType: EventTypes): AdaptedEvent {\n const rect = this.view.getBoundingClientRect();\n const { scaleX, scaleY } = calculateViewScale(this.view);\n\n return {\n x: event.clientX,\n y: event.clientY,\n offsetX: (event.clientX - rect.left) / scaleX,\n offsetY: (event.clientY - rect.top) / scaleY,\n pointerId: event.pointerId,\n eventType: eventType,\n pointerType:\n PointerTypeMapping.get(event.pointerType) ?? PointerType.OTHER,\n button: this.mouseButtonsMapper.get(event.button),\n time: event.timeStamp,\n stylusData: tryExtractStylusData(event),\n };\n }\n\n public resetManager(): void {\n super.resetManager();\n this.trackedPointers.clear();\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
3
  import { DiagonalDirections, Directions } from '../../Directions';
4
- import { MINIMAL_FLING_VELOCITY } from '../constants';
4
+ import { MINIMAL_RECOGNIZABLE_MAGNITUDE } from '../constants';
5
5
  export default class Vector {
6
6
  constructor(x, y) {
7
7
  _defineProperty(this, "x", void 0);
@@ -17,13 +17,15 @@ export default class Vector {
17
17
  this.x = x;
18
18
  this.y = y;
19
19
  this._magnitude = Math.hypot(this.x, this.y);
20
- const isMagnitudeSufficient = this._magnitude > MINIMAL_FLING_VELOCITY;
20
+ const isMagnitudeSufficient = this._magnitude > MINIMAL_RECOGNIZABLE_MAGNITUDE;
21
21
  this.unitX = isMagnitudeSufficient ? this.x / this._magnitude : 0;
22
22
  this.unitY = isMagnitudeSufficient ? this.y / this._magnitude : 0;
23
23
  }
24
24
 
25
25
  static fromDirection(direction) {
26
- return DirectionToVectorMappings.get(direction);
26
+ var _DirectionToVectorMap;
27
+
28
+ return (_DirectionToVectorMap = DirectionToVectorMappings.get(direction)) !== null && _DirectionToVectorMap !== void 0 ? _DirectionToVectorMap : new Vector(0, 0);
27
29
  }
28
30
 
29
31
  static fromVelocity(tracker, pointerId) {
@@ -1 +1 @@
1
- {"version":3,"sources":["Vector.ts"],"names":["DiagonalDirections","Directions","MINIMAL_FLING_VELOCITY","Vector","constructor","x","y","_magnitude","Math","hypot","isMagnitudeSufficient","unitX","unitY","fromDirection","direction","DirectionToVectorMappings","get","fromVelocity","tracker","pointerId","velocity","getVelocity","magnitude","computeSimilarity","vector","isSimilar","threshold","Map","LEFT","RIGHT","UP","DOWN","UP_RIGHT","DOWN_RIGHT","UP_LEFT","DOWN_LEFT"],"mappings":";;AAAA,SAASA,kBAAT,EAA6BC,UAA7B,QAA+C,kBAA/C;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAGA,eAAe,MAAMC,MAAN,CAAa;AAO1BC,EAAAA,WAAW,CAACC,CAAD,EAAYC,CAAZ,EAAuB;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAChC,SAAKD,CAAL,GAASA,CAAT;AACA,SAAKC,CAAL,GAASA,CAAT;AAEA,SAAKC,UAAL,GAAkBC,IAAI,CAACC,KAAL,CAAW,KAAKJ,CAAhB,EAAmB,KAAKC,CAAxB,CAAlB;AACA,UAAMI,qBAAqB,GAAG,KAAKH,UAAL,GAAkBL,sBAAhD;AAEA,SAAKS,KAAL,GAAaD,qBAAqB,GAAG,KAAKL,CAAL,GAAS,KAAKE,UAAjB,GAA8B,CAAhE;AACA,SAAKK,KAAL,GAAaF,qBAAqB,GAAG,KAAKJ,CAAL,GAAS,KAAKC,UAAjB,GAA8B,CAAhE;AACD;;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,IAAI9B,MAAJ,CAAW,CAAX,EAAc,CAAd,CAAhC,CAPA,EAQA,CAACH,kBAAkB,CAACkC,OAApB,EAA6B,IAAI/B,MAAJ,CAAW,CAAC,CAAZ,EAAe,CAAC,CAAhB,CAA7B,CARA,EASA,CAACH,kBAAkB,CAACmC,SAApB,EAA+B,IAAIhC,MAAJ,CAAW,CAAC,CAAZ,EAAe,CAAf,CAA/B,CATA,CAHgC,CAAlC","sourcesContent":["import { DiagonalDirections, Directions } from '../../Directions';\nimport { MINIMAL_FLING_VELOCITY } from '../constants';\nimport PointerTracker from './PointerTracker';\n\nexport default class Vector {\n private readonly x;\n private readonly y;\n private readonly unitX;\n private readonly unitY;\n private readonly _magnitude;\n\n constructor(x: number, y: number) {\n this.x = x;\n this.y = y;\n\n this._magnitude = Math.hypot(this.x, this.y);\n const isMagnitudeSufficient = this._magnitude > MINIMAL_FLING_VELOCITY;\n\n this.unitX = isMagnitudeSufficient ? this.x / this._magnitude : 0;\n this.unitY = isMagnitudeSufficient ? this.y / this._magnitude : 0;\n }\n\n static fromDirection(direction: Directions | DiagonalDirections): Vector {\n return DirectionToVectorMappings.get(direction)!;\n }\n\n static fromVelocity(tracker: PointerTracker, pointerId: number) {\n const velocity = tracker.getVelocity(pointerId);\n return new Vector(velocity.x, velocity.y);\n }\n\n get magnitude() {\n return this._magnitude;\n }\n\n computeSimilarity(vector: Vector) {\n return this.unitX * vector.unitX + this.unitY * vector.unitY;\n }\n\n isSimilar(vector: Vector, threshold: number) {\n return this.computeSimilarity(vector) > threshold;\n }\n}\n\nconst DirectionToVectorMappings = new Map<\n Directions | DiagonalDirections,\n Vector\n>([\n [Directions.LEFT, new Vector(-1, 0)],\n [Directions.RIGHT, new Vector(1, 0)],\n [Directions.UP, new Vector(0, -1)],\n [Directions.DOWN, new Vector(0, 1)],\n\n [DiagonalDirections.UP_RIGHT, new Vector(1, -1)],\n [DiagonalDirections.DOWN_RIGHT, new Vector(1, 1)],\n [DiagonalDirections.UP_LEFT, new Vector(-1, -1)],\n [DiagonalDirections.DOWN_LEFT, new Vector(-1, 1)],\n]);\n"]}
1
+ {"version":3,"sources":["Vector.ts"],"names":["DiagonalDirections","Directions","MINIMAL_RECOGNIZABLE_MAGNITUDE","Vector","constructor","x","y","_magnitude","Math","hypot","isMagnitudeSufficient","unitX","unitY","fromDirection","direction","DirectionToVectorMappings","get","fromVelocity","tracker","pointerId","velocity","getVelocity","magnitude","computeSimilarity","vector","isSimilar","threshold","Map","LEFT","RIGHT","UP","DOWN","UP_RIGHT","DOWN_RIGHT","UP_LEFT","DOWN_LEFT"],"mappings":";;AAAA,SAASA,kBAAT,EAA6BC,UAA7B,QAA+C,kBAA/C;AACA,SAASC,8BAAT,QAA+C,cAA/C;AAGA,eAAe,MAAMC,MAAN,CAAa;AAO1BC,EAAAA,WAAW,CAACC,CAAD,EAAYC,CAAZ,EAAuB;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAChC,SAAKD,CAAL,GAASA,CAAT;AACA,SAAKC,CAAL,GAASA,CAAT;AAEA,SAAKC,UAAL,GAAkBC,IAAI,CAACC,KAAL,CAAW,KAAKJ,CAAhB,EAAmB,KAAKC,CAAxB,CAAlB;AACA,UAAMI,qBAAqB,GACzB,KAAKH,UAAL,GAAkBL,8BADpB;AAGA,SAAKS,KAAL,GAAaD,qBAAqB,GAAG,KAAKL,CAAL,GAAS,KAAKE,UAAjB,GAA8B,CAAhE;AACA,SAAKK,KAAL,GAAaF,qBAAqB,GAAG,KAAKJ,CAAL,GAAS,KAAKC,UAAjB,GAA8B,CAAhE;AACD;;AAEmB,SAAbM,aAAa,CAACC,SAAD,EAAqD;AAAA;;AACvE,oCAAOC,yBAAyB,CAACC,GAA1B,CAA8BF,SAA9B,CAAP,yEAAmD,IAAIX,MAAJ,CAAW,CAAX,EAAc,CAAd,CAAnD;AACD;;AAEkB,SAAZc,YAAY,CAACC,OAAD,EAA0BC,SAA1B,EAA6C;AAC9D,UAAMC,QAAQ,GAAGF,OAA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AApB,EAA+B,IAAIhC,MAAJ,CAAW,CAAC,CAAZ,EAAe,CAAf,CAA/B,CATA,CAHgC,CAAlC","sourcesContent":["import { DiagonalDirections, Directions } from '../../Directions';\nimport { MINIMAL_RECOGNIZABLE_MAGNITUDE } from '../constants';\nimport PointerTracker from './PointerTracker';\n\nexport default class Vector {\n private readonly x;\n private readonly y;\n private readonly unitX;\n private readonly unitY;\n private readonly _magnitude;\n\n constructor(x: number, y: number) {\n this.x = x;\n this.y = y;\n\n this._magnitude = Math.hypot(this.x, this.y);\n const isMagnitudeSufficient =\n this._magnitude > MINIMAL_RECOGNIZABLE_MAGNITUDE;\n\n this.unitX = isMagnitudeSufficient ? this.x / this._magnitude : 0;\n this.unitY = isMagnitudeSufficient ? this.y / this._magnitude : 0;\n }\n\n static fromDirection(direction: Directions | DiagonalDirections): Vector {\n return DirectionToVectorMappings.get(direction) ?? new Vector(0, 0);\n }\n\n static fromVelocity(tracker: PointerTracker, pointerId: number) {\n const velocity = tracker.getVelocity(pointerId);\n return new Vector(velocity.x, velocity.y);\n }\n\n get magnitude() {\n return this._magnitude;\n }\n\n computeSimilarity(vector: Vector) {\n return this.unitX * vector.unitX + this.unitY * vector.unitY;\n }\n\n isSimilar(vector: Vector, threshold: number) {\n return this.computeSimilarity(vector) > threshold;\n }\n}\n\nconst DirectionToVectorMappings = new Map<\n Directions | DiagonalDirections,\n Vector\n>([\n [Directions.LEFT, new Vector(-1, 0)],\n [Directions.RIGHT, new Vector(1, 0)],\n [Directions.UP, new Vector(0, -1)],\n [Directions.DOWN, new Vector(0, 1)],\n\n [DiagonalDirections.UP_RIGHT, new Vector(1, -1)],\n [DiagonalDirections.DOWN_RIGHT, new Vector(1, 1)],\n [DiagonalDirections.UP_LEFT, new Vector(-1, -1)],\n [DiagonalDirections.DOWN_LEFT, new Vector(-1, 1)],\n]);\n"]}
@@ -16,26 +16,197 @@ export function calculateViewScale(view) {
16
16
  const resultScales = {
17
17
  scaleX: 1,
18
18
  scaleY: 1
19
- };
20
- const scales = styles.scale.split(' ');
19
+ }; // Get scales from scale property
21
20
 
22
- if (scales[0] !== 'none') {
23
- resultScales.scaleX = parseFloat(scales[0]);
24
- }
21
+ if (styles.scale !== undefined && styles.scale !== 'none') {
22
+ const scales = styles.scale.split(' ');
23
+
24
+ if (scales[0]) {
25
+ resultScales.scaleX = parseFloat(scales[0]);
26
+ }
27
+
28
+ resultScales.scaleY = scales[1] ? parseFloat(scales[1]) : parseFloat(scales[0]);
29
+ } // Get scales from transform property
25
30
 
26
- if (scales[1]) {
27
- resultScales.scaleY = parseFloat(scales[1]);
28
- }
29
31
 
30
32
  const matrixElements = (_RegExp$exec = new RegExp(/matrix\((.+)\)/).exec(styles.transform)) === null || _RegExp$exec === void 0 ? void 0 : _RegExp$exec[1];
31
33
 
32
- if (!matrixElements) {
33
- return resultScales;
34
+ if (matrixElements) {
35
+ const matrixElementsArray = matrixElements.split(', ');
36
+ resultScales.scaleX *= parseFloat(matrixElementsArray[0]);
37
+ resultScales.scaleY *= parseFloat(matrixElementsArray[3]);
34
38
  }
35
39
 
36
- const matrixElementsArray = matrixElements.split(', ');
37
- resultScales.scaleX *= parseFloat(matrixElementsArray[0]);
38
- resultScales.scaleY *= parseFloat(matrixElementsArray[3]);
39
40
  return resultScales;
40
41
  }
42
+ export function tryExtractStylusData(event) {
43
+ const pointerType = PointerTypeMapping.get(event.pointerType);
44
+
45
+ if (pointerType !== PointerType.STYLUS) {
46
+ return;
47
+ } // @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
48
+
49
+
50
+ const eventAzimuthAngle = event.azimuthAngle; // @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
51
+
52
+ const eventAltitudeAngle = event.altitudeAngle;
53
+
54
+ if (event.tiltX === 0 && event.tiltY === 0) {
55
+ // If we are in this branch, it means that either tilt properties are not supported and we have to calculate them from altitude and azimuth angles,
56
+ // or stylus is perpendicular to the screen and we can use altitude / azimuth instead of tilt
57
+ // If azimuth and altitude are undefined in this branch, it means that we are either perpendicular to the screen,
58
+ // or that none of the position sets is supported. In that case, we can treat stylus as perpendicular
59
+ if (eventAzimuthAngle === undefined || eventAltitudeAngle === undefined) {
60
+ return {
61
+ tiltX: 0,
62
+ tiltY: 0,
63
+ azimuthAngle: Math.PI / 2,
64
+ altitudeAngle: Math.PI / 2,
65
+ pressure: event.pressure
66
+ };
67
+ }
68
+
69
+ const {
70
+ tiltX,
71
+ tiltY
72
+ } = spherical2tilt(eventAltitudeAngle, eventAzimuthAngle);
73
+ return {
74
+ tiltX,
75
+ tiltY,
76
+ azimuthAngle: eventAzimuthAngle,
77
+ altitudeAngle: eventAltitudeAngle,
78
+ pressure: event.pressure
79
+ };
80
+ }
81
+
82
+ const {
83
+ altitudeAngle,
84
+ azimuthAngle
85
+ } = tilt2spherical(event.tiltX, event.tiltY);
86
+ return {
87
+ tiltX: event.tiltX,
88
+ tiltY: event.tiltY,
89
+ azimuthAngle,
90
+ altitudeAngle,
91
+ pressure: event.pressure
92
+ };
93
+ } // `altitudeAngle` and `azimuthAngle` are experimental properties, which are not supported on Firefox and Safari.
94
+ // Given that, we use `tilt` properties and algorithm that converts one value to another.
95
+ //
96
+ // Source: https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle
97
+
98
+ function tilt2spherical(tiltX, tiltY) {
99
+ const tiltXrad = tiltX * Math.PI / 180;
100
+ const tiltYrad = tiltY * Math.PI / 180; // calculate azimuth angle
101
+
102
+ let azimuthAngle = 0;
103
+
104
+ if (tiltX === 0) {
105
+ if (tiltY > 0) {
106
+ azimuthAngle = Math.PI / 2;
107
+ } else if (tiltY < 0) {
108
+ azimuthAngle = 3 * Math.PI / 2;
109
+ }
110
+ } else if (tiltY === 0) {
111
+ if (tiltX < 0) {
112
+ azimuthAngle = Math.PI;
113
+ }
114
+ } else if (Math.abs(tiltX) === 90 || Math.abs(tiltY) === 90) {
115
+ // not enough information to calculate azimuth
116
+ azimuthAngle = 0;
117
+ } else {
118
+ // Non-boundary case: neither tiltX nor tiltY is equal to 0 or +-90
119
+ const tanX = Math.tan(tiltXrad);
120
+ const tanY = Math.tan(tiltYrad);
121
+ azimuthAngle = Math.atan2(tanY, tanX);
122
+
123
+ if (azimuthAngle < 0) {
124
+ azimuthAngle += 2 * Math.PI;
125
+ }
126
+ } // calculate altitude angle
127
+
128
+
129
+ let altitudeAngle = 0;
130
+
131
+ if (Math.abs(tiltX) === 90 || Math.abs(tiltY) === 90) {
132
+ altitudeAngle = 0;
133
+ } else if (tiltX === 0) {
134
+ altitudeAngle = Math.PI / 2 - Math.abs(tiltYrad);
135
+ } else if (tiltY === 0) {
136
+ altitudeAngle = Math.PI / 2 - Math.abs(tiltXrad);
137
+ } else {
138
+ // Non-boundary case: neither tiltX nor tiltY is equal to 0 or +-90
139
+ altitudeAngle = Math.atan(1.0 / Math.sqrt(Math.pow(Math.tan(tiltXrad), 2) + Math.pow(Math.tan(tiltYrad), 2)));
140
+ }
141
+
142
+ return {
143
+ altitudeAngle: altitudeAngle,
144
+ azimuthAngle: azimuthAngle
145
+ };
146
+ } // If we are on a platform that doesn't support `tiltX` and `tiltY`, we have to calculate them from `altitude` and `azimuth` angles.
147
+ //
148
+ // Source: https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle
149
+
150
+
151
+ function spherical2tilt(altitudeAngle, azimuthAngle) {
152
+ const radToDeg = 180 / Math.PI;
153
+ let tiltXrad = 0;
154
+ let tiltYrad = 0;
155
+
156
+ if (altitudeAngle === 0) {
157
+ // the pen is in the X-Y plane
158
+ if (azimuthAngle === 0 || azimuthAngle === 2 * Math.PI) {
159
+ // pen is on positive X axis
160
+ tiltXrad = Math.PI / 2;
161
+ }
162
+
163
+ if (azimuthAngle === Math.PI / 2) {
164
+ // pen is on positive Y axis
165
+ tiltYrad = Math.PI / 2;
166
+ }
167
+
168
+ if (azimuthAngle === Math.PI) {
169
+ // pen is on negative X axis
170
+ tiltXrad = -Math.PI / 2;
171
+ }
172
+
173
+ if (azimuthAngle === 3 * Math.PI / 2) {
174
+ // pen is on negative Y axis
175
+ tiltYrad = -Math.PI / 2;
176
+ }
177
+
178
+ if (azimuthAngle > 0 && azimuthAngle < Math.PI / 2) {
179
+ tiltXrad = Math.PI / 2;
180
+ tiltYrad = Math.PI / 2;
181
+ }
182
+
183
+ if (azimuthAngle > Math.PI / 2 && azimuthAngle < Math.PI) {
184
+ tiltXrad = -Math.PI / 2;
185
+ tiltYrad = Math.PI / 2;
186
+ }
187
+
188
+ if (azimuthAngle > Math.PI && azimuthAngle < 3 * Math.PI / 2) {
189
+ tiltXrad = -Math.PI / 2;
190
+ tiltYrad = -Math.PI / 2;
191
+ }
192
+
193
+ if (azimuthAngle > 3 * Math.PI / 2 && azimuthAngle < 2 * Math.PI) {
194
+ tiltXrad = Math.PI / 2;
195
+ tiltYrad = -Math.PI / 2;
196
+ }
197
+ }
198
+
199
+ if (altitudeAngle !== 0) {
200
+ const tanAlt = Math.tan(altitudeAngle);
201
+ tiltXrad = Math.atan(Math.cos(azimuthAngle) / tanAlt);
202
+ tiltYrad = Math.atan(Math.sin(azimuthAngle) / tanAlt);
203
+ }
204
+
205
+ const tiltX = Math.round(tiltXrad * radToDeg);
206
+ const tiltY = Math.round(tiltYrad * radToDeg);
207
+ return {
208
+ tiltX,
209
+ tiltY
210
+ };
211
+ }
41
212
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["utils.ts"],"names":["PointerType","isPointerInBounds","view","x","y","rect","getBoundingClientRect","left","right","top","bottom","PointerTypeMapping","Map","MOUSE","TOUCH","STYLUS","OTHER","degToRad","degrees","Math","PI","coneToDeviation","cos","calculateViewScale","styles","getComputedStyle","resultScales","scaleX","scaleY","scales","scale","split","parseFloat","matrixElements","RegExp","exec","transform","matrixElementsArray"],"mappings":"AAAA,SAASA,WAAT,QAA4B,gBAA5B;AAGA,OAAO,S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,CAAhC;AACD;;AAED,MAAIA,MAAM,CAAC,CAAD,CAAV,EAAe;AACbH,IAAAA,YAAY,CAACE,MAAb,GAAsBI,UAAU,CAACH,MAAM,CAAC,CAAD,CAAP,CAAhC;AACD;;AAED,QAAMI,cAAc,mBAAG,IAAIC,MAAJ,CAAW,gBAAX,EAA6BC,IAA7B,CACrBX,MAAM,CAACY,SADc,CAAH,iDAAG,aAEnB,CAFmB,CAAvB;;AAIA,MAAI,CAACH,cAAL,EAAqB;AACnB,WAAOP,YAAP;AACD;;AAED,QAAMW,mBAAmB,GAAGJ,cAAc,CAACF,KAAf,CAAqB,IAArB,CAA5B;AAEAL,EAAAA,YAAY,CAACC,MAAb,IAAuBK,UAAU,CAACK,mBAAmB,CAAC,CAAD,CAApB,CAAjC;AACAX,EAAAA,YAAY,CAACE,MAAb,IAAuBI,UAAU,CAACK,mBAAmB,CAAC,CAAD,CAApB,CAAjC;AAEA,SAAOX,YAAP;AACD","sourcesContent":["import { PointerType } from '../PointerType';\nimport { Point } from './interfaces';\n\nexport function isPointerInBounds(view: HTMLElement, { x, y }: Point): boolean {\n const rect: DOMRect = view.getBoundingClientRect();\n\n return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;\n}\n\nexport const PointerTypeMapping = new Map<string, PointerType>([\n ['mouse', PointerType.MOUSE],\n ['touch', PointerType.TOUCH],\n ['pen', PointerType.STYLUS],\n ['none', PointerType.OTHER],\n]);\n\nexport const degToRad = (degrees: number) => (degrees * Math.PI) / 180;\n\nexport const coneToDeviation = (degrees: number) =>\n Math.cos(degToRad(degrees / 2));\n\nexport function calculateViewScale(view: HTMLElement) {\n const styles = getComputedStyle(view);\n\n const resultScales = {\n scaleX: 1,\n scaleY: 1,\n };\n\n const scales = styles.scale.split(' ');\n\n if (scales[0] !== 'none') {\n resultScales.scaleX = parseFloat(scales[0]);\n }\n\n if (scales[1]) {\n resultScales.scaleY = parseFloat(scales[1]);\n }\n\n const matrixElements = new RegExp(/matrix\\((.+)\\)/).exec(\n styles.transform\n )?.[1];\n\n if (!matrixElements) {\n return resultScales;\n }\n\n const matrixElementsArray = matrixElements.split(', ');\n\n resultScales.scaleX *= parseFloat(matrixElementsArray[0]);\n resultScales.scaleY *= parseFloat(matrixElementsArray[3]);\n\n return resultScales;\n}\n"]}
1
+ {"version":3,"sources":["utils.ts"],"names":["PointerType","isPointerInBounds","view","x","y","rect","getBoundingClientRect","left","right","top","bottom","PointerTypeMapping","Map","MOUSE","TOUCH","STYLUS","OTHER","degToRad","degrees","Math","PI","coneToDeviation","cos","calculateViewScale","styles","getComputedStyle","resultScales","scaleX","scaleY","scale","undefined","scales","split","parseFloat","matrixElements","RegExp","exec","transform","matrixElementsArray","tryExtractStylusData","event","pointerType","get","eventAzimuthAngle","azimuthAngle","eventAltitudeAngle","altitudeAngle","tiltX","tiltY","pressure","spherical2tilt","tilt2spherical","tiltXrad","tiltYrad","abs","tanX","tan","tanY","atan2","atan","sqrt","pow","radToDeg","tanAlt","sin","round"],"mappings":"AAAA,SAASA,WAAT,QAA4B,gBAA5B;AAGA,OAAO,SAASC,iBAAT,CAA2BC,IAA3B,EAA8C;AAAEC,EAAAA,CAAF;AAAKC,EAAAA;AAAL,CAA9C,EAAwE;AAC7E,QAAMC,IAAa,GAAGH,IAAI,CAACI,qBAAL,EAAtB;AAEA,SAAOH,CAAC,IAAIE,IAAI,CAACE,IAAV,IAAkBJ,CAAC,IAAIE,IAAI,CAACG,KAA5B,IAAqCJ,CAAC,IAAIC,IAAI,CAACI,GAA/C,IAAsDL,CAAC,IAAIC,IAAI,CAACK,MAAvE;AACD;AAED,OAAO,MAAMC,kBAAkB,GAAG,IAAIC,GAAJ,CAA6B,CAC7D,CAAC,OAAD,EAAUZ,WAAW,CAACa,KAAtB,CAD6D,EAE7D,CAAC,OAAD,EAAUb,WAAW,CAACc,KAAtB,CAF6D,EAG7D,CAAC,KAAD,EAAQd,WAAW,CAACe,MAApB,CAH6D,EAI7D,CAAC,MAAD,EAASf,WA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AY,GAAGzB,IAAI,CAACC,EAApB,IAA0BwB,YAAY,GAAI,IAAIzB,IAAI,CAACC,EAAV,GAAgB,CAA7D,EAAgE;AAC9DgC,MAAAA,QAAQ,GAAG,CAACjC,IAAI,CAACC,EAAN,GAAW,CAAtB;AACAiC,MAAAA,QAAQ,GAAG,CAAClC,IAAI,CAACC,EAAN,GAAW,CAAtB;AACD;;AACD,QAAIwB,YAAY,GAAI,IAAIzB,IAAI,CAACC,EAAV,GAAgB,CAA/B,IAAoCwB,YAAY,GAAG,IAAIzB,IAAI,CAACC,EAAhE,EAAoE;AAClEgC,MAAAA,QAAQ,GAAGjC,IAAI,CAACC,EAAL,GAAU,CAArB;AACAiC,MAAAA,QAAQ,GAAG,CAAClC,IAAI,CAACC,EAAN,GAAW,CAAtB;AACD;AACF;;AAED,MAAI0B,aAAa,KAAK,CAAtB,EAAyB;AACvB,UAAMiB,MAAM,GAAG5C,IAAI,CAACqC,GAAL,CAASV,aAAT,CAAf;AAEAM,IAAAA,QAAQ,GAAGjC,IAAI,CAACwC,IAAL,CAAUxC,IAAI,CAACG,GAAL,CAASsB,YAAT,IAAyBmB,MAAnC,CAAX;AACAV,IAAAA,QAAQ,GAAGlC,IAAI,CAACwC,IAAL,CAAUxC,IAAI,CAAC6C,GAAL,CAASpB,YAAT,IAAyBmB,MAAnC,CAAX;AACD;;AAED,QAAMhB,KAAK,GAAG5B,IAAI,CAAC8C,KAAL,CAAWb,QAAQ,GAAGU,QAAtB,CAAd;AACA,QAAMd,KAAK,GAAG7B,IAAI,CAAC8C,KAAL,CAAWZ,QAAQ,GAAGS,QAAtB,CAAd;AAEA,SAAO;AAAEf,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAP;AACD","sourcesContent":["import { PointerType } from '../PointerType';\nimport type { Point, StylusData } from './interfaces';\n\nexport function isPointerInBounds(view: HTMLElement, { x, y }: Point): boolean {\n const rect: DOMRect = view.getBoundingClientRect();\n\n return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;\n}\n\nexport const PointerTypeMapping = new Map<string, PointerType>([\n ['mouse', PointerType.MOUSE],\n ['touch', PointerType.TOUCH],\n ['pen', PointerType.STYLUS],\n ['none', PointerType.OTHER],\n]);\n\nexport const degToRad = (degrees: number) => (degrees * Math.PI) / 180;\n\nexport const coneToDeviation = (degrees: number) =>\n Math.cos(degToRad(degrees / 2));\n\nexport function calculateViewScale(view: HTMLElement) {\n const styles = getComputedStyle(view);\n\n const resultScales = {\n scaleX: 1,\n scaleY: 1,\n };\n\n // Get scales from scale property\n if (styles.scale !== undefined && styles.scale !== 'none') {\n const scales = styles.scale.split(' ');\n\n if (scales[0]) {\n resultScales.scaleX = parseFloat(scales[0]);\n }\n\n resultScales.scaleY = scales[1]\n ? parseFloat(scales[1])\n : parseFloat(scales[0]);\n }\n\n // Get scales from transform property\n const matrixElements = new RegExp(/matrix\\((.+)\\)/).exec(\n styles.transform\n )?.[1];\n\n if (matrixElements) {\n const matrixElementsArray = matrixElements.split(', ');\n\n resultScales.scaleX *= parseFloat(matrixElementsArray[0]);\n resultScales.scaleY *= parseFloat(matrixElementsArray[3]);\n }\n\n return resultScales;\n}\n\nexport function tryExtractStylusData(\n event: PointerEvent\n): StylusData | undefined {\n const pointerType = PointerTypeMapping.get(event.pointerType);\n\n if (pointerType !== PointerType.STYLUS) {\n return;\n }\n\n // @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)\n const eventAzimuthAngle: number | undefined = event.azimuthAngle;\n // @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)\n const eventAltitudeAngle: number | undefined = event.altitudeAngle;\n\n if (event.tiltX === 0 && event.tiltY === 0) {\n // If we are in this branch, it means that either tilt properties are not supported and we have to calculate them from altitude and azimuth angles,\n // or stylus is perpendicular to the screen and we can use altitude / azimuth instead of tilt\n\n // If azimuth and altitude are undefined in this branch, it means that we are either perpendicular to the screen,\n // or that none of the position sets is supported. In that case, we can treat stylus as perpendicular\n if (eventAzimuthAngle === undefined || eventAltitudeAngle === undefined) {\n return {\n tiltX: 0,\n tiltY: 0,\n azimuthAngle: Math.PI / 2,\n altitudeAngle: Math.PI / 2,\n pressure: event.pressure,\n };\n }\n\n const { tiltX, tiltY } = spherical2tilt(\n eventAltitudeAngle,\n eventAzimuthAngle\n );\n\n return {\n tiltX,\n tiltY,\n azimuthAngle: eventAzimuthAngle,\n altitudeAngle: eventAltitudeAngle,\n pressure: event.pressure,\n };\n }\n\n const { altitudeAngle, azimuthAngle } = tilt2spherical(\n event.tiltX,\n event.tiltY\n );\n\n return {\n tiltX: event.tiltX,\n tiltY: event.tiltY,\n azimuthAngle,\n altitudeAngle,\n pressure: event.pressure,\n };\n}\n\n// `altitudeAngle` and `azimuthAngle` are experimental properties, which are not supported on Firefox and Safari.\n// Given that, we use `tilt` properties and algorithm that converts one value to another.\n//\n// Source: https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle\nfunction tilt2spherical(tiltX: number, tiltY: number) {\n const tiltXrad = (tiltX * Math.PI) / 180;\n const tiltYrad = (tiltY * Math.PI) / 180;\n\n // calculate azimuth angle\n let azimuthAngle = 0;\n\n if (tiltX === 0) {\n if (tiltY > 0) {\n azimuthAngle = Math.PI / 2;\n } else if (tiltY < 0) {\n azimuthAngle = (3 * Math.PI) / 2;\n }\n } else if (tiltY === 0) {\n if (tiltX < 0) {\n azimuthAngle = Math.PI;\n }\n } else if (Math.abs(tiltX) === 90 || Math.abs(tiltY) === 90) {\n // not enough information to calculate azimuth\n azimuthAngle = 0;\n } else {\n // Non-boundary case: neither tiltX nor tiltY is equal to 0 or +-90\n const tanX = Math.tan(tiltXrad);\n const tanY = Math.tan(tiltYrad);\n\n azimuthAngle = Math.atan2(tanY, tanX);\n if (azimuthAngle < 0) {\n azimuthAngle += 2 * Math.PI;\n }\n }\n\n // calculate altitude angle\n let altitudeAngle = 0;\n\n if (Math.abs(tiltX) === 90 || Math.abs(tiltY) === 90) {\n altitudeAngle = 0;\n } else if (tiltX === 0) {\n altitudeAngle = Math.PI / 2 - Math.abs(tiltYrad);\n } else if (tiltY === 0) {\n altitudeAngle = Math.PI / 2 - Math.abs(tiltXrad);\n } else {\n // Non-boundary case: neither tiltX nor tiltY is equal to 0 or +-90\n altitudeAngle = Math.atan(\n 1.0 /\n Math.sqrt(\n Math.pow(Math.tan(tiltXrad), 2) + Math.pow(Math.tan(tiltYrad), 2)\n )\n );\n }\n\n return { altitudeAngle: altitudeAngle, azimuthAngle: azimuthAngle };\n}\n\n// If we are on a platform that doesn't support `tiltX` and `tiltY`, we have to calculate them from `altitude` and `azimuth` angles.\n//\n// Source: https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle\nfunction spherical2tilt(altitudeAngle: number, azimuthAngle: number) {\n const radToDeg = 180 / Math.PI;\n\n let tiltXrad = 0;\n let tiltYrad = 0;\n\n if (altitudeAngle === 0) {\n // the pen is in the X-Y plane\n if (azimuthAngle === 0 || azimuthAngle === 2 * Math.PI) {\n // pen is on positive X axis\n tiltXrad = Math.PI / 2;\n }\n if (azimuthAngle === Math.PI / 2) {\n // pen is on positive Y axis\n tiltYrad = Math.PI / 2;\n }\n if (azimuthAngle === Math.PI) {\n // pen is on negative X axis\n tiltXrad = -Math.PI / 2;\n }\n if (azimuthAngle === (3 * Math.PI) / 2) {\n // pen is on negative Y axis\n tiltYrad = -Math.PI / 2;\n }\n if (azimuthAngle > 0 && azimuthAngle < Math.PI / 2) {\n tiltXrad = Math.PI / 2;\n tiltYrad = Math.PI / 2;\n }\n if (azimuthAngle > Math.PI / 2 && azimuthAngle < Math.PI) {\n tiltXrad = -Math.PI / 2;\n tiltYrad = Math.PI / 2;\n }\n if (azimuthAngle > Math.PI && azimuthAngle < (3 * Math.PI) / 2) {\n tiltXrad = -Math.PI / 2;\n tiltYrad = -Math.PI / 2;\n }\n if (azimuthAngle > (3 * Math.PI) / 2 && azimuthAngle < 2 * Math.PI) {\n tiltXrad = Math.PI / 2;\n tiltYrad = -Math.PI / 2;\n }\n }\n\n if (altitudeAngle !== 0) {\n const tanAlt = Math.tan(altitudeAngle);\n\n tiltXrad = Math.atan(Math.cos(azimuthAngle) / tanAlt);\n tiltYrad = Math.atan(Math.sin(azimuthAngle) / tanAlt);\n }\n\n const tiltX = Math.round(tiltXrad * radToDeg);\n const tiltY = Math.round(tiltYrad * radToDeg);\n\n return { tiltX, tiltY };\n}\n"]}
@@ -2,5 +2,6 @@ export declare enum PointerType {
2
2
  TOUCH = 0,
3
3
  STYLUS = 1,
4
4
  MOUSE = 2,
5
- OTHER = 3
5
+ KEY = 3,
6
+ OTHER = 4
6
7
  }
@@ -17,6 +17,6 @@ export declare const DrawerLayoutAndroid: React.ForwardRefExoticComponent<RNDraw
17
17
  children?: React.ReactNode;
18
18
  } & NativeViewGestureHandlerProps & React.RefAttributes<React.ComponentType<any>>>;
19
19
  export type DrawerLayoutAndroid = typeof DrawerLayoutAndroid & RNDrawerLayoutAndroid;
20
- export declare const FlatList: <ItemT = any>(props: React.PropsWithChildren<RNFlatListProps<ItemT> & React.RefAttributes<FlatList<ItemT>> & NativeViewGestureHandlerProps>, ref: React.ForwardedRef<FlatList<ItemT>>) => ReactElement | null;
20
+ export declare const FlatList: <ItemT = any>(props: React.PropsWithChildren<Omit<RNFlatListProps<ItemT>, "renderScrollComponent"> & React.RefAttributes<FlatList<ItemT>> & NativeViewGestureHandlerProps>, ref: React.ForwardedRef<FlatList<ItemT>>) => ReactElement | null;
21
21
  export type FlatList<ItemT = any> = typeof FlatList & RNFlatList<ItemT>;
22
22
  export {};
@@ -1,2 +1,2 @@
1
- export { PressableProps } from './PressableProps';
1
+ export type { PressableProps } from './PressableProps';
2
2
  export { default } from './Pressable';
@@ -1,7 +1,6 @@
1
- import { Insets, ViewStyle } from 'react-native';
2
- import { LongPressGestureHandlerEventPayload } from '../../handlers/GestureHandlerEventPayload';
1
+ import { Insets } from 'react-native';
2
+ import { HoverGestureHandlerEventPayload, LongPressGestureHandlerEventPayload } from '../../handlers/GestureHandlerEventPayload';
3
3
  import { TouchData, GestureStateChangeEvent, GestureTouchEvent } from '../../handlers/gestureHandlerCommon';
4
- import { HoverGestureHandlerEventPayload } from '../../handlers/gestures/hoverGesture';
5
4
  import { PressableEvent } from './PressableProps';
6
5
  declare const numberAsInset: (value: number) => Insets;
7
6
  declare const addInsets: (a: Insets, b: Insets) => Insets;
@@ -11,5 +10,4 @@ declare const isTouchWithinInset: (dimensions: {
11
10
  }, inset: Insets, touch?: TouchData) => boolean;
12
11
  declare const gestureToPressableEvent: (event: GestureStateChangeEvent<HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload>) => PressableEvent;
13
12
  declare const gestureTouchToPressableEvent: (event: GestureTouchEvent) => PressableEvent;
14
- declare const splitStyles: (from: ViewStyle) => [ViewStyle, ViewStyle];
15
- export { numberAsInset, addInsets, isTouchWithinInset, gestureToPressableEvent, gestureTouchToPressableEvent, splitStyles, };
13
+ export { numberAsInset, addInsets, isTouchWithinInset, gestureToPressableEvent, gestureTouchToPressableEvent, };
@@ -1,3 +1,4 @@
1
+ import { StylusData } from '../web/interfaces';
1
2
  export type FlingGestureHandlerEventPayload = {
2
3
  x: number;
3
4
  y: number;
@@ -104,6 +105,10 @@ export type PanGestureHandlerEventPayload = {
104
105
  * value is expressed in point units per second.
105
106
  */
106
107
  velocityY: number;
108
+ /**
109
+ * Object containing additional stylus data.
110
+ */
111
+ stylusData: StylusData | undefined;
107
112
  };
108
113
  export type PinchGestureHandlerEventPayload = {
109
114
  /**
@@ -157,3 +162,33 @@ export type RotationGestureHandlerEventPayload = {
157
162
  */
158
163
  velocity: number;
159
164
  };
165
+ export type HoverGestureHandlerEventPayload = {
166
+ /**
167
+ * X coordinate of the current position of the pointer relative to the view
168
+ * attached to the handler. Expressed in point units.
169
+ */
170
+ x: number;
171
+ /**
172
+ * Y coordinate of the current position of the pointer relative to the view
173
+ * attached to the handler. Expressed in point units.
174
+ */
175
+ y: number;
176
+ /**
177
+ * X coordinate of the current position of the pointer relative to the window.
178
+ * The value is expressed in point units. It is recommended to use it instead
179
+ * of `x` in cases when the original view can be transformed as an
180
+ * effect of the gesture.
181
+ */
182
+ absoluteX: number;
183
+ /**
184
+ * Y coordinate of the current position of the pointer relative to the window.
185
+ * The value is expressed in point units. It is recommended to use it instead
186
+ * of `y` in cases when the original view can be transformed as an
187
+ * effect of the gesture.
188
+ */
189
+ absoluteY: number;
190
+ /**
191
+ * Object containing additional stylus data.
192
+ */
193
+ stylusData: StylusData | undefined;
194
+ };
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { LongPressGestureHandlerEventPayload } from './GestureHandlerEventPayload';
3
3
  import { BaseGestureHandlerProps } from './gestureHandlerCommon';
4
- export declare const longPressGestureHandlerProps: readonly ["minDurationMs", "maxDist"];
4
+ export declare const longPressGestureHandlerProps: readonly ["minDurationMs", "maxDist", "numberOfPointers"];
5
5
  export interface LongPressGestureConfig {
6
6
  /**
7
7
  * Minimum time, expressed in milliseconds, that a finger must remain pressed on
@@ -15,6 +15,10 @@ export interface LongPressGestureConfig {
15
15
  * will fail to recognize the gesture. The default value is 10.
16
16
  */
17
17
  maxDist?: number;
18
+ /**
19
+ * Determine exact number of points required to handle the long press gesture.
20
+ */
21
+ numberOfPointers?: number;
18
22
  }
19
23
  export interface LongPressGestureHandlerProps extends BaseGestureHandlerProps<LongPressGestureHandlerEventPayload>, LongPressGestureConfig {
20
24
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { HitSlop, CommonGestureConfig, GestureTouchEvent, GestureStateChangeEvent, GestureUpdateEvent, ActiveCursor, MouseButton } from '../gestureHandlerCommon';
3
3
  import { GestureStateManagerType } from './gestureStateManager';
4
- import type { FlingGestureHandlerEventPayload, ForceTouchGestureHandlerEventPayload, LongPressGestureHandlerEventPayload, PanGestureHandlerEventPayload, PinchGestureHandlerEventPayload, RotationGestureHandlerEventPayload, TapGestureHandlerEventPayload, NativeViewGestureHandlerPayload } from '../GestureHandlerEventPayload';
5
- export type GestureType = BaseGesture<Record<string, unknown>> | BaseGesture<Record<string, never>> | BaseGesture<TapGestureHandlerEventPayload> | BaseGesture<PanGestureHandlerEventPayload> | BaseGesture<LongPressGestureHandlerEventPayload> | BaseGesture<RotationGestureHandlerEventPayload> | BaseGesture<PinchGestureHandlerEventPayload> | BaseGesture<FlingGestureHandlerEventPayload> | BaseGesture<ForceTouchGestureHandlerEventPayload> | BaseGesture<NativeViewGestureHandlerPayload>;
4
+ import type { FlingGestureHandlerEventPayload, ForceTouchGestureHandlerEventPayload, LongPressGestureHandlerEventPayload, PanGestureHandlerEventPayload, PinchGestureHandlerEventPayload, RotationGestureHandlerEventPayload, TapGestureHandlerEventPayload, NativeViewGestureHandlerPayload, HoverGestureHandlerEventPayload } from '../GestureHandlerEventPayload';
5
+ export type GestureType = BaseGesture<Record<string, unknown>> | BaseGesture<Record<string, never>> | BaseGesture<TapGestureHandlerEventPayload> | BaseGesture<PanGestureHandlerEventPayload> | BaseGesture<LongPressGestureHandlerEventPayload> | BaseGesture<RotationGestureHandlerEventPayload> | BaseGesture<PinchGestureHandlerEventPayload> | BaseGesture<FlingGestureHandlerEventPayload> | BaseGesture<ForceTouchGestureHandlerEventPayload> | BaseGesture<NativeViewGestureHandlerPayload> | BaseGesture<HoverGestureHandlerEventPayload>;
6
6
  export type GestureRef = number | GestureType | React.RefObject<GestureType | undefined> | React.RefObject<React.ComponentType | undefined>;
7
7
  export interface BaseGestureConfig extends CommonGestureConfig, Record<string, unknown> {
8
8
  ref?: React.MutableRefObject<GestureType | undefined>;
@@ -1,11 +1,6 @@
1
1
  import { BaseGestureConfig, ContinousBaseGesture } from './gesture';
2
2
  import { GestureUpdateEvent } from '../gestureHandlerCommon';
3
- export type HoverGestureHandlerEventPayload = {
4
- x: number;
5
- y: number;
6
- absoluteX: number;
7
- absoluteY: number;
8
- };
3
+ import type { HoverGestureHandlerEventPayload } from '../GestureHandlerEventPayload';
9
4
  export type HoverGestureChangeEventPayload = {
10
5
  changeX: number;
11
6
  changeY: number;
@@ -16,5 +16,10 @@ export declare class LongPressGesture extends BaseGesture<LongPressGestureHandle
16
16
  * @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/long-press-gesture#maxdistancevalue-number
17
17
  */
18
18
  maxDistance(distance: number): this;
19
+ /**
20
+ * Determine exact number of points required to handle the long press gesture.
21
+ * @param pointers
22
+ */
23
+ numberOfPointers(pointers: number): this;
19
24
  }
20
25
  export type LongPressGestureType = InstanceType<typeof LongPressGesture>;
@@ -6,7 +6,7 @@ export declare function registerOldGestureHandler(handlerTag: number, handler: G
6
6
  export declare function unregisterHandler(handlerTag: number, testID?: string): void;
7
7
  export declare function findHandler(handlerTag: number): GestureType | undefined;
8
8
  export declare function findOldGestureHandler(handlerTag: number): GestureHandlerCallbacks | undefined;
9
- export declare function findHandlerByTestID(testID: string): import("./gestures/gesture").BaseGesture<Record<string, unknown>> | import("./gestures/gesture").BaseGesture<Record<string, never>> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").TapGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").PanGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").LongPressGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").RotationGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").PinchGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").ForceTouchGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").NativeViewGestureHandlerPayload> | null;
9
+ export declare function findHandlerByTestID(testID: string): import("./gestures/gesture").BaseGesture<Record<string, unknown>> | import("./gestures/gesture").BaseGesture<Record<string, never>> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").TapGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").PanGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").LongPressGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").RotationGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").PinchGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").ForceTouchGestureHandlerEventPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").NativeViewGestureHandlerPayload> | import("./gestures/gesture").BaseGesture<import("./GestureHandlerEventPayload").HoverGestureHandlerEventPayload> | null;
10
10
  export interface GestureHandlerCallbacks {
11
11
  onGestureEvent: (event: GestureEvent<any>) => void;
12
12
  onGestureStateChange: (event: HandlerStateChangeEvent<any>) => void;
@@ -26,5 +26,5 @@ type ClassComponentConstructor<P> = new (props: P) => React.Component<P, any, an
26
26
  type ExtractPayloadFromProps<T> = T extends BaseGestureHandlerProps<infer TPayload> ? TPayload : never;
27
27
  type ExtractConfig<T> = T extends BaseGesture<infer TGesturePayload> ? TGesturePayload : T extends ClassComponentConstructor<infer THandlerProps> ? ExtractPayloadFromProps<THandlerProps> : Record<string, unknown>;
28
28
  export declare function fireGestureHandler<THandler extends AllGestures | AllHandlers>(componentOrGesture: ReactTestInstance | GestureType, eventList?: Partial<GestureHandlerTestEvent<ExtractConfig<THandler>>>[]): void;
29
- export declare function getByGestureTestId(testID: string): BaseGesture<Record<string, unknown>> | BaseGesture<Record<string, never>> | BaseGesture<TapGestureHandlerEventPayload> | BaseGesture<PanGestureHandlerEventPayload> | BaseGesture<LongPressGestureHandlerEventPayload> | BaseGesture<RotationGestureHandlerEventPayload> | BaseGesture<PinchGestureHandlerEventPayload> | BaseGesture<ForceTouchGestureHandlerEventPayload> | BaseGesture<NativeViewGestureHandlerPayload>;
29
+ export declare function getByGestureTestId(testID: string): BaseGesture<Record<string, unknown>> | BaseGesture<Record<string, never>> | BaseGesture<TapGestureHandlerEventPayload> | BaseGesture<PanGestureHandlerEventPayload> | BaseGesture<LongPressGestureHandlerEventPayload> | BaseGesture<RotationGestureHandlerEventPayload> | BaseGesture<PinchGestureHandlerEventPayload> | BaseGesture<ForceTouchGestureHandlerEventPayload> | BaseGesture<NativeViewGestureHandlerPayload> | BaseGesture<import("../handlers/GestureHandlerEventPayload").HoverGestureHandlerEventPayload>;
30
30
  export {};
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import { TouchableHighlight, TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, ScrollView, FlatList, Switch, TextInput, DrawerLayoutAndroid, View } from 'react-native';
2
3
  declare const _default: {
3
4
  readonly TouchableHighlight: typeof TouchableHighlight;
@@ -16,9 +17,9 @@ declare const _default: {
16
17
  readonly PinchGestureHandler: typeof View;
17
18
  readonly RotationGestureHandler: typeof View;
18
19
  readonly FlingGestureHandler: typeof View;
19
- readonly RawButton: typeof TouchableNativeFeedback;
20
- readonly BaseButton: typeof TouchableNativeFeedback;
21
- readonly RectButton: typeof TouchableNativeFeedback;
20
+ readonly RawButton: ({ enabled, ...rest }: any) => React.JSX.Element;
21
+ readonly BaseButton: ({ enabled, ...rest }: any) => React.JSX.Element;
22
+ readonly RectButton: ({ enabled, ...rest }: any) => React.JSX.Element;
22
23
  readonly BorderlessButton: typeof TouchableNativeFeedback;
23
24
  readonly PanGestureHandler: typeof View;
24
25
  readonly attachGestureHandler: () => void;
@@ -16,3 +16,4 @@ export declare function isRemoteDebuggingEnabled(): boolean;
16
16
  * @returns `true` if the objects are deeply equal, `false` otherwise.
17
17
  */
18
18
  export declare function deepEqual(obj1: any, obj2: any): boolean;
19
+ export declare const INT32_MAX: number;
@@ -1,2 +1,2 @@
1
1
  export declare const DEFAULT_TOUCH_SLOP = 15;
2
- export declare const MINIMAL_FLING_VELOCITY = 0.1;
2
+ export declare const MINIMAL_RECOGNIZABLE_MAGNITUDE = 0.1;
@@ -3,10 +3,10 @@ import { State } from '../../State';
3
3
  import { Config, AdaptedEvent } from '../interfaces';
4
4
  import EventManager from '../tools/EventManager';
5
5
  import PointerTracker from '../tools/PointerTracker';
6
- import { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
7
6
  import IGestureHandler from './IGestureHandler';
8
7
  import { MouseButton } from '../../handlers/gestureHandlerCommon';
9
8
  import { PointerType } from '../../PointerType';
9
+ import { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
10
10
  export default abstract class GestureHandler implements IGestureHandler {
11
11
  private lastSentState;
12
12
  protected currentState: State;
@@ -2,7 +2,9 @@
2
2
  import { AdaptedEvent, Config } from '../interfaces';
3
3
  import GestureHandler from './GestureHandler';
4
4
  export default class HoverGestureHandler extends GestureHandler {
5
+ private stylusData;
5
6
  init(ref: number, propsRef: React.RefObject<unknown>): void;
7
+ protected transformNativeEvent(): Record<string, unknown>;
6
8
  updateGestureConfig({ enabled, ...props }: Config): void;
7
9
  protected onPointerMoveOver(event: AdaptedEvent): void;
8
10
  protected onPointerMoveOut(event: AdaptedEvent): void;