gbpptx 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 -253
  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,187 +1,187 @@
1
- // [文件] gbpptx·slides·keys —— 全局事件 —— 快捷键分发、粘贴与拖放
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { isReadOnlyViewKey } from 'guabiutils';
7
- import { isPptxFile } from '../ui/file-io.js';
8
- function bindGlobal() {
9
- this.onKeyBound = (e) => this.onKeyDown(e);
10
- this.onSelectionChangeBound = () => this.onSelectionChange();
11
- this.onBeforeUnloadBound = (e) => {
12
- if (!this.dirty) return;
13
- e.preventDefault();
14
- e.returnValue = '';
15
- };
16
- this.onDragOverBound = (e) => {
17
- if ([...e.dataTransfer.types].includes('Files')) e.preventDefault();
18
- };
19
- this.onDropBound = (e) => this.onDrop(e);
20
- this.onPasteBound = (e) => this.onPaste(e);
21
- this.onResizeBound = () => {
22
- if (this.view === 'reading') this.renderReading();
23
- };
24
- this.onFullscreenEsc = (e) => {
25
- if (e.key !== 'Escape' || !this.pageFullscreen) return;
26
- // 放映中 Esc 归放映器;菜单/弹窗开着时也先交给它们
27
- if (this.presenter?.el || document.querySelector('.gbp-popup, .gbp-modal-overlay, .gbp-menu')) return;
28
- e.stopPropagation();
29
- this.setPageFullscreen(false);
30
- };
31
-
32
- document.addEventListener('keydown', this.onKeyBound);
33
- document.addEventListener('selectionchange', this.onSelectionChangeBound);
34
- document.addEventListener('paste', this.onPasteBound);
35
- document.addEventListener('keydown', this.onFullscreenEsc, true);
36
- window.addEventListener('beforeunload', this.onBeforeUnloadBound);
37
- window.addEventListener('dragover', this.onDragOverBound);
38
- window.addEventListener('drop', this.onDropBound);
39
- window.addEventListener('resize', this.onResizeBound);
40
- }
41
-
42
- function isTypingTarget(target) {
43
- return target instanceof Element && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName));
44
- }
45
-
46
- function onKeyDown(e) {
47
- if (this.presenter?.el) return;
48
- // [设计] 事件落在应用外时 DOM 守卫接不到,全局快捷键入口按同一份白名单再挡一次
49
- if (this.readOnly && !isReadOnlyViewKey(e)) return;
50
- const target = e.target;
51
- const typing = this.isTypingTarget(target);
52
- const mod = e.ctrlKey || e.metaKey;
53
- const k = e.key.toLowerCase();
54
-
55
- if (mod && !e.altKey) {
56
- if (k === 's') { e.preventDefault(); e.shiftKey ? this.saveAs(this.doc.name) : this.save(); return; }
57
- if (k === 'o') { e.preventDefault(); this.openFile(); return; }
58
- if (k === 'n') { e.preventDefault(); this.newDoc(); return; }
59
- if (k === 'f') { e.preventDefault(); this.commitEditing({ render: false }); this.openFind(false); return; }
60
- if (k === 'h') { e.preventDefault(); this.commitEditing({ render: false }); this.openFind(true); return; }
61
- if (this.editing) {
62
- const styleKey = { b: 'bold', i: 'italic', u: 'underline' }[k];
63
- if (styleKey) { e.preventDefault(); this.toggleTextStyle(styleKey); return; }
64
- const alignKey = { l: 'left', e: 'center', r: 'right', j: 'justify' }[k];
65
- if (alignKey) { e.preventDefault(); this.applyAlign(alignKey); return; }
66
- }
67
- if (typing) return;
68
- if (k === 'z' && e.shiftKey) { e.preventDefault(); this.redo(); return; }
69
- if (k === 'z') { e.preventDefault(); this.undo(); return; }
70
- if (k === 'y') { e.preventDefault(); this.redo(); return; }
71
- if (k === 'm') { e.preventDefault(); this.addSlide(); return; }
72
- if (k === 'd') { e.preventDefault(); this.selectedIds.length ? this.duplicateSelected() : this.dupSlide(); return; }
73
- if (k === 'a') { e.preventDefault(); this.selectAll(); return; }
74
- if (k === 'c') { e.preventDefault(); this.copySelected(); return; }
75
- if (k === 'x') { e.preventDefault(); this.cutSelected(); return; }
76
- if (k === 'v') {
77
- // 有内部对象剪贴板才拦截;否则交给 paste 事件处理系统文字/图片
78
- if (this.canPaste()) { e.preventDefault(); this.paste(); }
79
- return;
80
- }
81
- const alignKey = { l: 'left', e: 'center', r: 'right', j: 'justify' }[k];
82
- if (alignKey) { e.preventDefault(); this.applyAlign(alignKey); return; }
83
- if (k === '=' || k === '+') { e.preventDefault(); this.setZoom(this.zoom + 10); return; }
84
- if (k === '-') { e.preventDefault(); this.setZoom(this.zoom - 10); return; }
85
- if (k === '0') { e.preventDefault(); this.setZoom(100); return; }
86
- if (k === 'b' && !typing) { e.preventDefault(); this.toggleTextStyle('bold'); return; }
87
- if (k === 'i' && !typing) { e.preventDefault(); this.toggleTextStyle('italic'); return; }
88
- if (k === 'u' && !typing) { e.preventDefault(); this.toggleTextStyle('underline'); return; }
89
- }
90
-
91
- if (typing) {
92
- if (e.key === 'Escape' && this.findEl && !this.findEl.hidden) this.closeFind();
93
- return;
94
- }
95
-
96
- if (e.key === 'F5') { e.preventDefault(); e.shiftKey ? this.presentFromCurrent() : this.presentFromStart(); return; }
97
- if (e.key === 'Escape') {
98
- if (this.preview) { this.setPreview(false); return; }
99
- if (this.findEl && !this.findEl.hidden) { this.closeFind(); return; }
100
- if (this.view !== 'normal') { this.setView('normal'); return; }
101
- this.clearSelection();
102
- return;
103
- }
104
- if (this.view === 'reading') {
105
- if (e.key === 'ArrowRight' || e.key === 'PageDown' || e.key === ' ') { e.preventDefault(); this.selectSlide(this.index + 1); }
106
- if (e.key === 'ArrowLeft' || e.key === 'PageUp') { e.preventDefault(); this.selectSlide(this.index - 1); }
107
- return;
108
- }
109
- if (this.view === 'sorter' && ['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'].includes(e.key)) {
110
- e.preventDefault();
111
- const delta = e.key === 'ArrowRight' || e.key === 'ArrowDown' ? 1 : -1;
112
- this.selectSlide(this.index + delta);
113
- return;
114
- }
115
-
116
- if (e.key === 'Delete' || e.key === 'Backspace') {
117
- if (this.selectedIds.length) { e.preventDefault(); this.removeSelected(); }
118
- return;
119
- }
120
- if (e.key === 'F2' || e.key === 'Enter') {
121
- const o = this.firstSelected();
122
- if (o && (o.type === 'text' || o.type === 'shape')) {
123
- e.preventDefault();
124
- this.startEditingById(o.id);
125
- }
126
- return;
127
- }
128
- if (e.key === 'Tab') {
129
- const objs = this.currentSlide()?.objects || [];
130
- if (!objs.length) return;
131
- e.preventDefault();
132
- const current = this.selectedIds[0];
133
- const at = objs.findIndex((o) => o.id === current);
134
- const next = e.shiftKey ? (at - 1 + objs.length) % objs.length : (at + 1) % objs.length;
135
- this.selectObjects([objs[next].id]);
136
- return;
137
- }
138
- if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key) && this.selectedIds.length) {
139
- e.preventDefault();
140
- const step = e.shiftKey ? 10 : 1;
141
- const dx = e.key === 'ArrowLeft' ? -step : e.key === 'ArrowRight' ? step : 0;
142
- const dy = e.key === 'ArrowUp' ? -step : e.key === 'ArrowDown' ? step : 0;
143
- this.nudge(dx, dy);
144
- }
145
- }
146
-
147
- function onPaste(e) {
148
- if (this.readOnly) return;
149
- const files = [...(e.clipboardData?.files || [])];
150
- const items = [...(e.clipboardData?.items || [])];
151
- const imageItem = items.find((i) => i.type.startsWith('image/'));
152
- const image = files.find((f) => /^image\/(png|jpeg|gif)$/i.test(f.type)) || imageItem?.getAsFile();
153
- if (image) {
154
- // 图片一律作为独立对象插入(正文里不支持内联图片)
155
- e.preventDefault();
156
- this.insertImageFile(image);
157
- return;
158
- }
159
- if (this.editing || this.isTypingTarget(e.target)) return;
160
- const text = e.clipboardData?.getData('text/plain');
161
- if (text && text.trim()) {
162
- e.preventDefault();
163
- this.pasteText(text);
164
- }
165
- }
166
-
167
- async function onDrop(e) {
168
- if (this.readOnly) return;
169
- const files = [...(e.dataTransfer?.files || [])];
170
- if (!files.length) return;
171
- e.preventDefault();
172
- const pptx = files.find((f) => isPptxFile(f));
173
- if (pptx) {
174
- await this.importFile(pptx);
175
- return;
176
- }
177
- const images = files.filter((f) => /^image\/(png|jpeg|gif)$/i.test(f.type));
178
- if (!images.length) return;
179
- let point = null;
180
- if (this.canvas.el.contains(e.target) || e.target === this.canvas.el) {
181
- const rect = this.canvas.inner.getBoundingClientRect();
182
- point = { x: (e.clientX - rect.left) / (this.zoom / 100), y: (e.clientY - rect.top) / (this.zoom / 100) };
183
- }
184
- for (const image of images) await this.insertImageFile(image, point);
185
- }
186
-
187
- export const keysMethods = { bindGlobal, isTypingTarget, onKeyDown, onPaste, onDrop };
1
+ // [文件] gbpptx·slides·keys —— 全局事件 —— 快捷键分发、粘贴与拖放
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { isReadOnlyViewKey } from 'guabiutils';
7
+ import { isPptxFile } from '../ui/file-io.js';
8
+ function bindGlobal() {
9
+ this.onKeyBound = (e) => this.onKeyDown(e);
10
+ this.onSelectionChangeBound = () => this.onSelectionChange();
11
+ this.onBeforeUnloadBound = (e) => {
12
+ if (!this.dirty) return;
13
+ e.preventDefault();
14
+ e.returnValue = '';
15
+ };
16
+ this.onDragOverBound = (e) => {
17
+ if ([...e.dataTransfer.types].includes('Files')) e.preventDefault();
18
+ };
19
+ this.onDropBound = (e) => this.onDrop(e);
20
+ this.onPasteBound = (e) => this.onPaste(e);
21
+ this.onResizeBound = () => {
22
+ if (this.view === 'reading') this.renderReading();
23
+ };
24
+ this.onFullscreenEsc = (e) => {
25
+ if (e.key !== 'Escape' || !this.pageFullscreen) return;
26
+ // 放映中 Esc 归放映器;菜单/弹窗开着时也先交给它们
27
+ if (this.presenter?.el || document.querySelector('.gbp-popup, .gbp-modal-overlay, .gbp-menu')) return;
28
+ e.stopPropagation();
29
+ this.setPageFullscreen(false);
30
+ };
31
+
32
+ document.addEventListener('keydown', this.onKeyBound);
33
+ document.addEventListener('selectionchange', this.onSelectionChangeBound);
34
+ document.addEventListener('paste', this.onPasteBound);
35
+ document.addEventListener('keydown', this.onFullscreenEsc, true);
36
+ window.addEventListener('beforeunload', this.onBeforeUnloadBound);
37
+ window.addEventListener('dragover', this.onDragOverBound);
38
+ window.addEventListener('drop', this.onDropBound);
39
+ window.addEventListener('resize', this.onResizeBound);
40
+ }
41
+
42
+ function isTypingTarget(target) {
43
+ return target instanceof Element && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName));
44
+ }
45
+
46
+ function onKeyDown(e) {
47
+ if (this.presenter?.el) return;
48
+ // [设计] 事件落在应用外时 DOM 守卫接不到,全局快捷键入口按同一份白名单再挡一次
49
+ if (this.readOnly && !isReadOnlyViewKey(e)) return;
50
+ const target = e.target;
51
+ const typing = this.isTypingTarget(target);
52
+ const mod = e.ctrlKey || e.metaKey;
53
+ const k = e.key.toLowerCase();
54
+
55
+ if (mod && !e.altKey) {
56
+ if (k === 's') { e.preventDefault(); e.shiftKey ? this.saveAs(this.doc.name) : this.save(); return; }
57
+ if (k === 'o') { e.preventDefault(); this.openFile(); return; }
58
+ if (k === 'n') { e.preventDefault(); this.newDoc(); return; }
59
+ if (k === 'f') { e.preventDefault(); this.commitEditing({ render: false }); this.openFind(false); return; }
60
+ if (k === 'h') { e.preventDefault(); this.commitEditing({ render: false }); this.openFind(true); return; }
61
+ if (this.editing) {
62
+ const styleKey = { b: 'bold', i: 'italic', u: 'underline' }[k];
63
+ if (styleKey) { e.preventDefault(); this.toggleTextStyle(styleKey); return; }
64
+ const alignKey = { l: 'left', e: 'center', r: 'right', j: 'justify' }[k];
65
+ if (alignKey) { e.preventDefault(); this.applyAlign(alignKey); return; }
66
+ }
67
+ if (typing) return;
68
+ if (k === 'z' && e.shiftKey) { e.preventDefault(); this.redo(); return; }
69
+ if (k === 'z') { e.preventDefault(); this.undo(); return; }
70
+ if (k === 'y') { e.preventDefault(); this.redo(); return; }
71
+ if (k === 'm') { e.preventDefault(); this.addSlide(); return; }
72
+ if (k === 'd') { e.preventDefault(); this.selectedIds.length ? this.duplicateSelected() : this.dupSlide(); return; }
73
+ if (k === 'a') { e.preventDefault(); this.selectAll(); return; }
74
+ if (k === 'c') { e.preventDefault(); this.copySelected(); return; }
75
+ if (k === 'x') { e.preventDefault(); this.cutSelected(); return; }
76
+ if (k === 'v') {
77
+ // 有内部对象剪贴板才拦截;否则交给 paste 事件处理系统文字/图片
78
+ if (this.canPaste()) { e.preventDefault(); this.paste(); }
79
+ return;
80
+ }
81
+ const alignKey = { l: 'left', e: 'center', r: 'right', j: 'justify' }[k];
82
+ if (alignKey) { e.preventDefault(); this.applyAlign(alignKey); return; }
83
+ if (k === '=' || k === '+') { e.preventDefault(); this.setZoom(this.zoom + 10); return; }
84
+ if (k === '-') { e.preventDefault(); this.setZoom(this.zoom - 10); return; }
85
+ if (k === '0') { e.preventDefault(); this.setZoom(100); return; }
86
+ if (k === 'b' && !typing) { e.preventDefault(); this.toggleTextStyle('bold'); return; }
87
+ if (k === 'i' && !typing) { e.preventDefault(); this.toggleTextStyle('italic'); return; }
88
+ if (k === 'u' && !typing) { e.preventDefault(); this.toggleTextStyle('underline'); return; }
89
+ }
90
+
91
+ if (typing) {
92
+ if (e.key === 'Escape' && this.findEl && !this.findEl.hidden) this.closeFind();
93
+ return;
94
+ }
95
+
96
+ if (e.key === 'F5') { e.preventDefault(); e.shiftKey ? this.presentFromCurrent() : this.presentFromStart(); return; }
97
+ if (e.key === 'Escape') {
98
+ if (this.preview) { this.setPreview(false); return; }
99
+ if (this.findEl && !this.findEl.hidden) { this.closeFind(); return; }
100
+ if (this.view !== 'normal') { this.setView('normal'); return; }
101
+ this.clearSelection();
102
+ return;
103
+ }
104
+ if (this.view === 'reading') {
105
+ if (e.key === 'ArrowRight' || e.key === 'PageDown' || e.key === ' ') { e.preventDefault(); this.selectSlide(this.index + 1); }
106
+ if (e.key === 'ArrowLeft' || e.key === 'PageUp') { e.preventDefault(); this.selectSlide(this.index - 1); }
107
+ return;
108
+ }
109
+ if (this.view === 'sorter' && ['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'].includes(e.key)) {
110
+ e.preventDefault();
111
+ const delta = e.key === 'ArrowRight' || e.key === 'ArrowDown' ? 1 : -1;
112
+ this.selectSlide(this.index + delta);
113
+ return;
114
+ }
115
+
116
+ if (e.key === 'Delete' || e.key === 'Backspace') {
117
+ if (this.selectedIds.length) { e.preventDefault(); this.removeSelected(); }
118
+ return;
119
+ }
120
+ if (e.key === 'F2' || e.key === 'Enter') {
121
+ const o = this.firstSelected();
122
+ if (o && (o.type === 'text' || o.type === 'shape')) {
123
+ e.preventDefault();
124
+ this.startEditingById(o.id);
125
+ }
126
+ return;
127
+ }
128
+ if (e.key === 'Tab') {
129
+ const objs = this.currentSlide()?.objects || [];
130
+ if (!objs.length) return;
131
+ e.preventDefault();
132
+ const current = this.selectedIds[0];
133
+ const at = objs.findIndex((o) => o.id === current);
134
+ const next = e.shiftKey ? (at - 1 + objs.length) % objs.length : (at + 1) % objs.length;
135
+ this.selectObjects([objs[next].id]);
136
+ return;
137
+ }
138
+ if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key) && this.selectedIds.length) {
139
+ e.preventDefault();
140
+ const step = e.shiftKey ? 10 : 1;
141
+ const dx = e.key === 'ArrowLeft' ? -step : e.key === 'ArrowRight' ? step : 0;
142
+ const dy = e.key === 'ArrowUp' ? -step : e.key === 'ArrowDown' ? step : 0;
143
+ this.nudge(dx, dy);
144
+ }
145
+ }
146
+
147
+ function onPaste(e) {
148
+ if (this.readOnly) return;
149
+ const files = [...(e.clipboardData?.files || [])];
150
+ const items = [...(e.clipboardData?.items || [])];
151
+ const imageItem = items.find((i) => i.type.startsWith('image/'));
152
+ const image = files.find((f) => /^image\/(png|jpeg|gif)$/i.test(f.type)) || imageItem?.getAsFile();
153
+ if (image) {
154
+ // 图片一律作为独立对象插入(正文里不支持内联图片)
155
+ e.preventDefault();
156
+ this.insertImageFile(image);
157
+ return;
158
+ }
159
+ if (this.editing || this.isTypingTarget(e.target)) return;
160
+ const text = e.clipboardData?.getData('text/plain');
161
+ if (text && text.trim()) {
162
+ e.preventDefault();
163
+ this.pasteText(text);
164
+ }
165
+ }
166
+
167
+ async function onDrop(e) {
168
+ if (this.readOnly) return;
169
+ const files = [...(e.dataTransfer?.files || [])];
170
+ if (!files.length) return;
171
+ e.preventDefault();
172
+ const pptx = files.find((f) => isPptxFile(f));
173
+ if (pptx) {
174
+ await this.importFile(pptx);
175
+ return;
176
+ }
177
+ const images = files.filter((f) => /^image\/(png|jpeg|gif)$/i.test(f.type));
178
+ if (!images.length) return;
179
+ let point = null;
180
+ if (this.canvas.el.contains(e.target) || e.target === this.canvas.el) {
181
+ const rect = this.canvas.inner.getBoundingClientRect();
182
+ point = { x: (e.clientX - rect.left) / (this.zoom / 100), y: (e.clientY - rect.top) / (this.zoom / 100) };
183
+ }
184
+ for (const image of images) await this.insertImageFile(image, point);
185
+ }
186
+
187
+ export const keysMethods = { bindGlobal, isTypingTarget, onKeyDown, onPaste, onDrop };
@@ -1,105 +1,105 @@
1
- // [文件] gbpptx·slides·menus —— 右键菜单 —— 画布与缩略图两处上下文菜单
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
7
- import { openContextMenu } from '../ui/menu.js';
8
- import { icon } from '../ui/icons.js';
9
- function openCanvasMenu(x, y) {
10
- const has = this.selectedObjects().length > 0;
11
- const o = this.firstSelected();
12
- const items = [];
13
- if (!has) {
14
- items.push(
15
- { label: '粘贴', icon: 'paste', shortcut: 'Ctrl+V', disabled: !this.canPaste(), onClick: () => this.paste() },
16
- { divided: true },
17
- { label: '新建文本框', icon: 'textBox', onClick: () => this.insert('text') },
18
- { label: '新建幻灯片', icon: 'newSlide', shortcut: 'Ctrl+M', onClick: () => this.addSlide() },
19
- { divided: true },
20
- { label: '设置背景格式…', icon: 'background', onClick: () => this.openFormatPane() },
21
- { label: '网格线', checked: this.gridVisible, onClick: () => this.toggleGrid() },
22
- { label: '参考线', checked: this.guidesVisible, onClick: () => this.toggleGuides() },
23
- );
24
- } else {
25
- items.push(
26
- { label: '剪切', icon: 'cut', shortcut: 'Ctrl+X', onClick: () => this.cutSelected() },
27
- { label: '复制', icon: 'copy', shortcut: 'Ctrl+C', onClick: () => this.copySelected() },
28
- { label: '粘贴', icon: 'paste', shortcut: 'Ctrl+V', disabled: !this.canPaste(), onClick: () => this.paste() },
29
- { label: '复制对象', icon: 'duplicate', shortcut: 'Ctrl+D', onClick: () => this.duplicateSelected() },
30
- { divided: true },
31
- { label: '置于顶层', icon: 'bringForward', onClick: () => this.arrange('front') },
32
- { label: '上移一层', onClick: () => this.arrange('forward') },
33
- { label: '下移一层', onClick: () => this.arrange('backward') },
34
- { label: '置于底层', icon: 'sendBackward', onClick: () => this.arrange('back') },
35
- { divided: true },
36
- {
37
- label: '对齐页面',
38
- icon: 'alignLeft',
39
- children: [
40
- { label: '左对齐', onClick: () => this.alignToSlide('left') },
41
- { label: '水平居中', onClick: () => this.alignToSlide('centerH') },
42
- { label: '右对齐', onClick: () => this.alignToSlide('right') },
43
- { divided: true },
44
- { label: '顶端对齐', onClick: () => this.alignToSlide('top') },
45
- { label: '垂直居中', onClick: () => this.alignToSlide('middle') },
46
- { label: '底端对齐', onClick: () => this.alignToSlide('bottom') },
47
- ],
48
- },
49
- { divided: true },
50
- );
51
- if (o?.type === 'text' || o?.type === 'shape') {
52
- items.push({ label: '编辑文字', icon: 'text', onClick: () => this.startEditingById(o.id) });
53
- }
54
- if (o?.type === 'image') {
55
- items.push(
56
- { label: '替换图片…', icon: 'replaceImage', onClick: () => this.replaceSelectedImage() },
57
- { label: '裁剪图片…', icon: 'crop', onClick: () => this.cropSelected() },
58
- );
59
- }
60
- if (o?.type === 'table') {
61
- items.push(
62
- { label: '在上方插入行', icon: 'rowAbove', onClick: () => this.insertTableRow('above') },
63
- { label: '在下方插入行', icon: 'rowBelow', onClick: () => this.insertTableRow('below') },
64
- { label: '在左侧插入列', icon: 'colLeft', onClick: () => this.insertTableColumn('left') },
65
- { label: '在右侧插入列', icon: 'colRight', onClick: () => this.insertTableColumn('right') },
66
- );
67
- }
68
- items.push(
69
- { label: '设置形状格式…', icon: 'formatPane', onClick: () => this.openFormatPane() },
70
- { divided: true },
71
- { label: '删除对象', icon: 'delete', shortcut: 'Del', danger: true, onClick: () => this.removeSelected() },
72
- );
73
- }
74
- openContextMenu({ x, y, items });
75
- }
76
-
77
- function openSlideMenu(x, y, index) {
78
- const slide = this.snapshot.slides[index];
79
- if (!slide) return;
80
- openContextMenu({
81
- x,
82
- y,
83
- items: [
84
- { label: '新建幻灯片', icon: 'newSlide', onClick: () => this.addSlide() },
85
- { label: '复制幻灯片', icon: 'duplicate', onClick: () => this.dupSlide() },
86
- { label: '删除幻灯片', icon: 'delete', danger: true, disabled: this.snapshot.slides.length <= 1, onClick: () => this.delSlide() },
87
- { divided: true },
88
- { label: '隐藏幻灯片', icon: 'hide', checked: !!slide.hidden, onClick: () => this.toggleSlideHidden() },
89
- {
90
- label: '新建页(版式)',
91
- icon: 'layout',
92
- children: SLIDE_LAYOUTS.map((l) => ({ label: l.label, onClick: () => this.addSlide(l.key) })),
93
- },
94
- {
95
- label: '切换',
96
- icon: 'transition',
97
- children: TRANSITIONS.map((t) => ({ label: t.label, onClick: () => this.setTransition({ type: t.key, dir: t.dir || 'l' }) })),
98
- },
99
- { divided: true },
100
- { label: '设置背景格式…', icon: 'background', onClick: () => this.openFormatPane() },
101
- ],
102
- });
103
- }
104
-
105
- export const menusMethods = { openCanvasMenu, openSlideMenu };
1
+ // [文件] gbpptx·slides·menus —— 右键菜单 —— 画布与缩略图两处上下文菜单
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
7
+ import { openContextMenu } from '../ui/menu.js';
8
+ import { icon } from '../ui/icons.js';
9
+ function openCanvasMenu(x, y) {
10
+ const has = this.selectedObjects().length > 0;
11
+ const o = this.firstSelected();
12
+ const items = [];
13
+ if (!has) {
14
+ items.push(
15
+ { label: '粘贴', icon: 'paste', shortcut: 'Ctrl+V', disabled: !this.canPaste(), onClick: () => this.paste() },
16
+ { divided: true },
17
+ { label: '新建文本框', icon: 'textBox', onClick: () => this.insert('text') },
18
+ { label: '新建幻灯片', icon: 'newSlide', shortcut: 'Ctrl+M', onClick: () => this.addSlide() },
19
+ { divided: true },
20
+ { label: '设置背景格式…', icon: 'background', onClick: () => this.openFormatPane() },
21
+ { label: '网格线', checked: this.gridVisible, onClick: () => this.toggleGrid() },
22
+ { label: '参考线', checked: this.guidesVisible, onClick: () => this.toggleGuides() },
23
+ );
24
+ } else {
25
+ items.push(
26
+ { label: '剪切', icon: 'cut', shortcut: 'Ctrl+X', onClick: () => this.cutSelected() },
27
+ { label: '复制', icon: 'copy', shortcut: 'Ctrl+C', onClick: () => this.copySelected() },
28
+ { label: '粘贴', icon: 'paste', shortcut: 'Ctrl+V', disabled: !this.canPaste(), onClick: () => this.paste() },
29
+ { label: '复制对象', icon: 'duplicate', shortcut: 'Ctrl+D', onClick: () => this.duplicateSelected() },
30
+ { divided: true },
31
+ { label: '置于顶层', icon: 'bringForward', onClick: () => this.arrange('front') },
32
+ { label: '上移一层', onClick: () => this.arrange('forward') },
33
+ { label: '下移一层', onClick: () => this.arrange('backward') },
34
+ { label: '置于底层', icon: 'sendBackward', onClick: () => this.arrange('back') },
35
+ { divided: true },
36
+ {
37
+ label: '对齐页面',
38
+ icon: 'alignLeft',
39
+ children: [
40
+ { label: '左对齐', onClick: () => this.alignToSlide('left') },
41
+ { label: '水平居中', onClick: () => this.alignToSlide('centerH') },
42
+ { label: '右对齐', onClick: () => this.alignToSlide('right') },
43
+ { divided: true },
44
+ { label: '顶端对齐', onClick: () => this.alignToSlide('top') },
45
+ { label: '垂直居中', onClick: () => this.alignToSlide('middle') },
46
+ { label: '底端对齐', onClick: () => this.alignToSlide('bottom') },
47
+ ],
48
+ },
49
+ { divided: true },
50
+ );
51
+ if (o?.type === 'text' || o?.type === 'shape') {
52
+ items.push({ label: '编辑文字', icon: 'text', onClick: () => this.startEditingById(o.id) });
53
+ }
54
+ if (o?.type === 'image') {
55
+ items.push(
56
+ { label: '替换图片…', icon: 'replaceImage', onClick: () => this.replaceSelectedImage() },
57
+ { label: '裁剪图片…', icon: 'crop', onClick: () => this.cropSelected() },
58
+ );
59
+ }
60
+ if (o?.type === 'table') {
61
+ items.push(
62
+ { label: '在上方插入行', icon: 'rowAbove', onClick: () => this.insertTableRow('above') },
63
+ { label: '在下方插入行', icon: 'rowBelow', onClick: () => this.insertTableRow('below') },
64
+ { label: '在左侧插入列', icon: 'colLeft', onClick: () => this.insertTableColumn('left') },
65
+ { label: '在右侧插入列', icon: 'colRight', onClick: () => this.insertTableColumn('right') },
66
+ );
67
+ }
68
+ items.push(
69
+ { label: '设置形状格式…', icon: 'formatPane', onClick: () => this.openFormatPane() },
70
+ { divided: true },
71
+ { label: '删除对象', icon: 'delete', shortcut: 'Del', danger: true, onClick: () => this.removeSelected() },
72
+ );
73
+ }
74
+ openContextMenu({ x, y, items });
75
+ }
76
+
77
+ function openSlideMenu(x, y, index) {
78
+ const slide = this.snapshot.slides[index];
79
+ if (!slide) return;
80
+ openContextMenu({
81
+ x,
82
+ y,
83
+ items: [
84
+ { label: '新建幻灯片', icon: 'newSlide', onClick: () => this.addSlide() },
85
+ { label: '复制幻灯片', icon: 'duplicate', onClick: () => this.dupSlide() },
86
+ { label: '删除幻灯片', icon: 'delete', danger: true, disabled: this.snapshot.slides.length <= 1, onClick: () => this.delSlide() },
87
+ { divided: true },
88
+ { label: '隐藏幻灯片', icon: 'hide', checked: !!slide.hidden, onClick: () => this.toggleSlideHidden() },
89
+ {
90
+ label: '新建页(版式)',
91
+ icon: 'layout',
92
+ children: SLIDE_LAYOUTS.map((l) => ({ label: l.label, onClick: () => this.addSlide(l.key) })),
93
+ },
94
+ {
95
+ label: '切换',
96
+ icon: 'transition',
97
+ children: TRANSITIONS.map((t) => ({ label: t.label, onClick: () => this.setTransition({ type: t.key, dir: t.dir || 'l' }) })),
98
+ },
99
+ { divided: true },
100
+ { label: '设置背景格式…', icon: 'background', onClick: () => this.openFormatPane() },
101
+ ],
102
+ });
103
+ }
104
+
105
+ export const menusMethods = { openCanvasMenu, openSlideMenu };