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,76 +1,76 @@
1
- // [文件] gbpptx·打印 / PDF 通道 —— 逐页堆进隐藏 iframe 调起浏览器打印(用户在对话框选「另存为 PDF」即得 PDF;移植 slidesPrint.js)
2
- // 说明:页渲染从 UI 侧注入(renderPage(slide, theme) → HTMLElement),内核不耦合渲染实现。
3
-
4
- import { SLIDE_W } from './model.js';
5
-
6
- /** A4 横向纸张尺寸按 96dpi CSS px 换算:幻灯片占满纸宽,剩余高度留作上下白边 */
7
- const SHEET_W = Math.round((297 / 25.4) * 96);
8
- /** [坑] 纸高留 2px 余量:mm→px 四舍五入后正好等于纸高时,浏览器会多切一张空白页 */
9
- const SHEET_H = Math.round((210 / 25.4) * 96) - 2;
10
- const PRINT_SCALE = SHEET_W / SLIDE_W;
11
-
12
- const PRINT_CSS = `
13
- @page { size: A4 landscape; margin: 0 }
14
- html, body { margin: 0; padding: 0 }
15
- .pptx-print-page {
16
- width: ${SHEET_W}px;
17
- height: ${SHEET_H}px;
18
- display: flex;
19
- align-items: center;
20
- justify-content: center;
21
- overflow: hidden;
22
- break-after: page;
23
- }
24
- .pptx-print-page:last-child { break-after: auto }
25
- .pptx-print-scale { transform: scale(${PRINT_SCALE}); transform-origin: center center }
26
- `;
27
-
28
- /** 主文档样式表整套搬进 iframe(样式与正文同源,不在 iframe 里重抄一份) */
29
- const styleTags = () =>
30
- `<base href="${document.baseURI}">` +
31
- [...document.querySelectorAll('style, link[rel="stylesheet"]')].map((node) => node.outerHTML).join('');
32
-
33
- /**
34
- * 把页栈逐页堆进隐藏 iframe 并调起浏览器打印。
35
- * @param {Array} slides 归一后的页面列表
36
- * @param {string} theme 主题键
37
- * @param {(slide:object, theme:string) => HTMLElement} renderPage 单页渲染器(UI 注入)
38
- * @returns {Promise<void>} 打印对话框关闭后兑现
39
- */
40
- export const printSlides = (slides, theme, renderPage) => new Promise((resolve) => {
41
- if (!slides || !slides.length || typeof renderPage !== 'function') return resolve();
42
- const host = document.createElement('div');
43
- host.style.cssText = 'position:fixed;left:-99999px;top:0';
44
- document.body.appendChild(host);
45
- for (const slide of slides) {
46
- const page = document.createElement('div');
47
- page.className = 'pptx-print-page';
48
- const scale = document.createElement('div');
49
- scale.className = 'pptx-print-scale';
50
- scale.appendChild(renderPage(slide, theme));
51
- page.appendChild(scale);
52
- host.appendChild(page);
53
- }
54
- const html = host.innerHTML;
55
- host.remove();
56
-
57
- // 上一次对话框没关掉就再导一次:先摘掉残留的打印框
58
- document.getElementById('pptx-print-frame')?.remove();
59
- const frame = document.createElement('iframe');
60
- frame.id = 'pptx-print-frame';
61
- frame.style.cssText = 'position:fixed;right:0;bottom:0;width:0;height:0;border:0;opacity:0';
62
- document.body.appendChild(frame);
63
-
64
- const doc = frame.contentDocument;
65
- doc.head.innerHTML = `<meta charset="utf-8">${styleTags()}<style>${PRINT_CSS}</style>`;
66
- doc.body.innerHTML = html;
67
-
68
- const cleanup = () => {
69
- frame.contentWindow.removeEventListener('afterprint', cleanup);
70
- frame.remove();
71
- resolve();
72
- };
73
- frame.contentWindow.addEventListener('afterprint', cleanup);
74
- frame.contentWindow.focus();
75
- frame.contentWindow.print();
76
- });
1
+ // [文件] gbpptx·打印 / PDF 通道 —— 逐页堆进隐藏 iframe 调起浏览器打印(用户在对话框选「另存为 PDF」即得 PDF;移植 slidesPrint.js)
2
+ // 说明:页渲染从 UI 侧注入(renderPage(slide, theme) → HTMLElement),内核不耦合渲染实现。
3
+
4
+ import { SLIDE_W } from './model.js';
5
+
6
+ /** A4 横向纸张尺寸按 96dpi CSS px 换算:幻灯片占满纸宽,剩余高度留作上下白边 */
7
+ const SHEET_W = Math.round((297 / 25.4) * 96);
8
+ /** [坑] 纸高留 2px 余量:mm→px 四舍五入后正好等于纸高时,浏览器会多切一张空白页 */
9
+ const SHEET_H = Math.round((210 / 25.4) * 96) - 2;
10
+ const PRINT_SCALE = SHEET_W / SLIDE_W;
11
+
12
+ const PRINT_CSS = `
13
+ @page { size: A4 landscape; margin: 0 }
14
+ html, body { margin: 0; padding: 0 }
15
+ .pptx-print-page {
16
+ width: ${SHEET_W}px;
17
+ height: ${SHEET_H}px;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ overflow: hidden;
22
+ break-after: page;
23
+ }
24
+ .pptx-print-page:last-child { break-after: auto }
25
+ .pptx-print-scale { transform: scale(${PRINT_SCALE}); transform-origin: center center }
26
+ `;
27
+
28
+ /** 主文档样式表整套搬进 iframe(样式与正文同源,不在 iframe 里重抄一份) */
29
+ const styleTags = () =>
30
+ `<base href="${document.baseURI}">` +
31
+ [...document.querySelectorAll('style, link[rel="stylesheet"]')].map((node) => node.outerHTML).join('');
32
+
33
+ /**
34
+ * 把页栈逐页堆进隐藏 iframe 并调起浏览器打印。
35
+ * @param {Array} slides 归一后的页面列表
36
+ * @param {string} theme 主题键
37
+ * @param {(slide:object, theme:string) => HTMLElement} renderPage 单页渲染器(UI 注入)
38
+ * @returns {Promise<void>} 打印对话框关闭后兑现
39
+ */
40
+ export const printSlides = (slides, theme, renderPage) => new Promise((resolve) => {
41
+ if (!slides || !slides.length || typeof renderPage !== 'function') return resolve();
42
+ const host = document.createElement('div');
43
+ host.style.cssText = 'position:fixed;left:-99999px;top:0';
44
+ document.body.appendChild(host);
45
+ for (const slide of slides) {
46
+ const page = document.createElement('div');
47
+ page.className = 'pptx-print-page';
48
+ const scale = document.createElement('div');
49
+ scale.className = 'pptx-print-scale';
50
+ scale.appendChild(renderPage(slide, theme));
51
+ page.appendChild(scale);
52
+ host.appendChild(page);
53
+ }
54
+ const html = host.innerHTML;
55
+ host.remove();
56
+
57
+ // 上一次对话框没关掉就再导一次:先摘掉残留的打印框
58
+ document.getElementById('pptx-print-frame')?.remove();
59
+ const frame = document.createElement('iframe');
60
+ frame.id = 'pptx-print-frame';
61
+ frame.style.cssText = 'position:fixed;right:0;bottom:0;width:0;height:0;border:0;opacity:0';
62
+ document.body.appendChild(frame);
63
+
64
+ const doc = frame.contentDocument;
65
+ doc.head.innerHTML = `<meta charset="utf-8">${styleTags()}<style>${PRINT_CSS}</style>`;
66
+ doc.body.innerHTML = html;
67
+
68
+ const cleanup = () => {
69
+ frame.contentWindow.removeEventListener('afterprint', cleanup);
70
+ frame.remove();
71
+ resolve();
72
+ };
73
+ frame.contentWindow.addEventListener('afterprint', cleanup);
74
+ frame.contentWindow.focus();
75
+ frame.contentWindow.print();
76
+ });