gbpptx 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -214
- package/package.json +4 -3
- package/src/kernel/model.js +1 -2
- package/src/kernel/parts.js +11 -15
- package/src/kernel/print.js +14 -16
- package/web/app/main.js +8 -8
- package/web/app/slides/arrange.js +101 -0
- package/web/app/slides/clipboard.js +93 -0
- package/web/app/slides/file.js +243 -0
- package/web/app/slides/find.js +199 -0
- package/web/app/slides/history.js +100 -0
- package/web/app/slides/keys.js +174 -0
- package/web/app/slides/menus.js +105 -0
- package/web/app/slides/objects.js +254 -0
- package/web/app/slides/render.js +183 -0
- package/web/app/slides/shared.js +85 -0
- package/web/app/slides/slides.js +103 -0
- package/web/app/slides/table.js +102 -0
- package/web/app/slides/text.js +418 -0
- package/web/app/slides/view.js +130 -0
- package/web/app/slides-app.js +285 -2446
- package/web/app/ui/backstage.js +255 -255
- package/web/app/ui/canvas.js +762 -755
- package/web/app/ui/color-panel.js +58 -76
- package/web/app/ui/dialogs.js +120 -159
- package/web/app/ui/file-io.js +116 -132
- package/web/app/ui/format-pane.js +427 -427
- package/web/app/ui/icons.js +129 -129
- package/web/app/ui/menu.js +75 -89
- package/web/app/ui/notify.js +45 -45
- package/web/app/ui/page-view.js +221 -221
- package/web/app/ui/popup.js +80 -80
- package/web/app/ui/present.js +292 -292
- package/web/app/ui/ribbon.js +878 -878
- package/web/app/ui/slide-pane.js +189 -189
- package/web/app/ui/statusbar.js +93 -93
- package/web/app/ui/text-styles.js +84 -84
- package/web/app/ui/titlebar.js +173 -66
- package/web/app/ui/transition.js +30 -30
- package/web/index.html +23 -22
- package/web/serve.mjs +20 -67
- package/web/styles/office.css +642 -644
- package/web/styles/slides.css +210 -219
- package/web/styles/tokens.css +154 -155
- package/src/kernel/util/escape.js +0 -21
- package/src/kernel/util/id.js +0 -13
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// [文件] gbpptx·slides·text —— 文本编辑与格式 —— 就地编辑生命周期、行内格式与段落格式
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
|
|
4
|
+
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
+
|
|
6
|
+
import { clamp, escapeHtml, normalizeColor } from 'guabiutils';
|
|
7
|
+
import { htmlToPlain, setObjectFontSize, themeOf } from '../../../src/kernel/model.js';
|
|
8
|
+
import { htmlToParas, parasToHTML, sanitizeTextHtml } from '../../../src/kernel/text.js';
|
|
9
|
+
import { styleFromNode, closestBlock, closeAlign } from './shared.js';
|
|
10
|
+
function beginTextEdit(obj, node, kind, meta = {}) {
|
|
11
|
+
this.editing = {
|
|
12
|
+
obj, id: obj.id, node, kind, meta,
|
|
13
|
+
before: JSON.stringify(this.snapshot),
|
|
14
|
+
changed: false,
|
|
15
|
+
range: null,
|
|
16
|
+
};
|
|
17
|
+
if (kind === 'cell') {
|
|
18
|
+
this.tableCursor = { objId: obj.id, ri: meta.ri, ci: meta.ci };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function syncEditing() {
|
|
23
|
+
const e = this.editing;
|
|
24
|
+
if (!e) return;
|
|
25
|
+
if (!e.changed) {
|
|
26
|
+
this.pushHistorySnapshot(e.before);
|
|
27
|
+
e.changed = true;
|
|
28
|
+
}
|
|
29
|
+
if (e.kind === 'cell') {
|
|
30
|
+
const { ri, ci } = e.meta;
|
|
31
|
+
const rows = e.obj.props.rows;
|
|
32
|
+
if (rows[ri]) rows[ri][ci] = String(e.node.innerText || '').replace(/\n+$/, '');
|
|
33
|
+
} else if (e.kind === 'text') {
|
|
34
|
+
e.obj.props.html = sanitizeTextHtml(e.node.innerHTML);
|
|
35
|
+
} else if (e.kind === 'shape') {
|
|
36
|
+
e.obj.props.text = String(e.node.innerText || '').replace(/\n+$/, '');
|
|
37
|
+
}
|
|
38
|
+
this.markDirty();
|
|
39
|
+
this.ribbon.refresh();
|
|
40
|
+
this.titlebar.refresh();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function noteEditChange() {
|
|
44
|
+
const e = this.editing;
|
|
45
|
+
if (!e || e.changed) return;
|
|
46
|
+
this.pushHistorySnapshot(e.before);
|
|
47
|
+
e.changed = true;
|
|
48
|
+
this.markDirty();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function commitEditing({ render = true, node = null } = {}) {
|
|
52
|
+
const e = this.editing;
|
|
53
|
+
if (!e) return;
|
|
54
|
+
if (node && e.node !== node) return;
|
|
55
|
+
if (e.kind === 'cell') {
|
|
56
|
+
this.tableCursor = { objId: e.obj.id, ri: e.meta.ri, ci: e.meta.ci };
|
|
57
|
+
}
|
|
58
|
+
this.editing = null;
|
|
59
|
+
if (e.changed) {
|
|
60
|
+
this.setDirty(true);
|
|
61
|
+
if (render) this.notifyChange();
|
|
62
|
+
else {
|
|
63
|
+
// 不重建格式窗格:点击窗格控件触发的 blur 不能把正在点的 DOM 换掉
|
|
64
|
+
this.ribbon.refresh();
|
|
65
|
+
this.titlebar.refresh();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function startEditingById(id) {
|
|
71
|
+
this.selectSlide(this.index);
|
|
72
|
+
this.selectObjects([id]);
|
|
73
|
+
setTimeout(() => this.canvas.editObject(id), 0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function editCellAt(objId, ri, ci) {
|
|
77
|
+
const obj = this.selectedById(objId);
|
|
78
|
+
if (!obj || obj.type !== 'table') return;
|
|
79
|
+
if (ri >= obj.props.rows.length || ci >= (obj.props.rows[0]?.length || 1)) return;
|
|
80
|
+
this.selectedIds = [obj.id];
|
|
81
|
+
this.renderAll();
|
|
82
|
+
this.canvas.editCell(obj, ri, ci);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function canFormatText() {
|
|
86
|
+
if (this.editing) return true;
|
|
87
|
+
const objs = this.selectedObjects();
|
|
88
|
+
return objs.some((o) => o.type === 'text' || o.type === 'shape' || o.type === 'table');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function canRichText() {
|
|
92
|
+
if (this.editing) return this.editing.kind !== 'cell';
|
|
93
|
+
const objs = this.selectedObjects();
|
|
94
|
+
return objs.length > 0 && objs.every((o) => o.type === 'text' || o.type === 'shape');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function canAlignText() {
|
|
98
|
+
return this.canRichText();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function canList() {
|
|
102
|
+
if (this.editing) return this.editing.kind === 'text';
|
|
103
|
+
return this.selectedObjects().some((o) => o.type === 'text');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function textState() {
|
|
107
|
+
const base = {
|
|
108
|
+
bold: false, italic: false, underline: false, strike: false,
|
|
109
|
+
font: '', fontSize: 0, color: '', align: 'left', lineSpacing: 1, list: '', editing: false,
|
|
110
|
+
};
|
|
111
|
+
if (this.editing) {
|
|
112
|
+
const e = this.editing;
|
|
113
|
+
const sel = window.getSelection();
|
|
114
|
+
let node = sel?.anchorNode || e.node;
|
|
115
|
+
if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
|
|
116
|
+
if (!node || !e.node.contains(node)) node = e.node;
|
|
117
|
+
const cs = window.getComputedStyle(node);
|
|
118
|
+
const style = styleFromNode(node, e.node);
|
|
119
|
+
const block = closestBlock(node, e.node);
|
|
120
|
+
const alignMap = { left: 'left', start: 'left', center: 'center', right: 'right', justify: 'justify' };
|
|
121
|
+
const list = node.closest?.('ul,ol');
|
|
122
|
+
return {
|
|
123
|
+
...base,
|
|
124
|
+
...style,
|
|
125
|
+
align: alignMap[closeAlign(block)] || 'left',
|
|
126
|
+
lineSpacing: e.obj.props.lineSpacing || 1,
|
|
127
|
+
list: list ? (list.tagName === 'OL' ? 'number' : 'bullet') : '',
|
|
128
|
+
editing: true,
|
|
129
|
+
fontSize: parseFloat(cs.fontSize) || e.obj.props.fontSize || 24,
|
|
130
|
+
color: normalizeColor(cs.color) || e.obj.props.color || '',
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const o = this.firstSelected();
|
|
134
|
+
if (!o) return base;
|
|
135
|
+
const p = o.props || {};
|
|
136
|
+
const defaultColor = themeOf(this.snapshot.theme).text;
|
|
137
|
+
return {
|
|
138
|
+
...base,
|
|
139
|
+
bold: !!p.bold,
|
|
140
|
+
italic: !!p.italic,
|
|
141
|
+
underline: !!p.underline,
|
|
142
|
+
strike: !!p.strike,
|
|
143
|
+
font: p.font || '',
|
|
144
|
+
fontSize: p.fontSize || 0,
|
|
145
|
+
color: o.type === 'shape' ? (p.textColor || defaultColor) : (p.color || defaultColor),
|
|
146
|
+
align: p.align || 'left',
|
|
147
|
+
lineSpacing: p.lineSpacing || 1,
|
|
148
|
+
list: '',
|
|
149
|
+
editing: false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function toggleTextStyle(key) {
|
|
154
|
+
const command = { bold: 'bold', italic: 'italic', underline: 'underline', strike: 'strikeThrough' }[key];
|
|
155
|
+
if (!command) return;
|
|
156
|
+
if (this.editing?.kind === 'text') {
|
|
157
|
+
this.canvas.focusEditing?.();
|
|
158
|
+
document.execCommand(command, false);
|
|
159
|
+
this.syncEditing();
|
|
160
|
+
this.ribbon.refresh();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (this.editing?.kind === 'shape') {
|
|
164
|
+
const o = this.editing.obj;
|
|
165
|
+
const value = !o.props[key];
|
|
166
|
+
o.props[key] = value;
|
|
167
|
+
if (key === 'bold') this.editing.node.style.fontWeight = value ? '700' : '400';
|
|
168
|
+
else if (key === 'italic') this.editing.node.style.fontStyle = value ? 'italic' : 'normal';
|
|
169
|
+
else {
|
|
170
|
+
this.editing.node.style.textDecoration = [o.props.underline ? 'underline' : '', o.props.strike ? 'line-through' : '']
|
|
171
|
+
.filter(Boolean).join(' ') || 'none';
|
|
172
|
+
}
|
|
173
|
+
this.noteEditChange();
|
|
174
|
+
this.ribbon.refresh();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (this.editing) return;
|
|
178
|
+
if (!this.canRichText()) return;
|
|
179
|
+
const objs = this.selectedObjects();
|
|
180
|
+
const first = objs[0];
|
|
181
|
+
const value = !first?.props?.[key];
|
|
182
|
+
this.pushHistory();
|
|
183
|
+
for (const o of objs) {
|
|
184
|
+
if (o.type === 'text' || o.type === 'shape') o.props[key] = value;
|
|
185
|
+
}
|
|
186
|
+
this.notifyChange();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function applyFontFamily(font) {
|
|
190
|
+
if (this.editing?.kind === 'text' && this.canvas.wrapSelection({ fontFamily: font })) {
|
|
191
|
+
this.ribbon.refresh();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (this.editing) {
|
|
195
|
+
const o = this.editing.obj;
|
|
196
|
+
if (this.editing.kind === 'cell') {
|
|
197
|
+
o.props.font = font;
|
|
198
|
+
this.editing.node.closest('table')?.querySelectorAll('td').forEach((td) => { td.style.fontFamily = font; });
|
|
199
|
+
} else {
|
|
200
|
+
for (const target of this.selectedObjects()) if (target.props) target.props.font = font;
|
|
201
|
+
this.editing.node.style.fontFamily = font;
|
|
202
|
+
}
|
|
203
|
+
this.noteEditChange();
|
|
204
|
+
this.ribbon.refresh();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (!this.canFormatText()) return;
|
|
208
|
+
this.pushHistory();
|
|
209
|
+
for (const o of this.selectedObjects()) {
|
|
210
|
+
if (o.props && o.type !== 'line') o.props.font = font;
|
|
211
|
+
}
|
|
212
|
+
this.notifyChange();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function applyFontSize(px) {
|
|
216
|
+
const value = clamp(Math.round(Number(px) || 0), 6, 200);
|
|
217
|
+
if (!value) return;
|
|
218
|
+
if (this.editing?.kind === 'text' && this.canvas.wrapSelection({ fontSize: `${value}px` })) {
|
|
219
|
+
this.ribbon.refresh();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (this.editing) {
|
|
223
|
+
const o = this.editing.obj;
|
|
224
|
+
if (this.editing.kind === 'cell') {
|
|
225
|
+
o.props.fontSize = value;
|
|
226
|
+
this.editing.node.closest('table')?.querySelectorAll('td').forEach((td) => { td.style.fontSize = `${value}px`; });
|
|
227
|
+
} else {
|
|
228
|
+
for (const target of this.selectedObjects()) {
|
|
229
|
+
if (target.type === 'text') setObjectFontSize(target, value);
|
|
230
|
+
else if (target.props) target.props.fontSize = value;
|
|
231
|
+
}
|
|
232
|
+
this.editing.node.style.fontSize = `${value}px`;
|
|
233
|
+
}
|
|
234
|
+
this.noteEditChange();
|
|
235
|
+
this.ribbon.refresh();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (!this.canFormatText()) return;
|
|
239
|
+
this.pushHistory();
|
|
240
|
+
for (const o of this.selectedObjects()) {
|
|
241
|
+
if (o.type === 'text') setObjectFontSize(o, value);
|
|
242
|
+
else if (o.type === 'shape' || o.type === 'table') o.props.fontSize = value;
|
|
243
|
+
}
|
|
244
|
+
this.notifyChange();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function setFontSize(px) { this.applyFontSize(px); }
|
|
248
|
+
|
|
249
|
+
function setFontFamily(font) { this.applyFontFamily(font); }
|
|
250
|
+
|
|
251
|
+
function stepFontSize(delta) {
|
|
252
|
+
const current = this.textState().fontSize || 24;
|
|
253
|
+
this.applyFontSize(current + (delta > 0 ? 2 : -2));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function applyTextColor(color) {
|
|
257
|
+
const themed = color || themeOf(this.snapshot.theme).text;
|
|
258
|
+
if (this.editing?.kind === 'text' && this.canvas.wrapSelection({ color: themed })) {
|
|
259
|
+
this.ribbon.refresh();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (this.editing) {
|
|
263
|
+
if (this.editing.kind === 'cell') {
|
|
264
|
+
this.editing.obj.props.color = color;
|
|
265
|
+
this.editing.node.closest('table')?.querySelectorAll('td').forEach((td) => { td.style.color = themed; });
|
|
266
|
+
} else {
|
|
267
|
+
for (const o of this.selectedObjects()) {
|
|
268
|
+
if (o.type === 'shape') o.props.textColor = themed;
|
|
269
|
+
else if (o.props && o.type !== 'line') o.props.color = color;
|
|
270
|
+
}
|
|
271
|
+
this.editing.node.style.color = themed;
|
|
272
|
+
}
|
|
273
|
+
this.noteEditChange();
|
|
274
|
+
this.ribbon.refresh();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (!this.canFormatText()) return;
|
|
278
|
+
this.pushHistory();
|
|
279
|
+
for (const o of this.selectedObjects()) {
|
|
280
|
+
if (o.type === 'shape') o.props.textColor = themed;
|
|
281
|
+
else if (o.props && o.type !== 'line') o.props.color = color;
|
|
282
|
+
}
|
|
283
|
+
this.notifyChange();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function applyAlign(align) {
|
|
287
|
+
if (this.editing?.kind === 'text') {
|
|
288
|
+
const command = { left: 'justifyLeft', center: 'justifyCenter', right: 'justifyRight', justify: 'justifyFull' }[align];
|
|
289
|
+
if (command) document.execCommand(command, false);
|
|
290
|
+
this.syncEditing();
|
|
291
|
+
this.ribbon.refresh();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (this.editing?.kind === 'shape') {
|
|
295
|
+
this.editing.obj.props.align = align;
|
|
296
|
+
this.editing.node.style.textAlign = align;
|
|
297
|
+
this.noteEditChange();
|
|
298
|
+
this.ribbon.refresh();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (this.editing) return;
|
|
302
|
+
if (!this.canAlignText()) return;
|
|
303
|
+
this.pushHistory();
|
|
304
|
+
for (const o of this.selectedObjects()) if (o.props) o.props.align = align;
|
|
305
|
+
this.notifyChange();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function applyList(kind) {
|
|
309
|
+
if (this.editing) {
|
|
310
|
+
if (this.editing.kind !== 'text') return;
|
|
311
|
+
document.execCommand(kind === 'bullet' ? 'insertUnorderedList' : 'insertOrderedList', false);
|
|
312
|
+
this.syncEditing();
|
|
313
|
+
this.ribbon.refresh();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!this.canRichText()) return;
|
|
317
|
+
this.pushHistory();
|
|
318
|
+
for (const o of this.selectedObjects()) {
|
|
319
|
+
if (o.type !== 'text') continue;
|
|
320
|
+
const lines = htmlToPlain(o.props.html).split('\n').map((s) => s.trim()).filter(Boolean);
|
|
321
|
+
if (!lines.length) continue;
|
|
322
|
+
const tag = kind === 'bullet' ? 'ul' : 'ol';
|
|
323
|
+
o.props.html = `<${tag}>${lines.map((line) => `<li>${escapeHtml(line)}</li>`).join('')}</${tag}>`;
|
|
324
|
+
}
|
|
325
|
+
this.notifyChange();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function applyIndent(delta) {
|
|
329
|
+
if (!this.editing || this.editing.kind !== 'text') return;
|
|
330
|
+
// 只对列表项改层级:普通段落缩进不在对象模型里,做了也存不下来
|
|
331
|
+
if (!this.textState().list) return;
|
|
332
|
+
document.execCommand(delta > 0 ? 'indent' : 'outdent', false);
|
|
333
|
+
this.syncEditing();
|
|
334
|
+
this.ribbon.refresh();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function applyLineSpacing(v) {
|
|
338
|
+
const value = clamp(Number(v) || 1, 0.6, 4);
|
|
339
|
+
if (this.editing) {
|
|
340
|
+
if (this.editing.kind === 'cell') return;
|
|
341
|
+
for (const o of this.selectedObjects()) if (o.props && (o.type === 'text' || o.type === 'shape')) o.props.lineSpacing = value;
|
|
342
|
+
this.editing.node.style.lineHeight = String(value * 1.2);
|
|
343
|
+
this.noteEditChange();
|
|
344
|
+
this.ribbon.refresh();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (!this.canRichText()) return;
|
|
348
|
+
this.pushHistory();
|
|
349
|
+
for (const o of this.selectedObjects()) if (o.props && (o.type === 'text' || o.type === 'shape')) o.props.lineSpacing = value;
|
|
350
|
+
this.notifyChange();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function clearFormatting() {
|
|
354
|
+
if (this.editing?.kind === 'cell') {
|
|
355
|
+
const table = this.editing.obj;
|
|
356
|
+
Object.assign(table.props, { font: '', fontSize: 16, color: '' });
|
|
357
|
+
this.editing.node.closest('table')?.querySelectorAll('td').forEach((td) => {
|
|
358
|
+
td.style.fontFamily = '';
|
|
359
|
+
td.style.fontSize = '16px';
|
|
360
|
+
td.style.color = themeOf(this.snapshot.theme).text;
|
|
361
|
+
});
|
|
362
|
+
this.noteEditChange();
|
|
363
|
+
this.ribbon.refresh();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (this.editing?.kind === 'shape') {
|
|
367
|
+
const shape = this.editing.obj;
|
|
368
|
+
Object.assign(shape.props, {
|
|
369
|
+
font: '', fontSize: 18, textColor: '#ffffff', bold: false, italic: false,
|
|
370
|
+
underline: false, strike: false, align: 'center', lineSpacing: 1,
|
|
371
|
+
});
|
|
372
|
+
Object.assign(this.editing.node.style, {
|
|
373
|
+
fontFamily: '', fontSize: '18px', color: '#ffffff', fontWeight: '400',
|
|
374
|
+
fontStyle: 'normal', textDecoration: 'none', textAlign: 'center', lineHeight: '1.2',
|
|
375
|
+
});
|
|
376
|
+
this.noteEditChange();
|
|
377
|
+
this.ribbon.refresh();
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (this.editing) {
|
|
381
|
+
this.canvas.focusEditing();
|
|
382
|
+
document.execCommand('removeFormat', false);
|
|
383
|
+
const o = this.editing.obj;
|
|
384
|
+
Object.assign(o.props, {
|
|
385
|
+
font: '', fontSize: 24, color: '', bold: false, italic: false,
|
|
386
|
+
underline: false, strike: false, lineSpacing: 1,
|
|
387
|
+
});
|
|
388
|
+
Object.assign(this.editing.node.style, {
|
|
389
|
+
fontFamily: '', fontSize: '24px', color: themeOf(this.snapshot.theme).text,
|
|
390
|
+
fontWeight: '400', fontStyle: 'normal', textDecoration: 'none', lineHeight: '1.2',
|
|
391
|
+
});
|
|
392
|
+
this.syncEditing();
|
|
393
|
+
this.ribbon.refresh();
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (!this.selectedObjects().length) return;
|
|
397
|
+
this.pushHistory();
|
|
398
|
+
for (const o of this.selectedObjects()) {
|
|
399
|
+
if (o.type === 'text') {
|
|
400
|
+
const paras = htmlToParas(o.props.html);
|
|
401
|
+
for (const p of paras) {
|
|
402
|
+
for (const r of p.runs) {
|
|
403
|
+
r.bold = false; r.italic = false; r.underline = false; r.strike = false;
|
|
404
|
+
r.color = ''; r.font = ''; r.size = 0;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
o.props.html = parasToHTML(paras);
|
|
408
|
+
Object.assign(o.props, { font: '', fontSize: 24, color: '', bold: false, italic: false, underline: false, strike: false, align: 'left', lineSpacing: 1 });
|
|
409
|
+
} else if (o.type === 'shape') {
|
|
410
|
+
Object.assign(o.props, { font: '', fontSize: 18, textColor: '#ffffff', bold: false, italic: false, underline: false, align: 'center', lineSpacing: 1, shadow: false });
|
|
411
|
+
} else if (o.type === 'table') {
|
|
412
|
+
Object.assign(o.props, { font: '', fontSize: 16, color: '', tableStyle: 'plain', headerRow: false, bandedRows: false });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
this.notifyChange();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export const textMethods = { beginTextEdit, syncEditing, noteEditChange, commitEditing, startEditingById, editCellAt, canFormatText, canRichText, canAlignText, canList, textState, toggleTextStyle, applyFontFamily, applyFontSize, setFontSize, setFontFamily, stepFontSize, applyTextColor, applyAlign, applyList, applyIndent, applyLineSpacing, clearFormatting };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// [文件] gbpptx·slides·view —— 视图与放映 —— 缩放/网格/参考线/窗格/放映
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
|
|
4
|
+
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
+
|
|
6
|
+
import { clamp } from 'guabiutils';
|
|
7
|
+
import { savePrefs, ZOOM_MIN, ZOOM_MAX } from './shared.js';
|
|
8
|
+
function setView(view) {
|
|
9
|
+
if (!['normal', 'sorter', 'reading'].includes(view)) return;
|
|
10
|
+
this.commitEditing({ render: false });
|
|
11
|
+
this.view = view;
|
|
12
|
+
if (view !== 'normal') {
|
|
13
|
+
this.selectedIds = [];
|
|
14
|
+
this.findEl && (this.findEl.hidden = true);
|
|
15
|
+
}
|
|
16
|
+
this.updateLayout();
|
|
17
|
+
this.renderAll();
|
|
18
|
+
this.statusbar.refresh();
|
|
19
|
+
this.ribbon.refresh();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setZoom(z, opts = {}) {
|
|
23
|
+
this.zoom = clamp(Math.round(Number(z) || 100), ZOOM_MIN, ZOOM_MAX);
|
|
24
|
+
this.prefs.zoom = this.zoom;
|
|
25
|
+
savePrefs(this.prefs);
|
|
26
|
+
if (this.view === 'normal') this.canvas.rescale();
|
|
27
|
+
else if (this.view === 'sorter') this.renderSorter();
|
|
28
|
+
else this.renderReading();
|
|
29
|
+
this.statusbar.refresh();
|
|
30
|
+
if (!opts.fromSlider) this.statusbar.slider.value = String(this.zoom);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function fitToWindow() {
|
|
34
|
+
if (this.view !== 'normal') return;
|
|
35
|
+
const w = Math.max(200, this.canvas.scroll.clientWidth - 72);
|
|
36
|
+
const h = Math.max(150, this.canvas.scroll.clientHeight - 72);
|
|
37
|
+
const size = this.size;
|
|
38
|
+
this.setZoom(Math.min(w / size.w, h / size.h) * 100);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toggleNotes() {
|
|
42
|
+
this.commitEditing({ render: false });
|
|
43
|
+
this.notesVisible = !this.notesVisible;
|
|
44
|
+
this.prefs.notesVisible = this.notesVisible;
|
|
45
|
+
savePrefs(this.prefs);
|
|
46
|
+
this.updateLayout();
|
|
47
|
+
this.renderNotes();
|
|
48
|
+
this.ribbon.refresh();
|
|
49
|
+
this.statusbar.refresh();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function toggleGrid() {
|
|
53
|
+
this.commitEditing({ render: false });
|
|
54
|
+
this.gridVisible = !this.gridVisible;
|
|
55
|
+
this.prefs.grid = this.gridVisible;
|
|
56
|
+
savePrefs(this.prefs);
|
|
57
|
+
if (this.view === 'normal') this.canvas.render();
|
|
58
|
+
this.ribbon.refresh();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toggleGuides() {
|
|
62
|
+
this.commitEditing({ render: false });
|
|
63
|
+
this.guidesVisible = !this.guidesVisible;
|
|
64
|
+
this.prefs.guides = this.guidesVisible;
|
|
65
|
+
savePrefs(this.prefs);
|
|
66
|
+
if (this.view === 'normal') this.canvas.render();
|
|
67
|
+
this.ribbon.refresh();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function setRibbonCollapsed(on) {
|
|
71
|
+
this.ribbonCollapsed = !!on;
|
|
72
|
+
this.prefs.ribbonCollapsed = this.ribbonCollapsed;
|
|
73
|
+
savePrefs(this.prefs);
|
|
74
|
+
this.ribbon.setCollapsed(this.ribbonCollapsed);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toggleFormatPane() {
|
|
78
|
+
if (this.formatPaneOpen && this.view === 'normal') {
|
|
79
|
+
this.formatPaneOpen = false;
|
|
80
|
+
this.formatPane.close();
|
|
81
|
+
} else {
|
|
82
|
+
this.openFormatPane();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.prefs.formatPaneOpen = this.formatPaneOpen;
|
|
86
|
+
savePrefs(this.prefs);
|
|
87
|
+
this.updateLayout();
|
|
88
|
+
this.ribbon.refresh();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function openFormatPane() {
|
|
92
|
+
if (this.view !== 'normal') this.setView('normal');
|
|
93
|
+
this.formatPaneOpen = true;
|
|
94
|
+
this.prefs.formatPaneOpen = true;
|
|
95
|
+
savePrefs(this.prefs);
|
|
96
|
+
this.updateLayout();
|
|
97
|
+
this.formatPane.open();
|
|
98
|
+
this.ribbon.refresh();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function togglePresenter() {
|
|
102
|
+
this.presentOptions.presenter = !this.presentOptions.presenter;
|
|
103
|
+
this.prefs.presenter = this.presentOptions.presenter;
|
|
104
|
+
savePrefs(this.prefs);
|
|
105
|
+
this.ribbon.refresh();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function toggleLoop() {
|
|
109
|
+
this.presentOptions.loop = !this.presentOptions.loop;
|
|
110
|
+
this.prefs.loop = this.presentOptions.loop;
|
|
111
|
+
savePrefs(this.prefs);
|
|
112
|
+
this.ribbon.refresh();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function presentFromStart() {
|
|
116
|
+
this.commitEditing({ render: false });
|
|
117
|
+
this.presenter.open(0);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function presentFromCurrent() {
|
|
121
|
+
this.commitEditing({ render: false });
|
|
122
|
+
this.presenter.open(this.index);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function presentAt(index) {
|
|
126
|
+
this.commitEditing({ render: false });
|
|
127
|
+
this.presenter.open(Number(index) || 0);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const viewMethods = { setView, setZoom, fitToWindow, toggleNotes, toggleGrid, toggleGuides, setRibbonCollapsed, toggleFormatPane, openFormatPane, togglePresenter, toggleLoop, presentFromStart, presentFromCurrent, presentAt };
|