gbpptx 0.2.0 → 0.4.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.
Files changed (46) hide show
  1. package/README.md +237 -214
  2. package/package.json +5 -3
  3. package/src/kernel/model.js +1 -2
  4. package/src/kernel/parts.js +11 -15
  5. package/src/kernel/print.js +14 -16
  6. package/web/app/main.js +8 -8
  7. package/web/app/slides/arrange.js +101 -0
  8. package/web/app/slides/clipboard.js +93 -0
  9. package/web/app/slides/file.js +213 -0
  10. package/web/app/slides/find.js +201 -0
  11. package/web/app/slides/history.js +100 -0
  12. package/web/app/slides/keys.js +179 -0
  13. package/web/app/slides/menus.js +105 -0
  14. package/web/app/slides/objects.js +254 -0
  15. package/web/app/slides/render.js +183 -0
  16. package/web/app/slides/shared.js +85 -0
  17. package/web/app/slides/slides.js +103 -0
  18. package/web/app/slides/table.js +102 -0
  19. package/web/app/slides/text.js +418 -0
  20. package/web/app/slides/view.js +156 -0
  21. package/web/app/slides-app.js +323 -2446
  22. package/web/app/ui/canvas.js +769 -755
  23. package/web/app/ui/color-panel.js +58 -76
  24. package/web/app/ui/dialogs.js +120 -159
  25. package/web/app/ui/file-io.js +116 -132
  26. package/web/app/ui/format-pane.js +427 -427
  27. package/web/app/ui/icons.js +129 -129
  28. package/web/app/ui/menu.js +75 -89
  29. package/web/app/ui/notify.js +45 -45
  30. package/web/app/ui/page-view.js +221 -221
  31. package/web/app/ui/popup.js +80 -80
  32. package/web/app/ui/present.js +292 -292
  33. package/web/app/ui/ribbon.js +868 -878
  34. package/web/app/ui/slide-pane.js +197 -189
  35. package/web/app/ui/statusbar.js +93 -93
  36. package/web/app/ui/text-styles.js +84 -84
  37. package/web/app/ui/titlebar.js +184 -67
  38. package/web/app/ui/transition.js +30 -30
  39. package/web/index.html +23 -21
  40. package/web/serve.mjs +22 -67
  41. package/web/styles/office.css +466 -644
  42. package/web/styles/slides.css +97 -219
  43. package/web/styles/tokens.css +154 -155
  44. package/src/kernel/util/escape.js +0 -21
  45. package/src/kernel/util/id.js +0 -13
  46. package/web/app/ui/backstage.js +0 -255
@@ -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,156 @@
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
+
9
+ /** 预览模式:只读 + 阅读视图 + 收起菜单/功能窗格;同一按钮或 Esc 退出并恢复原视图 */
10
+ function setPreview(on) {
11
+ const next = !!on;
12
+ if (next === this.preview) return;
13
+ if (next) {
14
+ this.previewRestore = { readOnly: this.readOnly, menuBar: this.menuBarVisible, view: this.view };
15
+ this.preview = true;
16
+ this.root.classList.add('gbp-is-preview');
17
+ this.ribbon.setPreview(true);
18
+ this.commitEditing({ render: false });
19
+ this.setView('reading');
20
+ this.setReadOnly(true);
21
+ this.setMenuBarVisible(false);
22
+ } else {
23
+ const restore = this.previewRestore || { readOnly: false, menuBar: true, view: 'normal' };
24
+ this.preview = false;
25
+ this.root.classList.remove('gbp-is-preview');
26
+ this.ribbon.setPreview(false);
27
+ this.setView(restore.view);
28
+ this.setReadOnly(restore.readOnly);
29
+ this.setMenuBarVisible(restore.menuBar);
30
+ this.previewRestore = null;
31
+ }
32
+ }
33
+
34
+ function setView(view) {
35
+ if (!['normal', 'sorter', 'reading'].includes(view)) return;
36
+ this.commitEditing({ render: false });
37
+ this.view = view;
38
+ if (view !== 'normal') {
39
+ this.selectedIds = [];
40
+ this.findEl && (this.findEl.hidden = true);
41
+ }
42
+ this.updateLayout();
43
+ this.renderAll();
44
+ this.statusbar.refresh();
45
+ this.ribbon.refresh();
46
+ }
47
+
48
+ function setZoom(z, opts = {}) {
49
+ this.zoom = clamp(Math.round(Number(z) || 100), ZOOM_MIN, ZOOM_MAX);
50
+ this.prefs.zoom = this.zoom;
51
+ savePrefs(this.prefs);
52
+ if (this.view === 'normal') this.canvas.rescale();
53
+ else if (this.view === 'sorter') this.renderSorter();
54
+ else this.renderReading();
55
+ this.statusbar.refresh();
56
+ if (!opts.fromSlider) this.statusbar.slider.value = String(this.zoom);
57
+ }
58
+
59
+ function fitToWindow() {
60
+ if (this.view !== 'normal') return;
61
+ const w = Math.max(200, this.canvas.scroll.clientWidth - 72);
62
+ const h = Math.max(150, this.canvas.scroll.clientHeight - 72);
63
+ const size = this.size;
64
+ this.setZoom(Math.min(w / size.w, h / size.h) * 100);
65
+ }
66
+
67
+ function toggleNotes() {
68
+ this.commitEditing({ render: false });
69
+ this.notesVisible = !this.notesVisible;
70
+ this.prefs.notesVisible = this.notesVisible;
71
+ savePrefs(this.prefs);
72
+ this.updateLayout();
73
+ this.renderNotes();
74
+ this.ribbon.refresh();
75
+ this.statusbar.refresh();
76
+ }
77
+
78
+ function toggleGrid() {
79
+ this.commitEditing({ render: false });
80
+ this.gridVisible = !this.gridVisible;
81
+ this.prefs.grid = this.gridVisible;
82
+ savePrefs(this.prefs);
83
+ if (this.view === 'normal') this.canvas.render();
84
+ this.ribbon.refresh();
85
+ }
86
+
87
+ function toggleGuides() {
88
+ this.commitEditing({ render: false });
89
+ this.guidesVisible = !this.guidesVisible;
90
+ this.prefs.guides = this.guidesVisible;
91
+ savePrefs(this.prefs);
92
+ if (this.view === 'normal') this.canvas.render();
93
+ this.ribbon.refresh();
94
+ }
95
+
96
+ function setRibbonCollapsed(on) {
97
+ this.ribbonCollapsed = !!on;
98
+ this.prefs.ribbonCollapsed = this.ribbonCollapsed;
99
+ savePrefs(this.prefs);
100
+ this.ribbon.setCollapsed(this.ribbonCollapsed);
101
+ }
102
+
103
+ function toggleFormatPane() {
104
+ if (this.formatPaneOpen && this.view === 'normal') {
105
+ this.formatPaneOpen = false;
106
+ this.formatPane.close();
107
+ } else {
108
+ this.openFormatPane();
109
+ return;
110
+ }
111
+ this.prefs.formatPaneOpen = this.formatPaneOpen;
112
+ savePrefs(this.prefs);
113
+ this.updateLayout();
114
+ this.ribbon.refresh();
115
+ }
116
+
117
+ function openFormatPane() {
118
+ if (this.view !== 'normal') this.setView('normal');
119
+ this.formatPaneOpen = true;
120
+ this.prefs.formatPaneOpen = true;
121
+ savePrefs(this.prefs);
122
+ this.updateLayout();
123
+ this.formatPane.open();
124
+ this.ribbon.refresh();
125
+ }
126
+
127
+ function togglePresenter() {
128
+ this.presentOptions.presenter = !this.presentOptions.presenter;
129
+ this.prefs.presenter = this.presentOptions.presenter;
130
+ savePrefs(this.prefs);
131
+ this.ribbon.refresh();
132
+ }
133
+
134
+ function toggleLoop() {
135
+ this.presentOptions.loop = !this.presentOptions.loop;
136
+ this.prefs.loop = this.presentOptions.loop;
137
+ savePrefs(this.prefs);
138
+ this.ribbon.refresh();
139
+ }
140
+
141
+ function presentFromStart() {
142
+ this.commitEditing({ render: false });
143
+ this.presenter.open(0);
144
+ }
145
+
146
+ function presentFromCurrent() {
147
+ this.commitEditing({ render: false });
148
+ this.presenter.open(this.index);
149
+ }
150
+
151
+ function presentAt(index) {
152
+ this.commitEditing({ render: false });
153
+ this.presenter.open(Number(index) || 0);
154
+ }
155
+
156
+ export const viewMethods = { setView, setZoom, fitToWindow, toggleNotes, toggleGrid, toggleGuides, setRibbonCollapsed, toggleFormatPane, openFormatPane, togglePresenter, toggleLoop, presentFromStart, presentFromCurrent, presentAt, setPreview };