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
package/web/app/ui/slide-pane.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
// [文件] gbpptx·幻灯片窗格 —— 缩略图/大纲双视图、拖拽排序、页操作入口
|
|
2
|
-
|
|
3
|
-
import { SLIDE_LAYOUTS, TRANSITIONS, htmlToPlain } from '../../../src/kernel/model.js';
|
|
4
|
-
import { renderPage } from './page-view.js';
|
|
5
|
-
import { icon } from './icons.js';
|
|
6
|
-
import { openMenu } from './menu.js';
|
|
7
|
-
|
|
8
|
-
const THUMB_W = 164;
|
|
9
|
-
|
|
10
|
-
export class SlidePane {
|
|
11
|
-
constructor(app) {
|
|
12
|
-
this.app = app;
|
|
13
|
-
this.el = document.createElement('aside');
|
|
14
|
-
this.el.className = 'pp-slidepane';
|
|
15
|
-
this.el.innerHTML = `
|
|
16
|
-
<div class="pp-slidepane__tabs">
|
|
17
|
-
<button type="button" class="pp-slidepane__tab is-active" data-tab="slides">幻灯片</button>
|
|
18
|
-
<button type="button" class="pp-slidepane__tab" data-tab="outline">大纲</button>
|
|
19
|
-
</div>
|
|
20
|
-
<div class="pp-slidepane__body">
|
|
21
|
-
<div class="pp-thumbs" data-view="slides"></div>
|
|
22
|
-
<div class="pp-outline" data-view="outline" hidden></div>
|
|
23
|
-
</div>
|
|
24
|
-
<div class="pp-slidepane__foot">
|
|
25
|
-
<button type="button" class="pp-slidepane__new" data-act="new">${icon('newSlide', 18)}<span>新建幻灯片</span></button>
|
|
26
|
-
<button type="button" class="pp-slidepane__layout" data-act="layout" title="选择版式">${icon('chevronDown', 14)}</button>
|
|
27
|
-
</div>`;
|
|
28
|
-
this.thumbsEl = this.el.querySelector('.pp-thumbs');
|
|
29
|
-
this.outlineEl = this.el.querySelector('.pp-outline');
|
|
30
|
-
this.tabButtons = [...this.el.querySelectorAll('[data-tab]')];
|
|
31
|
-
this.view = 'slides';
|
|
32
|
-
this.bind();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
bind() {
|
|
36
|
-
for (const btn of this.tabButtons) {
|
|
37
|
-
btn.addEventListener('click', () => this.setView(btn.dataset.tab));
|
|
38
|
-
}
|
|
39
|
-
this.el.querySelector('[data-act="new"]').addEventListener('click', () => this.app.addSlide());
|
|
40
|
-
this.el.querySelector('[data-act="layout"]').addEventListener('click', (e) => {
|
|
41
|
-
openMenu({
|
|
42
|
-
anchor: e.currentTarget,
|
|
43
|
-
placement: 'top-end',
|
|
44
|
-
items: SLIDE_LAYOUTS.map((l) => ({ label: l.label, onClick: () => this.app.addSlide(l.key) })),
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
this.thumbsEl.addEventListener('click', (e) => {
|
|
48
|
-
const thumb = e.target.closest('.pp-thumb');
|
|
49
|
-
if (thumb) this.app.selectSlide(Number(thumb.dataset.index));
|
|
50
|
-
});
|
|
51
|
-
this.thumbsEl.addEventListener('dblclick', (e) => {
|
|
52
|
-
const thumb = e.target.closest('.pp-thumb');
|
|
53
|
-
if (thumb) this.app.presentAt(Number(thumb.dataset.index));
|
|
54
|
-
});
|
|
55
|
-
this.thumbsEl.addEventListener('contextmenu', (e) => {
|
|
56
|
-
const thumb = e.target.closest('.pp-thumb');
|
|
57
|
-
if (!thumb) return;
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
this.app.selectSlide(Number(thumb.dataset.index));
|
|
60
|
-
this.app.openSlideMenu(e.clientX, e.clientY, Number(thumb.dataset.index));
|
|
61
|
-
});
|
|
62
|
-
this.thumbsEl.addEventListener('dragstart', (e) => {
|
|
63
|
-
const thumb = e.target.closest('.pp-thumb');
|
|
64
|
-
if (!thumb) return;
|
|
65
|
-
this.dragIndex = Number(thumb.dataset.index);
|
|
66
|
-
thumb.classList.add('is-dragging');
|
|
67
|
-
e.dataTransfer.effectAllowed = 'move';
|
|
68
|
-
e.dataTransfer.setData('text/plain', String(this.dragIndex));
|
|
69
|
-
});
|
|
70
|
-
this.thumbsEl.addEventListener('dragend', () => {
|
|
71
|
-
this.dragIndex = null;
|
|
72
|
-
this.thumbsEl.querySelectorAll('.is-dragging, .is-drop').forEach((el) => el.classList.remove('is-dragging', 'is-drop'));
|
|
73
|
-
});
|
|
74
|
-
this.thumbsEl.addEventListener('dragover', (e) => {
|
|
75
|
-
const thumb = e.target.closest('.pp-thumb');
|
|
76
|
-
if (!thumb || this.dragIndex === null) return;
|
|
77
|
-
e.preventDefault();
|
|
78
|
-
this.thumbsEl.querySelectorAll('.is-drop').forEach((el) => el.classList.remove('is-drop'));
|
|
79
|
-
thumb.classList.add('is-drop');
|
|
80
|
-
});
|
|
81
|
-
this.thumbsEl.addEventListener('drop', (e) => {
|
|
82
|
-
const thumb = e.target.closest('.pp-thumb');
|
|
83
|
-
if (!thumb || this.dragIndex === null) return;
|
|
84
|
-
e.preventDefault();
|
|
85
|
-
const to = Number(thumb.dataset.index);
|
|
86
|
-
this.thumbsEl.querySelectorAll('.is-drop').forEach((el) => el.classList.remove('is-drop'));
|
|
87
|
-
if (to !== this.dragIndex) this.app.moveSlideTo(this.dragIndex, to);
|
|
88
|
-
this.dragIndex = null;
|
|
89
|
-
});
|
|
90
|
-
this.outlineEl.addEventListener('click', (e) => {
|
|
91
|
-
const line = e.target.closest('[data-slide]');
|
|
92
|
-
if (!line) return;
|
|
93
|
-
this.app.selectSlide(Number(line.dataset.slide));
|
|
94
|
-
if (line.dataset.obj) this.app.selectObjects([line.dataset.obj]);
|
|
95
|
-
});
|
|
96
|
-
this.outlineEl.addEventListener('dblclick', (e) => {
|
|
97
|
-
const line = e.target.closest('[data-slide]');
|
|
98
|
-
if (!line) return;
|
|
99
|
-
this.app.selectSlide(Number(line.dataset.slide));
|
|
100
|
-
if (line.dataset.obj) this.app.startEditingById(line.dataset.obj);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setView(view) {
|
|
105
|
-
this.view = view;
|
|
106
|
-
for (const btn of this.tabButtons) btn.classList.toggle('is-active', btn.dataset.tab === view);
|
|
107
|
-
this.el.querySelector('.pp-thumbs').hidden = view !== 'slides';
|
|
108
|
-
this.el.querySelector('.pp-outline').hidden = view !== 'outline';
|
|
109
|
-
if (view === 'outline') this.renderOutline();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
render() {
|
|
113
|
-
this.renderThumbs();
|
|
114
|
-
if (this.view === 'outline') this.renderOutline();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
renderThumbs() {
|
|
118
|
-
const { slides } = this.app.snapshot;
|
|
119
|
-
const theme = this.app.snapshot.theme;
|
|
120
|
-
const size = this.app.size;
|
|
121
|
-
this.thumbsEl.replaceChildren();
|
|
122
|
-
slides.forEach((slide, i) => {
|
|
123
|
-
const thumb = document.createElement('div');
|
|
124
|
-
thumb.className = `pp-thumb${i === this.app.index ? ' is-active' : ''}${slide.hidden ? ' is-hidden' : ''}`;
|
|
125
|
-
thumb.dataset.index = String(i);
|
|
126
|
-
thumb.draggable = true;
|
|
127
|
-
const no = document.createElement('div');
|
|
128
|
-
no.className = 'pp-thumb__no';
|
|
129
|
-
no.textContent = String(i + 1);
|
|
130
|
-
const box = document.createElement('div');
|
|
131
|
-
box.className = 'pp-thumb__box';
|
|
132
|
-
box.style.paddingBottom = `${(size.h / size.w) * 100}%`;
|
|
133
|
-
const page = renderPage(slide, theme, { size });
|
|
134
|
-
page.style.transform = `scale(${THUMB_W / size.w})`;
|
|
135
|
-
box.appendChild(page);
|
|
136
|
-
thumb.append(no, box);
|
|
137
|
-
if (slide.hidden) {
|
|
138
|
-
const flag = document.createElement('span');
|
|
139
|
-
flag.className = 'pp-thumb__flag pp-thumb__flag--hidden';
|
|
140
|
-
flag.innerHTML = icon('hide', 13);
|
|
141
|
-
thumb.appendChild(flag);
|
|
142
|
-
}
|
|
143
|
-
const tr = slide.transition || {};
|
|
144
|
-
if (tr.type && tr.type !== 'none') {
|
|
145
|
-
const flag = document.createElement('span');
|
|
146
|
-
flag.className = 'pp-thumb__flag pp-thumb__flag--transition';
|
|
147
|
-
flag.innerHTML = icon('transition', 13);
|
|
148
|
-
flag.title = `切换:${TRANSITIONS.find((t) => t.key === tr.type)?.label || tr.type}`;
|
|
149
|
-
thumb.appendChild(flag);
|
|
150
|
-
}
|
|
151
|
-
this.thumbsEl.appendChild(thumb);
|
|
152
|
-
});
|
|
153
|
-
this.scrollToActive();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
renderOutline() {
|
|
157
|
-
const { slides } = this.app.snapshot;
|
|
158
|
-
this.outlineEl.replaceChildren();
|
|
159
|
-
slides.forEach((slide, si) => {
|
|
160
|
-
const row = document.createElement('div');
|
|
161
|
-
row.className = 'pp-outline__slide';
|
|
162
|
-
const no = document.createElement('span');
|
|
163
|
-
no.className = 'pp-outline__no';
|
|
164
|
-
no.textContent = String(si + 1);
|
|
165
|
-
row.appendChild(no);
|
|
166
|
-
const texts = slide.objects.filter((o) => o.type === 'text');
|
|
167
|
-
if (texts.length === 0) {
|
|
168
|
-
const empty = document.createElement('span');
|
|
169
|
-
empty.className = 'pp-outline__empty';
|
|
170
|
-
empty.textContent = '(空白页)';
|
|
171
|
-
empty.dataset.slide = String(si);
|
|
172
|
-
row.appendChild(empty);
|
|
173
|
-
}
|
|
174
|
-
texts.forEach((o, ti) => {
|
|
175
|
-
const line = document.createElement('span');
|
|
176
|
-
line.className = `pp-outline__line${ti === 0 ? ' is-title' : ''}`;
|
|
177
|
-
line.dataset.slide = String(si);
|
|
178
|
-
line.dataset.obj = o.id;
|
|
179
|
-
line.textContent = htmlToPlain(o.props.html).replace(/\n+/g, ' / ') || '(空文本框)';
|
|
180
|
-
row.appendChild(line);
|
|
181
|
-
});
|
|
182
|
-
this.outlineEl.appendChild(row);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
scrollToActive() {
|
|
187
|
-
this.thumbsEl.querySelector('.pp-thumb.is-active')?.scrollIntoView({ block: 'nearest' });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
1
|
+
// [文件] gbpptx·幻灯片窗格 —— 缩略图/大纲双视图、拖拽排序、页操作入口
|
|
2
|
+
|
|
3
|
+
import { SLIDE_LAYOUTS, TRANSITIONS, htmlToPlain } from '../../../src/kernel/model.js';
|
|
4
|
+
import { renderPage } from './page-view.js';
|
|
5
|
+
import { icon } from './icons.js';
|
|
6
|
+
import { openMenu } from './menu.js';
|
|
7
|
+
|
|
8
|
+
const THUMB_W = 164;
|
|
9
|
+
|
|
10
|
+
export class SlidePane {
|
|
11
|
+
constructor(app) {
|
|
12
|
+
this.app = app;
|
|
13
|
+
this.el = document.createElement('aside');
|
|
14
|
+
this.el.className = 'pp-slidepane';
|
|
15
|
+
this.el.innerHTML = `
|
|
16
|
+
<div class="pp-slidepane__tabs">
|
|
17
|
+
<button type="button" class="pp-slidepane__tab gbp-is-active" data-tab="slides">幻灯片</button>
|
|
18
|
+
<button type="button" class="pp-slidepane__tab" data-tab="outline">大纲</button>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="pp-slidepane__body">
|
|
21
|
+
<div class="pp-thumbs" data-view="slides"></div>
|
|
22
|
+
<div class="pp-outline" data-view="outline" hidden></div>
|
|
23
|
+
</div>
|
|
24
|
+
<div class="pp-slidepane__foot">
|
|
25
|
+
<button type="button" class="pp-slidepane__new" data-act="new">${icon('newSlide', 18)}<span>新建幻灯片</span></button>
|
|
26
|
+
<button type="button" class="pp-slidepane__layout" data-act="layout" title="选择版式">${icon('chevronDown', 14)}</button>
|
|
27
|
+
</div>`;
|
|
28
|
+
this.thumbsEl = this.el.querySelector('.pp-thumbs');
|
|
29
|
+
this.outlineEl = this.el.querySelector('.pp-outline');
|
|
30
|
+
this.tabButtons = [...this.el.querySelectorAll('[data-tab]')];
|
|
31
|
+
this.view = 'slides';
|
|
32
|
+
this.bind();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
bind() {
|
|
36
|
+
for (const btn of this.tabButtons) {
|
|
37
|
+
btn.addEventListener('click', () => this.setView(btn.dataset.tab));
|
|
38
|
+
}
|
|
39
|
+
this.el.querySelector('[data-act="new"]').addEventListener('click', () => this.app.addSlide());
|
|
40
|
+
this.el.querySelector('[data-act="layout"]').addEventListener('click', (e) => {
|
|
41
|
+
openMenu({
|
|
42
|
+
anchor: e.currentTarget,
|
|
43
|
+
placement: 'top-end',
|
|
44
|
+
items: SLIDE_LAYOUTS.map((l) => ({ label: l.label, onClick: () => this.app.addSlide(l.key) })),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
this.thumbsEl.addEventListener('click', (e) => {
|
|
48
|
+
const thumb = e.target.closest('.pp-thumb');
|
|
49
|
+
if (thumb) this.app.selectSlide(Number(thumb.dataset.index));
|
|
50
|
+
});
|
|
51
|
+
this.thumbsEl.addEventListener('dblclick', (e) => {
|
|
52
|
+
const thumb = e.target.closest('.pp-thumb');
|
|
53
|
+
if (thumb) this.app.presentAt(Number(thumb.dataset.index));
|
|
54
|
+
});
|
|
55
|
+
this.thumbsEl.addEventListener('contextmenu', (e) => {
|
|
56
|
+
const thumb = e.target.closest('.pp-thumb');
|
|
57
|
+
if (!thumb) return;
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
this.app.selectSlide(Number(thumb.dataset.index));
|
|
60
|
+
this.app.openSlideMenu(e.clientX, e.clientY, Number(thumb.dataset.index));
|
|
61
|
+
});
|
|
62
|
+
this.thumbsEl.addEventListener('dragstart', (e) => {
|
|
63
|
+
const thumb = e.target.closest('.pp-thumb');
|
|
64
|
+
if (!thumb) return;
|
|
65
|
+
this.dragIndex = Number(thumb.dataset.index);
|
|
66
|
+
thumb.classList.add('gbp-is-dragging');
|
|
67
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
68
|
+
e.dataTransfer.setData('text/plain', String(this.dragIndex));
|
|
69
|
+
});
|
|
70
|
+
this.thumbsEl.addEventListener('dragend', () => {
|
|
71
|
+
this.dragIndex = null;
|
|
72
|
+
this.thumbsEl.querySelectorAll('.gbp-is-dragging, .gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-dragging', 'gbp-is-drop'));
|
|
73
|
+
});
|
|
74
|
+
this.thumbsEl.addEventListener('dragover', (e) => {
|
|
75
|
+
const thumb = e.target.closest('.pp-thumb');
|
|
76
|
+
if (!thumb || this.dragIndex === null) return;
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
this.thumbsEl.querySelectorAll('.gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-drop'));
|
|
79
|
+
thumb.classList.add('gbp-is-drop');
|
|
80
|
+
});
|
|
81
|
+
this.thumbsEl.addEventListener('drop', (e) => {
|
|
82
|
+
const thumb = e.target.closest('.pp-thumb');
|
|
83
|
+
if (!thumb || this.dragIndex === null) return;
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
const to = Number(thumb.dataset.index);
|
|
86
|
+
this.thumbsEl.querySelectorAll('.gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-drop'));
|
|
87
|
+
if (to !== this.dragIndex) this.app.moveSlideTo(this.dragIndex, to);
|
|
88
|
+
this.dragIndex = null;
|
|
89
|
+
});
|
|
90
|
+
this.outlineEl.addEventListener('click', (e) => {
|
|
91
|
+
const line = e.target.closest('[data-slide]');
|
|
92
|
+
if (!line) return;
|
|
93
|
+
this.app.selectSlide(Number(line.dataset.slide));
|
|
94
|
+
if (line.dataset.obj) this.app.selectObjects([line.dataset.obj]);
|
|
95
|
+
});
|
|
96
|
+
this.outlineEl.addEventListener('dblclick', (e) => {
|
|
97
|
+
const line = e.target.closest('[data-slide]');
|
|
98
|
+
if (!line) return;
|
|
99
|
+
this.app.selectSlide(Number(line.dataset.slide));
|
|
100
|
+
if (line.dataset.obj) this.app.startEditingById(line.dataset.obj);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setView(view) {
|
|
105
|
+
this.view = view;
|
|
106
|
+
for (const btn of this.tabButtons) btn.classList.toggle('gbp-is-active', btn.dataset.tab === view);
|
|
107
|
+
this.el.querySelector('.pp-thumbs').hidden = view !== 'slides';
|
|
108
|
+
this.el.querySelector('.pp-outline').hidden = view !== 'outline';
|
|
109
|
+
if (view === 'outline') this.renderOutline();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render() {
|
|
113
|
+
this.renderThumbs();
|
|
114
|
+
if (this.view === 'outline') this.renderOutline();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
renderThumbs() {
|
|
118
|
+
const { slides } = this.app.snapshot;
|
|
119
|
+
const theme = this.app.snapshot.theme;
|
|
120
|
+
const size = this.app.size;
|
|
121
|
+
this.thumbsEl.replaceChildren();
|
|
122
|
+
slides.forEach((slide, i) => {
|
|
123
|
+
const thumb = document.createElement('div');
|
|
124
|
+
thumb.className = `pp-thumb${i === this.app.index ? ' gbp-is-active' : ''}${slide.hidden ? ' gbp-is-hidden' : ''}`;
|
|
125
|
+
thumb.dataset.index = String(i);
|
|
126
|
+
thumb.draggable = true;
|
|
127
|
+
const no = document.createElement('div');
|
|
128
|
+
no.className = 'pp-thumb__no';
|
|
129
|
+
no.textContent = String(i + 1);
|
|
130
|
+
const box = document.createElement('div');
|
|
131
|
+
box.className = 'pp-thumb__box';
|
|
132
|
+
box.style.paddingBottom = `${(size.h / size.w) * 100}%`;
|
|
133
|
+
const page = renderPage(slide, theme, { size });
|
|
134
|
+
page.style.transform = `scale(${THUMB_W / size.w})`;
|
|
135
|
+
box.appendChild(page);
|
|
136
|
+
thumb.append(no, box);
|
|
137
|
+
if (slide.hidden) {
|
|
138
|
+
const flag = document.createElement('span');
|
|
139
|
+
flag.className = 'pp-thumb__flag pp-thumb__flag--hidden';
|
|
140
|
+
flag.innerHTML = icon('hide', 13);
|
|
141
|
+
thumb.appendChild(flag);
|
|
142
|
+
}
|
|
143
|
+
const tr = slide.transition || {};
|
|
144
|
+
if (tr.type && tr.type !== 'none') {
|
|
145
|
+
const flag = document.createElement('span');
|
|
146
|
+
flag.className = 'pp-thumb__flag pp-thumb__flag--transition';
|
|
147
|
+
flag.innerHTML = icon('transition', 13);
|
|
148
|
+
flag.title = `切换:${TRANSITIONS.find((t) => t.key === tr.type)?.label || tr.type}`;
|
|
149
|
+
thumb.appendChild(flag);
|
|
150
|
+
}
|
|
151
|
+
this.thumbsEl.appendChild(thumb);
|
|
152
|
+
});
|
|
153
|
+
this.scrollToActive();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
renderOutline() {
|
|
157
|
+
const { slides } = this.app.snapshot;
|
|
158
|
+
this.outlineEl.replaceChildren();
|
|
159
|
+
slides.forEach((slide, si) => {
|
|
160
|
+
const row = document.createElement('div');
|
|
161
|
+
row.className = 'pp-outline__slide';
|
|
162
|
+
const no = document.createElement('span');
|
|
163
|
+
no.className = 'pp-outline__no';
|
|
164
|
+
no.textContent = String(si + 1);
|
|
165
|
+
row.appendChild(no);
|
|
166
|
+
const texts = slide.objects.filter((o) => o.type === 'text');
|
|
167
|
+
if (texts.length === 0) {
|
|
168
|
+
const empty = document.createElement('span');
|
|
169
|
+
empty.className = 'pp-outline__empty';
|
|
170
|
+
empty.textContent = '(空白页)';
|
|
171
|
+
empty.dataset.slide = String(si);
|
|
172
|
+
row.appendChild(empty);
|
|
173
|
+
}
|
|
174
|
+
texts.forEach((o, ti) => {
|
|
175
|
+
const line = document.createElement('span');
|
|
176
|
+
line.className = `pp-outline__line${ti === 0 ? ' gbp-is-title' : ''}`;
|
|
177
|
+
line.dataset.slide = String(si);
|
|
178
|
+
line.dataset.obj = o.id;
|
|
179
|
+
line.textContent = htmlToPlain(o.props.html).replace(/\n+/g, ' / ') || '(空文本框)';
|
|
180
|
+
row.appendChild(line);
|
|
181
|
+
});
|
|
182
|
+
this.outlineEl.appendChild(row);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
scrollToActive() {
|
|
187
|
+
this.thumbsEl.querySelector('.pp-thumb.gbp-is-active')?.scrollIntoView({ block: 'nearest' });
|
|
188
|
+
}
|
|
189
|
+
}
|
package/web/app/ui/statusbar.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
// [文件] gbpptx·状态栏 —— 页数/语言/备注 + 视图切换 + 缩放滑块(Office 式)
|
|
2
|
-
|
|
3
|
-
import { icon } from './icons.js';
|
|
4
|
-
import { openMenu } from './menu.js';
|
|
5
|
-
|
|
6
|
-
const el = (tag, cls, text) => {
|
|
7
|
-
const node = document.createElement(tag);
|
|
8
|
-
if (cls) node.className = cls;
|
|
9
|
-
if (text != null) node.textContent = text;
|
|
10
|
-
return node;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class StatusBar {
|
|
14
|
-
constructor(app) {
|
|
15
|
-
this.app = app;
|
|
16
|
-
this.el = el('footer', 'pp-statusbar');
|
|
17
|
-
this.build();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
build() {
|
|
21
|
-
const left = el('div', 'pp-statusbar__left');
|
|
22
|
-
this.infoEl = el('span', 'pp-statusbar__text');
|
|
23
|
-
this.statusEl = el('span', 'pp-statusbar__status');
|
|
24
|
-
const lang = el('span', 'pp-statusbar__text', '中文(中国)');
|
|
25
|
-
this.notesBtn = el('button', 'pp-statusbar__btn', '备注');
|
|
26
|
-
this.notesBtn.type = 'button';
|
|
27
|
-
this.notesBtn.addEventListener('click', () => this.app.toggleNotes());
|
|
28
|
-
left.append(this.infoEl, lang, this.statusEl, this.notesBtn);
|
|
29
|
-
|
|
30
|
-
const right = el('div', 'pp-statusbar__right');
|
|
31
|
-
const views = el('div', 'pp-statusbar__views');
|
|
32
|
-
this.viewButtons = {};
|
|
33
|
-
for (const [key, iconName, title] of [
|
|
34
|
-
['normal', 'viewNormal', '普通视图'],
|
|
35
|
-
['sorter', 'viewSorter', '幻灯片浏览'],
|
|
36
|
-
['reading', 'viewReading', '阅读视图'],
|
|
37
|
-
]) {
|
|
38
|
-
const b = el('button', 'pp-statusbar__view');
|
|
39
|
-
b.type = 'button';
|
|
40
|
-
b.title = title;
|
|
41
|
-
b.innerHTML = icon(iconName, 16);
|
|
42
|
-
b.addEventListener('click', () => this.app.setView(key));
|
|
43
|
-
this.viewButtons[key] = b;
|
|
44
|
-
views.appendChild(b);
|
|
45
|
-
}
|
|
46
|
-
const zoomOut = el('button', 'pp-statusbar__zoombtn');
|
|
47
|
-
zoomOut.type = 'button';
|
|
48
|
-
zoomOut.title = '缩小';
|
|
49
|
-
zoomOut.innerHTML = icon('minus', 14);
|
|
50
|
-
zoomOut.addEventListener('click', () => this.app.setZoom(this.app.zoom - 10));
|
|
51
|
-
this.slider = el('input', 'pp-statusbar__slider');
|
|
52
|
-
this.slider.type = 'range';
|
|
53
|
-
this.slider.min = '20';
|
|
54
|
-
this.slider.max = '400';
|
|
55
|
-
this.slider.step = '5';
|
|
56
|
-
this.slider.addEventListener('input', () => this.app.setZoom(Number(this.slider.value), { fromSlider: true }));
|
|
57
|
-
const zoomIn = el('button', 'pp-statusbar__zoombtn');
|
|
58
|
-
zoomIn.type = 'button';
|
|
59
|
-
zoomIn.title = '放大';
|
|
60
|
-
zoomIn.innerHTML = icon('plus', 14);
|
|
61
|
-
zoomIn.addEventListener('click', () => this.app.setZoom(this.app.zoom + 10));
|
|
62
|
-
this.zoomText = el('button', 'pp-statusbar__zoomtext', '100%');
|
|
63
|
-
this.zoomText.type = 'button';
|
|
64
|
-
this.zoomText.title = '缩放';
|
|
65
|
-
this.zoomText.addEventListener('click', () => openMenu({
|
|
66
|
-
anchor: this.zoomText,
|
|
67
|
-
placement: 'top-end',
|
|
68
|
-
items: [50, 75, 100, 125, 150, 200, 400].map((z) => ({ label: `${z}%`, checked: this.app.zoom === z, onClick: () => this.app.setZoom(z) }))
|
|
69
|
-
.concat([{ divided: true }, { label: '适应窗口', onClick: () => this.app.fitToWindow() }]),
|
|
70
|
-
}));
|
|
71
|
-
const fit = el('button', 'pp-statusbar__zoombtn');
|
|
72
|
-
fit.type = 'button';
|
|
73
|
-
fit.title = '适应窗口';
|
|
74
|
-
fit.innerHTML = icon('fitWindow', 15);
|
|
75
|
-
fit.addEventListener('click', () => this.app.fitToWindow());
|
|
76
|
-
right.append(views, zoomOut, this.slider, zoomIn, this.zoomText, fit);
|
|
77
|
-
|
|
78
|
-
this.el.append(left, right);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
refresh() {
|
|
82
|
-
const app = this.app;
|
|
83
|
-
this.infoEl.textContent = `幻灯片 ${app.index + 1} / ${app.snapshot.slides.length}`;
|
|
84
|
-
this.notesBtn.classList.toggle('is-active', app.notesVisible);
|
|
85
|
-
for (const [key, b] of Object.entries(this.viewButtons)) b.classList.toggle('is-active', app.view === key);
|
|
86
|
-
this.zoomText.textContent = `${app.zoom}%`;
|
|
87
|
-
if (document.activeElement !== this.slider) this.slider.value = String(app.zoom);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
setStatus(text) {
|
|
91
|
-
this.statusEl.textContent = text || '';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
1
|
+
// [文件] gbpptx·状态栏 —— 页数/语言/备注 + 视图切换 + 缩放滑块(Office 式)
|
|
2
|
+
|
|
3
|
+
import { icon } from './icons.js';
|
|
4
|
+
import { openMenu } from './menu.js';
|
|
5
|
+
|
|
6
|
+
const el = (tag, cls, text) => {
|
|
7
|
+
const node = document.createElement(tag);
|
|
8
|
+
if (cls) node.className = cls;
|
|
9
|
+
if (text != null) node.textContent = text;
|
|
10
|
+
return node;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class StatusBar {
|
|
14
|
+
constructor(app) {
|
|
15
|
+
this.app = app;
|
|
16
|
+
this.el = el('footer', 'pp-statusbar');
|
|
17
|
+
this.build();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
build() {
|
|
21
|
+
const left = el('div', 'pp-statusbar__left');
|
|
22
|
+
this.infoEl = el('span', 'pp-statusbar__text');
|
|
23
|
+
this.statusEl = el('span', 'pp-statusbar__status');
|
|
24
|
+
const lang = el('span', 'pp-statusbar__text', '中文(中国)');
|
|
25
|
+
this.notesBtn = el('button', 'pp-statusbar__btn', '备注');
|
|
26
|
+
this.notesBtn.type = 'button';
|
|
27
|
+
this.notesBtn.addEventListener('click', () => this.app.toggleNotes());
|
|
28
|
+
left.append(this.infoEl, lang, this.statusEl, this.notesBtn);
|
|
29
|
+
|
|
30
|
+
const right = el('div', 'pp-statusbar__right');
|
|
31
|
+
const views = el('div', 'pp-statusbar__views');
|
|
32
|
+
this.viewButtons = {};
|
|
33
|
+
for (const [key, iconName, title] of [
|
|
34
|
+
['normal', 'viewNormal', '普通视图'],
|
|
35
|
+
['sorter', 'viewSorter', '幻灯片浏览'],
|
|
36
|
+
['reading', 'viewReading', '阅读视图'],
|
|
37
|
+
]) {
|
|
38
|
+
const b = el('button', 'pp-statusbar__view');
|
|
39
|
+
b.type = 'button';
|
|
40
|
+
b.title = title;
|
|
41
|
+
b.innerHTML = icon(iconName, 16);
|
|
42
|
+
b.addEventListener('click', () => this.app.setView(key));
|
|
43
|
+
this.viewButtons[key] = b;
|
|
44
|
+
views.appendChild(b);
|
|
45
|
+
}
|
|
46
|
+
const zoomOut = el('button', 'pp-statusbar__zoombtn');
|
|
47
|
+
zoomOut.type = 'button';
|
|
48
|
+
zoomOut.title = '缩小';
|
|
49
|
+
zoomOut.innerHTML = icon('minus', 14);
|
|
50
|
+
zoomOut.addEventListener('click', () => this.app.setZoom(this.app.zoom - 10));
|
|
51
|
+
this.slider = el('input', 'pp-statusbar__slider');
|
|
52
|
+
this.slider.type = 'range';
|
|
53
|
+
this.slider.min = '20';
|
|
54
|
+
this.slider.max = '400';
|
|
55
|
+
this.slider.step = '5';
|
|
56
|
+
this.slider.addEventListener('input', () => this.app.setZoom(Number(this.slider.value), { fromSlider: true }));
|
|
57
|
+
const zoomIn = el('button', 'pp-statusbar__zoombtn');
|
|
58
|
+
zoomIn.type = 'button';
|
|
59
|
+
zoomIn.title = '放大';
|
|
60
|
+
zoomIn.innerHTML = icon('plus', 14);
|
|
61
|
+
zoomIn.addEventListener('click', () => this.app.setZoom(this.app.zoom + 10));
|
|
62
|
+
this.zoomText = el('button', 'pp-statusbar__zoomtext', '100%');
|
|
63
|
+
this.zoomText.type = 'button';
|
|
64
|
+
this.zoomText.title = '缩放';
|
|
65
|
+
this.zoomText.addEventListener('click', () => openMenu({
|
|
66
|
+
anchor: this.zoomText,
|
|
67
|
+
placement: 'top-end',
|
|
68
|
+
items: [50, 75, 100, 125, 150, 200, 400].map((z) => ({ label: `${z}%`, checked: this.app.zoom === z, onClick: () => this.app.setZoom(z) }))
|
|
69
|
+
.concat([{ divided: true }, { label: '适应窗口', onClick: () => this.app.fitToWindow() }]),
|
|
70
|
+
}));
|
|
71
|
+
const fit = el('button', 'pp-statusbar__zoombtn');
|
|
72
|
+
fit.type = 'button';
|
|
73
|
+
fit.title = '适应窗口';
|
|
74
|
+
fit.innerHTML = icon('fitWindow', 15);
|
|
75
|
+
fit.addEventListener('click', () => this.app.fitToWindow());
|
|
76
|
+
right.append(views, zoomOut, this.slider, zoomIn, this.zoomText, fit);
|
|
77
|
+
|
|
78
|
+
this.el.append(left, right);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
refresh() {
|
|
82
|
+
const app = this.app;
|
|
83
|
+
this.infoEl.textContent = `幻灯片 ${app.index + 1} / ${app.snapshot.slides.length}`;
|
|
84
|
+
this.notesBtn.classList.toggle('gbp-is-active', app.notesVisible);
|
|
85
|
+
for (const [key, b] of Object.entries(this.viewButtons)) b.classList.toggle('gbp-is-active', app.view === key);
|
|
86
|
+
this.zoomText.textContent = `${app.zoom}%`;
|
|
87
|
+
if (document.activeElement !== this.slider) this.slider.value = String(app.zoom);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setStatus(text) {
|
|
91
|
+
this.statusEl.textContent = text || '';
|
|
92
|
+
}
|
|
93
|
+
}
|