PresentationSlideView
Displays a PowerPoint slide with its layout, text, pictures, shapes and charts.
import { PresentationSlideView } from '@tumblerjs/svelte/slides';
Example
Loading workspace-brief.pptx…
Choose a slide, or pinch to zoom.
SlidePreview.svelte
<script lang="ts">
import { untrack } from 'svelte';
import { openPresentationArtifact } from '@tumblerjs/slides';
import {
PresentationSlideView,
} from '@tumblerjs/svelte/slides';
let { bytes }: { bytes: Uint8Array } = $props();
const { document } = untrack(
() => openPresentationArtifact(bytes),
);
let index = $state(0);
let scale = $state(1);
const slide = $derived(document.slides[index]);
</script>
<label>
Slide
<select aria-label="Slide" bind:value={index}>
{#each document.slides as { title }, i}
<option value={i}>{i + 1}. {title}</option>
{/each}
</select>
</label>
<div class="slide-example">
{#if slide}
<PresentationSlideView
presentation={document}
{slide}
bind:scale
/>
{/if}
</div>
<style>
label {
display: flex;
gap: 10px;
align-items: center;
margin-bottom: 14px;
}
select { min-width: 0; max-width: 85%; }
.slide-example { height: 430px; min-width: 0; }
</style>
Usage
Call openPresentationArtifact(bytes) from @tumblerjs/slides. Pass its document as presentation and one entry of document.slides as slide. The view scales the slide to fit its container.
The example takes the file contents as a bytes prop. To run it in your app, save the example source as SlidePreview.svelte, put workspace-brief.pptx in static/, and load it from +page.svelte:
+page.svelte
<script lang="ts">
import { onMount } from 'svelte';
import SlidePreview from './SlidePreview.svelte';
let bytes = $state<Uint8Array>();
onMount(async () => {
const response = await fetch('/workspace-brief.pptx');
bytes = new Uint8Array(await response.arrayBuffer());
});
</script>
{#if bytes}<SlidePreview {bytes} />{/if}Props
| Prop | Description |
|---|---|
presentationrequired PresentationDocument | The parsed presentation, artifact.document. Supplies the layouts and theme the slide inherits. |
sliderequired PresentationSlide | The slide to display. |
scale number | Bindable zoom factor. 1 fits the slide to the container. |
editable boolean | Lets the user move, resize and rotate objects and edit their text. Moving needs onobjectchange and text editing needs ontextedit; without them nothing changes. |
selectedKey string | Bindable key of the selected object. |
onobjectchange (change: PresentationObjectChange) => void | Called when the user finishes moving, resizing or rotating an object. Apply it with artifact.updateObject(change) and assign the result. |
ontextedit (change: PresentationTextEdit) => void | Called as the user inserts, replaces or deletes text. Apply it with artifact.editText(change) and assign the result. |