-
Notifications
You must be signed in to change notification settings - Fork 382
/
polyfill.ts
36 lines (34 loc) · 1.42 KB
/
polyfill.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { defineProperty, isNull, getOwnPropertyDescriptor } from '@lwc/shared';
import { pathComposer } from '../../3rdparty/polymer/path-composer';
import { retarget } from '../../3rdparty/polymer/retarget';
import { eventCurrentTargetGetter } from '../../env/dom';
import { isNodeShadowed } from '../../shared/node-ownership';
import { getOwnerDocument } from '../../shared/utils';
const mouseEventRelatedTargetGetter = getOwnPropertyDescriptor(
FocusEvent.prototype,
'relatedTarget'
)!.get as () => EventTarget | null;
defineProperty(MouseEvent.prototype, 'relatedTarget', {
get(this: Event): EventTarget | null | undefined {
const relatedTarget = mouseEventRelatedTargetGetter.call(this);
if (isNull(relatedTarget)) {
return null;
}
if (!(relatedTarget instanceof Node) || !isNodeShadowed(relatedTarget as Node)) {
return relatedTarget;
}
let pointOfReference = eventCurrentTargetGetter.call(this);
if (isNull(pointOfReference)) {
pointOfReference = getOwnerDocument(relatedTarget as Node);
}
return retarget(pointOfReference, pathComposer(relatedTarget, true));
},
enumerable: true,
configurable: true,
});