import { Gesture, THRESHOLD } from './gesture'; class Pan extends Gesture { isSingleFigure = true; holdTimeout = null; startTime = 0; isHold = false; constructor(handler) { super('drag', handler); } handleTouchStart(event) { this.isSingleFigure = event.touches.length === 1; if (!this.isSingleFigure) return; this.holdTimeout && clearTimeout(this.holdTimeout); this.startTime = Date.now(); this.holdTimeout = setTimeout(() => { this.isHold = true; }, THRESHOLD.PAN_BEFORE_HOLD); } handleTouchMove(event) { if (!this.isSingleFigure) return; const currentTime = Date.now(); if (currentTime - this.startTime < THRESHOLD.PAN_BEFORE_HOLD) { clearTimeout(this.holdTimeout); } else { if (this.isHold) { this.dispatchEvent(event); } } } handleTouchEnd(_event) { if (!this.isSingleFigure) return; clearTimeout(this.holdTimeout); this.startTime = 0; this.holdTimeout = null; this.isHold = false; } } export default Pan;