forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.ts
More file actions
31 lines (28 loc) · 986 Bytes
/
misc.ts
File metadata and controls
31 lines (28 loc) · 986 Bytes
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
import Viewport from '../builtin-simulator/viewport';
export function isElementNode(domNode: Element) {
return domNode.nodeType === Node.ELEMENT_NODE;
}
/**
* 判断节点是否在 viewport 内,判断依据:只要节点有一部分在 viewport 内,都算 true,其余情况 false
* @param domNode 待检测的节点
* @param viewport 画布 viewport
* @returns 是否在 viewport 内
*/
export function isDOMNodeVisible(domNode: Element, viewport: Viewport) {
const domNodeRect = domNode.getBoundingClientRect();
const { width, height } = viewport.contentBounds;
const { left, right, top, bottom, width: nodeWidth, height: nodeHeight } = domNodeRect;
return (
left >= -nodeWidth &&
top >= -nodeHeight &&
bottom <= height + nodeHeight &&
right <= width + nodeWidth
);
}
/**
* normalize triggers
* @param triggers
*/
export function normalizeTriggers(triggers: string[]) {
return triggers.map((trigger: string) => trigger?.toUpperCase());
}