UNPKG

tdesign-react

Version:
110 lines (105 loc) 3.22 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import { isString } from 'lodash-es'; var trim = function trim(str) { return (str || "").replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, ""); }; function hasClass(el, cls) { if (!el || !cls) return false; if (cls.indexOf(" ") !== -1) throw new Error("className should not contain space."); if (el.classList) { return el.classList.contains(cls); } return " ".concat(el.className, " ").indexOf(" ".concat(cls, " ")) > -1; } var addClass = function addClass(el, cls) { if (!el) return; var curClass = el.className; var classes = (cls || "").split(" "); for (var i = 0, j = classes.length; i < j; i++) { var clsName = classes[i]; if (!clsName) continue; if (el.classList) { el.classList.add(clsName); } else if (!hasClass(el, clsName)) { curClass += " ".concat(clsName); } } if (!el.classList) { el.className = curClass; } }; var removeClass = function removeClass(el, cls) { if (!el || !cls) return; var classes = cls.split(" "); var curClass = " ".concat(el.className, " "); for (var i = 0, j = classes.length; i < j; i++) { var clsName = classes[i]; if (!clsName) continue; if (el.classList) { el.classList.remove(clsName); } else if (hasClass(el, clsName)) { curClass = curClass.replace(" ".concat(clsName, " "), " "); } } if (!el.classList) { el.className = trim(curClass); } }; var getCssVarsValue = function getCssVarsValue(name, element) { if (!canUseDocument) return; var el = element || document.documentElement; return getComputedStyle(el).getPropertyValue(name); }; var canUseDocument = !!(typeof window !== "undefined" && window.document && window.document.createElement); var isWindow = function isWindow(val) { return val === window; }; var getAttach = function getAttach(node) { var attachNode = typeof node === "function" ? node() : node; if (!attachNode) { return document.body; } if (isString(attachNode)) { return document.querySelector(attachNode); } if (attachNode instanceof HTMLElement) { return attachNode; } return document.body; }; function elementInViewport(elm, parent) { var rect = elm.getBoundingClientRect(); if (parent) { var parentRect = parent.getBoundingClientRect(); return rect.top >= parentRect.top && rect.left >= parentRect.left && rect.bottom <= parentRect.bottom && rect.right <= parentRect.right; } return rect.top >= 0 && rect.left >= 0 && rect.bottom + 80 <= window.innerHeight && rect.right <= window.innerWidth; } function isFixed(element) { var p = element.parentNode; if (!p || p.nodeName === "HTML") { return false; } if (getCssVarsValue("position", element) === "fixed") { return true; } return isFixed(p); } function getWindowSize() { if (canUseDocument) { return { width: window.innerWidth, height: window.innerHeight }; } return { width: 0, height: 0 }; } export { addClass as a, getAttach as b, canUseDocument as c, getWindowSize as d, isWindow as e, elementInViewport as f, getCssVarsValue as g, hasClass as h, isFixed as i, removeClass as r }; //# sourceMappingURL=dep-3a09424a.js.map