gbpptx 0.3.0 → 0.4.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,6 +1,6 @@
1
1
  {
2
2
  "name": "gbpptx",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Office-style PowerPoint (pptx) editor: real PresentationML read/write, ribbon UI, slide sorter, presenter view.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,10 +34,11 @@
34
34
  },
35
35
  "scripts": {
36
36
  "start": "node web/serve.mjs",
37
- "test": "node --test test/roundtrip.test.js test/external-import.test.js test/ui-zoom.test.js"
37
+ "test": "node --test test/roundtrip.test.js test/external-import.test.js test/ui-zoom.test.js test/mode.test.js"
38
38
  },
39
39
  "dependencies": {
40
40
  "gbooxml": "^0.1.0",
41
+ "gbofficeui": "^0.1.0",
41
42
  "guabiutils": "^0.3.0"
42
43
  },
43
44
  "devDependencies": {
@@ -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.ribbon.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.ribbon.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();
@@ -61,6 +63,8 @@ export class SlidesApp {
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
  /* ===================== 骨架 ===================== */
@@ -103,6 +107,9 @@ export class SlidesApp {
103
107
  <div class="pp-statusbar-host"></div>`;
104
108
  this.mount.appendChild(root);
105
109
  this.root = root;
110
+ this.topbarHost = root.querySelector('.pp-topbar-host');
111
+ this.ribbonHost = root.querySelector('.pp-ribbon-host');
112
+ this.formatPaneHost = root.querySelector('.pp-main__right');
106
113
  this.left = root.querySelector('.pp-main__left');
107
114
  this.center = root.querySelector('.pp-center');
108
115
  this.right = root.querySelector('.pp-main__right');
@@ -133,6 +140,36 @@ export class SlidesApp {
133
140
  this.buildSorterEvents();
134
141
 
135
142
  this.bindNotes(root.querySelector('[data-act="notes-close"]'));
143
+ // 只 inert 功能区与各选项卡本身:预览按钮同在选项卡行,必须保持可点
144
+ this.guard = createReadOnlyGuard(root, {
145
+ editZones: () => [
146
+ this.ribbon.bodyEl,
147
+ ...this.ribbon.tabsEl.querySelectorAll('.pp-rb-tab'),
148
+ this.ribbon.contextHost,
149
+ this.formatPaneHost,
150
+ this.notesEl,
151
+ ],
152
+ });
153
+ }
154
+
155
+ /** 构造参数落 DOM:装配完成后才调用,此时标题栏、Ribbon、格式窗格都已就位 */
156
+ applyMode() {
157
+ this.setMenuBarVisible(this.menuBarVisible);
158
+ if (this.readOnly) this.setReadOnly(true);
159
+ }
160
+
161
+ /** 显示/隐藏顶部菜单栏那一行(含同行文档名与保存按钮) */
162
+ setMenuBarVisible(on) {
163
+ this.menuBarVisible = !!on;
164
+ this.topbarHost.style.display = this.menuBarVisible ? '' : 'none';
165
+ }
166
+
167
+ /** 只读开关:DOM 守卫 + 编辑面板 + 菜单栏/备注可用性同一处切换 */
168
+ setReadOnly(on) {
169
+ this.readOnly = !!on;
170
+ this.guard.setReadOnly(this.readOnly);
171
+ this.notesText.disabled = this.readOnly;
172
+ this.renderAll();
136
173
  }
137
174
 
138
175
  bindNotes(closeBtn) {
@@ -210,7 +247,7 @@ export class SlidesApp {
210
247
 
211
248
  start() {
212
249
  this.renderAll();
213
- notify.info('已就绪:可直接编辑,或用「文件 → 打开」载入 .pptx');
250
+ notify.info(this.readOnly ? '已就绪:只读预览' : '已就绪:可直接编辑,或用「文件 → 打开」载入 .pptx');
214
251
  }
215
252
 
216
253
  destroy() {
@@ -224,6 +261,7 @@ export class SlidesApp {
224
261
  window.removeEventListener('dragover', this.onDragOverBound);
225
262
  window.removeEventListener('drop', this.onDropBound);
226
263
  window.removeEventListener('resize', this.onResizeBound);
264
+ this.guard.destroy();
227
265
  }
228
266
 
229
267
  /* ===================== 渲染 ===================== */
@@ -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,16 +206,17 @@ 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');
222
213
  this.tabsEl.appendChild(this.contextHost);
223
214
  const spacer = el('div', 'pp-rb-tabs__spacer');
224
215
  this.tabsEl.appendChild(spacer);
216
+ this.previewBtn = button('pp-rb-preview', `${icon('eye', 15)}<span>预览</span>`, '预览模式');
217
+ this.previewBtn.setAttribute('aria-pressed', 'false');
218
+ this.previewBtn.addEventListener('click', () => this.app.setPreview(!this.app.preview));
219
+ this.tabsEl.appendChild(this.previewBtn);
225
220
  this.collapseBtn = button('pp-rb-collapse', icon('chevronDown', 14), '收起功能区');
226
221
  this.collapseBtn.addEventListener('click', () => {
227
222
  this.app.setRibbonCollapsed(!this.app.ribbonCollapsed);
@@ -229,6 +224,15 @@ export class Ribbon {
229
224
  this.tabsEl.appendChild(this.collapseBtn);
230
225
  }
231
226
 
227
+ /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
228
+ setPreview(on) {
229
+ const active = !!on;
230
+ this.previewBtn.classList.toggle('gbp-is-active', active);
231
+ this.previewBtn.title = active ? '退出预览' : '预览模式';
232
+ this.previewBtn.setAttribute('aria-pressed', String(active));
233
+ this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
234
+ }
235
+
232
236
  buildPanels() {
233
237
  const builders = {
234
238
  home: (p) => this.buildHome(p),
@@ -270,7 +274,6 @@ export class Ribbon {
270
274
  for (const tab of this.tabsEl.querySelectorAll('.pp-rb-tab')) {
271
275
  tab.classList.toggle('gbp-is-active', tab.dataset.tab === key);
272
276
  }
273
- if (this.fileTab) this.fileTab.classList.remove('gbp-is-active');
274
277
  for (const [k, panel] of this.panels) panel.hidden = k !== key;
275
278
  this.panel(key);
276
279
  for (const [k, panel] of this.panels) panel.hidden = k !== key;
@@ -278,16 +281,6 @@ export class Ribbon {
278
281
  this.refresh();
279
282
  }
280
283
 
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
284
  setCollapsed(on) {
292
285
  this.el.classList.toggle('gbp-is-collapsed', !!on);
293
286
  this.collapseBtn.innerHTML = icon(on ? 'chevronUp' : 'chevronDown', 14);
@@ -344,10 +337,7 @@ export class Ribbon {
344
337
  const def = defs[kind];
345
338
  const tab = button('pp-rb-tab pp-rb-tab--context', def.label, def.label);
346
339
  tab.dataset.tab = def.key;
347
- tab.addEventListener('click', () => {
348
- this.app.closeBackstage();
349
- this.activate(def.key);
350
- });
340
+ tab.addEventListener('click', () => this.activate(def.key));
351
341
  this.contextHost.appendChild(tab);
352
342
  this.contextTabs.push(def);
353
343
  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
  }
@@ -1,4 +1,4 @@
1
- // [文件] gbpptx·顶部菜单栏 —— 与 gbdocs / gbxlxs 一致:左侧菜单栏 + 右侧文档名/保存状态/保存按钮
1
+ // [文件] gbpptx·顶部菜单栏 —— 与 gbdocx / gbxlxs 一致:左侧菜单栏 + 右侧文档名/保存状态/保存按钮
2
2
 
3
3
  import { SHAPE_KINDS, SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
4
4
  import { icon } from './icons.js';
@@ -24,18 +24,19 @@ export class TitleBar {
24
24
 
25
25
  build() {
26
26
  const defs = [
27
- ['文件', () => this.fileItems()],
28
- ['编辑', () => this.editItems()],
29
- ['插入', () => this.insertItems()],
30
- ['幻灯片', () => this.slideItems()],
31
- ['放映', () => this.showItems()],
32
- ['审阅', () => this.reviewItems()],
33
- ['视图', () => this.viewItems()],
27
+ ['file', '文件', () => this.fileItems()],
28
+ ['edit', '编辑', () => this.editItems()],
29
+ ['insert', '插入', () => this.insertItems()],
30
+ ['slide', '幻灯片', () => this.slideItems()],
31
+ ['show', '放映', () => this.showItems()],
32
+ ['review', '审阅', () => this.reviewItems()],
33
+ ['view', '视图', () => this.viewItems()],
34
34
  ];
35
35
  const bar = el('div', 'pp-menubar');
36
- for (const [label, items] of defs) {
36
+ for (const [key, label, items] of defs) {
37
37
  const btn = el('button', 'pp-menubar__btn', label);
38
38
  btn.type = 'button';
39
+ btn.dataset.menu = key;
39
40
  btn.addEventListener('click', () => {
40
41
  btn.classList.add('gbp-is-open');
41
42
  openMenu({ anchor: btn, items: items(), onClose: () => btn.classList.remove('gbp-is-open') });
@@ -60,7 +61,7 @@ export class TitleBar {
60
61
  fileItems() {
61
62
  const app = this.app;
62
63
  const hasSlides = app.snapshot.slides.length > 0;
63
- return [
64
+ const items = [
64
65
  { label: '新建', shortcut: 'Ctrl+N', onClick: () => app.newDoc() },
65
66
  { label: '打开…', shortcut: 'Ctrl+O', onClick: () => app.openFile() },
66
67
  { divided: true },
@@ -74,6 +75,10 @@ export class TitleBar {
74
75
  { divided: true },
75
76
  { label: '关闭', onClick: () => app.closeDocument() },
76
77
  ];
78
+ // 只读档保留导出/打印,其余文件动作会替换或写回文档,一律禁用
79
+ if (!app.readOnly) return items;
80
+ const viewActions = new Set(['导出 PPTX', '导出 PDF', '打印…']);
81
+ return items.map((item) => ({ ...item, disabled: item.disabled || !viewActions.has(item.label) }));
77
82
  }
78
83
 
79
84
  editItems() {
@@ -186,7 +191,7 @@ export class TitleBar {
186
191
  confirmText: '知道了',
187
192
  build: (body) => {
188
193
  const p = el('div', 'pp-about');
189
- p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-backstage__muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
194
+ p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
190
195
  body.appendChild(p);
191
196
  },
192
197
  });
@@ -203,6 +208,11 @@ export class TitleBar {
203
208
  ? '未保存'
204
209
  : app.doc.handle ? '已保存' : (app.doc.savedAt ? '已保存副本' : '尚未保存');
205
210
  this.stateEl.classList.toggle('gbp-is-dirty', app.dirty);
206
- this.saveBtn.disabled = !app.snapshot.slides.length;
211
+ this.saveBtn.disabled = app.readOnly || !app.snapshot.slides.length;
212
+ // 只读档锁掉纯编辑类菜单,放映/视图与文件菜单里的导出/打印照常可用
213
+ const writeMenus = new Set(['edit', 'insert', 'slide', 'review']);
214
+ this.el.querySelectorAll('[data-menu]').forEach((btn) => {
215
+ btn.disabled = app.readOnly && writeMenus.has(btn.dataset.menu);
216
+ });
207
217
  }
208
218
  }