gbpptx 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +253 -253
  3. package/package.json +48 -47
  4. package/src/index.js +29 -29
  5. package/src/kernel/model.js +651 -651
  6. package/src/kernel/parts.js +173 -173
  7. package/src/kernel/pptx.js +72 -72
  8. package/src/kernel/print.js +76 -76
  9. package/src/kernel/read.js +1018 -1018
  10. package/src/kernel/roundtrip.js +174 -174
  11. package/src/kernel/text.js +278 -278
  12. package/src/kernel/write.js +385 -385
  13. package/web/app/main.js +8 -8
  14. package/web/app/slides/arrange.js +101 -101
  15. package/web/app/slides/clipboard.js +93 -93
  16. package/web/app/slides/file.js +240 -240
  17. package/web/app/slides/find.js +201 -201
  18. package/web/app/slides/history.js +100 -100
  19. package/web/app/slides/keys.js +187 -187
  20. package/web/app/slides/menus.js +105 -105
  21. package/web/app/slides/objects.js +254 -254
  22. package/web/app/slides/render.js +183 -183
  23. package/web/app/slides/shared.js +85 -85
  24. package/web/app/slides/slides.js +103 -103
  25. package/web/app/slides/table.js +102 -102
  26. package/web/app/slides/text.js +418 -418
  27. package/web/app/slides/view.js +182 -182
  28. package/web/app/slides-app.js +354 -354
  29. package/web/app/ui/canvas.js +769 -769
  30. package/web/app/ui/color-panel.js +58 -58
  31. package/web/app/ui/dialogs.js +120 -120
  32. package/web/app/ui/file-io.js +116 -116
  33. package/web/app/ui/format-pane.js +427 -427
  34. package/web/app/ui/icons.js +241 -133
  35. package/web/app/ui/menu.js +77 -75
  36. package/web/app/ui/notify.js +45 -45
  37. package/web/app/ui/page-view.js +221 -221
  38. package/web/app/ui/popup.js +80 -80
  39. package/web/app/ui/present.js +292 -292
  40. package/web/app/ui/ribbon.js +855 -855
  41. package/web/app/ui/slide-pane.js +197 -197
  42. package/web/app/ui/statusbar.js +93 -93
  43. package/web/app/ui/text-styles.js +84 -84
  44. package/web/app/ui/titlebar.js +253 -250
  45. package/web/app/ui/transition.js +30 -30
  46. package/web/index.html +30 -29
  47. package/web/serve.mjs +26 -23
  48. package/web/styles/office.css +463 -463
  49. package/web/styles/slides.css +97 -97
  50. package/web/styles/tokens.css +154 -154
@@ -1,855 +1,855 @@
1
- // [文件] gbpptx·Ribbon —— Office 式功能区(开始/插入/设计/切换/放映/审阅/视图 + 形状/图片/表格上下文标签)
2
-
3
- import {
4
- FONT_FAMILIES, FONT_SIZES, TEXT_COLORS,
5
- } from './text-styles.js';
6
- import {
7
- SHAPE_KINDS, SLIDE_LAYOUTS, TABLE_STYLES, THEME_KEYS, TRANSITIONS, contrastText, shapePath, themeOf,
8
- } from '../../../src/kernel/model.js';
9
- import { icon } from './icons.js';
10
- import { openMenu } from './menu.js';
11
- import { openPopup } from './popup.js';
12
- import { openColorPanel } from './color-panel.js';
13
-
14
- const keepFocus = (el) => {
15
- el.addEventListener('mousedown', (e) => {
16
- if (e.button === 0) e.preventDefault();
17
- });
18
- };
19
-
20
- const el = (tag, cls, html) => {
21
- const node = document.createElement(tag);
22
- if (cls) node.className = cls;
23
- if (html != null) node.innerHTML = html;
24
- return node;
25
- };
26
-
27
- const button = (cls, html, title) => {
28
- const b = el('button', cls, html);
29
- b.type = 'button';
30
- if (title) b.title = title;
31
- keepFocus(b);
32
- return b;
33
- };
34
-
35
- const big = (name, label, onClick, title) => {
36
- const b = button('pp-rb-big', `${icon(name, 26)}<span class="pp-rb-big__label">${label}</span>`, title || label);
37
- b.addEventListener('click', onClick);
38
- return b;
39
- };
40
-
41
- const splitBig = (name, label, onClick, onMenu, title) => {
42
- const wrap = el('div', 'pp-rb-split');
43
- const main = big(name, label, onClick, title);
44
- const caret = button('pp-rb-split__caret', icon('chevronDown', 12), '更多');
45
- caret.addEventListener('click', onMenu);
46
- wrap.append(main, caret);
47
- return wrap;
48
- };
49
-
50
- const small = (name, label, onClick, title, cls = '') => {
51
- const b = button(`pp-rb-small${cls ? ` ${cls}` : ''}`, `${icon(name, 16)}${label ? `<span>${label}</span>` : ''}`, title || label || name);
52
- b.addEventListener('click', onClick);
53
- return b;
54
- };
55
-
56
- const menuButton = (name, label, items, title, cls = '') => {
57
- const b = small(name, label, () => openMenu({ anchor: b, items: items() }), title || label, cls);
58
- return b;
59
- };
60
-
61
- const column = (...children) => {
62
- const c = el('div', 'pp-rb-col');
63
- c.append(...children);
64
- return c;
65
- };
66
-
67
- const group = (label, ...children) => {
68
- const g = el('div', 'pp-rb-group');
69
- const body = el('div', 'pp-rb-group__body');
70
- body.append(...children);
71
- const cap = el('div', 'pp-rb-group__label');
72
- cap.textContent = label;
73
- g.append(body, cap);
74
- return g;
75
- };
76
-
77
- const combo = (width, onClick, title) => {
78
- const b = button('pp-rb-combo', '<span class="pp-rb-combo__label"></span><span class="pp-rb-combo__caret">▾</span>', title);
79
- b.style.width = `${width}px`;
80
- b.addEventListener('click', onClick);
81
- return b;
82
- };
83
-
84
- const colorButton = (name, label, title, getColor, onPick) => {
85
- const b = button('pp-rb-small pp-rb-colorbtn', `${icon(name, 16)}${label ? `<span>${label}</span>` : ''}<i class="pp-rb-colorbar"></i>`, title);
86
- b.addEventListener('click', (e) => {
87
- openColorPanel({
88
- anchor: e.currentTarget,
89
- colors: TEXT_COLORS,
90
- value: getColor() || '',
91
- columns: 10,
92
- title,
93
- onPick,
94
- });
95
- });
96
- b.colorBar = b.querySelector('.pp-rb-colorbar');
97
- return b;
98
- };
99
-
100
- const blend = (a, b, t) => {
101
- const parse = (hex) => {
102
- const n = Number.parseInt(String(hex).replace('#', ''), 16);
103
- return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
104
- };
105
- const x = parse(a);
106
- const y = parse(b);
107
- const k = Math.max(0, Math.min(1, t));
108
- return `#${[x.r + (y.r - x.r) * k, x.g + (y.g - x.g) * k, x.b + (y.b - x.b) * k]
109
- .map((v) => Math.round(v).toString(16).padStart(2, '0')).join('')}`;
110
- };
111
-
112
- const readableText = (background, fallback) => {
113
- const n = Number.parseInt(String(background).replace('#', ''), 16);
114
- const lum = Number.isFinite(n) ? (0.2126 * ((n >> 16) & 255) + 0.7152 * ((n >> 8) & 255) + 0.0722 * (n & 255)) / 255 : 1;
115
- return lum > 0.55 ? '#201f1e' : fallback;
116
- };
117
-
118
- /** 形状快速样式(按当前主题推导) */
119
- export function shapeQuickStyles(themeKey) {
120
- const t = themeOf(themeKey);
121
- return [
122
- { key: 'accent', label: '彩色填充', fill: t.accent, stroke: '', text: contrastText(t.accent) },
123
- { key: 'light', label: '浅色填充', fill: blend(t.accent, t.bg, 0.8), stroke: t.accent, text: readableText(blend(t.accent, t.bg, 0.8), t.text) },
124
- { key: 'outline', label: '轮廓', fill: '', stroke: t.accent, text: t.text },
125
- { key: 'deep', label: '深色填充', fill: blend(t.accent, '#000000', 0.55), stroke: '', text: '#ffffff' },
126
- { key: 'paper', label: '浅色轮廓', fill: t.bg, stroke: blend(t.text, t.bg, 0.5), text: t.text },
127
- { key: 'dark', label: '深色强调', fill: t.text, stroke: '', text: contrastText(t.text) },
128
- ];
129
- }
130
-
131
- function openShapeGallery(anchor, onPick) {
132
- const box = el('div', 'pp-shape-gallery');
133
- const handle = { close: () => {} };
134
- for (const s of SHAPE_KINDS) {
135
- const item = button('pp-shape-gallery__item', `<svg viewBox="0 0 40 30" width="40" height="30" aria-hidden="true"><path d="${shapePath(s.kind, 34, 24)}" transform="translate(3,3)" fill="currentColor"/></svg><span>${s.label}</span>`, s.label);
136
- item.addEventListener('click', () => { handle.close(); onPick(s.kind); });
137
- box.appendChild(item);
138
- }
139
- Object.assign(handle, openPopup({ anchor, content: box, placement: 'bottom-start', className: 'pp-popup--gallery' }));
140
- return handle;
141
- }
142
-
143
- /** Office 式表格尺寸选择器 */
144
- function openTableGrid(anchor, onPick) {
145
- const box = el('div', 'pp-table-grid');
146
- const title = el('div', 'pp-table-grid__title', '插入表格');
147
- const hint = el('div', 'pp-table-grid__hint', '1×1 表格');
148
- const grid = el('div', 'pp-table-grid__grid');
149
- const cells = [];
150
- for (let r = 1; r <= 8; r += 1) {
151
- for (let c = 1; c <= 10; c += 1) {
152
- const cell = button('pp-table-grid__cell', '', `${r}×${c}`);
153
- cell.dataset.r = String(r);
154
- cell.dataset.c = String(c);
155
- cell.addEventListener('mouseenter', () => {
156
- hint.textContent = `${r}×${c} 表格`;
157
- for (const x of cells) {
158
- x.classList.toggle('gbp-is-on', Number(x.dataset.r) <= r && Number(x.dataset.c) <= c);
159
- }
160
- });
161
- cell.addEventListener('click', () => { handle.close(); onPick(r, c); });
162
- cells.push(cell);
163
- grid.appendChild(cell);
164
- }
165
- }
166
- grid.addEventListener('mouseleave', () => {
167
- for (const x of cells) x.classList.remove('gbp-is-on');
168
- hint.textContent = '1×1 表格';
169
- });
170
- box.append(title, grid, hint);
171
- const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'pp-popup--table-grid' });
172
- return handle;
173
- }
174
-
175
- export class Ribbon {
176
- constructor(app) {
177
- this.app = app;
178
- this.el = el('div', 'pp-ribbon');
179
- this.updates = [];
180
- this.contextKey = '';
181
- this.contextTabs = [];
182
- this.panels = new Map();
183
- this.activeTab = 'home';
184
-
185
- this.tabsEl = el('div', 'pp-ribbon__tabs');
186
- this.bodyEl = el('div', 'pp-ribbon__body');
187
- this.el.append(this.tabsEl, this.bodyEl);
188
- this.buildTabs();
189
- this.buildPanels();
190
- this.activate(app.prefs.ribbonTab && this.isKnownTab(app.prefs.ribbonTab) ? app.prefs.ribbonTab : 'home', { expand: false });
191
- this.setCollapsed(!!app.ribbonCollapsed);
192
- this.refresh();
193
- }
194
-
195
- /* ===================== 骨架 ===================== */
196
-
197
- isKnownTab(key) {
198
- return ['home', 'insert', 'design', 'transitions', 'slideshow', 'review', 'view'].includes(key);
199
- }
200
-
201
- buildTabs() {
202
- const defs = [
203
- ['home', '开始'], ['insert', '插入'], ['design', '设计'], ['transitions', '切换'],
204
- ['slideshow', '幻灯片放映'], ['review', '审阅'], ['view', '视图'],
205
- ];
206
- for (const [key, label] of defs) {
207
- const tab = button('pp-rb-tab', label, label);
208
- tab.dataset.tab = key;
209
- tab.addEventListener('click', () => this.activate(key));
210
- this.tabsEl.appendChild(tab);
211
- }
212
- this.contextHost = el('div', 'pp-rb-tabs__context');
213
- this.tabsEl.appendChild(this.contextHost);
214
- const spacer = el('div', 'pp-rb-tabs__spacer');
215
- this.tabsEl.appendChild(spacer);
216
- this.collapseBtn = button('pp-rb-collapse', icon('chevronDown', 14), '收起功能区');
217
- this.collapseBtn.addEventListener('click', () => {
218
- this.app.setRibbonCollapsed(!this.app.ribbonCollapsed);
219
- });
220
- this.tabsEl.appendChild(this.collapseBtn);
221
- }
222
-
223
- buildPanels() {
224
- const builders = {
225
- home: (p) => this.buildHome(p),
226
- insert: (p) => this.buildInsert(p),
227
- design: (p) => this.buildDesign(p),
228
- transitions: (p) => this.buildTransitions(p),
229
- slideshow: (p) => this.buildSlideshow(p),
230
- review: (p) => this.buildReview(p),
231
- view: (p) => this.buildView(p),
232
- };
233
- for (const [key, build] of Object.entries(builders)) {
234
- const panel = el('div', 'pp-rb-panel');
235
- panel.dataset.tab = key;
236
- panel.hidden = true;
237
- build(panel);
238
- this.panels.set(key, panel);
239
- this.bodyEl.appendChild(panel);
240
- }
241
- }
242
-
243
- panel(key) {
244
- if (!this.panels.has(key)) {
245
- const panel = el('div', 'pp-rb-panel');
246
- panel.dataset.tab = key;
247
- panel.hidden = true;
248
- if (key === 'ctx-shape') this.buildContextShape(panel);
249
- if (key === 'ctx-image') this.buildContextImage(panel);
250
- if (key === 'ctx-table') this.buildContextTable(panel);
251
- this.panels.set(key, panel);
252
- this.bodyEl.appendChild(panel);
253
- }
254
- return this.panels.get(key);
255
- }
256
-
257
- activate(key, { expand = true } = {}) {
258
- if (!this.isKnownTab(key) && !['ctx-shape', 'ctx-image', 'ctx-table'].includes(key)) key = 'home';
259
- this.activeTab = key;
260
- this.app.prefs.ribbonTab = key;
261
- for (const tab of this.tabsEl.querySelectorAll('.pp-rb-tab')) {
262
- tab.classList.toggle('gbp-is-active', tab.dataset.tab === key);
263
- }
264
- for (const [k, panel] of this.panels) panel.hidden = k !== key;
265
- this.panel(key);
266
- for (const [k, panel] of this.panels) panel.hidden = k !== key;
267
- if (expand && this.app.ribbonCollapsed) this.app.setRibbonCollapsed(false);
268
- this.refresh();
269
- }
270
-
271
- setCollapsed(on) {
272
- this.el.classList.toggle('gbp-is-collapsed', !!on);
273
- this.collapseBtn.innerHTML = icon(on ? 'chevronUp' : 'chevronDown', 14);
274
- this.collapseBtn.title = on ? '展开功能区' : '收起功能区';
275
- }
276
-
277
- reg(target, update) {
278
- this.updates.push({ target, update });
279
- update();
280
- return target;
281
- }
282
-
283
- refresh() {
284
- this.ensureContext();
285
- for (const entry of this.updates) {
286
- if (!entry.target.isConnected) continue;
287
- entry.update();
288
- }
289
- }
290
-
291
- /* ===================== 上下文标签 ===================== */
292
-
293
- selectionKind() {
294
- const app = this.app;
295
- if (app.selectedIds.length !== 1) return '';
296
- const o = app.firstSelected();
297
- if (!o) return '';
298
- if (o.type === 'shape' || o.type === 'line') return 'shape';
299
- if (o.type === 'image') return 'image';
300
- if (o.type === 'table') return 'table';
301
- return '';
302
- }
303
-
304
- ensureContext() {
305
- const kind = this.selectionKind();
306
- if (kind === this.contextKey) return;
307
- this.contextHost.replaceChildren();
308
- for (const t of this.contextTabs) {
309
- this.panels.get(t.key)?.remove();
310
- this.panels.delete(t.key);
311
- this.updates = this.updates.filter((u) => u.target.isConnected);
312
- }
313
- this.contextTabs = [];
314
- this.contextKey = kind;
315
- if (!kind) {
316
- if (this.activeTab.startsWith('ctx-')) this.activate('home', { expand: false });
317
- return;
318
- }
319
- const defs = {
320
- shape: { key: 'ctx-shape', label: '形状格式' },
321
- image: { key: 'ctx-image', label: '图片格式' },
322
- table: { key: 'ctx-table', label: '表格' },
323
- };
324
- const def = defs[kind];
325
- const tab = button('pp-rb-tab pp-rb-tab--context', def.label, def.label);
326
- tab.dataset.tab = def.key;
327
- tab.addEventListener('click', () => this.activate(def.key));
328
- this.contextHost.appendChild(tab);
329
- this.contextTabs.push(def);
330
- this.panel(def.key);
331
- if (this.activeTab.startsWith('ctx-')) this.activate(def.key, { expand: false });
332
- }
333
-
334
- /* ===================== 开始 ===================== */
335
-
336
- buildHome(panel) {
337
- const app = this.app;
338
- const hasSel = () => app.selectedIds.length > 0;
339
- const canText = () => app.canFormatText();
340
- const canRich = () => app.canRichText();
341
- const canAlign = () => app.canAlignText();
342
- const canList = () => app.canList();
343
- const state = () => app.textState();
344
-
345
- /* 剪贴板 */
346
- const pasteWrap = el('div', 'pp-rb-split');
347
- const pasteMain = big('paste', '粘贴', () => app.paste(), '粘贴 (Ctrl+V)');
348
- const pasteCaret = button('pp-rb-split__caret', icon('chevronDown', 12), '粘贴选项');
349
- pasteCaret.addEventListener('click', () => openMenu({
350
- anchor: pasteCaret,
351
- items: [
352
- { label: '粘贴', icon: 'paste', onClick: () => app.paste() },
353
- { label: '粘贴为纯文本', icon: 'text', onClick: () => app.pastePlain() },
354
- ],
355
- }));
356
- pasteWrap.append(pasteMain, pasteCaret);
357
- const cutBtn = small('cut', '剪切', () => app.cutSelected(), '剪切 (Ctrl+X)');
358
- const copyBtn = small('copy', '复制', () => app.copySelected(), '复制 (Ctrl+C)');
359
- const clip = group('剪贴板', pasteWrap, column(cutBtn, copyBtn));
360
- panel.appendChild(clip);
361
-
362
- /* 幻灯片 */
363
- const newSlide = splitBig('newSlide', '新建幻灯片', () => app.addSlide(), (e) => this.layoutMenu(e.currentTarget), '新建幻灯片 (Ctrl+M)');
364
- const hideBtn = small('hide', '隐藏', () => app.toggleSlideHidden(), '隐藏幻灯片');
365
- const resetBtn = small('reset', '重设', () => app.resetSelected(), '重设位置与大小');
366
- panel.appendChild(group('幻灯片', newSlide, column(hideBtn, resetBtn)));
367
-
368
- /* 字体 */
369
- const fontBtn = combo(132, () => openMenu({
370
- anchor: fontBtn,
371
- items: FONT_FAMILIES.map((f) => ({ label: f.label, checked: state().font === f.value, onClick: () => app.applyFontFamily(f.value) })),
372
- }), '字体');
373
- const sizeBtn = combo(64, () => openMenu({
374
- anchor: sizeBtn,
375
- items: FONT_SIZES.map((s) => ({ label: String(s), checked: Math.round(state().fontSize) === s, onClick: () => app.applyFontSize(s) })),
376
- }), '字号');
377
- const boldBtn = small('bold', '', () => app.toggleTextStyle('bold'), '加粗 (Ctrl+B)');
378
- const italicBtn = small('italic', '', () => app.toggleTextStyle('italic'), '斜体 (Ctrl+I)');
379
- const underlineBtn = small('underline', '', () => app.toggleTextStyle('underline'), '下划线 (Ctrl+U)');
380
- const strikeBtn = small('strike', '', () => app.toggleTextStyle('strike'), '删除线');
381
- const incBtn = small('increaseFont', '', () => app.stepFontSize(1), '增大字号');
382
- const decBtn = small('decreaseFont', '', () => app.stepFontSize(-1), '减小字号');
383
- const clearBtn = small('clearFormat', '清除格式', () => app.clearFormatting(), '清除所有格式');
384
- const fontColor = colorButton('fontColor', '', '字体颜色', () => state().color || themeOf(app.snapshot.theme).text, (c) => app.applyTextColor(c));
385
- panel.appendChild(group('字体',
386
- fontBtn, sizeBtn, column(incBtn, decBtn),
387
- column(boldBtn, italicBtn),
388
- column(underlineBtn, strikeBtn),
389
- column(clearBtn, fontColor),
390
- ));
391
-
392
- /* 段落 */
393
- const bulletBtn = small('bullets', '', () => app.applyList('bullet'), '项目符号');
394
- const numberBtn = small('numbering', '', () => app.applyList('number'), '编号');
395
- const outdentBtn = small('indentDecrease', '', () => app.applyIndent(-1), '减少缩进');
396
- const indentBtn = small('indentIncrease', '', () => app.applyIndent(1), '增加缩进');
397
- const lineBtn = combo(74, () => openMenu({
398
- anchor: lineBtn,
399
- items: [1, 1.15, 1.5, 2, 2.5, 3].map((v) => ({
400
- label: v === 1 ? '1.0' : String(v),
401
- checked: Math.abs(state().lineSpacing - v) < 0.01,
402
- onClick: () => app.applyLineSpacing(v),
403
- })),
404
- }), '行距');
405
- const alignLeft = small('alignLeft', '', () => app.applyAlign('left'), '左对齐 (Ctrl+L)');
406
- const alignCenter = small('alignCenter', '', () => app.applyAlign('center'), '居中 (Ctrl+E)');
407
- const alignRight = small('alignRight', '', () => app.applyAlign('right'), '右对齐 (Ctrl+R)');
408
- const alignJustify = small('alignJustify', '', () => app.applyAlign('justify'), '两端对齐 (Ctrl+J)');
409
- panel.appendChild(group('段落',
410
- column(bulletBtn, numberBtn),
411
- column(outdentBtn, indentBtn),
412
- lineBtn,
413
- column(alignLeft, alignCenter),
414
- column(alignRight, alignJustify),
415
- ));
416
-
417
- /* 形状与排列 */
418
- const shapeBtn = big('shapes', '形状', (e) => openShapeGallery(e.currentTarget, (kind) => app.insert('shape', kind)), '插入形状');
419
- const fillBtn = colorButton('fill', '填充', '形状填充', () => (app.firstSelected()?.props?.fill || ''), (c) => app.setSelectedProp('fill', c));
420
- const outlineBtn = colorButton('outline', '轮廓', '形状轮廓', () => (app.firstSelected()?.props?.stroke || ''), (c) => app.setSelectedProp('stroke', c));
421
- const effectsBtn = menuButton('effects', '效果', () => [
422
- { label: '无阴影', checked: !app.firstSelected()?.props?.shadow, icon: 'effects', onClick: () => app.setSelectedProp('shadow', false) },
423
- { label: '阴影', checked: !!app.firstSelected()?.props?.shadow, icon: 'shadow', onClick: () => app.setSelectedProp('shadow', true) },
424
- ], '形状效果');
425
- const arrangeItems = () => [
426
- { label: '置于顶层', icon: 'bringForward', onClick: () => app.arrange('front') },
427
- { label: '上移一层', onClick: () => app.arrange('forward') },
428
- { label: '下移一层', onClick: () => app.arrange('backward') },
429
- { label: '置于底层', icon: 'sendBackward', onClick: () => app.arrange('back') },
430
- { divided: true },
431
- {
432
- label: '对齐',
433
- icon: 'alignLeft',
434
- children: [
435
- { label: '左对齐', onClick: () => app.alignToSlide('left') },
436
- { label: '水平居中', onClick: () => app.alignToSlide('centerH') },
437
- { label: '右对齐', onClick: () => app.alignToSlide('right') },
438
- { divided: true },
439
- { label: '顶端对齐', onClick: () => app.alignToSlide('top') },
440
- { label: '垂直居中', onClick: () => app.alignToSlide('middle') },
441
- { label: '底端对齐', onClick: () => app.alignToSlide('bottom') },
442
- ],
443
- },
444
- {
445
- label: '分布',
446
- children: [
447
- { label: '横向分布', onClick: () => app.distribute('h') },
448
- { label: '纵向分布', onClick: () => app.distribute('v') },
449
- ],
450
- },
451
- ];
452
- const arrangeBtn = menuButton('arrange', '排列', arrangeItems, '排列');
453
- const selectBtn = menuButton('selectAll', '选择', () => [
454
- { label: '全选', shortcut: 'Ctrl+A', onClick: () => app.selectAll() },
455
- { label: '取消选择', shortcut: 'Esc', onClick: () => app.clearSelection() },
456
- ], '选择');
457
- panel.appendChild(group('形状', shapeBtn, column(fillBtn, outlineBtn), column(effectsBtn, arrangeBtn), selectBtn));
458
-
459
- /* 编辑 */
460
- const findBtn = big('find', '查找', () => app.openFind(false), '查找 (Ctrl+F)');
461
- const replaceBtn = small('replace', '替换', () => app.openFind(true), '替换 (Ctrl+H)');
462
- const selectAllBtn = small('selectAll', '全选', () => app.selectAll(), '全选 (Ctrl+A)');
463
- panel.appendChild(group('编辑', findBtn, column(replaceBtn, selectAllBtn)));
464
-
465
- /* 状态刷新 */
466
- this.reg(boldBtn, () => { boldBtn.classList.toggle('gbp-is-active', !!state().bold); boldBtn.disabled = !canRich(); });
467
- this.reg(italicBtn, () => { italicBtn.classList.toggle('gbp-is-active', !!state().italic); italicBtn.disabled = !canRich(); });
468
- this.reg(underlineBtn, () => { underlineBtn.classList.toggle('gbp-is-active', !!state().underline); underlineBtn.disabled = !canRich(); });
469
- this.reg(strikeBtn, () => { strikeBtn.classList.toggle('gbp-is-active', !!state().strike); strikeBtn.disabled = !canRich(); });
470
- this.reg(alignLeft, () => { alignLeft.classList.toggle('gbp-is-active', state().align === 'left'); alignLeft.disabled = !canAlign(); });
471
- this.reg(alignCenter, () => { alignCenter.classList.toggle('gbp-is-active', state().align === 'center'); alignCenter.disabled = !canAlign(); });
472
- this.reg(alignRight, () => { alignRight.classList.toggle('gbp-is-active', state().align === 'right'); alignRight.disabled = !canAlign(); });
473
- this.reg(alignJustify, () => { alignJustify.classList.toggle('gbp-is-active', state().align === 'justify'); alignJustify.disabled = !canAlign(); });
474
- this.reg(bulletBtn, () => { bulletBtn.classList.toggle('gbp-is-active', state().list === 'bullet'); bulletBtn.disabled = !canList(); });
475
- this.reg(numberBtn, () => { numberBtn.classList.toggle('gbp-is-active', state().list === 'number'); numberBtn.disabled = !canList(); });
476
- const inList = () => app.editing?.kind === 'text' && Boolean(state().list);
477
- this.reg(outdentBtn, () => { outdentBtn.disabled = !inList(); });
478
- this.reg(indentBtn, () => { indentBtn.disabled = !inList(); });
479
- this.reg(fontBtn, () => {
480
- fontBtn.disabled = !canText();
481
- const f = FONT_FAMILIES.find((x) => x.value === state().font);
482
- fontBtn.querySelector('.pp-rb-combo__label').textContent = f ? f.label : (state().font ? String(state().font).split(',')[0].replace(/["']/g, '') : '默认');
483
- });
484
- this.reg(sizeBtn, () => {
485
- sizeBtn.disabled = !canText();
486
- sizeBtn.querySelector('.pp-rb-combo__label').textContent = state().fontSize ? String(Math.round(state().fontSize)) : '字号';
487
- });
488
- this.reg(incBtn, () => { incBtn.disabled = !canText(); });
489
- this.reg(decBtn, () => { decBtn.disabled = !canText(); });
490
- this.reg(clearBtn, () => {
491
- clearBtn.disabled = !app.editing && !app.selectedObjects().some((o) => ['text', 'shape', 'table'].includes(o.type));
492
- });
493
- this.reg(cutBtn, () => { cutBtn.disabled = !hasSel() && !app.editing; });
494
- this.reg(copyBtn, () => { copyBtn.disabled = !hasSel() && !app.editing; });
495
- this.reg(fontColor, () => {
496
- fontColor.disabled = !canText();
497
- fontColor.colorBar.style.background = state().color || themeOf(app.snapshot.theme).text;
498
- });
499
- this.reg(lineBtn, () => {
500
- lineBtn.disabled = !canRich();
501
- const v = state().lineSpacing || 1;
502
- lineBtn.querySelector('.pp-rb-combo__label').textContent = Math.abs(v - 1) < 0.01 ? '1.0' : String(v);
503
- });
504
- this.reg(fillBtn, () => {
505
- const o = app.firstSelected();
506
- fillBtn.disabled = !o || o.type === 'line';
507
- fillBtn.colorBar.style.background = o?.props?.fill || 'transparent';
508
- fillBtn.classList.toggle('gbp-is-off', !o?.props?.fill);
509
- });
510
- this.reg(outlineBtn, () => {
511
- const o = app.firstSelected();
512
- outlineBtn.disabled = !o;
513
- outlineBtn.colorBar.style.background = o?.props?.stroke || 'transparent';
514
- outlineBtn.classList.toggle('gbp-is-off', !o?.props?.stroke || !o?.props?.strokeW);
515
- });
516
- this.reg(effectsBtn, () => {
517
- const o = app.firstSelected();
518
- effectsBtn.disabled = !o || o.type === 'line';
519
- effectsBtn.classList.toggle('gbp-is-active', !!o?.props?.shadow);
520
- });
521
- this.reg(arrangeBtn, () => { arrangeBtn.disabled = !hasSel(); });
522
- this.reg(selectBtn, () => { selectBtn.disabled = !app.snapshot.slides.length; });
523
- this.reg(pasteMain, () => { pasteMain.disabled = !app.canPaste(); });
524
- this.reg(hideBtn, () => { hideBtn.disabled = false; hideBtn.classList.toggle('gbp-is-active', !!app.currentSlide()?.hidden); });
525
- this.reg(resetBtn, () => { resetBtn.disabled = !hasSel(); });
526
- }
527
-
528
- layoutMenu(anchor) {
529
- openMenu({
530
- anchor,
531
- items: SLIDE_LAYOUTS.map((l) => ({ label: l.label, onClick: () => this.app.addSlide(l.key) })),
532
- });
533
- }
534
-
535
- /* ===================== 插入 ===================== */
536
-
537
- buildInsert(panel) {
538
- const app = this.app;
539
- const newSlide = splitBig('newSlide', '新建幻灯片', () => app.addSlide(), (e) => this.layoutMenu(e.currentTarget));
540
- panel.appendChild(group('幻灯片', newSlide));
541
-
542
- const tableBtn = big('table', '表格', (e) => openTableGrid(e.currentTarget, (r, c) => app.insertTable(r, c)), '插入表格');
543
- panel.appendChild(group('表格', tableBtn));
544
-
545
- const pic = big('image', '图片', () => app.insert('image'), '插入图片');
546
- const shape = big('shapes', '形状', (e) => openShapeGallery(e.currentTarget, (kind) => app.insert('shape', kind)), '插入形状');
547
- const text = big('textBox', '文本框', () => app.insert('text'), '插入文本框');
548
- const line = small('line', '线条', () => app.insert('line'), '插入线条');
549
- const arrow = small('arrow', '箭头', () => app.insert('arrow'), '插入箭头');
550
- panel.appendChild(group('插图', pic, shape, text, column(line, arrow)));
551
-
552
- const notes = small('notes', '备注', () => app.toggleNotes(), '显示/隐藏备注');
553
- panel.appendChild(group('显示', notes));
554
- }
555
-
556
- /* ===================== 设计 ===================== */
557
-
558
- buildDesign(panel) {
559
- const app = this.app;
560
- const gallery = el('div', 'pp-theme-gallery');
561
- const cards = new Map();
562
- for (const key of THEME_KEYS) {
563
- const t = themeOf(key);
564
- const card = button('pp-theme-card', '', t.label);
565
- card.style.setProperty('--gbp-t-bg', t.bg);
566
- card.style.setProperty('--gbp-t-text', t.text);
567
- card.style.setProperty('--gbp-t-accent', t.accent);
568
- card.innerHTML = `<span class="pp-theme-card__preview"><i class="pp-theme-card__title"></i><i class="pp-theme-card__line"></i><i class="pp-theme-card__block"></i></span><span class="pp-theme-card__label">${t.label}</span>`;
569
- card.addEventListener('click', () => app.setTheme(key));
570
- cards.set(key, card);
571
- gallery.appendChild(card);
572
- }
573
- panel.appendChild(group('主题', gallery));
574
-
575
- const bgBtn = big('background', '设置背景格式', () => app.openFormatPane(), '设置背景格式');
576
- const bgColor = colorButton('fill', '背景色', '页面背景色', () => app.currentSlide()?.bg || themeOf(app.snapshot.theme).bg, (c) => app.setSlideBg(c));
577
- const bgReset = small('reset', '重置背景', () => app.setSlideBg(''), '跟随主题背景');
578
- panel.appendChild(group('背景', bgBtn, column(bgColor, bgReset)));
579
-
580
- const wide = small('size', '宽屏', () => app.setSlideSize('wide'), '16:9');
581
- const standard = small('size', '标准', () => app.setSlideSize('standard'), '4:3');
582
- panel.appendChild(group('幻灯片大小', column(wide, standard)));
583
-
584
- this.reg(gallery, () => {
585
- for (const [key, card] of cards) card.classList.toggle('gbp-is-active', app.snapshot.theme === key);
586
- });
587
- this.reg(bgColor, () => {
588
- const bg = app.currentSlide()?.bg;
589
- bgColor.colorBar.style.background = bg || themeOf(app.snapshot.theme).bg;
590
- bgColor.classList.toggle('gbp-is-off', !bg);
591
- });
592
- }
593
-
594
- /* ===================== 切换 ===================== */
595
-
596
- buildTransitions(panel) {
597
- const app = this.app;
598
- const gallery = el('div', 'pp-transition-gallery');
599
- const cards = new Map();
600
- const iconOf = { none: 'close', fade: 'effects', push: 'arrow', wipe: 'outline', cover: 'bringForward', split: 'viewSorter', zoom: 'zoomIn' };
601
- for (const tr of TRANSITIONS) {
602
- const card = button('pp-transition-card', `<span class="pp-transition-card__ico">${icon(iconOf[tr.key] || 'transition', 20)}</span><span>${tr.label}</span>`, tr.label);
603
- card.addEventListener('click', () => {
604
- app.setTransition({ type: tr.key, dir: tr.dir || 'l' });
605
- app.previewTransition();
606
- });
607
- cards.set(tr.key, card);
608
- gallery.appendChild(card);
609
- }
610
- panel.appendChild(group('切换到此幻灯片', gallery));
611
-
612
- const duration = combo(82, () => openMenu({
613
- anchor: duration,
614
- items: [
615
- { label: '0.5 秒', checked: app.currentSlide().transition?.speed === 'fast', onClick: () => app.setTransition({ speed: 'fast' }) },
616
- { label: '1 秒', checked: !app.currentSlide().transition?.speed || app.currentSlide().transition?.speed === 'med', onClick: () => app.setTransition({ speed: 'med' }) },
617
- { label: '2 秒', checked: app.currentSlide().transition?.speed === 'slow', onClick: () => app.setTransition({ speed: 'slow' }) },
618
- ],
619
- }), '持续时间');
620
- const applyAll = small('selectAll', '应用到全部', () => app.applyTransitionAll(), '应用到全部幻灯片');
621
- const preview = big('play', '预览', () => app.previewTransition(), '预览切换');
622
- panel.appendChild(group('计时', duration, column(applyAll)));
623
- panel.appendChild(group('预览', preview));
624
-
625
- this.reg(gallery, () => {
626
- const type = app.currentSlide()?.transition?.type || 'none';
627
- for (const [key, card] of cards) card.classList.toggle('gbp-is-active', key === type);
628
- });
629
- this.reg(duration, () => {
630
- const speed = app.currentSlide()?.transition?.speed || 'med';
631
- duration.querySelector('.pp-rb-combo__label').textContent = speed === 'fast' ? '0.5 秒' : speed === 'slow' ? '2 秒' : '1 秒';
632
- });
633
- }
634
-
635
- /* ===================== 幻灯片放映 ===================== */
636
-
637
- buildSlideshow(panel) {
638
- const app = this.app;
639
- const fromStart = big('play', '从头开始', () => app.presentFromStart(), '从头开始放映 (F5)');
640
- const fromCurrent = big('present', '从当前页', () => app.presentFromCurrent(), '从当前幻灯片开始 (Shift+F5)');
641
- const presenter = small('presenter', '演讲者视图', () => app.togglePresenter(), '使用演讲者视图');
642
- const loop = small('loop', '循环放映', () => app.toggleLoop(), '按 Esc 前循环放映');
643
- const hide = small('hide', '隐藏幻灯片', () => app.toggleSlideHidden(), '隐藏当前幻灯片');
644
- panel.appendChild(group('开始放映幻灯片', fromStart, fromCurrent, column(presenter, hide)));
645
- panel.appendChild(group('设置', column(loop)));
646
-
647
- this.reg(presenter, () => presenter.classList.toggle('gbp-is-active', !!app.presentOptions.presenter));
648
- this.reg(loop, () => loop.classList.toggle('gbp-is-active', !!app.presentOptions.loop));
649
- this.reg(hide, () => hide.classList.toggle('gbp-is-active', !!app.currentSlide()?.hidden));
650
- }
651
-
652
- /* ===================== 审阅 ===================== */
653
-
654
- buildReview(panel) {
655
- const app = this.app;
656
- const notes = big('notes', '显示备注', () => app.toggleNotes(), '显示/隐藏备注窗格');
657
- const count = big('wordCount', '字数统计', () => app.showWordCount(), '统计幻灯片与文字数量');
658
- panel.appendChild(group('备注', notes));
659
- panel.appendChild(group('校对', count));
660
- this.reg(notes, () => notes.classList.toggle('gbp-is-active', !!app.notesVisible));
661
- }
662
-
663
- /* ===================== 视图 ===================== */
664
-
665
- buildView(panel) {
666
- const app = this.app;
667
- const normal = big('viewNormal', '普通', () => app.setView('normal'), '普通视图');
668
- const sorter = big('viewSorter', '幻灯片浏览', () => app.setView('sorter'), '幻灯片浏览视图');
669
- const reading = big('viewReading', '阅读视图', () => app.setView('reading'), '阅读视图');
670
- const grid = small('grid', '网格线', () => app.toggleGrid(), '显示网格线');
671
- const guides = small('guides', '参考线', () => app.toggleGuides(), '显示参考线');
672
- const notes = small('notes', '备注', () => app.toggleNotes(), '显示备注');
673
- const pane = small('formatPane', '格式窗格', () => app.toggleFormatPane(), '设置形状格式窗格');
674
- const fit = big('fitWindow', '适应窗口', () => app.fitToWindow(), '缩放到适合窗口');
675
- const zoom = combo(76, () => openMenu({
676
- anchor: zoom,
677
- items: [50, 75, 100, 125, 150, 200, 400].map((z) => ({ label: `${z}%`, checked: app.zoom === z, onClick: () => app.setZoom(z) })),
678
- }), '缩放');
679
- panel.appendChild(group('演示文稿视图', normal, sorter, reading));
680
- panel.appendChild(group('显示', column(grid, guides), column(notes, pane)));
681
- panel.appendChild(group('缩放', fit, zoom));
682
-
683
- this.reg(normal, () => normal.classList.toggle('gbp-is-active', app.view === 'normal'));
684
- this.reg(sorter, () => sorter.classList.toggle('gbp-is-active', app.view === 'sorter'));
685
- this.reg(reading, () => reading.classList.toggle('gbp-is-active', app.view === 'reading'));
686
- this.reg(grid, () => grid.classList.toggle('gbp-is-active', !!app.gridVisible));
687
- this.reg(guides, () => guides.classList.toggle('gbp-is-active', !!app.guidesVisible));
688
- this.reg(notes, () => notes.classList.toggle('gbp-is-active', !!app.notesVisible));
689
- this.reg(pane, () => pane.classList.toggle('gbp-is-active', !!app.formatPaneOpen));
690
- this.reg(zoom, () => { zoom.querySelector('.pp-rb-combo__label').textContent = `${app.zoom}%`; });
691
- }
692
-
693
- /* ===================== 上下文:形状 ===================== */
694
-
695
- buildContextShape(panel) {
696
- const app = this.app;
697
- const shapeBtn = big('shapes', '更改形状', (e) => openShapeGallery(e.currentTarget, (kind) => app.setSelectedProp('kind', kind)), '更改形状');
698
- const gallery = el('div', 'pp-style-gallery');
699
- const cards = new Map();
700
- const render = () => {
701
- gallery.replaceChildren();
702
- for (const s of shapeQuickStyles(app.snapshot.theme)) {
703
- const card = button('pp-style-card', `<span style="background:${s.fill || 'transparent'};border-color:${s.stroke || 'transparent'};color:${s.text}">Aa</span><small>${s.label}</small>`, s.label);
704
- card.addEventListener('click', () => app.applyShapeQuickStyle(s));
705
- cards.set(s.key, card);
706
- gallery.appendChild(card);
707
- }
708
- };
709
- render();
710
- panel.appendChild(group('插入形状', shapeBtn));
711
- panel.appendChild(group('形状样式', gallery));
712
-
713
- const fillBtn = colorButton('fill', '填充', '形状填充', () => app.firstSelected()?.props?.fill || '', (c) => app.setSelectedProp('fill', c));
714
- const outlineColor = colorButton('outline', '轮廓', '形状轮廓', () => app.firstSelected()?.props?.stroke || '', (c) => app.setSelectedProp('stroke', c));
715
- const outlineWidth = menuButton('outline', '粗细', () => [1, 2, 3, 4, 6].map((w) => ({
716
- label: `${w} px`, checked: Math.round(app.firstSelected()?.props?.strokeW) === w, onClick: () => app.setSelectedProp('strokeW', w),
717
- })), '轮廓粗细');
718
- const dash = menuButton('line', '虚线', () => [
719
- { label: '实线', checked: (app.firstSelected()?.props?.dash || 'solid') === 'solid', onClick: () => app.setSelectedProp('dash', 'solid') },
720
- { label: '虚线', checked: app.firstSelected()?.props?.dash === 'dash', onClick: () => app.setSelectedProp('dash', 'dash') },
721
- { label: '点线', checked: app.firstSelected()?.props?.dash === 'dot', onClick: () => app.setSelectedProp('dash', 'dot') },
722
- { label: '点划线', checked: app.firstSelected()?.props?.dash === 'dashDot', onClick: () => app.setSelectedProp('dash', 'dashDot') },
723
- ], '轮廓样式');
724
- const shadow = small('shadow', '阴影', () => app.setSelectedProp('shadow', !app.firstSelected()?.props?.shadow), '阴影');
725
- const noOutline = small('close', '无轮廓', () => app.setSelectedProp('strokeW', 0), '无轮廓');
726
- panel.appendChild(group('形状填充与轮廓', column(fillBtn, noOutline), column(outlineColor, outlineWidth), column(dash, shadow)));
727
-
728
- const rotateLeft = small('rotate', '左转 90°', () => app.rotateSelected(-90), '向左旋转 90°');
729
- const rotateRight = small('rotate', '右转 90°', () => app.rotateSelected(90), '向右旋转 90°');
730
- const arrange = menuButton('arrange', '排列', () => [
731
- { label: '置于顶层', onClick: () => app.arrange('front') },
732
- { label: '上移一层', onClick: () => app.arrange('forward') },
733
- { label: '下移一层', onClick: () => app.arrange('backward') },
734
- { label: '置于底层', onClick: () => app.arrange('back') },
735
- ], '排列');
736
- panel.appendChild(group('排列', column(rotateLeft, rotateRight), arrange));
737
-
738
- this.buildSizeGroup(panel);
739
-
740
- this.reg(gallery, () => {
741
- // 快速样式不强制高亮(组合样式难以反推),仅保持可点
742
- });
743
- this.reg(fillBtn, () => { fillBtn.colorBar.style.background = app.firstSelected()?.props?.fill || 'transparent'; });
744
- this.reg(outlineColor, () => { outlineColor.colorBar.style.background = app.firstSelected()?.props?.stroke || 'transparent'; });
745
- this.reg(shadow, () => { shadow.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.shadow); });
746
- this.reg(noOutline, () => { noOutline.disabled = !app.firstSelected(); });
747
- }
748
-
749
- /* ===================== 上下文:图片 ===================== */
750
-
751
- buildContextImage(panel) {
752
- const app = this.app;
753
- const replace = big('replaceImage', '替换图片', () => app.replaceSelectedImage(), '替换图片');
754
- const reset = big('resetImage', '重置图片', () => app.resetSelectedImage(), '重置裁剪与效果');
755
- const crop = small('crop', '裁剪', () => app.cropSelected(), '裁剪图片');
756
- panel.appendChild(group('调整', replace, reset, column(crop)));
757
-
758
- const shadow = small('shadow', '阴影', () => app.setSelectedProp('shadow', !app.firstSelected()?.props?.shadow), '阴影');
759
- const alt = small('textBox', '替代文字', () => app.editAltText(), '编辑替代文字(无障碍)');
760
- panel.appendChild(group('图片样式', column(shadow, alt)));
761
-
762
- const arrange = menuButton('arrange', '排列', () => [
763
- { label: '置于顶层', onClick: () => app.arrange('front') },
764
- { label: '上移一层', onClick: () => app.arrange('forward') },
765
- { label: '下移一层', onClick: () => app.arrange('backward') },
766
- { label: '置于底层', onClick: () => app.arrange('back') },
767
- ], '排列');
768
- panel.appendChild(group('排列', arrange));
769
- this.buildSizeGroup(panel);
770
- this.reg(shadow, () => { shadow.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.shadow); });
771
- }
772
-
773
- /* ===================== 上下文:表格 ===================== */
774
-
775
- buildContextTable(panel) {
776
- const app = this.app;
777
- const gallery = el('div', 'pp-table-style-gallery');
778
- const cards = new Map();
779
- for (const s of TABLE_STYLES) {
780
- const card = button('pp-table-style-card', `<span class="pp-table-style-card__preview pp-table-style-card__preview--${s.key}"><i></i><i></i><i></i><i></i></span><span>${s.label}</span>`, s.label);
781
- card.addEventListener('click', () => app.setTableStyle(s.key));
782
- cards.set(s.key, card);
783
- gallery.appendChild(card);
784
- }
785
- panel.appendChild(group('表格样式', gallery));
786
-
787
- const header = small('tableStyle', '标题行', () => app.toggleHeaderRow(), '标题行');
788
- const banded = small('tableStyle', '镶边行', () => app.toggleBandedRows(), '镶边行');
789
- panel.appendChild(group('样式选项', column(header, banded)));
790
-
791
- const rowAbove = small('rowAbove', '上方', () => app.insertTableRow('above'), '在上方插入行');
792
- const rowBelow = small('rowBelow', '下方', () => app.insertTableRow('below'), '在下方插入行');
793
- const colLeft = small('colLeft', '左侧', () => app.insertTableColumn('left'), '在左侧插入列');
794
- const colRight = small('colRight', '右侧', () => app.insertTableColumn('right'), '在右侧插入列');
795
- const delRow = small('delete', '删除行', () => app.deleteTableRow(), '删除行');
796
- const delCol = small('delete', '删除列', () => app.deleteTableColumn(), '删除列');
797
- panel.appendChild(group('行和列', column(rowAbove, rowBelow), column(colLeft, colRight), column(delRow, delCol)));
798
-
799
- const arrange = menuButton('arrange', '排列', () => [
800
- { label: '置于顶层', onClick: () => app.arrange('front') },
801
- { label: '置于底层', onClick: () => app.arrange('back') },
802
- ], '排列');
803
- panel.appendChild(group('排列', arrange));
804
- this.buildSizeGroup(panel);
805
-
806
- this.reg(gallery, () => {
807
- const o = app.firstSelected();
808
- for (const [key, card] of cards) card.classList.toggle('gbp-is-active', o?.props?.tableStyle === key);
809
- });
810
- this.reg(header, () => { header.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.headerRow); });
811
- this.reg(banded, () => { banded.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.bandedRows); });
812
- }
813
-
814
- /** 大小与位置组(单选对象) */
815
- buildSizeGroup(panel) {
816
- const app = this.app;
817
- const wInput = el('input', 'pp-rb-num');
818
- wInput.type = 'number';
819
- wInput.step = '1';
820
- wInput.min = '1';
821
- wInput.title = '宽度';
822
- const hInput = el('input', 'pp-rb-num');
823
- hInput.type = 'number';
824
- hInput.step = '1';
825
- hInput.min = '1';
826
- hInput.title = '高度';
827
- wInput.addEventListener('mousedown', (e) => e.stopPropagation());
828
- hInput.addEventListener('mousedown', (e) => e.stopPropagation());
829
- const apply = (key, input) => {
830
- const o = app.firstSelected();
831
- const v = Number(input.value);
832
- if (!o || !Number.isFinite(v) || v <= 0) return;
833
- app.updateObject(o.id, { [key]: key === 'w' || key === 'h' ? Math.round(v * (o[key] < 0 ? -1 : 1)) : Math.round(v) });
834
- };
835
- wInput.addEventListener('change', () => apply('w', wInput));
836
- hInput.addEventListener('change', () => apply('h', hInput));
837
- const wWrap = el('label', 'pp-rb-field');
838
- wWrap.append(el('span', '', '宽'), wInput);
839
- const hWrap = el('label', 'pp-rb-field');
840
- hWrap.append(el('span', '', '高'), hInput);
841
- panel.appendChild(group('大小', column(wWrap, hWrap)));
842
- this.reg(wInput, () => {
843
- if (document.activeElement === wInput) return;
844
- const o = app.firstSelected();
845
- wInput.value = o ? String(Math.round(Math.abs(o.w))) : '';
846
- wInput.disabled = !o;
847
- });
848
- this.reg(hInput, () => {
849
- if (document.activeElement === hInput) return;
850
- const o = app.firstSelected();
851
- hInput.value = o ? String(Math.round(Math.abs(o.h))) : '';
852
- hInput.disabled = !o;
853
- });
854
- }
855
- }
1
+ // [文件] gbpptx·Ribbon —— Office 式功能区(开始/插入/设计/切换/放映/审阅/视图 + 形状/图片/表格上下文标签)
2
+
3
+ import {
4
+ FONT_FAMILIES, FONT_SIZES, TEXT_COLORS,
5
+ } from './text-styles.js';
6
+ import {
7
+ SHAPE_KINDS, SLIDE_LAYOUTS, TABLE_STYLES, THEME_KEYS, TRANSITIONS, contrastText, shapePath, themeOf,
8
+ } from '../../../src/kernel/model.js';
9
+ import { icon } from './icons.js';
10
+ import { openMenu } from './menu.js';
11
+ import { openPopup } from './popup.js';
12
+ import { openColorPanel } from './color-panel.js';
13
+
14
+ const keepFocus = (el) => {
15
+ el.addEventListener('mousedown', (e) => {
16
+ if (e.button === 0) e.preventDefault();
17
+ });
18
+ };
19
+
20
+ const el = (tag, cls, html) => {
21
+ const node = document.createElement(tag);
22
+ if (cls) node.className = cls;
23
+ if (html != null) node.innerHTML = html;
24
+ return node;
25
+ };
26
+
27
+ const button = (cls, html, title) => {
28
+ const b = el('button', cls, html);
29
+ b.type = 'button';
30
+ if (title) b.title = title;
31
+ keepFocus(b);
32
+ return b;
33
+ };
34
+
35
+ const big = (name, label, onClick, title) => {
36
+ const b = button('pp-rb-big', `${icon(name, 26)}<span class="pp-rb-big__label">${label}</span>`, title || label);
37
+ b.addEventListener('click', onClick);
38
+ return b;
39
+ };
40
+
41
+ const splitBig = (name, label, onClick, onMenu, title) => {
42
+ const wrap = el('div', 'pp-rb-split');
43
+ const main = big(name, label, onClick, title);
44
+ const caret = button('pp-rb-split__caret', icon('chevronDown', 12), '更多');
45
+ caret.addEventListener('click', onMenu);
46
+ wrap.append(main, caret);
47
+ return wrap;
48
+ };
49
+
50
+ const small = (name, label, onClick, title, cls = '') => {
51
+ const b = button(`pp-rb-small${cls ? ` ${cls}` : ''}`, `${icon(name, 16)}${label ? `<span>${label}</span>` : ''}`, title || label || name);
52
+ b.addEventListener('click', onClick);
53
+ return b;
54
+ };
55
+
56
+ const menuButton = (name, label, items, title, cls = '') => {
57
+ const b = small(name, label, () => openMenu({ anchor: b, items: items() }), title || label, cls);
58
+ return b;
59
+ };
60
+
61
+ const column = (...children) => {
62
+ const c = el('div', 'pp-rb-col');
63
+ c.append(...children);
64
+ return c;
65
+ };
66
+
67
+ const group = (label, ...children) => {
68
+ const g = el('div', 'pp-rb-group');
69
+ const body = el('div', 'pp-rb-group__body');
70
+ body.append(...children);
71
+ const cap = el('div', 'pp-rb-group__label');
72
+ cap.textContent = label;
73
+ g.append(body, cap);
74
+ return g;
75
+ };
76
+
77
+ const combo = (width, onClick, title) => {
78
+ const b = button('pp-rb-combo', '<span class="pp-rb-combo__label"></span><span class="pp-rb-combo__caret">▾</span>', title);
79
+ b.style.width = `${width}px`;
80
+ b.addEventListener('click', onClick);
81
+ return b;
82
+ };
83
+
84
+ const colorButton = (name, label, title, getColor, onPick) => {
85
+ const b = button('pp-rb-small pp-rb-colorbtn', `${icon(name, 16)}${label ? `<span>${label}</span>` : ''}<i class="pp-rb-colorbar"></i>`, title);
86
+ b.addEventListener('click', (e) => {
87
+ openColorPanel({
88
+ anchor: e.currentTarget,
89
+ colors: TEXT_COLORS,
90
+ value: getColor() || '',
91
+ columns: 10,
92
+ title,
93
+ onPick,
94
+ });
95
+ });
96
+ b.colorBar = b.querySelector('.pp-rb-colorbar');
97
+ return b;
98
+ };
99
+
100
+ const blend = (a, b, t) => {
101
+ const parse = (hex) => {
102
+ const n = Number.parseInt(String(hex).replace('#', ''), 16);
103
+ return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
104
+ };
105
+ const x = parse(a);
106
+ const y = parse(b);
107
+ const k = Math.max(0, Math.min(1, t));
108
+ return `#${[x.r + (y.r - x.r) * k, x.g + (y.g - x.g) * k, x.b + (y.b - x.b) * k]
109
+ .map((v) => Math.round(v).toString(16).padStart(2, '0')).join('')}`;
110
+ };
111
+
112
+ const readableText = (background, fallback) => {
113
+ const n = Number.parseInt(String(background).replace('#', ''), 16);
114
+ const lum = Number.isFinite(n) ? (0.2126 * ((n >> 16) & 255) + 0.7152 * ((n >> 8) & 255) + 0.0722 * (n & 255)) / 255 : 1;
115
+ return lum > 0.55 ? '#201f1e' : fallback;
116
+ };
117
+
118
+ /** 形状快速样式(按当前主题推导) */
119
+ export function shapeQuickStyles(themeKey) {
120
+ const t = themeOf(themeKey);
121
+ return [
122
+ { key: 'accent', label: '彩色填充', fill: t.accent, stroke: '', text: contrastText(t.accent) },
123
+ { key: 'light', label: '浅色填充', fill: blend(t.accent, t.bg, 0.8), stroke: t.accent, text: readableText(blend(t.accent, t.bg, 0.8), t.text) },
124
+ { key: 'outline', label: '轮廓', fill: '', stroke: t.accent, text: t.text },
125
+ { key: 'deep', label: '深色填充', fill: blend(t.accent, '#000000', 0.55), stroke: '', text: '#ffffff' },
126
+ { key: 'paper', label: '浅色轮廓', fill: t.bg, stroke: blend(t.text, t.bg, 0.5), text: t.text },
127
+ { key: 'dark', label: '深色强调', fill: t.text, stroke: '', text: contrastText(t.text) },
128
+ ];
129
+ }
130
+
131
+ function openShapeGallery(anchor, onPick) {
132
+ const box = el('div', 'pp-shape-gallery');
133
+ const handle = { close: () => {} };
134
+ for (const s of SHAPE_KINDS) {
135
+ const item = button('pp-shape-gallery__item', `<svg viewBox="0 0 40 30" width="40" height="30" aria-hidden="true"><path d="${shapePath(s.kind, 34, 24)}" transform="translate(3,3)" fill="currentColor"/></svg><span>${s.label}</span>`, s.label);
136
+ item.addEventListener('click', () => { handle.close(); onPick(s.kind); });
137
+ box.appendChild(item);
138
+ }
139
+ Object.assign(handle, openPopup({ anchor, content: box, placement: 'bottom-start', className: 'pp-popup--gallery' }));
140
+ return handle;
141
+ }
142
+
143
+ /** Office 式表格尺寸选择器 */
144
+ function openTableGrid(anchor, onPick) {
145
+ const box = el('div', 'pp-table-grid');
146
+ const title = el('div', 'pp-table-grid__title', '插入表格');
147
+ const hint = el('div', 'pp-table-grid__hint', '1×1 表格');
148
+ const grid = el('div', 'pp-table-grid__grid');
149
+ const cells = [];
150
+ for (let r = 1; r <= 8; r += 1) {
151
+ for (let c = 1; c <= 10; c += 1) {
152
+ const cell = button('pp-table-grid__cell', '', `${r}×${c}`);
153
+ cell.dataset.r = String(r);
154
+ cell.dataset.c = String(c);
155
+ cell.addEventListener('mouseenter', () => {
156
+ hint.textContent = `${r}×${c} 表格`;
157
+ for (const x of cells) {
158
+ x.classList.toggle('gbp-is-on', Number(x.dataset.r) <= r && Number(x.dataset.c) <= c);
159
+ }
160
+ });
161
+ cell.addEventListener('click', () => { handle.close(); onPick(r, c); });
162
+ cells.push(cell);
163
+ grid.appendChild(cell);
164
+ }
165
+ }
166
+ grid.addEventListener('mouseleave', () => {
167
+ for (const x of cells) x.classList.remove('gbp-is-on');
168
+ hint.textContent = '1×1 表格';
169
+ });
170
+ box.append(title, grid, hint);
171
+ const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'pp-popup--table-grid' });
172
+ return handle;
173
+ }
174
+
175
+ export class Ribbon {
176
+ constructor(app) {
177
+ this.app = app;
178
+ this.el = el('div', 'pp-ribbon');
179
+ this.updates = [];
180
+ this.contextKey = '';
181
+ this.contextTabs = [];
182
+ this.panels = new Map();
183
+ this.activeTab = 'home';
184
+
185
+ this.tabsEl = el('div', 'pp-ribbon__tabs');
186
+ this.bodyEl = el('div', 'pp-ribbon__body');
187
+ this.el.append(this.tabsEl, this.bodyEl);
188
+ this.buildTabs();
189
+ this.buildPanels();
190
+ this.activate(app.prefs.ribbonTab && this.isKnownTab(app.prefs.ribbonTab) ? app.prefs.ribbonTab : 'home', { expand: false });
191
+ this.setCollapsed(!!app.ribbonCollapsed);
192
+ this.refresh();
193
+ }
194
+
195
+ /* ===================== 骨架 ===================== */
196
+
197
+ isKnownTab(key) {
198
+ return ['home', 'insert', 'design', 'transitions', 'slideshow', 'review', 'view'].includes(key);
199
+ }
200
+
201
+ buildTabs() {
202
+ const defs = [
203
+ ['home', '开始'], ['insert', '插入'], ['design', '设计'], ['transitions', '切换'],
204
+ ['slideshow', '幻灯片放映'], ['review', '审阅'], ['view', '视图'],
205
+ ];
206
+ for (const [key, label] of defs) {
207
+ const tab = button('pp-rb-tab', label, label);
208
+ tab.dataset.tab = key;
209
+ tab.addEventListener('click', () => this.activate(key));
210
+ this.tabsEl.appendChild(tab);
211
+ }
212
+ this.contextHost = el('div', 'pp-rb-tabs__context');
213
+ this.tabsEl.appendChild(this.contextHost);
214
+ const spacer = el('div', 'pp-rb-tabs__spacer');
215
+ this.tabsEl.appendChild(spacer);
216
+ this.collapseBtn = button('pp-rb-collapse', icon('chevronDown', 14), '收起功能区');
217
+ this.collapseBtn.addEventListener('click', () => {
218
+ this.app.setRibbonCollapsed(!this.app.ribbonCollapsed);
219
+ });
220
+ this.tabsEl.appendChild(this.collapseBtn);
221
+ }
222
+
223
+ buildPanels() {
224
+ const builders = {
225
+ home: (p) => this.buildHome(p),
226
+ insert: (p) => this.buildInsert(p),
227
+ design: (p) => this.buildDesign(p),
228
+ transitions: (p) => this.buildTransitions(p),
229
+ slideshow: (p) => this.buildSlideshow(p),
230
+ review: (p) => this.buildReview(p),
231
+ view: (p) => this.buildView(p),
232
+ };
233
+ for (const [key, build] of Object.entries(builders)) {
234
+ const panel = el('div', 'pp-rb-panel');
235
+ panel.dataset.tab = key;
236
+ panel.hidden = true;
237
+ build(panel);
238
+ this.panels.set(key, panel);
239
+ this.bodyEl.appendChild(panel);
240
+ }
241
+ }
242
+
243
+ panel(key) {
244
+ if (!this.panels.has(key)) {
245
+ const panel = el('div', 'pp-rb-panel');
246
+ panel.dataset.tab = key;
247
+ panel.hidden = true;
248
+ if (key === 'ctx-shape') this.buildContextShape(panel);
249
+ if (key === 'ctx-image') this.buildContextImage(panel);
250
+ if (key === 'ctx-table') this.buildContextTable(panel);
251
+ this.panels.set(key, panel);
252
+ this.bodyEl.appendChild(panel);
253
+ }
254
+ return this.panels.get(key);
255
+ }
256
+
257
+ activate(key, { expand = true } = {}) {
258
+ if (!this.isKnownTab(key) && !['ctx-shape', 'ctx-image', 'ctx-table'].includes(key)) key = 'home';
259
+ this.activeTab = key;
260
+ this.app.prefs.ribbonTab = key;
261
+ for (const tab of this.tabsEl.querySelectorAll('.pp-rb-tab')) {
262
+ tab.classList.toggle('gbp-is-active', tab.dataset.tab === key);
263
+ }
264
+ for (const [k, panel] of this.panels) panel.hidden = k !== key;
265
+ this.panel(key);
266
+ for (const [k, panel] of this.panels) panel.hidden = k !== key;
267
+ if (expand && this.app.ribbonCollapsed) this.app.setRibbonCollapsed(false);
268
+ this.refresh();
269
+ }
270
+
271
+ setCollapsed(on) {
272
+ this.el.classList.toggle('gbp-is-collapsed', !!on);
273
+ this.collapseBtn.innerHTML = icon(on ? 'chevronUp' : 'chevronDown', 14);
274
+ this.collapseBtn.title = on ? '展开功能区' : '收起功能区';
275
+ }
276
+
277
+ reg(target, update) {
278
+ this.updates.push({ target, update });
279
+ update();
280
+ return target;
281
+ }
282
+
283
+ refresh() {
284
+ this.ensureContext();
285
+ for (const entry of this.updates) {
286
+ if (!entry.target.isConnected) continue;
287
+ entry.update();
288
+ }
289
+ }
290
+
291
+ /* ===================== 上下文标签 ===================== */
292
+
293
+ selectionKind() {
294
+ const app = this.app;
295
+ if (app.selectedIds.length !== 1) return '';
296
+ const o = app.firstSelected();
297
+ if (!o) return '';
298
+ if (o.type === 'shape' || o.type === 'line') return 'shape';
299
+ if (o.type === 'image') return 'image';
300
+ if (o.type === 'table') return 'table';
301
+ return '';
302
+ }
303
+
304
+ ensureContext() {
305
+ const kind = this.selectionKind();
306
+ if (kind === this.contextKey) return;
307
+ this.contextHost.replaceChildren();
308
+ for (const t of this.contextTabs) {
309
+ this.panels.get(t.key)?.remove();
310
+ this.panels.delete(t.key);
311
+ this.updates = this.updates.filter((u) => u.target.isConnected);
312
+ }
313
+ this.contextTabs = [];
314
+ this.contextKey = kind;
315
+ if (!kind) {
316
+ if (this.activeTab.startsWith('ctx-')) this.activate('home', { expand: false });
317
+ return;
318
+ }
319
+ const defs = {
320
+ shape: { key: 'ctx-shape', label: '形状格式' },
321
+ image: { key: 'ctx-image', label: '图片格式' },
322
+ table: { key: 'ctx-table', label: '表格' },
323
+ };
324
+ const def = defs[kind];
325
+ const tab = button('pp-rb-tab pp-rb-tab--context', def.label, def.label);
326
+ tab.dataset.tab = def.key;
327
+ tab.addEventListener('click', () => this.activate(def.key));
328
+ this.contextHost.appendChild(tab);
329
+ this.contextTabs.push(def);
330
+ this.panel(def.key);
331
+ if (this.activeTab.startsWith('ctx-')) this.activate(def.key, { expand: false });
332
+ }
333
+
334
+ /* ===================== 开始 ===================== */
335
+
336
+ buildHome(panel) {
337
+ const app = this.app;
338
+ const hasSel = () => app.selectedIds.length > 0;
339
+ const canText = () => app.canFormatText();
340
+ const canRich = () => app.canRichText();
341
+ const canAlign = () => app.canAlignText();
342
+ const canList = () => app.canList();
343
+ const state = () => app.textState();
344
+
345
+ /* 剪贴板 */
346
+ const pasteWrap = el('div', 'pp-rb-split');
347
+ const pasteMain = big('paste', '粘贴', () => app.paste(), '粘贴 (Ctrl+V)');
348
+ const pasteCaret = button('pp-rb-split__caret', icon('chevronDown', 12), '粘贴选项');
349
+ pasteCaret.addEventListener('click', () => openMenu({
350
+ anchor: pasteCaret,
351
+ items: [
352
+ { label: '粘贴', icon: 'paste', onClick: () => app.paste() },
353
+ { label: '粘贴为纯文本', icon: 'text', onClick: () => app.pastePlain() },
354
+ ],
355
+ }));
356
+ pasteWrap.append(pasteMain, pasteCaret);
357
+ const cutBtn = small('cut', '剪切', () => app.cutSelected(), '剪切 (Ctrl+X)');
358
+ const copyBtn = small('copy', '复制', () => app.copySelected(), '复制 (Ctrl+C)');
359
+ const clip = group('剪贴板', pasteWrap, column(cutBtn, copyBtn));
360
+ panel.appendChild(clip);
361
+
362
+ /* 幻灯片 */
363
+ const newSlide = splitBig('newSlide', '新建幻灯片', () => app.addSlide(), (e) => this.layoutMenu(e.currentTarget), '新建幻灯片 (Ctrl+M)');
364
+ const hideBtn = small('hide', '隐藏', () => app.toggleSlideHidden(), '隐藏幻灯片');
365
+ const resetBtn = small('reset', '重设', () => app.resetSelected(), '重设位置与大小');
366
+ panel.appendChild(group('幻灯片', newSlide, column(hideBtn, resetBtn)));
367
+
368
+ /* 字体 */
369
+ const fontBtn = combo(132, () => openMenu({
370
+ anchor: fontBtn,
371
+ items: FONT_FAMILIES.map((f) => ({ label: f.label, checked: state().font === f.value, onClick: () => app.applyFontFamily(f.value) })),
372
+ }), '字体');
373
+ const sizeBtn = combo(64, () => openMenu({
374
+ anchor: sizeBtn,
375
+ items: FONT_SIZES.map((s) => ({ label: String(s), checked: Math.round(state().fontSize) === s, onClick: () => app.applyFontSize(s) })),
376
+ }), '字号');
377
+ const boldBtn = small('bold', '', () => app.toggleTextStyle('bold'), '加粗 (Ctrl+B)');
378
+ const italicBtn = small('italic', '', () => app.toggleTextStyle('italic'), '斜体 (Ctrl+I)');
379
+ const underlineBtn = small('underline', '', () => app.toggleTextStyle('underline'), '下划线 (Ctrl+U)');
380
+ const strikeBtn = small('strike', '', () => app.toggleTextStyle('strike'), '删除线');
381
+ const incBtn = small('increaseFont', '', () => app.stepFontSize(1), '增大字号');
382
+ const decBtn = small('decreaseFont', '', () => app.stepFontSize(-1), '减小字号');
383
+ const clearBtn = small('clearFormat', '清除格式', () => app.clearFormatting(), '清除所有格式');
384
+ const fontColor = colorButton('fontColor', '', '字体颜色', () => state().color || themeOf(app.snapshot.theme).text, (c) => app.applyTextColor(c));
385
+ panel.appendChild(group('字体',
386
+ fontBtn, sizeBtn, column(incBtn, decBtn),
387
+ column(boldBtn, italicBtn),
388
+ column(underlineBtn, strikeBtn),
389
+ column(clearBtn, fontColor),
390
+ ));
391
+
392
+ /* 段落 */
393
+ const bulletBtn = small('bullets', '', () => app.applyList('bullet'), '项目符号');
394
+ const numberBtn = small('numbering', '', () => app.applyList('number'), '编号');
395
+ const outdentBtn = small('indentDecrease', '', () => app.applyIndent(-1), '减少缩进');
396
+ const indentBtn = small('indentIncrease', '', () => app.applyIndent(1), '增加缩进');
397
+ const lineBtn = combo(74, () => openMenu({
398
+ anchor: lineBtn,
399
+ items: [1, 1.15, 1.5, 2, 2.5, 3].map((v) => ({
400
+ label: v === 1 ? '1.0' : String(v),
401
+ checked: Math.abs(state().lineSpacing - v) < 0.01,
402
+ onClick: () => app.applyLineSpacing(v),
403
+ })),
404
+ }), '行距');
405
+ const alignLeft = small('alignLeft', '', () => app.applyAlign('left'), '左对齐 (Ctrl+L)');
406
+ const alignCenter = small('alignCenter', '', () => app.applyAlign('center'), '居中 (Ctrl+E)');
407
+ const alignRight = small('alignRight', '', () => app.applyAlign('right'), '右对齐 (Ctrl+R)');
408
+ const alignJustify = small('alignJustify', '', () => app.applyAlign('justify'), '两端对齐 (Ctrl+J)');
409
+ panel.appendChild(group('段落',
410
+ column(bulletBtn, numberBtn),
411
+ column(outdentBtn, indentBtn),
412
+ lineBtn,
413
+ column(alignLeft, alignCenter),
414
+ column(alignRight, alignJustify),
415
+ ));
416
+
417
+ /* 形状与排列 */
418
+ const shapeBtn = big('shapes', '形状', (e) => openShapeGallery(e.currentTarget, (kind) => app.insert('shape', kind)), '插入形状');
419
+ const fillBtn = colorButton('fill', '填充', '形状填充', () => (app.firstSelected()?.props?.fill || ''), (c) => app.setSelectedProp('fill', c));
420
+ const outlineBtn = colorButton('outline', '轮廓', '形状轮廓', () => (app.firstSelected()?.props?.stroke || ''), (c) => app.setSelectedProp('stroke', c));
421
+ const effectsBtn = menuButton('effects', '效果', () => [
422
+ { label: '无阴影', checked: !app.firstSelected()?.props?.shadow, icon: 'effects', onClick: () => app.setSelectedProp('shadow', false) },
423
+ { label: '阴影', checked: !!app.firstSelected()?.props?.shadow, icon: 'shadow', onClick: () => app.setSelectedProp('shadow', true) },
424
+ ], '形状效果');
425
+ const arrangeItems = () => [
426
+ { label: '置于顶层', icon: 'bringForward', onClick: () => app.arrange('front') },
427
+ { label: '上移一层', onClick: () => app.arrange('forward') },
428
+ { label: '下移一层', onClick: () => app.arrange('backward') },
429
+ { label: '置于底层', icon: 'sendBackward', onClick: () => app.arrange('back') },
430
+ { divided: true },
431
+ {
432
+ label: '对齐',
433
+ icon: 'alignLeft',
434
+ children: [
435
+ { label: '左对齐', onClick: () => app.alignToSlide('left') },
436
+ { label: '水平居中', onClick: () => app.alignToSlide('centerH') },
437
+ { label: '右对齐', onClick: () => app.alignToSlide('right') },
438
+ { divided: true },
439
+ { label: '顶端对齐', onClick: () => app.alignToSlide('top') },
440
+ { label: '垂直居中', onClick: () => app.alignToSlide('middle') },
441
+ { label: '底端对齐', onClick: () => app.alignToSlide('bottom') },
442
+ ],
443
+ },
444
+ {
445
+ label: '分布',
446
+ children: [
447
+ { label: '横向分布', onClick: () => app.distribute('h') },
448
+ { label: '纵向分布', onClick: () => app.distribute('v') },
449
+ ],
450
+ },
451
+ ];
452
+ const arrangeBtn = menuButton('arrange', '排列', arrangeItems, '排列');
453
+ const selectBtn = menuButton('selectAll', '选择', () => [
454
+ { label: '全选', shortcut: 'Ctrl+A', onClick: () => app.selectAll() },
455
+ { label: '取消选择', shortcut: 'Esc', onClick: () => app.clearSelection() },
456
+ ], '选择');
457
+ panel.appendChild(group('形状', shapeBtn, column(fillBtn, outlineBtn), column(effectsBtn, arrangeBtn), selectBtn));
458
+
459
+ /* 编辑 */
460
+ const findBtn = big('find', '查找', () => app.openFind(false), '查找 (Ctrl+F)');
461
+ const replaceBtn = small('replace', '替换', () => app.openFind(true), '替换 (Ctrl+H)');
462
+ const selectAllBtn = small('selectAll', '全选', () => app.selectAll(), '全选 (Ctrl+A)');
463
+ panel.appendChild(group('编辑', findBtn, column(replaceBtn, selectAllBtn)));
464
+
465
+ /* 状态刷新 */
466
+ this.reg(boldBtn, () => { boldBtn.classList.toggle('gbp-is-active', !!state().bold); boldBtn.disabled = !canRich(); });
467
+ this.reg(italicBtn, () => { italicBtn.classList.toggle('gbp-is-active', !!state().italic); italicBtn.disabled = !canRich(); });
468
+ this.reg(underlineBtn, () => { underlineBtn.classList.toggle('gbp-is-active', !!state().underline); underlineBtn.disabled = !canRich(); });
469
+ this.reg(strikeBtn, () => { strikeBtn.classList.toggle('gbp-is-active', !!state().strike); strikeBtn.disabled = !canRich(); });
470
+ this.reg(alignLeft, () => { alignLeft.classList.toggle('gbp-is-active', state().align === 'left'); alignLeft.disabled = !canAlign(); });
471
+ this.reg(alignCenter, () => { alignCenter.classList.toggle('gbp-is-active', state().align === 'center'); alignCenter.disabled = !canAlign(); });
472
+ this.reg(alignRight, () => { alignRight.classList.toggle('gbp-is-active', state().align === 'right'); alignRight.disabled = !canAlign(); });
473
+ this.reg(alignJustify, () => { alignJustify.classList.toggle('gbp-is-active', state().align === 'justify'); alignJustify.disabled = !canAlign(); });
474
+ this.reg(bulletBtn, () => { bulletBtn.classList.toggle('gbp-is-active', state().list === 'bullet'); bulletBtn.disabled = !canList(); });
475
+ this.reg(numberBtn, () => { numberBtn.classList.toggle('gbp-is-active', state().list === 'number'); numberBtn.disabled = !canList(); });
476
+ const inList = () => app.editing?.kind === 'text' && Boolean(state().list);
477
+ this.reg(outdentBtn, () => { outdentBtn.disabled = !inList(); });
478
+ this.reg(indentBtn, () => { indentBtn.disabled = !inList(); });
479
+ this.reg(fontBtn, () => {
480
+ fontBtn.disabled = !canText();
481
+ const f = FONT_FAMILIES.find((x) => x.value === state().font);
482
+ fontBtn.querySelector('.pp-rb-combo__label').textContent = f ? f.label : (state().font ? String(state().font).split(',')[0].replace(/["']/g, '') : '默认');
483
+ });
484
+ this.reg(sizeBtn, () => {
485
+ sizeBtn.disabled = !canText();
486
+ sizeBtn.querySelector('.pp-rb-combo__label').textContent = state().fontSize ? String(Math.round(state().fontSize)) : '字号';
487
+ });
488
+ this.reg(incBtn, () => { incBtn.disabled = !canText(); });
489
+ this.reg(decBtn, () => { decBtn.disabled = !canText(); });
490
+ this.reg(clearBtn, () => {
491
+ clearBtn.disabled = !app.editing && !app.selectedObjects().some((o) => ['text', 'shape', 'table'].includes(o.type));
492
+ });
493
+ this.reg(cutBtn, () => { cutBtn.disabled = !hasSel() && !app.editing; });
494
+ this.reg(copyBtn, () => { copyBtn.disabled = !hasSel() && !app.editing; });
495
+ this.reg(fontColor, () => {
496
+ fontColor.disabled = !canText();
497
+ fontColor.colorBar.style.background = state().color || themeOf(app.snapshot.theme).text;
498
+ });
499
+ this.reg(lineBtn, () => {
500
+ lineBtn.disabled = !canRich();
501
+ const v = state().lineSpacing || 1;
502
+ lineBtn.querySelector('.pp-rb-combo__label').textContent = Math.abs(v - 1) < 0.01 ? '1.0' : String(v);
503
+ });
504
+ this.reg(fillBtn, () => {
505
+ const o = app.firstSelected();
506
+ fillBtn.disabled = !o || o.type === 'line';
507
+ fillBtn.colorBar.style.background = o?.props?.fill || 'transparent';
508
+ fillBtn.classList.toggle('gbp-is-off', !o?.props?.fill);
509
+ });
510
+ this.reg(outlineBtn, () => {
511
+ const o = app.firstSelected();
512
+ outlineBtn.disabled = !o;
513
+ outlineBtn.colorBar.style.background = o?.props?.stroke || 'transparent';
514
+ outlineBtn.classList.toggle('gbp-is-off', !o?.props?.stroke || !o?.props?.strokeW);
515
+ });
516
+ this.reg(effectsBtn, () => {
517
+ const o = app.firstSelected();
518
+ effectsBtn.disabled = !o || o.type === 'line';
519
+ effectsBtn.classList.toggle('gbp-is-active', !!o?.props?.shadow);
520
+ });
521
+ this.reg(arrangeBtn, () => { arrangeBtn.disabled = !hasSel(); });
522
+ this.reg(selectBtn, () => { selectBtn.disabled = !app.snapshot.slides.length; });
523
+ this.reg(pasteMain, () => { pasteMain.disabled = !app.canPaste(); });
524
+ this.reg(hideBtn, () => { hideBtn.disabled = false; hideBtn.classList.toggle('gbp-is-active', !!app.currentSlide()?.hidden); });
525
+ this.reg(resetBtn, () => { resetBtn.disabled = !hasSel(); });
526
+ }
527
+
528
+ layoutMenu(anchor) {
529
+ openMenu({
530
+ anchor,
531
+ items: SLIDE_LAYOUTS.map((l) => ({ label: l.label, onClick: () => this.app.addSlide(l.key) })),
532
+ });
533
+ }
534
+
535
+ /* ===================== 插入 ===================== */
536
+
537
+ buildInsert(panel) {
538
+ const app = this.app;
539
+ const newSlide = splitBig('newSlide', '新建幻灯片', () => app.addSlide(), (e) => this.layoutMenu(e.currentTarget));
540
+ panel.appendChild(group('幻灯片', newSlide));
541
+
542
+ const tableBtn = big('table', '表格', (e) => openTableGrid(e.currentTarget, (r, c) => app.insertTable(r, c)), '插入表格');
543
+ panel.appendChild(group('表格', tableBtn));
544
+
545
+ const pic = big('image', '图片', () => app.insert('image'), '插入图片');
546
+ const shape = big('shapes', '形状', (e) => openShapeGallery(e.currentTarget, (kind) => app.insert('shape', kind)), '插入形状');
547
+ const text = big('textBox', '文本框', () => app.insert('text'), '插入文本框');
548
+ const line = small('line', '线条', () => app.insert('line'), '插入线条');
549
+ const arrow = small('arrow', '箭头', () => app.insert('arrow'), '插入箭头');
550
+ panel.appendChild(group('插图', pic, shape, text, column(line, arrow)));
551
+
552
+ const notes = small('notes', '备注', () => app.toggleNotes(), '显示/隐藏备注');
553
+ panel.appendChild(group('显示', notes));
554
+ }
555
+
556
+ /* ===================== 设计 ===================== */
557
+
558
+ buildDesign(panel) {
559
+ const app = this.app;
560
+ const gallery = el('div', 'pp-theme-gallery');
561
+ const cards = new Map();
562
+ for (const key of THEME_KEYS) {
563
+ const t = themeOf(key);
564
+ const card = button('pp-theme-card', '', t.label);
565
+ card.style.setProperty('--gbp-t-bg', t.bg);
566
+ card.style.setProperty('--gbp-t-text', t.text);
567
+ card.style.setProperty('--gbp-t-accent', t.accent);
568
+ card.innerHTML = `<span class="pp-theme-card__preview"><i class="pp-theme-card__title"></i><i class="pp-theme-card__line"></i><i class="pp-theme-card__block"></i></span><span class="pp-theme-card__label">${t.label}</span>`;
569
+ card.addEventListener('click', () => app.setTheme(key));
570
+ cards.set(key, card);
571
+ gallery.appendChild(card);
572
+ }
573
+ panel.appendChild(group('主题', gallery));
574
+
575
+ const bgBtn = big('background', '设置背景格式', () => app.openFormatPane(), '设置背景格式');
576
+ const bgColor = colorButton('fill', '背景色', '页面背景色', () => app.currentSlide()?.bg || themeOf(app.snapshot.theme).bg, (c) => app.setSlideBg(c));
577
+ const bgReset = small('reset', '重置背景', () => app.setSlideBg(''), '跟随主题背景');
578
+ panel.appendChild(group('背景', bgBtn, column(bgColor, bgReset)));
579
+
580
+ const wide = small('size', '宽屏', () => app.setSlideSize('wide'), '16:9');
581
+ const standard = small('size', '标准', () => app.setSlideSize('standard'), '4:3');
582
+ panel.appendChild(group('幻灯片大小', column(wide, standard)));
583
+
584
+ this.reg(gallery, () => {
585
+ for (const [key, card] of cards) card.classList.toggle('gbp-is-active', app.snapshot.theme === key);
586
+ });
587
+ this.reg(bgColor, () => {
588
+ const bg = app.currentSlide()?.bg;
589
+ bgColor.colorBar.style.background = bg || themeOf(app.snapshot.theme).bg;
590
+ bgColor.classList.toggle('gbp-is-off', !bg);
591
+ });
592
+ }
593
+
594
+ /* ===================== 切换 ===================== */
595
+
596
+ buildTransitions(panel) {
597
+ const app = this.app;
598
+ const gallery = el('div', 'pp-transition-gallery');
599
+ const cards = new Map();
600
+ const iconOf = { none: 'close', fade: 'effects', push: 'arrow', wipe: 'outline', cover: 'bringForward', split: 'viewSorter', zoom: 'zoomIn' };
601
+ for (const tr of TRANSITIONS) {
602
+ const card = button('pp-transition-card', `<span class="pp-transition-card__ico">${icon(iconOf[tr.key] || 'transition', 20)}</span><span>${tr.label}</span>`, tr.label);
603
+ card.addEventListener('click', () => {
604
+ app.setTransition({ type: tr.key, dir: tr.dir || 'l' });
605
+ app.previewTransition();
606
+ });
607
+ cards.set(tr.key, card);
608
+ gallery.appendChild(card);
609
+ }
610
+ panel.appendChild(group('切换到此幻灯片', gallery));
611
+
612
+ const duration = combo(82, () => openMenu({
613
+ anchor: duration,
614
+ items: [
615
+ { label: '0.5 秒', checked: app.currentSlide().transition?.speed === 'fast', onClick: () => app.setTransition({ speed: 'fast' }) },
616
+ { label: '1 秒', checked: !app.currentSlide().transition?.speed || app.currentSlide().transition?.speed === 'med', onClick: () => app.setTransition({ speed: 'med' }) },
617
+ { label: '2 秒', checked: app.currentSlide().transition?.speed === 'slow', onClick: () => app.setTransition({ speed: 'slow' }) },
618
+ ],
619
+ }), '持续时间');
620
+ const applyAll = small('selectAll', '应用到全部', () => app.applyTransitionAll(), '应用到全部幻灯片');
621
+ const preview = big('play', '预览', () => app.previewTransition(), '预览切换');
622
+ panel.appendChild(group('计时', duration, column(applyAll)));
623
+ panel.appendChild(group('预览', preview));
624
+
625
+ this.reg(gallery, () => {
626
+ const type = app.currentSlide()?.transition?.type || 'none';
627
+ for (const [key, card] of cards) card.classList.toggle('gbp-is-active', key === type);
628
+ });
629
+ this.reg(duration, () => {
630
+ const speed = app.currentSlide()?.transition?.speed || 'med';
631
+ duration.querySelector('.pp-rb-combo__label').textContent = speed === 'fast' ? '0.5 秒' : speed === 'slow' ? '2 秒' : '1 秒';
632
+ });
633
+ }
634
+
635
+ /* ===================== 幻灯片放映 ===================== */
636
+
637
+ buildSlideshow(panel) {
638
+ const app = this.app;
639
+ const fromStart = big('play', '从头开始', () => app.presentFromStart(), '从头开始放映 (F5)');
640
+ const fromCurrent = big('present', '从当前页', () => app.presentFromCurrent(), '从当前幻灯片开始 (Shift+F5)');
641
+ const presenter = small('presenter', '演讲者视图', () => app.togglePresenter(), '使用演讲者视图');
642
+ const loop = small('loop', '循环放映', () => app.toggleLoop(), '按 Esc 前循环放映');
643
+ const hide = small('hide', '隐藏幻灯片', () => app.toggleSlideHidden(), '隐藏当前幻灯片');
644
+ panel.appendChild(group('开始放映幻灯片', fromStart, fromCurrent, column(presenter, hide)));
645
+ panel.appendChild(group('设置', column(loop)));
646
+
647
+ this.reg(presenter, () => presenter.classList.toggle('gbp-is-active', !!app.presentOptions.presenter));
648
+ this.reg(loop, () => loop.classList.toggle('gbp-is-active', !!app.presentOptions.loop));
649
+ this.reg(hide, () => hide.classList.toggle('gbp-is-active', !!app.currentSlide()?.hidden));
650
+ }
651
+
652
+ /* ===================== 审阅 ===================== */
653
+
654
+ buildReview(panel) {
655
+ const app = this.app;
656
+ const notes = big('notes', '显示备注', () => app.toggleNotes(), '显示/隐藏备注窗格');
657
+ const count = big('wordCount', '字数统计', () => app.showWordCount(), '统计幻灯片与文字数量');
658
+ panel.appendChild(group('备注', notes));
659
+ panel.appendChild(group('校对', count));
660
+ this.reg(notes, () => notes.classList.toggle('gbp-is-active', !!app.notesVisible));
661
+ }
662
+
663
+ /* ===================== 视图 ===================== */
664
+
665
+ buildView(panel) {
666
+ const app = this.app;
667
+ const normal = big('viewNormal', '普通', () => app.setView('normal'), '普通视图');
668
+ const sorter = big('viewSorter', '幻灯片浏览', () => app.setView('sorter'), '幻灯片浏览视图');
669
+ const reading = big('viewReading', '阅读视图', () => app.setView('reading'), '阅读视图');
670
+ const grid = small('grid', '网格线', () => app.toggleGrid(), '显示网格线');
671
+ const guides = small('guides', '参考线', () => app.toggleGuides(), '显示参考线');
672
+ const notes = small('notes', '备注', () => app.toggleNotes(), '显示备注');
673
+ const pane = small('formatPane', '格式窗格', () => app.toggleFormatPane(), '设置形状格式窗格');
674
+ const fit = big('fitWindow', '适应窗口', () => app.fitToWindow(), '缩放到适合窗口');
675
+ const zoom = combo(76, () => openMenu({
676
+ anchor: zoom,
677
+ items: [50, 75, 100, 125, 150, 200, 400].map((z) => ({ label: `${z}%`, checked: app.zoom === z, onClick: () => app.setZoom(z) })),
678
+ }), '缩放');
679
+ panel.appendChild(group('演示文稿视图', normal, sorter, reading));
680
+ panel.appendChild(group('显示', column(grid, guides), column(notes, pane)));
681
+ panel.appendChild(group('缩放', fit, zoom));
682
+
683
+ this.reg(normal, () => normal.classList.toggle('gbp-is-active', app.view === 'normal'));
684
+ this.reg(sorter, () => sorter.classList.toggle('gbp-is-active', app.view === 'sorter'));
685
+ this.reg(reading, () => reading.classList.toggle('gbp-is-active', app.view === 'reading'));
686
+ this.reg(grid, () => grid.classList.toggle('gbp-is-active', !!app.gridVisible));
687
+ this.reg(guides, () => guides.classList.toggle('gbp-is-active', !!app.guidesVisible));
688
+ this.reg(notes, () => notes.classList.toggle('gbp-is-active', !!app.notesVisible));
689
+ this.reg(pane, () => pane.classList.toggle('gbp-is-active', !!app.formatPaneOpen));
690
+ this.reg(zoom, () => { zoom.querySelector('.pp-rb-combo__label').textContent = `${app.zoom}%`; });
691
+ }
692
+
693
+ /* ===================== 上下文:形状 ===================== */
694
+
695
+ buildContextShape(panel) {
696
+ const app = this.app;
697
+ const shapeBtn = big('shapes', '更改形状', (e) => openShapeGallery(e.currentTarget, (kind) => app.setSelectedProp('kind', kind)), '更改形状');
698
+ const gallery = el('div', 'pp-style-gallery');
699
+ const cards = new Map();
700
+ const render = () => {
701
+ gallery.replaceChildren();
702
+ for (const s of shapeQuickStyles(app.snapshot.theme)) {
703
+ const card = button('pp-style-card', `<span style="background:${s.fill || 'transparent'};border-color:${s.stroke || 'transparent'};color:${s.text}">Aa</span><small>${s.label}</small>`, s.label);
704
+ card.addEventListener('click', () => app.applyShapeQuickStyle(s));
705
+ cards.set(s.key, card);
706
+ gallery.appendChild(card);
707
+ }
708
+ };
709
+ render();
710
+ panel.appendChild(group('插入形状', shapeBtn));
711
+ panel.appendChild(group('形状样式', gallery));
712
+
713
+ const fillBtn = colorButton('fill', '填充', '形状填充', () => app.firstSelected()?.props?.fill || '', (c) => app.setSelectedProp('fill', c));
714
+ const outlineColor = colorButton('outline', '轮廓', '形状轮廓', () => app.firstSelected()?.props?.stroke || '', (c) => app.setSelectedProp('stroke', c));
715
+ const outlineWidth = menuButton('outline', '粗细', () => [1, 2, 3, 4, 6].map((w) => ({
716
+ label: `${w} px`, checked: Math.round(app.firstSelected()?.props?.strokeW) === w, onClick: () => app.setSelectedProp('strokeW', w),
717
+ })), '轮廓粗细');
718
+ const dash = menuButton('line', '虚线', () => [
719
+ { label: '实线', checked: (app.firstSelected()?.props?.dash || 'solid') === 'solid', onClick: () => app.setSelectedProp('dash', 'solid') },
720
+ { label: '虚线', checked: app.firstSelected()?.props?.dash === 'dash', onClick: () => app.setSelectedProp('dash', 'dash') },
721
+ { label: '点线', checked: app.firstSelected()?.props?.dash === 'dot', onClick: () => app.setSelectedProp('dash', 'dot') },
722
+ { label: '点划线', checked: app.firstSelected()?.props?.dash === 'dashDot', onClick: () => app.setSelectedProp('dash', 'dashDot') },
723
+ ], '轮廓样式');
724
+ const shadow = small('shadow', '阴影', () => app.setSelectedProp('shadow', !app.firstSelected()?.props?.shadow), '阴影');
725
+ const noOutline = small('close', '无轮廓', () => app.setSelectedProp('strokeW', 0), '无轮廓');
726
+ panel.appendChild(group('形状填充与轮廓', column(fillBtn, noOutline), column(outlineColor, outlineWidth), column(dash, shadow)));
727
+
728
+ const rotateLeft = small('rotate', '左转 90°', () => app.rotateSelected(-90), '向左旋转 90°');
729
+ const rotateRight = small('rotate', '右转 90°', () => app.rotateSelected(90), '向右旋转 90°');
730
+ const arrange = menuButton('arrange', '排列', () => [
731
+ { label: '置于顶层', onClick: () => app.arrange('front') },
732
+ { label: '上移一层', onClick: () => app.arrange('forward') },
733
+ { label: '下移一层', onClick: () => app.arrange('backward') },
734
+ { label: '置于底层', onClick: () => app.arrange('back') },
735
+ ], '排列');
736
+ panel.appendChild(group('排列', column(rotateLeft, rotateRight), arrange));
737
+
738
+ this.buildSizeGroup(panel);
739
+
740
+ this.reg(gallery, () => {
741
+ // 快速样式不强制高亮(组合样式难以反推),仅保持可点
742
+ });
743
+ this.reg(fillBtn, () => { fillBtn.colorBar.style.background = app.firstSelected()?.props?.fill || 'transparent'; });
744
+ this.reg(outlineColor, () => { outlineColor.colorBar.style.background = app.firstSelected()?.props?.stroke || 'transparent'; });
745
+ this.reg(shadow, () => { shadow.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.shadow); });
746
+ this.reg(noOutline, () => { noOutline.disabled = !app.firstSelected(); });
747
+ }
748
+
749
+ /* ===================== 上下文:图片 ===================== */
750
+
751
+ buildContextImage(panel) {
752
+ const app = this.app;
753
+ const replace = big('replaceImage', '替换图片', () => app.replaceSelectedImage(), '替换图片');
754
+ const reset = big('resetImage', '重置图片', () => app.resetSelectedImage(), '重置裁剪与效果');
755
+ const crop = small('crop', '裁剪', () => app.cropSelected(), '裁剪图片');
756
+ panel.appendChild(group('调整', replace, reset, column(crop)));
757
+
758
+ const shadow = small('shadow', '阴影', () => app.setSelectedProp('shadow', !app.firstSelected()?.props?.shadow), '阴影');
759
+ const alt = small('textBox', '替代文字', () => app.editAltText(), '编辑替代文字(无障碍)');
760
+ panel.appendChild(group('图片样式', column(shadow, alt)));
761
+
762
+ const arrange = menuButton('arrange', '排列', () => [
763
+ { label: '置于顶层', onClick: () => app.arrange('front') },
764
+ { label: '上移一层', onClick: () => app.arrange('forward') },
765
+ { label: '下移一层', onClick: () => app.arrange('backward') },
766
+ { label: '置于底层', onClick: () => app.arrange('back') },
767
+ ], '排列');
768
+ panel.appendChild(group('排列', arrange));
769
+ this.buildSizeGroup(panel);
770
+ this.reg(shadow, () => { shadow.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.shadow); });
771
+ }
772
+
773
+ /* ===================== 上下文:表格 ===================== */
774
+
775
+ buildContextTable(panel) {
776
+ const app = this.app;
777
+ const gallery = el('div', 'pp-table-style-gallery');
778
+ const cards = new Map();
779
+ for (const s of TABLE_STYLES) {
780
+ const card = button('pp-table-style-card', `<span class="pp-table-style-card__preview pp-table-style-card__preview--${s.key}"><i></i><i></i><i></i><i></i></span><span>${s.label}</span>`, s.label);
781
+ card.addEventListener('click', () => app.setTableStyle(s.key));
782
+ cards.set(s.key, card);
783
+ gallery.appendChild(card);
784
+ }
785
+ panel.appendChild(group('表格样式', gallery));
786
+
787
+ const header = small('tableStyle', '标题行', () => app.toggleHeaderRow(), '标题行');
788
+ const banded = small('tableStyle', '镶边行', () => app.toggleBandedRows(), '镶边行');
789
+ panel.appendChild(group('样式选项', column(header, banded)));
790
+
791
+ const rowAbove = small('rowAbove', '上方', () => app.insertTableRow('above'), '在上方插入行');
792
+ const rowBelow = small('rowBelow', '下方', () => app.insertTableRow('below'), '在下方插入行');
793
+ const colLeft = small('colLeft', '左侧', () => app.insertTableColumn('left'), '在左侧插入列');
794
+ const colRight = small('colRight', '右侧', () => app.insertTableColumn('right'), '在右侧插入列');
795
+ const delRow = small('delete', '删除行', () => app.deleteTableRow(), '删除行');
796
+ const delCol = small('delete', '删除列', () => app.deleteTableColumn(), '删除列');
797
+ panel.appendChild(group('行和列', column(rowAbove, rowBelow), column(colLeft, colRight), column(delRow, delCol)));
798
+
799
+ const arrange = menuButton('arrange', '排列', () => [
800
+ { label: '置于顶层', onClick: () => app.arrange('front') },
801
+ { label: '置于底层', onClick: () => app.arrange('back') },
802
+ ], '排列');
803
+ panel.appendChild(group('排列', arrange));
804
+ this.buildSizeGroup(panel);
805
+
806
+ this.reg(gallery, () => {
807
+ const o = app.firstSelected();
808
+ for (const [key, card] of cards) card.classList.toggle('gbp-is-active', o?.props?.tableStyle === key);
809
+ });
810
+ this.reg(header, () => { header.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.headerRow); });
811
+ this.reg(banded, () => { banded.classList.toggle('gbp-is-active', !!app.firstSelected()?.props?.bandedRows); });
812
+ }
813
+
814
+ /** 大小与位置组(单选对象) */
815
+ buildSizeGroup(panel) {
816
+ const app = this.app;
817
+ const wInput = el('input', 'pp-rb-num');
818
+ wInput.type = 'number';
819
+ wInput.step = '1';
820
+ wInput.min = '1';
821
+ wInput.title = '宽度';
822
+ const hInput = el('input', 'pp-rb-num');
823
+ hInput.type = 'number';
824
+ hInput.step = '1';
825
+ hInput.min = '1';
826
+ hInput.title = '高度';
827
+ wInput.addEventListener('mousedown', (e) => e.stopPropagation());
828
+ hInput.addEventListener('mousedown', (e) => e.stopPropagation());
829
+ const apply = (key, input) => {
830
+ const o = app.firstSelected();
831
+ const v = Number(input.value);
832
+ if (!o || !Number.isFinite(v) || v <= 0) return;
833
+ app.updateObject(o.id, { [key]: key === 'w' || key === 'h' ? Math.round(v * (o[key] < 0 ? -1 : 1)) : Math.round(v) });
834
+ };
835
+ wInput.addEventListener('change', () => apply('w', wInput));
836
+ hInput.addEventListener('change', () => apply('h', hInput));
837
+ const wWrap = el('label', 'pp-rb-field');
838
+ wWrap.append(el('span', '', '宽'), wInput);
839
+ const hWrap = el('label', 'pp-rb-field');
840
+ hWrap.append(el('span', '', '高'), hInput);
841
+ panel.appendChild(group('大小', column(wWrap, hWrap)));
842
+ this.reg(wInput, () => {
843
+ if (document.activeElement === wInput) return;
844
+ const o = app.firstSelected();
845
+ wInput.value = o ? String(Math.round(Math.abs(o.w))) : '';
846
+ wInput.disabled = !o;
847
+ });
848
+ this.reg(hInput, () => {
849
+ if (document.activeElement === hInput) return;
850
+ const o = app.firstSelected();
851
+ hInput.value = o ? String(Math.round(Math.abs(o.h))) : '';
852
+ hInput.disabled = !o;
853
+ });
854
+ }
855
+ }