Skip to content

Commit

Permalink
fix: Shiki magic move with zoom option (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Mar 21, 2024
1 parent 4a8ad4e commit 0e94054
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/client/builtin/ShikiMagicMove.vue
Expand Up @@ -14,7 +14,7 @@ const props = defineProps<{
}>()
const steps = JSON.parse(lz.decompressFromBase64(props.stepsLz)) as KeyedTokensInfo[]
const { $clicksContext: clicks, $scale: scale } = useSlideContext()
const { $clicksContext: clicks, $scale: scale, $zoom: zoom } = useSlideContext()
const { isPrintMode } = useNav()
const id = makeId()
Expand Down Expand Up @@ -96,7 +96,7 @@ onMounted(() => {
:step="stepIndex"
:animate="!isPrintMode"
:options="{
globalScale: scale,
globalScale: scale * zoom,
// TODO: make this configurable later
duration: 800,
stagger: 1,
Expand Down
1 change: 1 addition & 0 deletions packages/client/constants.ts
Expand Up @@ -12,6 +12,7 @@ export const injectionRoute = '$$slidev-route' as unknown as InjectionKey<SlideR
export const injectionRenderContext = '$$slidev-render-context' as unknown as InjectionKey<Ref<RenderContext>>
export const injectionActive = '$$slidev-active' as unknown as InjectionKey<Ref<boolean>>
export const injectionFrontmatter = '$$slidev-fontmatter' as unknown as InjectionKey<Record<string, any>>
export const injectionSlideZoom = '$$slidev-slide-zoom' as unknown as InjectionKey<ComputedRef<number>>

export const CLASS_VCLICK_TARGET = 'slidev-vclick-target'
export const CLASS_VCLICK_HIDDEN = 'slidev-vclick-hidden'
Expand Down
7 changes: 5 additions & 2 deletions packages/client/context.ts
@@ -1,4 +1,4 @@
import { ref, toRef } from 'vue'
import { computed, ref, toRef } from 'vue'
import { injectLocal, objectOmit, provideLocal } from '@vueuse/core'
import {
FRONTMATTER_FIELDS,
Expand All @@ -9,6 +9,7 @@ import {
injectionRenderContext,
injectionRoute,
injectionSlideScale,
injectionSlideZoom,
injectionSlidevContext,
} from './constants'

Expand All @@ -24,7 +25,8 @@ export function useSlideContext() {
const $renderContext = injectLocal(injectionRenderContext)!
const $frontmatter = injectLocal(injectionFrontmatter, {})
const $route = injectLocal(injectionRoute, undefined)
const $scale = injectLocal(injectionSlideScale, ref(1))!
const $scale = injectLocal(injectionSlideScale, ref(1))
const $zoom = injectLocal(injectionSlideZoom, computed(() => 1))

return {
$slidev,
Expand All @@ -36,6 +38,7 @@ export function useSlideContext() {
$renderContext,
$frontmatter,
$scale,
$zoom,
}
}

Expand Down
14 changes: 8 additions & 6 deletions packages/client/internals/SlideWrapper.vue
Expand Up @@ -3,7 +3,7 @@ import { computed, defineAsyncComponent, defineComponent, h, onMounted, ref, toR
import type { PropType } from 'vue'
import { provideLocal } from '@vueuse/core'
import type { ClicksContext, RenderContext, SlideRoute } from '@slidev/types'
import { injectionActive, injectionClicksContext, injectionCurrentPage, injectionRenderContext, injectionRoute } from '../constants'
import { injectionActive, injectionClicksContext, injectionCurrentPage, injectionRenderContext, injectionRoute, injectionSlideZoom } from '../constants'
import SlideLoading from './SlideLoading.vue'
const props = defineProps({
Expand All @@ -29,21 +29,23 @@ const props = defineProps({
},
})
const zoom = computed(() => props.route.meta?.slide?.frontmatter.zoom ?? 1)
provideLocal(injectionRoute, props.route)
provideLocal(injectionCurrentPage, ref(props.route.no))
provideLocal(injectionRenderContext, ref(props.renderContext as RenderContext))
provideLocal(injectionActive, toRef(props, 'active'))
provideLocal(injectionClicksContext, toRef(props, 'clicksContext'))
provideLocal(injectionSlideZoom, zoom)
const style = computed(() => {
const zoom = props.route.meta?.slide?.frontmatter.zoom ?? 1
return zoom === 1
return zoom.value === 1
? undefined
: {
width: `${100 / zoom}%`,
height: `${100 / zoom}%`,
width: `${100 / zoom.value}%`,
height: `${100 / zoom.value}%`,
transformOrigin: 'top left',
transform: `scale(${zoom})`,
transform: `scale(${zoom.value})`,
}
})
Expand Down

0 comments on commit 0e94054

Please sign in to comment.