UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

50 lines (46 loc) 1.49 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { computed, ref, onMounted, nextTick } from 'vue'; import observe from '../../_common/js/utils/observe.js'; import { isServer } from '../../utils/dom.js'; import '../../_chunks/dep-3a1cce9f.js'; import 'lodash/isString'; import 'lodash/isFunction'; import 'lodash/isArray'; import '../../utils/easing.js'; function useLazyLoad(containerRef, childRef, params) { var tRowHeight = computed(function () { return Math.max(params.rowHeight || 48, 48); }); var isInit = ref(false); var hasLazyLoadHolder = computed(function () { return (params === null || params === void 0 ? void 0 : params.type) === "lazy" && !isInit.value; }); var requestAnimationFrame = !isServer && window.requestAnimationFrame || function (cb) { return setTimeout(cb, 16.6); }; var init = function init() { if (!isInit.value) { requestAnimationFrame(function () { isInit.value = true; }); } }; onMounted(function () { if ((params === null || params === void 0 ? void 0 : params.type) !== "lazy") return; nextTick(function () { var bufferSize = Math.max(10, params.bufferSize || 10); var height = tRowHeight.value * bufferSize; observe(childRef.value, containerRef.value, init, height); }); }); return { hasLazyLoadHolder: hasLazyLoadHolder, tRowHeight: tRowHeight }; } export { useLazyLoad as default }; //# sourceMappingURL=useLazyLoad.js.map