gbpptx 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +220 -158
  2. package/package.json +15 -4
  3. package/src/index.js +16 -8
  4. package/src/kernel/model.js +397 -91
  5. package/src/kernel/parts.js +3 -3
  6. package/src/kernel/pptx.js +17 -12
  7. package/src/kernel/read.js +747 -157
  8. package/src/kernel/roundtrip.js +118 -18
  9. package/src/kernel/text.js +133 -28
  10. package/src/kernel/write.js +160 -49
  11. package/web/app/main.js +8 -8
  12. package/web/app/slides/arrange.js +101 -0
  13. package/web/app/slides/clipboard.js +93 -0
  14. package/web/app/slides/file.js +243 -0
  15. package/web/app/slides/find.js +199 -0
  16. package/web/app/slides/history.js +100 -0
  17. package/web/app/slides/keys.js +174 -0
  18. package/web/app/slides/menus.js +105 -0
  19. package/web/app/slides/objects.js +254 -0
  20. package/web/app/slides/render.js +183 -0
  21. package/web/app/slides/shared.js +85 -0
  22. package/web/app/slides/slides.js +103 -0
  23. package/web/app/slides/table.js +102 -0
  24. package/web/app/slides/text.js +418 -0
  25. package/web/app/slides/view.js +130 -0
  26. package/web/app/slides-app.js +285 -844
  27. package/web/app/ui/backstage.js +255 -0
  28. package/web/app/ui/canvas.js +762 -277
  29. package/web/app/ui/color-panel.js +58 -58
  30. package/web/app/ui/dialogs.js +120 -120
  31. package/web/app/ui/file-io.js +116 -89
  32. package/web/app/ui/format-pane.js +427 -0
  33. package/web/app/ui/icons.js +129 -0
  34. package/web/app/ui/menu.js +75 -105
  35. package/web/app/ui/notify.js +45 -45
  36. package/web/app/ui/page-view.js +221 -150
  37. package/web/app/ui/popup.js +80 -80
  38. package/web/app/ui/present.js +292 -100
  39. package/web/app/ui/ribbon.js +878 -0
  40. package/web/app/ui/slide-pane.js +189 -0
  41. package/web/app/ui/statusbar.js +93 -0
  42. package/web/app/ui/text-styles.js +84 -84
  43. package/web/app/ui/titlebar.js +208 -0
  44. package/web/app/ui/transition.js +30 -0
  45. package/web/index.html +23 -21
  46. package/web/serve.mjs +20 -67
  47. package/web/styles/office.css +642 -0
  48. package/web/styles/slides.css +210 -212
  49. package/web/styles/tokens.css +154 -155
  50. package/src/kernel/menus.js +0 -123
  51. package/src/kernel/util/escape.js +0 -21
  52. package/src/kernel/util/id.js +0 -13
  53. package/web/app/ui/inspector.js +0 -209
  54. package/web/app/ui/slides-bar.js +0 -63
  55. package/web/app/ui/toolbar.js +0 -200
@@ -1,844 +1,285 @@
1
- // [文件] gbpptx·SlidesApp —— 演示编辑器装配(画布/页栏/检查器/工具栏/菜单/放映/文件读写)
2
-
3
- import {
4
- SHAPE_KINDS, SLIDE_H, SLIDE_W, cloneObject, copySlide, createDraft, createImageObject, createLineObject,
5
- createShapeObject, createSlide, createSlideWithLayout, createTableObject, createTextObject, normalizeSnapshot,
6
- objectRect, setObjectFontSize, topZ,
7
- } 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 { buildMenus } from '../../src/kernel/menus.js';
12
- import { notify } from './ui/notify.js';
13
- import { buildMenuBar, openContextMenu } from './ui/menu.js';
14
- import { buildToolbar } from './ui/toolbar.js';
15
- import { Canvas } from './ui/canvas.js';
16
- import { Inspector } from './ui/inspector.js';
17
- import { SlidesBar } from './ui/slides-bar.js';
18
- import { Present } from './ui/present.js';
19
- import { renderPage } from './ui/page-view.js';
20
- import { promptText } from './ui/dialogs.js';
21
- import { openPptx, savePptx, savePptxAs, downloadBlob, ensureExt, PPTX_MIME } from './ui/file-io.js';
22
-
23
- const LS_KEY = 'gbpptx.prefs';
24
- const HISTORY_LIMIT = 60;
25
- const EMPTY = { version: 1, title: '', theme: 'clean', slides: [createSlide()] };
26
-
27
- export class SlidesApp {
28
- constructor(mount) {
29
- this.mount = mount;
30
- this.doc = { name: '新建演示', handle: null };
31
- this.snapshot = createDraft();
32
- this.index = 0;
33
- this.selectedIds = [];
34
- this.zoom = 60;
35
- this.dirty = false;
36
- this.saving = false;
37
- this.history = [];
38
- this.future = [];
39
- this.clipboard = null;
40
- this.prefs = loadPrefs();
41
- this.autosave = !!this.prefs.autosave;
42
- this.notesVisible = true;
43
- this.presenter = new Present({ getSlides: () => this.snapshot.slides, getTheme: () => this.snapshot.theme });
44
- this.build();
45
- }
46
-
47
- /* ===================== 骨架 ===================== */
48
-
49
- build() {
50
- const root = document.createElement('div');
51
- root.className = 'slides-app';
52
- root.innerHTML = `
53
- <div class="sl-menubar-host"></div>
54
- <div class="sl-head">
55
- <span class="sl-head__title"></span>
56
- <span class="sl-head__path"></span>
57
- <span class="sl-head__dirty" hidden>●</span>
58
- <span class="sl-head__spacer"></span>
59
- <label class="sl-head__auto"><input type="checkbox" class="sl-head__autosave" />自动保存</label>
60
- <button type="button" class="gb-btn" data-act="open">打开</button>
61
- <button type="button" class="gb-btn" data-act="save">保存</button>
62
- <button type="button" class="gb-btn" data-act="export">导出 pptx</button>
63
- </div>
64
- <div class="sl-toolbar-host"></div>
65
- <div class="sl-main"></div>
66
- <div class="sl-statusbar">
67
- <span data-k="info">第 1 / 1 页</span>
68
- <span data-k="objects">对象 0</span>
69
- <span class="sl-statusbar__spacer"></span>
70
- <button type="button" class="sl-statusbar__btn" data-act="notes">备注</button>
71
- <button type="button" class="sl-statusbar__btn" data-act="present">放映</button>
72
- <button type="button" class="sl-statusbar__btn" data-act="zoomOut">−</button>
73
- <button type="button" class="sl-statusbar__btn" data-act="zoomReset"><span data-k="zoom">60%</span></button>
74
- <button type="button" class="sl-statusbar__btn" data-act="zoomIn">+</button>
75
- </div>`;
76
- this.mount.appendChild(root);
77
- this.root = root;
78
- this.titleEl = root.querySelector('.sl-head__title');
79
- this.pathEl = root.querySelector('.sl-head__path');
80
- this.dirtyEl = root.querySelector('.sl-head__dirty');
81
- this.autosaveEl = root.querySelector('.sl-head__autosave');
82
- const main = root.querySelector('.sl-main');
83
-
84
- this.slidesBar = new SlidesBar(this);
85
- this.canvas = new Canvas(this);
86
- this.inspector = new Inspector(this);
87
- this.slidesBar.el.style.display = 'flex';
88
- main.append(this.slidesBar.el, this.canvas.el, this.inspector.el);
89
-
90
- const toolbar = buildToolbar(this);
91
- this.toolbar = toolbar;
92
- root.querySelector('.sl-toolbar-host').appendChild(toolbar.el);
93
-
94
- root.querySelector('.sl-menubar-host').appendChild(buildMenuBar(buildMenus(this.menuCtx())));
95
-
96
- this.bindHead();
97
- this.bindStatus();
98
- this.bindKeys();
99
- this.canvas.el.addEventListener('contextmenu', (e) => {
100
- e.preventDefault();
101
- this.openObjectMenu(e.clientX, e.clientY);
102
- });
103
- this.autosaveEl.checked = this.autosave;
104
- }
105
-
106
- bindHead() {
107
- this.root.querySelector('[data-act="open"]').addEventListener('click', () => this.openFile());
108
- this.root.querySelector('[data-act="save"]').addEventListener('click', () => this.save());
109
- this.root.querySelector('[data-act="export"]').addEventListener('click', () => this.exportPptx());
110
- this.autosaveEl.addEventListener('change', () => {
111
- this.autosave = this.autosaveEl.checked;
112
- this.prefs.autosave = this.autosave;
113
- savePrefs(this.prefs);
114
- });
115
- }
116
-
117
- bindStatus() {
118
- const r = this.root;
119
- r.querySelector('[data-act="present"]').addEventListener('click', () => this.present());
120
- r.querySelector('[data-act="zoomIn"]').addEventListener('click', () => this.setZoom(this.zoom + 10));
121
- r.querySelector('[data-act="zoomOut"]').addEventListener('click', () => this.setZoom(this.zoom - 10));
122
- r.querySelector('[data-act="zoomReset"]').addEventListener('click', () => this.setZoom(60));
123
- r.querySelector('[data-act="notes"]').addEventListener('click', () => this.toggleNotes());
124
- }
125
-
126
- toggleNotes() {
127
- this.notesVisible = !this.notesVisible;
128
- this.slidesBar.el.querySelector('.sl-notes').style.display = this.notesVisible ? '' : 'none';
129
- }
130
-
131
- bindKeys() {
132
- document.addEventListener('keydown', (e) => {
133
- const typing = e.target instanceof Element && (e.target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(e.target.tagName));
134
- if (typing && e.key !== 'Escape') return;
135
- const mod = e.ctrlKey || e.metaKey;
136
- const k = e.key.toLowerCase();
137
- if (mod && !e.altKey) {
138
- if (k === 's') { e.preventDefault(); e.shiftKey ? this.saveAs() : this.save(); return; }
139
- if (k === 'o') { e.preventDefault(); this.openFile(); return; }
140
- if (k === 'z') { e.preventDefault(); this.undo(); return; }
141
- if (k === 'y') { e.preventDefault(); this.redo(); return; }
142
- if (k === 'd') { e.preventDefault(); this.selectedIds.length ? this.duplicateSelected() : this.dupSlide(); return; }
143
- if (k === 'm') { e.preventDefault(); this.addSlide(); return; }
144
- if (k === 'a') { e.preventDefault(); this.selectObjects(this.currentSlide().objects.map((o) => o.id)); return; }
145
- if (k === 'c') { this.copySelected(); return; }
146
- if (k === 'x') { this.cutSelected(); return; }
147
- if (k === 'v') { this.paste(); return; }
148
- if (k === '=' || k === '+') { e.preventDefault(); this.setZoom(this.zoom + 10); return; }
149
- if (k === '-') { e.preventDefault(); this.setZoom(this.zoom - 10); return; }
150
- if (k === '0') { e.preventDefault(); this.setZoom(60); return; }
151
- if (k === 'n' && e.altKey) { e.preventDefault(); this.newDoc(); return; }
152
- }
153
- if (e.key === 'F5') { e.preventDefault(); this.present(); return; }
154
- if (e.key === 'Delete' || e.key === 'Backspace') {
155
- if (this.selectedIds.length) { e.preventDefault(); this.removeSelected(); }
156
- return;
157
- }
158
- if (e.key === 'Escape') this.clearSelection();
159
- });
160
- }
161
-
162
- /* ===================== 渲染 ===================== */
163
-
164
- renderAll(opts = {}) {
165
- this.index = Math.max(0, Math.min(this.snapshot.slides.length - 1, this.index));
166
- if (opts.thumbs !== false) {
167
- this.slidesBar.render();
168
- this.slidesBar.scrollToActive();
169
- }
170
- this.canvas.render();
171
- this.inspector.render();
172
- this.toolbar.refresh();
173
- this.renderHead();
174
- this.renderStatus();
175
- }
176
-
177
- renderHead() {
178
- this.titleEl.textContent = this.doc.name || '新建演示';
179
- this.pathEl.textContent = this.doc.handle ? '(已关联文件)' : '(未关联文件,保存将另存为)';
180
- this.dirtyEl.hidden = !this.dirty;
181
- }
182
-
183
- renderStatus() {
184
- this.root.querySelector('[data-k="info"]').textContent = `第 ${this.index + 1} / ${this.snapshot.slides.length} 页`;
185
- this.root.querySelector('[data-k="objects"]').textContent = `对象 ${this.currentSlide().objects.length}`;
186
- this.root.querySelector('[data-k="zoom"]').textContent = `${this.zoom}%`;
187
- }
188
-
189
- /** 文档已变更:置脏 + 排期自动保存 + 重渲染 */
190
- notifyChange(opts) {
191
- this.setDirty(true);
192
- if (this.autosave) this.scheduleAutosave();
193
- this.renderAll(opts);
194
- }
195
-
196
- setDirty(on) {
197
- this.dirty = on;
198
- this.dirtyEl.hidden = !on;
199
- }
200
-
201
- scheduleAutosave() {
202
- clearTimeout(this._autoTimer);
203
- this._autoTimer = setTimeout(() => {
204
- if (this.dirty && this.doc.handle) this.save(true);
205
- }, 2500);
206
- }
207
-
208
- /* ===================== 历史 ===================== */
209
-
210
- pushHistory() {
211
- this.history.push(JSON.stringify(this.snapshot));
212
- if (this.history.length > HISTORY_LIMIT) this.history.shift();
213
- this.future = [];
214
- }
215
-
216
- canUndo() { return this.history.length > 0; }
217
- canRedo() { return this.future.length > 0; }
218
-
219
- undo() {
220
- if (!this.history.length) return;
221
- this.future.push(JSON.stringify(this.snapshot));
222
- this.snapshot = JSON.parse(this.history.pop());
223
- this.selectedIds = [];
224
- this.notifyChange();
225
- }
226
-
227
- redo() {
228
- if (!this.future.length) return;
229
- this.history.push(JSON.stringify(this.snapshot));
230
- this.snapshot = JSON.parse(this.future.pop());
231
- this.selectedIds = [];
232
- this.notifyChange();
233
- }
234
-
235
- /* ===================== 选择 ===================== */
236
-
237
- currentSlide() {
238
- return this.snapshot.slides[this.index] || this.snapshot.slides[0];
239
- }
240
-
241
- selectedById(id) {
242
- return this.currentSlide().objects.find((o) => o.id === id) || null;
243
- }
244
-
245
- firstSelected() {
246
- return this.selectedById(this.selectedIds[0]);
247
- }
248
-
249
- selectObjects(ids) {
250
- this.selectedIds = [...new Set(ids)];
251
- this.canvas.syncSelection();
252
- this.inspector.render();
253
- this.toolbar.refresh();
254
- }
255
-
256
- toggleSelect(id) {
257
- const set = new Set(this.selectedIds);
258
- if (set.has(id)) set.delete(id); else set.add(id);
259
- this.selectObjects([...set]);
260
- }
261
-
262
- clearSelection() {
263
- if (!this.selectedIds.length) return;
264
- this.selectedIds = [];
265
- this.canvas.syncSelection();
266
- this.inspector.render();
267
- this.toolbar.refresh();
268
- }
269
-
270
- selectSlide(i) {
271
- this.index = Math.max(0, Math.min(this.snapshot.slides.length - 1, i));
272
- this.selectedIds = [];
273
- this.renderAll();
274
- }
275
-
276
- /* ===================== 对象编辑 ===================== */
277
-
278
- updateObject(id, patch) {
279
- const obj = this.selectedById(id);
280
- if (!obj) return;
281
- this.pushHistory();
282
- Object.assign(obj, patch);
283
- this.notifyChange({ thumbs: false });
284
- }
285
-
286
- updateProps(id, patch) {
287
- const obj = this.selectedById(id);
288
- if (!obj) return;
289
- this.pushHistory();
290
- Object.assign(obj.props, patch);
291
- this.notifyChange();
292
- }
293
-
294
- setProp(key, value) {
295
- if (!this.selectedIds.length) return;
296
- this.pushHistory();
297
- for (const obj of this.currentSlide().objects) {
298
- if (this.selectedIds.includes(obj.id)) obj.props[key] = value;
299
- }
300
- this.notifyChange();
301
- }
302
-
303
- toggleProp(key) {
304
- if (!this.selectedIds.length) return;
305
- this.pushHistory();
306
- for (const obj of this.currentSlide().objects) {
307
- if (this.selectedIds.includes(obj.id)) obj.props[key] = !obj.props[key];
308
- }
309
- this.notifyChange();
310
- }
311
-
312
- setFontSize(px) {
313
- if (!this.selectedIds.length || !px) return;
314
- this.pushHistory();
315
- for (const obj of this.currentSlide().objects) {
316
- if (this.selectedIds.includes(obj.id)) setObjectFontSize(obj, px);
317
- }
318
- this.notifyChange();
319
- }
320
-
321
- setFontFamily(font) {
322
- if (!this.selectedIds.length) return;
323
- this.pushHistory();
324
- for (const obj of this.currentSlide().objects) {
325
- if (this.selectedIds.includes(obj.id)) obj.props.font = font;
326
- }
327
- this.notifyChange();
328
- }
329
-
330
- /** 新建对象:落在当前页中心附近,自动选中 */
331
- insert(kind, variant) {
332
- const slide = this.currentSlide();
333
- const cx = Math.round((SLIDE_W - 360) / 2);
334
- const cy = Math.round((SLIDE_H - 110) / 2);
335
- const z = topZ(slide.objects) + 1;
336
- this.pushHistory();
337
- let obj = null;
338
- if (kind === 'text') obj = createTextObject(cx, cy, z);
339
- else if (kind === 'shape') obj = createShapeObject(variant || 'rect', cx, cy, z);
340
- else if (kind === 'line') obj = createLineObject(cx, cy, z, false);
341
- else if (kind === 'arrow') obj = createLineObject(cx, cy, z, true);
342
- else if (kind === 'table') obj = createTableObject(cx, cy, z);
343
- else if (kind === 'image') { this.pickImage(); return; }
344
- if (!obj) return;
345
- slide.objects.push(obj);
346
- this.selectedIds = [obj.id];
347
- this.notifyChange();
348
- }
349
-
350
- pickImage() {
351
- const input = document.createElement('input');
352
- input.type = 'file';
353
- input.accept = 'image/png,image/jpeg,image/gif';
354
- input.addEventListener('change', () => {
355
- const file = input.files?.[0];
356
- if (!file) return;
357
- const reader = new FileReader();
358
- reader.onload = () => {
359
- const img = new Image();
360
- img.onload = () => {
361
- const maxW = 480;
362
- const ratio = img.height / Math.max(1, img.width);
363
- const w = Math.min(maxW, img.width);
364
- const h = Math.round(w * ratio);
365
- const slide = this.currentSlide();
366
- this.pushHistory();
367
- const obj = createImageObject(reader.result, Math.round((SLIDE_W - w) / 2), Math.round((SLIDE_H - h) / 2), w, h, topZ(slide.objects) + 1);
368
- slide.objects.push(obj);
369
- this.selectedIds = [obj.id];
370
- this.notifyChange();
371
- };
372
- img.src = String(reader.result);
373
- };
374
- reader.readAsDataURL(file);
375
- });
376
- input.click();
377
- }
378
-
379
- removeSelected() {
380
- if (!this.selectedIds.length) return;
381
- this.pushHistory();
382
- const slide = this.currentSlide();
383
- slide.objects = slide.objects.filter((o) => !this.selectedIds.includes(o.id));
384
- this.selectedIds = [];
385
- this.notifyChange();
386
- }
387
-
388
- duplicateSelected() {
389
- if (!this.selectedIds.length) return;
390
- this.pushHistory();
391
- const slide = this.currentSlide();
392
- const copies = [];
393
- for (const o of slide.objects) {
394
- if (!this.selectedIds.includes(o.id)) continue;
395
- const c = cloneObject(o);
396
- c.x += 16;
397
- c.y += 16;
398
- c.z = topZ(slide.objects) + 1 + copies.length;
399
- copies.push(c);
400
- }
401
- slide.objects.push(...copies);
402
- this.selectedIds = copies.map((c) => c.id);
403
- this.notifyChange();
404
- }
405
-
406
- copySelected() {
407
- if (!this.selectedIds.length) return;
408
- this.clipboard = this.currentSlide().objects.filter((o) => this.selectedIds.includes(o.id)).map((o) => JSON.parse(JSON.stringify(o)));
409
- }
410
-
411
- cutSelected() {
412
- this.copySelected();
413
- this.removeSelected();
414
- }
415
-
416
- paste() {
417
- if (!this.clipboard?.length) return;
418
- this.pushHistory();
419
- const slide = this.currentSlide();
420
- const pasted = this.clipboard.map((o, i) => {
421
- const c = JSON.parse(JSON.stringify(o));
422
- c.id = `${c.id}-p${Date.now().toString(36)}${i}`;
423
- c.x += 16;
424
- c.y += 16;
425
- c.z = topZ(slide.objects) + 1 + i;
426
- return c;
427
- });
428
- slide.objects.push(...pasted);
429
- this.selectedIds = pasted.map((c) => c.id);
430
- this.notifyChange();
431
- }
432
-
433
- /** 层级调整 */
434
- arrange(key) {
435
- const slide = this.currentSlide();
436
- const sel = slide.objects.filter((o) => this.selectedIds.includes(o.id));
437
- if (!sel.length) return;
438
- this.pushHistory();
439
- const sorted = [...slide.objects].sort((a, b) => (a.z || 0) - (b.z || 0));
440
- for (const o of sel) {
441
- const i = sorted.indexOf(o);
442
- if (key === 'front') sorted.splice(i, 1), sorted.push(o);
443
- else if (key === 'back') sorted.splice(i, 1), sorted.unshift(o);
444
- else if (key === 'forward' && i < sorted.length - 1) { sorted.splice(i, 1); sorted.splice(i + 1, 0, o); }
445
- else if (key === 'backward' && i > 0) { sorted.splice(i, 1); sorted.splice(i - 1, 0, o); }
446
- }
447
- sorted.forEach((o, i) => { o.z = i + 1; });
448
- this.notifyChange();
449
- }
450
-
451
- /** 对齐页面 */
452
- alignToSlide(key) {
453
- const slide = this.currentSlide();
454
- const sel = slide.objects.filter((o) => this.selectedIds.includes(o.id));
455
- if (!sel.length) return;
456
- this.pushHistory();
457
- for (const o of sel) {
458
- const r = objectRect(o);
459
- if (key === 'left') o.x = 0;
460
- else if (key === 'centerH') o.x = Math.round((SLIDE_W - r.width) / 2);
461
- else if (key === 'right') o.x = SLIDE_W - r.width;
462
- else if (key === 'top') o.y = 0;
463
- else if (key === 'middle') o.y = Math.round((SLIDE_H - r.height) / 2);
464
- else if (key === 'bottom') o.y = SLIDE_H - r.height;
465
- }
466
- this.notifyChange();
467
- }
468
-
469
- resizeTable(id, rows, cols) {
470
- const obj = this.selectedById(id);
471
- if (!obj || obj.type !== 'table') return;
472
- this.pushHistory();
473
- const cur = obj.props.rows;
474
- const next = [];
475
- for (let r = 0; r < rows; r += 1) {
476
- const row = [];
477
- for (let c = 0; c < cols; c += 1) row.push(cur[r]?.[c] ?? '');
478
- next.push(row);
479
- }
480
- obj.props.rows = next;
481
- obj.props.colW = [];
482
- obj.props.rowH = [];
483
- this.notifyChange();
484
- }
485
-
486
- /** 文本列表(项目符号/编号):把正文各行包成列表 */
487
- applyList(tag) {
488
- const obj = this.firstSelected();
489
- if (!obj || obj.type !== 'text') return;
490
- this.pushHistory();
491
- const items = String(obj.props.html || '')
492
- .replace(/<\/?br\s*\/?>/gi, '\n')
493
- .replace(/<\/?[^>]+>/g, '\n')
494
- .split('\n')
495
- .map((s) => s.trim())
496
- .filter(Boolean);
497
- obj.props.html = `<${tag}>${items.map((t) => `<li>${t}</li>`).join('')}</${tag}>`;
498
- this.notifyChange();
499
- }
500
-
501
- /* ===================== 页操作 ===================== */
502
-
503
- addSlide(key) {
504
- this.pushHistory();
505
- const slide = key ? createSlideWithLayout(key) : createSlide();
506
- this.snapshot.slides.splice(this.index + 1, 0, slide);
507
- this.index += 1;
508
- this.selectedIds = [];
509
- this.notifyChange();
510
- }
511
-
512
- dupSlide() {
513
- this.pushHistory();
514
- this.snapshot.slides.splice(this.index + 1, 0, copySlide(this.currentSlide()));
515
- this.index += 1;
516
- this.notifyChange();
517
- }
518
-
519
- delSlide() {
520
- if (this.snapshot.slides.length <= 1) return notify.warning('至少要保留一页');
521
- this.pushHistory();
522
- this.snapshot.slides.splice(this.index, 1);
523
- this.index = Math.max(0, this.index - 1);
524
- this.selectedIds = [];
525
- this.notifyChange();
526
- }
527
-
528
- moveSlide(delta) {
529
- const next = this.index + delta;
530
- if (next < 0 || next >= this.snapshot.slides.length) return;
531
- this.pushHistory();
532
- const [slide] = this.snapshot.slides.splice(this.index, 1);
533
- this.snapshot.slides.splice(next, 0, slide);
534
- this.index = next;
535
- this.notifyChange();
536
- }
537
-
538
- setTheme(key) {
539
- if (this.snapshot.theme === key) return;
540
- this.pushHistory();
541
- this.snapshot.theme = key;
542
- this.notifyChange();
543
- }
544
-
545
- setSlideBg(color) {
546
- this.pushHistory();
547
- this.currentSlide().bg = color || '';
548
- this.notifyChange();
549
- }
550
-
551
- setZoom(z) {
552
- this.zoom = Math.max(20, Math.min(200, Math.round(z)));
553
- this.prefs.zoom = this.zoom;
554
- savePrefs(this.prefs);
555
- this.canvas.render();
556
- this.renderStatus();
557
- }
558
-
559
- /* ===================== 放映 ===================== */
560
-
561
- present() {
562
- if (!this.snapshot.slides.length) return;
563
- this.presenter.open(this.index);
564
- }
565
-
566
- presentAt(i) {
567
- this.presenter.open(i);
568
- }
569
-
570
- presentFromStart() {
571
- this.presenter.open(0);
572
- }
573
-
574
- /* ===================== 文件 ===================== */
575
-
576
- newDoc() {
577
- const start = () => {
578
- this.doc = { name: '新建演示', handle: null };
579
- this.snapshot = createDraft();
580
- this.index = 0;
581
- this.selectedIds = [];
582
- this.history = [];
583
- this.future = [];
584
- this.setDirty(false);
585
- this.renderAll();
586
- };
587
- if (this.dirty && !window.confirm('当前演示有未保存的修改,新建将丢弃这些修改。\n\n确定继续吗?')) return;
588
- start();
589
- }
590
-
591
- async openFile() {
592
- try {
593
- const picked = await openPptx();
594
- if (!picked) return;
595
- if (this.dirty && !window.confirm('当前演示有未保存的修改,打开将丢弃这些修改。\n\n确定继续吗?')) return;
596
- await this.applyBytes(picked.bytes, picked.name);
597
- this.doc = { name: picked.name.replace(/\.pptx$/i, ''), handle: picked.handle };
598
- notify.success(`已打开 ${picked.name}`);
599
- } catch (err) {
600
- notify.error(`打开失败:${err.message || err}`);
601
- }
602
- }
603
-
604
- async applyBytes(bytes, name) {
605
- const snap = normalizeSnapshot(await parsePptx(bytes)) || createDraft();
606
- if (!snap.title) snap.title = String(name || '').replace(/\.pptx$/i, '');
607
- this.snapshot = snap;
608
- this.index = 0;
609
- this.selectedIds = [];
610
- this.history = [];
611
- this.future = [];
612
- this.setDirty(false);
613
- this.renderAll();
614
- }
615
-
616
- async save(silent = false) {
617
- if (!this.snapshot.slides.length) return false;
618
- if (!this.doc.handle) return this.saveAs();
619
- this.saving = true;
620
- try {
621
- const bytes = await buildPptxVerified(this.snapshot);
622
- await savePptx(bytes, `${this.doc.name || '新建演示'}.pptx`, this.doc.handle);
623
- this.setDirty(false);
624
- if (!silent) notify.success('已保存');
625
- return true;
626
- } catch (err) {
627
- notify.error(`保存失败:${err.message || err}`);
628
- return false;
629
- } finally {
630
- this.saving = false;
631
- }
632
- }
633
-
634
- async saveAs() {
635
- if (!this.snapshot.slides.length) return false;
636
- try {
637
- const bytes = await buildPptxVerified(this.snapshot);
638
- const result = await savePptxAs(bytes, this.doc.name || '新建演示');
639
- if (!result.saved) return false;
640
- this.doc = { name: (result.name || this.doc.name).replace(/\.pptx$/i, ''), handle: result.handle };
641
- this.setDirty(false);
642
- this.renderHead();
643
- notify.success('已另存为');
644
- return true;
645
- } catch (err) {
646
- notify.error(`另存失败:${err.message || err}`);
647
- return false;
648
- }
649
- }
650
-
651
- async exportPptx() {
652
- if (!this.snapshot.slides.length) return;
653
- try {
654
- const bytes = await buildPptxVerified(this.snapshot);
655
- downloadBlob(new Blob([bytes], { type: PPTX_MIME }), ensureExt(this.doc.name || '新建演示', '.pptx'));
656
- } catch (err) {
657
- notify.error(`导出失败:${err.message || err}`);
658
- }
659
- }
660
-
661
- exportPdf() {
662
- printSlides(this.snapshot.slides, this.snapshot.theme, (slide, theme) => renderPage(slide, theme));
663
- }
664
-
665
- importDoc() {
666
- const input = document.createElement('input');
667
- input.type = 'file';
668
- input.accept = '.pptx';
669
- input.addEventListener('change', async () => {
670
- const file = input.files?.[0];
671
- if (!file) return;
672
- try {
673
- const bytes = new Uint8Array(await file.arrayBuffer());
674
- await this.applyBytes(bytes, file.name);
675
- this.doc = { name: file.name.replace(/\.pptx$/i, ''), handle: null };
676
- this.renderHead();
677
- notify.success(`已导入 ${file.name}`);
678
- } catch (err) {
679
- notify.error(`导入失败:${err.message || err}`);
680
- }
681
- });
682
- input.click();
683
- }
684
-
685
- /* ===================== 右键菜单 ===================== */
686
-
687
- openObjectMenu(x, y) {
688
- const hasSel = this.selectedIds.length > 0;
689
- openContextMenu({
690
- x, y,
691
- items: [
692
- { label: '剪切', shortcut: 'Ctrl+X', disabled: !hasSel, onClick: () => this.cutSelected() },
693
- { label: '复制', shortcut: 'Ctrl+C', disabled: !hasSel, onClick: () => this.copySelected() },
694
- { label: '粘贴', shortcut: 'Ctrl+V', disabled: !this.clipboard?.length, onClick: () => this.paste() },
695
- { label: '复制对象', shortcut: 'Ctrl+D', disabled: !hasSel, onClick: () => this.duplicateSelected() },
696
- { divided: true },
697
- { label: '置于顶层', disabled: !hasSel, onClick: () => this.arrange('front') },
698
- { label: '置于底层', disabled: !hasSel, onClick: () => this.arrange('back') },
699
- { divided: true },
700
- { label: '删除对象', shortcut: 'Del', disabled: !hasSel, onClick: () => this.removeSelected() },
701
- ],
702
- });
703
- }
704
-
705
- /* ===================== 菜单 ctx ===================== */
706
-
707
- menuCtx() {
708
- const app = this;
709
- return {
710
- state: {
711
- hasDoc: app.snapshot.slides.length > 0,
712
- autosave: app.autosave,
713
- canUndo: app.canUndo(),
714
- canRedo: app.canRedo(),
715
- hasSelection: app.selectedIds.length > 0,
716
- canPaste: Boolean(app.clipboard?.length),
717
- canRemoveSlide: app.snapshot.slides.length > 1,
718
- canMoveUp: app.index > 0,
719
- canMoveDown: app.index < app.snapshot.slides.length - 1,
720
- editing: app.firstSelected()?.type === 'text',
721
- bulletList: false,
722
- numberList: false,
723
- theme: app.snapshot.theme,
724
- notesVisible: app.notesVisible,
725
- },
726
- file: {
727
- newDoc: () => app.newDoc(),
728
- open: () => app.openFile(),
729
- save: () => app.save(),
730
- saveAs: () => app.saveAs(),
731
- setAutosave: (on) => { app.autosave = on; app.prefs.autosave = on; savePrefs(app.prefs); app.autosaveEl.checked = on; },
732
- importDoc: () => app.importDoc(),
733
- exportPptx: () => app.exportPptx(),
734
- exportPdf: () => app.exportPdf(),
735
- print: () => app.exportPdf(),
736
- },
737
- edit: {
738
- undo: () => app.undo(),
739
- redo: () => app.redo(),
740
- cut: () => app.cutSelected(),
741
- copy: () => app.copySelected(),
742
- paste: () => app.paste(),
743
- remove: () => app.removeSelected(),
744
- selectAll: () => app.selectObjects(app.currentSlide().objects.map((o) => o.id)),
745
- },
746
- insert: {
747
- text: () => app.insert('text'),
748
- image: () => app.insert('image'),
749
- shape: (kind) => app.insert('shape', kind),
750
- shapeKinds: SHAPE_KINDS,
751
- line: () => app.insert('line'),
752
- arrow: () => app.insert('arrow'),
753
- table: () => app.insert('table'),
754
- },
755
- slide: {
756
- new: () => app.addSlide(),
757
- newWithLayout: (key) => app.addSlide(key),
758
- duplicate: () => app.dupSlide(),
759
- remove: () => app.delSlide(),
760
- moveUp: () => app.moveSlide(-1),
761
- moveDown: () => app.moveSlide(1),
762
- background: () => app.editSlideBg(),
763
- },
764
- format: {
765
- bullet: () => app.applyList('ul'),
766
- numbered: () => app.applyList('ol'),
767
- align: (key) => app.alignToSlide(key),
768
- order: (key) => app.arrange(key),
769
- duplicate: () => app.duplicateSelected(),
770
- remove: () => app.removeSelected(),
771
- },
772
- design: {
773
- theme: (key) => app.setTheme(key),
774
- },
775
- view: {
776
- zoomIn: () => app.setZoom(app.zoom + 10),
777
- zoomOut: () => app.setZoom(app.zoom - 10),
778
- zoomReset: () => app.setZoom(60),
779
- present: () => app.present(),
780
- presentFromStart: () => app.presentFromStart(),
781
- toggleNotes: () => app.toggleNotes(),
782
- },
783
- };
784
- }
785
-
786
- editSlideBg() {
787
- promptText({ title: '页面背景', label: '背景色 #rrggbb(留空跟随主题)', value: this.currentSlide().bg || '' }).then((v) => {
788
- if (v === null) return;
789
- this.setSlideBg(v.trim());
790
- });
791
- }
792
-
793
- /** 自检:前端编解码往返(build → parse)——供控制台/自动化快速校验内核与 gbooxml 集成 */
794
- async selfTest() {
795
- const snap = {
796
- version: 1,
797
- title: '自检',
798
- theme: 'midnight',
799
- slides: [
800
- {
801
- id: 's1',
802
- bg: '',
803
- notes: '备注第一行\n第二行',
804
- objects: [
805
- { id: 'o1', type: 'text', x: 40, y: 30, w: 400, h: 120, rot: 0, z: 1, props: { html: '<div>标题 <b>加粗</b></div>', font: '', fontSize: 32, color: '', align: 'left', bold: false, italic: false, underline: false } },
806
- { id: 'o2', type: 'shape', x: 500, y: 60, w: 220, h: 140, rot: 0, z: 2, props: { kind: 'round', fill: '#4c9be8', stroke: '#333333', strokeW: 2, text: '形状文字', textColor: '#ffffff', font: '', fontSize: 18, bold: false } },
807
- { id: 'o3', type: 'line', x: 260, y: 300, w: -200, h: 80, rot: 0, z: 3, props: { stroke: '#202124', strokeW: 2, dash: true, arrowEnd: true } },
808
- { id: 'o4', type: 'table', x: 120, y: 380, w: 440, h: 120, rot: 0, z: 4, props: { rows: [['A', 'B'], ['C', 'D']], headerRow: true, font: '', fontSize: 16, color: '', colW: [], rowH: [] } },
809
- ],
810
- },
811
- { id: 's2', bg: '#123456', notes: '', objects: [] },
812
- ],
813
- };
814
- const bytes = await buildPptxVerified(snap);
815
- const back = await parsePptx(bytes);
816
- return {
817
- bytes: bytes.length,
818
- slides: back.slides.length,
819
- theme: back.theme,
820
- title: back.title,
821
- s1Objects: back.slides[0].objects.length,
822
- s1Types: back.slides[0].objects.map((o) => o.type),
823
- s1Notes: back.slides[0].notes,
824
- bg2: back.slides[1].bg,
825
- };
826
- }
827
-
828
- async start() {
829
- this.renderAll();
830
- notify.info('gbpptx 已就绪:可直接编辑,或用「打开」载入 .pptx');
831
- }
832
-
833
- destroy() {
834
- this.presenter.close();
835
- clearTimeout(this._autoTimer);
836
- }
837
- }
838
-
839
- function loadPrefs() {
840
- try { return JSON.parse(localStorage.getItem(LS_KEY) || '{}') || {}; } catch { return {}; }
841
- }
842
- function savePrefs(prefs) {
843
- try { localStorage.setItem(LS_KEY, JSON.stringify(prefs)); } catch { /* 忽略存储失败 */ }
844
- }
1
+ // [文件] gbpptx·SlidesApp —— Office 式演示编辑器装配(Ribbon/窗格/画布/放映/文件读写/查找替换)
2
+ //
3
+ // [设计] 本文件只留「装配 + 渲染 + 生命周期 + 自检」;其余职责按段落拆到 ./slides/*:
4
+ // render(选择与渲染)/ history(脏状态与撤销)/ text(文本编辑与格式)/ objects(属性与插入)/
5
+ // clipboard / arrange / table / slides(页操作)/ view(视图与放映)/ file / find / menus / keys。
6
+ // 各模块导出方法组,由文件末尾 Object.assign 装配到 SlidesApp.prototype —— 同一个 this、同一套调用,
7
+ // 外部拿到的 SlidesApp 形状与拆分前完全一致。
8
+ // [坑] 装配必须在实例化之前完成:Object.assign 在模块求值时执行,而实例只能在 import 之后 new。
9
+
10
+ import { clamp } from 'guabiutils';
11
+ import { createDraft, sizeOf } from '../../src/kernel/model.js';
12
+ import { buildPptxVerified } from '../../src/kernel/roundtrip.js';
13
+ import { parsePptx } from '../../src/kernel/read.js';
14
+ import { notify } from './ui/notify.js';
15
+ import { TitleBar } from './ui/titlebar.js';
16
+ import { Ribbon } from './ui/ribbon.js';
17
+ import { SlidePane } from './ui/slide-pane.js';
18
+ import { Canvas } from './ui/canvas.js';
19
+ import { FormatPane } from './ui/format-pane.js';
20
+ import { StatusBar } from './ui/statusbar.js';
21
+ import { Backstage } from './ui/backstage.js';
22
+ import { Present } from './ui/present.js';
23
+ import { icon } from './ui/icons.js';
24
+ import { el, loadPrefs, savePrefs, ZOOM_MIN, ZOOM_MAX } from './slides/shared.js';
25
+ import { renderMethods } from './slides/render.js';
26
+ import { historyMethods } from './slides/history.js';
27
+ import { textMethods } from './slides/text.js';
28
+ import { objectsMethods } from './slides/objects.js';
29
+ import { clipboardMethods } from './slides/clipboard.js';
30
+ import { arrangeMethods } from './slides/arrange.js';
31
+ import { tableMethods } from './slides/table.js';
32
+ import { slidesMethods } from './slides/slides.js';
33
+ import { viewMethods } from './slides/view.js';
34
+ import { fileMethods } from './slides/file.js';
35
+ import { findMethods } from './slides/find.js';
36
+ import { menusMethods } from './slides/menus.js';
37
+ import { keysMethods } from './slides/keys.js';
38
+
39
+ export class SlidesApp {
40
+ constructor(mount) {
41
+ this.mount = mount;
42
+ const prefs = loadPrefs();
43
+ this.prefs = prefs;
44
+ this.snapshot = createDraft();
45
+ this.index = 0;
46
+ this.selectedIds = [];
47
+ this.zoom = clamp(Number(prefs.zoom) || 65, ZOOM_MIN, ZOOM_MAX);
48
+ this.dirty = false;
49
+ this.saving = false;
50
+ this.revision = 0;
51
+ this.history = [];
52
+ this.future = [];
53
+ this.clipboard = null;
54
+ this.editing = null;
55
+ this.tableCursor = null;
56
+ this.notesSession = false;
57
+ this.autosave = !!prefs.autosave;
58
+ this.notesVisible = prefs.notesVisible !== false;
59
+ this.gridVisible = !!prefs.grid;
60
+ this.guidesVisible = prefs.guides === true;
61
+ this.ribbonCollapsed = !!prefs.ribbonCollapsed;
62
+ this.formatPaneOpen = !!prefs.formatPaneOpen;
63
+ this.view = 'normal';
64
+ this.presentOptions = { presenter: !!prefs.presenter, loop: !!prefs.loop };
65
+ this.lastBytes = null;
66
+
67
+ const seq = Number(prefs.docSeq) || 1;
68
+ prefs.docSeq = seq + 1;
69
+ savePrefs(prefs);
70
+ this.doc = { name: `演示文稿${seq}`, handle: null, savedAt: 0 };
71
+
72
+ this.build();
73
+ this.bindGlobal();
74
+ this.presenter = new Present(this);
75
+ this.backstage = new Backstage(this);
76
+ }
77
+
78
+ /* ===================== 骨架 ===================== */
79
+
80
+ get size() {
81
+ return sizeOf(this.snapshot);
82
+ }
83
+
84
+ build() {
85
+ const root = el('div', 'pp-app');
86
+ root.innerHTML = `
87
+ <div class="pp-topbar-host"></div>
88
+ <div class="pp-ribbon-host"></div>
89
+ <div class="pp-main">
90
+ <div class="pp-main__left"></div>
91
+ <div class="pp-center">
92
+ <div class="pp-canvas-host"></div>
93
+ <div class="pp-notes" hidden>
94
+ <div class="pp-notes__head">
95
+ <span class="pp-notes__title">备注</span>
96
+ <button type="button" class="pp-iconbtn" data-act="notes-close" title="关闭备注">${icon('close', 14)}</button>
97
+ </div>
98
+ <textarea class="pp-notes__text" placeholder="单击此处添加演讲者备注"></textarea>
99
+ </div>
100
+ </div>
101
+ <div class="pp-main__right"></div>
102
+ </div>
103
+ <div class="pp-statusbar-host"></div>`;
104
+ this.mount.appendChild(root);
105
+ this.root = root;
106
+ this.left = root.querySelector('.pp-main__left');
107
+ this.center = root.querySelector('.pp-center');
108
+ this.right = root.querySelector('.pp-main__right');
109
+ this.canvasHost = root.querySelector('.pp-canvas-host');
110
+ this.notesEl = root.querySelector('.pp-notes');
111
+ this.notesText = root.querySelector('.pp-notes__text');
112
+
113
+ this.titlebar = new TitleBar(this);
114
+ this.ribbon = new Ribbon(this);
115
+ this.slidePane = new SlidePane(this);
116
+ this.canvas = new Canvas(this);
117
+ this.formatPane = new FormatPane(this);
118
+ this.statusbar = new StatusBar(this);
119
+
120
+ root.querySelector('.pp-topbar-host').appendChild(this.titlebar.el);
121
+ root.querySelector('.pp-ribbon-host').appendChild(this.ribbon.el);
122
+ this.left.appendChild(this.slidePane.el);
123
+ this.canvasHost.appendChild(this.canvas.el);
124
+ this.right.appendChild(this.formatPane.el);
125
+ root.querySelector('.pp-statusbar-host').appendChild(this.statusbar.el);
126
+
127
+ this.sorterEl = el('div', 'pp-sorter');
128
+ this.sorterEl.hidden = true;
129
+ this.center.appendChild(this.sorterEl);
130
+ this.readingEl = el('div', 'pp-reading');
131
+ this.readingEl.hidden = true;
132
+ this.center.appendChild(this.readingEl);
133
+ this.buildSorterEvents();
134
+
135
+ this.bindNotes(root.querySelector('[data-act="notes-close"]'));
136
+ }
137
+
138
+ bindNotes(closeBtn) {
139
+ this.notesText.addEventListener('focus', () => { this.notesSession = false; });
140
+ this.notesText.addEventListener('input', () => {
141
+ const slide = this.currentSlide();
142
+ if (!slide) return;
143
+ if (!this.notesSession) {
144
+ this.pushHistory();
145
+ this.notesSession = true;
146
+ }
147
+ slide.notes = this.notesText.value;
148
+ this.markDirty();
149
+ this.statusbar.setStatus('正在编辑备注');
150
+ });
151
+ this.notesText.addEventListener('blur', () => {
152
+ if (!this.notesSession) return;
153
+ this.notesSession = false;
154
+ this.statusbar.setStatus('');
155
+ this.ribbon.refresh();
156
+ });
157
+ closeBtn.addEventListener('click', () => this.toggleNotes());
158
+ }
159
+
160
+ buildSorterEvents() {
161
+ this.sorterEl.addEventListener('click', (e) => {
162
+ const card = e.target.closest('[data-index]');
163
+ if (card) this.selectSlide(Number(card.dataset.index));
164
+ });
165
+ this.sorterEl.addEventListener('dblclick', (e) => {
166
+ const card = e.target.closest('[data-index]');
167
+ if (card) {
168
+ this.selectSlide(Number(card.dataset.index));
169
+ this.setView('normal');
170
+ }
171
+ });
172
+ this.sorterEl.addEventListener('contextmenu', (e) => {
173
+ const card = e.target.closest('[data-index]');
174
+ if (!card) return;
175
+ e.preventDefault();
176
+ const i = Number(card.dataset.index);
177
+ this.selectSlide(i);
178
+ this.openSlideMenu(e.clientX, e.clientY, i);
179
+ });
180
+ this.sorterEl.addEventListener('dragstart', (e) => {
181
+ const card = e.target.closest('[data-index]');
182
+ if (!card) return;
183
+ this.dragIndex = Number(card.dataset.index);
184
+ card.classList.add('gbp-is-dragging');
185
+ e.dataTransfer.effectAllowed = 'move';
186
+ e.dataTransfer.setData('text/plain', String(this.dragIndex));
187
+ });
188
+ this.sorterEl.addEventListener('dragend', () => {
189
+ this.dragIndex = null;
190
+ this.sorterEl.querySelectorAll('.gbp-is-dragging, .gbp-is-drop').forEach((n) => n.classList.remove('gbp-is-dragging', 'gbp-is-drop'));
191
+ });
192
+ this.sorterEl.addEventListener('dragover', (e) => {
193
+ const card = e.target.closest('[data-index]');
194
+ if (!card || this.dragIndex === null) return;
195
+ e.preventDefault();
196
+ this.sorterEl.querySelectorAll('.gbp-is-drop').forEach((n) => n.classList.remove('gbp-is-drop'));
197
+ card.classList.add('gbp-is-drop');
198
+ });
199
+ this.sorterEl.addEventListener('drop', (e) => {
200
+ const card = e.target.closest('[data-index]');
201
+ if (!card || this.dragIndex === null) return;
202
+ e.preventDefault();
203
+ const to = Number(card.dataset.index);
204
+ if (to !== this.dragIndex) this.moveSlideTo(this.dragIndex, to);
205
+ this.dragIndex = null;
206
+ });
207
+ }
208
+
209
+ /* ===================== 启动/销毁 ===================== */
210
+
211
+ start() {
212
+ this.renderAll();
213
+ notify.info('已就绪:可直接编辑,或用「文件 → 打开」载入 .pptx');
214
+ }
215
+
216
+ destroy() {
217
+ this.canvas?.unbindWheel?.();
218
+ this.presenter?.close();
219
+ clearTimeout(this.autosaveTimer);
220
+ document.removeEventListener('keydown', this.onKeyBound);
221
+ document.removeEventListener('paste', this.onPasteBound);
222
+ document.removeEventListener('selectionchange', this.onSelectionChangeBound);
223
+ window.removeEventListener('beforeunload', this.onBeforeUnloadBound);
224
+ window.removeEventListener('dragover', this.onDragOverBound);
225
+ window.removeEventListener('drop', this.onDropBound);
226
+ window.removeEventListener('resize', this.onResizeBound);
227
+ }
228
+
229
+ /* ===================== 渲染 ===================== */
230
+
231
+ async selfTest() {
232
+ const snap = {
233
+ version: 2,
234
+ title: '自检',
235
+ theme: 'midnight',
236
+ size: { w: 960, h: 540 },
237
+ slides: [
238
+ {
239
+ id: 's1',
240
+ bg: '',
241
+ notes: '备注第一行\n第二行',
242
+ hidden: false,
243
+ transition: { type: 'fade', dir: 'l', speed: 'med' },
244
+ objects: [
245
+ { id: 'o1', type: 'text', x: 40, y: 30, w: 400, h: 120, rot: 0, z: 1, props: { html: '<div>标题 <b>加粗</b></div><ul><li>项目一</li><li>项目二</li></ul>', font: '', fontSize: 32, color: '', align: 'left', bold: false, italic: false, underline: false, strike: false, anchor: 'top', lineSpacing: 1, fill: '', stroke: '', strokeW: 0 } },
246
+ { id: 'o2', type: 'shape', x: 500, y: 60, w: 220, h: 140, rot: 15, z: 2, props: { kind: 'star', fill: '#4c9be8', stroke: '#333333', strokeW: 2, dash: 'dash', shadow: true, text: '形状文字', textColor: '#ffffff', font: '', fontSize: 18, bold: false, italic: false, underline: false, align: 'center', anchor: 'middle' } },
247
+ { id: 'o3', type: 'line', x: 260, y: 300, w: -200, h: 80, rot: 0, z: 3, props: { stroke: '#202124', strokeW: 2, dash: 'dot', arrowStart: true, arrowEnd: true } },
248
+ { id: 'o4', type: 'table', x: 120, y: 380, w: 440, h: 120, rot: 0, z: 4, props: { rows: [['A', 'B'], ['C', 'D']], headerRow: true, bandedRows: true, tableStyle: 'banded', font: '', fontSize: 16, color: '', colW: [], rowH: [] } },
249
+ ],
250
+ },
251
+ { id: 's2', bg: '#123456', notes: '', hidden: true, transition: { type: 'push', dir: 'u', speed: 'slow' }, objects: [] },
252
+ ],
253
+ };
254
+ const bytes = await buildPptxVerified(snap);
255
+ const back = await parsePptx(bytes);
256
+ return {
257
+ bytes: bytes.length,
258
+ size: back.size,
259
+ slides: back.slides.length,
260
+ theme: back.theme,
261
+ hidden: back.slides.map((s) => s.hidden),
262
+ transition: back.slides.map((s) => s.transition.type),
263
+ objects: back.slides[0].objects.map((o) => o.type),
264
+ list: back.slides[0].objects[0]?.props?.html?.includes('<ul>'),
265
+ tableStyle: back.slides[0].objects[3]?.props?.tableStyle,
266
+ };
267
+ }
268
+ }
269
+
270
+ Object.assign(
271
+ SlidesApp.prototype,
272
+ renderMethods,
273
+ historyMethods,
274
+ textMethods,
275
+ objectsMethods,
276
+ clipboardMethods,
277
+ arrangeMethods,
278
+ tableMethods,
279
+ slidesMethods,
280
+ viewMethods,
281
+ fileMethods,
282
+ findMethods,
283
+ menusMethods,
284
+ keysMethods
285
+ );