dsh-ppt 0.10.0 → 0.12.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/CHANGELOG.md +11 -0
- package/README.en.md +1 -0
- package/README.md +1 -0
- package/docs/USAGE.md +4 -0
- package/lib/client.js +123 -16
- package/lib/workbench.js +18 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
[历史英文记录](docs/CHANGELOG.en.md)
|
|
6
6
|
|
|
7
|
+
## 0.12.0(2026-10-20)
|
|
8
|
+
|
|
9
|
+
- 新增逐页 Markdown 讲稿下载,使用当前页序、标题与备注,保留空备注提示和修订保护。
|
|
10
|
+
- 修复图片读取中切页或返回项目时图片可能落到另一页的问题;可取消读取,读取期间暂缓保存、结构修改与下载。
|
|
11
|
+
- 面板图片上限与引擎统一为 5 MiB,提前提示超限。
|
|
12
|
+
- 首次使用引导跟随宿主中文 / English,完成或跳过的状态继续保留。
|
|
13
|
+
|
|
14
|
+
## 0.11.0(2026-10-17)
|
|
15
|
+
|
|
16
|
+
- 设置面板顶部新增「首次使用」分步引导:一次只讲一步,支持上一步/下一步/跳过,看完记在本机不再出现。
|
|
17
|
+
- 引导内容与该插件的实际用法一致;可在开发者工具里清掉 `dsh-first-run:dsh-ppt:v1` 重新查看。
|
|
7
18
|
## 0.10.0 (2026-10-15)
|
|
8
19
|
|
|
9
20
|
实际操作、最终 PPTX 渲染与未测范围见 [验收记录](docs/validation-0.10.0.md)。
|
package/README.en.md
CHANGED
|
@@ -15,6 +15,7 @@ Feedback and contributions are welcome: report [issues](https://github.com/STARD
|
|
|
15
15
|
- Create branded decks with text, images, tables and native charts.
|
|
16
16
|
- Edit text and images in Settings, reorder, duplicate or delete slides, and undo changes.
|
|
17
17
|
- Check quality and optionally render the final PPTX as images or PDF.
|
|
18
|
+
- Download Markdown speaker notes with each slide's current title and notes.
|
|
18
19
|
|
|
19
20
|
## Install
|
|
20
21
|
|
package/README.md
CHANGED
package/docs/USAGE.md
CHANGED
|
@@ -85,6 +85,10 @@ node <skill-dir>/scripts/build-deck.mjs \
|
|
|
85
85
|
|
|
86
86
|
保存会同时更新 HTML、PPTX 和 JSON。未保存时先保存或取消,再切换页面、排序、下载或渲染。若助手同时修改了工程,旧修订不会覆盖新文件;点击「载入最新版本,保留我的输入」后检查重叠字段,再明确保存。
|
|
87
87
|
|
|
88
|
+
选择图片后,等「图片已载入,保存后生效」再保存。每张 PNG/JPEG 最多 5 MiB,与生成引擎一致;读取期间切页、返回项目或取消修改会取消这次读取,图片不会加到另一页。
|
|
89
|
+
|
|
90
|
+
需要单独准备演讲提纲时,保存修改后点击「下载讲稿 Markdown」。讲稿按当前页序包含每页标题与演讲备注,空备注会明确标记;不会导出撤销历史里的旧备注。空备注提示跟随演示文稿语言,用户原文保留不变。
|
|
91
|
+
|
|
88
92
|
「HTML 预览」用于检查放映效果;安装可选引擎后,「渲染当前 PPTX」生成实际 PPTX 的逐页图片。编辑后旧渲染自动失效。最终交付前逐页检查图片和缺失字体提示,随后下载最新 PPTX / HTML,或备份 JSON 工程。面板仅编辑自产 JSON 工程,不导入任意外部 PPTX;普通生成和编辑不需要可选渲染引擎。
|
|
89
93
|
|
|
90
94
|
结构化 slides 新增 `image | image-left | image-right | chart`。图文页示例:
|
package/lib/client.js
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
// Browser source, distributed directly. tsc deliberately does not rewrite this file.
|
|
2
2
|
window.__ModuleLoader__.load({ id: 'dsh-ppt', factory: require => {
|
|
3
3
|
const React = require('react');
|
|
4
|
+
var __FR_KEY = "dsh-first-run:dsh-ppt:v1";
|
|
5
|
+
var __FR_TITLE = "演示文稿 · 首次使用(4 步)";
|
|
6
|
+
var __FR_TITLE_EN = "Presentations · First steps";
|
|
7
|
+
var __FR_STEPS_EN = [{title:"Choose a theme",body:"Choose from swiss, velvet, data, soft and bold before building your presentation."},{title:"Provide actual material",body:"Give the assistant your points, data and tables. It produces an editable PPTX and an HTML presentation.",tryIt:"Turn this quarterly update into eight slides using the data theme."},{title:"Review in the browser",body:"Step through the HTML preview, then edit text, images and speaker notes in this panel."},{title:"Check the final slides",body:"Review the final PPTX in PowerPoint or WPS, or use the optional renderer to check fonts and layout before delivery."}];
|
|
8
|
+
var __FR_STEPS = [{"title":"先选主题","body":"内置 5 套主题(swiss / velvet / data / soft / bold),先定风格再生成内容。"},{"title":"给内容,不给空话","body":"把要点、数据、表格直接给助手,它会排成幻灯片并同时产出 PPTX 与网页版。","tryIt":"把这份季度总结做成 8 页汇报,用 data 主题"},{"title":"先在浏览器里过一遍","body":"网页版可直接翻页预览,确认排版没问题再导出。"},{"title":"导出后看图核对","body":"渲染成图检查一遍再交付,避免字体缺失或溢出。"}];
|
|
9
|
+
|
|
10
|
+
// ---- first-run guide (shared snippet; keep in sync across plugins) ----
|
|
11
|
+
var __FR_STYLE_ID = 'dsh-first-run-css';
|
|
12
|
+
var __FR_CSS = [
|
|
13
|
+
'.fr-card{border:1px solid var(--dsw-border,rgba(0,0,0,.10));border-radius:12px;padding:14px 16px;margin:0 0 14px;background:linear-gradient(180deg,rgba(59,130,246,.06),rgba(59,130,246,.02))}',
|
|
14
|
+
'.fr-head{display:flex;align-items:center;gap:8px;margin-bottom:6px}',
|
|
15
|
+
'.fr-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-accent,#3b82f6)}',
|
|
16
|
+
'.fr-title{font-weight:650;font-size:13.5px}',
|
|
17
|
+
'.fr-count{margin-left:auto;font-size:11px;color:var(--dsw-text-weak,#6b7280);font-variant-numeric:tabular-nums}',
|
|
18
|
+
'.fr-step{font-weight:600;font-size:13px;margin:2px 0 4px}',
|
|
19
|
+
'.fr-body{color:var(--dsw-text-weak,#4b5563);font-size:12.5px;line-height:1.65}',
|
|
20
|
+
'.fr-try{margin-top:8px;padding:7px 9px;border-radius:8px;background:rgba(59,130,246,.09);font-size:12px;display:flex;gap:8px}',
|
|
21
|
+
'.fr-try code{font-family:ui-monospace,monospace;white-space:pre-wrap;word-break:break-word}',
|
|
22
|
+
'.fr-bar{display:flex;gap:8px;align-items:center;margin-top:12px}',
|
|
23
|
+
'.fr-progress{display:flex;gap:4px;margin-right:auto}',
|
|
24
|
+
'.fr-seg{width:16px;height:3px;border-radius:2px;background:var(--dsw-border,rgba(0,0,0,.12))}',
|
|
25
|
+
'.fr-seg.on{background:var(--dsw-accent,#3b82f6)}',
|
|
26
|
+
'.fr-btn{border:1px solid var(--dsw-border,rgba(0,0,0,.14));background:transparent;color:inherit;border-radius:8px;padding:4px 10px;font-size:12px;cursor:pointer}',
|
|
27
|
+
'.fr-btn:hover{background:rgba(0,0,0,.04)}',
|
|
28
|
+
'.fr-btn.primary{background:var(--dsw-accent,#3b82f6);border-color:transparent;color:#fff}',
|
|
29
|
+
'.fr-btn.ghost{border-color:transparent;color:var(--dsw-text-weak,#6b7280)}',
|
|
30
|
+
].join('\n');
|
|
31
|
+
function __frEnsureCss() {
|
|
32
|
+
if (typeof document === 'undefined' || document.getElementById(__FR_STYLE_ID)) return;
|
|
33
|
+
var el = document.createElement('style');
|
|
34
|
+
el.id = __FR_STYLE_ID;
|
|
35
|
+
el.textContent = __FR_CSS;
|
|
36
|
+
document.head.appendChild(el);
|
|
37
|
+
}
|
|
38
|
+
function __frRead() { try { return localStorage.getItem(__FR_KEY) === 'done'; } catch (e) { return false; } }
|
|
39
|
+
function __frWrite() { try { localStorage.setItem(__FR_KEY, 'done'); } catch (e) {} }
|
|
40
|
+
function __FirstRunCard(props) {
|
|
41
|
+
useLanguage(props?.locale || localeService);
|
|
42
|
+
var english = languageOf(props?.locale || localeService) === 'en';
|
|
43
|
+
var steps = english ? __FR_STEPS_EN : __FR_STEPS;
|
|
44
|
+
var text = (zh, en) => english ? en : zh;
|
|
45
|
+
var doneState = React.useState(__frRead);
|
|
46
|
+
var done = doneState[0], setDone = doneState[1];
|
|
47
|
+
var idxState = React.useState(0);
|
|
48
|
+
var index = idxState[0], setIndex = idxState[1];
|
|
49
|
+
React.useEffect(function () { __frEnsureCss(); }, []);
|
|
50
|
+
if (done) return null;
|
|
51
|
+
var step = steps[index];
|
|
52
|
+
var last = index >= steps.length - 1;
|
|
53
|
+
var close = function () { __frWrite(); setDone(true); };
|
|
54
|
+
var kids = [
|
|
55
|
+
React.createElement('div', { className: 'fr-head', key: 'h' },
|
|
56
|
+
React.createElement('span', { className: 'fr-dot' }),
|
|
57
|
+
React.createElement('span', { className: 'fr-title' }, english ? __FR_TITLE_EN : __FR_TITLE),
|
|
58
|
+
React.createElement('span', { className: 'fr-count' }, (index + 1) + ' / ' + steps.length)),
|
|
59
|
+
React.createElement('div', { className: 'fr-step', key: 't' }, step.title),
|
|
60
|
+
React.createElement('div', { className: 'fr-body', key: 'b' }, step.body),
|
|
61
|
+
];
|
|
62
|
+
if (step.tryIt) kids.push(React.createElement('div', { className: 'fr-try', key: 'y' },
|
|
63
|
+
React.createElement('span', null, text('可以直接说', 'Try saying')),
|
|
64
|
+
React.createElement('code', null, text('「', '“') + step.tryIt + text('」', '”'))));
|
|
65
|
+
var buttons = [React.createElement('div', { className: 'fr-progress', key: 'p' }, steps.map(function (_, i) {
|
|
66
|
+
return React.createElement('span', { key: i, className: 'fr-seg' + (i <= index ? ' on' : '') });
|
|
67
|
+
}))];
|
|
68
|
+
buttons.push(React.createElement('button', { className: 'fr-btn ghost', type: 'button', onClick: close, key: 's' }, text('跳过', 'Skip')));
|
|
69
|
+
if (index > 0) buttons.push(React.createElement('button', { className: 'fr-btn', type: 'button', key: 'prev', onClick: function () { setIndex(index - 1); } }, text('上一步', 'Back')));
|
|
70
|
+
buttons.push(React.createElement('button', { className: 'fr-btn primary', type: 'button', key: 'next', onClick: function () { if (last) close(); else setIndex(index + 1); } }, last ? text('开始使用', 'Start') : text('下一步', 'Next')));
|
|
71
|
+
kids.push(React.createElement('div', { className: 'fr-bar', key: 'bar' }, buttons));
|
|
72
|
+
return React.createElement('div', { className: 'fr-card' }, kids);
|
|
73
|
+
}
|
|
74
|
+
function __withFirstRun(Component) {
|
|
75
|
+
return function FirstRunWrapped(props) {
|
|
76
|
+
return React.createElement(React.Fragment, null, React.createElement(__FirstRunCard, props), React.createElement(Component, props));
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// ---- end first-run guide ----
|
|
80
|
+
|
|
4
81
|
const { useState, useEffect, useRef, useMemo } = React;
|
|
5
82
|
const h = React.createElement;
|
|
6
83
|
|
|
@@ -33,8 +110,11 @@ const EN = Object.freeze({
|
|
|
33
110
|
"当前 PPTX 已生成逐页图片,请查看画面。": "Slide images were rendered from the current PPTX. Review each slide.",
|
|
34
111
|
"正在渲染最终 PPTX,较大文件可能需要几分钟…": "Rendering the final PPTX. Large files may take a few minutes…",
|
|
35
112
|
"已请求下载,请查看浏览器的下载列表。": "Download requested. Check your browser’s downloads.",
|
|
36
|
-
"请选择
|
|
113
|
+
"请选择 5 MiB 以内的 PNG 或 JPEG 图片。": "Choose a PNG or JPEG image up to 5 MiB.",
|
|
37
114
|
"无法读取图片,请重试。": "Could not read the image. Try again.",
|
|
115
|
+
"正在读取图片,切换页面会取消本次读取。": "Reading the image. Switching slides cancels this upload.",
|
|
116
|
+
"图片已载入,保存后生效。": "Image loaded. Save this slide to apply it.",
|
|
117
|
+
"下载讲稿 Markdown": "Download speaker notes",
|
|
38
118
|
"演示文稿编辑": "Presentation editor",
|
|
39
119
|
"修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。": "Edit presentations generated by this plugin. Saving updates the HTML, editable PPTX and project file together.",
|
|
40
120
|
"载入最新版本,保留我的输入": "Load latest and keep my input",
|
|
@@ -156,6 +236,25 @@ function useLanguage(locale) {
|
|
|
156
236
|
// Presenter code contains a quoted </body>; only append at the document end.
|
|
157
237
|
return html.replace(/<head>/i, '<head>' + policy).replace(/<\/body>(\s*<\/html>\s*)$/i, bridge + '</body>$1');
|
|
158
238
|
}
|
|
239
|
+
function createImageLoader() {
|
|
240
|
+
let current = null;
|
|
241
|
+
function cancel() {
|
|
242
|
+
const reader = current; current = null;
|
|
243
|
+
if (reader?.readyState === 1) reader.abort();
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
cancel,
|
|
247
|
+
get pending() { return current !== null; },
|
|
248
|
+
read(file, success, failure) {
|
|
249
|
+
cancel(); const reader = new FileReader(); current = reader;
|
|
250
|
+
const settle = callback => { if (current !== reader) return; current = null; callback(); };
|
|
251
|
+
reader.onload = () => settle(() => success(String(reader.result)));
|
|
252
|
+
reader.onerror = () => settle(failure);
|
|
253
|
+
reader.onabort = () => { if (current === reader) current = null; };
|
|
254
|
+
try { reader.readAsDataURL(file); } catch { settle(failure); }
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
159
258
|
function Workbench({ locale } = {}) {
|
|
160
259
|
useLanguage(locale);
|
|
161
260
|
const [projects, setProjects] = useState([]), [project, setProject] = useState(null), [selected, setSelected] = useState('');
|
|
@@ -164,11 +263,14 @@ function useLanguage(locale) {
|
|
|
164
263
|
const [mode, setMode] = useState('html'), [raster, setRaster] = useState('');
|
|
165
264
|
const [conflict, setConflict] = useState(false), [overlaps, setOverlaps] = useState([]);
|
|
166
265
|
const frame = useRef(null), previewBox = useRef(null), fieldRefs = useRef({}), alive = useRef(true), operations = useRef(new Set());
|
|
266
|
+
const imageLoader = useRef(null);
|
|
267
|
+
if (!imageLoader.current) imageLoader.current = createImageLoader();
|
|
167
268
|
const nonce = useRef(crypto.randomUUID());
|
|
168
269
|
const previewDocument = useMemo(() => project?.html ? editorHtml(project.html, nonce.current) : '', [project?.html]);
|
|
169
270
|
const index = project ? Math.max(0, project.slides.findIndex(s => s.id === selected)) : 0;
|
|
170
271
|
const slide = project?.slides[index];
|
|
171
272
|
function adopt(next, preferred) {
|
|
273
|
+
imageLoader.current.cancel();
|
|
172
274
|
setProject(next);
|
|
173
275
|
const row = next.slides.find(s => s.id === preferred) || next.slides[0];
|
|
174
276
|
setSelected(row.id); setDraft(draftFor(row)); setImage(null); setDirty(false); setRaster(''); setOverlaps([]);
|
|
@@ -185,7 +287,7 @@ function useLanguage(locale) {
|
|
|
185
287
|
useEffect(() => {
|
|
186
288
|
alive.current = true; const abort = new AbortController();
|
|
187
289
|
action({ operation: 'list' }, abort.signal).then(value => { if (alive.current) setProjects(value.projects) }).catch(e => { if (!abort.signal.aborted) setError(e.message) });
|
|
188
|
-
return () => { alive.current = false; abort.abort(); for (const operation of operations.current) operation.abort(); };
|
|
290
|
+
return () => { alive.current = false; abort.abort(); imageLoader.current.cancel(); for (const operation of operations.current) operation.abort(); };
|
|
189
291
|
}, []);
|
|
190
292
|
useEffect(() => {
|
|
191
293
|
function receive(event) {
|
|
@@ -230,7 +332,7 @@ function useLanguage(locale) {
|
|
|
230
332
|
setMessage(t("已载入最新版本并保留你的修改,请核对后再保存。"));
|
|
231
333
|
});
|
|
232
334
|
}
|
|
233
|
-
function choose(row) { if (dirty || busy) return; setSelected(row.id); setDraft(draftFor(row)); setImage(null); }
|
|
335
|
+
function choose(row) { if (dirty || busy) return; imageLoader.current.cancel(); setSelected(row.id); setDraft(draftFor(row)); setImage(null); setMessage(''); }
|
|
234
336
|
function save() {
|
|
235
337
|
const original = draftFor(slide), patch = {};
|
|
236
338
|
for (const [key] of fields) if (draft[key] !== original[key]) patch[key] = key === 'bullets' ? draft[key].split('\n').map(v => v.trim()).filter(Boolean) : draft[key];
|
|
@@ -264,12 +366,17 @@ function useLanguage(locale) {
|
|
|
264
366
|
}
|
|
265
367
|
function upload(event) {
|
|
266
368
|
const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
369
|
+
imageLoader.current.cancel(); setMessage(''); setError('');
|
|
370
|
+
if (!['image/png', 'image/jpeg'].includes(file.type) || file.size > 5 * 1024 * 1024) { setError(t("请选择 5 MiB 以内的 PNG 或 JPEG 图片。")); return; }
|
|
371
|
+
imageLoader.current.read(file, data => {
|
|
372
|
+
if (!alive.current) return;
|
|
373
|
+
setImage({ src: data, alt: slide.image?.alt || file.name.replace(/\.[^.]+$/, ''), caption: slide.image?.caption || '', fit: slide.image?.fit || 'contain', name: file.name });
|
|
374
|
+
setDirty(true); setError(''); setMessage(t("图片已载入,保存后生效。"));
|
|
375
|
+
}, () => { if (alive.current) { setError(t("无法读取图片,请重试。")); setMessage(''); } });
|
|
376
|
+
if (imageLoader.current.pending) setMessage(t("正在读取图片,切换页面会取消本次读取。"));
|
|
271
377
|
}
|
|
272
378
|
const currentImage = image?.src || (slide?.image?.assetId && project.assets[slide.image.assetId]?.data);
|
|
379
|
+
const imagePending = imageLoader.current.pending;
|
|
273
380
|
return h('div', { className: 'pptw' }, h('style', null, css),
|
|
274
381
|
h('h2', null, t("演示文稿编辑")), h('p', { className: 'muted' }, t("修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。")),
|
|
275
382
|
error && h('div', { role: 'alert', className: 'notice error' }, error),
|
|
@@ -281,16 +388,16 @@ function useLanguage(locale) {
|
|
|
281
388
|
projects.length ? h('div', { className: 'project-list' }, projects.map(row => h('button', { key: row.id, onClick: () => open(row.id), disabled: busy }, h('strong', null, row.title), h('div', { className: 'file muted' }, row.path)))) :
|
|
282
389
|
h('div', { className: 'card' }, h('h3', null, t("还没有可以编辑的项目")), h('p', null, t("先在对话中让助手生成演示文稿。已有项目可以让助手调用 ppt_check 检查一次,它会出现在这里。")), h('p', { className: 'muted' }, t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。")))
|
|
283
390
|
) : h(React.Fragment, null,
|
|
284
|
-
h('div', { className: 'tools' }, h('button', { disabled: busy || dirty, onClick: () => { setProject(null); refreshList(); } }, t("返回项目")), h('strong', null, project.title), h('span', { className: 'muted' }, project.slides.length + t(" 页 · 修订 ") + project.revision)),
|
|
391
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy || dirty, onClick: () => { imageLoader.current.cancel(); setImage(null); setProject(null); refreshList(); } }, t("返回项目")), h('strong', null, project.title), h('span', { className: 'muted' }, project.slides.length + t(" 页 · 修订 ") + project.revision)),
|
|
285
392
|
h('div', { className: 'layout' },
|
|
286
393
|
h('div', null, h('h3', null, t("页面")), h('div', { className: 'pages' }, project.slides.map((row, i) => h('button', { key: row.id, 'aria-current': row.id === selected ? 'true' : undefined, disabled: busy || dirty, onClick: () => choose(row) }, (i + 1) + '. ' + (row.title || t("未命名页"))))),
|
|
287
|
-
h('div', { className: 'tools' }, h('button', { disabled: busy || dirty || index === 0, onClick: () => move(-1) }, t("上移")), h('button', { disabled: busy || dirty || index === project.slides.length - 1, onClick: () => move(1) }, t("下移")),
|
|
288
|
-
h('button', { disabled: busy || dirty || project.slides.length >= 120, onClick: () => structure('duplicate') }, t("复制本页")),
|
|
289
|
-
h('button', { disabled: busy || dirty || project.slides.length <= 1, onClick: () => structure('remove') }, t("删除本页")))),
|
|
394
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy || dirty || imagePending || index === 0, onClick: () => move(-1) }, t("上移")), h('button', { disabled: busy || dirty || imagePending || index === project.slides.length - 1, onClick: () => move(1) }, t("下移")),
|
|
395
|
+
h('button', { disabled: busy || dirty || imagePending || project.slides.length >= 120, onClick: () => structure('duplicate') }, t("复制本页")),
|
|
396
|
+
h('button', { disabled: busy || dirty || imagePending || project.slides.length <= 1, onClick: () => structure('remove') }, t("删除本页")))),
|
|
290
397
|
h('div', null,
|
|
291
398
|
h('div', { className: 'tools' }, h('button', { disabled: busy, 'aria-pressed': mode === 'html', onClick: () => setMode('html') }, t("HTML 预览")),
|
|
292
399
|
h('button', { disabled: busy || !project.render, 'aria-pressed': mode === 'pptx', onClick: () => setMode('pptx') }, t("最终 PPTX 预览")),
|
|
293
|
-
h('button', { disabled: busy || dirty, onClick: render }, t("渲染当前 PPTX"))),
|
|
400
|
+
h('button', { disabled: busy || dirty || imagePending, onClick: render }, t("渲染当前 PPTX"))),
|
|
294
401
|
h('div', { className: 'preview', ref: previewBox }, mode === 'html' ? (project.html ? h('iframe', { ref: frame, title: t("演示文稿 HTML 预览"), sandbox: 'allow-scripts', srcDoc: previewDocument, onLoad: jump }) : h('p', null, t("此项目尚无 HTML,请保存一次生成预览。"))) : raster ? h('img', { className: 'render-page', src: raster, alt: t("最终 PPTX 第 ") + (index + 1) + t(" 页渲染结果") }) : h('p', null, t("正在载入当前页渲染…"))),
|
|
295
402
|
h('p', { className: 'muted' }, mode === 'html' ? t("这是 HTML 放映预览。最终 PPTX 的字体和排版请用上方渲染检查。点击文字可定位编辑字段。") : t("这是当前 PPTX 文件的实际渲染图片,仍需检查每页画面;PowerPoint / WPS 可能因字体环境而不同。")),
|
|
296
403
|
project.render?.missingFonts?.length ? h('div', { role: 'alert', className: 'notice error' }, t("渲染引擎报告缺失字体:") + project.render.missingFonts.join('、') + t("。请替换为目标电脑可用字体后重新渲染。")) : null,
|
|
@@ -302,10 +409,10 @@ function useLanguage(locale) {
|
|
|
302
409
|
h('input', { id: 'pptw-image', type: 'file', accept: 'image/png,image/jpeg', disabled: busy, onChange: upload }),
|
|
303
410
|
currentImage && h('img', { className: 'image-preview', src: currentImage, alt: image?.alt || slide.image?.alt || t("当前图片") }),
|
|
304
411
|
image && h(React.Fragment, null, h('p', { className: 'muted' }, t("已选择:") + image.name), h('label', { htmlFor: 'pptw-alt' }, t("图片说明")), h('input', { id: 'pptw-alt', value: image.alt, disabled: busy, onChange: e => setImage({ ...image, alt: e.target.value }) }), h('label', { htmlFor: 'pptw-fit' }, t("图片适应方式")), h('select', { id: 'pptw-fit', value: image.fit, disabled: busy, onChange: e => setImage({ ...image, fit: e.target.value }) }, h('option', { value: 'contain' }, t("完整显示")), h('option', { value: 'cover' }, t("填满并裁切")))),
|
|
305
|
-
h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || !dirty, onClick: save }, t("保存此页")), h('button', { disabled: busy || !dirty, onClick: () => { setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setConflict(false); setOverlaps([]); } }, t("取消修改")), h('button', { disabled: busy || dirty || !project.undoAvailable, onClick: undo }, t("撤销上次修改")))),
|
|
412
|
+
h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || imagePending || !dirty, onClick: save }, t("保存此页")), h('button', { disabled: busy || (!dirty && !imagePending), onClick: () => { imageLoader.current.cancel(); setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setMessage(''); setConflict(false); setOverlaps([]); } }, t("取消修改")), h('button', { disabled: busy || dirty || imagePending || !project.undoAvailable, onClick: undo }, t("撤销上次修改")))),
|
|
306
413
|
h('details', { className: 'card' }, h('summary', null, t("质量提醒(") + project.quality.warningCount + (languageOf() === 'en' ? ')' : ')')), (project.quality.issues || []).map((issue, i) => h('p', { key: i }, t("第 ") + issue.slide + t(" 页:") + (languageOf() === 'en' ? issue.messageEn : issue.message) + (languageOf() === 'en' ? ' ' : ';') + (languageOf() === 'en' ? issue.suggestionEn : issue.suggestion)))),
|
|
307
414
|
h('p', { className: 'muted' }, t("成品包包含 PPTX、HTML 和工程文件。请先保存修改,再下载最新版本。")),
|
|
308
|
-
h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || dirty, onClick: () => download('bundle') }, t("下载成品包 ZIP")), h('button', { disabled: busy || dirty, onClick: () => download('pptx') }, t("下载最新 PPTX")), h('button', { disabled: busy || dirty, onClick: () => download('html') }, t("下载 HTML")), h('button', { disabled: busy || dirty, onClick: () => download('json') }, t("备份工程")))
|
|
415
|
+
h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || dirty || imagePending, onClick: () => download('bundle') }, t("下载成品包 ZIP")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('pptx') }, t("下载最新 PPTX")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('html') }, t("下载 HTML")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('notes') }, t("下载讲稿 Markdown")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('json') }, t("备份工程")))
|
|
309
416
|
)
|
|
310
417
|
)
|
|
311
418
|
)
|
|
@@ -313,7 +420,7 @@ function useLanguage(locale) {
|
|
|
313
420
|
}
|
|
314
421
|
function apply(ctx) {
|
|
315
422
|
try { localeService = ctx.get?.('locale') || ctx.locale; } catch { localeService = ctx.locale; }
|
|
316
|
-
ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'dsh-ppt', order: 58, label: () => t("演示文稿"), inject: () => ({ locale: localeService }) }, Workbench));
|
|
423
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'dsh-ppt', order: 58, label: () => t("演示文稿"), inject: () => ({ locale: localeService }) }, __withFirstRun(Workbench)));
|
|
317
424
|
}
|
|
318
|
-
return { inject: ['slots', 'locale'], apply, __internals: { draftFor, editorHtml } };
|
|
425
|
+
return { inject: ['slots', 'locale'], apply, __internals: { draftFor, editorHtml, createImageLoader } };
|
|
319
426
|
} });
|
package/lib/workbench.js
CHANGED
|
@@ -19,6 +19,16 @@ function ordinaryFile(path) {
|
|
|
19
19
|
return readFileSync(path);
|
|
20
20
|
}
|
|
21
21
|
function pathsFor(path) { const base = path.slice(0, -5); return { json: path, html: base + '.html', pptx: base + '.pptx' }; }
|
|
22
|
+
function speakerNotes(manifest) {
|
|
23
|
+
const label = (zh, en) => manifest.language === 'en' ? en : manifest.language === 'bilingual' ? zh + ' / ' + en : zh;
|
|
24
|
+
const heading = (value) => String(value ?? '').replace(/[\r\n]+/g, ' ').trim();
|
|
25
|
+
const sections = manifest.slides.map((slide, index) => {
|
|
26
|
+
const title = heading(slide.title) || label('第 ' + (index + 1) + ' 页', 'Slide ' + (index + 1));
|
|
27
|
+
const notes = typeof slide.notes === 'string' && slide.notes.trim() ? slide.notes : label('(本页未填写演讲备注。)', '(No speaker notes for this slide.)');
|
|
28
|
+
return '## ' + (index + 1) + '. ' + title + '\n\n' + notes;
|
|
29
|
+
});
|
|
30
|
+
return '# ' + heading(manifest.title) + '\n\n' + sections.join('\n\n---\n\n') + '\n';
|
|
31
|
+
}
|
|
22
32
|
function json(status, value) {
|
|
23
33
|
return new Response(JSON.stringify(value), { status, headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' } });
|
|
24
34
|
}
|
|
@@ -215,14 +225,18 @@ export class PptWorkbench {
|
|
|
215
225
|
return denied;
|
|
216
226
|
try {
|
|
217
227
|
const params = new URL(request.url).searchParams, kind = params.get('kind');
|
|
218
|
-
if (!['html', 'pptx', 'json', 'bundle'].includes(String(kind)))
|
|
228
|
+
if (!['html', 'pptx', 'json', 'bundle', 'notes'].includes(String(kind)))
|
|
219
229
|
return fail(400, '不支持此文件类型');
|
|
220
230
|
const { entry, manifest, files } = await this.project(params.get('id'));
|
|
221
231
|
if (String(manifest.revision) !== params.get('revision'))
|
|
222
232
|
return fail(409, '项目已被修改,请重新打开后下载');
|
|
223
233
|
request.signal.throwIfAborted();
|
|
224
234
|
let name, bytes;
|
|
225
|
-
if (kind === '
|
|
235
|
+
if (kind === 'notes') {
|
|
236
|
+
bytes = strToU8(speakerNotes(manifest));
|
|
237
|
+
name = basename(entry.path, '.json') + '-speaker-notes.md';
|
|
238
|
+
}
|
|
239
|
+
else if (kind === 'bundle') {
|
|
226
240
|
const entries = {};
|
|
227
241
|
let total = 0;
|
|
228
242
|
for (const path of Object.values(files)) {
|
|
@@ -250,10 +264,10 @@ export class PptWorkbench {
|
|
|
250
264
|
request.signal.throwIfAborted();
|
|
251
265
|
if ((await this.project(entry.id)).manifest.revision !== manifest.revision)
|
|
252
266
|
return fail(409, '项目已被修改,请重新打开后下载');
|
|
253
|
-
const type = kind === 'bundle' ? 'application/zip' : kind === 'pptx' ? 'application/vnd.openxmlformats-officedocument.presentationml.presentation' : kind === 'html' ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8';
|
|
267
|
+
const type = kind === 'notes' ? 'text/markdown; charset=utf-8' : kind === 'bundle' ? 'application/zip' : kind === 'pptx' ? 'application/vnd.openxmlformats-officedocument.presentationml.presentation' : kind === 'html' ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8';
|
|
254
268
|
return new Response(new Uint8Array(bytes), { headers: {
|
|
255
269
|
'content-type': type, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff',
|
|
256
|
-
'content-disposition': `attachment; filename="presentation.${kind === 'bundle' ? 'zip' : kind}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
270
|
+
'content-disposition': `attachment; filename="presentation.${kind === 'bundle' ? 'zip' : kind === 'notes' ? 'md' : kind}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
257
271
|
} });
|
|
258
272
|
}
|
|
259
273
|
catch (error) {
|