Skip to content

Commit f41603e

Browse files
authored
fix: slide exporter (#1380)
1 parent f32cc16 commit f41603e

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

packages/client/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<body>
99
<div id="app"></div>
1010
<script type="module" src="__ENTRY__"></script>
11+
<div id="mermaid-rendering-container"></div>
1112
<!-- body -->
1213
</body>
1314
</html>

packages/client/internals/SlideLoading.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ onMounted(() => {
1010
</script>
1111

1212
<template>
13-
<div class="h-full w-full flex items-center justify-center gap-2">
13+
<div class="h-full w-full flex items-center justify-center gap-2 slidev-slide-loading">
1414
<template v-if="timeout">
1515
<div class="i-svg-spinners-90-ring-with-bg text-xl" />
1616
<div>Loading slide...</div>

packages/client/modules/mermaid.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ mermaid.startOnLoad = false
88
mermaid.initialize({ startOnLoad: false })
99

1010
const cache = new Map<string, string>()
11+
let containerElement: Element | undefined
1112

1213
export async function renderMermaid(lzEncoded: string, options: any) {
14+
containerElement ??= document.getElementById('mermaid-rendering-container')!
1315
const key = lzEncoded + JSON.stringify(options)
1416
const _cache = cache.get(key)
1517
if (_cache)
@@ -22,7 +24,7 @@ export async function renderMermaid(lzEncoded: string, options: any) {
2224
})
2325
const code = lz.decompressFromBase64(lzEncoded)
2426
const id = makeId()
25-
const { svg } = await mermaid.render(id, code)
27+
const { svg } = await mermaid.render(id, code, containerElement)
2628
cache.set(key, svg)
2729
return svg
2830
}

packages/slidev/node/export.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,49 @@ export async function exportSlides({
193193
})
194194
await page.waitForLoadState('networkidle')
195195
await page.emulateMedia({ colorScheme: dark ? 'dark' : 'light', media: 'screen' })
196+
// Wait for slides to be loaded
197+
{
198+
const elements = page.locator('.slidev-slide-loading')
199+
const count = await elements.count()
200+
for (let index = 0; index < count; index++)
201+
await elements.nth(index).waitFor({ state: 'detached' })
202+
}
196203
// Check for "data-waitfor" attribute and wait for given element to be loaded
197-
const elements = page.locator('[data-waitfor]')
198-
const count = await elements.count()
199-
for (let index = 0; index < count; index++) {
200-
const element = elements.nth(index)
201-
const attribute = await element.getAttribute('data-waitfor')
202-
if (attribute)
203-
await element.locator(attribute).waitFor()
204+
{
205+
const elements = page.locator('[data-waitfor]')
206+
const count = await elements.count()
207+
for (let index = 0; index < count; index++) {
208+
const element = elements.nth(index)
209+
const attribute = await element.getAttribute('data-waitfor')
210+
if (attribute)
211+
await element.locator(attribute).waitFor()
212+
}
204213
}
205214
// Wait for frames to load
206-
const frames = page.frames()
207-
await Promise.all(frames.map(frame => frame.waitForLoadState()))
215+
{
216+
const frames = page.frames()
217+
await Promise.all(frames.map(frame => frame.waitForLoadState()))
218+
}
219+
// Wait for Mermaid graphs to be rendered
220+
{
221+
const container = page.locator('#mermaid-rendering-container')
222+
while (true) {
223+
const element = container.locator('div').first()
224+
if (await element.count() === 0)
225+
break
226+
await element.waitFor({ state: 'detached' })
227+
}
228+
await container.evaluate(node => node.style.display = 'none')
229+
}
230+
// Hide Monaco aria container
231+
{
232+
const elements = page.locator('.monaco-aria-container')
233+
const count = await elements.count()
234+
for (let index = 0; index < count; index++) {
235+
const element = elements.nth(index)
236+
await element.evaluate(node => node.style.display = 'none')
237+
}
238+
}
208239
}
209240

210241
async function getSlidesIndex() {

0 commit comments

Comments
 (0)