| 1 | import type { AppContext } from '@slidev/types' |
| 2 | import type { App } from 'vue' |
| 3 | import TwoSlashFloatingVue from '@shikijs/vitepress-twoslash/client' |
| 4 | import { createHead } from '@unhead/vue/client' |
| 5 | import { createMemoryHistory, createRouter, createWebHashHistory, createWebHistory } from 'vue-router' |
| 6 | import setups from '#slidev/setups/main' |
| 7 | import { createVClickDirectives } from '../modules/v-click' |
| 8 | import { createVDragDirective } from '../modules/v-drag' |
| 9 | import { createVMarkDirective } from '../modules/v-mark' |
| 10 | import { createVMotionDirectives } from '../modules/v-motion' |
| 11 | import { setupPWA } from '../setup/pwa' |
| 12 | import setupRoutes from '../setup/routes' |
| 13 | import '../styles' |
| 14 | |
| 15 | export default async function setupMain(app: App) { |
| 16 | function setMaxHeight() { |
| 17 | // disable the mobile navbar scroll |
| 18 | // see https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ |
| 19 | document.documentElement.style.setProperty('--vh', `${window.innerHeight * 0.01}px`) |
| 20 | } |
| 21 | setMaxHeight() |
| 22 | window.addEventListener('resize', setMaxHeight) |
| 23 | |
| 24 | const router = createRouter({ |
| 25 | history: __SLIDEV_MEMORY_ROUTE__ |
| 26 | ? createMemoryHistory(import.meta.env.BASE_URL) |
| 27 | : __SLIDEV_HASH_ROUTE__ |
| 28 | ? createWebHashHistory(import.meta.env.BASE_URL) |
| 29 | : createWebHistory(import.meta.env.BASE_URL), |
| 30 | routes: setupRoutes(), |
| 31 | }) |
| 32 | |
| 33 | app.use(router) |
| 34 | app.use(createHead()) |
| 35 | app.use(createVClickDirectives()) |
| 36 | app.use(createVMarkDirective()) |
| 37 | app.use(createVDragDirective()) |
| 38 | app.use(createVMotionDirectives()) |
| 39 | app.use(TwoSlashFloatingVue as any, { container: '#twoslash-container' }) |
| 40 | |
| 41 | const context: AppContext = { |
| 42 | app, |
| 43 | router, |
| 44 | } |
| 45 | |
| 46 | for (const setup of setups) |
| 47 | await setup(context) |
| 48 | |
| 49 | if (__SLIDEV_FEATURE_PWA__) |
| 50 | setupPWA() |
| 51 | } |
| 52 |