UNPKG

hongluan-ui

Version:
79 lines (76 loc) 2.79 kB
import { defineComponent, inject, ref, resolveComponent, openBlock, createElementBlock, Fragment, createVNode } from 'vue'; import '../../../tokens/index.mjs'; import Thumb from './thumb2.mjs'; import { barProps } from './bar.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { scrollbarContextKey } from '../../../tokens/scrollbar.mjs'; const _sfc_main = defineComponent({ components: { Thumb }, props: barProps, setup(props) { const scrollbar = inject(scrollbarContextKey); const moveX = ref(0); const moveY = ref(0); const sizeWidth = ref(""); const sizeHeight = ref(""); const ratioY = ref(1); const ratioX = ref(1); const GAP = 0; const handleScroll = (wrap) => { if (wrap) { const offsetHeight = wrap.offsetHeight - GAP; const offsetWidth = wrap.offsetWidth - GAP; moveY.value = wrap.scrollTop * 100 / offsetHeight * ratioY.value; moveX.value = wrap.scrollLeft * 100 / offsetWidth * ratioX.value; } }; const update = () => { const wrap = scrollbar == null ? void 0 : scrollbar.wrapElement; if (!wrap) return; const offsetHeight = wrap.offsetHeight - GAP; const offsetWidth = wrap.offsetWidth - GAP; const originalHeight = offsetHeight ** 2 / wrap.scrollHeight; const originalWidth = offsetWidth ** 2 / wrap.scrollWidth; const height = Math.max(originalHeight, props.minSize); const width = Math.max(originalWidth, props.minSize); ratioY.value = originalHeight / (offsetHeight - originalHeight) / (height / (offsetHeight - height)); ratioX.value = originalWidth / (offsetWidth - originalWidth) / (width / (offsetWidth - width)); sizeHeight.value = height + GAP < offsetHeight ? `${height}px` : ""; sizeWidth.value = width + GAP < offsetWidth ? `${width}px` : ""; }; return { handleScroll, moveX, moveY, ratioX, ratioY, sizeWidth, sizeHeight, update }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_thumb = resolveComponent("thumb"); return openBlock(), createElementBlock(Fragment, null, [ createVNode(_component_thumb, { move: _ctx.moveX, ratio: _ctx.ratioX, size: _ctx.sizeWidth, always: _ctx.always }, null, 8, ["move", "ratio", "size", "always"]), createVNode(_component_thumb, { move: _ctx.moveY, ratio: _ctx.ratioY, size: _ctx.sizeHeight, vertical: "", always: _ctx.always }, null, 8, ["move", "ratio", "size", "always"]) ], 64); } var Bar = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { Bar as default }; //# sourceMappingURL=bar2.mjs.map