跳转到内容

界面自定义 ​

将查看器的 inspectorInitiallyOpen 选项设为 false,即可在启动时关闭属性检查器。面板开关和功能区组启动器仍可打开它。省略该选项则保留绑定的桌面/移动端默认行为;之后对这个初始选项的修改不会重置用户的面板状态。

使用共享的自定义对象隐藏无选中内容时检查器中的单个卡片:

ts
const customization: ViewerCustomization = {
	inspector: { hiddenCards: ['presentation', 'theme', 'themeOverride', 'slideSize'] },
};

卡片 id 为 presentation、theme、themeOverride、slideSize、slideTransition、notesHandout、document、tags、slide、slideBackground 和 templateBackground。每个 id 会在绑定提供该卡片的所有位置将其隐藏。updateCustomization({ inspector: { hiddenCards: [] } }) 可实时恢复这些卡片。卡片可见性按每个查看器独立设置,与检查器的打开和关闭无关。

属性选项卡是一个“格式”窗格,包含为当前选择内容而定的可折叠分节(文本框为“字体”和“段落”,形状为“填充”和“轮廓”,另有“图片”、“表格”、“图表”、“排列”、“大小和位置”等)。使用 inspector.hiddenSections 隐藏分节,使用 inspector.sectionOrder 将分节移至前面:

ts
const customization: ViewerCustomization = {
	inspector: { hiddenSections: ['effects'], sectionOrder: ['sizePosition'] },
};

分节 id 为 slide、font、paragraph、picture、table、chart、smartArt、media、object、fill、outline、effects、arrange、sizePosition、altText 和 action。每种选择类型下展开的分节只在当前会话中记住,不会存储任何内容。

每个绑定都渲染相同的 PowerPoint 风格界面:功能区、“文件”选项卡、“文件 > 选项”(设置)对话框、右键菜单、键盘映射、幻灯片栏、检查器、状态栏以及若干对话框。大多数嵌入场景并不需要全部这些内容。展台不需要任何编辑界面;企业门户希望去掉 AI 助手,并将作者名固定为已登录用户;教学工具则只需要三个标签页的功能区。

这一切都由一个对象 ViewerCustomization 完成,你把它传给查看器,并可在运行时修改:

ts
import type { ViewerCustomization } from 'pptx-react-viewer'; // 或 vue / angular / svelte / vanilla

const customization: ViewerCustomization = {
	ribbon: {
		hiddenTabs: ['draw', 'record'],
		hiddenGroups: ['insert.media'],
		hiddenButtons: ['broadcast', 'home.font.changeCase'],
	},
	options: {
		hiddenPages: ['trust', 'addIns'],
		locked: { 'general.userName': 'Ada Lovelace' },
		defaults: { 'advanced.showGrid': true },
	},
	contextMenu: { hiddenElementCommands: ['save-as-picture'] },
	keyboard: { disabled: ['newSlide'], remap: { duplicate: 'Mod+Shift+D' } },
	hiddenPanels: ['notes'],
	disabledFeatures: ['ai'],
	hiddenDialogs: ['broadcast'],
	hiddenExportFormats: ['video', 'gif'],
	capabilities: { print: false },
	regions: { 'dialog.options': 'acme-settings' }, // 你自己的设置视图
};

该对象、其类型、id 目录和辅助方法在全部五个绑定中完全一致。逻辑只在 ooxml-ui/pptx(src/ui/src/pptx/render/customization/)中存在一份,因此在 React 中可用的自定义在 Svelte 中的行为完全相同。

可配置的内容 ​

下面的一切要么是 customization 的字段(本指南),要么是查看器组件的属性(绑定自己的指南)。自定义字段如下:

你想要字段
隐藏功能区标签页、组、控件和工具栏按钮ribbon.hiddenTabs, ribbon.hiddenGroups, ribbon.hiddenButtons
添加你自己的功能区标签页ribbonAddIns 属性(见下文)
隐藏、锁定“文件 > 选项”的页面、分区和设置,或为其设置默认值options.hiddenPages, options.hiddenSections, options.hiddenSettings, options.locked, options.defaults
完全移除“文件 > 选项”hiddenDialogs: ['options']
用你自己的设置视图替换“文件 > 选项”regions['dialog.options']
隐藏“文件”选项卡的页面和卡片backstage.hiddenPages, backstage.hiddenCards
添加你自己的“文件”选项卡页面backstage.extraPages
替换“文件”选项卡的某个页面regions['backstage.<page>']
隐藏或添加右键菜单命令contextMenu.*
禁用或重映射快捷键keyboard.*
隐藏面板(检查器、幻灯片栏、备注、状态栏、标题栏、选择窗格、查找和替换等)hiddenPanels
替换检查器、幻灯片栏、备注或状态栏regions.inspector, regions.slidesPane, regions.notes, regions.statusBar
隐藏检查器卡片inspector.hiddenCards
关闭 AI、协作、批注、放映模式、编辑顶点disabledFeatures
移除对话框及所有打开它们的入口hiddenDialogs
替换共享、广播或打印对话框的主体regions['dialog.share'], regions['dialog.broadcast'], regions['dialog.print']
移除导出格式hiddenExportFormats
移除绘图工具hiddenDrawingTools
将演示文稿设为只读,或禁止导出、打印、共享、复制、放映或批注capabilities

概念 ​

隐藏、锁定、默认值 ​

对“文件 > 选项”中的某个设置可以做三种不同的事,它们可以组合使用:

你想要使用
用户永远看不到该设置options.hiddenSettings: ['general.userInitials']
该设置有固定值,用户无法更改options.locked: { 'general.userName': 'Ada' }(以只读渲染)
两者兼有:固定值且完全没有控件将该 id 同时放入 locked 和 hiddenSettings
不同的起始值,但用户仍可更改options.defaults: { 'advanced.showGrid': true }
  • 锁定的值会立即强制写入选项存储,此后无论来自哪条路径(对话框、写入同一选项的功能区开关、重置),对它的写入都会被忽略。控件以禁用状态渲染,并带有工具提示“此设置由您的组织管理”。锁定的值绝不会写入用户保存的偏好,因此移除锁定后,用户会恢复自己的值。
  • 默认值会替换尚未保存自己选择的用户的内置默认值,并成为“重置”所返回的值。宿主默认值同样不会被持久化:在后续版本中更改默认值,所有从未改动该设置的用户都会跟随,而保留了自己选择的用户则不受影响。

派生规则 ​

有些 id 会同时关闭多个入口,因此你不必列出每个打开某个对话框的按钮。这些规则在共享的解析器中统一应用一次:

  • hiddenDialogs: ['share'] 会移除共享按钮、“文件 > 共享”页面和共享卡片。['print'] 移除“文件 > 打印”和打印卡片;['export'] 移除导出按钮和“文件 > 导出”;['options'] 移除“文件 > 选项”。
  • disabledFeatures: ['collaboration'] 隐藏共享和广播对话框(因此上述针对它们的内容也一并生效)。
  • disabledFeatures: ['ai'] 移除 AI 开关和面板、“询问 AI” / “用 AI 修复”右键菜单项以及“文件 > 选项”的 AI 页面,即使宿主传入了 ai 配置也是如此。
  • disabledFeatures: ['comments'] 移除“添加批注”右键菜单项以及“插入”和“审阅”选项卡的批注组。
  • disabledFeatures: ['presentMode'] 移除“幻灯片放映”功能区标签页以及 F5 / Shift+F5 开始放映快捷键。
  • hiddenExportFormats 移除“文件 > 导出”中的单个卡片;六个全部隐藏时,导出按钮和页面也会被移除。
  • 隐藏面板会移除打开它的功能区控件和快捷键:findReplace 会连带移除“开始 > 查找 / 替换”和 Ctrl+F / Ctrl+H,selectionPane 移除“视图 > 选择窗格”,accessibilityPane 移除“审阅 > 检查辅助功能”和“帮助 > 辅助功能检查器”,comparePane 移除“审阅 > 比较”,notes 移除备注按钮。
  • 隐藏对话框对其入口同样如此:hyperlink 移除“插入 > 链接”、链接菜单项和 Ctrl+K;equation 移除“插入 > 公式”;pasteSpecial 移除其快捷键;slideTemplates 移除“开始 > 新建幻灯片”中的幻灯片模板项;passwordProtection 和 signatures 移除其“文件 > 信息”卡片。
  • capabilities 会展开为上面的列表(参见能力)。
  • 失去所有控件的选项分区会被移除;失去所有分区的选项页面也会被移除。当某组的第一项被隐藏时,菜单会自行修复分隔线。

属性与命令式 API ​

将该对象作为 customization 属性(输入、选项)传入以预先设置,并使用组件句柄上的命令式辅助方法在查看器运行时修改它。每次更改都会立即重新渲染受影响的界面,无需重新挂载。

  • 属性是替换:当你给查看器一个新的 customization 对象时,它就成为完整的自定义,之前通过辅助方法所做的修改都会被丢弃。除非你有意替换,否则请保持该对象稳定(用 memo 缓存,或保存在状态中)。
  • 辅助方法是合并:hideRibbonTab('draw') 会向现有内容中添加一个 id。updateCustomization(patch) 合并一层深度(每个分区逐字段合并;你传入的列表会替换该列表)。

向后兼容:hiddenActions 和自定义功能区 ​

较早的 hiddenActions 属性仍然有效。它会与 ribbon.hiddenTabs 和 ribbon.hiddenButtons 取并集,因此你可以按自己的节奏迁移。用户自己在“文件 > 选项 > 自定义功能区”中的选择会在其上再取并集:只有宿主和用户都没有隐藏的标签页才会显示。

功能区组和控件 ​

在标签页层级之下,每个功能区组和组内的每个控件都在一个共享目录中拥有稳定的 id:组为 <tab>.<group>,控件为 <tab>.<group>.<control>,按 PowerPoint 自身的标题命名(home.font、home.font.bold、insert.media.media、view.show.ruler)。因选择而出现的上下文标签页(shapeFormat、pictureFormat、tableDesign、tableLayout、chartDesign、chartFormat、smartArtDesign)以同样方式寻址,其标签页 id 可用于 ribbon.hiddenTabs。

ts
const customization: ViewerCustomization = {
	ribbon: {
		hiddenGroups: ['home.editing', 'insert.media'],
		hiddenButtons: ['home.font.changeCase', 'home.paragraph.columns', 'mergeShapes'],
		hiddenTabs: ['chartDesign'],
	},
};

ribbon.hiddenButtons 同时接受两种 id:较早的顶层工具栏按钮(share、zoom 等)和目录中的功能区控件。mergeShapes / home.arrange.mergeShapes 以及 crop / home.arrange.crop 指向同一个控件,因此两种写法都能将其隐藏。两种裁剪写法也会隐藏第二个裁剪入口 pictureFormat.size.crop(图片格式 > 大小);指定 pictureFormat.size 或 pictureFormat.size.crop 则只隐藏那一个。完整列表见下方的参考。

每个绑定都会为其功能区标记添加 data-ribbon-group 和 data-ribbon-control,并渲染一份由共享模型根据解析后的自定义生成、限定在该查看器范围内(data-pptx-ribbon-scope)的样式表,因此隐藏的组或控件在全部五个绑定中都以相同方式从布局和无障碍树中移除。这些属性同样是你自己的样式或测试的稳定挂钩。

宿主功能区标签页(ribbonAddIns) ​

自定义是移除内容;ribbonAddIns 则像 Office 加载项一样,在“帮助”之后添加你自己的标签页。它是每个绑定上的独立属性(React、Svelte 和 vanilla 选项中为 ribbonAddIns,Vue 中为 :ribbon-add-ins,Angular 中为 [ribbonAddIns];vanilla 实例还有 setRibbonAddIns(tabs)),并接受与 Word、Excel 和 Visio 编辑器相同的普通描述符:

tsx
const tabs = [
	{
		id: 'reports',
		label: 'Reports',
		groups: [
			{
				label: 'Export',
				commands: [
					{ id: 'export', label: 'Export', icon: 'save', run: () => exportReport() },
					{ id: 'options', label: 'Options', size: 'small' },
				],
			},
		],
	},
];

<PowerPointViewer content={bytes} ribbonAddIns={tabs} />;

选中某个命令后,会运行其 run 回调,然后从查看器内部派发一个冒泡的 office-ribbon-add-in DOM 事件(detail: { tab, command }),因此在查看器容器上放一个监听器即可听到所有宿主命令。它没有对应的各绑定回调属性。

  • 标签页不能使用内置标签页或上下文标签页的 id;这样的标签页会被忽略。label 是你自己的文本,不会被翻译。
  • size: 'small' 的命令以三个一列排布。PowerPoint 功能区没有宿主命令的下拉菜单,因此带 items 的命令会被绘制为其各项,即以父项标签为标题的小命令。
  • 再次传入相等的描述符(框架每次渲染都会这样做)会保留该标签页的控件,只替换回调。移除正在显示的标签页会使功能区返回“开始”。
  • 宿主标签页仅显示在桌面功能区中;手机工具栏及其菜单面板不会列出它们。
  • hiddenActions 和 ribbon.hiddenTabs 不适用于宿主标签页:要隐藏某个标签页,只需将其从列表中去掉。

命令式 API ​

每个绑定都在其组件句柄上公开这些方法(React ref、Vue 模板 ref、Angular 组件实例、Svelte bind:this、Vanilla 实例):

方法作用
getCustomization()当前的 ViewerCustomization(快照;请勿修改它)。
setCustomization(c)替换整个自定义。
updateCustomization(patch)合并部分自定义。
resetCustomization()恢复默认界面。
hideRibbonTab(id) / showRibbonTab(id)切换一个功能区标签页(上下文标签页 id 会使该标签页不再出现)。
hideRibbonGroup(id) / showRibbonGroup(id)切换标签页内的一个组(home.font)。
hideToolbarButton(id) / showToolbarButton(id)切换一个工具栏按钮、控件簇或功能区控件。
hideRibbonControl(id) / showRibbonControl(id)切换一个功能区控件(home.font.bold)。
hideOptionsPage(id) / showOptionsPage(id)切换“文件 > 选项”的一个页面。
hideOptionsSection(id) / showOptionsSection(id)切换选项页面的一个分区。
hideSetting(id) / showSetting(id)切换一个设置。
lockSetting(id, value, hidden?)将设置固定为 value;hidden: true 同时移除其控件。
unlockSetting(id)移除锁定。
setSettingDefault(id, value)设置宿主默认值(undefined 表示清除)。
hideBackstagePage(id) / showBackstagePage(id)切换“文件”选项卡的一个页面。
hideBackstageCard(id) / showBackstageCard(id)切换“文件”选项卡的一个操作卡片。
hideContextMenuCommand(id) / showContextMenuCommand(id)切换一个元素右键菜单项。
hideCanvasContextMenuCommand(id) / showCanvasContextMenuCommand(id)切换一个空白画布右键菜单项。
disableShortcut(id) / enableShortcut(id)切换一个编辑器快捷键。
remapShortcut(id, chords)将命令移到新的组合键;undefined 恢复内置组合键。
setPanelVisible(id, visible)显示或隐藏一个界面区域。
setFeatureEnabled(id, enabled)开启或关闭一个功能领域。
setDialogAvailable(id, available)允许或移除一个对话框及其入口。
setCapability(id, allowed)切换一项能力;undefined 恢复默认值。
setRegion(id, renderer)用你的界面替换一个区域;undefined 恢复内置界面。
addBackstagePage(page) / removeBackstagePage(id)添加(或按 id 替换)和移除宿主“文件”选项卡页面。

快捷键组合 ​

组合键的形式为 Modifier+Modifier+Key:修饰键为 Mod(Windows 和 Linux 上是 Ctrl,macOS 上是 Cmd)、Ctrl、Meta、Alt 和 Shift;键为 KeyboardEvent.key 值,例如 D、Delete、ArrowLeft 或 F2(+ 写作 Plus)。字母不区分大小写。被重映射的命令不再响应其内置组合键。重映射后的组合键保留所有内置保护:在只读查看器中、放映期间、用户在文本框中输入时,或(对于选区命令)没有选中任何内容时,它们都不会触发。nudge 和 escape 可以禁用,但不能重映射。

各绑定的用法 ​

tsx
import { PowerPointViewer } from 'pptx-react-viewer';
import type { PowerPointViewerHandle, ViewerCustomization } from 'pptx-react-viewer';
import { useMemo, useRef } from 'react';

export function Deck({ bytes }: { bytes: Uint8Array }) {
	const viewer = useRef<PowerPointViewerHandle>(null);
	// 使用 memo 缓存:每次渲染都生成新对象会替换辅助方法所做的修改。
	const customization = useMemo<ViewerCustomization>(
		() => ({ ribbon: { hiddenTabs: ['draw'] }, disabledFeatures: ['ai'] }),
		[],
	);
	return (
		<>
			<button onClick={() => viewer.current?.hideRibbonTab('insert')}>Hide Insert</button>
			<PowerPointViewer ref={viewer} content={bytes} canEdit customization={customization} />
		</>
	);
}
vue
<script setup lang="ts">
import { PowerPointViewer } from 'pptx-vue-viewer';
import type { PowerPointViewerExpose, ViewerCustomization } from 'pptx-vue-viewer';
import { ref } from 'vue';

defineProps<{ bytes: Uint8Array }>();
const viewer = ref<PowerPointViewerExpose | null>(null);
const customization: ViewerCustomization = {
	ribbon: { hiddenTabs: ['draw'] },
	disabledFeatures: ['ai'],
};
</script>

<template>
	<button @click="viewer?.hideRibbonTab('insert')">Hide Insert</button>
	<PowerPointViewer ref="viewer" :content="bytes" can-edit :customization="customization" />
</template>
ts
import { Component, viewChild } from '@angular/core';
import { PowerPointViewerComponent } from 'pptx-angular-viewer';
import type { ViewerCustomization } from 'pptx-angular-viewer';

@Component({
	selector: 'app-deck',
	imports: [PowerPointViewerComponent],
	template: `
		<button (click)="viewer()?.hideRibbonTab('insert')">Hide Insert</button>
		<pptx-viewer #viewer [content]="bytes" [canEdit]="true" [customization]="customization" />
	`,
})
export class DeckComponent {
	bytes: Uint8Array | null = null;
	readonly viewer = viewChild<PowerPointViewerComponent>('viewer');
	readonly customization: ViewerCustomization = {
		ribbon: { hiddenTabs: ['draw'] },
		disabledFeatures: ['ai'],
	};
}
svelte
<script lang="ts">
	import { PowerPointViewer } from 'pptx-svelte-viewer';
	import type { ViewerCustomization } from 'pptx-svelte-viewer';

	let { bytes }: { bytes: Uint8Array } = $props();
	let viewer: ReturnType<typeof PowerPointViewer> | undefined = $state();
	const customization: ViewerCustomization = {
		ribbon: { hiddenTabs: ['draw'] },
		disabledFeatures: ['ai'],
	};
</script>

<button onclick={() => viewer?.hideRibbonTab('insert')}>Hide Insert</button>
<PowerPointViewer bind:this={viewer} source={bytes} editable {customization} />
ts
import { createPptxViewer } from 'pptx-vanilla-viewer';
import type { ViewerCustomization } from 'pptx-vanilla-viewer';

const customization: ViewerCustomization = {
	ribbon: { hiddenTabs: ['draw'] },
	disabledFeatures: ['ai'],
};
const viewer = createPptxViewer(document.getElementById('deck')!, {
	source: bytes,
	editable: true,
	customization,
});

document.getElementById('hide-insert')!.addEventListener('click', () => {
	viewer.hideRibbonTab('insert');
});

用你自己的界面替换区域 ​

隐藏是移除一个区域;替换则保留其在布局中的位置,并把这个位置交给你。查看器会在内置界面原本所在之处(检查器所在的列、“选项”对话框的主体、“文件”选项卡的某个页面)渲染一个空容器,由你用任意框架或不用框架来填充。将渲染器放在 regions 下:

ts
const customization: ViewerCustomization = {
	regions: {
		'dialog.options': 'acme-settings', // 你注册的自定义元素
		inspector: (container, context) => {
			const view = new AcmeInspector(container, context.viewer);
			view.show(context.selectedElementIds);
			return {
				update: (next) => view.show(next.selectedElementIds),
				destroy: () => view.dispose(),
			};
		},
	},
};

区域 ​

区域你替换的内容查看器保留的内容
inspector检查器窗格其所在列、宽度、调整手柄、打开/关闭状态和移动端面板
slidesPane幻灯片缩略图栏其宽度和折叠状态
notes演讲者备注面板其高度、调整手柄和折叠状态
statusBar状态栏其在画布下方的行
dialog.options“文件 > 选项”(设置对话框)的主体对话框外框:背景遮罩、标题、关闭按钮、Escape
dialog.share, dialog.broadcast, dialog.print该对话框的主体对话框外框
backstage.<page>“文件”选项卡某个页面的主体(backstage.info、backstage.export 等)“文件”选项卡导航、标题和返回按钮

完整列表见参考。隐藏优先于替换:同时被隐藏的区域(通过 hiddenPanels、hiddenDialogs、backstage.hiddenPages 或某项能力)根本不会被渲染。

渲染器形式 ​

区域接受三种形式中的任意一种。选择适合你技术栈的即可:

  • 挂载函数 (container, context) => cleanup | handle | void。它在区域出现时运行一次。返回一个清理函数,或返回句柄 { update?(context), destroy?() } 以同时接收上下文变化。
  • 自定义元素标签,以字符串形式给出('acme-settings')。查看器创建该元素,将其追加到容器中并赋值其 context 属性,此后每当上下文变化都会再次赋值 context。请在区域首次出现之前自行注册该元素。
  • 自定义元素规格 { element: 'acme-settings', properties: { tenant } }。与上面相同,只是 properties 会在元素挂接之前赋值一次。再次传入相等的规格(相同标签、相同属性值)会保留该元素。

只有当渲染器改变时,查看器才会重新挂载区域:不同的函数、不同的标签或不同的 properties。请只定义一次挂载函数(放在渲染函数之外,或使用 memo 缓存),就像对 customization 对象的其余部分那样。

抛出异常的渲染器会被捕获并记录;它绝不会使查看器崩溃。

区域何时挂载 ​

被替换的区域会在内置界面出现的位置和时机出现,并且查看器保留该槽位自身的行为:

  • 可见性规则沿用。 只读的演示文稿没有检查器,因此也没有宿主检查器;内置界面仅在桌面端显示或仅在编辑时显示的区域,遵循同样的规则。
  • 折叠是隐藏,而不是卸载。 折叠的备注或关闭的检查器会让你的渲染器保持挂载并隐藏,因此其状态得以保留;只有当该区域不再被替换、其渲染器改变或查看器被销毁时,它才会被销毁。
  • 尺寸仍由查看器管理。 检查器保留其宽度和调整手柄,备注面板保留其高度、调整手柄和折叠开关。你的内容填满容器(width 和 height 均为 100%)。
  • 手机布局会在容纳检查器、备注和幻灯片栏的底部面板内替换相同的内容。
  • 对话框上的 close() 行为与对话框的关闭(X)按钮一致:它会关闭对话框,并保留通过 setOption 所做的所有更改。

每个容器都带有 data-pptx-region="<id>" 属性,这是你自己的 CSS 和测试的稳定挂钩。

上下文 ​

每个渲染器都会收到一个 ViewerRegionContext:

字段含义
region区域 id(inspector、dialog.options、backstage.host.<id> 等)
viewer查看器的命令式 API,与组件句柄是同一个对象:getSlides()、getElementById()、updateElement()、goTo()、undo()、自定义辅助方法等
mode'edit'、'preview'、'present' 或 'master'
canEdit演示文稿只读时为 false(edit 属性、capabilities.edit 或保护)
activeSlideIndex, slideCount当前幻灯片(从零开始)和幻灯片数量
selectedElementIds当前幻灯片上选中的元素(为空:未选中任何内容)
locale当前界面区域设置
close()关闭对话框、离开“文件”选项卡或关闭检查器;对状态栏、备注和幻灯片窗格不执行任何操作

dialog.options 还会添加“文件 > 选项”模型,使宿主设置视图能够读取和写入与内置对话框相同的设置:

字段含义
options当前的 ViewerOptions(已应用宿主锁定)
setOption(id, value)按 <group>.<key> id(advanced.showGrid)更改一个设置;锁定的设置会忽略
resetOptions()恢复为宿主默认值或内置默认值

close、setOption 和 resetOptions 是稳定的:保留旧的上下文并在稍后调用它们是安全的。

每个绑定都在共享的 <pptx-ui-options-dialog> 元素中显示“文件 > 选项”。被替换的主体会被放入其槽位(slot="body"),位于页面自己的 DOM 中而不是该元素的 shadow 树里,因此你的页面样式可以作用到它。你的视图自行确定尺寸;当它比窗口高时,对话框会让它滚动。关闭按钮和 Escape 会保留你通过 setOption 所做的修改,与内置对话框相同。

挂载框架组件 ​

挂载函数与框架无关,因此区域可以容纳任何框架的组件,包括与查看器绑定不同的框架:

tsx
import type { ViewerRegionMount } from 'ooxml-ui/pptx';
import { createRoot } from 'react-dom/client';

const settings: ViewerRegionMount = (container, context) => {
	const root = createRoot(container);
	root.render(<AcmeSettings context={context} />);
	return {
		update: (next) => root.render(<AcmeSettings context={next} />),
		destroy: () => root.unmount(),
	};
};

<PowerPointViewer content={bytes} customization={{ regions: { 'dialog.options': settings } }} />;
ts
import type { ViewerRegionContext, ViewerRegionMount } from 'ooxml-ui/pptx';
import { createApp, shallowRef } from 'vue';

const settings: ViewerRegionMount = (container, context) => {
	const current = shallowRef<ViewerRegionContext>(context);
	const app = createApp(AcmeSettings, { context: current });
	app.mount(container);
	return { update: (next) => (current.value = next), destroy: () => app.unmount() };
};
ts
import { createComponent, type ApplicationRef, type EnvironmentInjector } from '@angular/core';
import type { ViewerRegionMount } from 'pptx-angular-viewer';

function settingsRegion(app: ApplicationRef, injector: EnvironmentInjector): ViewerRegionMount {
	return (container, context) => {
		const ref = createComponent(AcmeSettingsComponent, {
			environmentInjector: injector,
			hostElement: container.appendChild(document.createElement('acme-settings-host')),
		});
		ref.setInput('context', context);
		app.attachView(ref.hostView);
		return {
			update: (next) => ref.setInput('context', next),
			destroy: () => {
				app.detachView(ref.hostView);
				ref.destroy();
			},
		};
	};
}
ts
import type { ViewerRegionMount } from 'ooxml-ui/pptx';
// settings-region.svelte.ts(runes 需要 .svelte.ts 模块)
import { mount, unmount } from 'svelte';

const settings: ViewerRegionMount = (container, context) => {
	const props = $state({ context });
	const component = mount(AcmeSettings, { target: container, props });
	return { update: (next) => (props.context = next), destroy: () => unmount(component) };
};
ts
import type { ViewerRegionMount, ViewerSettingsRegionContext } from 'ooxml-ui/pptx';

const settings: ViewerRegionMount = (container, context) => {
	// `dialog.options` 在基础上下文之上还会收到设置模型。
	const { options, setOption } = context as ViewerSettingsRegionContext;
	const grid = document.createElement('label');
	const box = document.createElement('input');
	box.type = 'checkbox';
	box.checked = options.advanced.showGrid;
	box.addEventListener('change', () => setOption('advanced.showGrid', box.checked));
	grid.append(box, ' Show gridlines');
	container.append(grid);
};

你自己的“文件”选项卡页面 ​

backstage.extraPages 会在“文件”选项卡中其所属分组的内置页面之后添加页面。每个页面的主体是一个区域(backstage.host.<id>),接受相同的渲染器形式:

ts
const customization: ViewerCustomization = {
	backstage: {
		extraPages: [
			{ id: 'policies', label: 'Policies', render: 'acme-policies' },
			{ id: 'about', label: 'About Acme', group: 'footer', render: mountAbout },
		],
	},
};

label 是你自己的文本,不会被翻译。页面 id 在你的页面之间必须唯一;重复的 id 会被忽略。addBackstagePage(page) 和 removeBackstagePage(id) 可在运行时更改它们。

能力 ​

capabilities 声明用户可以做什么,每项能力一个开关,并移除通向被关闭内容的所有路径:按钮、菜单项、快捷键、“文件”页面和卡片。省略某个键(或为 true)则由查看器自身的规则决定。

ts
const portal: ViewerCustomization = {
	capabilities: { edit: false, export: false, print: false, copy: false },
};
能力false 的含义
edit演示文稿以只读方式打开,无论编辑属性(canEdit、editable)如何设置。
export没有“文件 > 导出”页面、导出按钮或导出卡片。
print没有打印对话框、“文件 > 打印”页面或打印卡片。
share没有共享或广播对话框、按钮、页面或卡片。
copy没有复制、剪切或另存为图片(菜单、功能区、快捷键),也没有复制为图像。
present没有“幻灯片放映”标签页或 F5 / Shift+F5(presentMode 功能)。
comment没有“添加批注”项,“插入”和“审阅”中也没有批注组(comments 功能)。

能力是界面策略,而不是文档保护。使用浏览器开发者工具的用户仍然拥有你交给查看器的字节;如果某个演示文稿不得被复制或导出,就不要把它发送到浏览器。

setCapability(id, allowed) 可在运行时更改其中一项;undefined 恢复默认值。

示例 ​

展台:没有编辑界面的查看器 ​

只读已经隐藏了编辑命令;这里还会移除展台访客可能误入的所有内容。

ts
const kiosk: ViewerCustomization = {
	ribbon: {
		hiddenTabs: [
			'file',
			'home',
			'insert',
			'draw',
			'design',
			'transitions',
			'animations',
			'record',
			'review',
			'view',
			'help',
		],
		hiddenButtons: ['share', 'broadcast', 'export', 'undo', 'redo', 'record'],
	},
	hiddenPanels: ['inspector', 'notes', 'quickAccessToolbar'],
	disabledFeatures: ['ai', 'collaboration', 'comments'],
	hiddenDialogs: ['options', 'print', 'export'],
	contextMenu: { disableElementMenu: true, disableCanvasMenu: true },
	keyboard: { disableAll: true },
};

保留 slideShow(以及 navigation 和 fullscreen 按钮)可见,访客仍可放映。

隐藏用户不需要的设置页面 ​

ts
const settings: ViewerCustomization = {
	options: {
		hiddenPages: ['proofing', 'addIns', 'trust', 'quickAccess', 'ribbon'],
		hiddenSections: ['general.startup', 'save.cache', 'advanced.print'],
		hiddenSettings: ['advanced.disableHardwareAcceleration'],
	},
};

要完全移除“文件 > 选项”,请使用 hiddenDialogs: ['options']。

固定用户身份、区域设置和主题 ​

作者名来自已登录用户,不得被编辑:

ts
viewer.lockSetting('general.userName', currentUser.displayName);
viewer.lockSetting('general.userInitials', currentUser.initials, true); // 锁定并隐藏

区域设置和主题是宿主属性,而不是“选项”中的设置。请通过你所用绑定的区域设置和主题属性来固定它们(defaultLocale / locale、theme / defaultThemeKey,参见本地化和主题指南),然后移除选择器:

ts
const pinned: ViewerCustomization = {
	options: {
		hiddenPages: ['language'], // 显示语言选择器
		hiddenSections: ['general.appearance'], // 查看器主题选择器
	},
};

移除 AI 和协作 ​

ts
const noCloud: ViewerCustomization = { disabledFeatures: ['ai', 'collaboration'] };

禁用 ai 后,即使传入了 ai 配置,助手也保持关闭,这样同一个构建就可以发布给有和没有该附加组件的租户:

ts
viewer.setFeatureEnabled('ai', tenant.hasAiAddOn);

将功能区精简为最小集合 ​

ts
import { RIBBON_TAB_IDS } from 'pptx-react-viewer';

const keep = new Set(['file', 'home', 'insert']);
const minimal: ViewerCustomization = {
	ribbon: {
		hiddenTabs: RIBBON_TAB_IDS.filter((id) => !keep.has(id)),
		hiddenButtons: ['broadcast', 'record'],
	},
};

公司快捷键 ​

ts
const keys: ViewerCustomization = {
	keyboard: {
		disabled: ['newSlide', 'toggleShortcuts'],
		remap: { duplicate: 'Mod+Shift+D', group: ['Mod+G', 'Alt+G'] },
	},
};

你自己的设置视图 ​

保留查看器“选项”对话框的外框,但显示你自己的设置,读写同一个模型:

ts
customElements.define(
	'acme-settings',
	class extends HTMLElement {
		set context(context: ViewerSettingsRegionContext) {
			this.textContent = '';
			const grid = document.createElement('input');
			grid.type = 'checkbox';
			grid.checked = context.options.advanced.showGrid;
			grid.onchange = () => context.setOption('advanced.showGrid', grid.checked);
			const done = document.createElement('button');
			done.textContent = 'Done';
			done.onclick = () => context.close();
			this.append(grid, done);
		}
	},
);

const customization: ViewerCustomization = { regions: { 'dialog.options': 'acme-settings' } };

若要改为将用户引导到你应用自己的设置页面,请隐藏该对话框(hiddenDialogs: ['options']),并添加一个导航到那里的“文件”选项卡页面或功能区加载项命令。

只读门户 ​

ts
const portal: ViewerCustomization = {
	capabilities: { edit: false, export: false, print: false, share: false, copy: false },
	disabledFeatures: ['ai'],
	hiddenPanels: ['inspector'],
};

构建你自己的管理界面 ​

每个 id 列表都与类型一起以运行时数组的形式导出:RIBBON_TAB_IDS、TOOLBAR_BUTTON_IDS、OPTIONS_PAGE_IDS、OPTIONS_SECTION_IDS、OPTIONS_SETTING_IDS、BACKSTAGE_PAGE_IDS、BACKSTAGE_CARD_IDS、ELEMENT_CONTEXT_MENU_COMMAND_IDS、CANVAS_CONTEXT_MENU_COMMAND_IDS、EDITOR_SHORTCUT_ACTION_IDS、VIEWER_PANEL_IDS、VIEWER_FEATURE_IDS、VIEWER_DIALOG_IDS、VIEWER_EXPORT_FORMAT_IDS。VIEWER_CAPABILITY_IDS 和 VIEWER_REGION_IDS 从 ooxml-ui/pptx 导出。用它们渲染复选框,按租户保存得到的对象,并通过 setCustomization 回传。

目前尚不可自定义的内容 ​

  • 下拉菜单或库内的控件(项目符号库中的单个条目、一个形状样式图块)无法单独寻址;请改为隐藏打开该菜单的控件。
  • 放映、幻灯片浏览和演示者视图的键盘映射。 keyboard 只涵盖编辑器键盘映射。它唯一影响的放映键是 F5 / Shift+F5,通过 presentMode 功能实现。
  • 键盘快捷键参考(? 浮层和“选项 > 自定义功能区 > 键盘快捷键”)列出的是内置组合键,而不是你的重映射。如果这很重要,请用 keyboard.disabled: ['toggleShortcuts'] 和 options.hiddenSections: ['ribbon.shortcutReference'] 将其隐藏。
  • 检查器分区和幻灯片栏自身的右键菜单无法单独寻址;请用 hiddenPanels 隐藏整个区域,或用 regions.inspector 替换整个检查器。
  • 可替换的区域是区域下列出的那些。功能区、标题栏、快速访问栏和其他对话框可以隐藏但不能替换;请改用 ribbonAddIns 添加你自己的功能区标签页。
  • 框架原生插槽(React render props、Vue 插槽、Angular 模板、Svelte 代码片段)不予提供;每个绑定都接受相同的挂载函数或自定义元素,它们可以渲染任何框架的组件(参见挂载框架组件)。
  • 移动端布局遵循功能区、菜单、对话框和功能的自定义,但移动端底部面板没有自己的面板 id,并且某些移动端底栏按钮(幻灯片、备注、格式)在其面板被隐藏后仍然可见(点按它们不会有任何反应)。
  • 用户添加的快速访问命令(例如打印)在其对话框被移除后仍留在栏中;它们是失效而非隐藏。
  • presentMode 移除“幻灯片放映”标签页和 F5 / Shift+F5,但不会移除所有次要的“放映”入口(例如某些绑定中视图切换器的放映选项)。
  • Vanilla 没有 update(options),因此它的 customization 选项只是初始值;请使用 setCustomization 和其他辅助方法在运行时更改。更改会重建界面(与 setLocale 相同),这会使功能区回到第一个标签页。
  • React 的无头 useViewerBuildingBlocks 组合不接受 customization;请使用 PowerPointViewer 组件。

参考 ​

由共享的 id 目录生成(bun run docs:customization);如果此处缺少某个 id,单元测试会失败。

Ribbon tabs (ribbon.hiddenTabs) ​

IdTab
fileFile
homeHome
insertInsert
drawDraw
designDesign
transitionsTransitions
animationsAnimations
slideShowSlide Show
recordRecord
reviewReview
viewView
helpHelp
shapeFormatShape Format
pictureFormatPicture Format
tableDesignTable Design
tableLayoutTable Layout
chartDesignChart Design
chartFormatChart Format
smartArtDesignSmartArt Design

Ribbon groups (ribbon.hiddenGroups) ​

IdGroup
home.clipboardClipboard
home.slidesSlides
home.fontFont
home.paragraphParagraph
home.drawingDrawing
home.arrangeArrange
home.editingEditing
insert.slidesSlides
insert.tablesTables
insert.imagesImages
insert.cameraCamera
insert.illustrationsIllustrations
insert.formsForms
insert.addInsAdd-ins
insert.linksLinks
insert.commentsComments
insert.textText
insert.symbolsSymbols
insert.mediaMedia
draw.toolsDrawing Tools
draw.convertConvert
design.themesThemes
design.variantsVariants
design.customizeCustomize
design.designerDesigner
transitions.previewPreview
transitions.transitionToThisSlideTransition to This Slide
transitions.timingTiming
animations.previewPreview
animations.animationAnimation
animations.motionPathMotion Paths
animations.advancedAnimationAdvanced Animation
animations.timingTiming
slideShow.startSlideShowStart Slide Show
slideShow.presentPresent
slideShow.setUpSet Up
slideShow.captionsCaptions & Subtitles
record.cameraCamera
record.recordRecord
record.manageManage
record.helpHelp
review.proofingProofing
review.accessibilityAccessibility
review.languageLanguage
review.commentsComments
review.compareCompare
review.protectProtect
review.inkInk
view.presentationViewsPresentation Views
view.masterViewsMaster Views
view.showShow
view.zoomZoom
view.windowWindow
help.helpHelp
shapeFormat.shapeStylesShape Styles
shapeFormat.wordArtStylesWordArt Styles
pictureFormat.adjustAdjust
pictureFormat.pictureStylesPicture Styles
pictureFormat.sizeSize
tableDesign.tableStylesTable Styles
tableLayout.tableTable
tableLayout.rowsColumnsRows & Columns
tableLayout.mergeMerge
tableLayout.cellSizeCell Size
tableLayout.alignmentAlignment
tableLayout.tableSizeTable Size
tableLayout.arrangeArrange
chartDesign.chartLayoutsChart Layouts
chartDesign.chartStylesChart Styles
chartFormat.currentSelectionCurrent Selection
smartArtDesign.createGraphicCreate Graphic
smartArtDesign.layoutsLayouts
smartArtDesign.smartArtStylesSmartArt Styles
smartArtDesign.resetReset

Ribbon controls (ribbon.hiddenButtons) ​

IdControl
home.clipboard.pastePaste
home.clipboard.cutCut
home.clipboard.copyCopy
home.clipboard.formatPainterFormat Painter
home.slides.newSlideNew Slide
home.slides.layoutLayout
home.slides.resetReset
home.slides.sectionSection
home.slides.slideTemplatesSlide templates (New Slide menu entry)
home.font.fontFamilyFont
home.font.fontSizeFont Size
home.font.increaseFontSizeIncrease Font Size
home.font.decreaseFontSizeDecrease Font Size
home.font.clearFormattingClear All Formatting
home.font.boldBold
home.font.italicItalic
home.font.underlineUnderline
home.font.strikethroughStrikethrough
home.font.shadowText Shadow
home.font.characterSpacingCharacter Spacing
home.font.changeCaseChange Case
home.font.fontColorFont Color
home.font.highlightColorText Highlight Color
home.font.superscriptSuperscript
home.font.subscriptSubscript
home.paragraph.bulletsBullets (toggle and gallery)
home.paragraph.numberingNumbering (toggle and gallery)
home.paragraph.decreaseIndentDecrease List Level
home.paragraph.increaseIndentIncrease List Level
home.paragraph.lineSpacingLine Spacing
home.paragraph.alignLeftAlign Left
home.paragraph.alignCenterCenter
home.paragraph.alignRightAlign Right
home.paragraph.justifyJustify
home.paragraph.columnsColumns
home.paragraph.textDirectionText Direction
home.paragraph.alignTextAlign Text
home.drawing.shapesShapes
home.drawing.arrangeArrange
home.drawing.quickStylesQuick Styles (Shape Styles gallery)
home.drawing.shapeFillShape Fill
home.drawing.shapeOutlineShape Outline
home.drawing.shapeEffectsShape Effects gallery
home.arrange.bringForwardBring Forward
home.arrange.sendBackwardSend Backward
home.arrange.bringToFrontBring to Front
home.arrange.sendToBackSend to Back
home.arrange.flipHorizontalFlip Horizontal
home.arrange.flipVerticalFlip Vertical
home.arrange.duplicateDuplicate
home.arrange.deleteDelete
home.arrange.groupGroup
home.arrange.ungroupUngroup
home.arrange.alignAlign
home.arrange.mergeShapesMerge Shapes
home.arrange.cropCrop
home.arrange.outlineWidthOutline width
home.editing.findFind
home.editing.replaceReplace
home.editing.selectSelect
insert.slides.newSlideNew Slide
insert.slides.reuseSlidesReuse Slides
insert.tables.tableTable
insert.images.picturesPictures
insert.images.screenshotScreenshot
insert.images.photoAlbumPhoto Album
insert.camera.cameoCameo
insert.illustrations.shapesShapes
insert.illustrations.iconsIcons
insert.illustrations.threeDModels3D Models
insert.illustrations.smartArtSmartArt
insert.illustrations.chartChart
insert.forms.formsForms
insert.addIns.getAddInsGet Add-ins
insert.addIns.myAddInsMy Add-ins
insert.links.zoomZoom
insert.links.linkLink
insert.links.actionAction button
insert.comments.commentComment
insert.text.textBoxText Box
insert.text.headerFooterHeader & Footer
insert.text.wordArtWordArt
insert.text.dateTimeDate & Time
insert.text.slideNumberSlide Number
insert.text.objectObject
insert.text.fieldDate & Time and Slide Number (deprecated alias: use dateTime and slideNumber)
insert.symbols.equationEquation
insert.symbols.symbolSymbol
insert.media.mediaVideo
insert.media.audioAudio
insert.media.screenRecordingScreen Recording
draw.tools.selectSelect
draw.tools.penPen
draw.tools.highlighterHighlighter
draw.tools.freeformFreeform
draw.tools.eraserEraser
draw.tools.penColorPen colour
draw.tools.penWidthPen width
draw.convert.inkToShapeInk to Shape
design.themes.galleryThemes (inline gallery)
design.themes.browseThemesThemes gallery
design.themes.editThemeEdit theme
design.variants.galleryVariants (inline gallery)
design.variants.colorsVariants: Colors gallery
design.variants.fontsVariants: Fonts gallery
design.variants.effectsVariants: Effects gallery
design.variants.backgroundStylesVariants: Background Styles gallery
design.customize.slideSizeSlide Size
design.customize.formatBackgroundFormat Background
design.designer.designIdeasDesign Ideas
transitions.preview.previewPreview
transitions.transitionToThisSlide.galleryTransition gallery
transitions.transitionToThisSlide.effectOptionsEffect Options
transitions.timing.soundSound
transitions.timing.durationDuration
transitions.timing.applyToAllApply To All
transitions.timing.advanceOnClickOn Mouse Click
transitions.timing.advanceAfterAfter
animations.preview.previewPreview
animations.animation.galleryAnimation gallery
animations.animation.effectOptionsEffect Options
animations.motionPath.galleryMotion path gallery
animations.advancedAnimation.addAnimationAdd Animation
animations.advancedAnimation.animationPaneAnimation Pane
animations.advancedAnimation.triggerTrigger
animations.advancedAnimation.animationPainterAnimation Painter
animations.advancedAnimation.removeRemove animation
animations.timing.startStart
animations.timing.durationDuration
animations.timing.delayDelay
animations.timing.reorderReorder
slideShow.startSlideShow.fromBeginningFrom Beginning
slideShow.startSlideShow.fromCurrentFrom Current Slide
slideShow.startSlideShow.customShowCustom Slide Show
slideShow.present.presenterViewPresenter View
slideShow.present.broadcastPresent Online
slideShow.setUp.setUpSlideShowSet Up Slide Show
slideShow.setUp.hideSlideHide Slide
slideShow.setUp.rehearseTimingsRehearse Timings
slideShow.setUp.recordRecord
slideShow.setUp.rehearseWithCoachRehearse with Coach
slideShow.captions.subtitlesAlways Use Subtitles
slideShow.captions.subtitleSettingsSubtitle Settings
record.camera.cameoCameo
record.record.fromBeginningFrom Beginning
record.record.fromCurrentFrom Current Slide
record.manage.clearClear
record.manage.resetReset to Cameo
record.help.learnMoreLearn more
review.proofing.spellingSpelling
review.proofing.thesaurusThesaurus
review.accessibility.checkCheck Accessibility
review.language.translateTranslate
review.language.languageLanguage
review.comments.newCommentNew Comment
review.comments.deleteDelete
review.comments.deleteSlideDelete Slide Comments
review.comments.deleteAllDelete All Comments
review.comments.previousPrevious
review.comments.nextNext
review.comments.showCommentsShow Comments
review.compare.compareCompare
review.compare.markAllReadMark all read
review.protect.readOnlyRead-only
review.protect.restrictPermissionRestrict Permission
review.ink.hideInkHide Ink
view.presentationViews.normalNormal
view.presentationViews.outlineOutline View
view.presentationViews.slideSorterSlide Sorter
view.presentationViews.notesPageNotes Page
view.presentationViews.readingViewReading View
view.masterViews.slideMasterSlide Master
view.masterViews.handoutMasterHandout Master
view.masterViews.notesMasterNotes Master
view.show.rulerRuler
view.show.gridlinesGridlines
view.show.guidesGuides
view.show.snapToGridSnap to Grid
view.show.snapToShapeSnap to Shape
view.show.addGuideAdd horizontal / vertical guide
view.show.selectionPaneSelection Pane
view.show.eyedropperEyedropper
view.show.notesNotes
view.zoom.zoomZoom
view.zoom.fitToWindowFit to Window
view.window.templateEditingEdit template elements
view.window.macrosMacros
help.help.optionsOptions
help.help.keyboardShortcutsKeyboard shortcuts
help.help.accessibilityAccessibility checker
shapeFormat.shapeStyles.galleryShape Styles gallery
shapeFormat.shapeStyles.shapeEffectsShape Effects gallery
shapeFormat.wordArtStyles.galleryWordArt Styles gallery
pictureFormat.adjust.correctionsCorrections gallery
pictureFormat.adjust.colorColor gallery
pictureFormat.adjust.artisticEffectsArtistic Effects gallery
pictureFormat.pictureStyles.galleryPicture Styles gallery
pictureFormat.pictureStyles.pictureEffectsPicture Effects gallery
pictureFormat.pictureStyles.graphicsFill图形填充库
pictureFormat.size.cropCrop
tableDesign.tableStyles.galleryTable Styles gallery
tableLayout.table.selectSelect
tableLayout.table.viewGridlinesView Gridlines
tableLayout.rowsColumns.deleteRowsDelete Rows
tableLayout.rowsColumns.deleteColumnsDelete Columns
tableLayout.rowsColumns.insertAboveInsert Above
tableLayout.rowsColumns.insertBelowInsert Below
tableLayout.rowsColumns.insertLeftInsert Left
tableLayout.rowsColumns.insertRightInsert Right
tableLayout.merge.mergeCellsMerge Cells
tableLayout.merge.splitCellsSplit Cells
tableLayout.cellSize.distributeRowsDistribute Rows
tableLayout.cellSize.distributeColumnsDistribute Columns
tableLayout.alignment.alignLeftAlign Left
tableLayout.alignment.alignCenterCenter
tableLayout.alignment.alignRightAlign Right
tableLayout.alignment.alignTopAlign Top
tableLayout.alignment.alignMiddleCenter Vertically
tableLayout.alignment.alignBottomAlign Bottom
tableLayout.alignment.textDirectionText Direction
tableLayout.alignment.cellMarginsCell Margins
tableLayout.tableSize.sizeTable Size
tableLayout.arrange.arrangeArrange
chartDesign.chartLayouts.quickLayoutQuick Layout gallery
chartDesign.chartStyles.changeColorsChange Colors gallery
chartDesign.chartStyles.galleryChart Styles gallery
chartFormat.currentSelection.chartElementsChart Elements
chartFormat.currentSelection.formatSelectionFormat Selection
chartFormat.currentSelection.resetToMatchStyleReset to Match Style
smartArtDesign.createGraphic.addShapeAdd Shape
smartArtDesign.createGraphic.addShapeBeforeAdd Shape Before
smartArtDesign.createGraphic.addShapeAboveAdd Shape Above
smartArtDesign.createGraphic.addBulletAdd Bullet
smartArtDesign.createGraphic.textPaneText Pane
smartArtDesign.createGraphic.promotePromote
smartArtDesign.createGraphic.demoteDemote
smartArtDesign.createGraphic.rightToLeftRight to Left
smartArtDesign.createGraphic.moveUpMove Up
smartArtDesign.createGraphic.moveDownMove Down
smartArtDesign.layouts.galleryLayouts gallery
smartArtDesign.smartArtStyles.changeColorsChange Colors gallery
smartArtDesign.smartArtStyles.gallerySmartArt Styles gallery
smartArtDesign.reset.resetGraphicReset Graphic
smartArtDesign.reset.convertConvert

Toolbar buttons (ribbon.hiddenButtons) ​

IdWhat it removes
shareShare / collaboration button in the tab row and mobile toolbar.
broadcastBroadcast (present online) button.
exportExport button and the File > Export page.
undoUndo button in the quick-access strip.
redoRedo button in the quick-access strip.
recordRecord button and the Record ribbon tab.
notesNotes toggle in the status bar.
fullscreenFull-screen toggle.
zoomThe zoom cluster (zoom in, zoom out, fit).
navigationThe previous / next slide cluster.
mergeShapesThe Merge Shapes dropdown (Union, Combine, Fragment, Intersect, Subtract) in the Home tab Arrange group.
cropBoth picture Crop buttons (crop mode, aspect ratio, Fill, Fit): Home > Arrange, Picture Format > Size.

Options pages (options.hiddenPages) ​

IdPage
generalGeneral
proofingProofing
saveSave
languageLanguage
accessibilityAccessibility
advancedAdvanced
ribbonCustomize Ribbon
quickAccessQuick Access Toolbar
addInsAdd-ins
trustTrust Center
aiAI

Options sections (options.hiddenSections) ​

IdSection
general.userInterfaceUser Interface options
general.personalizePersonalize your copy of the viewer
general.appearanceViewer theme
general.fontsFonts
general.startupStart up options
proofing.autoCorrectAutoCorrect options
proofing.spellingOfficeWhen correcting spelling
proofing.spellingViewerWhen correcting spelling in the viewer
save.savePresentationsSave presentations
save.cacheCache Settings
accessibility.assistantMake your document accessible to others
accessibility.feedbackFeedback options
accessibility.displayApplication display options
advanced.editingEditing options
advanced.cutCopyPasteCut, copy, and paste
advanced.imageQualityImage Size and Quality
advanced.chartChart
advanced.displayDisplay
advanced.slideShowSlide Show
advanced.printPrint
advanced.pdfSave as PDF
ribbon.shortcutReferenceKeyboard Shortcuts
quickAccess.quickAccessOptionsQuick Access Toolbar options
trust.trustSettingsSecurity settings

Settings (options.hiddenSettings, options.locked, options.defaults) ​

IdTypeBuilt-in defaultLabel
general.displayOptimizationstring'appearance'When using multiple displays
general.showMiniToolbarbooleantrueShow Mini Toolbar on selection
general.enableLivePreviewbooleantrueEnable Live Preview
general.collapseRibbonAutomaticallybooleanfalseCollapse the ribbon automatically
general.collapseSearchByDefaultbooleanfalseCollapse the search box by default
general.screenTipStylestring'descriptions'ScreenTip style
general.userNamestring''User name
general.userInitialsstring''Initials
general.showStartScreenbooleantrueShow the Start screen when this application starts
general.enableCustomFontUploadbooleanfalseLet me add font files to this session
proofing.autoCorrectTwoInitialCapitalsbooleantrueCorrect TWo INitial CApitals
proofing.autoCorrectCapitalizeFirstLetterbooleantrueCapitalize first letter of sentences
proofing.autoCorrectCapitalizeDayNamesbooleantrueCapitalize names of days
proofing.autoCorrectSmartQuotesbooleantrueReplace straight quotes with smart quotes
proofing.autoCorrectHyphensToDashbooleantrueReplace hyphens (--) with dash
proofing.autoCorrectFractionsbooleantrueReplace fractions (1/2) with fraction characters (½)
proofing.autoCorrectOrdinalsbooleantrueReplace ordinals (1st) with superscript
proofing.ignoreUppercasebooleantrueIgnore words in UPPERCASE
proofing.ignoreWordsWithNumbersbooleantrueIgnore words that contain numbers
proofing.ignoreInternetAddressesbooleantrueIgnore Internet and file addresses
proofing.flagRepeatedWordsbooleantrueFlag repeated words
proofing.checkSpellingAsYouTypebooleanfalseCheck spelling as you type
proofing.hideSpellingErrorsbooleanfalseHide spelling errors
save.autoSavebooleantrueSave changes automatically (AutoSave)
save.autoRecoverIntervalMinutesnumber2Save AutoRecover information every
save.keepLastAutoRecoveredVersionbooleantrueKeep the last AutoRecovered version if I close without saving
save.defaultExportFormatstring'pptx'Save files in this format
save.cacheRetentionDaysnumber14Days to keep files in the local document cache
save.clearCacheOnClosebooleanfalseDelete files from the local document cache when they are closed
accessibility.subtitleLanguagestring'auto'(not shown in the dialog)
accessibility.showAccessibilityStatusbooleantrueShow accessibility status in the status bar
accessibility.feedbackWithSoundbooleanfalseProvide feedback with sound
accessibility.soundSchemestring'modern'Sound Scheme
accessibility.showShortcutKeysInScreenTipsbooleantrueShow shortcut keys in ScreenTips
accessibility.reducedMotionbooleanfalseReduced motion
advanced.autoSelectEntireWordbooleantrueWhen selecting, automatically select entire word
advanced.allowTextDragAndDropbooleantrueAllow text to be dragged and dropped
advanced.maximumUndoStepsnumber100Maximum number of undos
advanced.useSmartCutAndPastebooleantrueUse smart cut and paste
advanced.showPasteOptionsButtonbooleantrueShow Paste Options button when content is pasted
advanced.imageDefaultResolutionstring'highFidelity'Default resolution
advanced.doNotCompressImagesbooleanfalseDo not compress images in file
advanced.chartPropertiesFollowDataPointbooleantrueProperties follow chart data point
advanced.recentPresentationsCountnumber50Show this number of Recent Presentations
advanced.showVerticalRulerbooleanfalseShow rulers
advanced.showGridbooleanfalseShow grid
advanced.snapToGridbooleanfalseSnap to grid
advanced.disableHardwareAccelerationbooleanfalseDisable hardware graphics acceleration
advanced.disable3DRenderingbooleanfalseDisable 3D rendering (for performance)
advanced.pixelateMosaicAnimationbooleanfalseShow a mosaic effect for Pixelate transitions
advanced.openDocumentsViewstring'savedView'Open all documents using this view
advanced.slideShowShowMenuOnRightClickbooleantrueShow menu on right mouse click
advanced.slideShowShowPopupToolbarbooleantrueShow popup toolbar
advanced.slideShowPromptKeepInkAnnotationsbooleantruePrompt to keep ink annotations when exiting
advanced.slideShowEndWithBlackSlidebooleantrueEnd with black slide
advanced.printInBackgroundbooleantruePrint in background
advanced.printHighQualitybooleanfalseHigh quality
advanced.printUseMostRecentSettingsbooleantrueUse the most recently used print settings
advanced.printWhatstring'slides'Print what
advanced.printColorModestring'color'Color/grayscale
advanced.printHiddenSlidesbooleanfalsePrint hidden slides
advanced.printScaleToFitbooleanfalseScale to fit paper
advanced.printFrameSlidesbooleanfalseFrame slides
advanced.pdfIncludeHiddenSlidesbooleanfalseInclude hidden slides
advanced.pdfSlidesAsPicturesbooleanfalseSave slides as pictures
quickAccess.visiblebooleantrueShow Quick Access Toolbar
quickAccess.positionstring'above'Toolbar Position
quickAccess.showCommandLabelsbooleanfalseAlways show command labels
trust.openInProtectedViewbooleanfalseOpen presentations in Protected View
trust.allowExternalContentbooleanfalseAllow external content (remote images and media)
trust.allowFontDownloadsbooleantrueDownload fonts that are not installed or embedded (Google Fonts)
trust.confirmExternalHyperlinksbooleantrueConfirm before opening external hyperlinks

File tab pages (backstage.hiddenPages) ​

IdPage
homeHome
newNew
openOpen
infoInfo
saveSave
saveAsSave As
printPrint
shareShare
exportExport
closeClose
accountAccount
optionsOptions

File tab cards (backstage.hiddenCards) ​

IdCard
protectProtect Presentation
inspectInspect Presentation
embedFontsEmbed Fonts
signaturesDigital Signatures
versionHistoryVersion History
saveAsPptxPowerPoint Presentation
saveAsPpsxPowerPoint Show
saveAsPptmMacro-Enabled Presentation
saveAsPptPowerPoint 97-2003 Presentation
pdfCreate PDF
pngExport current slide
videoCreate a Video
gifCreate an Animated GIF
jsonExport as JSON
copyImageCopy as Image
printPrint Presentation
shareShare with People

Host context-menu commands ​

All five bindings accept contextMenu.extraElementCommands and contextMenu.extraCanvasCommands. These arrays contain { id, label, group?, disabled?, onSelect } commands. Labels are plain text supplied by the host. group is "top" (the default) or "bottom", separated from the built-in commands. IDs are isolated from built-in IDs; duplicate host IDs keep the first entry.

Element callbacks receive { slideIndex, elementIds }; canvas callbacks receive { slideIndex }. slideIndex is zero-based. Context is an immutable snapshot of the effective selection when the command was offered. disabled accepts a boolean or a predicate receiving that context. A disabled command cannot run. The menu closes before onSelect runs.

ts
viewer.setCustomization({
	contextMenu: {
		extraElementCommands: [
			{
				id: 'send-to-chat',
				label: 'Send to chat',
				disabled: ({ elementIds }) => elementIds.length === 0,
				onSelect: ({ slideIndex, elementIds }) => sendToChat(slideIndex, elementIds),
			},
		],
		extraCanvasCommands: [
			{
				id: 'send-slide',
				label: 'Send slide',
				group: 'bottom',
				onSelect: ({ slideIndex }) => sendSlide(slideIndex),
			},
		],
	},
});

Use the customization prop/input/option or setCustomization / updateCustomization to replace commands live. Callbacks remain in memory and are not persisted in viewer settings. Disabling the corresponding menu also removes host commands.

Element context menu (contextMenu.hiddenElementCommands) ​

IdEntry
copyCopy
cutCut
pastePaste
duplicateDuplicate
edit-textEdit Text
edit-pointsEdit Points
bring-forwardBring Forward
send-backwardSend Backward
bring-frontBring to Front
send-backSend to Back
ai-askAsk AI about this
ai-fixFix with AI
commentAdd Comment
hyperlinkEdit Hyperlink
table-insert-row-aboveInsert Row Above
table-insert-row-belowInsert Row Below
table-delete-rowDelete Row
table-insert-col-leftInsert Column Left
table-insert-col-rightInsert Column Right
table-delete-colDelete Column
table-merge-selectedMerge Selected Cells
table-merge-rightMerge Right
table-merge-downMerge down
table-splitSplit Cell
groupGroup
ungroupUngroup
cropCrop
merge-unionUnion Shapes
merge-combineCombine Shapes
merge-fragmentFragment Shapes
merge-intersectIntersect Shapes
merge-subtractSubtract Shapes
save-as-pictureSave as Picture...
edit-alt-textEdit Alt Text...
size-and-positionSize and Position...
format-shapeFormat Shape...
format-chart-elementFormat Chart Area...
deleteDelete

Empty-canvas context menu (contextMenu.hiddenCanvasCommands) ​

IdEntry
pastePaste
layoutLayout
reset-slideReset Slide
format-backgroundFormat Background...
grid-and-guidesGrid and Guides
rulerRuler

Edit Points menu (contextMenu.hiddenEditPointsCommands) ​

IdEntry
add-pointAdd Point
delete-pointDelete Point
delete-segmentDelete Segment
open-pathOpen Path
close-pathClose Path
smooth-pointSmooth Point
straight-pointStraight Point
corner-pointCorner Point
straight-segmentStraight Segment
curved-segmentCurved Segment
exitExit Edit Points

Editor shortcuts (keyboard.disabled, keyboard.remap) ​

IdCommand
undoUndo (Ctrl/Cmd+Z).
redoRedo (Ctrl/Cmd+Y, Ctrl/Cmd+Shift+Z).
copyCopy the selection (Ctrl/Cmd+C).
cutCut the selection (Ctrl/Cmd+X).
pastePaste (Ctrl/Cmd+V).
duplicateDuplicate the selection (Ctrl/Cmd+D).
deleteDelete the selection (Delete, Backspace).
selectAllSelect every element on the slide (Ctrl/Cmd+A).
groupGroup the selection (Ctrl/Cmd+G).
ungroupUngroup (Ctrl/Cmd+Shift+G).
nudgeMove the selection with the arrow keys (disable only; not remappable).
prevSlidePrevious slide (ArrowLeft with nothing selected).
nextSlideNext slide (ArrowRight with nothing selected).
escapeEscape: leave the current mode (disable only; not remappable).
findFind (Ctrl/Cmd+F).
findReplaceFind and replace (Ctrl/Cmd+H).
toggleShortcutsKeyboard-shortcut reference (?, Ctrl/Cmd+/).
alignLeftAlign text left (Ctrl/Cmd+L).
alignCenterCenter text (Ctrl/Cmd+E).
alignRightAlign text right (Ctrl/Cmd+R).
alignJustifyJustify text (Ctrl/Cmd+J).
increaseFontSizeIncrease font size (Ctrl/Cmd+Shift+>).
decreaseFontSizeDecrease font size (Ctrl/Cmd+Shift+<).
copyFormatCopy formatting (Ctrl/Cmd+Shift+C).
pasteFormatPaste formatting (Ctrl/Cmd+Shift+V).
newSlideNew slide (Ctrl/Cmd+M).
hyperlinkInsert or edit a hyperlink (Ctrl/Cmd+K).
clearFormattingClear character formatting (Ctrl/Cmd+Space).
cycleSelectionNextSelect the next element (Tab, inside the slide).
cycleSelectionPrevSelect the previous element (Shift+Tab, inside the slide).
editTextEdit the text of the selected object (Enter, inside the slide).
pasteSpecialPaste Special (Ctrl/Cmd+Alt+V).

Panels (hiddenPanels) ​

IdRegion
statusBarThe status bar under the canvas (slide counter, zoom, view buttons).
slidesPaneThe slide thumbnail rail on the left.
inspectorThe format / properties inspector on the right.
notesThe speaker-notes panel under the canvas.
quickAccessToolbarThe quick-access strip in the title bar (save, undo, redo, ...).
titleBarThe title bar above the ribbon (file name, quick access, account).
selectionPaneThe Selection Pane and View > Selection Pane.
findReplaceThe Find and Replace panel, Home > Find / Replace and their shortcuts.
accessibilityPaneThe accessibility checker panel, Review > Check Accessibility and Help > Accessibility checker.
comparePaneThe Compare panel and Review > Compare.

Features (disabledFeatures) ​

IdWhat it switches off
aiThe AI assistant: toolbar toggle, chat panel, AI context-menu entries, AI Options page.
collaborationReal-time collaboration: Share and Broadcast buttons, dialogs and File pages.
commentsCommenting: the Add Comment context-menu entry and the Comments groups of Insert and Review.
presentModeSlide-show entry points: the Slide Show ribbon tab.
editPointsEdit Points: the Edit Points context-menu entry and the point-editing mode it opens.

Dialogs (hiddenDialogs) ​

IdWhat it removes
optionsFile > Options (the Settings dialog) and the File tab entry that opens it.
shareThe Share dialog, its toolbar button, File > Share page and card.
broadcastThe Broadcast dialog and its button.
printThe Print dialog, File > Print page and card.
exportFile > Export page, its cards and the Export button.
hyperlinkThe Insert Hyperlink dialog: Insert > Link, the Link menu entry and its shortcut.
equationThe Equation editor and Insert > Equation.
pasteSpecialThe Paste Special dialog and its shortcut.
slideTemplatesThe slide template gallery and its entry at the end of the Home > New Slide menu.
passwordProtectionThe password protection dialog and the File > Info Protect card.
signaturesThe digital signatures dialog and the File > Info Signatures card.

Export formats (hiddenExportFormats) ​

IdFormat
pdfExport to PDF.
pngExport the current slide as PNG.
videoExport the deck as a video.
gifExport the deck as an animated GIF.
jsonExport the parsed deck as JSON.
copyImageCopy the current slide to the clipboard as an image.

Capabilities (capabilities) ​

IdWhat false removes
editEditing. false opens the deck read-only whatever the edit prop says.
exportExporting: the same as hiding the export dialog.
printPrinting: the same as hiding the print dialog.
shareSharing: hides the share and broadcast dialogs.
copyCopying content out: Copy, Cut, Save as Picture, their shortcuts and Copy as image.
presentPresenting: the same as disabling the presentMode feature.
commentCommenting: the same as disabling the comments feature.

Replaceable regions (regions) ​

IdRegion
inspectorThe right-hand inspector column (the pane, not its open/close state).
slidesPaneThe slide thumbnail rail on the left.
notesThe speaker-notes panel under the canvas.
statusBarThe status bar under the canvas.
dialog.optionsThe body of File > Options (the Settings dialog). Context adds options, setOption, resetOptions.
dialog.shareThe body of the Share dialog.
dialog.broadcastThe body of the Broadcast dialog.
dialog.printThe body of the Print dialog.
backstage.homeThe body of File > Home.
backstage.newThe body of File > New.
backstage.openThe body of File > Open.
backstage.infoThe body of File > Info.
backstage.saveThe body of File > Save.
backstage.saveAsThe body of File > Save As.
backstage.printThe body of File > Print.
backstage.shareThe body of File > Share.
backstage.exportThe body of File > Export.
backstage.closeThe body of File > Close.
backstage.accountThe body of File > Account.
backstage.optionsThe body of File > Options.

Drawing tools (hiddenDrawingTools) ​

IdTool
freeformShapeFreeform: Shape
curveCurve

基于 Apache-2.0 许可证发布