"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const isDOMChildNode_1 = __importDefault(require("./isDOMChildNode")); const viewport_1 = __importDefault(require("./viewport")); /** * Get the parent element that has scrolling * * @param elm - The element whose scroll parent is determined * @return The scroll parent or the viewport */ function scrollParent(elm) { const vp = viewport_1.default(elm); if (!isDOMChildNode_1.default(elm) || elm === vp) { return vp; } const { position: elmPosition } = getComputedStyle(elm); if (elmPosition === 'fixed') { return vp; } const noStaticParent = elmPosition === 'absolute'; let parent = elm.parentElement; while (parent && parent !== document.body) { const { position, overflow, overflowX, overflowY } = getComputedStyle(parent); if (!(noStaticParent && position === 'static') && /(auto|scroll)/.test(overflow + overflowY + overflowX)) { return parent; } parent = parent.parentElement; } return vp; } exports.default = scrollParent;