fake-event-detection-DWOdFTFz.mjs 1.5 KB

123456789101112131415161718192021222324
  1. /** Gets whether an event could be a faked `mousedown` event dispatched by a screen reader. */
  2. function isFakeMousedownFromScreenReader(event) {
  3. // Some screen readers will dispatch a fake `mousedown` event when pressing enter or space on
  4. // a clickable element. We can distinguish these events when `event.buttons` is zero, or
  5. // `event.detail` is zero depending on the browser:
  6. // - `event.buttons` works on Firefox, but fails on Chrome.
  7. // - `detail` works on Chrome, but fails on Firefox.
  8. return event.buttons === 0 || event.detail === 0;
  9. }
  10. /** Gets whether an event could be a faked `touchstart` event dispatched by a screen reader. */
  11. function isFakeTouchstartFromScreenReader(event) {
  12. const touch = (event.touches && event.touches[0]) || (event.changedTouches && event.changedTouches[0]);
  13. // A fake `touchstart` can be distinguished from a real one by looking at the `identifier`
  14. // which is typically >= 0 on a real device versus -1 from a screen reader. Just to be safe,
  15. // we can also look at `radiusX` and `radiusY`. This behavior was observed against a Windows 10
  16. // device with a touch screen running NVDA v2020.4 and Firefox 85 or Chrome 88.
  17. return (!!touch &&
  18. touch.identifier === -1 &&
  19. (touch.radiusX == null || touch.radiusX === 1) &&
  20. (touch.radiusY == null || touch.radiusY === 1));
  21. }
  22. export { isFakeTouchstartFromScreenReader as a, isFakeMousedownFromScreenReader as i };
  23. //# sourceMappingURL=fake-event-detection-DWOdFTFz.mjs.map