gbpptx 0.6.1 → 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.
Files changed (50) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +253 -253
  3. package/package.json +48 -47
  4. package/src/index.js +29 -29
  5. package/src/kernel/model.js +651 -651
  6. package/src/kernel/parts.js +173 -173
  7. package/src/kernel/pptx.js +72 -72
  8. package/src/kernel/print.js +76 -76
  9. package/src/kernel/read.js +1018 -1018
  10. package/src/kernel/roundtrip.js +174 -174
  11. package/src/kernel/text.js +278 -278
  12. package/src/kernel/write.js +385 -385
  13. package/web/app/main.js +8 -8
  14. package/web/app/slides/arrange.js +101 -101
  15. package/web/app/slides/clipboard.js +93 -93
  16. package/web/app/slides/file.js +240 -240
  17. package/web/app/slides/find.js +201 -201
  18. package/web/app/slides/history.js +100 -100
  19. package/web/app/slides/keys.js +187 -187
  20. package/web/app/slides/menus.js +105 -105
  21. package/web/app/slides/objects.js +254 -254
  22. package/web/app/slides/render.js +183 -183
  23. package/web/app/slides/shared.js +85 -85
  24. package/web/app/slides/slides.js +103 -103
  25. package/web/app/slides/table.js +102 -102
  26. package/web/app/slides/text.js +418 -418
  27. package/web/app/slides/view.js +182 -182
  28. package/web/app/slides-app.js +354 -354
  29. package/web/app/ui/canvas.js +769 -769
  30. package/web/app/ui/color-panel.js +58 -58
  31. package/web/app/ui/dialogs.js +120 -120
  32. package/web/app/ui/file-io.js +116 -116
  33. package/web/app/ui/format-pane.js +427 -427
  34. package/web/app/ui/icons.js +241 -133
  35. package/web/app/ui/menu.js +77 -75
  36. package/web/app/ui/notify.js +45 -45
  37. package/web/app/ui/page-view.js +221 -221
  38. package/web/app/ui/popup.js +80 -80
  39. package/web/app/ui/present.js +292 -292
  40. package/web/app/ui/ribbon.js +855 -855
  41. package/web/app/ui/slide-pane.js +197 -197
  42. package/web/app/ui/statusbar.js +93 -93
  43. package/web/app/ui/text-styles.js +84 -84
  44. package/web/app/ui/titlebar.js +253 -253
  45. package/web/app/ui/transition.js +30 -30
  46. package/web/index.html +30 -29
  47. package/web/serve.mjs +26 -23
  48. package/web/styles/office.css +463 -463
  49. package/web/styles/slides.css +97 -97
  50. package/web/styles/tokens.css +154 -154
@@ -1,197 +1,197 @@
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
- if (this.app.readOnly) return;
57
- const thumb = e.target.closest('.pp-thumb');
58
- if (!thumb) return;
59
- e.preventDefault();
60
- this.app.selectSlide(Number(thumb.dataset.index));
61
- this.app.openSlideMenu(e.clientX, e.clientY, Number(thumb.dataset.index));
62
- });
63
- this.thumbsEl.addEventListener('dragstart', (e) => {
64
- if (this.app.readOnly) return;
65
- const thumb = e.target.closest('.pp-thumb');
66
- if (!thumb) return;
67
- this.dragIndex = Number(thumb.dataset.index);
68
- thumb.classList.add('gbp-is-dragging');
69
- e.dataTransfer.effectAllowed = 'move';
70
- e.dataTransfer.setData('text/plain', String(this.dragIndex));
71
- });
72
- this.thumbsEl.addEventListener('dragend', () => {
73
- this.dragIndex = null;
74
- this.thumbsEl.querySelectorAll('.gbp-is-dragging, .gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-dragging', 'gbp-is-drop'));
75
- });
76
- this.thumbsEl.addEventListener('dragover', (e) => {
77
- const thumb = e.target.closest('.pp-thumb');
78
- if (!thumb || this.dragIndex === null) return;
79
- e.preventDefault();
80
- this.thumbsEl.querySelectorAll('.gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-drop'));
81
- thumb.classList.add('gbp-is-drop');
82
- });
83
- this.thumbsEl.addEventListener('drop', (e) => {
84
- if (this.app.readOnly) return;
85
- const thumb = e.target.closest('.pp-thumb');
86
- if (!thumb || this.dragIndex === null) return;
87
- e.preventDefault();
88
- const to = Number(thumb.dataset.index);
89
- this.thumbsEl.querySelectorAll('.gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-drop'));
90
- if (to !== this.dragIndex) this.app.moveSlideTo(this.dragIndex, to);
91
- this.dragIndex = null;
92
- });
93
- this.outlineEl.addEventListener('click', (e) => {
94
- const line = e.target.closest('[data-slide]');
95
- if (!line) return;
96
- this.app.selectSlide(Number(line.dataset.slide));
97
- if (line.dataset.obj) this.app.selectObjects([line.dataset.obj]);
98
- });
99
- this.outlineEl.addEventListener('dblclick', (e) => {
100
- if (this.app.readOnly) return;
101
- const line = e.target.closest('[data-slide]');
102
- if (!line) return;
103
- this.app.selectSlide(Number(line.dataset.slide));
104
- if (line.dataset.obj) this.app.startEditingById(line.dataset.obj);
105
- });
106
- }
107
-
108
- setView(view) {
109
- this.view = view;
110
- for (const btn of this.tabButtons) btn.classList.toggle('gbp-is-active', btn.dataset.tab === view);
111
- this.el.querySelector('.pp-thumbs').hidden = view !== 'slides';
112
- this.el.querySelector('.pp-outline').hidden = view !== 'outline';
113
- if (view === 'outline') this.renderOutline();
114
- }
115
-
116
- render() {
117
- // 只读档锁掉新建/版式入口;缩略图本身的选中、翻页、放映仍可用
118
- this.el.querySelectorAll('[data-act="new"], [data-act="layout"]').forEach((btn) => {
119
- btn.disabled = this.app.readOnly;
120
- });
121
- this.renderThumbs();
122
- if (this.view === 'outline') this.renderOutline();
123
- }
124
-
125
- renderThumbs() {
126
- const { slides } = this.app.snapshot;
127
- const theme = this.app.snapshot.theme;
128
- const size = this.app.size;
129
- this.thumbsEl.replaceChildren();
130
- slides.forEach((slide, i) => {
131
- const thumb = document.createElement('div');
132
- thumb.className = `pp-thumb${i === this.app.index ? ' gbp-is-active' : ''}${slide.hidden ? ' gbp-is-hidden' : ''}`;
133
- thumb.dataset.index = String(i);
134
- thumb.draggable = true;
135
- const no = document.createElement('div');
136
- no.className = 'pp-thumb__no';
137
- no.textContent = String(i + 1);
138
- const box = document.createElement('div');
139
- box.className = 'pp-thumb__box';
140
- box.style.paddingBottom = `${(size.h / size.w) * 100}%`;
141
- const page = renderPage(slide, theme, { size });
142
- page.style.transform = `scale(${THUMB_W / size.w})`;
143
- box.appendChild(page);
144
- thumb.append(no, box);
145
- if (slide.hidden) {
146
- const flag = document.createElement('span');
147
- flag.className = 'pp-thumb__flag pp-thumb__flag--hidden';
148
- flag.innerHTML = icon('hide', 13);
149
- thumb.appendChild(flag);
150
- }
151
- const tr = slide.transition || {};
152
- if (tr.type && tr.type !== 'none') {
153
- const flag = document.createElement('span');
154
- flag.className = 'pp-thumb__flag pp-thumb__flag--transition';
155
- flag.innerHTML = icon('transition', 13);
156
- flag.title = `切换:${TRANSITIONS.find((t) => t.key === tr.type)?.label || tr.type}`;
157
- thumb.appendChild(flag);
158
- }
159
- this.thumbsEl.appendChild(thumb);
160
- });
161
- this.scrollToActive();
162
- }
163
-
164
- renderOutline() {
165
- const { slides } = this.app.snapshot;
166
- this.outlineEl.replaceChildren();
167
- slides.forEach((slide, si) => {
168
- const row = document.createElement('div');
169
- row.className = 'pp-outline__slide';
170
- const no = document.createElement('span');
171
- no.className = 'pp-outline__no';
172
- no.textContent = String(si + 1);
173
- row.appendChild(no);
174
- const texts = slide.objects.filter((o) => o.type === 'text');
175
- if (texts.length === 0) {
176
- const empty = document.createElement('span');
177
- empty.className = 'pp-outline__empty';
178
- empty.textContent = '(空白页)';
179
- empty.dataset.slide = String(si);
180
- row.appendChild(empty);
181
- }
182
- texts.forEach((o, ti) => {
183
- const line = document.createElement('span');
184
- line.className = `pp-outline__line${ti === 0 ? ' gbp-is-title' : ''}`;
185
- line.dataset.slide = String(si);
186
- line.dataset.obj = o.id;
187
- line.textContent = htmlToPlain(o.props.html).replace(/\n+/g, ' / ') || '(空文本框)';
188
- row.appendChild(line);
189
- });
190
- this.outlineEl.appendChild(row);
191
- });
192
- }
193
-
194
- scrollToActive() {
195
- this.thumbsEl.querySelector('.pp-thumb.gbp-is-active')?.scrollIntoView({ block: 'nearest' });
196
- }
197
- }
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
+ if (this.app.readOnly) return;
57
+ const thumb = e.target.closest('.pp-thumb');
58
+ if (!thumb) return;
59
+ e.preventDefault();
60
+ this.app.selectSlide(Number(thumb.dataset.index));
61
+ this.app.openSlideMenu(e.clientX, e.clientY, Number(thumb.dataset.index));
62
+ });
63
+ this.thumbsEl.addEventListener('dragstart', (e) => {
64
+ if (this.app.readOnly) return;
65
+ const thumb = e.target.closest('.pp-thumb');
66
+ if (!thumb) return;
67
+ this.dragIndex = Number(thumb.dataset.index);
68
+ thumb.classList.add('gbp-is-dragging');
69
+ e.dataTransfer.effectAllowed = 'move';
70
+ e.dataTransfer.setData('text/plain', String(this.dragIndex));
71
+ });
72
+ this.thumbsEl.addEventListener('dragend', () => {
73
+ this.dragIndex = null;
74
+ this.thumbsEl.querySelectorAll('.gbp-is-dragging, .gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-dragging', 'gbp-is-drop'));
75
+ });
76
+ this.thumbsEl.addEventListener('dragover', (e) => {
77
+ const thumb = e.target.closest('.pp-thumb');
78
+ if (!thumb || this.dragIndex === null) return;
79
+ e.preventDefault();
80
+ this.thumbsEl.querySelectorAll('.gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-drop'));
81
+ thumb.classList.add('gbp-is-drop');
82
+ });
83
+ this.thumbsEl.addEventListener('drop', (e) => {
84
+ if (this.app.readOnly) return;
85
+ const thumb = e.target.closest('.pp-thumb');
86
+ if (!thumb || this.dragIndex === null) return;
87
+ e.preventDefault();
88
+ const to = Number(thumb.dataset.index);
89
+ this.thumbsEl.querySelectorAll('.gbp-is-drop').forEach((el) => el.classList.remove('gbp-is-drop'));
90
+ if (to !== this.dragIndex) this.app.moveSlideTo(this.dragIndex, to);
91
+ this.dragIndex = null;
92
+ });
93
+ this.outlineEl.addEventListener('click', (e) => {
94
+ const line = e.target.closest('[data-slide]');
95
+ if (!line) return;
96
+ this.app.selectSlide(Number(line.dataset.slide));
97
+ if (line.dataset.obj) this.app.selectObjects([line.dataset.obj]);
98
+ });
99
+ this.outlineEl.addEventListener('dblclick', (e) => {
100
+ if (this.app.readOnly) return;
101
+ const line = e.target.closest('[data-slide]');
102
+ if (!line) return;
103
+ this.app.selectSlide(Number(line.dataset.slide));
104
+ if (line.dataset.obj) this.app.startEditingById(line.dataset.obj);
105
+ });
106
+ }
107
+
108
+ setView(view) {
109
+ this.view = view;
110
+ for (const btn of this.tabButtons) btn.classList.toggle('gbp-is-active', btn.dataset.tab === view);
111
+ this.el.querySelector('.pp-thumbs').hidden = view !== 'slides';
112
+ this.el.querySelector('.pp-outline').hidden = view !== 'outline';
113
+ if (view === 'outline') this.renderOutline();
114
+ }
115
+
116
+ render() {
117
+ // 只读档锁掉新建/版式入口;缩略图本身的选中、翻页、放映仍可用
118
+ this.el.querySelectorAll('[data-act="new"], [data-act="layout"]').forEach((btn) => {
119
+ btn.disabled = this.app.readOnly;
120
+ });
121
+ this.renderThumbs();
122
+ if (this.view === 'outline') this.renderOutline();
123
+ }
124
+
125
+ renderThumbs() {
126
+ const { slides } = this.app.snapshot;
127
+ const theme = this.app.snapshot.theme;
128
+ const size = this.app.size;
129
+ this.thumbsEl.replaceChildren();
130
+ slides.forEach((slide, i) => {
131
+ const thumb = document.createElement('div');
132
+ thumb.className = `pp-thumb${i === this.app.index ? ' gbp-is-active' : ''}${slide.hidden ? ' gbp-is-hidden' : ''}`;
133
+ thumb.dataset.index = String(i);
134
+ thumb.draggable = true;
135
+ const no = document.createElement('div');
136
+ no.className = 'pp-thumb__no';
137
+ no.textContent = String(i + 1);
138
+ const box = document.createElement('div');
139
+ box.className = 'pp-thumb__box';
140
+ box.style.paddingBottom = `${(size.h / size.w) * 100}%`;
141
+ const page = renderPage(slide, theme, { size });
142
+ page.style.transform = `scale(${THUMB_W / size.w})`;
143
+ box.appendChild(page);
144
+ thumb.append(no, box);
145
+ if (slide.hidden) {
146
+ const flag = document.createElement('span');
147
+ flag.className = 'pp-thumb__flag pp-thumb__flag--hidden';
148
+ flag.innerHTML = icon('hide', 13);
149
+ thumb.appendChild(flag);
150
+ }
151
+ const tr = slide.transition || {};
152
+ if (tr.type && tr.type !== 'none') {
153
+ const flag = document.createElement('span');
154
+ flag.className = 'pp-thumb__flag pp-thumb__flag--transition';
155
+ flag.innerHTML = icon('transition', 13);
156
+ flag.title = `切换:${TRANSITIONS.find((t) => t.key === tr.type)?.label || tr.type}`;
157
+ thumb.appendChild(flag);
158
+ }
159
+ this.thumbsEl.appendChild(thumb);
160
+ });
161
+ this.scrollToActive();
162
+ }
163
+
164
+ renderOutline() {
165
+ const { slides } = this.app.snapshot;
166
+ this.outlineEl.replaceChildren();
167
+ slides.forEach((slide, si) => {
168
+ const row = document.createElement('div');
169
+ row.className = 'pp-outline__slide';
170
+ const no = document.createElement('span');
171
+ no.className = 'pp-outline__no';
172
+ no.textContent = String(si + 1);
173
+ row.appendChild(no);
174
+ const texts = slide.objects.filter((o) => o.type === 'text');
175
+ if (texts.length === 0) {
176
+ const empty = document.createElement('span');
177
+ empty.className = 'pp-outline__empty';
178
+ empty.textContent = '(空白页)';
179
+ empty.dataset.slide = String(si);
180
+ row.appendChild(empty);
181
+ }
182
+ texts.forEach((o, ti) => {
183
+ const line = document.createElement('span');
184
+ line.className = `pp-outline__line${ti === 0 ? ' gbp-is-title' : ''}`;
185
+ line.dataset.slide = String(si);
186
+ line.dataset.obj = o.id;
187
+ line.textContent = htmlToPlain(o.props.html).replace(/\n+/g, ' / ') || '(空文本框)';
188
+ row.appendChild(line);
189
+ });
190
+ this.outlineEl.appendChild(row);
191
+ });
192
+ }
193
+
194
+ scrollToActive() {
195
+ this.thumbsEl.querySelector('.pp-thumb.gbp-is-active')?.scrollIntoView({ block: 'nearest' });
196
+ }
197
+ }
@@ -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('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
- }
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
+ }