docs/.vitepress/theme/composables/medium-zoom.ts

53c2d136c9780558f15e25ca3866501c28520a1e
wotaku/docs/.vitepress/theme/composables/medium-zoom.ts
taskylizard wotaku 2bea9706e6c 1 year ago

38 lines · 1131 bytes

 1/**
 2 *  All Rights Reserved
 3 *
 4 *  Copyright (c) 2025 taskylizard
 5 *
 6 *  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.
 7 */
 8import mediumZoom from 'medium-zoom'
 9import type { Zoom } from 'medium-zoom'
10import type { Router } from 'vitepress'
11import { inject, nextTick, onMounted, watch } from 'vue'
12import type { App, InjectionKey } from 'vue'
13
14declare module 'medium-zoom' {
15  interface Zoom {
16    refresh: (selector?: string) => void
17  }
18}
19
20export const mediumZoomSymbol: InjectionKey<Zoom> = Symbol('mediumZoom')
21
22export function useMediumZoom() {
23  return onMounted(() => inject(mediumZoomSymbol)?.refresh())
24}
25
26export function createMediumZoomProvider(app: App, router: Router) {
27  if (import.meta.env.SSR) return
28  const zoom = mediumZoom()
29  zoom.refresh = () => {
30    zoom.detach()
31    zoom.attach(':not(a) > img:not(.image-src)')
32  }
33  app.provide(mediumZoomSymbol, zoom)
34  watch(
35    () => router.route.path,
36    () => nextTick(() => zoom.refresh())
37  )
38}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form