UNPKG

tdesign-mobile-vue

Version:
130 lines (124 loc) 4.24 kB
/** * tdesign v1.9.3 * (c) 2025 TDesign Group * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var shared_dom = require('../../shared/dom.js'); var isString = require('../../_chunks/dep-c3cb976c.js'); var isFunction = require('../../_chunks/dep-88fe047a.js'); require('../../_chunks/dep-2f809ed9.js'); require('@babel/runtime/helpers/typeof'); require('../../_chunks/dep-ef223206.js'); require('../../_chunks/dep-757b152c.js'); require('../../_chunks/dep-5be9198d.js'); function getElmCssPropValue(element, propName) { var propValue = ""; if (document.defaultView && document.defaultView.getComputedStyle) { propValue = document.defaultView.getComputedStyle(element, null).getPropertyValue(propName); } if (propValue && propValue.toLowerCase) { return propValue.toLowerCase(); } return propValue; } function isFixed(element) { var p = element.parentNode; if (!p || p.nodeName === "HTML") { return false; } if (getElmCssPropValue(element, "position") === "fixed") { return true; } return isFixed(p); } function getRelativePosition(elm) { var relativeElm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body; var _getWindowScroll = shared_dom.getWindowScroll(), scrollTop = _getWindowScroll.scrollTop, scrollLeft = _getWindowScroll.scrollLeft; var _elm$getBoundingClien = elm.getBoundingClientRect(), elmTop = _elm$getBoundingClien.top, elmLeft = _elm$getBoundingClien.left; var _relativeElm$getBound = relativeElm.getBoundingClientRect(), relElmTop = _relativeElm$getBound.top, relElmLeft = _relativeElm$getBound.left; var relativeElmPosition = getElmCssPropValue(relativeElm, "position"); if (relativeElm.tagName.toLowerCase() !== "body" && relativeElmPosition === "relative" || relativeElmPosition === "sticky") { return { top: elmTop - relElmTop, left: elmLeft - relElmLeft }; } if (isFixed(elm)) { return { top: elmTop, left: elmLeft }; } return { top: elmTop + scrollTop, left: elmLeft + scrollLeft }; } function getTargetElm(elm) { if (elm) { var _process; var targetElement = null; if (isString.isString(elm)) { targetElement = document.querySelector(elm); } else if (isFunction.isFunction(elm)) { targetElement = elm(); } else { throw new Error("elm should be string or function"); } if (targetElement) { return targetElement; } if (((_process = process) === null || _process === void 0 || (_process = _process.env) === null || _process === void 0 ? void 0 : _process.NODE_ENV) !== "test") { throw new Error("There is no element with given."); } } else { return document.body; } } function getScrollParent(element) { var style = window.getComputedStyle(element); var excludeStaticParent = style.position === "absolute"; var overflowRegex = /(auto|scroll)/; if (style.position === "fixed") return document.body; for (var parent = element; parent.parentElement;) { parent = parent.parentElement; style = window.getComputedStyle(parent); if (excludeStaticParent && style.position === "static") { continue; } if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent; } return document.body; } function scrollToParentVisibleArea(element) { var parent = getScrollParent(element); if (parent === document.body) return; if (shared_dom.elementInViewport(element, parent)) return; parent.scrollTop = element.offsetTop - parent.offsetTop; } function scrollToElm(elm) { var rect = elm.getBoundingClientRect(); if (!shared_dom.elementInViewport(elm)) { var winHeight = shared_dom.getWindowSize().height; window.scrollTo({ top: rect.top - (winHeight / 2 - rect.height / 2), behavior: "smooth" }); } } exports.getElmCssPropValue = getElmCssPropValue; exports.getRelativePosition = getRelativePosition; exports.getScrollParent = getScrollParent; exports.getTargetElm = getTargetElm; exports.isFixed = isFixed; exports.scrollToElm = scrollToElm; exports.scrollToParentVisibleArea = scrollToParentVisibleArea; //# sourceMappingURL=dom.js.map