UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

86 lines (73 loc) 1.94 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; export function getDocument(self) { try { var parent = self.parent, top = self.top; if (parent !== top) { return getDocument(parent); } return parent.document; } catch (e) { return self.document; } } export function getDocuments(self) { var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; try { var parent = self.parent, top = self.top; if (parent !== top) { return getDocuments(parent, list); } return list.concat(parent.document); } catch (e) { return list.concat(self.document); } } export function findIFrame(self) { return _toConsumableArray(self.parent.document.querySelectorAll('iframe')).find(function (frame) { return frame.contentWindow === self; }); } function getPageMousePosition(x, y, self) { var _self$document$docume = self.document.documentElement, scrollTop = _self$document$docume.scrollTop, scrollLeft = _self$document$docume.scrollLeft; return { x: x + scrollLeft, y: y + scrollTop }; } export function getMousePosition(x, y, self, client) { try { if (self.top === self) { return client ? { x: x, y: y } : getPageMousePosition(x, y, self); } var parent = self.parent; var iframe = findIFrame(self); var _ref = iframe ? iframe.getBoundingClientRect() : { top: 0, left: 0 }, top = _ref.top, left = _ref.left; var newX = x + left; var newY = y + top; if (parent === self.top) { return client ? { x: newX, y: newY } : getPageMousePosition(newX, newY, parent); } return getMousePosition(newX, newY, parent); } catch (e) { return client ? { x: x, y: y } : getPageMousePosition(x, y, self); } } //# sourceMappingURL=DocumentUtils.js.map