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.
- package/README.md +220 -158
- package/package.json +15 -4
- package/src/index.js +16 -8
- package/src/kernel/model.js +397 -91
- package/src/kernel/parts.js +3 -3
- package/src/kernel/pptx.js +17 -12
- package/src/kernel/read.js +747 -157
- package/src/kernel/roundtrip.js +118 -18
- package/src/kernel/text.js +133 -28
- package/src/kernel/write.js +160 -49
- package/web/app/main.js +8 -8
- package/web/app/slides/arrange.js +101 -0
- package/web/app/slides/clipboard.js +93 -0
- package/web/app/slides/file.js +243 -0
- package/web/app/slides/find.js +199 -0
- package/web/app/slides/history.js +100 -0
- package/web/app/slides/keys.js +174 -0
- package/web/app/slides/menus.js +105 -0
- package/web/app/slides/objects.js +254 -0
- package/web/app/slides/render.js +183 -0
- package/web/app/slides/shared.js +85 -0
- package/web/app/slides/slides.js +103 -0
- package/web/app/slides/table.js +102 -0
- package/web/app/slides/text.js +418 -0
- package/web/app/slides/view.js +130 -0
- package/web/app/slides-app.js +285 -844
- package/web/app/ui/backstage.js +255 -0
- package/web/app/ui/canvas.js +762 -277
- 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 -89
- package/web/app/ui/format-pane.js +427 -0
- package/web/app/ui/icons.js +129 -0
- package/web/app/ui/menu.js +75 -105
- package/web/app/ui/notify.js +45 -45
- package/web/app/ui/page-view.js +221 -150
- package/web/app/ui/popup.js +80 -80
- package/web/app/ui/present.js +292 -100
- package/web/app/ui/ribbon.js +878 -0
- package/web/app/ui/slide-pane.js +189 -0
- package/web/app/ui/statusbar.js +93 -0
- package/web/app/ui/text-styles.js +84 -84
- package/web/app/ui/titlebar.js +208 -0
- package/web/app/ui/transition.js +30 -0
- package/web/index.html +23 -21
- package/web/serve.mjs +20 -67
- package/web/styles/office.css +642 -0
- package/web/styles/slides.css +210 -212
- package/web/styles/tokens.css +154 -155
- package/src/kernel/menus.js +0 -123
- package/src/kernel/util/escape.js +0 -21
- package/src/kernel/util/id.js +0 -13
- package/web/app/ui/inspector.js +0 -209
- package/web/app/ui/slides-bar.js +0 -63
- package/web/app/ui/toolbar.js +0 -200
package/web/app/slides-app.js
CHANGED
|
@@ -1,844 +1,285 @@
|
|
|
1
|
-
// [文件] gbpptx·SlidesApp ——
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.root.querySelector('
|
|
108
|
-
this.root.querySelector('
|
|
109
|
-
this.root.querySelector('
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
this.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
+
);
|