返回 slidev
useSlideBounds.ts
根目录 / packages / client / composables / useSlideBounds.ts
1 import { useElementBounding } from '@vueuse/core'
2 import { inject, ref, watch } from 'vue'
3 import { injectionSlideElement } from '../constants'
4 import { editorHeight, editorWidth, isEditorVertical, showEditor, slideScale, windowSize } from '../state'
5
6 export function useSlideBounds(slideElement = inject(injectionSlideElement, ref())) {
7 const bounding = useElementBounding(slideElement)
8 const stop = watch(
9 [
10 showEditor,
11 isEditorVertical,
12 editorWidth,
13 editorHeight,
14 slideScale,
15 windowSize.width,
16 windowSize.height,
17 ],
18 () => {
19 setTimeout(bounding.update, 300)
20 },
21 {
22 flush: 'post',
23 immediate: true,
24 },
25 )
26 return {
27 ...bounding,
28 stop,
29 }
30 }
31
31 lines TYPESCRIPT