Skip to content

Commit

Permalink
fix: export in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 21, 2021
1 parent d1216e1 commit 3015e67
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/client/internals/NavControls.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, defineProps, ref, shallowRef } from 'vue'
import { isDark, toggleDark, isColorSchemaAuto } from '../logic/dark'
import { isDark, toggleDark, isColorSchemaConfigured } from '../logic/dark'
import { hasNext, hasPrev, prev, next, total, isPresenter, currentPage, downloadPDF, isEmbedded } from '../logic/nav'
import { toggleOverview, showEditor, showInfoDialog, fullscreen, breakpoints, activeElement } from '../state'
import { configs } from '../env'
Expand Down Expand Up @@ -49,7 +49,7 @@ if (__DEV__)
<carbon:apps />
</button>

<button v-if="isColorSchemaAuto" class="icon-btn" title="Toggle dark mode" @click="toggleDark">
<button v-if="!isColorSchemaConfigured" class="icon-btn" title="Toggle dark mode" @click="toggleDark">
<carbon-moon v-if="isDark" />
<carbon-sun v-else />
</button>
Expand Down
23 changes: 15 additions & 8 deletions packages/client/logic/dark.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { isClient, useStorage, useToggle } from '@vueuse/core'
import { isClient, usePreferredDark, useStorage, useToggle } from '@vueuse/core'
import { computed, watch } from 'vue'
import { configs } from '../env'

const _isDark = useStorage('slidev-color-schema', false)
const preferredDark = usePreferredDark()
const store = useStorage('slidev-color-schema', 'auto')

export const isColorSchemaAuto = computed(() => configs.colorSchema === 'auto')
export const isColorSchemaConfigured = computed(() => configs.colorSchema !== 'auto')
export const isDark = computed<boolean>({
get() {
return isColorSchemaAuto.value
? _isDark.value
: configs.colorSchema === 'dark'
if (isColorSchemaConfigured.value)
return configs.colorSchema === 'dark'
return store.value === 'auto'
? preferredDark.value
: store.value === 'dark'
},
set(v) {
if (isColorSchemaAuto.value)
_isDark.value = v
if (isColorSchemaConfigured.value)
return
store.value = v === preferredDark.value
? 'auto'
: v ? 'dark' : 'light'
},
})

export const toggleDark = useToggle(isDark)

if (isClient) {
Expand Down
4 changes: 1 addition & 3 deletions packages/slidev/node/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export async function exportSlides({
async function go(no: number) {
progress.update(no)

if (dark)
await page.emulateMedia({ colorScheme: 'dark' })
const url = routerMode === 'hash'
? `http://localhost:${port}/#${base}${no}?print`
: `http://localhost:${port}${base}${no}?print`
Expand All @@ -97,7 +95,7 @@ export async function exportSlides({
})
await page.waitForTimeout(timeout)
await page.waitForLoadState('networkidle')
await page.emulateMedia({ media: 'screen' })
await page.emulateMedia({ colorScheme: dark ? 'dark' : 'light', media: 'screen' })
}

const pages = parseRangeString(total, range)
Expand Down
2 changes: 2 additions & 0 deletions packages/slidev/node/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function createConfigPlugin(options: ResolvedSlidevOptions): Plugin {
'mermaid/dist/mermaid.min',
],
exclude: [
'@vueuse/core',
'@vueuse/shared',
'vue-demi',
'mermaid',
],
Expand Down

0 comments on commit 3015e67

Please sign in to comment.