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

8b470c0fb271ea1682707d86aad4f75a06455370
wotaku/docs/.vitepress/theme/composables/medium-zoom.ts
taskylizard chore: update license0dddca8d19 1 year ago

38 lines · 1125 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 { inject, nextTick, onMounted, watch } from 'vue'
10import type { Zoom } from 'medium-zoom'
11import type { App, InjectionKey } from 'vue'
12import type { Router } from 'vitepress'
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