Skip to content

Commit b0de0df

Browse files
committed
feat: ability to be controlled via messages
1 parent 9e00229 commit b0de0df

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

packages/client/internals/Play.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ if (__DEV__)
3636
<template>
3737
<div id="page-root" ref="root" class="grid grid-cols-[1fr,max-content]">
3838
<SlideContainer
39-
class="w-full h-full bg-black"
39+
class="w-full h-full"
40+
:style="{ background: 'var(--slidev-slide-container-background, black)'}"
4041
:width="isPrintMode ? windowSize.width.value : undefined"
4142
:scale="slideScale"
4243
@click="onClick"

packages/client/modules/context.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@ export default function createSlidevContext() {
1919
// @ts-expect-error
2020
navObj[key] = nav[key]
2121
}
22-
app.config.globalProperties.$slidev = reactive({
22+
const context = reactive({
2323
nav: navObj,
2424
})
25+
app.config.globalProperties.$slidev = context
26+
27+
// allows controls from postMessages
28+
if (__DEV__) {
29+
// @ts-expect-error
30+
window.__slidev__ = context
31+
window.addEventListener('message', ({ data }) => {
32+
if (data && data.target === 'slidev') {
33+
if (data.type === 'navigate') {
34+
context.nav.go(+data.no, +data.clicks || 0)
35+
}
36+
else if (data.type === 'css-vars') {
37+
const root = document.documentElement
38+
for (const [key, value] of Object.entries(data.vars || {}))
39+
root.style.setProperty(key, value as any)
40+
}
41+
}
42+
})
43+
}
2544
},
2645
}
2746
}

packages/client/styles/code.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ html:not(.dark) .shiki-dark {
66
display: none;
77
}
88

9-
:root {
10-
--slidev-code-background: rgba(125,125,125,0.03);
11-
--slidev-code-font-family: theme('fontFamily.mono');
12-
--slidev-code-padding: 8px;
13-
--slidev-code-font-size: 12px;
14-
--slidev-code-line-height: 18px;
15-
--slidev-code-radius: 4px;
16-
--slidev-code-margin: 4px 0;
17-
}
18-
199
.slidev-code {
2010
font-family: var(--slidev-code-font-family) !important;
2111
padding: var(--slidev-code-padding) !important;

packages/client/styles/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body,
1111
}
1212

1313
html {
14-
background: black;
14+
background: transparent;
1515
}
1616

1717
.icon-btn {

packages/client/styles/vars.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:root {
2+
--slidev-code-background: rgba(125,125,125,0.03);
3+
--slidev-code-font-family: theme('fontFamily.mono');
4+
--slidev-code-padding: 8px;
5+
--slidev-code-font-size: 12px;
6+
--slidev-code-line-height: 18px;
7+
--slidev-code-radius: 4px;
8+
--slidev-code-margin: 4px 0;
9+
--slidev-slide-container-background: black;
10+
}

packages/slidev/node/plugins/loaders.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export function createSlidesLoader(
304304

305305
async function generateUserStyles() {
306306
const imports: string[] = [
307+
`import "${toAtFS(join(clientRoot, 'styles/vars.css'))}"`,
307308
`import "${toAtFS(join(clientRoot, 'styles/index.css'))}"`,
308309
`import "${toAtFS(join(clientRoot, 'styles/code.css'))}"`,
309310
]

0 commit comments

Comments
 (0)