Created
March 8, 2025 20:22
-
-
Save mbforbes/9b91a9a7ebaefa020e897a0f9a4ad41e to your computer and use it in GitHub Desktop.
Dump touch event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dumpTouchEvent(event: TouchEvent): string { | |
// Start with the basics | |
const result = { | |
type: event.type, | |
timeStamp: event.timeStamp, | |
isTrusted: event.isTrusted, | |
bubbles: event.bubbles, | |
cancelable: event.cancelable, | |
defaultPrevented: event.defaultPrevented, | |
eventPhase: event.eventPhase, | |
}; | |
// Handle touches, targetTouches, and changedTouches | |
['touches', 'targetTouches', 'changedTouches'].forEach((touchListName) => { | |
if (event[touchListName]) { | |
result[touchListName] = []; | |
for (let i = 0; i < event[touchListName].length; i++) { | |
const touch = event[touchListName][i]; | |
result[touchListName].push({ | |
identifier: touch.identifier, | |
screenX: touch.screenX, | |
screenY: touch.screenY, | |
clientX: touch.clientX, | |
clientY: touch.clientY, | |
pageX: touch.pageX, | |
pageY: touch.pageY, | |
radiusX: touch.radiusX, | |
radiusY: touch.radiusY, | |
rotationAngle: touch.rotationAngle, | |
force: touch.force, | |
}); | |
} | |
} | |
}); | |
return JSON.stringify(result, null, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment