hongluan-ui
Version:
Hongluan Component Library for Vue 3
83 lines (78 loc) • 2.88 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('../../../tokens/index.js');
var thumb = require('./thumb2.js');
var bar = require('./bar.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var scrollbar = require('../../../tokens/scrollbar.js');
const _sfc_main = vue.defineComponent({
components: {
Thumb: thumb["default"]
},
props: bar.barProps,
setup(props) {
const scrollbar$1 = vue.inject(scrollbar.scrollbarContextKey);
const moveX = vue.ref(0);
const moveY = vue.ref(0);
const sizeWidth = vue.ref("");
const sizeHeight = vue.ref("");
const ratioY = vue.ref(1);
const ratioX = vue.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$1 == null ? void 0 : scrollbar$1.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 = vue.resolveComponent("thumb");
return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
vue.createVNode(_component_thumb, {
move: _ctx.moveX,
ratio: _ctx.ratioX,
size: _ctx.sizeWidth,
always: _ctx.always
}, null, 8, ["move", "ratio", "size", "always"]),
vue.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__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render]]);
exports["default"] = Bar;
//# sourceMappingURL=bar2.js.map