gbpptx 0.5.2 → 0.6.1

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.
@@ -11,7 +11,7 @@ import { printSlides } from '../../../src/kernel/print.js';
11
11
  import { notify } from '../ui/notify.js';
12
12
  import { renderPage } from '../ui/page-view.js';
13
13
  import { PPTX_MIME, ensureExt, isPptxFile, openPptx, readBytes, savePptx, savePptxAs } from '../ui/file-io.js';
14
- import { openModal } from '../ui/dialogs.js';
14
+ import { openModal, promptText } from '../ui/dialogs.js';
15
15
  import { savePrefs } from './shared.js';
16
16
  function resetDoc(draft, name, handle = null) {
17
17
  this.snapshot = draft;
@@ -210,4 +210,31 @@ async function closeDocument() {
210
210
  notify.success('演示文稿已关闭');
211
211
  }
212
212
 
213
- export const fileMethods = { resetDoc, confirmDiscard, newDoc, openFile, importFile, applyBytes, save, saveAs, exportPptx, exportPdf, closeDocument };
213
+ /** 文档头「重命名」:宿主在场交给宿主(宿主改的是服务端文档名),否则改本地演示名 */
214
+ async function renameDoc(event) {
215
+ if (this.host) {
216
+ this.host.rename?.(event);
217
+ return;
218
+ }
219
+ const name = await promptText({
220
+ title: '重命名演示',
221
+ label: '演示名称',
222
+ value: this.doc.name,
223
+ });
224
+ if (!name) return;
225
+ this.doc.name = name;
226
+ this.snapshot.title = name;
227
+ this.titlebar.refresh();
228
+ notify.success('已重命名');
229
+ }
230
+
231
+ /** 文档头「下载」:宿主在场交给宿主(走后端二进制流),否则导出当前 .pptx */
232
+ function downloadDoc() {
233
+ if (this.host) {
234
+ this.host.download?.();
235
+ return;
236
+ }
237
+ this.exportPptx();
238
+ }
239
+
240
+ export const fileMethods = { resetDoc, confirmDiscard, newDoc, openFile, importFile, applyBytes, save, saveAs, exportPptx, exportPdf, closeDocument, renameDoc, downloadDoc };
@@ -36,11 +36,15 @@ import { menusMethods } from './slides/menus.js';
36
36
  import { keysMethods } from './slides/keys.js';
37
37
 
38
38
  export class SlidesApp {
39
- /** @param {object} [options] readOnly=只读预览(禁写且锁编辑控件);hideMenuBar=隐藏顶部菜单栏那一行 */
39
+ /**
40
+ * @param {object} [options] readOnly=只读预览(禁写且锁编辑控件);hideMenuBar=隐藏顶部菜单栏那一行;
41
+ * host=嵌入宿主的文件能力(getTitle 文档名 / rename 重命名 / download 下载),缺省走包内实现
42
+ */
40
43
  constructor(mount, options = {}) {
41
44
  this.mount = mount;
42
45
  this.readOnly = Boolean(options.readOnly);
43
46
  this.menuBarVisible = !options.hideMenuBar;
47
+ this.host = options.host || null;
44
48
  const prefs = loadPrefs();
45
49
  this.prefs = prefs;
46
50
  this.snapshot = createDraft();
@@ -86,6 +90,26 @@ export class SlidesApp {
86
90
  return sizeOf(this.snapshot);
87
91
  }
88
92
 
93
+ /** 文档标题:宿主给了就用宿主的(服务端文档名),否则用本地文档名 */
94
+ getTitle() {
95
+ return this.host?.getTitle?.() || this.doc.name || '新建演示';
96
+ }
97
+
98
+ /** 文档头「重命名」是否可用:宿主提供才渲染,独立模式走包内实现 */
99
+ canRename() {
100
+ return this.host ? typeof this.host.rename === 'function' : true;
101
+ }
102
+
103
+ /** 文档头「下载」是否可用:宿主提供才渲染,独立模式走包内实现 */
104
+ canDownload() {
105
+ return this.host ? typeof this.host.download === 'function' : true;
106
+ }
107
+
108
+ /** 宿主改了文档名之后刷新文档头(标题/状态) */
109
+ refreshHead() {
110
+ this.titlebar?.refresh();
111
+ }
112
+
89
113
  build() {
90
114
  const root = el('div', 'pp-app');
91
115
  root.innerHTML = `
@@ -117,6 +117,8 @@ const BODY = {
117
117
  colLeft: r(3, 4, 18, 16, 1.5) + p('M3 10h18M9 4v16M15 4v16M2 12h5M4.5 9.5L2 12l2.5 2.5'),
118
118
  colRight: r(3, 4, 18, 16, 1.5) + p('M3 10h18M9 4v16M15 4v16M17 12h5M19.5 9.5L22 12l-2.5 2.5'),
119
119
  merge: r(3, 4, 18, 16, 1.5) + p('M3 10h18M9 10v10M15 10v10') + p('M8 7h8'),
120
+ download: p('M12 4v11') + p('M8 11l4 4 4-4') + p('M4 17v2a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-2'),
121
+ rename: p('M4 20h4L19 9a2 2 0 0 0-3-3L5 17v3z') + p('M14.5 6.5l3 3'),
120
122
  };
121
123
 
122
124
  const svg = (body, size) =>
@@ -1,263 +1,253 @@
1
- // [文件] gbpptx·顶部菜单栏与文档头 —— 与 gbdocx / gbxlxs 一致:菜单栏一行 + 文档头一行(标题/自动保存/保存/预览)
2
-
3
- import { SHAPE_KINDS, SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
4
- import { icon } from './icons.js';
5
- import { openMenu } from './menu.js';
6
- import { openModal } from './dialogs.js';
7
-
8
- const el = (tag, cls, text) => {
9
- const node = document.createElement(tag);
10
- if (cls) node.className = cls;
11
- if (text != null) node.textContent = text;
12
- return node;
13
- };
14
-
15
- const submenu = (label, items) => ({ label, children: items });
16
-
17
- export class TitleBar {
18
- constructor(app) {
19
- this.app = app;
20
- this.el = el('header', 'pp-topbar');
21
- this.headEl = el('header', 'gbo-head pp-head');
22
- this.build();
23
- this.buildHead();
24
- this.refresh();
25
- }
26
-
27
- build() {
28
- const defs = [
29
- ['file', '文件', () => this.fileItems()],
30
- ['edit', '编辑', () => this.editItems()],
31
- ['insert', '插入', () => this.insertItems()],
32
- ['slide', '幻灯片', () => this.slideItems()],
33
- ['show', '放映', () => this.showItems()],
34
- ['review', '审阅', () => this.reviewItems()],
35
- ['view', '视图', () => this.viewItems()],
36
- ];
37
- const bar = el('div', 'pp-menubar');
38
- for (const [key, label, items] of defs) {
39
- const btn = el('button', 'pp-menubar__btn', label);
40
- btn.type = 'button';
41
- btn.dataset.menu = key;
42
- btn.addEventListener('click', () => {
43
- btn.classList.add('gbp-is-open');
44
- openMenu({ anchor: btn, items: items(), onClose: () => btn.classList.remove('gbp-is-open') });
45
- });
46
- bar.appendChild(btn);
47
- }
48
- this.el.append(bar);
49
- }
50
-
51
- buildHead() {
52
- const title = el('span', 'gbo-head__title');
53
- const state = el('span', 'gbo-head__sub');
54
- const spacer = el('span', 'gbo-head__spacer');
55
-
56
- const auto = el('label', 'gbo-head__auto');
57
- this.autosaveEl = el('input', 'gbo-head__autosave');
58
- this.autosaveEl.type = 'checkbox';
59
- this.autosaveEl.addEventListener('change', () => this.app.setAutosave(this.autosaveEl.checked));
60
- auto.append(this.autosaveEl, document.createTextNode('自动保存'));
61
-
62
- this.saveBtn = el('button', 'gbo-head__btn gbo-head__btn--primary', '保存');
63
- this.saveBtn.type = 'button';
64
- this.saveBtn.title = '保存 (Ctrl+S)';
65
- this.saveBtn.addEventListener('click', () => this.app.save());
66
-
67
- const actions = el('span', 'gbo-head__actions');
68
- actions.append(auto, this.saveBtn);
69
-
70
- this.previewBtn = el('button', 'gbo-head__btn gbo-head__preview', '预览');
71
- this.previewBtn.type = 'button';
72
- this.previewBtn.title = '预览模式';
73
- this.previewBtn.setAttribute('aria-pressed', 'false');
74
- this.previewBtn.innerHTML = `${icon('eye', 14)}<span>预览</span>`;
75
- this.previewBtn.addEventListener('click', () => this.app.setPreview(!this.app.preview));
76
-
77
- this.nameEl = title;
78
- this.stateEl = state;
79
- this.fullscreenBtn = el('button', 'gbo-head__btn gbo-head__preview', '全屏');
80
- this.fullscreenBtn.type = 'button';
81
- this.fullscreenBtn.title = '全屏';
82
- this.fullscreenBtn.setAttribute('aria-pressed', 'false');
83
- this.fullscreenBtn.innerHTML = `${icon('fullscreen', 14)}<span>全屏</span>`;
84
- this.fullscreenBtn.addEventListener('click', () => this.app.toggleFullscreen());
85
- this.headEl.append(title, state, spacer, actions, this.previewBtn, this.fullscreenBtn);
86
- }
87
-
88
- /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
89
- setPreview(on) {
90
- const active = !!on;
91
- this.previewBtn.classList.toggle('gbo-head__preview--on', active);
92
- this.previewBtn.title = active ? '退出预览' : '预览模式';
93
- this.previewBtn.setAttribute('aria-pressed', String(active));
94
- this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
95
- }
96
-
97
- /* ===================== 菜单条目 ===================== */
98
-
99
- fileItems() {
100
- const app = this.app;
101
- const hasSlides = app.snapshot.slides.length > 0;
102
- const items = [
103
- { label: '新建', shortcut: 'Ctrl+N', onClick: () => app.newDoc() },
104
- { label: '打开…', shortcut: 'Ctrl+O', onClick: () => app.openFile() },
105
- { divided: true },
106
- { label: '保存', shortcut: 'Ctrl+S', disabled: !hasSlides, onClick: () => app.save() },
107
- { label: '另存为…', shortcut: 'Ctrl+Shift+S', disabled: !hasSlides, onClick: () => app.saveAs(app.doc.name) },
108
- { label: '自动保存', checked: app.autosave, onClick: () => app.setAutosave(!app.autosave) },
109
- { divided: true },
110
- { label: '导出 PPTX', disabled: !hasSlides, onClick: () => app.exportPptx() },
111
- { label: '导出 PDF', disabled: !hasSlides, onClick: () => app.exportPdf() },
112
- { label: '打印…', disabled: !hasSlides, onClick: () => app.exportPdf() },
113
- { divided: true },
114
- { label: '关闭', onClick: () => app.closeDocument() },
115
- ];
116
- // 只读档保留导出/打印,其余文件动作会替换或写回文档,一律禁用
117
- if (!app.readOnly) return items;
118
- const viewActions = new Set(['导出 PPTX', '导出 PDF', '打印…']);
119
- return items.map((item) => ({ ...item, disabled: item.disabled || !viewActions.has(item.label) }));
120
- }
121
-
122
- editItems() {
123
- const app = this.app;
124
- const hasSel = app.selectedIds.length > 0 || Boolean(app.editing);
125
- return [
126
- { label: '撤销', shortcut: 'Ctrl+Z', disabled: !app.canUndo(), onClick: () => app.undo() },
127
- { label: '重做', shortcut: 'Ctrl+Y', disabled: !app.canRedo(), onClick: () => app.redo() },
128
- { divided: true },
129
- { label: '剪切', shortcut: 'Ctrl+X', disabled: !hasSel, onClick: () => app.cutSelected() },
130
- { label: '复制', shortcut: 'Ctrl+C', disabled: !hasSel, onClick: () => app.copySelected() },
131
- { label: '粘贴', shortcut: 'Ctrl+V', disabled: !app.canPaste(), onClick: () => app.paste() },
132
- { label: '粘贴为纯文本', onClick: () => app.pastePlain() },
133
- { divided: true },
134
- { label: '全选', shortcut: 'Ctrl+A', onClick: () => app.selectAll() },
135
- { label: '查找…', shortcut: 'Ctrl+F', onClick: () => app.openFind(false) },
136
- { label: '替换…', shortcut: 'Ctrl+H', onClick: () => app.openFind(true) },
137
- ];
138
- }
139
-
140
- insertItems() {
141
- const app = this.app;
142
- return [
143
- { label: '新建幻灯片', shortcut: 'Ctrl+M', onClick: () => app.addSlide() },
144
- { divided: true },
145
- submenu('表格', [2, 3, 4, 5].map((n) => ({
146
- label: `${n}×${n} 表格`,
147
- onClick: () => app.insertTable(n, n),
148
- }))),
149
- { label: '图片…', onClick: () => app.insert('image') },
150
- submenu('形状', SHAPE_KINDS.map((s) => ({
151
- label: s.label,
152
- onClick: () => app.insert('shape', s.kind),
153
- }))),
154
- { label: '文本框', onClick: () => app.insert('text') },
155
- { label: '线条', onClick: () => app.insert('line') },
156
- { label: '箭头', onClick: () => app.insert('arrow') },
157
- { divided: true },
158
- { label: '备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
159
- ];
160
- }
161
-
162
- slideItems() {
163
- const app = this.app;
164
- const count = app.snapshot.slides.length;
165
- return [
166
- { label: '新建幻灯片', shortcut: 'Ctrl+M', onClick: () => app.addSlide() },
167
- { label: '复制幻灯片', onClick: () => app.dupSlide() },
168
- { label: '删除幻灯片', disabled: count <= 1, onClick: () => app.delSlide() },
169
- { divided: true },
170
- { label: '隐藏幻灯片', checked: Boolean(app.currentSlide()?.hidden), onClick: () => app.toggleSlideHidden() },
171
- submenu('版式', SLIDE_LAYOUTS.map((l) => ({
172
- label: l.label,
173
- onClick: () => app.addSlide(l.key),
174
- }))),
175
- submenu('切换', TRANSITIONS.map((t) => ({
176
- label: t.label,
177
- onClick: () => app.setTransition({ type: t.key, dir: t.dir || 'l' }),
178
- }))),
179
- { divided: true },
180
- { label: '重设位置与大小', disabled: !app.selectedIds.length, onClick: () => app.resetSelected() },
181
- { label: '设置背景格式…', onClick: () => app.openFormatPane() },
182
- ];
183
- }
184
-
185
- showItems() {
186
- const app = this.app;
187
- return [
188
- { label: '从头开始', shortcut: 'F5', onClick: () => app.presentFromStart() },
189
- { label: '从当前页', shortcut: 'Shift+F5', onClick: () => app.presentFromCurrent() },
190
- { divided: true },
191
- { label: '演讲者视图', checked: app.presentOptions.presenter, onClick: () => app.togglePresenter() },
192
- { label: '循环放映', checked: app.presentOptions.loop, onClick: () => app.toggleLoop() },
193
- { label: '隐藏幻灯片', checked: Boolean(app.currentSlide()?.hidden), onClick: () => app.toggleSlideHidden() },
194
- ];
195
- }
196
-
197
- reviewItems() {
198
- const app = this.app;
199
- return [
200
- { label: '显示备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
201
- { label: '字数统计…', onClick: () => app.showWordCount() },
202
- ];
203
- }
204
-
205
- viewItems() {
206
- const app = this.app;
207
- return [
208
- { label: '普通', checked: app.view === 'normal', onClick: () => app.setView('normal') },
209
- { label: '幻灯片浏览', checked: app.view === 'sorter', onClick: () => app.setView('sorter') },
210
- { label: '阅读视图', checked: app.view === 'reading', onClick: () => app.setView('reading') },
211
- { divided: true },
212
- { label: '网格线', checked: app.gridVisible, onClick: () => app.toggleGrid() },
213
- { label: '参考线', checked: app.guidesVisible, onClick: () => app.toggleGuides() },
214
- { label: '备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
215
- { label: '设置形状格式窗格', checked: app.formatPaneOpen, onClick: () => app.toggleFormatPane() },
216
- { divided: true },
217
- { label: '适应窗口', onClick: () => app.fitToWindow() },
218
- { label: '放大', shortcut: 'Ctrl+=', onClick: () => app.setZoom(app.zoom + 10) },
219
- { label: '缩小', shortcut: 'Ctrl+-', onClick: () => app.setZoom(app.zoom - 10) },
220
- { divided: true },
221
- { label: '关于挂逼演示…', onClick: () => this.showAbout() },
222
- ];
223
- }
224
-
225
- showAbout() {
226
- openModal({
227
- title: '关于',
228
- width: 400,
229
- confirmText: '知道了',
230
- build: (body) => {
231
- const p = el('div', 'pp-about');
232
- p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
233
- body.appendChild(p);
234
- },
235
- });
236
- }
237
-
238
- /* ===================== 状态刷新 ===================== */
239
-
240
- refresh() {
241
- const app = this.app;
242
- this.nameEl.textContent = app.doc.name || '新建演示';
243
- this.nameEl.title = this.nameEl.textContent;
244
- document.title = `${this.nameEl.textContent} - 挂逼演示`;
245
- this.stateEl.textContent = app.dirty
246
- ? '未保存'
247
- : app.doc.handle ? '已保存' : (app.doc.savedAt ? '已保存副本' : '尚未保存');
248
- this.stateEl.classList.toggle('gbp-is-dirty', app.dirty);
249
- this.saveBtn.disabled = app.readOnly || !app.snapshot.slides.length;
250
- this.autosaveEl.checked = app.autosave;
251
- // 全屏态:同一位置切成「恢复」
252
- const fullscreen = !!app.pageFullscreen;
253
- this.fullscreenBtn.title = fullscreen ? '退出全屏' : '全屏';
254
- this.fullscreenBtn.setAttribute('aria-pressed', String(fullscreen));
255
- this.fullscreenBtn.innerHTML = `${icon(fullscreen ? 'fullscreenExit' : 'fullscreen', 14)}<span>${fullscreen ? '恢复' : '全屏'}</span>`;
256
- this.setPreview(app.preview);
257
- // 只读档锁掉纯编辑类菜单,放映/视图与文件菜单里的导出/打印照常可用
258
- const writeMenus = new Set(['edit', 'insert', 'slide', 'review']);
259
- this.el.querySelectorAll('[data-menu]').forEach((btn) => {
260
- btn.disabled = app.readOnly && writeMenus.has(btn.dataset.menu);
261
- });
262
- }
263
- }
1
+ // [文件] gbpptx·顶部菜单栏与文档头 —— 与 gbdocx / gbxlxs 一致:菜单栏一行 + 文档头一行(标题/重命名/自动保存/保存/下载/预览)
2
+
3
+ import { SHAPE_KINDS, SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
4
+ import { createOfficeHead } from 'gbofficeui/head';
5
+ import { icon } from './icons.js';
6
+ import { openMenu } from './menu.js';
7
+ import { openModal } from './dialogs.js';
8
+
9
+ const el = (tag, cls, text) => {
10
+ const node = document.createElement(tag);
11
+ if (cls) node.className = cls;
12
+ if (text != null) node.textContent = text;
13
+ return node;
14
+ };
15
+
16
+ const submenu = (label, items) => ({ label, children: items });
17
+
18
+ export class TitleBar {
19
+ constructor(app) {
20
+ this.app = app;
21
+ this.el = el('header', 'pp-topbar');
22
+ this.build();
23
+ this.buildHead();
24
+ this.refresh();
25
+ }
26
+
27
+ build() {
28
+ const defs = [
29
+ ['file', '文件', () => this.fileItems()],
30
+ ['edit', '编辑', () => this.editItems()],
31
+ ['insert', '插入', () => this.insertItems()],
32
+ ['slide', '幻灯片', () => this.slideItems()],
33
+ ['show', '放映', () => this.showItems()],
34
+ ['review', '审阅', () => this.reviewItems()],
35
+ ['view', '视图', () => this.viewItems()],
36
+ ];
37
+ const bar = el('div', 'pp-menubar');
38
+ for (const [key, label, items] of defs) {
39
+ const btn = el('button', 'pp-menubar__btn', label);
40
+ btn.type = 'button';
41
+ btn.dataset.menu = key;
42
+ btn.addEventListener('click', () => {
43
+ btn.classList.add('gbp-is-open');
44
+ openMenu({ anchor: btn, items: items(), onClose: () => btn.classList.remove('gbp-is-open') });
45
+ });
46
+ bar.appendChild(btn);
47
+ }
48
+ this.el.append(bar);
49
+ }
50
+
51
+ buildHead() {
52
+ const app = this.app;
53
+ // 文档头骨架来自 gbofficeui(标题 / 重命名 / 保存 / 下载 / 预览 / 全屏 三家同一套)
54
+ this.head = createOfficeHead({
55
+ className: 'pp-head',
56
+ icon,
57
+ title: app.doc.name || '新建演示',
58
+ autoSave: app.autosave,
59
+ rename: app.canRename() ? { onClick: (event) => app.renameDoc(event) } : null,
60
+ download: app.canDownload() ? { onClick: () => app.downloadDoc() } : null,
61
+ onSave: () => app.save(),
62
+ onPreview: () => app.setPreview(!app.preview),
63
+ onFullscreen: () => app.toggleFullscreen(),
64
+ });
65
+ this.headEl = this.head.el;
66
+ this.nameEl = this.head.titleEl;
67
+ this.stateEl = this.head.subEl;
68
+ this.autosaveEl = this.head.autosaveEl;
69
+ this.saveBtn = this.head.saveBtn;
70
+ this.previewBtn = this.head.previewBtn;
71
+ this.fullscreenBtn = this.head.fullscreenBtn;
72
+ this.autosaveEl.addEventListener('change', () => app.setAutosave(this.autosaveEl.checked));
73
+ }
74
+
75
+ /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
76
+ setPreview(on) {
77
+ const active = !!on;
78
+ this.previewBtn.classList.toggle('gbo-head__preview--on', active);
79
+ this.previewBtn.title = active ? '退出预览' : '预览模式';
80
+ this.previewBtn.setAttribute('aria-pressed', String(active));
81
+ this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
82
+ }
83
+
84
+ /* ===================== 菜单条目 ===================== */
85
+
86
+ fileItems() {
87
+ const app = this.app;
88
+ const hasSlides = app.snapshot.slides.length > 0;
89
+ const items = [
90
+ { label: '新建', shortcut: 'Ctrl+N', onClick: () => app.newDoc() },
91
+ { label: '打开…', shortcut: 'Ctrl+O', onClick: () => app.openFile() },
92
+ { divided: true },
93
+ { label: '保存', shortcut: 'Ctrl+S', disabled: !hasSlides, onClick: () => app.save() },
94
+ { label: '另存为…', shortcut: 'Ctrl+Shift+S', disabled: !hasSlides, onClick: () => app.saveAs(app.doc.name) },
95
+ { label: '自动保存', checked: app.autosave, onClick: () => app.setAutosave(!app.autosave) },
96
+ { divided: true },
97
+ { label: '导出 PPTX', disabled: !hasSlides, onClick: () => app.exportPptx() },
98
+ { label: '导出 PDF', disabled: !hasSlides, onClick: () => app.exportPdf() },
99
+ { label: '打印…', disabled: !hasSlides, onClick: () => app.exportPdf() },
100
+ { divided: true },
101
+ { label: '关闭', onClick: () => app.closeDocument() },
102
+ ];
103
+ // 只读档保留导出/打印,其余文件动作会替换或写回文档,一律禁用
104
+ if (!app.readOnly) return items;
105
+ const viewActions = new Set(['导出 PPTX', '导出 PDF', '打印…']);
106
+ return items.map((item) => ({ ...item, disabled: item.disabled || !viewActions.has(item.label) }));
107
+ }
108
+
109
+ editItems() {
110
+ const app = this.app;
111
+ const hasSel = app.selectedIds.length > 0 || Boolean(app.editing);
112
+ return [
113
+ { label: '撤销', shortcut: 'Ctrl+Z', disabled: !app.canUndo(), onClick: () => app.undo() },
114
+ { label: '重做', shortcut: 'Ctrl+Y', disabled: !app.canRedo(), onClick: () => app.redo() },
115
+ { divided: true },
116
+ { label: '剪切', shortcut: 'Ctrl+X', disabled: !hasSel, onClick: () => app.cutSelected() },
117
+ { label: '复制', shortcut: 'Ctrl+C', disabled: !hasSel, onClick: () => app.copySelected() },
118
+ { label: '粘贴', shortcut: 'Ctrl+V', disabled: !app.canPaste(), onClick: () => app.paste() },
119
+ { label: '粘贴为纯文本', onClick: () => app.pastePlain() },
120
+ { divided: true },
121
+ { label: '全选', shortcut: 'Ctrl+A', onClick: () => app.selectAll() },
122
+ { label: '查找…', shortcut: 'Ctrl+F', onClick: () => app.openFind(false) },
123
+ { label: '替换…', shortcut: 'Ctrl+H', onClick: () => app.openFind(true) },
124
+ ];
125
+ }
126
+
127
+ insertItems() {
128
+ const app = this.app;
129
+ return [
130
+ { label: '新建幻灯片', shortcut: 'Ctrl+M', onClick: () => app.addSlide() },
131
+ { divided: true },
132
+ submenu('表格', [2, 3, 4, 5].map((n) => ({
133
+ label: `${n}×${n} 表格`,
134
+ onClick: () => app.insertTable(n, n),
135
+ }))),
136
+ { label: '图片…', onClick: () => app.insert('image') },
137
+ submenu('形状', SHAPE_KINDS.map((s) => ({
138
+ label: s.label,
139
+ onClick: () => app.insert('shape', s.kind),
140
+ }))),
141
+ { label: '文本框', onClick: () => app.insert('text') },
142
+ { label: '线条', onClick: () => app.insert('line') },
143
+ { label: '箭头', onClick: () => app.insert('arrow') },
144
+ { divided: true },
145
+ { label: '备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
146
+ ];
147
+ }
148
+
149
+ slideItems() {
150
+ const app = this.app;
151
+ const count = app.snapshot.slides.length;
152
+ return [
153
+ { label: '新建幻灯片', shortcut: 'Ctrl+M', onClick: () => app.addSlide() },
154
+ { label: '复制幻灯片', onClick: () => app.dupSlide() },
155
+ { label: '删除幻灯片', disabled: count <= 1, onClick: () => app.delSlide() },
156
+ { divided: true },
157
+ { label: '隐藏幻灯片', checked: Boolean(app.currentSlide()?.hidden), onClick: () => app.toggleSlideHidden() },
158
+ submenu('版式', SLIDE_LAYOUTS.map((l) => ({
159
+ label: l.label,
160
+ onClick: () => app.addSlide(l.key),
161
+ }))),
162
+ submenu('切换', TRANSITIONS.map((t) => ({
163
+ label: t.label,
164
+ onClick: () => app.setTransition({ type: t.key, dir: t.dir || 'l' }),
165
+ }))),
166
+ { divided: true },
167
+ { label: '重设位置与大小', disabled: !app.selectedIds.length, onClick: () => app.resetSelected() },
168
+ { label: '设置背景格式…', onClick: () => app.openFormatPane() },
169
+ ];
170
+ }
171
+
172
+ showItems() {
173
+ const app = this.app;
174
+ return [
175
+ { label: '从头开始', shortcut: 'F5', onClick: () => app.presentFromStart() },
176
+ { label: '从当前页', shortcut: 'Shift+F5', onClick: () => app.presentFromCurrent() },
177
+ { divided: true },
178
+ { label: '演讲者视图', checked: app.presentOptions.presenter, onClick: () => app.togglePresenter() },
179
+ { label: '循环放映', checked: app.presentOptions.loop, onClick: () => app.toggleLoop() },
180
+ { label: '隐藏幻灯片', checked: Boolean(app.currentSlide()?.hidden), onClick: () => app.toggleSlideHidden() },
181
+ ];
182
+ }
183
+
184
+ reviewItems() {
185
+ const app = this.app;
186
+ return [
187
+ { label: '显示备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
188
+ { label: '字数统计…', onClick: () => app.showWordCount() },
189
+ ];
190
+ }
191
+
192
+ viewItems() {
193
+ const app = this.app;
194
+ return [
195
+ { label: '普通', checked: app.view === 'normal', onClick: () => app.setView('normal') },
196
+ { label: '幻灯片浏览', checked: app.view === 'sorter', onClick: () => app.setView('sorter') },
197
+ { label: '阅读视图', checked: app.view === 'reading', onClick: () => app.setView('reading') },
198
+ { divided: true },
199
+ { label: '网格线', checked: app.gridVisible, onClick: () => app.toggleGrid() },
200
+ { label: '参考线', checked: app.guidesVisible, onClick: () => app.toggleGuides() },
201
+ { label: '备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
202
+ { label: '设置形状格式窗格', checked: app.formatPaneOpen, onClick: () => app.toggleFormatPane() },
203
+ { divided: true },
204
+ { label: '适应窗口', onClick: () => app.fitToWindow() },
205
+ { label: '放大', shortcut: 'Ctrl+=', onClick: () => app.setZoom(app.zoom + 10) },
206
+ { label: '缩小', shortcut: 'Ctrl+-', onClick: () => app.setZoom(app.zoom - 10) },
207
+ { divided: true },
208
+ { label: '关于挂逼演示…', onClick: () => this.showAbout() },
209
+ ];
210
+ }
211
+
212
+ showAbout() {
213
+ openModal({
214
+ title: '关于',
215
+ width: 400,
216
+ confirmText: '知道了',
217
+ build: (body) => {
218
+ const p = el('div', 'pp-about');
219
+ p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
220
+ body.appendChild(p);
221
+ },
222
+ });
223
+ }
224
+
225
+ /* ===================== 状态刷新 ===================== */
226
+
227
+ refresh() {
228
+ const app = this.app;
229
+ this.nameEl.textContent = app.getTitle();
230
+ this.nameEl.title = this.nameEl.textContent;
231
+ document.title = `${this.nameEl.textContent} - 挂逼演示`;
232
+ // 嵌入模式:保存状态由宿主给(落盘结果只有宿主知道)
233
+ const hostStatus = app.host?.getStatus?.();
234
+ this.stateEl.textContent = hostStatus?.text
235
+ || (app.dirty
236
+ ? '未保存'
237
+ : app.doc.handle ? '已保存' : (app.doc.savedAt ? '已保存副本' : '尚未保存'));
238
+ this.stateEl.classList.toggle('gbp-is-dirty', app.dirty || hostStatus?.kind === 'dirty');
239
+ this.saveBtn.disabled = app.readOnly || !app.snapshot.slides.length;
240
+ this.autosaveEl.checked = app.autosave;
241
+ // 全屏态:同一位置切成「恢复」
242
+ const fullscreen = !!app.pageFullscreen;
243
+ this.fullscreenBtn.title = fullscreen ? '退出全屏' : '全屏';
244
+ this.fullscreenBtn.setAttribute('aria-pressed', String(fullscreen));
245
+ this.fullscreenBtn.innerHTML = `${icon(fullscreen ? 'fullscreenExit' : 'fullscreen', 14)}<span>${fullscreen ? '恢复' : '全屏'}</span>`;
246
+ this.setPreview(app.preview);
247
+ // 只读档锁掉纯编辑类菜单,放映/视图与文件菜单里的导出/打印照常可用
248
+ const writeMenus = new Set(['edit', 'insert', 'slide', 'review']);
249
+ this.el.querySelectorAll('[data-menu]').forEach((btn) => {
250
+ btn.disabled = app.readOnly && writeMenus.has(btn.dataset.menu);
251
+ });
252
+ }
253
+ }