|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, onMounted, watch, shallowRef } from 'vue' |
| 3 | +// @ts-ignore |
| 4 | +import TypeIt from 'typeit' |
| 5 | +import Markdown from 'markdown-it' |
| 6 | +import type { SlidevMarkdown } from '@slidev/types' |
| 7 | +import { parse } from '../../../../../packages/parser/src/core' |
| 8 | +import Default from '../../../../../packages/client/layouts/default.vue' |
| 9 | +import Center from '../../../../../packages/client/layouts/center.vue' |
| 10 | +import SlideContainer from '../../../../../packages/client/internals/SlideContainer.vue' |
| 11 | +import Cover from '../../../../../packages/theme-default/layouts/cover.vue' |
| 12 | +import '../../../../../packages/theme-default/styles/layout.css' |
| 13 | +
|
| 14 | +const paused = ref(false) |
| 15 | +const code = ref('') |
| 16 | +const html = ref('') |
| 17 | +let info: SlidevMarkdown |
| 18 | +const block = ref<HTMLPreElement>() |
| 19 | +const layout = shallowRef<any>(Default) |
| 20 | +
|
| 21 | +const markdown = new Markdown() |
| 22 | +
|
| 23 | +watch([code, paused], () => { |
| 24 | + if (paused.value) |
| 25 | + return |
| 26 | + try { |
| 27 | + info = parse(code.value) |
| 28 | + html.value = markdown.render(info.slides[0].content) |
| 29 | + const name = info?.slides?.[0]?.frontmatter?.layout || 'default' |
| 30 | + layout.value = name === 'cover' |
| 31 | + ? Cover |
| 32 | + : name === 'center' |
| 33 | + ? Center |
| 34 | + : Default |
| 35 | + } |
| 36 | + catch (e) { |
| 37 | +
|
| 38 | + } |
| 39 | +}) |
| 40 | +
|
| 41 | +onMounted(() => { |
| 42 | + new TypeIt(block.value, { |
| 43 | + speed: 50, |
| 44 | + startDelay: 900, |
| 45 | + afterStep: () => { |
| 46 | + code.value = JSON.parse(JSON.stringify(block.value!.innerText.replace('|', ''))) |
| 47 | + }, |
| 48 | + }) |
| 49 | + .type('<br><span class="token title"># Welcome to Slidev!</span><br><br>', { delay: 400 }) |
| 50 | + .type('Presentation Slides for Developers', { delay: 400 }) |
| 51 | + .move('START', { speed: 0 }) |
| 52 | + .type('<br>') |
| 53 | + .move('START') |
| 54 | + .exec(() => paused.value = true) |
| 55 | + .type('<span class="token punctuation">---<br><br>---</span>') |
| 56 | + .move(-4) |
| 57 | + .type('<span class="token tag">layout:</span> center') |
| 58 | + .exec(() => paused.value = false) |
| 59 | + .pause(1000) |
| 60 | + .exec(() => paused.value = true) |
| 61 | + .delete(6, { delay: 100, speed: 50 }) |
| 62 | + .type('cover') |
| 63 | + .exec(() => paused.value = false) |
| 64 | + .pause(1000) |
| 65 | + .type('<br>') |
| 66 | + .type('<span class="token tag">background:</span> ', { delay: 500 }) |
| 67 | + .type('https://slidev.antfu.me/demo-cover.png', { speed: 0, delay: 1000 }) |
| 68 | + .move('END', { speed: 0 }) |
| 69 | + .type('<br><br><span class="token punctuation">---</span><br><br>', { delay: 400 }) |
| 70 | + .type('<span class="token title"># Page 2</span><br><br>', { delay: 400 }) |
| 71 | + .type('- 📄 Write sldies in a simple Markdown file<br>', { delay: 800 }) |
| 72 | + .type('- 🌈 Themes, code blocks, interactive components<br>', { delay: 800 }) |
| 73 | + .type('- 😎 Read the docs to learn more!', { delay: 800 }) |
| 74 | + .go() |
| 75 | +}) |
| 76 | +</script> |
| 77 | + |
| 78 | +<template> |
| 79 | + <div> |
| 80 | + <DemoEditor> |
| 81 | + <div class="text-sm opacity-50"> |
| 82 | + ./slides.md |
| 83 | + </div> |
| 84 | + |
| 85 | + <div class="language-md !bg-transparent"> |
| 86 | + <pre |
| 87 | + ref="block" |
| 88 | + class="text-left whitespace-normal font-mono bg-transparent" |
| 89 | + ></pre> |
| 90 | + </div> |
| 91 | + </DemoEditor> |
| 92 | + |
| 93 | + <DemoSlide class="text-left"> |
| 94 | + <SlideContainer class="w-full h-full"> |
| 95 | + <component :is="layout" v-bind="info?.slides?.[0]?.frontmatter"> |
| 96 | + <div v-html="html"></div> |
| 97 | + </component> |
| 98 | + </SlideContainer> |
| 99 | + </DemoSlide> |
| 100 | + </div> |
| 101 | +</template> |
0 commit comments