You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.9 KiB

{"ast":null,"code":"import _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\nvar EventManager = function () {\n function EventManager(view) {\n _classCallCheck(this, EventManager);\n _defineProperty(this, \"view\", void 0);\n _defineProperty(this, \"pointersInBounds\", []);\n _defineProperty(this, \"activePointersCounter\", void 0);\n this.view = view;\n this.activePointersCounter = 0;\n }\n _createClass(EventManager, [{\n key: \"onPointerDown\",\n value: function onPointerDown(_event) {}\n }, {\n key: \"onPointerAdd\",\n value: function onPointerAdd(_event) {}\n }, {\n key: \"onPointerUp\",\n value: function onPointerUp(_event) {}\n }, {\n key: \"onPointerRemove\",\n value: function onPointerRemove(_event) {}\n }, {\n key: \"onPointerMove\",\n value: function onPointerMove(_event) {}\n }, {\n key: \"onPointerOut\",\n value: function onPointerOut(_event) {}\n }, {\n key: \"onPointerEnter\",\n value: function onPointerEnter(_event) {}\n }, {\n key: \"onPointerCancel\",\n value: function onPointerCancel(_event) {}\n }, {\n key: \"onPointerOutOfBounds\",\n value: function onPointerOutOfBounds(_event) {}\n }, {\n key: \"setOnPointerDown\",\n value: function setOnPointerDown(callback) {\n this.onPointerDown = callback;\n }\n }, {\n key: \"setOnPointerAdd\",\n value: function setOnPointerAdd(callback) {\n this.onPointerAdd = callback;\n }\n }, {\n key: \"setOnPointerUp\",\n value: function setOnPointerUp(callback) {\n this.onPointerUp = callback;\n }\n }, {\n key: \"setOnPointerRemove\",\n value: function setOnPointerRemove(callback) {\n this.onPointerRemove = callback;\n }\n }, {\n key: \"setOnPointerMove\",\n value: function setOnPointerMove(callback) {\n this.onPointerMove = callback;\n }\n }, {\n key: \"setOnPointerOut\",\n value: function setOnPointerOut(callback) {\n this.onPointerOut = callback;\n }\n }, {\n key: \"setOnPointerEnter\",\n value: function setOnPointerEnter(callback) {\n this.onPointerEnter = callback;\n }\n }, {\n key: \"setOnPointerCancel\",\n value: function setOnPointerCancel(callback) {\n this.onPointerCancel = callback;\n }\n }, {\n key: \"setOnPointerOutOfBounds\",\n value: function setOnPointerOutOfBounds(callback) {\n this.onPointerOutOfBounds = callback;\n }\n }, {\n key: \"markAsInBounds\",\n value: function markAsInBounds(pointerId) {\n if (this.pointersInBounds.indexOf(pointerId) >= 0) {\n return;\n }\n this.pointersInBounds.push(pointerId);\n }\n }, {\n key: \"markAsOutOfBounds\",\n value: function markAsOutOfBounds(pointerId) {\n var index = this.pointersInBounds.indexOf(pointerId);\n if (index < 0) {\n return;\n }\n this.pointersInBounds.splice(index, 1);\n }\n }, {\n key: \"resetManager\",\n value: function resetManager() {\n this.activePointersCounter = 0;\n this.pointersInBounds = [];\n }\n }]);\n return EventManager;\n}();\nexport { EventManager as default };","map":{"version":3,"sources":["EventManager.ts"],"names":["EventManager","constructor","view","activePointersCounter","onPointerDown","_event","onPointerAdd","onPointerUp","onPointerRemove","onPointerMove","onPointerOut","onPointerEnter","onPointerCancel","onPointerOutOfBounds","setOnPointerDown","callback","setOnPointerAdd","setOnPointerUp","setOnPointerRemove","setOnPointerMove","setOnPointerOut","setOnPointerEnter","setOnPointerCancel","setOnPointerOutOfBounds","markAsInBounds","pointerId","pointersInBounds","indexOf","push","markAsOutOfBounds","index","splice","resetManager"],"mappings":";;;;;;;;;;;;;;;IAG8BA,YAAf;EAKbC,sBAAYC,IAAD,EAAoB;IAAA;IAAA,eAAA,CAAA,IAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;IAAA,eAAA,CAAA,IAAA,EAAA,kBAAA,EAHQ,EAGR,CAAA;IAAA,eAAA,CAAA,IAAA,EAAA,uBAAA,EAAA,KAAA,CAAA,CAAA;IAC7B,IAAA,CAAKA,IAAL,GAAYA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AAgD;MACvE,IAAA,CAAKH,eAAL,GAAuBG,QAAvB;IACD;EAAA;IAAA;IAAA,OACMQ,iCACLR,QAD4B,EAEtB;MACN,IAAA,CAAKF,oBAAL,GAA4BE,QAA5B;IACD;EAAA;IAAA;IAAA,OAESS,wBAAeC,SAAD,EAA0B;MAChD,IAAI,IAAA,CAAKC,gBAAL,CAAsBC,OAAtB,CAA8BF,SAA9B,CAAA,IAA4C,CAAhD,EAAmD;QACjD;MACD;MAED,IAAA,CAAKC,gBAAL,CAAsBE,IAAtB,CAA2BH,SAA3B,CAAA;IACD;EAAA;IAAA;IAAA,OAESI,2BAAkBJ,SAAD,EAA0B;MACnD,IAAMK,KAAa,GAAG,IAAA,CAAKJ,gBAAL,CAAsBC,OAAtB,CAA8BF,SAA9B,CAAtB;MAEA,IAAIK,KAAK,GAAG,CAAZ,EAAe;QACb;MACD;MAED,IAAA,CAAKJ,gBAAL,CAAsBK,MAAtB,CAA6BD,KAA7B,EAAoC,CAApC,CAAA;IACD;EAAA;IAAA;IAAA,OAEME,wBAAqB;MAQ1B,IAAA,CAAK7B,qBAAL,GAA6B,CAA7B;MACA,IAAA,CAAKuB,gBAAL,GAAwB,EAAxB;IACD;EAAA;EAAA;AAAA;AAAA,SA3F2B1B,YAAf","sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-function */\nimport { AdaptedEvent, EventTypes, TouchEventType } from '../interfaces';\n\nexport default abstract class EventManager {\n protected readonly view: HTMLElement;\n protected pointersInBounds: number[] = [];\n protected activePointersCounter: number;\n\n constructor(view: HTMLElement) {\n this.view = view;\n this.activePointersCounter = 0;\n }\n\n public abstract setListeners(): void;\n protected abstract mapEvent(\n event: Event,\n eventType: EventTypes,\n index?: number,\n touchEventType?: TouchEventType\n ): AdaptedEvent;\n\n protected onPointerDown(_event: AdaptedEvent): void {}\n protected onPointerAdd(_event: AdaptedEvent): void {}\n protected onPointerUp(_event: AdaptedEvent): void {}\n protected onPointerRemove(_event: AdaptedEvent): void {}\n protected onPointerMove(_event: AdaptedEvent): void {}\n protected onPointerOut(_event: AdaptedEvent): void {}\n protected onPointerEnter(_event: AdaptedEvent): void {}\n protected onPointerCancel(_event: AdaptedEvent): void {\n // When pointer cancel is triggered and there are more pointers on the view, only one pointer is cancelled\n // Because we want all pointers to be cancelled by that event, we are doing it manually by reseting handler and changing activePointersCounter to 0\n // Events that correspond to removing the pointer (pointerup, touchend) have condition, that they don't perform any action when activePointersCounter\n // is equal to 0. This prevents counter from going to negative values, when pointers are removed from view after one of them has been cancelled\n }\n protected onPointerOutOfBounds(_event: AdaptedEvent): void {}\n\n public setOnPointerDown(callback: (event: AdaptedEvent) => void): void {\n this.onPointerDown = callback;\n }\n public setOnPointerAdd(callback: (event: AdaptedEvent) => void): void {\n this.onPointerAdd = callback;\n }\n public setOnPointerUp(callback: (event: AdaptedEvent) => void): void {\n this.onPointerUp = callback;\n }\n public setOnPointerRemove(callback: (event: AdaptedEvent) => void): void {\n this.onPointerRemove = callback;\n }\n public setOnPointerMove(callback: (event: AdaptedEvent) => void): void {\n this.onPointerMove = callback;\n }\n public setOnPointerOut(callback: (event: AdaptedEvent) => void): void {\n this.onPointerOut = callback;\n }\n public setOnPointerEnter(callback: (event: AdaptedEvent) => void): void {\n this.onPointerEnter = callback;\n }\n public setOnPointerCancel(callback: (event: AdaptedEvent) => void): void {\n this.onPointerCancel = callback;\n }\n public setOnPointerOutOfBounds(\n callback: (event: AdaptedEvent) => void\n ): void {\n this.onPointerOutOfBounds = callback;\n }\n\n protected markAsInBounds(pointerId: number): void {\n if (this.pointersInBounds.indexOf(pointerId) >= 0) {\n return;\n }\n\n this.pointersInBounds.push(pointerId);\n }\n\n protected markAsOutOfBounds(pointerId: number): void {\n const index: number = this.pointersInBounds.indexOf(pointerId);\n\n if (index < 0) {\n return;\n }\n\n this.pointersInBounds.splice(index, 1);\n }\n\n public resetManager(): void {\n // Reseting activePointersCounter is necessary to make gestures such as pinch work properly\n // There are gestures that end when there is still one active pointer (like pinch/rotation)\n // When these gestures end, they are reset, but they still receive events from pointer that is active\n // This causes trouble, since only onPointerDown registers gesture in orchestrator, and while gestures receive\n // Events from active pointer after they finished, next pointerdown event will be registered as additional pointer, not the first one\n // This casues trouble like gestures getting stuck in END state, even though they should have gone to UNDETERMINED\n\n this.activePointersCounter = 0;\n this.pointersInBounds = [];\n }\n}\n"]},"metadata":{},"sourceType":"module"}