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