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.
- package/README.md +16 -0
- package/package.json +47 -47
- package/src/index.js +29 -29
- package/src/kernel/model.js +651 -651
- package/src/kernel/parts.js +173 -173
- package/src/kernel/pptx.js +72 -72
- package/src/kernel/print.js +76 -76
- package/src/kernel/read.js +1018 -1018
- package/src/kernel/roundtrip.js +174 -174
- package/src/kernel/text.js +278 -278
- package/src/kernel/write.js +385 -385
- package/web/app/slides/file.js +29 -2
- package/web/app/slides-app.js +25 -1
- package/web/app/ui/icons.js +2 -0
- package/web/app/ui/titlebar.js +253 -263
- package/web/index.html +3 -2
- package/web/serve.mjs +3 -2
- package/web/styles/slides.css +1 -1
package/web/app/slides/file.js
CHANGED
|
@@ -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
|
-
|
|
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 };
|
package/web/app/slides-app.js
CHANGED
|
@@ -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
|
-
/**
|
|
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 = `
|
package/web/app/ui/icons.js
CHANGED
|
@@ -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) =>
|
package/web/app/ui/titlebar.js
CHANGED
|
@@ -1,263 +1,253 @@
|
|
|
1
|
-
// [文件] gbpptx·顶部菜单栏与文档头 —— 与 gbdocx / gbxlxs 一致:菜单栏一行 +
|
|
2
|
-
|
|
3
|
-
import { SHAPE_KINDS, SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.previewBtn =
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
{ label: '
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
{ label: '
|
|
131
|
-
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
{ label: '
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
{ label: '
|
|
144
|
-
{ divided: true },
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
{ label: '
|
|
155
|
-
{ label: '
|
|
156
|
-
{
|
|
157
|
-
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
{
|
|
167
|
-
{ label: '
|
|
168
|
-
{ label: '
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
{
|
|
180
|
-
{ label: '
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
{ label: '
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
{ label: '
|
|
201
|
-
{ label: '
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
{ label: '
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.
|
|
244
|
-
|
|
245
|
-
this.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
this.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
+
}
|