|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed, defineAsyncComponent, ref, toRef } from 'vue' |
| 3 | +import type { PropType } from 'vue' |
| 4 | +import { provideLocal } from '@vueuse/core' |
| 5 | +import type { ClicksContext, RenderContext, SlideRoute } from '@slidev/types' |
| 6 | +import { injectionActive, injectionClicksContext, injectionCurrentPage, injectionRenderContext, injectionRoute } from '../constants' |
| 7 | +import SlideLoading from './SlideLoading.vue' |
| 8 | +
|
| 9 | +const props = defineProps({ |
| 10 | + clicksContext: { |
| 11 | + type: Object as PropType<ClicksContext>, |
| 12 | + required: true, |
| 13 | + }, |
| 14 | + renderContext: { |
| 15 | + type: String as PropType<RenderContext>, |
| 16 | + default: 'slide', |
| 17 | + }, |
| 18 | + active: { |
| 19 | + type: Boolean, |
| 20 | + default: false, |
| 21 | + }, |
| 22 | + is: { |
| 23 | + required: true, |
| 24 | + }, |
| 25 | + route: { |
| 26 | + type: Object as PropType<SlideRoute>, |
| 27 | + required: true, |
| 28 | + }, |
| 29 | +}) |
| 30 | +
|
| 31 | +provideLocal(injectionRoute, props.route) |
| 32 | +provideLocal(injectionCurrentPage, ref(props.route.no)) |
| 33 | +provideLocal(injectionRenderContext, ref(props.renderContext as RenderContext)) |
| 34 | +provideLocal(injectionActive, toRef(props, 'active')) |
| 35 | +provideLocal(injectionClicksContext, toRef(props, 'clicksContext')) |
| 36 | +
|
| 37 | +const style = computed(() => { |
| 38 | + const zoom = props.route.meta?.slide?.frontmatter.zoom ?? 1 |
| 39 | + return zoom === 1 |
| 40 | + ? undefined |
| 41 | + : { |
| 42 | + width: `${100 / zoom}%`, |
| 43 | + height: `${100 / zoom}%`, |
| 44 | + transformOrigin: 'top left', |
| 45 | + transform: `scale(${zoom})`, |
| 46 | + } |
| 47 | +}) |
| 48 | +
|
| 49 | +const SlideComponent = defineAsyncComponent({ |
| 50 | + loader: (props.is as any), |
| 51 | + delay: 300, |
| 52 | + loadingComponent: SlideLoading, |
| 53 | +}) |
| 54 | +</script> |
| 55 | + |
| 56 | +<template> |
| 57 | + <component :is="SlideComponent" :style="style" :class="{ 'disable-view-transition': !['slide', 'presenter'].includes(props.renderContext) }" /> |
| 58 | +</template> |
| 59 | + |
| 60 | +<style scoped> |
| 61 | +.disable-view-transition:deep(*) { |
| 62 | + view-transition-name: none !important; |
| 63 | +} |
| 64 | +</style> |
0 commit comments