/** * All Rights Reserved * * Copyright (c) 2025 taskylizard * * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder. */ import mediumZoom from 'medium-zoom' import { inject, nextTick, onMounted, watch } from 'vue' import type { Zoom } from 'medium-zoom' import type { App, InjectionKey } from 'vue' import type { Router } from 'vitepress' declare module 'medium-zoom' { interface Zoom { refresh: (selector?: string) => void } } export const mediumZoomSymbol: InjectionKey = Symbol('mediumZoom') export function useMediumZoom() { return onMounted(() => inject(mediumZoomSymbol)?.refresh()) } export function createMediumZoomProvider(app: App, router: Router) { if (import.meta.env.SSR) return const zoom = mediumZoom() zoom.refresh = () => { zoom.detach() zoom.attach(':not(a) > img:not(.image-src)') } app.provide(mediumZoomSymbol, zoom) watch( () => router.route.path, () => nextTick(() => zoom.refresh()) ) }