gbpptx 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,8 +7,8 @@
7
7
  ## 界面一览
8
8
 
9
9
  ```
10
- 标题栏:快速保存 / 撤销 / 重做 / 放映 · 文档名 · 保存状态 · 自动保存 · 设置
11
- Ribbon:文件 | 开始 | 插入 | 设计 | 切换 | 幻灯片放映 | 审阅 | 视图
10
+ 顶栏:菜单栏 · 文档名 · 保存状态 · 保存按钮
11
+ Ribbon:开始 | 插入 | 设计 | 切换 | 幻灯片放映 | 审阅 | 视图
12
12
  + 形状格式 / 图片格式 / 表格(上下文标签)
13
13
  左窗格:幻灯片缩略图 / 大纲
14
14
  画布: 多选、框选、吸附参考线、组缩放、旋转、就地文字与表格编辑
@@ -16,7 +16,6 @@ Ribbon:文件 | 开始 | 插入 | 设计 | 切换 | 幻灯片放映 | 审阅 |
16
16
  底部: 幻灯片浏览 / 阅读视图 / 普通视图 · 备注 · 缩放滑块
17
17
  ```
18
18
 
19
- - **文件后台**:主页、新建(7 种版式模板)、打开、信息、另存为、导出(PPTX / PDF)、打印、关闭。
20
19
  - **开始**:剪切/复制/粘贴、新建幻灯片、隐藏、重设、字体/字号/加粗/斜体/下划线/删除线/颜色、项目符号/编号/缩进/行距/对齐、形状库、填充/轮廓/阴影、排列/对齐/分布、查找/替换/全选。
21
20
  - **插入**:新建幻灯片、表格(Office 式 10×8 尺寸选择器)、图片、18 种形状、文本框、线条、箭头、备注。
22
21
  - **设计**:6 套主题预览、页面背景、幻灯片大小(16:9 / 4:3)。
@@ -28,6 +27,24 @@ Ribbon:文件 | 开始 | 插入 | 设计 | 切换 | 幻灯片放映 | 审阅 |
28
27
  - **放映**:全屏、单击/方向键翻页、B 黑屏、W 白屏、Esc 退出;演讲者视图带计时器、下一页预览和备注。
29
28
  - **文件工作流**:拖入 `.pptx` 直接打开;拖入 PNG/JPEG/GIF 直接插图;有本地文件句柄时自动保存;关闭页面前提示未保存更改。
30
29
 
30
+ ## 只读与隐藏菜单栏
31
+
32
+ `SlidesApp` 与 `gbdocx` / `gbxlxs` 共用同一套开关(`guabiutils` 的 `createReadOnlyGuard` 负责 DOM 层,本包在画布、缩略图与全局快捷键入口再挡一次):
33
+
34
+ | 能力 | 构造参数 | 运行时方法 |
35
+ | --- | --- | --- |
36
+ | 只读预览 | `readOnly: true` | `app.setReadOnly(on)` |
37
+ | 隐藏顶部菜单栏那一行 | `hideMenuBar: true` | `app.setMenuBarVisible(on)` |
38
+
39
+ ```js
40
+ const app = new SlidesApp(mountEl, { readOnly: true, hideMenuBar: true });
41
+ app.start();
42
+ app.setReadOnly(false); // 回到可编辑
43
+ app.setMenuBarVisible(true); // 再显示菜单栏
44
+ ```
45
+
46
+ 只读档下:Ribbon、格式窗格与备注 `inert`,编辑 / 插入 / 幻灯片 / 审阅菜单禁用(文件菜单只留导出与打印,放映 / 视图照常),画布的拖拽、缩放、旋转、就地文字与表格编辑入口关闭,缩略图的新建 / 版式 / 右键菜单 / 拖拽排序与查找替换一并锁定,粘贴、拖放和写快捷键由守卫拦下;选中对象、翻页、放映、缩放、复制、查找仍可用。`hideMenuBar` 隐藏 `.pp-topbar` 整行(含同行文档名与保存按钮),Ribbon 与画布不受影响。
47
+
31
48
  ## 安装与运行
32
49
 
33
50
  ```bash
@@ -42,9 +59,9 @@ npm test # 内核往返 + 外部 pptx 导入 + XML 合法性测
42
59
  - 页面级底座规则(`html,body` / `body` / `#app` / `*` / `button` / 滚动条)只挂在 `.gbp-root` 作用域内:**嵌入宿主时挂载点必须带 `gbp-root` 类**,否则字体、高度与盒模型底座不生效;宿主的 `body` / `#app` / 全局按钮不受任何影响。
43
60
  - `:root` 的设计令牌保持全局可见(菜单与弹层会挂到 `body`),变量名已包专属;暗色令牌由 `[data-gbp-theme='dark']` 切换,不再被宿主的 `data-theme` 误触发。
44
61
 
45
- `web/serve.mjs` 只是薄封装,静态服务器本体是 `guabiutils/dev-server`(三端共用同一份)。`web/index.html` 用 importmap 把 `gbooxml` / `guabiutils` 映射到 `/vendor/*`,服务器把这两个前缀指向同级目录的 `gbooxml/src`、`guabiutils/src`。这个 demo 依赖 monorepo 目录布局;从 npm 单独安装后要把 importmap 指到 `node_modules/gbooxml/src/index.js`。
62
+ `web/serve.mjs` 只是薄封装,静态服务器本体是 `guabiutils/dev-server`(三端共用同一份)。`web/index.html` 用 importmap 把 `gbooxml` / `guabiutils` 映射到 `/vendor/*`,服务器把前缀指向仓库里的 `packages/gboffice/gbooxml/src` 与 `packages/guabiutils/src`。这个 demo 依赖 monorepo 目录布局;从 npm 单独安装后要把 importmap 指到 `node_modules/gbooxml/src/index.js`。
46
63
 
47
- 页面依次加载 `tokens.css`、`slides.css`、`office.css`,自己装配页面时三份都要引入。
64
+ 页面依次加载 `tokens.css`、`slides.css`、`office.css`、`gbofficeui/styles/office-chrome.css`,自己装配页面时四份都要引入(最后一份是三家共用的顶栏皮肤,必须最后加载)。
48
65
 
49
66
  ## 三层结构
50
67
 
@@ -52,7 +69,7 @@ npm test # 内核往返 + 外部 pptx 导入 + XML 合法性测
52
69
  | --- | --- | --- |
53
70
  | 模型 | `gbpptx/model` | 快照结构、画幅、主题、形状/线条/表格/图片/文本工厂、版式、几何 |
54
71
  | 文件 | `gbpptx`(根入口) | `parsePptx` 读、`buildPptx` 写、`buildPptxVerified` 自检写 |
55
- | 界面 | `web/` | `SlidesApp`:Ribbon、窗格、画布、格式窗格、后台视图、放映 |
72
+ | 界面 | `web/` | `SlidesApp`:Ribbon、窗格、画布、格式窗格、放映 |
56
73
 
57
74
  根入口把模型层与文件层的名字一起导出:
58
75
 
@@ -210,7 +227,7 @@ src/kernel/roundtrip.js 写出并读回自检
210
227
  src/kernel/text.js HTML ⇄ 段落/run/列表
211
228
  src/kernel/print.js A4 横向打印 / PDF 通道
212
229
  web/app/slides-app.js 编辑器控制器
213
- web/app/ui/ Ribbon/画布/窗格/后台/放映/图标/浮层
230
+ web/app/ui/ Ribbon/画布/窗格/放映/图标/浮层
214
231
  web/styles/ tokens / 幻灯片渲染 / Office 外壳
215
232
  test/ 往返与外部导入测试
216
233
  ```
package/package.json CHANGED
@@ -1,46 +1,47 @@
1
- {
2
- "name": "gbpptx",
3
- "version": "0.3.0",
4
- "description": "Office-style PowerPoint (pptx) editor: real PresentationML read/write, ribbon UI, slide sorter, presenter view.",
5
- "type": "module",
6
- "license": "MIT",
7
- "sideEffects": false,
8
- "main": "./src/index.js",
9
- "exports": {
10
- ".": "./src/index.js",
11
- "./model": "./src/kernel/model.js",
12
- "./pptx": "./src/kernel/pptx.js",
13
- "./package.json": "./package.json",
14
- "./web/*": "./web/*",
15
- "./*": "./src/*.js"
16
- },
17
- "files": [
18
- "src",
19
- "web",
20
- "LICENSE"
21
- ],
22
- "keywords": [
23
- "pptx",
24
- "presentation",
25
- "powerpoint",
26
- "ooxml",
27
- "slides",
28
- "editor",
29
- "office",
30
- "ribbon"
31
- ],
32
- "engines": {
33
- "node": ">=18"
34
- },
35
- "scripts": {
36
- "start": "node web/serve.mjs",
37
- "test": "node --test test/roundtrip.test.js test/external-import.test.js test/ui-zoom.test.js"
38
- },
39
- "dependencies": {
40
- "gbooxml": "^0.1.0",
41
- "guabiutils": "^0.3.0"
42
- },
43
- "devDependencies": {
44
- "jsdom": "^30.1.3"
45
- }
46
- }
1
+ {
2
+ "name": "gbpptx",
3
+ "version": "0.5.0",
4
+ "description": "Office-style PowerPoint (pptx) editor: real PresentationML read/write, ribbon UI, slide sorter, presenter view.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "main": "./src/index.js",
9
+ "exports": {
10
+ ".": "./src/index.js",
11
+ "./model": "./src/kernel/model.js",
12
+ "./pptx": "./src/kernel/pptx.js",
13
+ "./package.json": "./package.json",
14
+ "./web/*": "./web/*",
15
+ "./*": "./src/*.js"
16
+ },
17
+ "files": [
18
+ "src",
19
+ "web",
20
+ "LICENSE"
21
+ ],
22
+ "keywords": [
23
+ "pptx",
24
+ "presentation",
25
+ "powerpoint",
26
+ "ooxml",
27
+ "slides",
28
+ "editor",
29
+ "office",
30
+ "ribbon"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "scripts": {
36
+ "start": "node web/serve.mjs",
37
+ "test": "node --test test/roundtrip.test.js test/external-import.test.js test/ui-zoom.test.js test/mode.test.js"
38
+ },
39
+ "dependencies": {
40
+ "gbooxml": "^0.1.0",
41
+ "gbofficeui": "^0.2.0",
42
+ "guabiutils": "^0.3.0"
43
+ },
44
+ "devDependencies": {
45
+ "jsdom": "^30.1.3"
46
+ }
47
+ }
@@ -1,10 +1,10 @@
1
- // [文件] gbpptx·slides·file —— 文件动作 —— 新建/打开/导入/保存/导出/重命名/关闭/后台视图
1
+ // [文件] gbpptx·slides·file —— 文件动作 —— 新建/打开/导入/保存/导出/关闭
2
2
 
3
3
  // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
4
  // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
5
 
6
6
  import { downloadBlob, stripExt } from 'guabiutils';
7
- import { createDraft, createSlideWithLayout, normalizeSnapshot } from '../../../src/kernel/model.js';
7
+ import { createDraft, normalizeSnapshot } from '../../../src/kernel/model.js';
8
8
  import { buildPptxVerified } from '../../../src/kernel/roundtrip.js';
9
9
  import { parsePptx } from '../../../src/kernel/read.js';
10
10
  import { printSlides } from '../../../src/kernel/print.js';
@@ -55,16 +55,14 @@ async function confirmDiscard(action) {
55
55
  });
56
56
  }
57
57
 
58
- function newDoc(layoutKey = '') {
58
+ function newDoc() {
59
59
  this.confirmDiscard('新建演示文稿').then((ok) => {
60
60
  if (!ok) return;
61
61
  const draft = createDraft();
62
- if (layoutKey) draft.slides = [createSlideWithLayout(layoutKey, draft.size)];
63
62
  const seq = Number(this.prefs.docSeq) || 1;
64
63
  this.prefs.docSeq = seq + 1;
65
64
  savePrefs(this.prefs);
66
65
  this.resetDoc(draft, `演示文稿${seq}`);
67
- this.backstage.close();
68
66
  notify.success('已新建空白演示');
69
67
  });
70
68
  }
@@ -79,7 +77,6 @@ async function openFile() {
79
77
  this.doc.name = stripExt(picked.name) || '新建演示';
80
78
  this.snapshot.title = this.doc.name;
81
79
  this.titlebar.refresh();
82
- this.backstage.close();
83
80
  notify.success(`已打开 ${picked.name}`);
84
81
  } catch (err) {
85
82
  notify.error(`打开失败:${err.message || err}`);
@@ -97,7 +94,6 @@ async function importFile(file) {
97
94
  try {
98
95
  const bytes = await readBytes(file);
99
96
  await this.applyBytes(bytes, file.name);
100
- this.backstage.close();
101
97
  notify.success(`已打开 ${file.name}`);
102
98
  } catch (err) {
103
99
  notify.error(`打开失败:${err.message || err}`);
@@ -177,7 +173,6 @@ async function saveAs(name) {
177
173
  this.lastBytes = bytes;
178
174
  this.setDirty(false);
179
175
  this.titlebar.refresh();
180
- if (this.backstage.el.isConnected) this.backstage.go(this.backstage.tab);
181
176
  notify.success('已另存为');
182
177
  return true;
183
178
  } catch (err) {
@@ -206,38 +201,13 @@ function exportPdf() {
206
201
  printSlides(this.snapshot.slides, this.snapshot.theme, renderPage, this.size);
207
202
  }
208
203
 
209
- function renameDoc(name) {
210
- const value = String(name || '').trim() || '新建演示';
211
- this.doc.name = value;
212
- this.snapshot.title = value;
213
- this.touch();
214
- this.titlebar.refresh();
215
- }
216
-
217
204
  async function closeDocument() {
218
205
  if (!(await this.confirmDiscard('关闭演示文稿'))) return;
219
206
  const seq = Number(this.prefs.docSeq) || 1;
220
207
  this.prefs.docSeq = seq + 1;
221
208
  savePrefs(this.prefs);
222
209
  this.resetDoc(createDraft(), `演示文稿${seq}`);
223
- this.backstage.close();
224
210
  notify.success('演示文稿已关闭');
225
211
  }
226
212
 
227
- function openBackstage(tab = 'home') {
228
- this.commitEditing({ render: false });
229
- this.backstage.open(tab);
230
- this.ribbon.setFileActive(true);
231
- }
232
-
233
- function closeBackstage() {
234
- if (!this.backstage || this.backstage.el.hidden) return;
235
- this.backstage.close();
236
- }
237
-
238
- function onBackstageClosed() {
239
- this.ribbon.setFileActive(false);
240
- this.ribbon.activate(this.ribbon.activeTab || 'home', { expand: false });
241
- }
242
-
243
- export const fileMethods = { resetDoc, confirmDiscard, newDoc, openFile, importFile, applyBytes, save, saveAs, exportPptx, exportPdf, renameDoc, closeDocument, openBackstage, closeBackstage, onBackstageClosed };
213
+ export const fileMethods = { resetDoc, confirmDiscard, newDoc, openFile, importFile, applyBytes, save, saveAs, exportPptx, exportPdf, closeDocument };
@@ -118,6 +118,7 @@ function findNext(back = false) {
118
118
  }
119
119
 
120
120
  function replaceCurrent() {
121
+ if (this.readOnly) return;
121
122
  const state = this.findState;
122
123
  const match = state?.matches?.[state.cursor];
123
124
  const q = this.findInput.value;
@@ -136,6 +137,7 @@ function replaceCurrent() {
136
137
  }
137
138
 
138
139
  function replaceAll() {
140
+ if (this.readOnly) return;
139
141
  const q = this.findInput.value;
140
142
  if (!q) return;
141
143
  const replacement = this.replaceInput.value;
@@ -3,6 +3,7 @@
3
3
  // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
4
  // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
5
 
6
+ import { isReadOnlyViewKey } from 'guabiutils';
6
7
  import { isPptxFile } from '../ui/file-io.js';
7
8
  function bindGlobal() {
8
9
  this.onKeyBound = (e) => this.onKeyDown(e);
@@ -36,7 +37,8 @@ function isTypingTarget(target) {
36
37
 
37
38
  function onKeyDown(e) {
38
39
  if (this.presenter?.el) return;
39
- if (this.backstage?.el && !this.backstage.el.hidden) return;
40
+ // [设计] 事件落在应用外时 DOM 守卫接不到,全局快捷键入口按同一份白名单再挡一次
41
+ if (this.readOnly && !isReadOnlyViewKey(e)) return;
40
42
  const target = e.target;
41
43
  const typing = this.isTypingTarget(target);
42
44
  const mod = e.ctrlKey || e.metaKey;
@@ -85,6 +87,7 @@ function onKeyDown(e) {
85
87
 
86
88
  if (e.key === 'F5') { e.preventDefault(); e.shiftKey ? this.presentFromCurrent() : this.presentFromStart(); return; }
87
89
  if (e.key === 'Escape') {
90
+ if (this.preview) { this.setPreview(false); return; }
88
91
  if (this.findEl && !this.findEl.hidden) { this.closeFind(); return; }
89
92
  if (this.view !== 'normal') { this.setView('normal'); return; }
90
93
  this.clearSelection();
@@ -134,6 +137,7 @@ function onKeyDown(e) {
134
137
  }
135
138
 
136
139
  function onPaste(e) {
140
+ if (this.readOnly) return;
137
141
  const files = [...(e.clipboardData?.files || [])];
138
142
  const items = [...(e.clipboardData?.items || [])];
139
143
  const imageItem = items.find((i) => i.type.startsWith('image/'));
@@ -153,6 +157,7 @@ function onPaste(e) {
153
157
  }
154
158
 
155
159
  async function onDrop(e) {
160
+ if (this.readOnly) return;
156
161
  const files = [...(e.dataTransfer?.files || [])];
157
162
  if (!files.length) return;
158
163
  e.preventDefault();
@@ -234,7 +234,7 @@ function cropSelected() {
234
234
  inputs[key] = input;
235
235
  body.appendChild(field(`${label}侧裁剪 %`, input));
236
236
  }
237
- const hint = el('p', 'pp-backstage__muted', '按百分比裁掉图片四边;四边合计不超过 98%。');
237
+ const hint = el('p', 'pp-muted', '按百分比裁掉图片四边;四边合计不超过 98%。');
238
238
  body.appendChild(hint);
239
239
  },
240
240
  });
@@ -5,6 +5,32 @@
5
5
 
6
6
  import { clamp } from 'guabiutils';
7
7
  import { savePrefs, ZOOM_MIN, ZOOM_MAX } from './shared.js';
8
+
9
+ /** 预览模式:只读 + 阅读视图 + 收起菜单/功能窗格;同一按钮或 Esc 退出并恢复原视图 */
10
+ function setPreview(on) {
11
+ const next = !!on;
12
+ if (next === this.preview) return;
13
+ if (next) {
14
+ this.previewRestore = { readOnly: this.readOnly, menuBar: this.menuBarVisible, view: this.view };
15
+ this.preview = true;
16
+ this.root.classList.add('gbp-is-preview');
17
+ this.titlebar.setPreview(true);
18
+ this.commitEditing({ render: false });
19
+ this.setView('reading');
20
+ this.setReadOnly(true);
21
+ this.setMenuBarVisible(false);
22
+ } else {
23
+ const restore = this.previewRestore || { readOnly: false, menuBar: true, view: 'normal' };
24
+ this.preview = false;
25
+ this.root.classList.remove('gbp-is-preview');
26
+ this.titlebar.setPreview(false);
27
+ this.setView(restore.view);
28
+ this.setReadOnly(restore.readOnly);
29
+ this.setMenuBarVisible(restore.menuBar);
30
+ this.previewRestore = null;
31
+ }
32
+ }
33
+
8
34
  function setView(view) {
9
35
  if (!['normal', 'sorter', 'reading'].includes(view)) return;
10
36
  this.commitEditing({ render: false });
@@ -127,4 +153,4 @@ function presentAt(index) {
127
153
  this.presenter.open(Number(index) || 0);
128
154
  }
129
155
 
130
- export const viewMethods = { setView, setZoom, fitToWindow, toggleNotes, toggleGrid, toggleGuides, setRibbonCollapsed, toggleFormatPane, openFormatPane, togglePresenter, toggleLoop, presentFromStart, presentFromCurrent, presentAt };
156
+ export const viewMethods = { setView, setZoom, fitToWindow, toggleNotes, toggleGrid, toggleGuides, setRibbonCollapsed, toggleFormatPane, openFormatPane, togglePresenter, toggleLoop, presentFromStart, presentFromCurrent, presentAt, setPreview };
@@ -7,7 +7,7 @@
7
7
  // 外部拿到的 SlidesApp 形状与拆分前完全一致。
8
8
  // [坑] 装配必须在实例化之前完成:Object.assign 在模块求值时执行,而实例只能在 import 之后 new。
9
9
 
10
- import { clamp } from 'guabiutils';
10
+ import { clamp, createReadOnlyGuard } from 'guabiutils';
11
11
  import { createDraft, sizeOf } from '../../src/kernel/model.js';
12
12
  import { buildPptxVerified } from '../../src/kernel/roundtrip.js';
13
13
  import { parsePptx } from '../../src/kernel/read.js';
@@ -18,7 +18,6 @@ import { SlidePane } from './ui/slide-pane.js';
18
18
  import { Canvas } from './ui/canvas.js';
19
19
  import { FormatPane } from './ui/format-pane.js';
20
20
  import { StatusBar } from './ui/statusbar.js';
21
- import { Backstage } from './ui/backstage.js';
22
21
  import { Present } from './ui/present.js';
23
22
  import { icon } from './ui/icons.js';
24
23
  import { el, loadPrefs, savePrefs, ZOOM_MIN, ZOOM_MAX } from './slides/shared.js';
@@ -37,8 +36,11 @@ import { menusMethods } from './slides/menus.js';
37
36
  import { keysMethods } from './slides/keys.js';
38
37
 
39
38
  export class SlidesApp {
40
- constructor(mount) {
39
+ /** @param {object} [options] readOnly=只读预览(禁写且锁编辑控件);hideMenuBar=隐藏顶部菜单栏那一行 */
40
+ constructor(mount, options = {}) {
41
41
  this.mount = mount;
42
+ this.readOnly = Boolean(options.readOnly);
43
+ this.menuBarVisible = !options.hideMenuBar;
42
44
  const prefs = loadPrefs();
43
45
  this.prefs = prefs;
44
46
  this.snapshot = createDraft();
@@ -54,13 +56,15 @@ export class SlidesApp {
54
56
  this.editing = null;
55
57
  this.tableCursor = null;
56
58
  this.notesSession = false;
57
- this.autosave = !!prefs.autosave;
59
+ this.autosave = options.autoSave !== undefined ? !!options.autoSave : !!prefs.autosave;
58
60
  this.notesVisible = prefs.notesVisible !== false;
59
61
  this.gridVisible = !!prefs.grid;
60
62
  this.guidesVisible = prefs.guides === true;
61
63
  this.ribbonCollapsed = !!prefs.ribbonCollapsed;
62
64
  this.formatPaneOpen = !!prefs.formatPaneOpen;
63
65
  this.view = 'normal';
66
+ this.preview = false;
67
+ this.previewRestore = null;
64
68
  this.presentOptions = { presenter: !!prefs.presenter, loop: !!prefs.loop };
65
69
  this.lastBytes = null;
66
70
 
@@ -72,7 +76,7 @@ export class SlidesApp {
72
76
  this.build();
73
77
  this.bindGlobal();
74
78
  this.presenter = new Present(this);
75
- this.backstage = new Backstage(this);
79
+ this.applyMode();
76
80
  }
77
81
 
78
82
  /* ===================== 骨架 ===================== */
@@ -84,6 +88,7 @@ export class SlidesApp {
84
88
  build() {
85
89
  const root = el('div', 'pp-app');
86
90
  root.innerHTML = `
91
+ <div class="pp-head-host"></div>
87
92
  <div class="pp-topbar-host"></div>
88
93
  <div class="pp-ribbon-host"></div>
89
94
  <div class="pp-main">
@@ -103,6 +108,10 @@ export class SlidesApp {
103
108
  <div class="pp-statusbar-host"></div>`;
104
109
  this.mount.appendChild(root);
105
110
  this.root = root;
111
+ this.topbarHost = root.querySelector('.pp-topbar-host');
112
+ this.headHost = root.querySelector('.pp-head-host');
113
+ this.ribbonHost = root.querySelector('.pp-ribbon-host');
114
+ this.formatPaneHost = root.querySelector('.pp-main__right');
106
115
  this.left = root.querySelector('.pp-main__left');
107
116
  this.center = root.querySelector('.pp-center');
108
117
  this.right = root.querySelector('.pp-main__right');
@@ -118,6 +127,7 @@ export class SlidesApp {
118
127
  this.statusbar = new StatusBar(this);
119
128
 
120
129
  root.querySelector('.pp-topbar-host').appendChild(this.titlebar.el);
130
+ root.querySelector('.pp-head-host').appendChild(this.titlebar.headEl);
121
131
  root.querySelector('.pp-ribbon-host').appendChild(this.ribbon.el);
122
132
  this.left.appendChild(this.slidePane.el);
123
133
  this.canvasHost.appendChild(this.canvas.el);
@@ -133,6 +143,36 @@ export class SlidesApp {
133
143
  this.buildSorterEvents();
134
144
 
135
145
  this.bindNotes(root.querySelector('[data-act="notes-close"]'));
146
+ // 只 inert 功能区与各选项卡本身:文档头的预览按钮在 inert 之外,预览档里仍可点「退出预览」
147
+ this.guard = createReadOnlyGuard(root, {
148
+ editZones: () => [
149
+ this.ribbon.bodyEl,
150
+ ...this.ribbon.tabsEl.querySelectorAll('.pp-rb-tab'),
151
+ this.ribbon.contextHost,
152
+ this.formatPaneHost,
153
+ this.notesEl,
154
+ ],
155
+ });
156
+ }
157
+
158
+ /** 构造参数落 DOM:装配完成后才调用,此时标题栏、Ribbon、格式窗格都已就位 */
159
+ applyMode() {
160
+ this.setMenuBarVisible(this.menuBarVisible);
161
+ if (this.readOnly) this.setReadOnly(true);
162
+ }
163
+
164
+ /** 显示/隐藏顶部菜单栏那一行;文档头(标题/自动保存/保存/预览)不受影响 */
165
+ setMenuBarVisible(on) {
166
+ this.menuBarVisible = !!on;
167
+ this.topbarHost.style.display = this.menuBarVisible ? '' : 'none';
168
+ }
169
+
170
+ /** 只读开关:DOM 守卫 + 编辑面板 + 菜单栏/备注可用性同一处切换 */
171
+ setReadOnly(on) {
172
+ this.readOnly = !!on;
173
+ this.guard.setReadOnly(this.readOnly);
174
+ this.notesText.disabled = this.readOnly;
175
+ this.renderAll();
136
176
  }
137
177
 
138
178
  bindNotes(closeBtn) {
@@ -210,7 +250,7 @@ export class SlidesApp {
210
250
 
211
251
  start() {
212
252
  this.renderAll();
213
- notify.info('已就绪:可直接编辑,或用「文件 → 打开」载入 .pptx');
253
+ notify.info(this.readOnly ? '已就绪:只读预览' : '已就绪:可直接编辑,或用「文件 → 打开」载入 .pptx');
214
254
  }
215
255
 
216
256
  destroy() {
@@ -224,6 +264,7 @@ export class SlidesApp {
224
264
  window.removeEventListener('dragover', this.onDragOverBound);
225
265
  window.removeEventListener('drop', this.onDropBound);
226
266
  window.removeEventListener('resize', this.onResizeBound);
267
+ this.guard.destroy();
227
268
  }
228
269
 
229
270
  /* ===================== 渲染 ===================== */
@@ -219,6 +219,7 @@ export class Canvas {
219
219
  }
220
220
 
221
221
  onDoubleClick(e) {
222
+ if (this.app.readOnly) return;
222
223
  const el = e.target.closest('[data-obj-id]');
223
224
  if (!el) return;
224
225
  const obj = this.app.selectedById(el.dataset.objId);
@@ -242,6 +243,8 @@ export class Canvas {
242
243
  return;
243
244
  }
244
245
  if (!app.selectedIds.includes(id)) app.selectObjects([id]);
246
+ // 只读档仍可选中对象,但不启动会改坐标的拖拽手势
247
+ if (app.readOnly) return;
245
248
  const origin = this.toPage(e);
246
249
  const starts = app.selectedObjects().map((o) => ({ obj: o, x: o.x, y: o.y }));
247
250
  if (!starts.length) return;
@@ -288,6 +291,7 @@ export class Canvas {
288
291
  /* ===================== 缩放 ===================== */
289
292
 
290
293
  startResize(dir, e) {
294
+ if (this.app.readOnly) return;
291
295
  e.preventDefault();
292
296
  e.stopPropagation();
293
297
  const app = this.app;
@@ -369,6 +373,7 @@ export class Canvas {
369
373
  /* ===================== 旋转 ===================== */
370
374
 
371
375
  startRotate(e) {
376
+ if (this.app.readOnly) return;
372
377
  e.preventDefault();
373
378
  e.stopPropagation();
374
379
  const app = this.app;
@@ -528,6 +533,7 @@ export class Canvas {
528
533
  /* ===================== 文本编辑 ===================== */
529
534
 
530
535
  startTextEdit(obj, el, e) {
536
+ if (this.app.readOnly) return;
531
537
  const node = obj.type === 'text' ? el.querySelector('.sl-text') : el.querySelector('.sl-shape-text');
532
538
  if (!node) return;
533
539
  if (this.app.editing) this.app.commitEditing({ render: false });
@@ -590,6 +596,7 @@ export class Canvas {
590
596
  /* ===================== 表格编辑 ===================== */
591
597
 
592
598
  startCellEdit(obj, td) {
599
+ if (this.app.readOnly) return;
593
600
  if (this.app.editing) this.app.commitEditing({ render: false });
594
601
  const tr = td.parentElement;
595
602
  const tbody = tr.parentElement;
@@ -8,7 +8,7 @@ function host() {
8
8
  if (!el) {
9
9
  el = document.createElement('div');
10
10
  el.id = HOST_ID;
11
- el.className = 'gbdocs-notify-host';
11
+ el.className = 'gbdocx-notify-host';
12
12
  document.body.appendChild(el);
13
13
  }
14
14
  return el;
@@ -199,12 +199,6 @@ export class Ribbon {
199
199
  }
200
200
 
201
201
  buildTabs() {
202
- this.fileTab = button('pp-rb-tab pp-rb-tab--file', '文件', '文件');
203
- this.fileTab.addEventListener('click', () => {
204
- this.app.openBackstage('home');
205
- this.setFileActive(true);
206
- });
207
- this.tabsEl.appendChild(this.fileTab);
208
202
  const defs = [
209
203
  ['home', '开始'], ['insert', '插入'], ['design', '设计'], ['transitions', '切换'],
210
204
  ['slideshow', '幻灯片放映'], ['review', '审阅'], ['view', '视图'],
@@ -212,10 +206,7 @@ export class Ribbon {
212
206
  for (const [key, label] of defs) {
213
207
  const tab = button('pp-rb-tab', label, label);
214
208
  tab.dataset.tab = key;
215
- tab.addEventListener('click', () => {
216
- this.app.closeBackstage();
217
- this.activate(key);
218
- });
209
+ tab.addEventListener('click', () => this.activate(key));
219
210
  this.tabsEl.appendChild(tab);
220
211
  }
221
212
  this.contextHost = el('div', 'pp-rb-tabs__context');
@@ -270,7 +261,6 @@ export class Ribbon {
270
261
  for (const tab of this.tabsEl.querySelectorAll('.pp-rb-tab')) {
271
262
  tab.classList.toggle('gbp-is-active', tab.dataset.tab === key);
272
263
  }
273
- if (this.fileTab) this.fileTab.classList.remove('gbp-is-active');
274
264
  for (const [k, panel] of this.panels) panel.hidden = k !== key;
275
265
  this.panel(key);
276
266
  for (const [k, panel] of this.panels) panel.hidden = k !== key;
@@ -278,16 +268,6 @@ export class Ribbon {
278
268
  this.refresh();
279
269
  }
280
270
 
281
- setFileActive(on) {
282
- if (on) {
283
- for (const tab of this.tabsEl.querySelectorAll('.pp-rb-tab')) {
284
- if (tab !== this.fileTab) tab.classList.remove('gbp-is-active');
285
- }
286
- }
287
- if (this.fileTab) this.fileTab.classList.toggle('gbp-is-active', on);
288
- this.bodyEl.classList.toggle('gbp-is-dimmed', on);
289
- }
290
-
291
271
  setCollapsed(on) {
292
272
  this.el.classList.toggle('gbp-is-collapsed', !!on);
293
273
  this.collapseBtn.innerHTML = icon(on ? 'chevronUp' : 'chevronDown', 14);
@@ -344,10 +324,7 @@ export class Ribbon {
344
324
  const def = defs[kind];
345
325
  const tab = button('pp-rb-tab pp-rb-tab--context', def.label, def.label);
346
326
  tab.dataset.tab = def.key;
347
- tab.addEventListener('click', () => {
348
- this.app.closeBackstage();
349
- this.activate(def.key);
350
- });
327
+ tab.addEventListener('click', () => this.activate(def.key));
351
328
  this.contextHost.appendChild(tab);
352
329
  this.contextTabs.push(def);
353
330
  this.panel(def.key);
@@ -53,6 +53,7 @@ export class SlidePane {
53
53
  if (thumb) this.app.presentAt(Number(thumb.dataset.index));
54
54
  });
55
55
  this.thumbsEl.addEventListener('contextmenu', (e) => {
56
+ if (this.app.readOnly) return;
56
57
  const thumb = e.target.closest('.pp-thumb');
57
58
  if (!thumb) return;
58
59
  e.preventDefault();
@@ -60,6 +61,7 @@ export class SlidePane {
60
61
  this.app.openSlideMenu(e.clientX, e.clientY, Number(thumb.dataset.index));
61
62
  });
62
63
  this.thumbsEl.addEventListener('dragstart', (e) => {
64
+ if (this.app.readOnly) return;
63
65
  const thumb = e.target.closest('.pp-thumb');
64
66
  if (!thumb) return;
65
67
  this.dragIndex = Number(thumb.dataset.index);
@@ -79,6 +81,7 @@ export class SlidePane {
79
81
  thumb.classList.add('gbp-is-drop');
80
82
  });
81
83
  this.thumbsEl.addEventListener('drop', (e) => {
84
+ if (this.app.readOnly) return;
82
85
  const thumb = e.target.closest('.pp-thumb');
83
86
  if (!thumb || this.dragIndex === null) return;
84
87
  e.preventDefault();
@@ -94,6 +97,7 @@ export class SlidePane {
94
97
  if (line.dataset.obj) this.app.selectObjects([line.dataset.obj]);
95
98
  });
96
99
  this.outlineEl.addEventListener('dblclick', (e) => {
100
+ if (this.app.readOnly) return;
97
101
  const line = e.target.closest('[data-slide]');
98
102
  if (!line) return;
99
103
  this.app.selectSlide(Number(line.dataset.slide));
@@ -110,6 +114,10 @@ export class SlidePane {
110
114
  }
111
115
 
112
116
  render() {
117
+ // 只读档锁掉新建/版式入口;缩略图本身的选中、翻页、放映仍可用
118
+ this.el.querySelectorAll('[data-act="new"], [data-act="layout"]').forEach((btn) => {
119
+ btn.disabled = this.app.readOnly;
120
+ });
113
121
  this.renderThumbs();
114
122
  if (this.view === 'outline') this.renderOutline();
115
123
  }