'use strict'; const vueDemi = require('vue-demi'); const SmoothScrollbar = require('smooth-scrollbar'); const smoothScrollbarKey = /* @__PURE__ */ Symbol("SmoothScrollbar injection key"); const isClient = typeof window !== "undefined"; const directiveHooks = { mounted: vueDemi.isVue3 ? "mounted" : "inserted", updated: vueDemi.isVue3 ? "updated" : "componentUpdated", unmounted: vueDemi.isVue3 ? "unmounted" : "unbind" }; function useScrollbar(target, options) { const scrollbarRef = vueDemi.shallowRef(); vueDemi.watchPostEffect((onCleanup) => { if (isClient) scrollbarRef.value = SmoothScrollbar.init(vueDemi.unref(target), vueDemi.toRaw(vueDemi.unref(options))); onCleanup(() => { if (scrollbarRef.value) scrollbarRef.value.destroy(); }); }); return scrollbarRef; } function useScrollbarInject() { return vueDemi.inject(smoothScrollbarKey); } const ScrollbarComponent = /* @__PURE__ */ vueDemi.defineComponent({ name: "Scrollbar", props: { as: { type: String, default: "div", required: false }, scrollbarOptions: { type: Object, required: false } }, emits: { // @ts-expect-error payload // eslint-disable-next-line @typescript-eslint/no-unused-vars mounted: (payload) => true }, setup(props, { emit, expose, slots }) { const target = vueDemi.shallowRef(null); const scrollbar = useScrollbar(target, props.scrollbarOptions); vueDemi.provide(smoothScrollbarKey, scrollbar); vueDemi.onMounted(() => { emit("mounted", { target, scrollbar: vueDemi.unref(scrollbar) }); }); expose({ scrollbar }); return () => { return vueDemi.h(props.as || "div", { ref: target }, slots.default && slots.default()); }; } }); const Scrollbar = ScrollbarComponent; const directiveWeakMap = /* @__PURE__ */ new WeakMap(); const vScrollbar = { [directiveHooks.mounted](el, { value }) { if (!directiveWeakMap.has(el) && isClient) { directiveWeakMap.set(el, SmoothScrollbar.init(el, value)); el.dispatchEvent(new CustomEvent("scrollbar-mounted", { detail: directiveWeakMap.get(el) })); } }, [directiveHooks.unmounted](el) { if (directiveWeakMap.has(el)) { directiveWeakMap.get(el).destroy(); directiveWeakMap.delete(el); el.dispatchEvent(new CustomEvent("scrollbar-unmounted", { detail: el })); } } }; exports.Scrollbar = Scrollbar; exports.useScrollbar = useScrollbar; exports.useScrollbarInject = useScrollbarInject; exports.vScrollbar = vScrollbar;