@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-width | 1px |
--presentation-rotate-handle-offset | 20px |
--presentation-rotate-cursor | crosshair |
:root {
--presentation-selection: #7c3aed;
}
许可证
阿帕奇2.0 (英语). 见 通知 对第三方的归属.