|
|
@ -175,6 +175,7 @@ export function getContext2D(canvas) {
|
|
|
|
* @prop {((touch: Touch[], touches: Map<number, Touch>) => void)=} onMove
|
|
|
|
* @prop {((touch: Touch[], touches: Map<number, Touch>) => void)=} onMove
|
|
|
|
* @prop {((touch: Touch | undefined, touches: Map<number, Touch>) => void)=} onUp
|
|
|
|
* @prop {((touch: Touch | undefined, touches: Map<number, Touch>) => void)=} onUp
|
|
|
|
* @prop {number=} downscale
|
|
|
|
* @prop {number=} downscale
|
|
|
|
|
|
|
|
* @prop {boolean=} preventDefault
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -191,11 +192,7 @@ export function attachTouch(element, options = {}) {
|
|
|
|
let queued_touches = [];
|
|
|
|
let queued_touches = [];
|
|
|
|
|
|
|
|
|
|
|
|
function get_dpr() {
|
|
|
|
function get_dpr() {
|
|
|
|
if (options.dpr) {
|
|
|
|
|
|
|
|
return window.devicePixelRatio ?? 1;
|
|
|
|
return window.devicePixelRatio ?? 1;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onDown(event) {
|
|
|
|
function onDown(event) {
|
|
|
@ -233,7 +230,7 @@ export function attachTouch(element, options = {}) {
|
|
|
|
let y = (event.clientY - bounding.y) * dpr / downscale;
|
|
|
|
let y = (event.clientY - bounding.y) * dpr / downscale;
|
|
|
|
|
|
|
|
|
|
|
|
if (touches.has(event.pointerId)) {
|
|
|
|
if (touches.has(event.pointerId)) {
|
|
|
|
let touch = touches.get(event.pointerId);
|
|
|
|
let touch = cloneGet(touches, event.pointerId);
|
|
|
|
|
|
|
|
|
|
|
|
touch.dx = x - touch.x;
|
|
|
|
touch.dx = x - touch.x;
|
|
|
|
touch.dy = y - touch.y;
|
|
|
|
touch.dy = y - touch.y;
|
|
|
@ -659,3 +656,23 @@ function subpixelPenalty(value) {
|
|
|
|
function approxEq(a, b, epsilon = 0) {
|
|
|
|
function approxEq(a, b, epsilon = 0) {
|
|
|
|
return Math.abs(a - b) <= epsilon;
|
|
|
|
return Math.abs(a - b) <= epsilon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Performs a shallow clone on `map.get(key)`, and replaces that value in the map.
|
|
|
|
|
|
|
|
* @template K,V
|
|
|
|
|
|
|
|
* @param {Map<K, V>} map - The map to get the object from, will be mutated
|
|
|
|
|
|
|
|
* @param {K} key
|
|
|
|
|
|
|
|
* @returns {V | undefined}
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
function cloneGet(map, key) {
|
|
|
|
|
|
|
|
let value = map.get(key);
|
|
|
|
|
|
|
|
if (!value) return value;
|
|
|
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
...value
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
map.set(key, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
|
|
|
}
|
|
|
|