{"version":3,"file":"bar2.mjs","names":[],"sources":["../../../../../../packages/components/scrollbar/src/bar.vue"],"sourcesContent":["<template>\n  <thumb :move=\"moveX\" :ratio=\"ratioX\" :size=\"sizeWidth\" :always=\"always\" />\n  <thumb\n    :move=\"moveY\"\n    :ratio=\"ratioY\"\n    :size=\"sizeHeight\"\n    vertical\n    :always=\"always\"\n  />\n</template>\n\n<script lang=\"ts\" setup>\nimport { inject, ref } from 'vue'\nimport { GAP } from './util'\nimport Thumb from './thumb.vue'\nimport { scrollbarContextKey } from './constants'\n\nimport type { BarProps } from './bar'\n\nconst props = withDefaults(defineProps<BarProps>(), {\n  always: true,\n})\n\nconst scrollbar = inject(scrollbarContextKey)\n\nconst moveX = ref(0)\nconst moveY = ref(0)\nconst sizeWidth = ref('')\nconst sizeHeight = ref('')\nconst ratioY = ref(1)\nconst ratioX = ref(1)\n\nconst handleScroll = (wrap: HTMLDivElement) => {\n  if (wrap) {\n    const offsetHeight = wrap.offsetHeight - GAP\n    const offsetWidth = wrap.offsetWidth - GAP\n\n    moveY.value = ((wrap.scrollTop * 100) / offsetHeight) * ratioY.value\n    moveX.value = ((wrap.scrollLeft * 100) / offsetWidth) * ratioX.value\n  }\n}\n\nconst update = () => {\n  const wrap = scrollbar?.wrapElement\n  if (!wrap) return\n  const offsetHeight = wrap.offsetHeight - GAP\n  const offsetWidth = wrap.offsetWidth - GAP\n\n  const originalHeight = offsetHeight ** 2 / wrap.scrollHeight\n  const originalWidth = offsetWidth ** 2 / wrap.scrollWidth\n  const height = Math.max(originalHeight, props.minSize)\n  const width = Math.max(originalWidth, props.minSize)\n\n  ratioY.value =\n    originalHeight /\n    (offsetHeight - originalHeight) /\n    (height / (offsetHeight - height))\n  ratioX.value =\n    originalWidth /\n    (offsetWidth - originalWidth) /\n    (width / (offsetWidth - width))\n\n  sizeHeight.value = height + GAP < offsetHeight ? `${height}px` : ''\n  sizeWidth.value = width + GAP < offsetWidth ? `${width}px` : ''\n}\n\ndefineExpose({\n  handleScroll,\n  update,\n})\n</script>\n"],"mappings":""}