dsh-ppt 0.10.0 → 0.11.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/lib/client.js CHANGED
@@ -1,7 +1,78 @@
1
- // Browser source, distributed directly. tsc deliberately does not rewrite this file.
2
- window.__ModuleLoader__.load({ id: 'dsh-ppt', factory: require => {
1
+ // Browser source, distributed directly. tsc deliberately does not rewrite this file.
2
+ window.__ModuleLoader__.load({ id: 'dsh-ppt', factory: require => {
3
3
  const React = require('react');
4
- const { useState, useEffect, useRef, useMemo } = React;
4
+ var __FR_KEY = "dsh-first-run:dsh-ppt:v1";
5
+ var __FR_TITLE = "演示文稿 · 首次使用(4 步)";
6
+ var __FR_STEPS = [{"title":"先选主题","body":"内置 5 套主题(swiss / velvet / data / soft / bold),先定风格再生成内容。"},{"title":"给内容,不给空话","body":"把要点、数据、表格直接给助手,它会排成幻灯片并同时产出 PPTX 与网页版。","tryIt":"把这份季度总结做成 8 页汇报,用 data 主题"},{"title":"先在浏览器里过一遍","body":"网页版可直接翻页预览,确认排版没问题再导出。"},{"title":"导出后看图核对","body":"渲染成图检查一遍再交付,避免字体缺失或溢出。"}];
7
+
8
+ // ---- first-run guide (shared snippet; keep in sync across plugins) ----
9
+ var __FR_STYLE_ID = 'dsh-first-run-css';
10
+ var __FR_CSS = [
11
+ '.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))}',
12
+ '.fr-head{display:flex;align-items:center;gap:8px;margin-bottom:6px}',
13
+ '.fr-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-accent,#3b82f6)}',
14
+ '.fr-title{font-weight:650;font-size:13.5px}',
15
+ '.fr-count{margin-left:auto;font-size:11px;color:var(--dsw-text-weak,#6b7280);font-variant-numeric:tabular-nums}',
16
+ '.fr-step{font-weight:600;font-size:13px;margin:2px 0 4px}',
17
+ '.fr-body{color:var(--dsw-text-weak,#4b5563);font-size:12.5px;line-height:1.65}',
18
+ '.fr-try{margin-top:8px;padding:7px 9px;border-radius:8px;background:rgba(59,130,246,.09);font-size:12px;display:flex;gap:8px}',
19
+ '.fr-try code{font-family:ui-monospace,monospace;white-space:pre-wrap;word-break:break-word}',
20
+ '.fr-bar{display:flex;gap:8px;align-items:center;margin-top:12px}',
21
+ '.fr-progress{display:flex;gap:4px;margin-right:auto}',
22
+ '.fr-seg{width:16px;height:3px;border-radius:2px;background:var(--dsw-border,rgba(0,0,0,.12))}',
23
+ '.fr-seg.on{background:var(--dsw-accent,#3b82f6)}',
24
+ '.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}',
25
+ '.fr-btn:hover{background:rgba(0,0,0,.04)}',
26
+ '.fr-btn.primary{background:var(--dsw-accent,#3b82f6);border-color:transparent;color:#fff}',
27
+ '.fr-btn.ghost{border-color:transparent;color:var(--dsw-text-weak,#6b7280)}',
28
+ ].join('\n');
29
+ function __frEnsureCss() {
30
+ if (typeof document === 'undefined' || document.getElementById(__FR_STYLE_ID)) return;
31
+ var el = document.createElement('style');
32
+ el.id = __FR_STYLE_ID;
33
+ el.textContent = __FR_CSS;
34
+ document.head.appendChild(el);
35
+ }
36
+ function __frRead() { try { return localStorage.getItem(__FR_KEY) === 'done'; } catch (e) { return false; } }
37
+ function __frWrite() { try { localStorage.setItem(__FR_KEY, 'done'); } catch (e) {} }
38
+ function __FirstRunCard() {
39
+ var doneState = React.useState(__frRead);
40
+ var done = doneState[0], setDone = doneState[1];
41
+ var idxState = React.useState(0);
42
+ var index = idxState[0], setIndex = idxState[1];
43
+ React.useEffect(function () { __frEnsureCss(); }, []);
44
+ if (done) return null;
45
+ var step = __FR_STEPS[index];
46
+ var last = index >= __FR_STEPS.length - 1;
47
+ var close = function () { __frWrite(); setDone(true); };
48
+ var kids = [
49
+ React.createElement('div', { className: 'fr-head', key: 'h' },
50
+ React.createElement('span', { className: 'fr-dot' }),
51
+ React.createElement('span', { className: 'fr-title' }, __FR_TITLE),
52
+ React.createElement('span', { className: 'fr-count' }, (index + 1) + ' / ' + __FR_STEPS.length)),
53
+ React.createElement('div', { className: 'fr-step', key: 't' }, step.title),
54
+ React.createElement('div', { className: 'fr-body', key: 'b' }, step.body),
55
+ ];
56
+ if (step.tryIt) kids.push(React.createElement('div', { className: 'fr-try', key: 'y' },
57
+ React.createElement('span', null, '可以直接说'),
58
+ React.createElement('code', null, '「' + step.tryIt + '」')));
59
+ var buttons = [React.createElement('div', { className: 'fr-progress', key: 'p' }, __FR_STEPS.map(function (_, i) {
60
+ return React.createElement('span', { key: i, className: 'fr-seg' + (i <= index ? ' on' : '') });
61
+ }))];
62
+ buttons.push(React.createElement('button', { className: 'fr-btn ghost', type: 'button', onClick: close, key: 's' }, '跳过'));
63
+ if (index > 0) buttons.push(React.createElement('button', { className: 'fr-btn', type: 'button', key: 'prev', onClick: function () { setIndex(index - 1); } }, '上一步'));
64
+ buttons.push(React.createElement('button', { className: 'fr-btn primary', type: 'button', key: 'next', onClick: function () { if (last) close(); else setIndex(index + 1); } }, last ? '开始使用' : '下一步'));
65
+ kids.push(React.createElement('div', { className: 'fr-bar', key: 'bar' }, buttons));
66
+ return React.createElement('div', { className: 'fr-card' }, kids);
67
+ }
68
+ function __withFirstRun(Component) {
69
+ return function FirstRunWrapped(props) {
70
+ return React.createElement(React.Fragment, null, React.createElement(__FirstRunCard, null), React.createElement(Component, props));
71
+ };
72
+ }
73
+ // ---- end first-run guide ----
74
+
75
+ const { useState, useEffect, useRef, useMemo } = React;
5
76
  const h = React.createElement;
6
77
 
7
78
  // Interface language follows DSH; user content and stored records keep their original text.
@@ -25,10 +96,10 @@ const EN = Object.freeze({
25
96
  "内容没有变化。": "No changes to save.",
26
97
  "已保存,HTML、PPTX 和工程文件已同步更新。": "Saved. HTML, PPTX and project files were updated together.",
27
98
  "页面顺序已更新,可撤销。": "Slides reordered. You can undo this change.",
28
- "复制本页": "Duplicate slide",
29
- "删除本页": "Delete slide",
30
- "页面已复制,图片、图表和备注一并保留,可撤销。": "Slide duplicated with its images, charts and notes. You can undo this change.",
31
- "页面已删除,可撤销。": "Slide deleted. You can undo this change.",
99
+ "复制本页": "Duplicate slide",
100
+ "删除本页": "Delete slide",
101
+ "页面已复制,图片、图表和备注一并保留,可撤销。": "Slide duplicated with its images, charts and notes. You can undo this change.",
102
+ "页面已删除,可撤销。": "Slide deleted. You can undo this change.",
32
103
  "已撤销上次修改。": "Last change undone.",
33
104
  "当前 PPTX 已生成逐页图片,请查看画面。": "Slide images were rendered from the current PPTX. Review each slide.",
34
105
  "正在渲染最终 PPTX,较大文件可能需要几分钟…": "Rendering the final PPTX. Large files may take a few minutes…",
@@ -101,219 +172,219 @@ function useLanguage(locale) {
101
172
  const [, rerender] = useState(0);
102
173
  useEffect(() => { const update = () => rerender(n => n + 1); update(); return locale?.subscribe?.(update); }, [locale]);
103
174
  }
104
-
105
- const ROUTE = 'api/dsh-ppt/workbench';
106
- const fields = [['title', '标题'], ['subtitle', '副标题'], ['kicker', '眉题'], ['text', '正文'], ['bullets', '要点(每行一条)'], ['notes', '演讲备注']];
107
- const css = `
108
- .pptw {color:var(--fg,#27354b);font:14px/1.6 system-ui,sans-serif;min-width:0;max-width:1140px;margin:0 auto;padding:8px}
109
- .pptw *{box-sizing:border-box}.pptw h2{font-size:22px;margin:0}.pptw h3{font-size:16px;margin:12px 0 6px}
110
- .pptw .muted{color:var(--fg-muted,#66768a);font-size:13px}.pptw .tools{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0;align-items:center}
111
- .pptw button{font:inherit;border:1px solid var(--border,#ccd8e5);border-radius:9px;background:var(--bg-surface,#fff);color:inherit;padding:7px 12px;cursor:pointer;text-align:left;white-space:normal}
112
- .pptw button.primary{background:#245ee9;border-color:#245ee9;color:#fff}.pptw button:disabled{opacity:.45;cursor:default}
113
- .pptw input:not([type=file]),.pptw textarea,.pptw select{font:inherit;color:inherit;width:100%;background:var(--bg,#fff);border:1px solid var(--border,#c9d5e4);border-radius:8px;padding:8px 10px}
114
- .pptw textarea{resize:vertical}.pptw label{display:block;margin:8px 0 3px}.pptw .layout{display:grid;grid-template-columns:minmax(130px,190px) minmax(0,1fr);gap:14px}
115
- .pptw .pages{display:flex;flex-direction:column;gap:5px;max-height:480px;overflow:auto}.pptw .pages button[aria-current=true]{background:#245ee9;color:#fff}
116
- .pptw .preview{border:1px solid var(--border,#ced8e6);border-radius:12px;overflow:hidden;background:#f0f4fa;aspect-ratio:16/9;position:relative}
117
- .pptw iframe{position:absolute;inset:0;width:100%;height:100%;border:0}.pptw .render-page{width:100%;display:block}
118
- .pptw .notice{border-radius:9px;padding:10px 12px;margin:10px 0;background:#edf4ff;color:#17408e;overflow-wrap:anywhere}.pptw .error{background:#fff1ef;color:#922d20}
119
- .pptw .card{border:1px solid var(--border,#d5dfeb);border-radius:12px;padding:12px;margin:10px 0;background:var(--bg-surface,#fff)}
120
- .pptw .project-list{display:flex;flex-direction:column;gap:8px}.pptw .project-list button{display:block;width:100%}
121
- .pptw .file{font-size:12px;overflow-wrap:anywhere}.pptw .image-preview{width:100%;max-height:160px;object-fit:contain;background:#edf2f8;border-radius:8px}
122
- .pptw :focus-visible{outline:3px solid #78a8ff;outline-offset:2px}.pptw .dirty{color:#986114;font-size:13px}
123
- [role=dialog]:has(.pptw){width:min(1200px,calc(100vw - 48px))!important;max-width:1200px!important}
124
- @media(max-width:700px){.pptw .layout{grid-template-columns:1fr}.pptw .pages{max-height:180px}.pptw .preview{min-height:190px}.pptw{padding:3px}
125
- [role=dialog]:has(.pptw){width:100%!important;max-width:100%!important;flex-direction:column!important}
126
- [role=dialog]:has(.pptw)>nav+div{min-width:0;width:100%}
127
- [role=dialog]:has(.pptw)>nav+div>div:has(.pptw){padding:12px!important;min-width:0}
128
- [role=dialog]:has(.pptw) nav{width:100%!important;flex-basis:auto!important;border-right:0;max-height:170px;overflow:auto}
129
- [role=dialog]:has(.pptw) nav>div:has(>button){display:flex;flex-direction:row!important;flex-wrap:wrap;flex-shrink:0;gap:4px}
130
- }`;
131
-
132
- async function action(body, signal) {
133
- const response = await fetch(new URL(ROUTE, document.baseURI), { method: 'POST', credentials: 'same-origin', signal,
134
- headers: { 'content-type': 'application/json', 'x-dsh-ppt-action': '1' }, body: JSON.stringify(body) });
135
- let value;
136
- try { value = await response.json(); } catch { throw new Error(t("无法读取服务响应,请检查插件是否加载")) }
137
- if (!response.ok || value.ok === false) { const localized = languageOf() === 'en' ? value.messageEn || englishError(value.message, response.status) : value.message; const hint = languageOf() === 'en' ? value.installationHintEn : value.installationHint; const error = new Error((localized || t("操作未完成")) + (hint ? '\n' + hint : '')); error.status = response.status; throw error; }
138
- return value;
139
- }
140
- function draftFor(slide) {
141
- return { title: slide.title || '', subtitle: slide.subtitle || '', kicker: slide.kicker || '', text: slide.text || '',
142
- bullets: (slide.bullets || []).join('\n'), notes: slide.notes || '' };
143
- }
144
- function editorHtml(html, nonce) {
145
- const bridge = `<style>#hud,#delivery-bar,#review-panel,#progress,#notes-panel,#help-panel,#toast,#blank{display:none!important}.slide-frame{pointer-events:none!important}.slide-frame .slide{pointer-events:auto!important}</style><script>(function(){const nonce=${JSON.stringify(nonce)};
146
- function tell(field){parent.postMessage({type:'dsh-ppt-select',nonce:nonce,field:field},'*')}
147
- document.addEventListener('keydown',function(e){e.stopImmediatePropagation();if(e.key!=='Tab')e.preventDefault()},true);
148
- document.addEventListener('touchstart',function(e){e.stopImmediatePropagation()},true);
149
- document.addEventListener('touchend',function(e){e.stopImmediatePropagation()},true);
150
- document.addEventListener('wheel',function(e){e.stopImmediatePropagation()},{capture:true,passive:true});
151
- document.addEventListener('click',function(e){const n=e.target.closest('h1,h2,.subtitle,.kicker,.statement-title,.quote-text,.quote-attr,li');if(!n)return;
152
- e.preventDefault();e.stopImmediatePropagation();let field=n.matches('li')?'bullets':n.matches('.subtitle,.quote-attr')?'subtitle':n.matches('.kicker')?'kicker':'title';tell(field)},true);
153
- window.addEventListener('message',function(e){if(e.source!==parent||e.data?.nonce!==nonce||e.data.type!=='dsh-ppt-jump')return;window.__dshPpt?.jump(e.data.page)});
154
- })();<\/script>`;
155
- const policy = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:; connect-src 'none'; form-action 'none'">`;
156
- // Presenter code contains a quoted </body>; only append at the document end.
157
- return html.replace(/<head>/i, '<head>' + policy).replace(/<\/body>(\s*<\/html>\s*)$/i, bridge + '</body>$1');
158
- }
175
+
176
+ const ROUTE = 'api/dsh-ppt/workbench';
177
+ const fields = [['title', '标题'], ['subtitle', '副标题'], ['kicker', '眉题'], ['text', '正文'], ['bullets', '要点(每行一条)'], ['notes', '演讲备注']];
178
+ const css = `
179
+ .pptw {color:var(--fg,#27354b);font:14px/1.6 system-ui,sans-serif;min-width:0;max-width:1140px;margin:0 auto;padding:8px}
180
+ .pptw *{box-sizing:border-box}.pptw h2{font-size:22px;margin:0}.pptw h3{font-size:16px;margin:12px 0 6px}
181
+ .pptw .muted{color:var(--fg-muted,#66768a);font-size:13px}.pptw .tools{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0;align-items:center}
182
+ .pptw button{font:inherit;border:1px solid var(--border,#ccd8e5);border-radius:9px;background:var(--bg-surface,#fff);color:inherit;padding:7px 12px;cursor:pointer;text-align:left;white-space:normal}
183
+ .pptw button.primary{background:#245ee9;border-color:#245ee9;color:#fff}.pptw button:disabled{opacity:.45;cursor:default}
184
+ .pptw input:not([type=file]),.pptw textarea,.pptw select{font:inherit;color:inherit;width:100%;background:var(--bg,#fff);border:1px solid var(--border,#c9d5e4);border-radius:8px;padding:8px 10px}
185
+ .pptw textarea{resize:vertical}.pptw label{display:block;margin:8px 0 3px}.pptw .layout{display:grid;grid-template-columns:minmax(130px,190px) minmax(0,1fr);gap:14px}
186
+ .pptw .pages{display:flex;flex-direction:column;gap:5px;max-height:480px;overflow:auto}.pptw .pages button[aria-current=true]{background:#245ee9;color:#fff}
187
+ .pptw .preview{border:1px solid var(--border,#ced8e6);border-radius:12px;overflow:hidden;background:#f0f4fa;aspect-ratio:16/9;position:relative}
188
+ .pptw iframe{position:absolute;inset:0;width:100%;height:100%;border:0}.pptw .render-page{width:100%;display:block}
189
+ .pptw .notice{border-radius:9px;padding:10px 12px;margin:10px 0;background:#edf4ff;color:#17408e;overflow-wrap:anywhere}.pptw .error{background:#fff1ef;color:#922d20}
190
+ .pptw .card{border:1px solid var(--border,#d5dfeb);border-radius:12px;padding:12px;margin:10px 0;background:var(--bg-surface,#fff)}
191
+ .pptw .project-list{display:flex;flex-direction:column;gap:8px}.pptw .project-list button{display:block;width:100%}
192
+ .pptw .file{font-size:12px;overflow-wrap:anywhere}.pptw .image-preview{width:100%;max-height:160px;object-fit:contain;background:#edf2f8;border-radius:8px}
193
+ .pptw :focus-visible{outline:3px solid #78a8ff;outline-offset:2px}.pptw .dirty{color:#986114;font-size:13px}
194
+ [role=dialog]:has(.pptw){width:min(1200px,calc(100vw - 48px))!important;max-width:1200px!important}
195
+ @media(max-width:700px){.pptw .layout{grid-template-columns:1fr}.pptw .pages{max-height:180px}.pptw .preview{min-height:190px}.pptw{padding:3px}
196
+ [role=dialog]:has(.pptw){width:100%!important;max-width:100%!important;flex-direction:column!important}
197
+ [role=dialog]:has(.pptw)>nav+div{min-width:0;width:100%}
198
+ [role=dialog]:has(.pptw)>nav+div>div:has(.pptw){padding:12px!important;min-width:0}
199
+ [role=dialog]:has(.pptw) nav{width:100%!important;flex-basis:auto!important;border-right:0;max-height:170px;overflow:auto}
200
+ [role=dialog]:has(.pptw) nav>div:has(>button){display:flex;flex-direction:row!important;flex-wrap:wrap;flex-shrink:0;gap:4px}
201
+ }`;
202
+
203
+ async function action(body, signal) {
204
+ const response = await fetch(new URL(ROUTE, document.baseURI), { method: 'POST', credentials: 'same-origin', signal,
205
+ headers: { 'content-type': 'application/json', 'x-dsh-ppt-action': '1' }, body: JSON.stringify(body) });
206
+ let value;
207
+ try { value = await response.json(); } catch { throw new Error(t("无法读取服务响应,请检查插件是否加载")) }
208
+ if (!response.ok || value.ok === false) { const localized = languageOf() === 'en' ? value.messageEn || englishError(value.message, response.status) : value.message; const hint = languageOf() === 'en' ? value.installationHintEn : value.installationHint; const error = new Error((localized || t("操作未完成")) + (hint ? '\n' + hint : '')); error.status = response.status; throw error; }
209
+ return value;
210
+ }
211
+ function draftFor(slide) {
212
+ return { title: slide.title || '', subtitle: slide.subtitle || '', kicker: slide.kicker || '', text: slide.text || '',
213
+ bullets: (slide.bullets || []).join('\n'), notes: slide.notes || '' };
214
+ }
215
+ function editorHtml(html, nonce) {
216
+ const bridge = `<style>#hud,#delivery-bar,#review-panel,#progress,#notes-panel,#help-panel,#toast,#blank{display:none!important}.slide-frame{pointer-events:none!important}.slide-frame .slide{pointer-events:auto!important}</style><script>(function(){const nonce=${JSON.stringify(nonce)};
217
+ function tell(field){parent.postMessage({type:'dsh-ppt-select',nonce:nonce,field:field},'*')}
218
+ document.addEventListener('keydown',function(e){e.stopImmediatePropagation();if(e.key!=='Tab')e.preventDefault()},true);
219
+ document.addEventListener('touchstart',function(e){e.stopImmediatePropagation()},true);
220
+ document.addEventListener('touchend',function(e){e.stopImmediatePropagation()},true);
221
+ document.addEventListener('wheel',function(e){e.stopImmediatePropagation()},{capture:true,passive:true});
222
+ document.addEventListener('click',function(e){const n=e.target.closest('h1,h2,.subtitle,.kicker,.statement-title,.quote-text,.quote-attr,li');if(!n)return;
223
+ e.preventDefault();e.stopImmediatePropagation();let field=n.matches('li')?'bullets':n.matches('.subtitle,.quote-attr')?'subtitle':n.matches('.kicker')?'kicker':'title';tell(field)},true);
224
+ window.addEventListener('message',function(e){if(e.source!==parent||e.data?.nonce!==nonce||e.data.type!=='dsh-ppt-jump')return;window.__dshPpt?.jump(e.data.page)});
225
+ })();<\/script>`;
226
+ const policy = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:; connect-src 'none'; form-action 'none'">`;
227
+ // Presenter code contains a quoted </body>; only append at the document end.
228
+ return html.replace(/<head>/i, '<head>' + policy).replace(/<\/body>(\s*<\/html>\s*)$/i, bridge + '</body>$1');
229
+ }
159
230
  function Workbench({ locale } = {}) {
160
231
  useLanguage(locale);
161
- const [projects, setProjects] = useState([]), [project, setProject] = useState(null), [selected, setSelected] = useState('');
162
- const [draft, setDraft] = useState({}), [image, setImage] = useState(null), [dirty, setDirty] = useState(false);
163
- const [busy, setBusy] = useState(false), [job, setJob] = useState(''), [message, setMessage] = useState(''), [error, setError] = useState('');
164
- const [mode, setMode] = useState('html'), [raster, setRaster] = useState('');
165
- const [conflict, setConflict] = useState(false), [overlaps, setOverlaps] = useState([]);
166
- const frame = useRef(null), previewBox = useRef(null), fieldRefs = useRef({}), alive = useRef(true), operations = useRef(new Set());
167
- const nonce = useRef(crypto.randomUUID());
168
- const previewDocument = useMemo(() => project?.html ? editorHtml(project.html, nonce.current) : '', [project?.html]);
169
- const index = project ? Math.max(0, project.slides.findIndex(s => s.id === selected)) : 0;
170
- const slide = project?.slides[index];
171
- function adopt(next, preferred) {
172
- setProject(next);
173
- const row = next.slides.find(s => s.id === preferred) || next.slides[0];
174
- setSelected(row.id); setDraft(draftFor(row)); setImage(null); setDirty(false); setRaster(''); setOverlaps([]);
175
- if (!next.render) setMode('html');
176
- }
177
- async function perform(work, success, label = t("正在处理,请稍候…")) {
178
- setBusy(true); setJob(label); setError(''); setMessage(''); setConflict(false);
179
- const controller = new AbortController(); operations.current.add(controller);
180
- try { const result = await work(controller.signal); if (alive.current && success) success(result); }
181
- catch (e) { if (alive.current) { setError(e.message || t("操作失败")); setConflict(e.status === 409); } }
182
- finally { operations.current.delete(controller); if (alive.current) setBusy(false); }
183
- }
184
- function refreshList() { return perform(signal => action({ operation: 'list' }, signal), value => setProjects(value.projects)); }
185
- useEffect(() => {
186
- alive.current = true; const abort = new AbortController();
187
- 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(); };
189
- }, []);
190
- useEffect(() => {
191
- function receive(event) {
192
- if (event.source !== frame.current?.contentWindow || event.data?.nonce !== nonce.current || event.data.type !== 'dsh-ppt-select' || mode !== 'html') return;
193
- const key = event.data.field;
194
- const field = fields.find(([field]) => field === key);
232
+ const [projects, setProjects] = useState([]), [project, setProject] = useState(null), [selected, setSelected] = useState('');
233
+ const [draft, setDraft] = useState({}), [image, setImage] = useState(null), [dirty, setDirty] = useState(false);
234
+ const [busy, setBusy] = useState(false), [job, setJob] = useState(''), [message, setMessage] = useState(''), [error, setError] = useState('');
235
+ const [mode, setMode] = useState('html'), [raster, setRaster] = useState('');
236
+ const [conflict, setConflict] = useState(false), [overlaps, setOverlaps] = useState([]);
237
+ const frame = useRef(null), previewBox = useRef(null), fieldRefs = useRef({}), alive = useRef(true), operations = useRef(new Set());
238
+ const nonce = useRef(crypto.randomUUID());
239
+ const previewDocument = useMemo(() => project?.html ? editorHtml(project.html, nonce.current) : '', [project?.html]);
240
+ const index = project ? Math.max(0, project.slides.findIndex(s => s.id === selected)) : 0;
241
+ const slide = project?.slides[index];
242
+ function adopt(next, preferred) {
243
+ setProject(next);
244
+ const row = next.slides.find(s => s.id === preferred) || next.slides[0];
245
+ setSelected(row.id); setDraft(draftFor(row)); setImage(null); setDirty(false); setRaster(''); setOverlaps([]);
246
+ if (!next.render) setMode('html');
247
+ }
248
+ async function perform(work, success, label = t("正在处理,请稍候…")) {
249
+ setBusy(true); setJob(label); setError(''); setMessage(''); setConflict(false);
250
+ const controller = new AbortController(); operations.current.add(controller);
251
+ try { const result = await work(controller.signal); if (alive.current && success) success(result); }
252
+ catch (e) { if (alive.current) { setError(e.message || t("操作失败")); setConflict(e.status === 409); } }
253
+ finally { operations.current.delete(controller); if (alive.current) setBusy(false); }
254
+ }
255
+ function refreshList() { return perform(signal => action({ operation: 'list' }, signal), value => setProjects(value.projects)); }
256
+ useEffect(() => {
257
+ alive.current = true; const abort = new AbortController();
258
+ action({ operation: 'list' }, abort.signal).then(value => { if (alive.current) setProjects(value.projects) }).catch(e => { if (!abort.signal.aborted) setError(e.message) });
259
+ return () => { alive.current = false; abort.abort(); for (const operation of operations.current) operation.abort(); };
260
+ }, []);
261
+ useEffect(() => {
262
+ function receive(event) {
263
+ if (event.source !== frame.current?.contentWindow || event.data?.nonce !== nonce.current || event.data.type !== 'dsh-ppt-select' || mode !== 'html') return;
264
+ const key = event.data.field;
265
+ const field = fields.find(([field]) => field === key);
195
266
  if (field) { fieldRefs.current[key]?.focus(); fieldRefs.current[key]?.scrollIntoView({ block: 'nearest' }); setMessage(t("已定位到") + t(field[1]) + t(",在字段中修改后保存。")); }
196
- }
197
- window.addEventListener('message', receive); return () => window.removeEventListener('message', receive);
198
- }, [mode]);
199
- useEffect(() => {
200
- if (mode !== 'html' || !project || !previewBox.current) return;
201
- // Align iframe edges/dimensions when the host uses fractional text metrics.
202
- const box = previewBox.current;
203
- function align() {
204
- const target = frame.current; if (!target) return;
205
- const r = box.getBoundingClientRect(), x = r.x + box.clientLeft, y = r.y + box.clientTop;
206
- target.style.width = box.clientWidth + 'px'; target.style.height = box.clientHeight + 'px';
207
- target.style.transform = 'translate(' + (Math.ceil(x) - x) + 'px,' + (Math.ceil(y) - y) + 'px)';
208
- }
209
- align(); const observer = new ResizeObserver(align); observer.observe(box);
210
- window.addEventListener('scroll', align, true);
211
- return () => { observer.disconnect(); window.removeEventListener('scroll', align, true); };
212
- }, [mode, !!project]);
213
- function jump() { frame.current?.contentWindow?.postMessage({ type: 'dsh-ppt-jump', nonce: nonce.current, page: index }, '*'); }
214
- useEffect(() => { jump(); }, [index, project?.revision, mode]);
215
- useEffect(() => {
216
- if (mode !== 'pptx' || !project?.render) return;
217
- const abort = new AbortController(); setRaster('');
218
- action({ operation: 'page', id: project.id, page: index + 1 }, abort.signal).then(value => setRaster(value.data)).catch(e => { if (!abort.signal.aborted) setError(e.message) });
219
- return () => abort.abort();
220
- }, [mode, index, project?.revision]);
221
- function open(id) { return perform(signal => action({ operation: 'open', id }, signal), value => { adopt(value.project); setMessage(t("点击预览里的文字,或在下方修改字段。")); }); }
222
- function keepInputsAndReload() {
223
- const original = draftFor(slide), keys = fields.filter(([key]) => draft[key] !== original[key]).map(([key]) => key), pending = { ...draft }, pendingImage = image;
224
- return perform(signal => action({ operation: 'open', id: project.id }, signal), value => {
225
- const row = value.project.slides.find(s => s.id === selected);
226
- if (!row) { setError(t("当前页已被删除,输入仍保留,请复制需要的内容后取消修改。")); return; }
227
- const latest = draftFor(row), merged = { ...latest }, shared = [];
228
- for (const key of keys) { merged[key] = pending[key]; if (latest[key] !== original[key] && latest[key] !== pending[key]) shared.push({ key, latest: latest[key], yours: pending[key] }); }
229
- adopt(value.project, selected); setDraft(merged); setImage(pendingImage); setDirty(keys.length > 0 || !!pendingImage); setOverlaps(shared);
230
- setMessage(t("已载入最新版本并保留你的修改,请核对后再保存。"));
231
- });
232
- }
233
- function choose(row) { if (dirty || busy) return; setSelected(row.id); setDraft(draftFor(row)); setImage(null); }
234
- function save() {
235
- const original = draftFor(slide), patch = {};
236
- 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];
237
- if (image) patch.image = { src: image.src, alt: image.alt, fit: image.fit, caption: image.caption };
238
- return perform(signal => action({ operation: 'edit', id: project.id, expectedRevision: project.revision, slide: slide.id, patch }, signal), value => {
239
- adopt(value.project, slide.id); setMessage(value.changed === false ? t("内容没有变化。") : t("已保存,HTML、PPTX 和工程文件已同步更新。"));
240
- });
241
- }
242
- function move(delta) {
243
- const order = project.slides.map(s => s.id); [order[index], order[index + delta]] = [order[index + delta], order[index]];
244
- return perform(signal => action({ operation: 'edit', id: project.id, expectedRevision: project.revision, order }, signal), value => { adopt(value.project, slide.id); setMessage(t("页面顺序已更新,可撤销。")); });
245
- }
246
- function structure(operation) {
247
- return perform(signal => action({ operation, id: project.id, expectedRevision: project.revision, slide: slide.id }, signal), value => {
248
- adopt(value.project, value.selected);
249
- setMessage(operation === 'duplicate' ? t("页面已复制,图片、图表和备注一并保留,可撤销。") : t("页面已删除,可撤销。"));
250
- });
251
- }
252
- function undo() { return perform(signal => action({ operation: 'undo', id: project.id, expectedRevision: project.revision }, signal), value => { adopt(value.project, selected); setMessage(t("已撤销上次修改。")); }); }
253
- function render() {
254
- return perform(signal => action({ operation: 'render', id: project.id, expectedRevision: project.revision }, signal), value => { adopt(value.project, selected); setMode('pptx'); setMessage(t("当前 PPTX 已生成逐页图片,请查看画面。")); }, t("正在渲染最终 PPTX,较大文件可能需要几分钟…"));
255
- }
256
- function download(kind) {
257
- const url = new URL('api/dsh-ppt/download', document.baseURI);
258
- url.searchParams.set('id', project.id); url.searchParams.set('kind', kind); url.searchParams.set('revision', String(project.revision));
259
- // An authenticated attachment response keeps the click's user gesture and
260
- // works in WebViews whose native download handler cannot read blob URLs.
261
- const link = document.createElement('a'); link.href = url.href; link.download = '';
262
- link.hidden = true; document.body.append(link); link.click(); link.remove();
263
- setMessage(t("已请求下载,请查看浏览器的下载列表。"));
264
- }
265
- function upload(event) {
266
- const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
267
- if (!['image/png', 'image/jpeg'].includes(file.type) || file.size > 8 * 1024 * 1024) { setError(t("请选择 8 MiB 以内的 PNG 或 JPEG 图片。")); return; }
268
- const reader = new FileReader();
269
- reader.onload = () => { if (!alive.current) return; setImage({ src: String(reader.result), alt: slide.image?.alt || file.name.replace(/\.[^.]+$/, ''), caption: slide.image?.caption || '', fit: slide.image?.fit || 'contain', name: file.name }); setDirty(true); setError(''); };
270
- reader.onerror = () => setError(t("无法读取图片,请重试。")); reader.readAsDataURL(file);
271
- }
272
- const currentImage = image?.src || (slide?.image?.assetId && project.assets[slide.image.assetId]?.data);
273
- return h('div', { className: 'pptw' }, h('style', null, css),
274
- h('h2', null, t("演示文稿编辑")), h('p', { className: 'muted' }, t("修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。")),
275
- error && h('div', { role: 'alert', className: 'notice error' }, error),
276
- conflict && project && h('button', { disabled: busy, onClick: keepInputsAndReload }, t("载入最新版本,保留我的输入")),
277
- message && h('div', { role: 'status', className: 'notice' }, message),
278
- busy && h('div', { role: 'status', className: 'muted' }, job),
279
- !project ? h(React.Fragment, null,
280
- h('div', { className: 'tools' }, h('button', { onClick: refreshList, disabled: busy }, t("刷新项目"))),
281
- 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
- h('div', { className: 'card' }, h('h3', null, t("还没有可以编辑的项目")), h('p', null, t("先在对话中让助手生成演示文稿。已有项目可以让助手调用 ppt_check 检查一次,它会出现在这里。")), h('p', { className: 'muted' }, t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。")))
283
- ) : 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)),
285
- h('div', { className: 'layout' },
286
- 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("删除本页")))),
290
- h('div', null,
291
- h('div', { className: 'tools' }, h('button', { disabled: busy, 'aria-pressed': mode === 'html', onClick: () => setMode('html') }, t("HTML 预览")),
292
- 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"))),
294
- 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
- h('p', { className: 'muted' }, mode === 'html' ? t("这是 HTML 放映预览。最终 PPTX 的字体和排版请用上方渲染检查。点击文字可定位编辑字段。") : t("这是当前 PPTX 文件的实际渲染图片,仍需检查每页画面;PowerPoint / WPS 可能因字体环境而不同。")),
296
- project.render?.missingFonts?.length ? h('div', { role: 'alert', className: 'notice error' }, t("渲染引擎报告缺失字体:") + project.render.missingFonts.join('、') + t("。请替换为目标电脑可用字体后重新渲染。")) : null,
297
- h('div', { className: 'card' }, h('h3', null, t("编辑第 ") + (index + 1) + t(" 页")),
298
- dirty && h('p', { className: 'dirty' }, t("有未保存修改,请先保存或取消,再切换页面。")),
299
- overlaps.length ? h('div', { className: 'notice' }, h('strong', null, t("这些字段也被修改过,请比较后决定是否保存:")), overlaps.map(row => h('div', { key: row.key }, h('strong', null, t(fields.find(([key]) => key === row.key)[1])), h('p', null, t("最新版本:") + row.latest), h('p', null, t("你的修改:") + row.yours)))) : null,
300
- fields.filter(([key]) => key === 'title' || key === 'notes' || key === 'bullets' && (slide.layout === 'bullets' || slide.bullets?.length > 0) || key !== 'bullets' && (slide[key] || key === 'subtitle' && ['cover','section','closing','quote'].includes(slide.layout) || key === 'kicker' && ['cover','section','closing'].includes(slide.layout))).map(([key, label]) => h('div', { key }, h('label', { htmlFor: 'pptw-' + key }, t(label)), h(key === 'title' || key === 'kicker' ? 'input' : 'textarea', { id: 'pptw-' + key, ref: el => { fieldRefs.current[key] = el }, disabled: busy, value: draft[key] || '', rows: key === 'bullets' ? 4 : 2, maxLength: 8000, onChange: e => { setDraft({ ...draft, [key]: e.target.value }); setDirty(true); } }))),
301
- h('label', { htmlFor: 'pptw-image' }, slide.image ? t("替换图片(PNG / JPEG)") : t("添加图片(会改为图文布局)")),
302
- h('input', { id: 'pptw-image', type: 'file', accept: 'image/png,image/jpeg', disabled: busy, onChange: upload }),
303
- currentImage && h('img', { className: 'image-preview', src: currentImage, alt: image?.alt || slide.image?.alt || t("当前图片") }),
304
- 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("撤销上次修改")))),
306
- 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)))),
267
+ }
268
+ window.addEventListener('message', receive); return () => window.removeEventListener('message', receive);
269
+ }, [mode]);
270
+ useEffect(() => {
271
+ if (mode !== 'html' || !project || !previewBox.current) return;
272
+ // Align iframe edges/dimensions when the host uses fractional text metrics.
273
+ const box = previewBox.current;
274
+ function align() {
275
+ const target = frame.current; if (!target) return;
276
+ const r = box.getBoundingClientRect(), x = r.x + box.clientLeft, y = r.y + box.clientTop;
277
+ target.style.width = box.clientWidth + 'px'; target.style.height = box.clientHeight + 'px';
278
+ target.style.transform = 'translate(' + (Math.ceil(x) - x) + 'px,' + (Math.ceil(y) - y) + 'px)';
279
+ }
280
+ align(); const observer = new ResizeObserver(align); observer.observe(box);
281
+ window.addEventListener('scroll', align, true);
282
+ return () => { observer.disconnect(); window.removeEventListener('scroll', align, true); };
283
+ }, [mode, !!project]);
284
+ function jump() { frame.current?.contentWindow?.postMessage({ type: 'dsh-ppt-jump', nonce: nonce.current, page: index }, '*'); }
285
+ useEffect(() => { jump(); }, [index, project?.revision, mode]);
286
+ useEffect(() => {
287
+ if (mode !== 'pptx' || !project?.render) return;
288
+ const abort = new AbortController(); setRaster('');
289
+ action({ operation: 'page', id: project.id, page: index + 1 }, abort.signal).then(value => setRaster(value.data)).catch(e => { if (!abort.signal.aborted) setError(e.message) });
290
+ return () => abort.abort();
291
+ }, [mode, index, project?.revision]);
292
+ function open(id) { return perform(signal => action({ operation: 'open', id }, signal), value => { adopt(value.project); setMessage(t("点击预览里的文字,或在下方修改字段。")); }); }
293
+ function keepInputsAndReload() {
294
+ const original = draftFor(slide), keys = fields.filter(([key]) => draft[key] !== original[key]).map(([key]) => key), pending = { ...draft }, pendingImage = image;
295
+ return perform(signal => action({ operation: 'open', id: project.id }, signal), value => {
296
+ const row = value.project.slides.find(s => s.id === selected);
297
+ if (!row) { setError(t("当前页已被删除,输入仍保留,请复制需要的内容后取消修改。")); return; }
298
+ const latest = draftFor(row), merged = { ...latest }, shared = [];
299
+ for (const key of keys) { merged[key] = pending[key]; if (latest[key] !== original[key] && latest[key] !== pending[key]) shared.push({ key, latest: latest[key], yours: pending[key] }); }
300
+ adopt(value.project, selected); setDraft(merged); setImage(pendingImage); setDirty(keys.length > 0 || !!pendingImage); setOverlaps(shared);
301
+ setMessage(t("已载入最新版本并保留你的修改,请核对后再保存。"));
302
+ });
303
+ }
304
+ function choose(row) { if (dirty || busy) return; setSelected(row.id); setDraft(draftFor(row)); setImage(null); }
305
+ function save() {
306
+ const original = draftFor(slide), patch = {};
307
+ 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];
308
+ if (image) patch.image = { src: image.src, alt: image.alt, fit: image.fit, caption: image.caption };
309
+ return perform(signal => action({ operation: 'edit', id: project.id, expectedRevision: project.revision, slide: slide.id, patch }, signal), value => {
310
+ adopt(value.project, slide.id); setMessage(value.changed === false ? t("内容没有变化。") : t("已保存,HTML、PPTX 和工程文件已同步更新。"));
311
+ });
312
+ }
313
+ function move(delta) {
314
+ const order = project.slides.map(s => s.id); [order[index], order[index + delta]] = [order[index + delta], order[index]];
315
+ return perform(signal => action({ operation: 'edit', id: project.id, expectedRevision: project.revision, order }, signal), value => { adopt(value.project, slide.id); setMessage(t("页面顺序已更新,可撤销。")); });
316
+ }
317
+ function structure(operation) {
318
+ return perform(signal => action({ operation, id: project.id, expectedRevision: project.revision, slide: slide.id }, signal), value => {
319
+ adopt(value.project, value.selected);
320
+ setMessage(operation === 'duplicate' ? t("页面已复制,图片、图表和备注一并保留,可撤销。") : t("页面已删除,可撤销。"));
321
+ });
322
+ }
323
+ function undo() { return perform(signal => action({ operation: 'undo', id: project.id, expectedRevision: project.revision }, signal), value => { adopt(value.project, selected); setMessage(t("已撤销上次修改。")); }); }
324
+ function render() {
325
+ return perform(signal => action({ operation: 'render', id: project.id, expectedRevision: project.revision }, signal), value => { adopt(value.project, selected); setMode('pptx'); setMessage(t("当前 PPTX 已生成逐页图片,请查看画面。")); }, t("正在渲染最终 PPTX,较大文件可能需要几分钟…"));
326
+ }
327
+ function download(kind) {
328
+ const url = new URL('api/dsh-ppt/download', document.baseURI);
329
+ url.searchParams.set('id', project.id); url.searchParams.set('kind', kind); url.searchParams.set('revision', String(project.revision));
330
+ // An authenticated attachment response keeps the click's user gesture and
331
+ // works in WebViews whose native download handler cannot read blob URLs.
332
+ const link = document.createElement('a'); link.href = url.href; link.download = '';
333
+ link.hidden = true; document.body.append(link); link.click(); link.remove();
334
+ setMessage(t("已请求下载,请查看浏览器的下载列表。"));
335
+ }
336
+ function upload(event) {
337
+ const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
338
+ if (!['image/png', 'image/jpeg'].includes(file.type) || file.size > 8 * 1024 * 1024) { setError(t("请选择 8 MiB 以内的 PNG 或 JPEG 图片。")); return; }
339
+ const reader = new FileReader();
340
+ reader.onload = () => { if (!alive.current) return; setImage({ src: String(reader.result), alt: slide.image?.alt || file.name.replace(/\.[^.]+$/, ''), caption: slide.image?.caption || '', fit: slide.image?.fit || 'contain', name: file.name }); setDirty(true); setError(''); };
341
+ reader.onerror = () => setError(t("无法读取图片,请重试。")); reader.readAsDataURL(file);
342
+ }
343
+ const currentImage = image?.src || (slide?.image?.assetId && project.assets[slide.image.assetId]?.data);
344
+ return h('div', { className: 'pptw' }, h('style', null, css),
345
+ h('h2', null, t("演示文稿编辑")), h('p', { className: 'muted' }, t("修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。")),
346
+ error && h('div', { role: 'alert', className: 'notice error' }, error),
347
+ conflict && project && h('button', { disabled: busy, onClick: keepInputsAndReload }, t("载入最新版本,保留我的输入")),
348
+ message && h('div', { role: 'status', className: 'notice' }, message),
349
+ busy && h('div', { role: 'status', className: 'muted' }, job),
350
+ !project ? h(React.Fragment, null,
351
+ h('div', { className: 'tools' }, h('button', { onClick: refreshList, disabled: busy }, t("刷新项目"))),
352
+ 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)))) :
353
+ h('div', { className: 'card' }, h('h3', null, t("还没有可以编辑的项目")), h('p', null, t("先在对话中让助手生成演示文稿。已有项目可以让助手调用 ppt_check 检查一次,它会出现在这里。")), h('p', { className: 'muted' }, t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。")))
354
+ ) : h(React.Fragment, null,
355
+ 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)),
356
+ h('div', { className: 'layout' },
357
+ 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("未命名页"))))),
358
+ 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("下移")),
359
+ h('button', { disabled: busy || dirty || project.slides.length >= 120, onClick: () => structure('duplicate') }, t("复制本页")),
360
+ h('button', { disabled: busy || dirty || project.slides.length <= 1, onClick: () => structure('remove') }, t("删除本页")))),
361
+ h('div', null,
362
+ h('div', { className: 'tools' }, h('button', { disabled: busy, 'aria-pressed': mode === 'html', onClick: () => setMode('html') }, t("HTML 预览")),
363
+ h('button', { disabled: busy || !project.render, 'aria-pressed': mode === 'pptx', onClick: () => setMode('pptx') }, t("最终 PPTX 预览")),
364
+ h('button', { disabled: busy || dirty, onClick: render }, t("渲染当前 PPTX"))),
365
+ 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("正在载入当前页渲染…"))),
366
+ h('p', { className: 'muted' }, mode === 'html' ? t("这是 HTML 放映预览。最终 PPTX 的字体和排版请用上方渲染检查。点击文字可定位编辑字段。") : t("这是当前 PPTX 文件的实际渲染图片,仍需检查每页画面;PowerPoint / WPS 可能因字体环境而不同。")),
367
+ project.render?.missingFonts?.length ? h('div', { role: 'alert', className: 'notice error' }, t("渲染引擎报告缺失字体:") + project.render.missingFonts.join('、') + t("。请替换为目标电脑可用字体后重新渲染。")) : null,
368
+ h('div', { className: 'card' }, h('h3', null, t("编辑第 ") + (index + 1) + t(" 页")),
369
+ dirty && h('p', { className: 'dirty' }, t("有未保存修改,请先保存或取消,再切换页面。")),
370
+ overlaps.length ? h('div', { className: 'notice' }, h('strong', null, t("这些字段也被修改过,请比较后决定是否保存:")), overlaps.map(row => h('div', { key: row.key }, h('strong', null, t(fields.find(([key]) => key === row.key)[1])), h('p', null, t("最新版本:") + row.latest), h('p', null, t("你的修改:") + row.yours)))) : null,
371
+ fields.filter(([key]) => key === 'title' || key === 'notes' || key === 'bullets' && (slide.layout === 'bullets' || slide.bullets?.length > 0) || key !== 'bullets' && (slide[key] || key === 'subtitle' && ['cover','section','closing','quote'].includes(slide.layout) || key === 'kicker' && ['cover','section','closing'].includes(slide.layout))).map(([key, label]) => h('div', { key }, h('label', { htmlFor: 'pptw-' + key }, t(label)), h(key === 'title' || key === 'kicker' ? 'input' : 'textarea', { id: 'pptw-' + key, ref: el => { fieldRefs.current[key] = el }, disabled: busy, value: draft[key] || '', rows: key === 'bullets' ? 4 : 2, maxLength: 8000, onChange: e => { setDraft({ ...draft, [key]: e.target.value }); setDirty(true); } }))),
372
+ h('label', { htmlFor: 'pptw-image' }, slide.image ? t("替换图片(PNG / JPEG)") : t("添加图片(会改为图文布局)")),
373
+ h('input', { id: 'pptw-image', type: 'file', accept: 'image/png,image/jpeg', disabled: busy, onChange: upload }),
374
+ currentImage && h('img', { className: 'image-preview', src: currentImage, alt: image?.alt || slide.image?.alt || t("当前图片") }),
375
+ 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("填满并裁切")))),
376
+ 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("撤销上次修改")))),
377
+ 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
378
  h('p', { className: 'muted' }, t("成品包包含 PPTX、HTML 和工程文件。请先保存修改,再下载最新版本。")),
308
379
  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("备份工程")))
309
- )
310
- )
311
- )
312
- );
313
- }
380
+ )
381
+ )
382
+ )
383
+ );
384
+ }
314
385
  function apply(ctx) {
315
386
  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));
317
- }
387
+ ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'dsh-ppt', order: 58, label: () => t("演示文稿"), inject: () => ({ locale: localeService }) }, __withFirstRun(Workbench)));
388
+ }
318
389
  return { inject: ['slots', 'locale'], apply, __internals: { draftFor, editorHtml } };
319
- } });
390
+ } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ppt",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "DSH 演示文稿插件:生成 HTML、可编辑 PPTX 和工程文件,支持图表、轻量编辑、撤销与质量检查。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",