安装
pptx-viewer 的各个包在 npm 上独立发布。按需安装不依赖框架的核心引擎,或与你使用的框架对应的预览组件即可。
Node 版本
编译 TypeScript 和在浏览器外运行这些包需要 Node.js 22.3 或更高版本。
选择你的框架
| 框架 | 包 | 说明 |
|---|---|---|
| React | pptx-react-viewer | 预览、编辑、放映、导出和协作 |
| Vue 3 | pptx-vue-viewer | 与 React 组件使用相同的引擎,功能一致 |
| Angular | pptx-angular-viewer | 与 React 组件使用相同的引擎,功能一致 |
| Svelte 5 | pptx-svelte-viewer | 与 React 组件使用相同的引擎,功能一致 |
| 无框架 | pptx-vanilla-viewer | 使用相同的引擎和原生 DOM,无需框架依赖 |
| 无界面处理(Node / 浏览器) | pptx-viewer-core | 不包含 UI,不依赖框架 |
| AI / MCP 工具 | pptx-viewer-mcp | 74 个 MCP 工具、命令行工具和 Y.Doc 编解码器 |
从 npm 安装
React 组件
React 预览和编辑组件的包名为 pptx-react-viewer。核心引擎已打包在其中,无需单独安装。
npm install pptx-react-viewer react react-dompnpm add pptx-react-viewer react react-domyarn add pptx-react-viewer react react-dombun add pptx-react-viewer react react-dom其他同级依赖
组件还使用 framer-motion、lucide-react、react-icons、jspdf、jszip、fast-xml-parser 和 i18next/react-i18next,请安装所用功能需要的依赖。如果通过 PptxI18nProvider 翻译,请从 pptx-react-viewer/no-i18next 导入:它从不使用也不打包 i18next 和 react-i18next,但由于它们是声明的 peer 依赖,大多数包管理器仍会安装它们,详见不使用 react-i18next。
Vue 3 组件
Vue 3 组件的包名为 pptx-vue-viewer,已包含核心引擎。
npm install pptx-vue-viewer vue vue-i18npnpm add pptx-vue-viewer vue vue-i18nyarn add pptx-vue-viewer vue vue-i18nbun add pptx-vue-viewer vue vue-i18n<script setup lang="ts">
import { PowerPointViewer } from 'pptx-vue-viewer';
import { ref } from 'vue';
const content = ref<ArrayBuffer | null>(null);
</script>
<template>
<PowerPointViewer :content="content" />
</template>Angular 组件
Angular 组件的包名为 pptx-angular-viewer,已包含核心引擎。
npm install pptx-angular-viewer @angular/core @angular/common @angular/platform-browser @ngx-translate/core rxjspnpm add pptx-angular-viewer @angular/core @angular/common @angular/platform-browser @ngx-translate/core rxjsyarn add pptx-angular-viewer @angular/core @angular/common @angular/platform-browser @ngx-translate/core rxjsbun add pptx-angular-viewer @angular/core @angular/common @angular/platform-browser @ngx-translate/core rxjs// app.component.ts (standalone component, no NgModule)
import { Component } from '@angular/core';
import { PowerPointViewerComponent } from 'pptx-angular-viewer';
@Component({
selector: 'app-root',
standalone: true,
imports: [PowerPointViewerComponent],
templateUrl: './app.component.html',
})
export class AppComponent {}<!-- app.component.html -->
<pptx-viewer [content]="content"></pptx-viewer>Svelte 5 组件
Svelte 5 组件的包名为 pptx-svelte-viewer,已包含核心引擎。完整的组件参考见 Svelte 文档。
npm install pptx-svelte-viewer sveltepnpm add pptx-svelte-viewer svelteyarn add pptx-svelte-viewer sveltebun add pptx-svelte-viewer svelte<script lang="ts">
import { PowerPointViewer } from 'pptx-svelte-viewer';
let bytes = $state<Uint8Array | null>(null);
</script>
{#if bytes}
<PowerPointViewer source={bytes} />
{/if}原生 JavaScript 组件(无需框架)
无框架组件的包名为 pptx-vanilla-viewer,已包含核心引擎,没有框架同级依赖。通过一个工厂函数即可使用预览、放映和编辑功能,其中编辑由 editable 选项控制。完整 API 参考见原生 JavaScript 文档。
npm install pptx-vanilla-viewerpnpm add pptx-vanilla-vieweryarn add pptx-vanilla-viewerbun add pptx-vanilla-viewerimport { createPptxViewer } from 'pptx-vanilla-viewer';
const viewer = createPptxViewer(document.getElementById('host')!, {
source: '/decks/quarterly.pptx',
editable: true,
});核心引擎
不依赖框架的核心引擎用于解析、编辑、序列化和转换 PPTX 文件,适合无界面自动化、构建脚本和不需要 UI 的 Node.js 工作流。上面的 UI 组件包均已包含核心引擎,使用它们时无需重复安装。
npm install pptx-viewer-corepnpm add pptx-viewer-coreyarn add pptx-viewer-corebun add pptx-viewer-coreMCP 服务器与工具
基于核心引擎提供 74 个 PPTX 操作工具函数、面向 AI 智能体的 MCP 服务器,以及 Y.Doc 协作编解码器。
npm install pptx-viewer-mcppnpm add pptx-viewer-mcpyarn add pptx-viewer-mcpbun add pptx-viewer-mcp可选同级依赖
React 包的部分功能只有在对应的可选同级依赖存在时才会启用。
| 功能 | 可选同级依赖 | 说明 |
|---|---|---|
| 三维模型(GLB/GLTF) | three | 未安装时,三维元素回退为预览图片。 |
| 实时协作 | yjs、y-websocket | 使用 Yjs CRDT 同步数据并跟踪在线状态。 |
npm install three yjs y-websocketpnpm add three yjs y-websocketyarn add three yjs y-websocketbun add three yjs y-websocket本地开发(克隆 monorepo)
PowerPoint 查看器位于 ooxml monorepo 的 viewers/pptx 目录。该 monorepo 使用 Bun 管理依赖和运行工作区。
# Clone the repository and install every workspace dependency from the root
git clone https://github.com/ChristopherVR/ooxml.git
cd ooxml
bun install
# Build ooxml-core and ooxml-ui first, then work from the viewer
bun run build
bun run --cwd src/ui build
cd viewers/pptx
# Build the viewer packages, then test / type-check
bun run build
bun run test
bun run typecheck注意构建顺序
查看器各包依赖已构建的 ooxml-core 和 ooxml-ui,因此请先在仓库根目录构建它们(如上所示)。在 viewers/pptx 内,各个包按照依赖顺序构建:
core -> shared -> locales -> tools -> react / vue / angular / vanilla / svelte -> cli在 viewers/pptx 中运行 bun run build 会自动处理这一顺序。手动构建单个包(cd packages/<pkg> && bun run build)时,请确保先构建它的依赖。
常用工作区命令
bun run build # Build all packages in dependency order
bun run test # Run vitest across all packages
bun run typecheck # Type-check all packages (needs built packages)
bun run typecheck:fresh # Build the packages, then type-check (clean checkouts)
bun run fmt # Format with oxfmt
bun run lint # Lint with oxlint
bun run demo # Start the React demo dev server (port 4173)
bun run demo:vue # Start the Vue demo dev server (port 4175)
bun run demo:angular # Start the Angular demo dev server (port 4174)
bun run demo:vanilla # Start the Vanilla JS demo dev server (port 4176)
bun run demo:svelte # Start the Svelte demo dev server (port 4177)