UNPKG

tdesign-vue

Version:
310 lines (302 loc) 9.53 kB
/** * tdesign v1.15.0 * (c) 2026 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var Vue = require('vue'); var raf = require('raf'); var utils_easing = require('./easing.js'); var isString = require('../_chunks/dep-a2217d56.js'); require('../_chunks/dep-3b2292ce.js'); require('@babel/runtime/helpers/typeof'); require('../_chunks/dep-10fcb46d.js'); require('../_chunks/dep-ba7f5924.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue); var raf__default = /*#__PURE__*/_interopDefaultLegacy(raf); var isServer = Vue__default["default"].prototype.$isServer || typeof window === "undefined"; var trim = function trim(str) { return (str || "").replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, ""); }; var on = function () { if (!isServer && document.addEventListener) { return function (element, event, handler, options) { if (element && event && handler) { element.addEventListener(event, handler, options); return function () { return off(element, event, handler, options); }; } }; } return function (element, event, handler) { if (element && event && handler) { element.attachEvent("on".concat(event), handler); return function () { return off(element, event, handler); }; } }; }(); var off = function () { if (!isServer && document.removeEventListener) { return function (element, event, handler, options) { if (element && event) { element.removeEventListener(event, handler, options); } }; } return function (element, event, handler) { if (element && event) { element.detachEvent("on".concat(event), handler); } }; }(); function once(element, event, handler, options) { var handlerFn = typeof handler === "function" ? handler : handler.handleEvent; var _callback = function callback(evt) { handlerFn(evt); off(element, event, _callback, options); }; on(element, event, _callback, options); } 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; } 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; } } 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 getAttach = function getAttach(node, triggerNode) { var attachNode = typeof node === "function" ? node(triggerNode) : node; if (!attachNode) { return document.body; } if (isString.isString(attachNode)) { return document.querySelector(attachNode); } if (attachNode instanceof HTMLElement) { return attachNode; } return document.body; }; var getScrollContainer = function getScrollContainer() { var container = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "body"; if (isString.isString(container)) { return document.querySelector(container); } if (typeof container === "function") { return container(); } return container; }; function isWindow(obj) { return obj && obj === obj.window; } function getScroll(target, isLeft) { if (typeof window === "undefined" || !target) { return 0; } var method = isLeft ? "scrollLeft" : "scrollTop"; var result = 0; if (isWindow(target)) { result = target[isLeft ? "pageXOffset" : "pageYOffset"]; } else if (target instanceof Document) { result = target.documentElement[method]; } else if (target) { result = target[method]; } return result; } function scrollTo(target, opt) { var _opt$container = opt.container, container = _opt$container === void 0 ? window : _opt$container, _opt$duration = opt.duration, duration = _opt$duration === void 0 ? 450 : _opt$duration, _opt$easing = opt.easing, easing = _opt$easing === void 0 ? utils_easing.easeInOutCubic : _opt$easing; var scrollTop = getScroll(container); var startTime = Date.now(); return new Promise(function (res) { var _fnc = function fnc() { var timestamp = Date.now(); var time = timestamp - startTime; var nextScrollTop = easing(Math.min(time, duration), scrollTop, target, duration); if (isWindow(container)) { container.scrollTo(window.pageXOffset, nextScrollTop); } else if (container instanceof HTMLDocument || container.constructor.name === "HTMLDocument") { container.documentElement.scrollTop = nextScrollTop; } else { container.scrollTop = nextScrollTop; } if (time < duration) { raf__default["default"](_fnc); } else { raf__default["default"](res); } }; raf__default["default"](_fnc); }); } function containerDom(parent, child) { if (parent && child) { var pNode = child; while (pNode) { if (parent === pNode) { return true; } var _pNode = pNode, parentNode = _pNode.parentNode; pNode = parentNode; } } return false; } var clickOut = function clickOut(els, cb) { on(document, "click", function (event) { if (Array.isArray(els)) { var isFlag = Array.from(els).every(function (item) { return containerDom(item, event.target) === false; }); isFlag && cb && cb(); } else { if (containerDom(els, event.target)) { return false; } cb && cb(); } }); }; var isNodeOverflow = function isNodeOverflow(ele) { var _ele$clientWidth = ele.clientWidth, clientWidth = _ele$clientWidth === void 0 ? 0 : _ele$clientWidth, _ele$scrollWidth = ele.scrollWidth, scrollWidth = _ele$scrollWidth === void 0 ? 0 : _ele$scrollWidth; return scrollWidth > clientWidth; }; var removeDom = function removeDom(el) { if (el.remove) { el.remove(); } else { el.parentNode.removeChild(el); } }; function getScrollbarWidth() { var scrollDiv = document.createElement("div"); scrollDiv.style.cssText = "width: 99px; height: 99px; overflow: scroll; position: absolute; visibility: hidden;"; document.body.appendChild(scrollDiv); var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; document.body.removeChild(scrollDiv); return scrollbarWidth; } 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 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 getWindowScroll() { var _document = document, body = _document.body; var docElm = document.documentElement; var scrollTop = window.pageYOffset || docElm.scrollTop || body.scrollTop; var scrollLeft = window.pageXOffset || docElm.scrollLeft || body.scrollLeft; return { scrollTop: scrollTop, scrollLeft: scrollLeft }; } function getWindowSize() { if (window.innerWidth !== void 0) { return { width: window.innerWidth, height: window.innerHeight }; } var doc = document.documentElement; return { width: doc.clientWidth, height: doc.clientHeight }; } exports.addClass = addClass; exports.clickOut = clickOut; exports.elementInViewport = elementInViewport; exports.getAttach = getAttach; exports.getElmCssPropValue = getElmCssPropValue; exports.getScroll = getScroll; exports.getScrollContainer = getScrollContainer; exports.getScrollbarWidth = getScrollbarWidth; exports.getWindowScroll = getWindowScroll; exports.getWindowSize = getWindowSize; exports.hasClass = hasClass; exports.isFixed = isFixed; exports.isNodeOverflow = isNodeOverflow; exports.isServer = isServer; exports.off = off; exports.on = on; exports.once = once; exports.removeClass = removeClass; exports.removeDom = removeDom; exports.scrollTo = scrollTo; exports.trim = trim; //# sourceMappingURL=dom.js.map