(
type: string,
clientX = 0,
clientY = 0,
offsetX = 0,
offsetY = 0,
button = 0,
modifiers: ModifierKeys = {},
)
| 16 | * @docs-private |
| 17 | */ |
| 18 | export function createMouseEvent( |
| 19 | type: string, |
| 20 | clientX = 0, |
| 21 | clientY = 0, |
| 22 | offsetX = 0, |
| 23 | offsetY = 0, |
| 24 | button = 0, |
| 25 | modifiers: ModifierKeys = {}, |
| 26 | ) { |
| 27 | // Note: We cannot determine the position of the mouse event based on the screen |
| 28 | // because the dimensions and position of the browser window are not available |
| 29 | // To provide reasonable `screenX` and `screenY` coordinates, we simply use the |
| 30 | // client coordinates as if the browser is opened in fullscreen. |
| 31 | const screenX = clientX; |
| 32 | const screenY = clientY; |
| 33 | |
| 34 | const event = new MouseEvent(type, { |
| 35 | bubbles: true, |
| 36 | cancelable: true, |
| 37 | composed: true, // Required for shadow DOM events. |
| 38 | view: getEventView(), |
| 39 | detail: 1, |
| 40 | relatedTarget: null, |
| 41 | screenX, |
| 42 | screenY, |
| 43 | clientX, |
| 44 | clientY, |
| 45 | ctrlKey: modifiers.control, |
| 46 | altKey: modifiers.alt, |
| 47 | shiftKey: modifiers.shift, |
| 48 | metaKey: modifiers.meta, |
| 49 | button: button, |
| 50 | buttons: 1, |
| 51 | }); |
| 52 | |
| 53 | // The `MouseEvent` constructor doesn't allow us to pass these properties into the constructor. |
| 54 | // Override them to `1`, because they're used for fake screen reader event detection. |
| 55 | if (offsetX != null) { |
| 56 | defineReadonlyEventProperty(event, 'offsetX', offsetX); |
| 57 | } |
| 58 | |
| 59 | if (offsetY != null) { |
| 60 | defineReadonlyEventProperty(event, 'offsetY', offsetY); |
| 61 | } |
| 62 | |
| 63 | return event; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates a browser `PointerEvent` with the specified options. Pointer events |
searching dependent graphs…