gbpptx 0.1.0 → 0.2.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.
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,101 @@
1
+ // [文件] gbpptx·标题栏 —— Office 快速访问工具栏 + 文档名/保存状态 + 自动保存与设置
2
+
3
+ import { icon } from './icons.js';
4
+ import { openMenu } from './menu.js';
5
+ import { openModal } from './dialogs.js';
6
+
7
+ const el = (tag, cls, text) => {
8
+ const node = document.createElement(tag);
9
+ if (cls) node.className = cls;
10
+ if (text != null) node.textContent = text;
11
+ return node;
12
+ };
13
+
14
+ export class TitleBar {
15
+ constructor(app) {
16
+ this.app = app;
17
+ this.el = el('header', 'pp-titlebar');
18
+ this.build();
19
+ }
20
+
21
+ build() {
22
+ const appIcon = el('span', 'pp-titlebar__app');
23
+ appIcon.innerHTML = icon('logo', 18);
24
+ appIcon.title = '挂逼演示';
25
+ const qa = el('div', 'pp-titlebar__qa');
26
+ this.saveBtn = this.tool('save', '保存 (Ctrl+S)', () => this.app.save());
27
+ this.undoBtn = this.tool('undo', '撤销 (Ctrl+Z)', () => this.app.undo());
28
+ this.redoBtn = this.tool('redo', '重做 (Ctrl+Y)', () => this.app.redo());
29
+ const playBtn = this.tool('play', '从头开始放映 (F5)', () => this.app.presentFromStart());
30
+ qa.append(this.saveBtn, this.undoBtn, this.redoBtn, playBtn);
31
+
32
+ const doc = el('div', 'pp-titlebar__doc');
33
+ this.nameEl = el('span', 'pp-titlebar__name', '新建演示');
34
+ this.stateEl = el('span', 'pp-titlebar__state', '已保存');
35
+ doc.append(this.nameEl, this.stateEl);
36
+
37
+ const right = el('div', 'pp-titlebar__right');
38
+ this.autosaveBtn = el('button', 'pp-titlebar__auto');
39
+ this.autosaveBtn.type = 'button';
40
+ this.autosaveBtn.title = '自动保存(需要已关联本地文件)';
41
+ this.autosaveBtn.innerHTML = '<span class="pp-switch"><i></i></span><span>自动保存</span>';
42
+ this.autosaveBtn.addEventListener('click', () => this.app.setAutosave(!this.app.autosave));
43
+ const settings = this.tool('more', '设置', () => this.openSettings(settings));
44
+ right.append(this.autosaveBtn, settings);
45
+
46
+ this.el.append(appIcon, qa, doc, right);
47
+ }
48
+
49
+ tool(name, title, onClick) {
50
+ const b = el('button', 'pp-titlebar__tool');
51
+ b.type = 'button';
52
+ b.title = title;
53
+ b.innerHTML = icon(name, 16);
54
+ b.addEventListener('click', onClick);
55
+ return b;
56
+ }
57
+
58
+ openSettings(anchor) {
59
+ const app = this.app;
60
+ openMenu({
61
+ anchor,
62
+ placement: 'bottom-end',
63
+ items: [
64
+ { header: '显示' },
65
+ { label: '网格线', checked: app.gridVisible, onClick: () => app.toggleGrid() },
66
+ { label: '参考线', checked: app.guidesVisible, onClick: () => app.toggleGuides() },
67
+ { label: '备注', checked: app.notesVisible, onClick: () => app.toggleNotes() },
68
+ { label: '设置形状格式窗格', checked: app.formatPaneOpen, onClick: () => app.toggleFormatPane() },
69
+ { divided: true },
70
+ { label: '演讲者视图', checked: app.presentOptions.presenter, onClick: () => app.togglePresenter() },
71
+ { label: '循环放映', checked: app.presentOptions.loop, onClick: () => app.toggleLoop() },
72
+ { divided: true },
73
+ { label: '自动保存', checked: app.autosave, onClick: () => app.setAutosave(!app.autosave) },
74
+ { label: '关于挂逼演示…', onClick: () => openModal({
75
+ title: '关于',
76
+ width: 400,
77
+ confirmText: '知道了',
78
+ build: (body) => {
79
+ const p = el('div', 'pp-about');
80
+ p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-backstage__muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
81
+ body.appendChild(p);
82
+ },
83
+ }) },
84
+ ],
85
+ });
86
+ }
87
+
88
+ refresh() {
89
+ const app = this.app;
90
+ this.nameEl.textContent = app.doc.name || '新建演示';
91
+ document.title = `${this.nameEl.textContent} - 挂逼演示`;
92
+ this.stateEl.textContent = app.dirty
93
+ ? '未保存的更改'
94
+ : app.doc.handle ? '已保存到本地' : (app.doc.savedAt ? '已保存副本' : '尚未保存');
95
+ this.stateEl.classList.toggle('is-dirty', app.dirty);
96
+ this.saveBtn.disabled = !app.snapshot.slides.length;
97
+ this.undoBtn.disabled = !app.canUndo();
98
+ this.redoBtn.disabled = !app.canRedo();
99
+ this.autosaveBtn.classList.toggle('is-active', app.autosave);
100
+ }
101
+ }
@@ -0,0 +1,30 @@
1
+ // [文件] gbpptx·切换动画 —— 放映与画布预览共用同一套 CSS 动画口径
2
+
3
+ const SPEED_MS = { fast: 500, med: 800, slow: 1500 };
4
+
5
+ /**
6
+ * 对「刚进入的页容器」播放切换动画
7
+ * @param {HTMLElement} wrap 承载页面的容器
8
+ * @param {{type:string,dir:string,speed:string}} tr
9
+ */
10
+ export function animateSlideFrame(wrap, tr) {
11
+ if (!wrap || !tr || tr.type === 'none') return;
12
+ const dur = SPEED_MS[tr.speed] || SPEED_MS.med;
13
+ const dir = tr.dir || 'l';
14
+ const tx = dir === 'l' ? '60px' : dir === 'r' ? '-60px' : '0';
15
+ const ty = dir === 'u' ? '60px' : dir === 'd' ? '-60px' : '0';
16
+ const easing = 'cubic-bezier(.2,.7,.2,1)';
17
+ if (tr.type === 'wipe') {
18
+ const from = dir === 'r' ? 'inset(0 0 0 100%)' : dir === 'u' ? 'inset(100% 0 0 0)' : dir === 'd' ? 'inset(0 0 100% 0)' : 'inset(0 100% 0 0)';
19
+ wrap.animate([{ clipPath: from }, { clipPath: 'inset(0 0 0 0)' }], { duration: dur, easing });
20
+ return;
21
+ }
22
+ if (tr.type === 'split') {
23
+ wrap.animate([{ clipPath: 'inset(0 50% 0 50%)' }, { clipPath: 'inset(0 0 0 0)' }], { duration: dur, easing });
24
+ return;
25
+ }
26
+ let frames = [{ opacity: 0 }, { opacity: 1 }];
27
+ if (tr.type === 'push' || tr.type === 'cover') frames = [{ transform: `translate(${tx}, ${ty})` }, { transform: 'translate(0, 0)' }];
28
+ if (tr.type === 'zoom') frames = [{ opacity: 0, transform: 'scale(1.08)' }, { opacity: 1, transform: 'scale(1)' }];
29
+ wrap.animate(frames, { duration: dur, easing, fill: 'both' });
30
+ }
package/web/index.html CHANGED
@@ -6,6 +6,7 @@
6
6
  <title>挂逼演示 gbpptx</title>
7
7
  <link rel="stylesheet" href="/web/styles/tokens.css" />
8
8
  <link rel="stylesheet" href="/web/styles/slides.css" />
9
+ <link rel="stylesheet" href="/web/styles/office.css" />
9
10
  <script type="importmap">
10
11
  {
11
12
  "imports": {
package/web/serve.mjs CHANGED
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';
8
8
  const WEB_DIR = fileURLToPath(new URL('.', import.meta.url));
9
9
  const ROOT = normalize(join(WEB_DIR, '..'));
10
10
  // gbOoxml 真实位置:同仓本地包(本包唯一依赖)
11
- const OOXML_ROOT = normalize(join(ROOT, '..', 'gbOoxml', 'src'));
11
+ const OOXML_ROOT = normalize(join(ROOT, '..', 'gbooxml', 'src'));
12
12
  const PORT = Number(process.argv[2] || process.env.GBPPTX_PORT || 5274);
13
13
 
14
14
  const MIME = {