@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
138 lines (134 loc) • 4.94 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function getNodeName(node) {
if (isNode(node)) {
return (node.nodeName || "").toLowerCase();
}
return "#document";
}
function getWindow(node) {
var _a;
return ((_a = node == null ? void 0 : node.ownerDocument) == null ? void 0 : _a.defaultView) || window;
}
function getDocumentElement(node) {
var _a;
return (_a = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _a.documentElement;
}
function isNode(value) {
return value instanceof Node || value instanceof getWindow(value).Node;
}
function isElement(value) {
return value instanceof Element || value instanceof getWindow(value).Element;
}
function isHTMLElement(value) {
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
}
function isShadowRoot(value) {
if (typeof ShadowRoot === "undefined") {
return false;
}
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
}
function isOverflowElement(element) {
const { overflow, overflowX, overflowY, display } = getComputedStyle(element);
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
}
function isTableElement(element) {
return ["table", "td", "th"].includes(getNodeName(element));
}
function isContainingBlock(element) {
const webkit = isWebKit();
const css = getComputedStyle(element);
return css.transform !== "none" || css.perspective !== "none" || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "perspective", "filter"].some(
(value) => (css.willChange || "").includes(value)
) || ["paint", "layout", "strict", "content"].some(
(value) => (css.contain || "").includes(value)
);
}
function getContainingBlock(element) {
let currentNode = getParentNode(element);
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
if (isContainingBlock(currentNode)) {
return currentNode;
}
currentNode = getParentNode(currentNode);
}
return null;
}
function isWebKit() {
if (typeof CSS === "undefined" || !CSS.supports)
return false;
return CSS.supports("-webkit-backdrop-filter", "none");
}
function isLastTraversableNode(node) {
return ["html", "body", "#document"].includes(getNodeName(node));
}
function getComputedStyle(element) {
return getWindow(element).getComputedStyle(element);
}
function getNodeScroll(element) {
if (isElement(element)) {
return {
scrollLeft: element.scrollLeft,
scrollTop: element.scrollTop
};
}
return {
scrollLeft: element.pageXOffset,
scrollTop: element.pageYOffset
};
}
function getParentNode(node) {
if (getNodeName(node) === "html") {
return node;
}
const result = node.assignedSlot || node.parentNode || isShadowRoot(node) && node.host || getDocumentElement(node);
return isShadowRoot(result) ? result.host : result;
}
function getNearestOverflowAncestor(node) {
const parentNode = getParentNode(node);
if (isLastTraversableNode(parentNode)) {
return node.ownerDocument ? node.ownerDocument.body : node.body;
}
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
return parentNode;
}
return getNearestOverflowAncestor(parentNode);
}
function getOverflowAncestors(node, list = [], traverseIframes = true) {
var _a;
const scrollableAncestor = getNearestOverflowAncestor(node);
const isBody = scrollableAncestor === ((_a = node.ownerDocument) == null ? void 0 : _a.body);
const win = getWindow(scrollableAncestor);
if (isBody) {
return list.concat(
win,
win.visualViewport || [],
isOverflowElement(scrollableAncestor) ? scrollableAncestor : [],
win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []
);
}
return list.concat(
scrollableAncestor,
getOverflowAncestors(scrollableAncestor, [], traverseIframes)
);
}
exports.getComputedStyle = getComputedStyle;
exports.getContainingBlock = getContainingBlock;
exports.getDocumentElement = getDocumentElement;
exports.getNearestOverflowAncestor = getNearestOverflowAncestor;
exports.getNodeName = getNodeName;
exports.getNodeScroll = getNodeScroll;
exports.getOverflowAncestors = getOverflowAncestors;
exports.getParentNode = getParentNode;
exports.getWindow = getWindow;
exports.isContainingBlock = isContainingBlock;
exports.isElement = isElement;
exports.isHTMLElement = isHTMLElement;
exports.isLastTraversableNode = isLastTraversableNode;
exports.isNode = isNode;
exports.isOverflowElement = isOverflowElement;
exports.isShadowRoot = isShadowRoot;
exports.isTableElement = isTableElement;
exports.isWebKit = isWebKit;
//# sourceMappingURL=dom.js.map