import { DomDatasetBoolean } from '../types'; /** `current` 是否是 `target` 的祖先元素 */ export function contains(current?: HTMLElement | null, target?: HTMLElement | null) { if (!current || !target) return false; if (current === target) return true; return current.contains(target); } /** `root` 是否是 `target` 的曝光祖先元素 */ export const isPaternalExposeElements = (root?: HTMLElement | null, target?: HTMLElement | null) => !!root && !!target && (root === document.body || root.dataset?.mlRoot === DomDatasetBoolean.TRUE) && root.contains(target); export const getElementKey = (el?: HTMLElement | null): string => { if (!el) return ''; const attrValue = el.getAttribute('ml-key'); if (attrValue && attrValue.length > 0) { return attrValue; } const dataValue = el.dataset.mlKey; if (dataValue && dataValue.length > 0) { return dataValue; } return ''; };