gbpptx 0.6.0 → 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.
Files changed (50) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +253 -253
  3. package/package.json +48 -47
  4. package/src/index.js +29 -29
  5. package/src/kernel/model.js +651 -651
  6. package/src/kernel/parts.js +173 -173
  7. package/src/kernel/pptx.js +72 -72
  8. package/src/kernel/print.js +76 -76
  9. package/src/kernel/read.js +1018 -1018
  10. package/src/kernel/roundtrip.js +174 -174
  11. package/src/kernel/text.js +278 -278
  12. package/src/kernel/write.js +385 -385
  13. package/web/app/main.js +8 -8
  14. package/web/app/slides/arrange.js +101 -101
  15. package/web/app/slides/clipboard.js +93 -93
  16. package/web/app/slides/file.js +240 -240
  17. package/web/app/slides/find.js +201 -201
  18. package/web/app/slides/history.js +100 -100
  19. package/web/app/slides/keys.js +187 -187
  20. package/web/app/slides/menus.js +105 -105
  21. package/web/app/slides/objects.js +254 -254
  22. package/web/app/slides/render.js +183 -183
  23. package/web/app/slides/shared.js +85 -85
  24. package/web/app/slides/slides.js +103 -103
  25. package/web/app/slides/table.js +102 -102
  26. package/web/app/slides/text.js +418 -418
  27. package/web/app/slides/view.js +182 -182
  28. package/web/app/slides-app.js +354 -354
  29. package/web/app/ui/canvas.js +769 -769
  30. package/web/app/ui/color-panel.js +58 -58
  31. package/web/app/ui/dialogs.js +120 -120
  32. package/web/app/ui/file-io.js +116 -116
  33. package/web/app/ui/format-pane.js +427 -427
  34. package/web/app/ui/icons.js +241 -133
  35. package/web/app/ui/menu.js +77 -75
  36. package/web/app/ui/notify.js +45 -45
  37. package/web/app/ui/page-view.js +221 -221
  38. package/web/app/ui/popup.js +80 -80
  39. package/web/app/ui/present.js +292 -292
  40. package/web/app/ui/ribbon.js +855 -855
  41. package/web/app/ui/slide-pane.js +197 -197
  42. package/web/app/ui/statusbar.js +93 -93
  43. package/web/app/ui/text-styles.js +84 -84
  44. package/web/app/ui/titlebar.js +253 -250
  45. package/web/app/ui/transition.js +30 -30
  46. package/web/index.html +30 -29
  47. package/web/serve.mjs +26 -23
  48. package/web/styles/office.css +463 -463
  49. package/web/styles/slides.css +97 -97
  50. package/web/styles/tokens.css +154 -154
@@ -1,240 +1,240 @@
1
- // [文件] gbpptx·slides·file —— 文件动作 —— 新建/打开/导入/保存/导出/关闭
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { downloadBlob, stripExt } from 'guabiutils';
7
- import { createDraft, normalizeSnapshot } from '../../../src/kernel/model.js';
8
- import { buildPptxVerified } from '../../../src/kernel/roundtrip.js';
9
- import { parsePptx } from '../../../src/kernel/read.js';
10
- import { printSlides } from '../../../src/kernel/print.js';
11
- import { notify } from '../ui/notify.js';
12
- import { renderPage } from '../ui/page-view.js';
13
- import { PPTX_MIME, ensureExt, isPptxFile, openPptx, readBytes, savePptx, savePptxAs } from '../ui/file-io.js';
14
- import { openModal, promptText } from '../ui/dialogs.js';
15
- import { savePrefs } from './shared.js';
16
- function resetDoc(draft, name, handle = null) {
17
- this.snapshot = draft;
18
- this.doc = { name, handle, savedAt: 0 };
19
- this.snapshot.title = name;
20
- this.index = 0;
21
- this.selectedIds = [];
22
- this.editing = null;
23
- this.history = [];
24
- this.future = [];
25
- this.revision = 0;
26
- this.dirty = false;
27
- this.lastBytes = null;
28
- this.tableCursor = null;
29
- this.notesSession = false;
30
- this.view = 'normal';
31
- this.closeFind();
32
- this.renderAll();
33
- this.titlebar.refresh();
34
- }
35
-
36
- async function confirmDiscard(action) {
37
- if (!this.dirty) return true;
38
- return new Promise((resolve) => {
39
- let confirmed = false;
40
- openModal({
41
- title: action || '放弃更改?',
42
- width: 420,
43
- confirmText: '继续',
44
- build: (body) => {
45
- const message = document.createElement('p');
46
- message.className = 'gbp-modal__message';
47
- message.textContent = '当前演示有未保存的更改,继续将丢弃这些更改。';
48
- body.appendChild(message);
49
- },
50
- onConfirm: () => {
51
- confirmed = true;
52
- },
53
- onClose: () => resolve(confirmed),
54
- });
55
- });
56
- }
57
-
58
- function newDoc() {
59
- this.confirmDiscard('新建演示文稿').then((ok) => {
60
- if (!ok) return;
61
- const draft = createDraft();
62
- const seq = Number(this.prefs.docSeq) || 1;
63
- this.prefs.docSeq = seq + 1;
64
- savePrefs(this.prefs);
65
- this.resetDoc(draft, `演示文稿${seq}`);
66
- notify.success('已新建空白演示');
67
- });
68
- }
69
-
70
- async function openFile() {
71
- if (!(await this.confirmDiscard('打开演示文稿'))) return;
72
- try {
73
- const picked = await openPptx();
74
- if (!picked) return;
75
- await this.applyBytes(picked.bytes, picked.name);
76
- this.doc.handle = picked.handle;
77
- this.doc.name = stripExt(picked.name) || '新建演示';
78
- this.snapshot.title = this.doc.name;
79
- this.titlebar.refresh();
80
- notify.success(`已打开 ${picked.name}`);
81
- } catch (err) {
82
- notify.error(`打开失败:${err.message || err}`);
83
- }
84
- }
85
-
86
- async function importFile(file) {
87
- if (!file) return;
88
- if (!isPptxFile(file)) {
89
- if (/^image\/(png|jpeg|gif)$/i.test(file.type || '')) return this.insertImageFile(file);
90
- notify.error('请选择 .pptx 演示文稿或 PNG/JPEG/GIF 图片');
91
- return;
92
- }
93
- if (!(await this.confirmDiscard('打开演示文稿'))) return;
94
- try {
95
- const bytes = await readBytes(file);
96
- await this.applyBytes(bytes, file.name);
97
- notify.success(`已打开 ${file.name}`);
98
- } catch (err) {
99
- notify.error(`打开失败:${err.message || err}`);
100
- }
101
- }
102
-
103
- async function applyBytes(bytes, name) {
104
- const raw = await parsePptx(bytes);
105
- const snap = normalizeSnapshot(raw);
106
- if (!snap) throw new Error('文件内容无法识别');
107
- this.snapshot = snap;
108
- this.doc = { name: stripExt(name) || '新建演示', handle: null, savedAt: 0 };
109
- this.snapshot.title = this.doc.name;
110
- this.index = 0;
111
- this.selectedIds = [];
112
- this.editing = null;
113
- this.history = [];
114
- this.future = [];
115
- this.revision = 0;
116
- this.dirty = false;
117
- this.lastBytes = bytes;
118
- this.tableCursor = null;
119
- this.notesSession = false;
120
- this.view = 'normal';
121
- this.closeFind();
122
- this.renderAll();
123
- this.fitToWindow();
124
- const w = raw.warnings || {};
125
- const parts = [];
126
- if (w.groups) parts.push(`${w.groups} 个组合已摊平`);
127
- if (w.charts) parts.push(`${w.charts} 个图表已跳过`);
128
- if (w.media) parts.push(`${w.media} 个音视频已跳过`);
129
- if (w.unknown) parts.push(`${w.unknown} 个未知元素已跳过`);
130
- if (parts.length) notify.warning(`已导入;${parts.join('、')}`);
131
- return snap;
132
- }
133
-
134
- async function save(silent = false) {
135
- if (!this.snapshot.slides.length) return false;
136
- if (!this.doc.handle) return this.saveAs(this.doc.name);
137
- if (this.saving) return false;
138
- this.saving = true;
139
- const rev = this.revision;
140
- this.statusbar.setStatus('正在保存…');
141
- try {
142
- this.snapshot.title = this.doc.name;
143
- const bytes = await buildPptxVerified(this.snapshot);
144
- await savePptx(bytes, ensureExt(this.doc.name, '.pptx'), this.doc.handle);
145
- this.lastBytes = bytes;
146
- this.doc.savedAt = Date.now();
147
- if (this.revision === rev) this.setDirty(false);
148
- this.statusbar.setStatus('已保存');
149
- setTimeout(() => this.statusbar.setStatus(''), 1600);
150
- if (!silent) notify.success('已保存');
151
- return true;
152
- } catch (err) {
153
- this.statusbar.setStatus('保存失败');
154
- notify.error(`保存失败:${err.message || err}`);
155
- return false;
156
- } finally {
157
- this.saving = false;
158
- }
159
- }
160
-
161
- async function saveAs(name) {
162
- if (!this.snapshot.slides.length) return false;
163
- if (this.saving) return false;
164
- this.saving = true;
165
- try {
166
- const suggested = stripExt(name || this.doc.name || '新建演示') || '新建演示';
167
- this.snapshot.title = suggested;
168
- const bytes = await buildPptxVerified(this.snapshot);
169
- const result = await savePptxAs(bytes, suggested);
170
- if (!result.saved) return false;
171
- this.doc = { name: stripExt(result.name || suggested), handle: result.handle, savedAt: Date.now() };
172
- this.snapshot.title = this.doc.name;
173
- this.lastBytes = bytes;
174
- this.setDirty(false);
175
- this.titlebar.refresh();
176
- notify.success('已另存为');
177
- return true;
178
- } catch (err) {
179
- notify.error(`另存失败:${err.message || err}`);
180
- return false;
181
- } finally {
182
- this.saving = false;
183
- }
184
- }
185
-
186
- async function exportPptx() {
187
- if (!this.snapshot.slides.length) return;
188
- try {
189
- this.snapshot.title = this.doc.name;
190
- const bytes = await buildPptxVerified(this.snapshot);
191
- this.lastBytes = bytes;
192
- downloadBlob(new Blob([bytes], { type: PPTX_MIME }), ensureExt(this.doc.name || '新建演示', '.pptx'));
193
- notify.success('已导出 .pptx');
194
- } catch (err) {
195
- notify.error(`导出失败:${err.message || err}`);
196
- }
197
- }
198
-
199
- function exportPdf() {
200
- this.commitEditing({ render: false });
201
- printSlides(this.snapshot.slides, this.snapshot.theme, renderPage, this.size);
202
- }
203
-
204
- async function closeDocument() {
205
- if (!(await this.confirmDiscard('关闭演示文稿'))) return;
206
- const seq = Number(this.prefs.docSeq) || 1;
207
- this.prefs.docSeq = seq + 1;
208
- savePrefs(this.prefs);
209
- this.resetDoc(createDraft(), `演示文稿${seq}`);
210
- notify.success('演示文稿已关闭');
211
- }
212
-
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 };
1
+ // [文件] gbpptx·slides·file —— 文件动作 —— 新建/打开/导入/保存/导出/关闭
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { downloadBlob, stripExt } from 'guabiutils';
7
+ import { createDraft, normalizeSnapshot } from '../../../src/kernel/model.js';
8
+ import { buildPptxVerified } from '../../../src/kernel/roundtrip.js';
9
+ import { parsePptx } from '../../../src/kernel/read.js';
10
+ import { printSlides } from '../../../src/kernel/print.js';
11
+ import { notify } from '../ui/notify.js';
12
+ import { renderPage } from '../ui/page-view.js';
13
+ import { PPTX_MIME, ensureExt, isPptxFile, openPptx, readBytes, savePptx, savePptxAs } from '../ui/file-io.js';
14
+ import { openModal, promptText } from '../ui/dialogs.js';
15
+ import { savePrefs } from './shared.js';
16
+ function resetDoc(draft, name, handle = null) {
17
+ this.snapshot = draft;
18
+ this.doc = { name, handle, savedAt: 0 };
19
+ this.snapshot.title = name;
20
+ this.index = 0;
21
+ this.selectedIds = [];
22
+ this.editing = null;
23
+ this.history = [];
24
+ this.future = [];
25
+ this.revision = 0;
26
+ this.dirty = false;
27
+ this.lastBytes = null;
28
+ this.tableCursor = null;
29
+ this.notesSession = false;
30
+ this.view = 'normal';
31
+ this.closeFind();
32
+ this.renderAll();
33
+ this.titlebar.refresh();
34
+ }
35
+
36
+ async function confirmDiscard(action) {
37
+ if (!this.dirty) return true;
38
+ return new Promise((resolve) => {
39
+ let confirmed = false;
40
+ openModal({
41
+ title: action || '放弃更改?',
42
+ width: 420,
43
+ confirmText: '继续',
44
+ build: (body) => {
45
+ const message = document.createElement('p');
46
+ message.className = 'gbp-modal__message';
47
+ message.textContent = '当前演示有未保存的更改,继续将丢弃这些更改。';
48
+ body.appendChild(message);
49
+ },
50
+ onConfirm: () => {
51
+ confirmed = true;
52
+ },
53
+ onClose: () => resolve(confirmed),
54
+ });
55
+ });
56
+ }
57
+
58
+ function newDoc() {
59
+ this.confirmDiscard('新建演示文稿').then((ok) => {
60
+ if (!ok) return;
61
+ const draft = createDraft();
62
+ const seq = Number(this.prefs.docSeq) || 1;
63
+ this.prefs.docSeq = seq + 1;
64
+ savePrefs(this.prefs);
65
+ this.resetDoc(draft, `演示文稿${seq}`);
66
+ notify.success('已新建空白演示');
67
+ });
68
+ }
69
+
70
+ async function openFile() {
71
+ if (!(await this.confirmDiscard('打开演示文稿'))) return;
72
+ try {
73
+ const picked = await openPptx();
74
+ if (!picked) return;
75
+ await this.applyBytes(picked.bytes, picked.name);
76
+ this.doc.handle = picked.handle;
77
+ this.doc.name = stripExt(picked.name) || '新建演示';
78
+ this.snapshot.title = this.doc.name;
79
+ this.titlebar.refresh();
80
+ notify.success(`已打开 ${picked.name}`);
81
+ } catch (err) {
82
+ notify.error(`打开失败:${err.message || err}`);
83
+ }
84
+ }
85
+
86
+ async function importFile(file) {
87
+ if (!file) return;
88
+ if (!isPptxFile(file)) {
89
+ if (/^image\/(png|jpeg|gif)$/i.test(file.type || '')) return this.insertImageFile(file);
90
+ notify.error('请选择 .pptx 演示文稿或 PNG/JPEG/GIF 图片');
91
+ return;
92
+ }
93
+ if (!(await this.confirmDiscard('打开演示文稿'))) return;
94
+ try {
95
+ const bytes = await readBytes(file);
96
+ await this.applyBytes(bytes, file.name);
97
+ notify.success(`已打开 ${file.name}`);
98
+ } catch (err) {
99
+ notify.error(`打开失败:${err.message || err}`);
100
+ }
101
+ }
102
+
103
+ async function applyBytes(bytes, name) {
104
+ const raw = await parsePptx(bytes);
105
+ const snap = normalizeSnapshot(raw);
106
+ if (!snap) throw new Error('文件内容无法识别');
107
+ this.snapshot = snap;
108
+ this.doc = { name: stripExt(name) || '新建演示', handle: null, savedAt: 0 };
109
+ this.snapshot.title = this.doc.name;
110
+ this.index = 0;
111
+ this.selectedIds = [];
112
+ this.editing = null;
113
+ this.history = [];
114
+ this.future = [];
115
+ this.revision = 0;
116
+ this.dirty = false;
117
+ this.lastBytes = bytes;
118
+ this.tableCursor = null;
119
+ this.notesSession = false;
120
+ this.view = 'normal';
121
+ this.closeFind();
122
+ this.renderAll();
123
+ this.fitToWindow();
124
+ const w = raw.warnings || {};
125
+ const parts = [];
126
+ if (w.groups) parts.push(`${w.groups} 个组合已摊平`);
127
+ if (w.charts) parts.push(`${w.charts} 个图表已跳过`);
128
+ if (w.media) parts.push(`${w.media} 个音视频已跳过`);
129
+ if (w.unknown) parts.push(`${w.unknown} 个未知元素已跳过`);
130
+ if (parts.length) notify.warning(`已导入;${parts.join('、')}`);
131
+ return snap;
132
+ }
133
+
134
+ async function save(silent = false) {
135
+ if (!this.snapshot.slides.length) return false;
136
+ if (!this.doc.handle) return this.saveAs(this.doc.name);
137
+ if (this.saving) return false;
138
+ this.saving = true;
139
+ const rev = this.revision;
140
+ this.statusbar.setStatus('正在保存…');
141
+ try {
142
+ this.snapshot.title = this.doc.name;
143
+ const bytes = await buildPptxVerified(this.snapshot);
144
+ await savePptx(bytes, ensureExt(this.doc.name, '.pptx'), this.doc.handle);
145
+ this.lastBytes = bytes;
146
+ this.doc.savedAt = Date.now();
147
+ if (this.revision === rev) this.setDirty(false);
148
+ this.statusbar.setStatus('已保存');
149
+ setTimeout(() => this.statusbar.setStatus(''), 1600);
150
+ if (!silent) notify.success('已保存');
151
+ return true;
152
+ } catch (err) {
153
+ this.statusbar.setStatus('保存失败');
154
+ notify.error(`保存失败:${err.message || err}`);
155
+ return false;
156
+ } finally {
157
+ this.saving = false;
158
+ }
159
+ }
160
+
161
+ async function saveAs(name) {
162
+ if (!this.snapshot.slides.length) return false;
163
+ if (this.saving) return false;
164
+ this.saving = true;
165
+ try {
166
+ const suggested = stripExt(name || this.doc.name || '新建演示') || '新建演示';
167
+ this.snapshot.title = suggested;
168
+ const bytes = await buildPptxVerified(this.snapshot);
169
+ const result = await savePptxAs(bytes, suggested);
170
+ if (!result.saved) return false;
171
+ this.doc = { name: stripExt(result.name || suggested), handle: result.handle, savedAt: Date.now() };
172
+ this.snapshot.title = this.doc.name;
173
+ this.lastBytes = bytes;
174
+ this.setDirty(false);
175
+ this.titlebar.refresh();
176
+ notify.success('已另存为');
177
+ return true;
178
+ } catch (err) {
179
+ notify.error(`另存失败:${err.message || err}`);
180
+ return false;
181
+ } finally {
182
+ this.saving = false;
183
+ }
184
+ }
185
+
186
+ async function exportPptx() {
187
+ if (!this.snapshot.slides.length) return;
188
+ try {
189
+ this.snapshot.title = this.doc.name;
190
+ const bytes = await buildPptxVerified(this.snapshot);
191
+ this.lastBytes = bytes;
192
+ downloadBlob(new Blob([bytes], { type: PPTX_MIME }), ensureExt(this.doc.name || '新建演示', '.pptx'));
193
+ notify.success('已导出 .pptx');
194
+ } catch (err) {
195
+ notify.error(`导出失败:${err.message || err}`);
196
+ }
197
+ }
198
+
199
+ function exportPdf() {
200
+ this.commitEditing({ render: false });
201
+ printSlides(this.snapshot.slides, this.snapshot.theme, renderPage, this.size);
202
+ }
203
+
204
+ async function closeDocument() {
205
+ if (!(await this.confirmDiscard('关闭演示文稿'))) return;
206
+ const seq = Number(this.prefs.docSeq) || 1;
207
+ this.prefs.docSeq = seq + 1;
208
+ savePrefs(this.prefs);
209
+ this.resetDoc(createDraft(), `演示文稿${seq}`);
210
+ notify.success('演示文稿已关闭');
211
+ }
212
+
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 };