1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/open-hand-choerodon-ui

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
index.tsx 2.2 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
heqiwei Отправлено 2 лет назад 69f68fd
import { MousePosition } from '../modal-manager';
let zoom = 0;
export function getDocument(self: Window): Document {
try {
const { parent, top } = self;
if (parent !== top) {
return getDocument(parent);
}
return parent.document;
} catch (e) {
return self.document;
}
}
export function getDocuments(self: Window, list: Document[] = []): Document[] {
try {
const { parent, top } = self;
if (parent !== top) {
return getDocuments(parent, list);
}
return list.concat(parent.document);
} catch (e) {
return list.concat(self.document);
}
}
export function findIFrame(self: Window): HTMLIFrameElement | undefined {
return [...self.parent.document.querySelectorAll('iframe')].find(frame => frame.contentWindow === self);
}
export { MousePosition };
function getPageMousePosition(x, y, self: Window, client?: boolean): MousePosition {
const { scrollTop, scrollLeft, clientWidth, clientHeight } = self.document.documentElement;
if (client) {
return { x, y, vw: clientWidth, vh: clientHeight };
}
return { x: x + scrollLeft, y: y + scrollTop, vw: clientWidth, vh: clientHeight };
}
export function getMousePosition(x: number, y: number, self: Window, client?: boolean): MousePosition {
try {
if (self.top === self) {
return getPageMousePosition(x, y, self, client);
}
const { parent } = self;
const iframe = findIFrame(self);
const { top, left } = iframe ? iframe.getBoundingClientRect() : { top: 0, left: 0 };
const newX = x + left;
const newY = y + top;
if (parent === self.top) {
return getPageMousePosition(newX, newY, parent, client);
}
return getMousePosition(newX, newY, parent);
} catch (e) {
return getPageMousePosition(x, y, self, client);
}
}
/**
* 转换缩放比例后的数据
* 场景:兼容全局带有 zoom 样式导致的数据偏差
* @param data 需要转换的数据
* @returns 转换后的数据
*/
export const transformZoomData = (data: number): number => {
if (!zoom) {
// eslint-disable-next-line dot-notation
zoom = Number(getComputedStyle(document.body)['zoom']) || 1;
}
return data / zoom;
};
export default {
getDocument,
getDocuments,
findIFrame,
getMousePosition,
transformZoomData,
};

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/open-hand-choerodon-ui.git
git@gitlife.ru:oschina-mirror/open-hand-choerodon-ui.git
oschina-mirror
open-hand-choerodon-ui
open-hand-choerodon-ui
1.6.4