bar2.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var util = require('./util.js');
  5. var thumb = require('./thumb2.js');
  6. var bar = require('./bar.js');
  7. var constants = require('./constants.js');
  8. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  9. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  10. __name: "bar",
  11. props: bar.barProps,
  12. setup(__props, { expose }) {
  13. const props = __props;
  14. const scrollbar = vue.inject(constants.scrollbarContextKey);
  15. const moveX = vue.ref(0);
  16. const moveY = vue.ref(0);
  17. const sizeWidth = vue.ref("");
  18. const sizeHeight = vue.ref("");
  19. const ratioY = vue.ref(1);
  20. const ratioX = vue.ref(1);
  21. const handleScroll = (wrap) => {
  22. if (wrap) {
  23. const offsetHeight = wrap.offsetHeight - util.GAP;
  24. const offsetWidth = wrap.offsetWidth - util.GAP;
  25. moveY.value = wrap.scrollTop * 100 / offsetHeight * ratioY.value;
  26. moveX.value = wrap.scrollLeft * 100 / offsetWidth * ratioX.value;
  27. }
  28. };
  29. const update = () => {
  30. const wrap = scrollbar == null ? void 0 : scrollbar.wrapElement;
  31. if (!wrap)
  32. return;
  33. const offsetHeight = wrap.offsetHeight - util.GAP;
  34. const offsetWidth = wrap.offsetWidth - util.GAP;
  35. const originalHeight = offsetHeight ** 2 / wrap.scrollHeight;
  36. const originalWidth = offsetWidth ** 2 / wrap.scrollWidth;
  37. const height = Math.max(originalHeight, props.minSize);
  38. const width = Math.max(originalWidth, props.minSize);
  39. ratioY.value = originalHeight / (offsetHeight - originalHeight) / (height / (offsetHeight - height));
  40. ratioX.value = originalWidth / (offsetWidth - originalWidth) / (width / (offsetWidth - width));
  41. sizeHeight.value = height + util.GAP < offsetHeight ? `${height}px` : "";
  42. sizeWidth.value = width + util.GAP < offsetWidth ? `${width}px` : "";
  43. };
  44. expose({
  45. handleScroll,
  46. update
  47. });
  48. return (_ctx, _cache) => {
  49. return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
  50. vue.createVNode(thumb["default"], {
  51. move: moveX.value,
  52. ratio: ratioX.value,
  53. size: sizeWidth.value,
  54. always: _ctx.always
  55. }, null, 8, ["move", "ratio", "size", "always"]),
  56. vue.createVNode(thumb["default"], {
  57. move: moveY.value,
  58. ratio: ratioY.value,
  59. size: sizeHeight.value,
  60. vertical: "",
  61. always: _ctx.always
  62. }, null, 8, ["move", "ratio", "size", "always"])
  63. ], 64);
  64. };
  65. }
  66. });
  67. var Bar = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "bar.vue"]]);
  68. exports["default"] = Bar;
  69. //# sourceMappingURL=bar2.js.map