| 1 | <script setup lang="ts"> |
| 2 | import { useStyleTag } from '@vueuse/core' |
| 3 | import { computed, ref, shallowRef } from 'vue' |
| 4 | import { useDrawings } from '../composables/useDrawings' |
| 5 | import { useHideCursorIdle } from '../composables/useHideCursorIdle' |
| 6 | import { useNav } from '../composables/useNav' |
| 7 | import { useSwipeControls } from '../composables/useSwipeControls' |
| 8 | import { useWakeLock } from '../composables/useWakeLock' |
| 9 | import Controls from '../internals/Controls.vue' |
| 10 | import LaserPointer from '../internals/LaserPointer.vue' |
| 11 | import NavControls from '../internals/NavControls.vue' |
| 12 | import PresenterMouse from '../internals/PresenterMouse.vue' |
| 13 | import SlideContainer from '../internals/SlideContainer.vue' |
| 14 | import SlidesShow from '../internals/SlidesShow.vue' |
| 15 | import { onContextMenu } from '../logic/contextMenu' |
| 16 | import { registerShortcuts } from '../logic/shortcuts' |
| 17 | import { editorHeight, editorWidth, isEditorVertical, isScreenVertical, showEditor, viewerCssFilter, viewerCssFilterDefaults } from '../state' |
| 18 | |
| 19 | const { next, prev, isPrintMode, isPlaying, isEmbedded } = useNav() |
| 20 | const { isDrawing } = useDrawings() |
| 21 | |
| 22 | const root = ref<HTMLDivElement>() |
| 23 | function onClick(e: MouseEvent) { |
| 24 | if (showEditor.value) |
| 25 | return |
| 26 | |
| 27 | if (e.button === 0 && (e.target as HTMLElement)?.id === 'slide-container') { |
| 28 | // click right to next, left to previous |
| 29 | if ((e.pageX / window.innerWidth) > 0.5) |
| 30 | next() |
| 31 | else |
| 32 | prev() |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | useSwipeControls(root) |
| 37 | registerShortcuts() |
| 38 | if (__SLIDEV_FEATURE_WAKE_LOCK__) |
| 39 | useWakeLock() |
| 40 | useHideCursorIdle(computed(() => isPlaying.value && !isEmbedded.value && !showEditor.value)) |
| 41 | |
| 42 | if (import.meta.hot) { |
| 43 | useStyleTag(computed(() => showEditor.value |
| 44 | ? ` |
| 45 | vite-error-overlay { |
| 46 | --width: calc(100vw - ${isEditorVertical.value ? 0 : editorWidth.value}px); |
| 47 | --height: calc(100vh - ${isEditorVertical.value ? editorHeight.value : 0}px); |
| 48 | position: fixed; |
| 49 | left: 0; |
| 50 | top: 0; |
| 51 | width: calc(var(--width) / var(--slidev-slide-scale)); |
| 52 | height: calc(var(--height) / var(--slidev-slide-scale)); |
| 53 | transform-origin: top left; |
| 54 | transform: scale(var(--slidev-slide-scale)); |
| 55 | }` |
| 56 | : '', |
| 57 | )) |
| 58 | } |
| 59 | |
| 60 | const persistNav = computed(() => isScreenVertical.value || showEditor.value) |
| 61 | |
| 62 | const SideEditor = shallowRef<any>() |
| 63 | if (__DEV__ && __SLIDEV_FEATURE_EDITOR__) |
| 64 | import('../internals/SideEditor.vue').then(v => SideEditor.value = v.default) |
| 65 | |
| 66 | const contentStyle = computed(() => { |
| 67 | let filter = '' |
| 68 | |
| 69 | if (viewerCssFilter.value.brightness !== viewerCssFilterDefaults.brightness) |
| 70 | filter += `brightness(${viewerCssFilter.value.brightness}) ` |
| 71 | if (viewerCssFilter.value.contrast !== viewerCssFilterDefaults.contrast) |
| 72 | filter += `contrast(${viewerCssFilter.value.contrast}) ` |
| 73 | if (viewerCssFilter.value.sepia !== viewerCssFilterDefaults.sepia) |
| 74 | filter += `sepia(${viewerCssFilter.value.sepia}) ` |
| 75 | if (viewerCssFilter.value.hueRotate !== viewerCssFilterDefaults.hueRotate) |
| 76 | filter += `hue-rotate(${viewerCssFilter.value.hueRotate}deg) ` |
| 77 | if (viewerCssFilter.value.invert) |
| 78 | filter += 'invert(1) ' |
| 79 | |
| 80 | return { |
| 81 | filter, |
| 82 | } |
| 83 | }) |
| 84 | </script> |
| 85 | |
| 86 | <template> |
| 87 | <div |
| 88 | id="page-root" ref="root" class="grid" |
| 89 | :class="isEditorVertical ? 'grid-rows-[1fr_max-content]' : 'grid-cols-[1fr_max-content]'" |
| 90 | > |
| 91 | <SlideContainer |
| 92 | :style="{ background: 'var(--slidev-slide-container-background, black)' }" |
| 93 | is-main |
| 94 | :content-style="contentStyle" |
| 95 | @pointerdown="onClick" |
| 96 | @contextmenu="onContextMenu" |
| 97 | > |
| 98 | <template #default> |
| 99 | <SlidesShow render-context="slide" /> |
| 100 | <PresenterMouse /> |
| 101 | <LaserPointer /> |
| 102 | </template> |
| 103 | <template #controls> |
| 104 | <div |
| 105 | v-if="!isPrintMode" |
| 106 | class="absolute bottom-0 left-0 transition duration-300 opacity-0 hover:opacity-100 focus-within:opacity-100 focus-visible:opacity-100" |
| 107 | :class="[ |
| 108 | persistNav ? '!opacity-100 right-0' : 'opacity-0 p-2', |
| 109 | isDrawing ? 'pointer-events-none' : '', |
| 110 | ]" |
| 111 | > |
| 112 | <NavControls :persist="persistNav" /> |
| 113 | </div> |
| 114 | </template> |
| 115 | </SlideContainer> |
| 116 | <SideEditor v-if="SideEditor && showEditor" :resize="true" /> |
| 117 | </div> |
| 118 | <Controls v-if="!isPrintMode" /> |
| 119 | <div id="twoslash-container" /> |
| 120 | </template> |
| 121 |