gbpptx 0.6.1 → 0.6.2
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/LICENSE +21 -21
- package/README.md +253 -253
- package/package.json +48 -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/main.js +8 -8
- package/web/app/slides/arrange.js +101 -101
- package/web/app/slides/clipboard.js +93 -93
- package/web/app/slides/file.js +240 -240
- package/web/app/slides/find.js +201 -201
- package/web/app/slides/history.js +100 -100
- package/web/app/slides/keys.js +187 -187
- package/web/app/slides/menus.js +105 -105
- package/web/app/slides/objects.js +254 -254
- package/web/app/slides/render.js +183 -183
- package/web/app/slides/shared.js +85 -85
- package/web/app/slides/slides.js +103 -103
- package/web/app/slides/table.js +102 -102
- package/web/app/slides/text.js +418 -418
- package/web/app/slides/view.js +182 -182
- package/web/app/slides-app.js +354 -354
- package/web/app/ui/canvas.js +769 -769
- package/web/app/ui/color-panel.js +58 -58
- package/web/app/ui/dialogs.js +120 -120
- package/web/app/ui/file-io.js +116 -116
- package/web/app/ui/format-pane.js +427 -427
- package/web/app/ui/icons.js +241 -133
- package/web/app/ui/menu.js +77 -75
- package/web/app/ui/notify.js +45 -45
- package/web/app/ui/page-view.js +221 -221
- package/web/app/ui/popup.js +80 -80
- package/web/app/ui/present.js +292 -292
- package/web/app/ui/ribbon.js +855 -855
- package/web/app/ui/slide-pane.js +197 -197
- package/web/app/ui/statusbar.js +93 -93
- package/web/app/ui/text-styles.js +84 -84
- package/web/app/ui/titlebar.js +253 -253
- package/web/app/ui/transition.js +30 -30
- package/web/index.html +30 -29
- package/web/serve.mjs +26 -23
- package/web/styles/office.css +463 -463
- package/web/styles/slides.css +97 -97
- package/web/styles/tokens.css +154 -154
package/web/app/ui/titlebar.js
CHANGED
|
@@ -1,253 +1,253 @@
|
|
|
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
|
-
}
|
|
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
|
+
}
|
package/web/app/ui/transition.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
// [文件] gbpptx·切换动画 —— 放映与画布预览共用同一套 CSS 动画口径
|
|
2
|
-
|
|
3
|
-
const SPEED_MS = { fast: 500, med: 800, slow: 1500 };
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 对「刚进入的页容器」播放切换动画
|
|
7
|
-
* @param {HTMLElement} wrap 承载页面的容器
|
|
8
|
-
* @param {{type:string,dir:string,speed:string}} tr
|
|
9
|
-
*/
|
|
10
|
-
export function animateSlideFrame(wrap, tr) {
|
|
11
|
-
if (!wrap || !tr || tr.type === 'none') return;
|
|
12
|
-
const dur = SPEED_MS[tr.speed] || SPEED_MS.med;
|
|
13
|
-
const dir = tr.dir || 'l';
|
|
14
|
-
const tx = dir === 'l' ? '60px' : dir === 'r' ? '-60px' : '0';
|
|
15
|
-
const ty = dir === 'u' ? '60px' : dir === 'd' ? '-60px' : '0';
|
|
16
|
-
const easing = 'cubic-bezier(.2,.7,.2,1)';
|
|
17
|
-
if (tr.type === 'wipe') {
|
|
18
|
-
const from = dir === 'r' ? 'inset(0 0 0 100%)' : dir === 'u' ? 'inset(100% 0 0 0)' : dir === 'd' ? 'inset(0 0 100% 0)' : 'inset(0 100% 0 0)';
|
|
19
|
-
wrap.animate([{ clipPath: from }, { clipPath: 'inset(0 0 0 0)' }], { duration: dur, easing });
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (tr.type === 'split') {
|
|
23
|
-
wrap.animate([{ clipPath: 'inset(0 50% 0 50%)' }, { clipPath: 'inset(0 0 0 0)' }], { duration: dur, easing });
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
let frames = [{ opacity: 0 }, { opacity: 1 }];
|
|
27
|
-
if (tr.type === 'push' || tr.type === 'cover') frames = [{ transform: `translate(${tx}, ${ty})` }, { transform: 'translate(0, 0)' }];
|
|
28
|
-
if (tr.type === 'zoom') frames = [{ opacity: 0, transform: 'scale(1.08)' }, { opacity: 1, transform: 'scale(1)' }];
|
|
29
|
-
wrap.animate(frames, { duration: dur, easing, fill: 'both' });
|
|
30
|
-
}
|
|
1
|
+
// [文件] gbpptx·切换动画 —— 放映与画布预览共用同一套 CSS 动画口径
|
|
2
|
+
|
|
3
|
+
const SPEED_MS = { fast: 500, med: 800, slow: 1500 };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 对「刚进入的页容器」播放切换动画
|
|
7
|
+
* @param {HTMLElement} wrap 承载页面的容器
|
|
8
|
+
* @param {{type:string,dir:string,speed:string}} tr
|
|
9
|
+
*/
|
|
10
|
+
export function animateSlideFrame(wrap, tr) {
|
|
11
|
+
if (!wrap || !tr || tr.type === 'none') return;
|
|
12
|
+
const dur = SPEED_MS[tr.speed] || SPEED_MS.med;
|
|
13
|
+
const dir = tr.dir || 'l';
|
|
14
|
+
const tx = dir === 'l' ? '60px' : dir === 'r' ? '-60px' : '0';
|
|
15
|
+
const ty = dir === 'u' ? '60px' : dir === 'd' ? '-60px' : '0';
|
|
16
|
+
const easing = 'cubic-bezier(.2,.7,.2,1)';
|
|
17
|
+
if (tr.type === 'wipe') {
|
|
18
|
+
const from = dir === 'r' ? 'inset(0 0 0 100%)' : dir === 'u' ? 'inset(100% 0 0 0)' : dir === 'd' ? 'inset(0 0 100% 0)' : 'inset(0 100% 0 0)';
|
|
19
|
+
wrap.animate([{ clipPath: from }, { clipPath: 'inset(0 0 0 0)' }], { duration: dur, easing });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (tr.type === 'split') {
|
|
23
|
+
wrap.animate([{ clipPath: 'inset(0 50% 0 50%)' }, { clipPath: 'inset(0 0 0 0)' }], { duration: dur, easing });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let frames = [{ opacity: 0 }, { opacity: 1 }];
|
|
27
|
+
if (tr.type === 'push' || tr.type === 'cover') frames = [{ transform: `translate(${tx}, ${ty})` }, { transform: 'translate(0, 0)' }];
|
|
28
|
+
if (tr.type === 'zoom') frames = [{ opacity: 0, transform: 'scale(1.08)' }, { opacity: 1, transform: 'scale(1)' }];
|
|
29
|
+
wrap.animate(frames, { duration: dur, easing, fill: 'both' });
|
|
30
|
+
}
|
package/web/index.html
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<title>挂逼演示 gbpptx</title>
|
|
7
|
-
<link rel="stylesheet" href="/web/styles/tokens.css" />
|
|
8
|
-
<link rel="stylesheet" href="/web/styles/slides.css" />
|
|
9
|
-
<link rel="stylesheet" href="/web/styles/office.css" />
|
|
10
|
-
<link rel="stylesheet" href="/vendor/gbofficeui/styles/office-chrome.css" />
|
|
11
|
-
<style>
|
|
12
|
-
/* 独立运行时撑满视口;嵌入宿主由宿主容器给高度,不依赖这条 */
|
|
13
|
-
html, body { height: 100%; margin: 0; }
|
|
14
|
-
</style>
|
|
15
|
-
<script type="importmap">
|
|
16
|
-
{
|
|
17
|
-
"imports": {
|
|
18
|
-
"gbooxml": "/vendor/gbooxml/index.js",
|
|
19
|
-
"guabiutils": "/vendor/guabiutils/index.js",
|
|
20
|
-
"gbofficeui/head": "/vendor/gbofficeui/src/head.js"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
</
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>挂逼演示 gbpptx</title>
|
|
7
|
+
<link rel="stylesheet" href="/web/styles/tokens.css" />
|
|
8
|
+
<link rel="stylesheet" href="/web/styles/slides.css" />
|
|
9
|
+
<link rel="stylesheet" href="/web/styles/office.css" />
|
|
10
|
+
<link rel="stylesheet" href="/vendor/gbofficeui/styles/office-chrome.css" />
|
|
11
|
+
<style>
|
|
12
|
+
/* 独立运行时撑满视口;嵌入宿主由宿主容器给高度,不依赖这条 */
|
|
13
|
+
html, body { height: 100%; margin: 0; }
|
|
14
|
+
</style>
|
|
15
|
+
<script type="importmap">
|
|
16
|
+
{
|
|
17
|
+
"imports": {
|
|
18
|
+
"gbooxml": "/vendor/gbooxml/index.js",
|
|
19
|
+
"guabiutils": "/vendor/guabiutils/index.js",
|
|
20
|
+
"gbofficeui/head": "/vendor/gbofficeui/src/head.js",
|
|
21
|
+
"gbicons/nodes": "/vendor/gbicons/src/nodes.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<div id="app" class="gbp-root"></div>
|
|
28
|
+
<script type="module" src="/web/app/main.js"></script>
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|