From 3ee8c3fb5078a1ded2ac5a36e9ce47ba29ae48d8 Mon Sep 17 00:00:00 2001 From: JinJianQi <2359634711@qq.com> Date: Sat, 10 Sep 2022 13:32:07 +0800 Subject: [PATCH] feat: let dispatchEvent work. issues#17638 --- src/core/event.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/event.ts b/src/core/event.ts index e872db58c..a6f0bde7d 100644 --- a/src/core/event.ts +++ b/src/core/event.ts @@ -19,6 +19,10 @@ type FirefoxMouseEvent = { layerY: number } +type DispatchedEvent = { + dispatchedOffsetX: number + dispatchedOffsetY: number +} /** * Get the `zrX` and `zrY`, which are relative to the top-left of @@ -45,19 +49,22 @@ type FirefoxMouseEvent = { */ export function clientToLocal( el: HTMLElement, - e: ZRRawEvent | FirefoxMouseEvent | Touch, + e: ZRRawEvent | FirefoxMouseEvent | Touch | DispatchedEvent, out: {zrX?: number, zrY?: number}, calculate?: boolean ) { out = out || {}; - + if ((e as DispatchedEvent).dispatchedOffsetX) { + out.zrX = (e as DispatchedEvent).dispatchedOffsetX; + out.zrY = (e as DispatchedEvent).dispatchedOffsetY; + } // According to the W3C Working Draft, offsetX and offsetY should be relative // to the padding edge of the target element. The only browser using this convention // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does // not support the properties. // (see http://www.jacklmoore.com/notes/mouse-position/) // In zr painter.dom, padding edge equals to border edge. - if (calculate) { + else if (calculate) { calculateZrXY(el, e as ZRRawEvent, out); } // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned