Skip to content

Composables ​

PowerPointViewer.vue is a thin <script setup> orchestrator. Almost all of its logic lives in 110+ custom composables under viewer/composables/, composed inside the component, while the visual components are largely presentational. State is held entirely in Vue's reactivity system; there is no external state library.

Public vs internal

Most of these composables are internal architecture: they assume a specific composition order and shared inputs. A small curated subset is exported from pptx-vue-viewer/viewer with a normal semver-stable API. The complete set is also importable from pptx-vue-viewer/internals: internal building blocks that are not covered by semver, so prefer the stable root exports. See Complete Composables Reference.

Architecture (internal) ​

These composables describe how the viewer is wired. They are importable (see below) but assume a specific composition order and shared inputs; treat this table as conceptual reference, not an API contract.

ComposableConcern
useLoadContentParses the PPTX buffer on load via PptxHandler.
useEditorHistoryUndo/redo snapshot stack, aware of the template (master/layout) element layer.
useEditorOperationsElement create/update/delete/duplicate primitives.
useElementDragMove / resize / rotate / adjust, plus snap & alignment guides.
useElementInsertionShape / image / text box / table / chart insertion.
useSlideOperationsAdd / delete / duplicate / reorder slides.
useAutosaveAutosave interval + status (see Props > Autosave).
usePresentationModeWiringSlideshow navigation wiring into the component.
useExportWiringPNG / PDF / GIF / WebM export + print, wired into the component.
useCollaborationWiringShare/Broadcast dialog + prop-driven Yjs session lifecycle.
useRibbonPropsComposes the full Office-ribbon RibbonProps contract.
useEditorKeyboardConfig-driven keyboard-shortcut registry + dispatch.
useIsMobileDevice/viewport classification (mobile/tablet/orientation).

There are dozens more (dialogs, comments, sections, SmartArt editing, table editing, presentation sub-composables, mobile chrome, etc.). See the Complete Composables Reference for the full list, grouped by concern.

Public composables ​

The following are exported from pptx-vue-viewer/viewer and are safe to import. They are opt-in and tree-shakeable. The root pptx-vue-viewer entry re-exports the collaboration composables (useCollaboration, useYjsProvider, usePresenceTracking, useCollaborativeState, and useCollaborativeHistory); the complete curated surface comes from the /viewer subpath.

ts
import {
	useCollaboration,
	useEditorHistory,
	useEditorOperations,
	useLoadContent,
} from 'pptx-vue-viewer/viewer';

useLoadContent ​

Parses a .pptx buffer via PptxHandler and exposes the result as reactive state. The input is a MaybeRefOrGetter, so a plain value, a ref, or a getter all work; the load re-runs when it changes.

ts
function useLoadContent(
	content: MaybeRefOrGetter<Uint8Array | ArrayBuffer | null | undefined>,
): UseLoadContentResult;

UseLoadContentResult exposes (all reactive): slides, templateElementsBySlideId, canvasSize, theme, themeColorMap, slideMasters, layoutOptions, mediaDataUrls, loading, error, isEncrypted, handler (the live PptxHandler, for saving), plus document metadata (coreProperties, appProperties, customProperties, sections, customShows, embeddedFonts, signatures, and more).

signatures is the deck's SignatureSummary (undefined when it carries no signature parts). A part alone never makes a deck signed: present it through signatureStatusView(summary, locale) from ooxml-ui/pptx, which reads "Signed" only when every signature verifies and gives the translated label, description, tone and per-signature rows.

vue
<script setup lang="ts">
import { useLoadContent } from 'pptx-vue-viewer/viewer';

const props = defineProps<{ bytes: ArrayBuffer | null }>();

const { slides, canvasSize, loading, error, handler } = useLoadContent(() => props.bytes);

async function save(): Promise<Uint8Array | undefined> {
	return handler.value?.save([...slides.value]);
}
</script>

<template>
	<p v-if="loading">Parsing...</p>
	<p v-else-if="error">{{ error }}</p>
	<p v-else>{{ slides.length }} slides at {{ canvasSize.width }}x{{ canvasSize.height }}</p>
</template>

useEditorHistory and useEditorOperations ​

These two compose into a minimal headless editor. useEditorHistory(slides) owns the undo/redo snapshot stack; useEditorOperations provides element CRUD that snapshots through it.

ts
function useEditorHistory(
	slides: Ref<PptxSlide[]>,
	templateElementsBySlideId?: Ref<TemplateElementMap>,
): {
	canUndo: ComputedRef<boolean>;
	canRedo: ComputedRef<boolean>;
	pushHistory: () => void; // call immediately BEFORE committing a mutation
	undo: () => void;
	redo: () => void;
	clearHistory: () => void;
};

function useEditorOperations(input: {
	slides: Ref<PptxSlide[]>;
	activeSlideIndex: Ref<number>;
	pushHistory: () => void;
	selectedElementIds?: Ref<string[]>;
	templateElementsBySlideId?: Ref<TemplateElementMap>;
}): EditorOperations;

EditorOperations includes activeSlide, selectedElementIds, addElement, updateElement, removeElement, transformElement / moveElement, duplicateElement, bringForward, sendBackward, reorder, and updateElementText.

ts
import { useEditorHistory, useEditorOperations, useLoadContent } from 'pptx-vue-viewer/viewer';
import { ref } from 'vue';

const { slides } = useLoadContent(() => props.bytes);
const activeSlideIndex = ref(0);

const history = useEditorHistory(slides);
const ops = useEditorOperations({
	slides,
	activeSlideIndex,
	pushHistory: history.pushHistory,
});

ops.updateElementText('el_12', 'Updated headline');
ops.transformElement('el_12', { x: 120, y: 80 });
history.undo(); // reverts both, most recent first

Snapshot ordering

pushHistory() snapshots the current state, so it must run before a mutation is committed. The operations returned by useEditorOperations handle this for you; only call pushHistory manually when you mutate slides yourself.

Slide thumbnail rail ​

SlidesPane (exported from the package root and pptx-vue-viewer/viewer) is the rail of slide thumbnails that PowerPointViewer shows beside the canvas. It lists every slide (grouped under section headers when the deck has sections) and highlights the active one. It never changes the deck itself: clicking a thumbnail emits select, and with canEdit the footer, the context menus, Enter and drag-to-reorder emit commands you map onto useSlideOperations and useSectionOperations (also exported from /viewer), so they share your undo history and collaboration sync. Pass the deck props from useLoadContent so the thumbnails resolve slide numbers, header/footer fields and table styles as the canvas does.

vue
<script setup lang="ts">
import {
	SlideCanvas,
	SlidesPane,
	useEditorHistory,
	useLoadContent,
	useSectionOperations,
	useSlideOperations,
} from 'pptx-vue-viewer/viewer';
import { ref } from 'vue';
import 'pptx-vue-viewer/styles';

const props = defineProps<{ bytes: ArrayBuffer | null }>();
const deck = useLoadContent(() => props.bytes);
const { slides, templateElementsBySlideId } = deck;
const active = ref(0);
const history = useEditorHistory(slides);
const slideOps = useSlideOperations({
	slides,
	activeSlideIndex: active,
	pushHistory: history.pushHistory,
	templateElementsBySlideId,
});
const sectionOps = useSectionOperations({
	sections: deck.sections,
	slides,
	activeSlideIndex: active,
	pushHistory: history.pushHistory,
});
</script>

<template>
	<div style="display: flex; height: 600px">
		<SlidesPane
			:slides="slides"
			:template-elements-by-slide-id="templateElementsBySlideId"
			:active-slide-index="active"
			:canvas-size="deck.canvasSize.value"
			:media-data-urls="deck.mediaDataUrls.value"
			:section-groups="sectionOps.slidesBySection.value"
			:header-footer="deck.headerFooter.value"
			:custom-properties="deck.customProperties.value"
			:first-slide-number="deck.firstSlideNumber.value"
			:theme="deck.theme.value"
			:table-style-map="deck.tableStyleMap.value"
			can-edit
			@select="active = $event"
			@add-slide="slideOps.addSlide()"
			@add-slide-after="slideOps.addSlide"
			@move-slide="slideOps.moveSlide"
			@duplicate-slide="slideOps.duplicateSlide"
			@delete-slide="slideOps.deleteSlide"
			@add-section="sectionOps.addSection"
			@rename-section="sectionOps.renameSection"
			@delete-section="sectionOps.deleteSection"
			@move-section-up="sectionOps.moveSectionUp"
			@move-section-down="sectionOps.moveSectionDown"
			@toggle-section-collapse="sectionOps.toggleSectionCollapse"
		/>
		<div style="flex: 1; min-width: 0; position: relative">
			<SlideCanvas
				:slide="slides[active]"
				:canvas-size="deck.canvasSize.value"
				:media-data-urls="deck.mediaDataUrls.value"
				:template-elements="templateElementsBySlideId[slides[active]?.id ?? '']"
			/>
		</div>
	</div>
</template>

A multi-slide command arrives as one duplicate-slide, delete-slide or toggle-slide-hidden event per selected slide, highest index first, so each copy lands right after its source. The "Layout" entry of a slide's context menu emits select for that slide, then open-layout-gallery with { slideIndex, x, y } (the click point) for a Layout gallery of your own. Without canEdit the rail only navigates and shows no "Add Slide" footer. SlidesPane needs the full pptx-vue-viewer/styles stylesheet.

Single slide thumbnail ​

SlideThumbnail (exported, with its SlideThumbnailProps type, from the package root and pptx-vue-viewer/viewer) draws one slide the way SlidesPane draws it, for a host that keeps its own thumbnail strip. It renders from the slide model, so it follows unsaved edits, and it is static: no selection, editing, pointer handlers, focus stops or element ids. A slide with a transition other than Cut shows the transition's name in a small badge in its top-right corner, as the thumbnail does in every binding (Vue's slides pane draws no badge). Its props are slide, templateElements (the slide's layout and master elements, drawn beneath its own; default none), canvasSize and previewWidth (pixels; default the rail thumbnail width; the height follows the deck's aspect ratio), plus the deck props SlidesPane already takes: mediaDataUrls, headerFooter, customProperties, firstSlideNumber, locale, theme and tableStyleMap. Feed both from the same useLoadContent values:

vue
<template>
	<ul class="my-strip">
		<li v-for="slide in slides" :key="slide.id" style="width: 120px">
			<SlideThumbnail
				:slide="slide"
				:template-elements="templateElementsBySlideId[slide.id]"
				:canvas-size="deck.canvasSize.value"
				:preview-width="120"
				:media-data-urls="deck.mediaDataUrls.value"
				:header-footer="deck.headerFooter.value"
				:custom-properties="deck.customProperties.value"
				:first-slide-number="deck.firstSlideNumber.value"
				:theme="deck.theme.value"
				:table-style-map="deck.tableStyleMap.value"
			/>
		</li>
	</ul>
</template>

The thumbnail fills its container's width and is as tall as previewWidth at the deck's aspect ratio, so give the container that width. It needs the same pptx-vue-viewer/styles stylesheet.

Linked pictures and media ​

SlideCanvas, SlidesPane and SlideThumbnail draw a deck's linked web pictures and media only when their linkedContent prop is true; without it they withhold them. To follow PowerPoint's security bar in your own shell, load with getAllowExternalImages: () => true (the deck keeps its links, and saves keep them), keep the consent with useExternalContentConsent (exported from /viewer) and pass its allowed on. Enable Content then only redraws: nothing reloads and undo history is kept.

ts
const deck = useLoadContent(() => props.bytes, { getAllowExternalImages: () => true });
const externalContent = useExternalContentConsent({
	content: () => props.bytes,
	host: () => undefined,
	options: () => ({ trust: { allowExternalContent: false } }),
	drawn: () => [deck.slides.value, deck.templateElementsBySlideId.value, deck.tableStyleMap.value],
});
// <ExternalContentBar v-if="externalContent.barVisible" @enable="externalContent.enable"
//   @close="externalContent.close" />, and :linked-content="externalContent.allowed" on each surface.

useCollaboration ​

useCollaboration manages a Yjs session, presence, cursors, and elected-writer synchronization without the viewer component. See Collaboration for the full guide.

ts
function useCollaboration(options: {
	slides: Ref<PptxSlide[]>;
	onRemoteSlides: (slides: PptxSlide[]) => void;
	userColor?: string;
	canvasWidth?: Ref<number> | number;
	canvasHeight?: Ref<number> | number;
	getSourceBytes?: () => Uint8Array | null;
	getTemplateElements?: () => Record<string, PptxElement[]>;
}): UseCollaborationResult;

The result exposes reactive status, connected, cursors, remotePresences, connectedCount, followedSlideIndex, broadcasterSlideIndex, and the imperative start(config), stop(), retry(), setCursor(x, y), setSelection(ids), setActiveSlide(index), and followUser(clientId).

ts
const collab = useCollaboration({
	slides,
	onRemoteSlides: (next) => (slides.value = next),
});

await collab.start({
	roomId: 'deck-42',
	serverUrl: 'wss://collab.example.com',
	userName: 'Ada',
});

The component's Share and Broadcast dialog lifecycle is wired by the internal useCollaborationWiring composable. It is available from pptx-vue-viewer/internals, not from the stable root or /viewer entries.

Helper functions ​

Alongside the composables, pptx-vue-viewer/viewer exports pure helper functions used by the renderer components: getContainerStyle, getShapeFillStrokeStyle, getTextBlockStyle, getImageSrc, getResolvedShapeClipPath, getResolvedShapeClipPathFor, collectMediaElements, collectImagePaths, buildInitialGuides, plus the audience/presenter content-sharing helpers (isAudienceTab, storeAudienceContent, loadAudienceContent, clearAudienceContent) and useToolbarVisibility.

The stable entry also exports CollaborationCursors, CollaborationStatusIndicator, RemoteSelectionOverlay, and FollowModeBar for custom presence UI. See Collaboration.

Using an internal composable directly ​

If the curated public composables above don't cover what you need, every internal composable is also importable in full from pptx-vue-viewer/internals:

ts
import { useAlignGroup, useAutosave } from 'pptx-vue-viewer/internals';

Internal building blocks

pptx-vue-viewer/internals re-exports the same composables PowerPointViewer.vue composes internally (directly, or via a wiring composable used by a child component), unmodified. They are not covered by semver: signatures and behavior can change, and composables can be renamed or removed, without a major bump. Prefer the props/defineExpose API or the curated pptx-vue-viewer/viewer composables first; reach for internals only for advanced integrations, and pin an exact version if you depend on it.

See the Complete Composables Reference for the full list and Overview for the broader architectural picture.

Released under the Apache-2.0 License.