excalidraw/src/gesture.ts
Jed Fox ab176937e6
Add touch support (#788)
* Add touch support

* Mock media query

* Mock media query pt 2

* Fix tests

* Allow installing as an app on iOS

* Fix type error

* Math.hypot

* delete and finalize buttons, hint viewer

* skip failing tests

* skip the rest of the failing tests

* Hide the selected shape actions when nothing is selected

* Don’t go into mobile view on short-but-wide viewports

* lol
2020-02-21 08:17:20 -05:00

18 lines
538 B
TypeScript

import { Pointer } from "./types";
import { normalizeScroll } from "./scene/data";
export function getCenter(pointers: readonly Pointer[]) {
return {
x: normalizeScroll(sum(pointers, p => p.x) / pointers.length),
y: normalizeScroll(sum(pointers, p => p.y) / pointers.length),
};
}
export function getDistance([a, b]: readonly Pointer[]) {
return Math.hypot(a.x - b.x, a.y - b.y);
}
function sum<T>(array: readonly T[], mapper: (item: T) => number): number {
return array.reduce((acc, item) => acc + mapper(item), 0);
}