UNPKG

tdesign-vue

Version:
162 lines (158 loc) 6.09 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _typeof from '@babel/runtime/helpers/typeof'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, ref, computed, onMounted, onBeforeUnmount } from '@vue/composition-api'; import { BacktopIcon } from 'tdesign-icons-vue'; import { scrollTo } from '../utils/dom.js'; import { renderContent } from '../utils/render-tnode.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { useGlobalIcon } from '../hooks/useGlobalIcon.js'; import props from './props.js'; import 'vue'; import 'raf'; import 'lodash-es'; import '../utils/easing.js'; import '@babel/runtime/helpers/readOnlyError'; import '../config-provider/useConfig.js'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-ba613a02.js'; import '../_chunks/dep-fdb1b253.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; import '@babel/runtime/helpers/slicedToArray'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _BackTop = defineComponent({ name: "TBackTop", props: _objectSpread({}, props), setup: function setup(props2) { var visible = ref(false); var containerRef = ref(null); var componentName = usePrefixClass("back-top"); var classPrefix = usePrefixClass(); var theme = props2.theme, shape = props2.shape, size = props2.size, target = props2.target, duration = props2.duration, offset = props2.offset, container = props2.container; var _useGlobalIcon = useGlobalIcon({ BacktopIcon: BacktopIcon }), BacktopIcon$1 = _useGlobalIcon.BacktopIcon; var getContainer = function getContainer(container2) { if (typeof container2 === "string" && (typeof document === "undefined" ? "undefined" : _typeof(document)) !== void 0) { if (container2 === "body") { return document; } return document.querySelector(container2); } if (typeof container2 === "function") { return container2(); } return null; }; var getBackTo = function getBackTo() { if (target === container) return 0; if (target === "body") return 0; if (!target) return 0; var targetNode = getContainer(target); if (!targetNode) return 0; var _targetNode$getBoundi = targetNode.getBoundingClientRect(), y = _targetNode$getBoundi.y; return y; }; var handleClick = function handleClick(e) { var _props2$onClick; var y = getBackTo(); scrollTo(y, { container: containerRef.value, duration: duration }); (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 || _props2$onClick.call(props2, { e: e }); }; var cls = computed(function () { return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, componentName.value, true), "".concat(componentName.value, "--theme-").concat(theme), true), "".concat(componentName.value, "--").concat(shape), true), "".concat(componentName.value, "--show"), visible.value), "".concat(classPrefix.value, "-size-s"), size === "small"), "".concat(classPrefix.value, "-size-m"), size === "medium"); }); var positionStyle = computed(function () { return { insetInlineEnd: offset[0], insetBlockEnd: offset[1] }; }); onMounted(function () { containerRef.value = getContainer(props2.container); var visibleHeight; if (typeof props2.visibleHeight === "string") { visibleHeight = Number(props2.visibleHeight.replace("px", "")); } else { visibleHeight = props2.visibleHeight; } if (visibleHeight === 0) { visible.value = true; return; } var scrollDOM; if (containerRef.value) { if (containerRef.value.scrollTop === void 0) { scrollDOM = document.documentElement; } else { scrollDOM = containerRef.value; } containerRef.value.onscroll = function () { var _scrollDOM = scrollDOM, scrollTop = _scrollDOM.scrollTop; if (scrollTop >= visibleHeight) { visible.value = true; } if (scrollTop < visibleHeight && visible.value) { visible.value = false; } }; } }); onBeforeUnmount(function () { containerRef.value.onscroll = null; }); return { BacktopIcon: BacktopIcon$1, cls: cls, handleClick: handleClick, positionStyle: positionStyle, componentName: componentName }; }, render: function render() { var h = arguments[0]; var BacktopIcon = this.BacktopIcon; var defaultContent = h("div", [h(BacktopIcon, { "class": "".concat(this.componentName, "__icon"), "attrs": { "size": "24" } }), h("span", { "class": "".concat(this.componentName, "__text") }, ["TOP"])]); return h("button", { "attrs": { "type": "button" }, "class": this.cls, "style": this.positionStyle, "on": { "click": this.handleClick } }, [renderContent(this, "content", "default", defaultContent)]); } }); export { _BackTop as default }; //# sourceMappingURL=back-top.js.map