@diceui/pptx

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

Composable primitives for viewing and editing PowerPoint presentations in the browser.

原始使用文档
文档目录10 节
  1. Documentation
  2. Install
  3. Viewer
  4. Editor
  5. Components
  6. Hooks
  7. Uncontrolled
  8. Controlled
  9. Theming
  10. License

@diceui/pptx

Composable primitives for viewing and editing PowerPoint presentations in the browser.

Documentation

Visit pptx.diceui.com to view the full documentation.

Install

npm install @diceui/pptx

Viewer

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

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

Editor

Load with readOnly={false} and add Selection inside Slide to enable drag-to-move, resize, rotation, snapping, inline text editing, multi-select, marquee selection, copy and paste, and keyboard shortcuts (nudge, delete, duplicate, arrange, and opt-in undo/redo):

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>
  );
}

Components

ComponentDescription
Presentation.ProviderMakes a store available to descendants without rendering DOM
Presentation.RootLoads a file and creates a store or inherits one from Provider
Presentation.ViewportScrollable canvas that scales the active slide to fit
Presentation.SlideRenders the active slide
Presentation.SelectionEditing overlay (move, resize, rotate, text, undo/redo)
Presentation.SelectionBoxOutline per selected shape, holding the handles
Presentation.ResizeHandleResize handles of a selected shape
Presentation.RotateHandleRotation handle of a selected shape
Presentation.SnapGuideGuides shown while a move or resize snaps
Presentation.MarqueeRubber band for marquee selection and draw tools
Presentation.ThumbnailListScrollable list of slide thumbnails
Presentation.LoadingSlot for custom loading states
Presentation.ErrorSlot for custom error states

All components support a render prop to replace the underlying element.

Hooks

These read from the nearest Root or 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 drives a formatting toolbar outside the slide. Mark the toolbar with data-pptx-keep-selection so pressing it keeps the selection.

Uncontrolled

Root creates the store. Reach it from a descendant when you need load, edit, undo, or save:

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

Controlled

Create the store manually and pass it to Provider:

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

Theming

The selection overlay reads its colors from CSS variables:

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

License

Apache-2.0. See NOTICE for third-party attributions.

版本与发布记录

@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 是什么?

Composable primitives for viewing and editing PowerPoint presentations in the browser.

如何安装 @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 和提交记录判断。