UNPKG

tdesign-react

Version:
79 lines (71 loc) 2.46 kB
/** * tdesign v1.11.6 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var raf = require('raf'); var _util_easing = require('../../_util/easing.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var raf__default = /*#__PURE__*/_interopDefaultLegacy(raf); function getOffsetTop(target, container) { var _target$getBoundingCl = target.getBoundingClientRect(), top = _target$getBoundingCl.top; if (container === window) { return top - document.documentElement.clientTop; } return top - container.getBoundingClientRect().top; } 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 ? _util_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); }); } exports.getOffsetTop = getOffsetTop; exports.getScroll = getScroll; exports.scrollTo = scrollTo; //# sourceMappingURL=dom.js.map