Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Shiki magic move with zoom option #1454

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/client/builtin/ShikiMagicMove.vue
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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