UNPKG

@egjs/axes

Version:

A module used to change the information of user action entered by various input devices such as touch screen or mouse into the logical virtual coordinates. You can easily create a UI that responds to user actions.

48 lines 1.54 kB
import { MouseEventInput } from "../eventInput/MouseEventInput"; import { TouchEventInput } from "../eventInput/TouchEventInput"; import { PointerEventInput } from "../eventInput/PointerEventInput"; import { TouchMouseEventInput } from "../eventInput/TouchMouseEventInput"; import { SUPPORT_POINTER_EVENTS, SUPPORT_TOUCH, } from "../eventInput/EventInput"; export var toAxis = function (source, offset) { return offset.reduce(function (acc, v, i) { if (source[i]) { acc[source[i]] = v; } return acc; }, {}); }; export var convertInputType = function (inputType) { if (inputType === void 0) { inputType = []; } var hasTouch = false; var hasMouse = false; var hasPointer = false; inputType.forEach(function (v) { switch (v) { case "mouse": hasMouse = true; break; case "touch": hasTouch = SUPPORT_TOUCH; break; case "pointer": hasPointer = SUPPORT_POINTER_EVENTS; } }); if (hasPointer) { return new PointerEventInput(); } else if (hasTouch && hasMouse) { return new TouchMouseEventInput(); } else if (hasTouch) { return new TouchEventInput(); } else if (hasMouse) { return new MouseEventInput(); } return null; }; export function getAddEventOptions(eventName) { return eventName.indexOf("touch") > -1 ? { passive: false } : false; } //# sourceMappingURL=InputType.js.map