gbpptx 0.4.0 → 0.5.1

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/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "gbpptx",
3
- "version": "0.4.0",
4
- "description": "Office-style PowerPoint (pptx) editor: real PresentationML read/write, ribbon UI, slide sorter, presenter view.",
5
- "type": "module",
6
- "license": "MIT",
7
- "sideEffects": false,
8
- "main": "./src/index.js",
9
- "exports": {
10
- ".": "./src/index.js",
11
- "./model": "./src/kernel/model.js",
12
- "./pptx": "./src/kernel/pptx.js",
13
- "./package.json": "./package.json",
14
- "./web/*": "./web/*",
15
- "./*": "./src/*.js"
16
- },
17
- "files": [
18
- "src",
19
- "web",
20
- "LICENSE"
21
- ],
22
- "keywords": [
23
- "pptx",
24
- "presentation",
25
- "powerpoint",
26
- "ooxml",
27
- "slides",
28
- "editor",
29
- "office",
30
- "ribbon"
31
- ],
32
- "engines": {
33
- "node": ">=18"
34
- },
35
- "scripts": {
36
- "start": "node web/serve.mjs",
37
- "test": "node --test test/roundtrip.test.js test/external-import.test.js test/ui-zoom.test.js test/mode.test.js"
38
- },
39
- "dependencies": {
40
- "gbooxml": "^0.1.0",
41
- "gbofficeui": "^0.1.0",
42
- "guabiutils": "^0.3.0"
43
- },
44
- "devDependencies": {
45
- "jsdom": "^30.1.3"
46
- }
47
- }
1
+ {
2
+ "name": "gbpptx",
3
+ "version": "0.5.1",
4
+ "description": "Office-style PowerPoint (pptx) editor: real PresentationML read/write, ribbon UI, slide sorter, presenter view.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "main": "./src/index.js",
9
+ "exports": {
10
+ ".": "./src/index.js",
11
+ "./model": "./src/kernel/model.js",
12
+ "./pptx": "./src/kernel/pptx.js",
13
+ "./package.json": "./package.json",
14
+ "./web/*": "./web/*",
15
+ "./*": "./src/*.js"
16
+ },
17
+ "files": [
18
+ "src",
19
+ "web",
20
+ "LICENSE"
21
+ ],
22
+ "keywords": [
23
+ "pptx",
24
+ "presentation",
25
+ "powerpoint",
26
+ "ooxml",
27
+ "slides",
28
+ "editor",
29
+ "office",
30
+ "ribbon"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "scripts": {
36
+ "start": "node web/serve.mjs",
37
+ "test": "node --test test/roundtrip.test.js test/external-import.test.js test/ui-zoom.test.js test/mode.test.js"
38
+ },
39
+ "dependencies": {
40
+ "gbooxml": "^0.1.0",
41
+ "gbofficeui": "^0.1.0",
42
+ "guabiutils": "^0.3.0"
43
+ },
44
+ "devDependencies": {
45
+ "jsdom": "^30.1.3"
46
+ }
47
+ }
@@ -21,10 +21,18 @@ function bindGlobal() {
21
21
  this.onResizeBound = () => {
22
22
  if (this.view === 'reading') this.renderReading();
23
23
  };
24
+ this.onFullscreenEsc = (e) => {
25
+ if (e.key !== 'Escape' || !this.pageFullscreen) return;
26
+ // 放映中 Esc 归放映器;菜单/弹窗开着时也先交给它们
27
+ if (this.presenter?.el || document.querySelector('.gbp-popup, .gbp-modal-overlay, .gbp-menu')) return;
28
+ e.stopPropagation();
29
+ this.setPageFullscreen(false);
30
+ };
24
31
 
25
32
  document.addEventListener('keydown', this.onKeyBound);
26
33
  document.addEventListener('selectionchange', this.onSelectionChangeBound);
27
34
  document.addEventListener('paste', this.onPasteBound);
35
+ document.addEventListener('keydown', this.onFullscreenEsc, true);
28
36
  window.addEventListener('beforeunload', this.onBeforeUnloadBound);
29
37
  window.addEventListener('dragover', this.onDragOverBound);
30
38
  window.addEventListener('drop', this.onDropBound);
@@ -14,7 +14,7 @@ function setPreview(on) {
14
14
  this.previewRestore = { readOnly: this.readOnly, menuBar: this.menuBarVisible, view: this.view };
15
15
  this.preview = true;
16
16
  this.root.classList.add('gbp-is-preview');
17
- this.ribbon.setPreview(true);
17
+ this.titlebar.setPreview(true);
18
18
  this.commitEditing({ render: false });
19
19
  this.setView('reading');
20
20
  this.setReadOnly(true);
@@ -23,7 +23,7 @@ function setPreview(on) {
23
23
  const restore = this.previewRestore || { readOnly: false, menuBar: true, view: 'normal' };
24
24
  this.preview = false;
25
25
  this.root.classList.remove('gbp-is-preview');
26
- this.ribbon.setPreview(false);
26
+ this.titlebar.setPreview(false);
27
27
  this.setView(restore.view);
28
28
  this.setReadOnly(restore.readOnly);
29
29
  this.setMenuBarVisible(restore.menuBar);
@@ -124,6 +124,20 @@ function openFormatPane() {
124
124
  this.ribbon.refresh();
125
125
  }
126
126
 
127
+ /** 全屏/恢复:整个演示应用铺满网页(页面内覆盖;不用原生 Fullscreen,
128
+ * 否则 append 到 body 的菜单/弹窗在全屏层外不可见) */
129
+ function toggleFullscreen() {
130
+ this.setPageFullscreen(!this.pageFullscreen);
131
+ }
132
+
133
+ function setPageFullscreen(on) {
134
+ this.pageFullscreen = !!on;
135
+ this.root.classList.toggle('gbp-is-pagefullscreen', this.pageFullscreen);
136
+ if (this.pageFullscreen) document.addEventListener('keydown', this.onFullscreenEsc, true);
137
+ else document.removeEventListener('keydown', this.onFullscreenEsc, true);
138
+ this.titlebar?.refresh();
139
+ }
140
+
127
141
  function togglePresenter() {
128
142
  this.presentOptions.presenter = !this.presentOptions.presenter;
129
143
  this.prefs.presenter = this.presentOptions.presenter;
@@ -153,4 +167,4 @@ function presentAt(index) {
153
167
  this.presenter.open(Number(index) || 0);
154
168
  }
155
169
 
156
- export const viewMethods = { setView, setZoom, fitToWindow, toggleNotes, toggleGrid, toggleGuides, setRibbonCollapsed, toggleFormatPane, openFormatPane, togglePresenter, toggleLoop, presentFromStart, presentFromCurrent, presentAt, setPreview };
170
+ export const viewMethods = { setView, setZoom, fitToWindow, toggleNotes, toggleGrid, toggleGuides, setRibbonCollapsed, toggleFormatPane, openFormatPane, togglePresenter, toggleLoop, presentFromStart, presentFromCurrent, presentAt, setPreview, toggleFullscreen, setPageFullscreen };
@@ -56,7 +56,7 @@ export class SlidesApp {
56
56
  this.editing = null;
57
57
  this.tableCursor = null;
58
58
  this.notesSession = false;
59
- this.autosave = !!prefs.autosave;
59
+ this.autosave = options.autoSave !== undefined ? !!options.autoSave : !!prefs.autosave;
60
60
  this.notesVisible = prefs.notesVisible !== false;
61
61
  this.gridVisible = !!prefs.grid;
62
62
  this.guidesVisible = prefs.guides === true;
@@ -65,6 +65,7 @@ export class SlidesApp {
65
65
  this.view = 'normal';
66
66
  this.preview = false;
67
67
  this.previewRestore = null;
68
+ this.pageFullscreen = false;
68
69
  this.presentOptions = { presenter: !!prefs.presenter, loop: !!prefs.loop };
69
70
  this.lastBytes = null;
70
71
 
@@ -88,6 +89,7 @@ export class SlidesApp {
88
89
  build() {
89
90
  const root = el('div', 'pp-app');
90
91
  root.innerHTML = `
92
+ <div class="pp-head-host"></div>
91
93
  <div class="pp-topbar-host"></div>
92
94
  <div class="pp-ribbon-host"></div>
93
95
  <div class="pp-main">
@@ -108,6 +110,7 @@ export class SlidesApp {
108
110
  this.mount.appendChild(root);
109
111
  this.root = root;
110
112
  this.topbarHost = root.querySelector('.pp-topbar-host');
113
+ this.headHost = root.querySelector('.pp-head-host');
111
114
  this.ribbonHost = root.querySelector('.pp-ribbon-host');
112
115
  this.formatPaneHost = root.querySelector('.pp-main__right');
113
116
  this.left = root.querySelector('.pp-main__left');
@@ -125,6 +128,7 @@ export class SlidesApp {
125
128
  this.statusbar = new StatusBar(this);
126
129
 
127
130
  root.querySelector('.pp-topbar-host').appendChild(this.titlebar.el);
131
+ root.querySelector('.pp-head-host').appendChild(this.titlebar.headEl);
128
132
  root.querySelector('.pp-ribbon-host').appendChild(this.ribbon.el);
129
133
  this.left.appendChild(this.slidePane.el);
130
134
  this.canvasHost.appendChild(this.canvas.el);
@@ -140,7 +144,7 @@ export class SlidesApp {
140
144
  this.buildSorterEvents();
141
145
 
142
146
  this.bindNotes(root.querySelector('[data-act="notes-close"]'));
143
- // 只 inert 功能区与各选项卡本身:预览按钮同在选项卡行,必须保持可点
147
+ // 只 inert 功能区与各选项卡本身:文档头的预览按钮在 inert 之外,预览档里仍可点「退出预览」
144
148
  this.guard = createReadOnlyGuard(root, {
145
149
  editZones: () => [
146
150
  this.ribbon.bodyEl,
@@ -158,7 +162,7 @@ export class SlidesApp {
158
162
  if (this.readOnly) this.setReadOnly(true);
159
163
  }
160
164
 
161
- /** 显示/隐藏顶部菜单栏那一行(含同行文档名与保存按钮) */
165
+ /** 显示/隐藏顶部菜单栏那一行;文档头(标题/自动保存/保存/预览)不受影响 */
162
166
  setMenuBarVisible(on) {
163
167
  this.menuBarVisible = !!on;
164
168
  this.topbarHost.style.display = this.menuBarVisible ? '' : 'none';
@@ -257,6 +261,7 @@ export class SlidesApp {
257
261
  document.removeEventListener('keydown', this.onKeyBound);
258
262
  document.removeEventListener('paste', this.onPasteBound);
259
263
  document.removeEventListener('selectionchange', this.onSelectionChangeBound);
264
+ document.removeEventListener('keydown', this.onFullscreenEsc, true);
260
265
  window.removeEventListener('beforeunload', this.onBeforeUnloadBound);
261
266
  window.removeEventListener('dragover', this.onDragOverBound);
262
267
  window.removeEventListener('drop', this.onDropBound);
@@ -95,6 +95,8 @@ const BODY = {
95
95
  more: c(5, 12, 1.3) + c(12, 12, 1.3) + c(19, 12, 1.3),
96
96
  lock: r(5, 10, 14, 10, 2) + p('M8 10V7a4 4 0 0 1 8 0v3'),
97
97
  eye: p('M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z') + c(12, 12, 3),
98
+ fullscreen: p('M4 4h6v2H6v4H4zM14 4h6v6h-2V6h-4zM4 14h2v4h4v2H4zM18 14h2v6h-6v-2h4z'),
99
+ fullscreenExit: p('M9 4h2v6H5V8h4zM13 4h2v4h4v2h-6zM5 14h6v6H9v-4H5zM13 16h6v-2h-4v-4h-2z'),
98
100
  crop: p('M6 3v13a2 2 0 0 0 2 2h13M3 6h13a2 2 0 0 1 2 2v13'),
99
101
  resetImage: r(4, 4, 16, 16, 2) + p('M9 15l3-3 2 2 2-2 3 3M14 3v4h4'),
100
102
  replaceImage: r(4, 4, 16, 16, 2) + p('M8 15l3-3 2 2 2-2 3 3M17 2v5h-5'),
@@ -213,10 +213,6 @@ export class Ribbon {
213
213
  this.tabsEl.appendChild(this.contextHost);
214
214
  const spacer = el('div', 'pp-rb-tabs__spacer');
215
215
  this.tabsEl.appendChild(spacer);
216
- this.previewBtn = button('pp-rb-preview', `${icon('eye', 15)}<span>预览</span>`, '预览模式');
217
- this.previewBtn.setAttribute('aria-pressed', 'false');
218
- this.previewBtn.addEventListener('click', () => this.app.setPreview(!this.app.preview));
219
- this.tabsEl.appendChild(this.previewBtn);
220
216
  this.collapseBtn = button('pp-rb-collapse', icon('chevronDown', 14), '收起功能区');
221
217
  this.collapseBtn.addEventListener('click', () => {
222
218
  this.app.setRibbonCollapsed(!this.app.ribbonCollapsed);
@@ -224,15 +220,6 @@ export class Ribbon {
224
220
  this.tabsEl.appendChild(this.collapseBtn);
225
221
  }
226
222
 
227
- /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
228
- setPreview(on) {
229
- const active = !!on;
230
- this.previewBtn.classList.toggle('gbp-is-active', active);
231
- this.previewBtn.title = active ? '退出预览' : '预览模式';
232
- this.previewBtn.setAttribute('aria-pressed', String(active));
233
- this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
234
- }
235
-
236
223
  buildPanels() {
237
224
  const builders = {
238
225
  home: (p) => this.buildHome(p),
@@ -1,4 +1,4 @@
1
- // [文件] gbpptx·顶部菜单栏 —— 与 gbdocx / gbxlxs 一致:左侧菜单栏 + 右侧文档名/保存状态/保存按钮
1
+ // [文件] gbpptx·顶部菜单栏与文档头 —— 与 gbdocx / gbxlxs 一致:菜单栏一行 + 文档头一行(标题/自动保存/保存/预览)
2
2
 
3
3
  import { SHAPE_KINDS, SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
4
4
  import { icon } from './icons.js';
@@ -18,7 +18,9 @@ export class TitleBar {
18
18
  constructor(app) {
19
19
  this.app = app;
20
20
  this.el = el('header', 'pp-topbar');
21
+ this.headEl = el('header', 'gbo-head pp-head');
21
22
  this.build();
23
+ this.buildHead();
22
24
  this.refresh();
23
25
  }
24
26
 
@@ -43,17 +45,53 @@ export class TitleBar {
43
45
  });
44
46
  bar.appendChild(btn);
45
47
  }
48
+ this.el.append(bar);
49
+ }
50
+
51
+ buildHead() {
52
+ const title = el('span', 'gbo-head__title');
53
+ const state = el('span', 'gbo-head__sub');
54
+ const spacer = el('span', 'gbo-head__spacer');
46
55
 
47
- const info = el('div', 'pp-docinfo');
48
- this.nameEl = el('span', 'pp-docinfo__name', '新建演示');
49
- this.stateEl = el('span', 'pp-docinfo__state', '已保存');
50
- this.saveBtn = el('button', 'pp-docinfo__save', '保存');
56
+ const auto = el('label', 'gbo-head__auto');
57
+ this.autosaveEl = el('input', 'gbo-head__autosave');
58
+ this.autosaveEl.type = 'checkbox';
59
+ this.autosaveEl.addEventListener('change', () => this.app.setAutosave(this.autosaveEl.checked));
60
+ auto.append(this.autosaveEl, document.createTextNode('自动保存'));
61
+
62
+ this.saveBtn = el('button', 'gbo-head__btn gbo-head__btn--primary', '保存');
51
63
  this.saveBtn.type = 'button';
52
64
  this.saveBtn.title = '保存 (Ctrl+S)';
53
65
  this.saveBtn.addEventListener('click', () => this.app.save());
54
- info.append(this.nameEl, this.stateEl, this.saveBtn);
55
66
 
56
- this.el.append(bar, info);
67
+ const actions = el('span', 'gbo-head__actions');
68
+ actions.append(auto, this.saveBtn);
69
+
70
+ this.previewBtn = el('button', 'gbo-head__btn gbo-head__preview', '预览');
71
+ this.previewBtn.type = 'button';
72
+ this.previewBtn.title = '预览模式';
73
+ this.previewBtn.setAttribute('aria-pressed', 'false');
74
+ this.previewBtn.innerHTML = `${icon('eye', 14)}<span>预览</span>`;
75
+ this.previewBtn.addEventListener('click', () => this.app.setPreview(!this.app.preview));
76
+
77
+ this.nameEl = title;
78
+ this.stateEl = state;
79
+ this.fullscreenBtn = el('button', 'gbo-head__btn gbo-head__preview', '全屏');
80
+ this.fullscreenBtn.type = 'button';
81
+ this.fullscreenBtn.title = '全屏';
82
+ this.fullscreenBtn.setAttribute('aria-pressed', 'false');
83
+ this.fullscreenBtn.innerHTML = `${icon('fullscreen', 14)}<span>全屏</span>`;
84
+ this.fullscreenBtn.addEventListener('click', () => this.app.toggleFullscreen());
85
+ this.headEl.append(title, state, spacer, actions, this.previewBtn, this.fullscreenBtn);
86
+ }
87
+
88
+ /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
89
+ setPreview(on) {
90
+ const active = !!on;
91
+ this.previewBtn.classList.toggle('gbo-head__preview--on', active);
92
+ this.previewBtn.title = active ? '退出预览' : '预览模式';
93
+ this.previewBtn.setAttribute('aria-pressed', String(active));
94
+ this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
57
95
  }
58
96
 
59
97
  /* ===================== 菜单条目 ===================== */
@@ -209,6 +247,13 @@ export class TitleBar {
209
247
  : app.doc.handle ? '已保存' : (app.doc.savedAt ? '已保存副本' : '尚未保存');
210
248
  this.stateEl.classList.toggle('gbp-is-dirty', app.dirty);
211
249
  this.saveBtn.disabled = app.readOnly || !app.snapshot.slides.length;
250
+ this.autosaveEl.checked = app.autosave;
251
+ // 全屏态:同一位置切成「恢复」
252
+ const fullscreen = !!app.pageFullscreen;
253
+ this.fullscreenBtn.title = fullscreen ? '退出全屏' : '全屏';
254
+ this.fullscreenBtn.setAttribute('aria-pressed', String(fullscreen));
255
+ this.fullscreenBtn.innerHTML = `${icon(fullscreen ? 'fullscreenExit' : 'fullscreen', 14)}<span>${fullscreen ? '恢复' : '全屏'}</span>`;
256
+ this.setPreview(app.preview);
212
257
  // 只读档锁掉纯编辑类菜单,放映/视图与文件菜单里的导出/打印照常可用
213
258
  const writeMenus = new Set(['edit', 'insert', 'slide', 'review']);
214
259
  this.el.querySelectorAll('[data-menu]').forEach((btn) => {
package/web/index.html CHANGED
@@ -6,8 +6,12 @@
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
+ <link rel="stylesheet" href="/web/styles/office.css" />
10
10
  <link rel="stylesheet" href="/vendor/gbofficeui/office-chrome.css" />
11
+ <style>
12
+ /* 独立运行时撑满视口;嵌入宿主由宿主容器给高度,不依赖这条 */
13
+ html, body { height: 100%; margin: 0; }
14
+ </style>
11
15
  <script type="importmap">
12
16
  {
13
17
  "imports": {
@@ -28,29 +28,26 @@
28
28
  .pp-ico { display: block; flex: none; }
29
29
  .pp-app { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--gbp-pp-workspace); }
30
30
 
31
+ /* 页面内全屏态:整个演示应用铺满视口(文档头留着,恢复按钮在同一位置) */
32
+ .pp-app.gbp-is-pagefullscreen { position: fixed; inset: 0; z-index: 500; width: 100%; height: 100%; }
33
+
31
34
  /* ==================== 只读档 ==================== */
32
35
  .pp-app.gb-is-readonly .pp-ribbon-host,
33
36
  .pp-app.gb-is-readonly .pp-main__right { opacity: .55; }
34
37
  .pp-menubar__btn:disabled { opacity: .5; }
35
38
 
36
39
  /* ==================== 预览模式 ==================== */
37
- /* 只留选项卡行右上的退出按钮与阅读视图;菜单、功能区、缩略图/格式窗格、备注、状态栏全部收起 */
40
+ /* 只留文档头(标题 + 退出预览)与阅读视图;菜单、功能区、缩略图/格式窗格、备注、状态栏全部收起 */
38
41
  .pp-app.gbp-is-preview .pp-topbar-host,
42
+ .pp-app.gbp-is-preview .pp-ribbon-host,
43
+ .pp-app.gbp-is-preview .gbo-head__actions,
39
44
  .pp-app.gbp-is-preview .pp-main__left,
40
45
  .pp-app.gbp-is-preview .pp-main__right,
41
46
  .pp-app.gbp-is-preview .pp-notes,
42
47
  .pp-app.gbp-is-preview .pp-statusbar-host,
43
- .pp-app.gbp-is-preview .pp-ribbon__body,
44
- .pp-app.gbp-is-preview .pp-rb-tab,
45
- .pp-app.gbp-is-preview .pp-rb-tabs__context,
46
- .pp-app.gbp-is-preview .pp-rb-collapse,
47
48
  .pp-app.gbp-is-preview .pp-reading__quit {
48
49
  display: none;
49
50
  }
50
- /* 预览档本体也是只读档,但退出按钮不能被只读档的 55% 透明度压暗 */
51
- .pp-app.gbp-is-preview .pp-ribbon-host {
52
- opacity: 1;
53
- }
54
51
 
55
52
  /* ==================== 顶部菜单栏 ==================== */
56
53
  /* 菜单栏 / 文档头 / Ribbon 的视觉由 gbofficeui/styles/office-chrome.css 统一,
@@ -71,7 +68,7 @@
71
68
  .pp-menubar::-webkit-scrollbar {
72
69
  display: none;
73
70
  }
74
- .pp-docinfo__state.gbp-is-dirty {
71
+ .pp-head .gbo-head__sub.gbp-is-dirty {
75
72
  color: var(--gbp-pp-accent);
76
73
  }
77
74
 
@@ -360,7 +357,7 @@
360
357
 
361
358
  .pp-reading {
362
359
  position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
363
- gap: 18px; background: #2b2b2b;
360
+ gap: 18px; background: #2b2b2b; overflow: hidden;
364
361
  }
365
362
  .pp-reading__stage { flex: none; overflow: hidden; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5); background: #fff; }
366
363
  .pp-reading__stage .sl-page { transform-origin: 0 0; }