@diceui/pptx

中文文档
0.4.0发布于 2026/11/06Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 9.9万

用于浏览和编辑浏览器中的PowerPoint演示文稿的可编译原始.

中文使用文档
文档目录10 节
  1. 文档
  2. 安装
  3. 查看器
  4. 编辑器
  5. 构成部分
  6. 钩子
  7. 无控制
  8. 已控制
  9. 他们
  10. 许可证

@diceui/pptx (英语)

用于浏览和编辑浏览器中的PowerPoint演示文稿的可编译原始.

文档

访问 pptx.diceui.com (中文(简体) ) 查看文件全文.

安装

npm install @diceui/pptx

查看器

import { Presentation } from "@diceui/pptx";

export function Viewer({ file }: { file: File }) {
  return (
    <Presentation.Root file={file}>
      <Presentation.Viewport>
        <Presentation.Slide />
      </Presentation.Viewport>
    </Presentation.Root>
  );
}

编辑器

装入 readOnly={false} 添加 Selection 内部 Slide 以允许拖放移动、调整大小、旋转、抓取、内置文本编辑、多选择、marquee选择、复制和粘贴以及键盘快捷键(按住、删除、复制、安排和选入取消/重做):

import { Presentation } from "@diceui/pptx";

export function Editor({ file }: { file: File }) {
  return (
    <Presentation.Root file={file} readOnly={false}>
      <Presentation.Viewport>
        <Presentation.Slide>
          <Presentation.Selection />
        </Presentation.Slide>
      </Presentation.Viewport>
    </Presentation.Root>
  );
}

构成部分

构成部分说明
Presentation.Provider在不渲染DOM的情况下为后代提供商店
Presentation.Root装入文件并创建存储或继承一个 Provider
Presentation.Viewport缩放活动幻灯片以适应的可滚动画布
Presentation.Slide渲染活动幻灯片
Presentation.Selection编辑覆盖( 移动、 调整大小、 旋转、 文本、 撤销/ 重做)
Presentation.SelectionBox每个选定形状的大纲, 握有控点
Presentation.ResizeHandle更改选定形状的手柄大小
Presentation.RotateHandle选定形状的旋转控件
Presentation.SnapGuide在移动或调整坐标时显示导线
Presentation.Marquee橡胶带,用于选择和绘制工具
Presentation.ThumbnailList幻灯片缩略图可滚动列表
Presentation.Loading自定义加载状态槽
Presentation.Error自定义错误的槽状态

所有组成部分都支持a render 用于替换基本元素的道具.

钩子

这些是从最近的 Root 或者说 Provider数字 :

const { presentation, status } = usePresentation();
const { slide, index, next, prev } = useSlide();
const { zoom, setZoom } = useZoom();
const { canUndo, canRedo, isDirty, undo, redo } = useHistory();
const { textStyle, setTextStyle, insertShape, startDrawing } = useSelection();

useSelection 在幻灯片外驱动格式化工具栏。 标记工具栏 data-pptx-keep-selection 因此,它保持选择.

无控制

Root 创建商店。 需要的时候从后人那里得到 load, (中文(简体) ), edit, (中文(简体) ), undo,或 save数字 :

const store = usePresentationStore();
const slideIndex = useSlideIndex(store, slideId);
const revision = useSlideRevision(store, slideId);

已控制

手动创建商店并传递给 Provider数字 :

const store = useCreatePresentationStore();
await store.load(buffer);
await store.edit({ type: "setSolidFill", slideId, nodeId, color: "FF0000" });
const bytes = await store.save();

他们

选择覆盖从 CSS 变量读取其颜色 :

变量默认
--presentation-selection#1a73e8
--presentation-snap-guide#f43f5e
--presentation-snap-guide-width1px
--presentation-rotate-handle-offset20px
--presentation-rotate-cursorcrosshair
:root {
  --presentation-selection: #7c3aed;
}

许可证

阿帕奇2.0 (英语). 见 通知 对第三方的归属.

版本与发布记录

@diceui/pptx 共发布 11 个版本,首次发布于 2026/09/01;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/11/066 天前
0.3.02026/11/056 天前
0.2.22026/11/057 天前
0.2.12026/09/261 个月前
0.2.02026/09/102 个月前
0.1.52026/09/102 个月前

关于 @diceui/pptx 的常见问题

@diceui/pptx 是什么?

用于浏览和编辑浏览器中的PowerPoint演示文稿的可编译原始.

如何安装 @diceui/pptx?

在项目目录运行 npm install @diceui/pptx,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@diceui/pptx 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@diceui/pptx 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@diceui/pptx 可以商用吗?

@diceui/pptx 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@diceui/pptx 的下载量有多少?

根据 npm 官方下载统计,@diceui/pptx 在 2026/10/12 – 2026/11/10 这 30 天内被下载 99,307 次,日均约 3,310 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@diceui/pptx 还在维护吗?

最新版本 0.4.0 发布于 2026/11/06(6 天前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/09/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。