Skip to content

Commit b05d49a

Browse files
committed
✨ add colorScheme prop to force VS Code color theme
1 parent 827cfc7 commit b05d49a

6 files changed

Lines changed: 228 additions & 174 deletions

File tree

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ Both absolute and relative paths are supported. Relative paths are resolved from
4646
<Editor session="demo" defaultFolder=".." />
4747
```
4848

49+
## 🌗 Color scheme
50+
51+
Force VS Code to use a specific color theme:
52+
53+
```md
54+
<Editor session="demo" colorScheme="dark" />
55+
<Editor session="demo" colorScheme="light" />
56+
```
57+
58+
If omitted, the color scheme automatically follows your Slidev presentation's `colorSchema` setting.
59+
4960
## 🔍 Zoom
5061

5162
VS Code can appear too large inside a slide. Use the `zoom` prop to scale it down:
@@ -93,13 +104,14 @@ Per-component props override these values.
93104

94105
| Prop | Type | Default | Description |
95106
| --------------- | --------- | ------------ | ----------------------------------------------------------------------- |
96-
| `session` | `string` | auto | Unique session identifier. Auto-generated from slide number if omitted. |
97-
| `defaultFolder` | `string` | project root | Workspace folder to open. Absolute or relative to the Slidev root. |
98-
| `height` | `string` | `100%` | CSS height of the editor container. |
99-
| `persist` | `boolean` | `false` | Keep the session alive when navigating away. |
100-
| `port` | `number` | auto | Force a specific port for this session. |
101-
| `startTimeout` | `number` | `30000` | Max startup time in ms before the session is marked as failed. |
102-
| `zoom` | `number` | `1` | Scale factor for the VS Code UI (e.g. `0.8` for 80%). |
107+
| `session` | `string` | auto | Unique session identifier. Auto-generated from slide number if omitted. |
108+
| `defaultFolder` | `string` | project root | Workspace folder to open. Absolute or relative to the Slidev root. |
109+
| `colorScheme` | `'dark' \| 'light'` | auto | VS Code color theme. Defaults to Slidev's `colorSchema` if set, otherwise none. |
110+
| `height` | `string` | `100%` | CSS height of the editor container. |
111+
| `persist` | `boolean` | `false` | Keep the session alive when navigating away. |
112+
| `port` | `number` | auto | Force a specific port for this session. |
113+
| `startTimeout` | `number` | `30000` | Max startup time in ms before the session is marked as failed. |
114+
| `zoom` | `number` | `1` | Scale factor for the VS Code UI (e.g. `0.8` for 80%). |
103115

104116
## ⚠️ Static exports
105117

components/Editor.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { REGISTRY_KEY } from '../setup/main'
88
import type { EditorDeckConfig, EditorProps, SessionEntry } from '../types'
99
1010
const props = withDefaults(defineProps<EditorProps>(), {
11+
colorScheme: undefined,
1112
defaultFolder: undefined,
1213
height: '100%',
1314
persist: false,
@@ -41,6 +42,12 @@ const isStarting = computed(
4142
const hasFailed = computed(() => session.value?.state === 'ERROR')
4243
4344
const resolvedFolder = computed(() => props.defaultFolder ?? deckConfig.value?.defaultFolder ?? '')
45+
46+
const slidevColorSchema = computed(() => {
47+
const schema = ($slidev.configs as { colorSchema?: string }).colorSchema
48+
return schema === 'light' || schema === 'dark' ? schema : undefined
49+
})
50+
const resolvedColorScheme = computed(() => props.colorScheme ?? slidevColorSchema.value)
4451
const resolvedZoom = computed(() => props.zoom ?? deckConfig.value?.zoom ?? 1)
4552
4653
const resolvedTimeout = computed(() => props.startTimeout ?? deckConfig.value?.startTimeout)
@@ -53,6 +60,7 @@ async function start(): Promise<void> {
5360
try {
5461
const url = await requestStart(
5562
{
63+
colorScheme: resolvedColorScheme.value,
5664
defaultFolder: resolvedFolder.value,
5765
defaultPort: deckConfig.value?.defaultPort,
5866
port: props.port,

0 commit comments

Comments
 (0)