project init

This commit is contained in:
zxy
2024-02-02 10:24:54 +08:00
commit 21a84c3035
253 changed files with 25212 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
class handler {
constructor(startTime, startX, startY) {
this.startTime = startTime
this.lastX = this.startX = startX
this.startY = startY
this._moveFunc = this.firstMove
}
move({
timeStamp,
pageX,
pageY
}) {
return this._moveFunc(timeStamp, pageX, pageY)
}
firstMove(timeStamp, pageX, pageY) {
if (Math.abs(pageX - this.startX) > Math.abs(pageY - this.startY)) {
this._moveFunc = this.nextMove
} else {
this._moveFunc = () => {
return 0
}
this.endMove = () => {
return {
invalid: true
}
}
}
return 0
}
nextMove(timeStamp, pageX, pageY) {
const r = pageX - this.lastX
this.lastX = pageX
return r
}
isQuick(endTime, endX) {
return endTime - this.startTime < 200 && Math.abs(endX - this.startX) > 50
}
endMove(endTime, pageX, pageY) {
return {
invalid: false,
quick: this.isQuick(endTime, pageX),
dir: pageX > this.startX ? 'r' : 'l',
move: Math.abs(pageX - this.startX)
}
}
}
export default handler