gbpptx 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +253 -253
- package/package.json +48 -47
- package/src/index.js +29 -29
- package/src/kernel/model.js +651 -651
- package/src/kernel/parts.js +173 -173
- package/src/kernel/pptx.js +72 -72
- package/src/kernel/print.js +76 -76
- package/src/kernel/read.js +1018 -1018
- package/src/kernel/roundtrip.js +174 -174
- package/src/kernel/text.js +278 -278
- package/src/kernel/write.js +385 -385
- package/web/app/main.js +8 -8
- package/web/app/slides/arrange.js +101 -101
- package/web/app/slides/clipboard.js +93 -93
- package/web/app/slides/file.js +240 -240
- package/web/app/slides/find.js +201 -201
- package/web/app/slides/history.js +100 -100
- package/web/app/slides/keys.js +187 -187
- package/web/app/slides/menus.js +105 -105
- package/web/app/slides/objects.js +254 -254
- package/web/app/slides/render.js +183 -183
- package/web/app/slides/shared.js +85 -85
- package/web/app/slides/slides.js +103 -103
- package/web/app/slides/table.js +102 -102
- package/web/app/slides/text.js +418 -418
- package/web/app/slides/view.js +182 -182
- package/web/app/slides-app.js +354 -354
- package/web/app/ui/canvas.js +769 -769
- package/web/app/ui/color-panel.js +58 -58
- package/web/app/ui/dialogs.js +120 -120
- package/web/app/ui/file-io.js +116 -116
- package/web/app/ui/format-pane.js +427 -427
- package/web/app/ui/icons.js +241 -133
- package/web/app/ui/menu.js +77 -75
- 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 +855 -855
- package/web/app/ui/slide-pane.js +197 -197
- package/web/app/ui/statusbar.js +93 -93
- package/web/app/ui/text-styles.js +84 -84
- package/web/app/ui/titlebar.js +253 -250
- package/web/app/ui/transition.js +30 -30
- package/web/index.html +30 -29
- package/web/serve.mjs +26 -23
- package/web/styles/office.css +463 -463
- package/web/styles/slides.css +97 -97
- package/web/styles/tokens.css +154 -154
package/web/app/slides/find.js
CHANGED
|
@@ -1,201 +1,201 @@
|
|
|
1
|
-
// [文件] gbpptx·slides·find —— 查找替换与字数统计
|
|
2
|
-
|
|
3
|
-
// [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
|
|
4
|
-
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
-
|
|
6
|
-
import { htmlToPlain } from '../../../src/kernel/model.js';
|
|
7
|
-
import { notify } from '../ui/notify.js';
|
|
8
|
-
import { field, openModal } from '../ui/dialogs.js';
|
|
9
|
-
import { icon } from '../ui/icons.js';
|
|
10
|
-
import { el, replaceInHtml, replaceInPlain } from './shared.js';
|
|
11
|
-
function openFind(replace = false) {
|
|
12
|
-
if (this.view !== 'normal') this.setView('normal');
|
|
13
|
-
this.commitEditing({ render: false });
|
|
14
|
-
if (!this.findEl) this.buildFindBar();
|
|
15
|
-
this.findEl.hidden = false;
|
|
16
|
-
this.findEl.classList.toggle('gbp-is-replace', replace);
|
|
17
|
-
this.findReplaceRow.hidden = !replace;
|
|
18
|
-
this.findState.replace = replace;
|
|
19
|
-
this.refreshMatches();
|
|
20
|
-
this.findInput.focus();
|
|
21
|
-
this.findInput.select();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function closeFind() {
|
|
25
|
-
if (!this.findEl) return;
|
|
26
|
-
this.findEl.hidden = true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function buildFindBar() {
|
|
30
|
-
const bar = el('div', 'pp-findbar');
|
|
31
|
-
const top = el('div', 'pp-findbar__row');
|
|
32
|
-
this.findInput = el('input', 'pp-input pp-findbar__input');
|
|
33
|
-
this.findInput.type = 'text';
|
|
34
|
-
this.findInput.placeholder = '查找';
|
|
35
|
-
this.findCount = el('span', 'pp-findbar__count', '0/0');
|
|
36
|
-
const prev = el('button', 'pp-iconbtn', '');
|
|
37
|
-
prev.type = 'button';
|
|
38
|
-
prev.title = '上一个';
|
|
39
|
-
prev.innerHTML = icon('chevronUp', 15);
|
|
40
|
-
const next = el('button', 'pp-iconbtn', '');
|
|
41
|
-
next.type = 'button';
|
|
42
|
-
next.title = '下一个';
|
|
43
|
-
next.innerHTML = icon('chevronDown', 15);
|
|
44
|
-
const close = el('button', 'pp-iconbtn', '');
|
|
45
|
-
close.type = 'button';
|
|
46
|
-
close.title = '关闭';
|
|
47
|
-
close.innerHTML = icon('close', 15);
|
|
48
|
-
top.append(this.findInput, this.findCount, prev, next, close);
|
|
49
|
-
|
|
50
|
-
this.findReplaceRow = el('div', 'pp-findbar__row');
|
|
51
|
-
this.replaceInput = el('input', 'pp-input pp-findbar__input');
|
|
52
|
-
this.replaceInput.type = 'text';
|
|
53
|
-
this.replaceInput.placeholder = '替换为';
|
|
54
|
-
const replaceBtn = el('button', 'pp-chip', '替换');
|
|
55
|
-
replaceBtn.type = 'button';
|
|
56
|
-
const allBtn = el('button', 'pp-chip', '全部替换');
|
|
57
|
-
allBtn.type = 'button';
|
|
58
|
-
this.findReplaceRow.append(this.replaceInput, replaceBtn, allBtn);
|
|
59
|
-
bar.append(top, this.findReplaceRow);
|
|
60
|
-
this.center.appendChild(bar);
|
|
61
|
-
this.findEl = bar;
|
|
62
|
-
this.findState = { replace: false, matches: [], cursor: -1 };
|
|
63
|
-
|
|
64
|
-
prev.addEventListener('click', () => this.findNext(true));
|
|
65
|
-
next.addEventListener('click', () => this.findNext(false));
|
|
66
|
-
close.addEventListener('click', () => this.closeFind());
|
|
67
|
-
replaceBtn.addEventListener('click', () => this.replaceCurrent());
|
|
68
|
-
allBtn.addEventListener('click', () => this.replaceAll());
|
|
69
|
-
this.findInput.addEventListener('input', () => { this.refreshMatches(); this.findNext(false); });
|
|
70
|
-
this.findInput.addEventListener('keydown', (e) => {
|
|
71
|
-
if (e.key === 'Enter') { e.preventDefault(); this.findNext(e.shiftKey); }
|
|
72
|
-
if (e.key === 'Escape') { e.preventDefault(); this.closeFind(); }
|
|
73
|
-
});
|
|
74
|
-
this.replaceInput.addEventListener('keydown', (e) => {
|
|
75
|
-
if (e.key === 'Enter') { e.preventDefault(); this.replaceCurrent(); }
|
|
76
|
-
if (e.key === 'Escape') { e.preventDefault(); this.closeFind(); }
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function objectTextFields(slide) {
|
|
81
|
-
const fields = [];
|
|
82
|
-
for (const o of slide.objects) {
|
|
83
|
-
if (o.type === 'text') fields.push({ obj: o, field: 'html', text: htmlToPlain(o.props.html) });
|
|
84
|
-
else if (o.type === 'shape') fields.push({ obj: o, field: 'text', text: o.props.text || '' });
|
|
85
|
-
else if (o.type === 'table') fields.push({ obj: o, field: 'table', text: (o.props.rows || []).flat().join('\n') });
|
|
86
|
-
}
|
|
87
|
-
return fields;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function refreshMatches() {
|
|
91
|
-
if (!this.findEl) return;
|
|
92
|
-
const q = this.findInput.value;
|
|
93
|
-
const matches = [];
|
|
94
|
-
if (q) {
|
|
95
|
-
this.snapshot.slides.forEach((slide, si) => {
|
|
96
|
-
for (const f of this.objectTextFields(slide)) {
|
|
97
|
-
if (f.text.toLowerCase().includes(q.toLowerCase())) matches.push({ si, objId: f.obj.id, field: f.field });
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
this.findState.matches = matches;
|
|
102
|
-
this.findState.cursor = matches.length ? Math.min(this.findState.cursor, matches.length - 1) : -1;
|
|
103
|
-
this.findCount.textContent = matches.length ? `${this.findState.cursor + 1}/${matches.length}` : '0/0';
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function findNext(back = false) {
|
|
107
|
-
const state = this.findState;
|
|
108
|
-
if (!state?.matches?.length) return;
|
|
109
|
-
state.cursor = back
|
|
110
|
-
? (state.cursor - 1 + state.matches.length) % state.matches.length
|
|
111
|
-
: (state.cursor + 1) % state.matches.length;
|
|
112
|
-
const match = state.matches[state.cursor];
|
|
113
|
-
this.findCount.textContent = `${state.cursor + 1}/${state.matches.length}`;
|
|
114
|
-
if (match.si !== this.index) this.selectSlide(match.si);
|
|
115
|
-
this.selectObjects([match.objId]);
|
|
116
|
-
this.canvas.flashObject(match.objId);
|
|
117
|
-
this.statusbar.setStatus(`找到于第 ${match.si + 1} 页`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function replaceCurrent() {
|
|
121
|
-
if (this.readOnly) return;
|
|
122
|
-
const state = this.findState;
|
|
123
|
-
const match = state?.matches?.[state.cursor];
|
|
124
|
-
const q = this.findInput.value;
|
|
125
|
-
if (!match || !q) return;
|
|
126
|
-
const slide = this.snapshot.slides[match.si];
|
|
127
|
-
const obj = slide.objects.find((o) => o.id === match.objId);
|
|
128
|
-
if (!obj) return;
|
|
129
|
-
this.pushHistory();
|
|
130
|
-
const replacement = this.replaceInput.value;
|
|
131
|
-
if (match.field === 'html') obj.props.html = replaceInHtml(obj.props.html, q, replacement);
|
|
132
|
-
else if (match.field === 'text') obj.props.text = replaceInPlain(obj.props.text, q, replacement);
|
|
133
|
-
else obj.props.rows = obj.props.rows.map((row) => row.map((cell) => replaceInPlain(cell, q, replacement)));
|
|
134
|
-
this.notifyChange();
|
|
135
|
-
this.refreshMatches();
|
|
136
|
-
this.findNext(false);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function replaceAll() {
|
|
140
|
-
if (this.readOnly) return;
|
|
141
|
-
const q = this.findInput.value;
|
|
142
|
-
if (!q) return;
|
|
143
|
-
const replacement = this.replaceInput.value;
|
|
144
|
-
this.pushHistory();
|
|
145
|
-
for (const slide of this.snapshot.slides) {
|
|
146
|
-
for (const o of slide.objects) {
|
|
147
|
-
if (o.type === 'text') o.props.html = replaceInHtml(o.props.html, q, replacement, true);
|
|
148
|
-
else if (o.type === 'shape') o.props.text = replaceInPlain(o.props.text, q, replacement, true);
|
|
149
|
-
else if (o.type === 'table') o.props.rows = o.props.rows.map((row) => row.map((cell) => replaceInPlain(cell, q, replacement, true)));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
this.notifyChange();
|
|
153
|
-
this.refreshMatches();
|
|
154
|
-
notify.success('已完成全部替换');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function showWordCount() {
|
|
158
|
-
let chars = 0;
|
|
159
|
-
let words = 0;
|
|
160
|
-
let textBoxes = 0;
|
|
161
|
-
let shapes = 0;
|
|
162
|
-
let images = 0;
|
|
163
|
-
let tables = 0;
|
|
164
|
-
const allText = [];
|
|
165
|
-
for (const slide of this.snapshot.slides) {
|
|
166
|
-
for (const o of slide.objects) {
|
|
167
|
-
if (o.type === 'text') { textBoxes += 1; allText.push(htmlToPlain(o.props.html)); }
|
|
168
|
-
else if (o.type === 'shape') { shapes += 1; allText.push(o.props.text || ''); }
|
|
169
|
-
else if (o.type === 'image') images += 1;
|
|
170
|
-
else if (o.type === 'table') { tables += 1; allText.push(...o.props.rows.flat()); }
|
|
171
|
-
else if (o.type === 'line') shapes += 1;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const text = allText.join('\n');
|
|
175
|
-
chars = text.replace(/\s/g, '').length;
|
|
176
|
-
words = (text.match(/[\u4e00-\u9fa5]|[A-Za-z0-9]+/g) || []).length;
|
|
177
|
-
openModal({
|
|
178
|
-
title: '字数统计',
|
|
179
|
-
width: 420,
|
|
180
|
-
confirmText: '关闭',
|
|
181
|
-
build: (body) => {
|
|
182
|
-
const grid = el('div', 'pp-info-grid');
|
|
183
|
-
for (const [k, v] of [
|
|
184
|
-
['幻灯片', `${this.snapshot.slides.length} 页`],
|
|
185
|
-
['文字框', textBoxes],
|
|
186
|
-
['图形/线条', shapes],
|
|
187
|
-
['图片', images],
|
|
188
|
-
['表格', tables],
|
|
189
|
-
['字数', words],
|
|
190
|
-
['字符数(不计空格)', chars],
|
|
191
|
-
]) {
|
|
192
|
-
const item = el('div', 'pp-info-grid__item');
|
|
193
|
-
item.append(el('span', '', k), el('strong', '', String(v)));
|
|
194
|
-
grid.appendChild(item);
|
|
195
|
-
}
|
|
196
|
-
body.appendChild(grid);
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export const findMethods = { openFind, closeFind, buildFindBar, objectTextFields, refreshMatches, findNext, replaceCurrent, replaceAll, showWordCount };
|
|
1
|
+
// [文件] gbpptx·slides·find —— 查找替换与字数统计
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
|
|
4
|
+
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
+
|
|
6
|
+
import { htmlToPlain } from '../../../src/kernel/model.js';
|
|
7
|
+
import { notify } from '../ui/notify.js';
|
|
8
|
+
import { field, openModal } from '../ui/dialogs.js';
|
|
9
|
+
import { icon } from '../ui/icons.js';
|
|
10
|
+
import { el, replaceInHtml, replaceInPlain } from './shared.js';
|
|
11
|
+
function openFind(replace = false) {
|
|
12
|
+
if (this.view !== 'normal') this.setView('normal');
|
|
13
|
+
this.commitEditing({ render: false });
|
|
14
|
+
if (!this.findEl) this.buildFindBar();
|
|
15
|
+
this.findEl.hidden = false;
|
|
16
|
+
this.findEl.classList.toggle('gbp-is-replace', replace);
|
|
17
|
+
this.findReplaceRow.hidden = !replace;
|
|
18
|
+
this.findState.replace = replace;
|
|
19
|
+
this.refreshMatches();
|
|
20
|
+
this.findInput.focus();
|
|
21
|
+
this.findInput.select();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function closeFind() {
|
|
25
|
+
if (!this.findEl) return;
|
|
26
|
+
this.findEl.hidden = true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function buildFindBar() {
|
|
30
|
+
const bar = el('div', 'pp-findbar');
|
|
31
|
+
const top = el('div', 'pp-findbar__row');
|
|
32
|
+
this.findInput = el('input', 'pp-input pp-findbar__input');
|
|
33
|
+
this.findInput.type = 'text';
|
|
34
|
+
this.findInput.placeholder = '查找';
|
|
35
|
+
this.findCount = el('span', 'pp-findbar__count', '0/0');
|
|
36
|
+
const prev = el('button', 'pp-iconbtn', '');
|
|
37
|
+
prev.type = 'button';
|
|
38
|
+
prev.title = '上一个';
|
|
39
|
+
prev.innerHTML = icon('chevronUp', 15);
|
|
40
|
+
const next = el('button', 'pp-iconbtn', '');
|
|
41
|
+
next.type = 'button';
|
|
42
|
+
next.title = '下一个';
|
|
43
|
+
next.innerHTML = icon('chevronDown', 15);
|
|
44
|
+
const close = el('button', 'pp-iconbtn', '');
|
|
45
|
+
close.type = 'button';
|
|
46
|
+
close.title = '关闭';
|
|
47
|
+
close.innerHTML = icon('close', 15);
|
|
48
|
+
top.append(this.findInput, this.findCount, prev, next, close);
|
|
49
|
+
|
|
50
|
+
this.findReplaceRow = el('div', 'pp-findbar__row');
|
|
51
|
+
this.replaceInput = el('input', 'pp-input pp-findbar__input');
|
|
52
|
+
this.replaceInput.type = 'text';
|
|
53
|
+
this.replaceInput.placeholder = '替换为';
|
|
54
|
+
const replaceBtn = el('button', 'pp-chip', '替换');
|
|
55
|
+
replaceBtn.type = 'button';
|
|
56
|
+
const allBtn = el('button', 'pp-chip', '全部替换');
|
|
57
|
+
allBtn.type = 'button';
|
|
58
|
+
this.findReplaceRow.append(this.replaceInput, replaceBtn, allBtn);
|
|
59
|
+
bar.append(top, this.findReplaceRow);
|
|
60
|
+
this.center.appendChild(bar);
|
|
61
|
+
this.findEl = bar;
|
|
62
|
+
this.findState = { replace: false, matches: [], cursor: -1 };
|
|
63
|
+
|
|
64
|
+
prev.addEventListener('click', () => this.findNext(true));
|
|
65
|
+
next.addEventListener('click', () => this.findNext(false));
|
|
66
|
+
close.addEventListener('click', () => this.closeFind());
|
|
67
|
+
replaceBtn.addEventListener('click', () => this.replaceCurrent());
|
|
68
|
+
allBtn.addEventListener('click', () => this.replaceAll());
|
|
69
|
+
this.findInput.addEventListener('input', () => { this.refreshMatches(); this.findNext(false); });
|
|
70
|
+
this.findInput.addEventListener('keydown', (e) => {
|
|
71
|
+
if (e.key === 'Enter') { e.preventDefault(); this.findNext(e.shiftKey); }
|
|
72
|
+
if (e.key === 'Escape') { e.preventDefault(); this.closeFind(); }
|
|
73
|
+
});
|
|
74
|
+
this.replaceInput.addEventListener('keydown', (e) => {
|
|
75
|
+
if (e.key === 'Enter') { e.preventDefault(); this.replaceCurrent(); }
|
|
76
|
+
if (e.key === 'Escape') { e.preventDefault(); this.closeFind(); }
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function objectTextFields(slide) {
|
|
81
|
+
const fields = [];
|
|
82
|
+
for (const o of slide.objects) {
|
|
83
|
+
if (o.type === 'text') fields.push({ obj: o, field: 'html', text: htmlToPlain(o.props.html) });
|
|
84
|
+
else if (o.type === 'shape') fields.push({ obj: o, field: 'text', text: o.props.text || '' });
|
|
85
|
+
else if (o.type === 'table') fields.push({ obj: o, field: 'table', text: (o.props.rows || []).flat().join('\n') });
|
|
86
|
+
}
|
|
87
|
+
return fields;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function refreshMatches() {
|
|
91
|
+
if (!this.findEl) return;
|
|
92
|
+
const q = this.findInput.value;
|
|
93
|
+
const matches = [];
|
|
94
|
+
if (q) {
|
|
95
|
+
this.snapshot.slides.forEach((slide, si) => {
|
|
96
|
+
for (const f of this.objectTextFields(slide)) {
|
|
97
|
+
if (f.text.toLowerCase().includes(q.toLowerCase())) matches.push({ si, objId: f.obj.id, field: f.field });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
this.findState.matches = matches;
|
|
102
|
+
this.findState.cursor = matches.length ? Math.min(this.findState.cursor, matches.length - 1) : -1;
|
|
103
|
+
this.findCount.textContent = matches.length ? `${this.findState.cursor + 1}/${matches.length}` : '0/0';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function findNext(back = false) {
|
|
107
|
+
const state = this.findState;
|
|
108
|
+
if (!state?.matches?.length) return;
|
|
109
|
+
state.cursor = back
|
|
110
|
+
? (state.cursor - 1 + state.matches.length) % state.matches.length
|
|
111
|
+
: (state.cursor + 1) % state.matches.length;
|
|
112
|
+
const match = state.matches[state.cursor];
|
|
113
|
+
this.findCount.textContent = `${state.cursor + 1}/${state.matches.length}`;
|
|
114
|
+
if (match.si !== this.index) this.selectSlide(match.si);
|
|
115
|
+
this.selectObjects([match.objId]);
|
|
116
|
+
this.canvas.flashObject(match.objId);
|
|
117
|
+
this.statusbar.setStatus(`找到于第 ${match.si + 1} 页`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function replaceCurrent() {
|
|
121
|
+
if (this.readOnly) return;
|
|
122
|
+
const state = this.findState;
|
|
123
|
+
const match = state?.matches?.[state.cursor];
|
|
124
|
+
const q = this.findInput.value;
|
|
125
|
+
if (!match || !q) return;
|
|
126
|
+
const slide = this.snapshot.slides[match.si];
|
|
127
|
+
const obj = slide.objects.find((o) => o.id === match.objId);
|
|
128
|
+
if (!obj) return;
|
|
129
|
+
this.pushHistory();
|
|
130
|
+
const replacement = this.replaceInput.value;
|
|
131
|
+
if (match.field === 'html') obj.props.html = replaceInHtml(obj.props.html, q, replacement);
|
|
132
|
+
else if (match.field === 'text') obj.props.text = replaceInPlain(obj.props.text, q, replacement);
|
|
133
|
+
else obj.props.rows = obj.props.rows.map((row) => row.map((cell) => replaceInPlain(cell, q, replacement)));
|
|
134
|
+
this.notifyChange();
|
|
135
|
+
this.refreshMatches();
|
|
136
|
+
this.findNext(false);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function replaceAll() {
|
|
140
|
+
if (this.readOnly) return;
|
|
141
|
+
const q = this.findInput.value;
|
|
142
|
+
if (!q) return;
|
|
143
|
+
const replacement = this.replaceInput.value;
|
|
144
|
+
this.pushHistory();
|
|
145
|
+
for (const slide of this.snapshot.slides) {
|
|
146
|
+
for (const o of slide.objects) {
|
|
147
|
+
if (o.type === 'text') o.props.html = replaceInHtml(o.props.html, q, replacement, true);
|
|
148
|
+
else if (o.type === 'shape') o.props.text = replaceInPlain(o.props.text, q, replacement, true);
|
|
149
|
+
else if (o.type === 'table') o.props.rows = o.props.rows.map((row) => row.map((cell) => replaceInPlain(cell, q, replacement, true)));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
this.notifyChange();
|
|
153
|
+
this.refreshMatches();
|
|
154
|
+
notify.success('已完成全部替换');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function showWordCount() {
|
|
158
|
+
let chars = 0;
|
|
159
|
+
let words = 0;
|
|
160
|
+
let textBoxes = 0;
|
|
161
|
+
let shapes = 0;
|
|
162
|
+
let images = 0;
|
|
163
|
+
let tables = 0;
|
|
164
|
+
const allText = [];
|
|
165
|
+
for (const slide of this.snapshot.slides) {
|
|
166
|
+
for (const o of slide.objects) {
|
|
167
|
+
if (o.type === 'text') { textBoxes += 1; allText.push(htmlToPlain(o.props.html)); }
|
|
168
|
+
else if (o.type === 'shape') { shapes += 1; allText.push(o.props.text || ''); }
|
|
169
|
+
else if (o.type === 'image') images += 1;
|
|
170
|
+
else if (o.type === 'table') { tables += 1; allText.push(...o.props.rows.flat()); }
|
|
171
|
+
else if (o.type === 'line') shapes += 1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const text = allText.join('\n');
|
|
175
|
+
chars = text.replace(/\s/g, '').length;
|
|
176
|
+
words = (text.match(/[\u4e00-\u9fa5]|[A-Za-z0-9]+/g) || []).length;
|
|
177
|
+
openModal({
|
|
178
|
+
title: '字数统计',
|
|
179
|
+
width: 420,
|
|
180
|
+
confirmText: '关闭',
|
|
181
|
+
build: (body) => {
|
|
182
|
+
const grid = el('div', 'pp-info-grid');
|
|
183
|
+
for (const [k, v] of [
|
|
184
|
+
['幻灯片', `${this.snapshot.slides.length} 页`],
|
|
185
|
+
['文字框', textBoxes],
|
|
186
|
+
['图形/线条', shapes],
|
|
187
|
+
['图片', images],
|
|
188
|
+
['表格', tables],
|
|
189
|
+
['字数', words],
|
|
190
|
+
['字符数(不计空格)', chars],
|
|
191
|
+
]) {
|
|
192
|
+
const item = el('div', 'pp-info-grid__item');
|
|
193
|
+
item.append(el('span', '', k), el('strong', '', String(v)));
|
|
194
|
+
grid.appendChild(item);
|
|
195
|
+
}
|
|
196
|
+
body.appendChild(grid);
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export const findMethods = { openFind, closeFind, buildFindBar, objectTextFields, refreshMatches, findNext, replaceCurrent, replaceAll, showWordCount };
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
// [文件] gbpptx·slides·history —— 脏状态与撤销历史 —— 自动保存调度、快照栈、变更通知
|
|
2
|
-
|
|
3
|
-
// [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
|
|
4
|
-
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
-
|
|
6
|
-
import { clamp } from 'guabiutils';
|
|
7
|
-
import { savePrefs, HISTORY_LIMIT, AUTOSAVE_MS } from './shared.js';
|
|
8
|
-
function setDirty(on) {
|
|
9
|
-
this.dirty = !!on;
|
|
10
|
-
this.titlebar.refresh();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function touch() {
|
|
14
|
-
this.revision += 1;
|
|
15
|
-
this.setDirty(true);
|
|
16
|
-
this.scheduleAutosave();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function markDirty() {
|
|
20
|
-
this.touch();
|
|
21
|
-
this.titlebar.refresh();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function persistPrefs() {
|
|
25
|
-
savePrefs(this.prefs);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function scheduleAutosave() {
|
|
29
|
-
clearTimeout(this.autosaveTimer);
|
|
30
|
-
if (!this.autosave || !this.doc.handle || !this.dirty) return;
|
|
31
|
-
this.autosaveTimer = setTimeout(() => {
|
|
32
|
-
if (this.dirty && this.doc.handle) this.save(true);
|
|
33
|
-
}, AUTOSAVE_MS);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function setAutosave(on) {
|
|
37
|
-
this.autosave = !!on;
|
|
38
|
-
this.prefs.autosave = this.autosave;
|
|
39
|
-
savePrefs(this.prefs);
|
|
40
|
-
this.scheduleAutosave();
|
|
41
|
-
this.titlebar.refresh();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function pushHistory() {
|
|
45
|
-
this.pushHistorySnapshot(JSON.stringify(this.snapshot));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function pushHistorySnapshot(snapshot) {
|
|
49
|
-
this.history.push(snapshot);
|
|
50
|
-
if (this.history.length > HISTORY_LIMIT) this.history.shift();
|
|
51
|
-
this.future = [];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function beginGesture() {
|
|
55
|
-
this.pushHistory();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function canUndo() { return this.history.length > 0; }
|
|
59
|
-
|
|
60
|
-
function canRedo() { return this.future.length > 0; }
|
|
61
|
-
|
|
62
|
-
function undo() {
|
|
63
|
-
this.commitEditing({ render: false });
|
|
64
|
-
if (!this.history.length) return;
|
|
65
|
-
this.future.push(JSON.stringify(this.snapshot));
|
|
66
|
-
this.snapshot = JSON.parse(this.history.pop());
|
|
67
|
-
this.index = clamp(this.index, 0, this.snapshot.slides.length - 1);
|
|
68
|
-
this.selectedIds = [];
|
|
69
|
-
this.touch();
|
|
70
|
-
this.renderAll();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function redo() {
|
|
74
|
-
this.commitEditing({ render: false });
|
|
75
|
-
if (!this.future.length) return;
|
|
76
|
-
this.history.push(JSON.stringify(this.snapshot));
|
|
77
|
-
this.snapshot = JSON.parse(this.future.pop());
|
|
78
|
-
this.index = clamp(this.index, 0, this.snapshot.slides.length - 1);
|
|
79
|
-
this.selectedIds = [];
|
|
80
|
-
this.touch();
|
|
81
|
-
this.renderAll();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function notifyChange(opts = {}) {
|
|
85
|
-
if (this.editing) this.commitEditing({ render: false });
|
|
86
|
-
this.touch();
|
|
87
|
-
this.statusbar.setStatus('');
|
|
88
|
-
if (opts.canvasOnly && this.view === 'normal') {
|
|
89
|
-
this.canvas.render();
|
|
90
|
-
this.slidePane.render();
|
|
91
|
-
this.formatPane.render();
|
|
92
|
-
this.ribbon.refresh();
|
|
93
|
-
this.titlebar.refresh();
|
|
94
|
-
this.statusbar.refresh();
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
this.renderAll();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export const historyMethods = { setDirty, touch, markDirty, persistPrefs, scheduleAutosave, setAutosave, pushHistory, pushHistorySnapshot, beginGesture, canUndo, canRedo, undo, redo, notifyChange };
|
|
1
|
+
// [文件] gbpptx·slides·history —— 脏状态与撤销历史 —— 自动保存调度、快照栈、变更通知
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
|
|
4
|
+
// 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
|
|
5
|
+
|
|
6
|
+
import { clamp } from 'guabiutils';
|
|
7
|
+
import { savePrefs, HISTORY_LIMIT, AUTOSAVE_MS } from './shared.js';
|
|
8
|
+
function setDirty(on) {
|
|
9
|
+
this.dirty = !!on;
|
|
10
|
+
this.titlebar.refresh();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function touch() {
|
|
14
|
+
this.revision += 1;
|
|
15
|
+
this.setDirty(true);
|
|
16
|
+
this.scheduleAutosave();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function markDirty() {
|
|
20
|
+
this.touch();
|
|
21
|
+
this.titlebar.refresh();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function persistPrefs() {
|
|
25
|
+
savePrefs(this.prefs);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function scheduleAutosave() {
|
|
29
|
+
clearTimeout(this.autosaveTimer);
|
|
30
|
+
if (!this.autosave || !this.doc.handle || !this.dirty) return;
|
|
31
|
+
this.autosaveTimer = setTimeout(() => {
|
|
32
|
+
if (this.dirty && this.doc.handle) this.save(true);
|
|
33
|
+
}, AUTOSAVE_MS);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function setAutosave(on) {
|
|
37
|
+
this.autosave = !!on;
|
|
38
|
+
this.prefs.autosave = this.autosave;
|
|
39
|
+
savePrefs(this.prefs);
|
|
40
|
+
this.scheduleAutosave();
|
|
41
|
+
this.titlebar.refresh();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function pushHistory() {
|
|
45
|
+
this.pushHistorySnapshot(JSON.stringify(this.snapshot));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function pushHistorySnapshot(snapshot) {
|
|
49
|
+
this.history.push(snapshot);
|
|
50
|
+
if (this.history.length > HISTORY_LIMIT) this.history.shift();
|
|
51
|
+
this.future = [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function beginGesture() {
|
|
55
|
+
this.pushHistory();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function canUndo() { return this.history.length > 0; }
|
|
59
|
+
|
|
60
|
+
function canRedo() { return this.future.length > 0; }
|
|
61
|
+
|
|
62
|
+
function undo() {
|
|
63
|
+
this.commitEditing({ render: false });
|
|
64
|
+
if (!this.history.length) return;
|
|
65
|
+
this.future.push(JSON.stringify(this.snapshot));
|
|
66
|
+
this.snapshot = JSON.parse(this.history.pop());
|
|
67
|
+
this.index = clamp(this.index, 0, this.snapshot.slides.length - 1);
|
|
68
|
+
this.selectedIds = [];
|
|
69
|
+
this.touch();
|
|
70
|
+
this.renderAll();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function redo() {
|
|
74
|
+
this.commitEditing({ render: false });
|
|
75
|
+
if (!this.future.length) return;
|
|
76
|
+
this.history.push(JSON.stringify(this.snapshot));
|
|
77
|
+
this.snapshot = JSON.parse(this.future.pop());
|
|
78
|
+
this.index = clamp(this.index, 0, this.snapshot.slides.length - 1);
|
|
79
|
+
this.selectedIds = [];
|
|
80
|
+
this.touch();
|
|
81
|
+
this.renderAll();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function notifyChange(opts = {}) {
|
|
85
|
+
if (this.editing) this.commitEditing({ render: false });
|
|
86
|
+
this.touch();
|
|
87
|
+
this.statusbar.setStatus('');
|
|
88
|
+
if (opts.canvasOnly && this.view === 'normal') {
|
|
89
|
+
this.canvas.render();
|
|
90
|
+
this.slidePane.render();
|
|
91
|
+
this.formatPane.render();
|
|
92
|
+
this.ribbon.refresh();
|
|
93
|
+
this.titlebar.refresh();
|
|
94
|
+
this.statusbar.refresh();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.renderAll();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const historyMethods = { setDirty, touch, markDirty, persistPrefs, scheduleAutosave, setAutosave, pushHistory, pushHistorySnapshot, beginGesture, canUndo, canRedo, undo, redo, notifyChange };
|