dsh-ppt 0.25.0 → 0.26.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 +13 -13
- package/README.md +13 -13
- package/docs/DATA.md +2 -2
- package/docs/REFERENCE.en.md +8 -8
- package/docs/REFERENCE.zh.md +8 -8
- package/docs/USAGE.en.md +11 -7
- package/docs/USAGE.md +11 -7
- package/docs/VALIDATION.md +4 -0
- package/docs/WORKBENCH.md +4 -4
- package/docs/assets/intro/workflow-en-dark.svg +1 -1
- package/docs/assets/intro/workflow-en-light.svg +1 -1
- package/docs/assets/intro/workflow-en-mobile-dark.svg +1 -1
- package/docs/assets/intro/workflow-en-mobile-light.svg +1 -1
- package/docs/assets/intro/workflow-zh-dark.svg +1 -1
- package/docs/assets/intro/workflow-zh-light.svg +1 -1
- package/docs/assets/intro/workflow-zh-mobile-dark.svg +1 -1
- package/docs/assets/intro/workflow-zh-mobile-light.svg +1 -1
- package/lib/client.js +230 -76
- package/lib/ecosystem.d.ts +73 -0
- package/lib/ecosystem.js +1352 -0
- package/lib/execution.d.ts +6 -1
- package/lib/execution.js +69 -0
- package/lib/tools.js +77 -0
- package/lib/types.d.ts +57 -1
- package/lib/workbench-language.js +4 -0
- package/lib/workbench.d.ts +2 -0
- package/lib/workbench.js +331 -8
- package/package.json +1 -1
- package/skills/dsh-ppt/SKILL.md +3 -3
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/references/advanced.md +10 -5
- package/skills/dsh-ppt/references/syntax.md +1 -0
- package/skills/dsh-ppt/scripts/build-deck.mjs +39 -8
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +50 -13
- package/skills/dsh-ppt/scripts/deck-chrome.mjs +1706 -0
- package/skills/dsh-ppt/scripts/deck-core.mjs +116 -6
- package/skills/dsh-ppt/scripts/deck-delivery.mjs +636 -41
- package/skills/dsh-ppt/scripts/deck-diagrams.mjs +2842 -0
- package/skills/dsh-ppt/scripts/deck-director.mjs +49 -3
- package/skills/dsh-ppt/scripts/deck-layouts.mjs +482 -5270
- package/skills/dsh-ppt/scripts/deck-mermaid.mjs +2737 -0
- package/skills/dsh-ppt/scripts/deck-office.mjs +1541 -0
package/lib/ecosystem.js
ADDED
|
@@ -0,0 +1,1352 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
4
|
+
const MAX_CITE_FILE_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
const REMOTION_VERSION = '4.0.539';
|
|
6
|
+
function cleanStr(value) {
|
|
7
|
+
return String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
8
|
+
}
|
|
9
|
+
export function normalizeDoi(raw) {
|
|
10
|
+
const s = cleanStr(raw);
|
|
11
|
+
if (!s)
|
|
12
|
+
return '';
|
|
13
|
+
const stripped = s.replace(/^https?:\/\/(?:dx\.)?doi\.org\//i, '').replace(/^doi:\s*/i, '').trim();
|
|
14
|
+
return /^10\.\d{4,9}\/\S+$/i.test(stripped) ? stripped.toLowerCase() : '';
|
|
15
|
+
}
|
|
16
|
+
function stripLatexBraces(value) {
|
|
17
|
+
return value
|
|
18
|
+
.replace(/\\&/g, '&')
|
|
19
|
+
.replace(/\\%/g, '%')
|
|
20
|
+
.replace(/\\_/g, '_')
|
|
21
|
+
.replace(/\\['"`^~=.uvHcdbtr]\{?([A-Za-z])\}?/g, '$1')
|
|
22
|
+
.replace(/[{}]/g, '')
|
|
23
|
+
.replace(/\s+/g, ' ')
|
|
24
|
+
.trim();
|
|
25
|
+
}
|
|
26
|
+
function parseBibtexAuthors(raw) {
|
|
27
|
+
if (!raw.trim())
|
|
28
|
+
return [];
|
|
29
|
+
return raw
|
|
30
|
+
.split(/\s+and\s+/i)
|
|
31
|
+
.map(part => stripLatexBraces(part))
|
|
32
|
+
.filter(Boolean)
|
|
33
|
+
.map(person => {
|
|
34
|
+
if (person.includes(',')) {
|
|
35
|
+
const [family, given] = person.split(',').map(s => s.trim());
|
|
36
|
+
return { family: family || '', given: given || '', name: [given, family].filter(Boolean).join(' ') };
|
|
37
|
+
}
|
|
38
|
+
const tokens = person.split(/\s+/).filter(Boolean);
|
|
39
|
+
if (tokens.length === 1)
|
|
40
|
+
return { family: tokens[0], given: '', name: tokens[0] };
|
|
41
|
+
const family = tokens.at(-1) || '';
|
|
42
|
+
const given = tokens.slice(0, -1).join(' ');
|
|
43
|
+
return { family, given, name: person };
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function parseBibtexEntries(text) {
|
|
47
|
+
const entries = [];
|
|
48
|
+
const src = String(text ?? '');
|
|
49
|
+
let i = 0;
|
|
50
|
+
while (i < src.length) {
|
|
51
|
+
const at = src.indexOf('@', i);
|
|
52
|
+
if (at < 0)
|
|
53
|
+
break;
|
|
54
|
+
const head = /@([A-Za-z]+)\s*[({]\s*([^,\s]+)\s*,/y;
|
|
55
|
+
head.lastIndex = at;
|
|
56
|
+
const m = head.exec(src);
|
|
57
|
+
if (!m) {
|
|
58
|
+
i = at + 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const entryType = m[1].toLowerCase();
|
|
62
|
+
const bibKey = m[2].trim();
|
|
63
|
+
if (['string', 'preamble', 'comment'].includes(entryType)) {
|
|
64
|
+
i = head.lastIndex;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const braceOffset = src.slice(at + 1 + m[1].length).search(/[({]/);
|
|
68
|
+
const openChar = braceOffset >= 0 ? src[at + 1 + m[1].length + braceOffset] : '{';
|
|
69
|
+
let depth = 1;
|
|
70
|
+
let pos = head.lastIndex;
|
|
71
|
+
while (pos < src.length && depth > 0) {
|
|
72
|
+
const ch = src[pos];
|
|
73
|
+
if (ch === '{' || (openChar === '(' && ch === '('))
|
|
74
|
+
depth++;
|
|
75
|
+
else if (ch === '}' || (openChar === '(' && ch === ')'))
|
|
76
|
+
depth--;
|
|
77
|
+
pos++;
|
|
78
|
+
}
|
|
79
|
+
const body = src.slice(head.lastIndex, Math.max(head.lastIndex, pos - 1));
|
|
80
|
+
i = pos;
|
|
81
|
+
const fields = {};
|
|
82
|
+
let fPos = 0;
|
|
83
|
+
while (fPos < body.length) {
|
|
84
|
+
while (fPos < body.length && /[\s,]/.test(body[fPos]))
|
|
85
|
+
fPos++;
|
|
86
|
+
if (fPos >= body.length)
|
|
87
|
+
break;
|
|
88
|
+
const keyMatch = /([A-Za-z_][A-Za-z0-9_-]*)\s*=\s*/y;
|
|
89
|
+
keyMatch.lastIndex = fPos;
|
|
90
|
+
const km = keyMatch.exec(body);
|
|
91
|
+
if (!km) {
|
|
92
|
+
fPos++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const fieldName = km[1].toLowerCase();
|
|
96
|
+
fPos = keyMatch.lastIndex;
|
|
97
|
+
let val = '';
|
|
98
|
+
if (body[fPos] === '{') {
|
|
99
|
+
let d = 1;
|
|
100
|
+
let p = fPos + 1;
|
|
101
|
+
while (p < body.length && d > 0) {
|
|
102
|
+
if (body[p] === '{')
|
|
103
|
+
d++;
|
|
104
|
+
else if (body[p] === '}')
|
|
105
|
+
d--;
|
|
106
|
+
p++;
|
|
107
|
+
}
|
|
108
|
+
val = body.slice(fPos + 1, Math.max(fPos + 1, p - 1));
|
|
109
|
+
fPos = p;
|
|
110
|
+
}
|
|
111
|
+
else if (body[fPos] === '"') {
|
|
112
|
+
let p = fPos + 1;
|
|
113
|
+
while (p < body.length) {
|
|
114
|
+
if (body[p] === '"' && body[p - 1] !== '\\')
|
|
115
|
+
break;
|
|
116
|
+
p++;
|
|
117
|
+
}
|
|
118
|
+
val = body.slice(fPos + 1, p);
|
|
119
|
+
fPos = p + 1;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const bare = /[^,\r\n}]+/y;
|
|
123
|
+
bare.lastIndex = fPos;
|
|
124
|
+
const bm = bare.exec(body);
|
|
125
|
+
if (bm) {
|
|
126
|
+
val = bm[0];
|
|
127
|
+
fPos = bare.lastIndex;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
fields[fieldName] = stripLatexBraces(val);
|
|
131
|
+
}
|
|
132
|
+
const yearMatch = /\d{4}/.exec(fields.year || '');
|
|
133
|
+
const doi = normalizeDoi(fields.doi || '');
|
|
134
|
+
entries.push({
|
|
135
|
+
id: bibKey,
|
|
136
|
+
bibKey,
|
|
137
|
+
doi,
|
|
138
|
+
title: fields.title || '',
|
|
139
|
+
authors: parseBibtexAuthors(fields.author || ''),
|
|
140
|
+
containerTitle: fields.journal || fields.booktitle || fields.series || '',
|
|
141
|
+
publisher: fields.publisher || '',
|
|
142
|
+
year: yearMatch ? Number(yearMatch[0]) : 0,
|
|
143
|
+
volume: fields.volume || '',
|
|
144
|
+
issue: fields.number || fields.issue || '',
|
|
145
|
+
page: fields.pages || fields.page || '',
|
|
146
|
+
url: cleanStr(fields.url || ''),
|
|
147
|
+
type: entryType,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return entries;
|
|
151
|
+
}
|
|
152
|
+
function normalizeJsonCitationRecord(raw, fallbackIndex = 0) {
|
|
153
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
154
|
+
return null;
|
|
155
|
+
const r = raw;
|
|
156
|
+
const work = (r.work && typeof r.work === 'object' ? r.work : r);
|
|
157
|
+
const rawAuthors = Array.isArray(work.authors) ? work.authors : Array.isArray(work.author) ? work.author : [];
|
|
158
|
+
const authors = rawAuthors
|
|
159
|
+
.map(a => {
|
|
160
|
+
if (typeof a === 'string') {
|
|
161
|
+
const parsed = parseBibtexAuthors(a);
|
|
162
|
+
return parsed[0] || { given: '', family: a, name: a };
|
|
163
|
+
}
|
|
164
|
+
if (!a || typeof a !== 'object')
|
|
165
|
+
return null;
|
|
166
|
+
const ao = a;
|
|
167
|
+
const given = cleanStr(ao.given);
|
|
168
|
+
const family = cleanStr(ao.family);
|
|
169
|
+
const name = cleanStr(ao.name) || [given, family].filter(Boolean).join(' ');
|
|
170
|
+
return (given || family || name) ? { given, family, name } : null;
|
|
171
|
+
})
|
|
172
|
+
.filter((a) => a !== null);
|
|
173
|
+
let year = 0;
|
|
174
|
+
if (typeof work.year === 'number' && Number.isInteger(work.year) && work.year > 0)
|
|
175
|
+
year = work.year;
|
|
176
|
+
else if (typeof work.year === 'string' && /^\d{4}$/.test(work.year.trim()))
|
|
177
|
+
year = Number(work.year.trim());
|
|
178
|
+
else if (work.issued && typeof work.issued === 'object') {
|
|
179
|
+
const dp = work.issued['date-parts'];
|
|
180
|
+
if (Array.isArray(dp) && Array.isArray(dp[0]) && typeof dp[0][0] === 'number')
|
|
181
|
+
year = dp[0][0];
|
|
182
|
+
}
|
|
183
|
+
const doi = normalizeDoi(work.doi ?? work.DOI);
|
|
184
|
+
const title = cleanStr(work.title);
|
|
185
|
+
const bibKey = cleanStr(r.bibKey || r.citeKey || r.citekey || r.key || r.id || (doi ? doi : `ref-${fallbackIndex + 1}`));
|
|
186
|
+
const containerTitle = cleanStr(work.containerTitle ?? work['container-title'] ?? work.journal ?? work.venue);
|
|
187
|
+
if (!title && !doi && !authors.length)
|
|
188
|
+
return null;
|
|
189
|
+
return {
|
|
190
|
+
id: cleanStr(r.id) || bibKey,
|
|
191
|
+
bibKey,
|
|
192
|
+
doi,
|
|
193
|
+
title,
|
|
194
|
+
authors,
|
|
195
|
+
containerTitle,
|
|
196
|
+
publisher: cleanStr(work.publisher),
|
|
197
|
+
year,
|
|
198
|
+
volume: cleanStr(work.volume),
|
|
199
|
+
issue: cleanStr(work.issue),
|
|
200
|
+
page: cleanStr(work.page),
|
|
201
|
+
url: cleanStr(work.url ?? work.URL),
|
|
202
|
+
type: cleanStr(work.type) || 'article',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function readVerifiedFile(path) {
|
|
206
|
+
const st = lstatSync(path);
|
|
207
|
+
if (!st.isFile() || st.isSymbolicLink() || st.size > MAX_CITE_FILE_BYTES) {
|
|
208
|
+
throw new Error('dsh-ppt:文献库文件无效或超过 8 MiB');
|
|
209
|
+
}
|
|
210
|
+
return readFileSync(path, 'utf8');
|
|
211
|
+
}
|
|
212
|
+
export function loadCitationEntriesFromFile(filePath) {
|
|
213
|
+
const ext = extname(filePath).toLowerCase();
|
|
214
|
+
const text = readVerifiedFile(filePath);
|
|
215
|
+
if (ext === '.bib')
|
|
216
|
+
return parseBibtexEntries(text);
|
|
217
|
+
if (ext === '.jsonl') {
|
|
218
|
+
const out = [];
|
|
219
|
+
for (const line of text.split(/\r?\n/)) {
|
|
220
|
+
if (!line.trim())
|
|
221
|
+
continue;
|
|
222
|
+
try {
|
|
223
|
+
const rec = normalizeJsonCitationRecord(JSON.parse(line), out.length);
|
|
224
|
+
if (rec)
|
|
225
|
+
out.push(rec);
|
|
226
|
+
}
|
|
227
|
+
catch { /* skip malformed line */ }
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
const parsed = JSON.parse(text);
|
|
232
|
+
const list = Array.isArray(parsed)
|
|
233
|
+
? parsed
|
|
234
|
+
: Array.isArray(parsed?.entries)
|
|
235
|
+
? parsed.entries
|
|
236
|
+
: Array.isArray(parsed?.works)
|
|
237
|
+
? parsed.works
|
|
238
|
+
: Array.isArray(parsed?.items)
|
|
239
|
+
? parsed.items
|
|
240
|
+
: [];
|
|
241
|
+
return list
|
|
242
|
+
.map((item, idx) => normalizeJsonCitationRecord(item, idx))
|
|
243
|
+
.filter((x) => x !== null);
|
|
244
|
+
}
|
|
245
|
+
export function discoverCitationStorePath(cwd) {
|
|
246
|
+
const candidates = [
|
|
247
|
+
join(cwd, '.dsh-cite', 'library.json'),
|
|
248
|
+
join(cwd, 'dsh-cite', 'library.json'),
|
|
249
|
+
join(cwd, 'references.bib'),
|
|
250
|
+
join(cwd, 'citations.bib'),
|
|
251
|
+
join(cwd, 'references.json'),
|
|
252
|
+
join(cwd, 'citations.json'),
|
|
253
|
+
join(cwd, 'citations.jsonl'),
|
|
254
|
+
join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'data', 'dsh-cite', 'library.json'),
|
|
255
|
+
];
|
|
256
|
+
for (const candidate of candidates) {
|
|
257
|
+
try {
|
|
258
|
+
if (!existsSync(candidate))
|
|
259
|
+
continue;
|
|
260
|
+
const st = lstatSync(candidate);
|
|
261
|
+
if (st.isFile() && !st.isSymbolicLink() && st.size <= MAX_CITE_FILE_BYTES)
|
|
262
|
+
return candidate;
|
|
263
|
+
}
|
|
264
|
+
catch { /* ignore */ }
|
|
265
|
+
}
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
function authorShortName(a) {
|
|
269
|
+
if (a.family)
|
|
270
|
+
return a.family;
|
|
271
|
+
if (a.name) {
|
|
272
|
+
const parts = a.name.trim().split(/\s+/);
|
|
273
|
+
return parts.length > 1 ? parts.at(-1) : a.name.trim();
|
|
274
|
+
}
|
|
275
|
+
return a.given;
|
|
276
|
+
}
|
|
277
|
+
function formatAuthorsList(authors, style) {
|
|
278
|
+
if (!authors.length)
|
|
279
|
+
return '';
|
|
280
|
+
const names = authors.map(a => {
|
|
281
|
+
if (a.family && a.given) {
|
|
282
|
+
return style === 'apa'
|
|
283
|
+
? `${a.family}, ${a.given[0]}.`
|
|
284
|
+
: `${a.family} ${a.given}`;
|
|
285
|
+
}
|
|
286
|
+
return a.name || a.family || a.given;
|
|
287
|
+
}).filter(Boolean);
|
|
288
|
+
if (names.length === 0)
|
|
289
|
+
return '';
|
|
290
|
+
if (names.length <= 3)
|
|
291
|
+
return names.join(style === 'apa' ? ', & ' : ', ');
|
|
292
|
+
return `${names.slice(0, 3).join(', ')}, et al.`;
|
|
293
|
+
}
|
|
294
|
+
function shortVenueLabel(venue) {
|
|
295
|
+
const clean = venue.trim();
|
|
296
|
+
if (clean.length > 24) {
|
|
297
|
+
const acronym = /\(([A-Za-z][A-Za-z0-9-]{1,15})\)/.exec(clean);
|
|
298
|
+
if (acronym)
|
|
299
|
+
return acronym[1];
|
|
300
|
+
}
|
|
301
|
+
return clean;
|
|
302
|
+
}
|
|
303
|
+
export function formatShortSourceCitation(entry, num, includeDoi = true) {
|
|
304
|
+
const first = entry.authors[0] ? authorShortName(entry.authors[0]) : '';
|
|
305
|
+
const authorPart = entry.authors.length > 2
|
|
306
|
+
? `${first} et al.`
|
|
307
|
+
: entry.authors.length === 2
|
|
308
|
+
? `${first} & ${authorShortName(entry.authors[1])}`
|
|
309
|
+
: first;
|
|
310
|
+
const venue = shortVenueLabel(entry.containerTitle);
|
|
311
|
+
const venueYear = [venue, entry.year ? String(entry.year) : ''].filter(Boolean).join(' ');
|
|
312
|
+
const core = [authorPart, venueYear].filter(Boolean).join(', ');
|
|
313
|
+
const doiPart = entry.doi && (includeDoi || !core) ? `doi:${entry.doi}` : '';
|
|
314
|
+
const parts = [core, doiPart].filter(Boolean);
|
|
315
|
+
if (parts.length === 0 && entry.title)
|
|
316
|
+
parts.push(entry.title.slice(0, 60));
|
|
317
|
+
return `[${num}] ${parts.join(' · ')}`.trim();
|
|
318
|
+
}
|
|
319
|
+
export function formatReferenceEntry(entry, num, style = 'gb-t-7714') {
|
|
320
|
+
if (!entry.title && !entry.authors.length && entry.doi) {
|
|
321
|
+
return `[${num}] doi:${entry.doi}`;
|
|
322
|
+
}
|
|
323
|
+
const authors = formatAuthorsList(entry.authors, style);
|
|
324
|
+
const authorToken = authors ? (authors.endsWith('.') ? authors : `${authors}.`) : '';
|
|
325
|
+
const title = entry.title || (entry.doi ? `doi:${entry.doi}` : entry.bibKey);
|
|
326
|
+
const venue = entry.containerTitle || entry.publisher;
|
|
327
|
+
const year = entry.year ? String(entry.year) : '';
|
|
328
|
+
const doi = entry.doi ? (style === 'apa' || style === 'chicago' ? `https://doi.org/${entry.doi}` : `DOI: ${entry.doi}`) : '';
|
|
329
|
+
if (style === 'apa') {
|
|
330
|
+
const head = [authors, year ? `(${year}).` : ''].filter(Boolean).join(' ');
|
|
331
|
+
const volIssue = entry.volume ? `${entry.volume}${entry.issue ? `(${entry.issue})` : ''}` : '';
|
|
332
|
+
const venuePart = [venue, volIssue, entry.page].filter(Boolean).join(', ');
|
|
333
|
+
return `[${num}] ${[head, `${title}.`, venuePart ? `${venuePart}.` : '', doi].filter(Boolean).join(' ')}`.trim();
|
|
334
|
+
}
|
|
335
|
+
if (style === 'mla' || style === 'chicago') {
|
|
336
|
+
const venuePart = [venue, entry.volume ? `vol. ${entry.volume}` : '', year, entry.page ? `pp. ${entry.page}` : ''].filter(Boolean).join(', ');
|
|
337
|
+
return `[${num}] ${[authorToken, `"${title}."`, venuePart ? `${venuePart}.` : '', doi].filter(Boolean).join(' ')}`.trim();
|
|
338
|
+
}
|
|
339
|
+
// GB/T 7714 default
|
|
340
|
+
const volPart = [year, entry.volume ? `${entry.volume}${entry.issue ? `(${entry.issue})` : ''}` : ''].filter(Boolean).join(', ');
|
|
341
|
+
const pubLine = [venue, volPart + (entry.page ? `: ${entry.page}` : '')].filter(Boolean).join(', ');
|
|
342
|
+
return `[${num}] ${[authorToken, `${title}${venue ? '[J]' : ''}.`, pubLine ? `${pubLine}.` : '', doi].filter(Boolean).join(' ')}`.trim();
|
|
343
|
+
}
|
|
344
|
+
function readManifestFromDeck(deckPath, engine) {
|
|
345
|
+
const engAny = engine;
|
|
346
|
+
if (engAny && typeof engAny.readDeckProject === 'function') {
|
|
347
|
+
return engAny.readDeckProject({ deckPath });
|
|
348
|
+
}
|
|
349
|
+
const st = lstatSync(deckPath);
|
|
350
|
+
if (!st.isFile() || st.isSymbolicLink() || st.size > 64 * 1024 * 1024) {
|
|
351
|
+
throw new Error('dsh-ppt:工程文件无效或过大');
|
|
352
|
+
}
|
|
353
|
+
return { manifest: JSON.parse(readFileSync(deckPath, 'utf8')), path: deckPath };
|
|
354
|
+
}
|
|
355
|
+
function collectSlideSearchText(slide) {
|
|
356
|
+
const parts = [];
|
|
357
|
+
for (const k of ['title', 'subtitle', 'takeaway', 'text', 'source', 'notes']) {
|
|
358
|
+
if (typeof slide?.[k] === 'string' && slide[k])
|
|
359
|
+
parts.push(slide[k]);
|
|
360
|
+
}
|
|
361
|
+
if (Array.isArray(slide?.bullets))
|
|
362
|
+
parts.push(...slide.bullets.filter((b) => typeof b === 'string'));
|
|
363
|
+
if (Array.isArray(slide?.items)) {
|
|
364
|
+
for (const it of slide.items) {
|
|
365
|
+
if (!it || typeof it !== 'object')
|
|
366
|
+
continue;
|
|
367
|
+
for (const k of ['tag', 'title', 'text', 'body']) {
|
|
368
|
+
if (typeof it[k] === 'string' && it[k])
|
|
369
|
+
parts.push(it[k]);
|
|
370
|
+
}
|
|
371
|
+
if (Array.isArray(it.bullets))
|
|
372
|
+
parts.push(...it.bullets.filter((b) => typeof b === 'string'));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (Array.isArray(slide?.rows)) {
|
|
376
|
+
for (const row of slide.rows) {
|
|
377
|
+
if (Array.isArray(row))
|
|
378
|
+
parts.push(row.map(c => String(c ?? '')).join(' '));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return parts.join('\n');
|
|
382
|
+
}
|
|
383
|
+
function isReferencesSlide(slide) {
|
|
384
|
+
const title = cleanStr(slide?.title).toLowerCase();
|
|
385
|
+
const kicker = cleanStr(slide?.kicker).toLowerCase();
|
|
386
|
+
return kicker === 'references' || /^(references|参考文献|bibliography|引用文献)(\s*[·/|].*)?$/i.test(title);
|
|
387
|
+
}
|
|
388
|
+
export async function attachCitationsToDeck(options) {
|
|
389
|
+
options.signal?.throwIfAborted();
|
|
390
|
+
const cwd = options.cwd ?? process.cwd();
|
|
391
|
+
const deckPath = resolve(cwd, options.deckPath);
|
|
392
|
+
const style = options.style && ['gb-t-7714', 'apa', 'mla', 'chicago'].includes(options.style)
|
|
393
|
+
? options.style
|
|
394
|
+
: 'gb-t-7714';
|
|
395
|
+
const { manifest } = readManifestFromDeck(deckPath, options.engine);
|
|
396
|
+
const loaded = [];
|
|
397
|
+
let sourcePath;
|
|
398
|
+
if (typeof options.citePath === 'string' && options.citePath.trim()) {
|
|
399
|
+
sourcePath = resolve(cwd, options.citePath.trim());
|
|
400
|
+
loaded.push(...loadCitationEntriesFromFile(sourcePath));
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
const discovered = discoverCitationStorePath(cwd);
|
|
404
|
+
if (discovered) {
|
|
405
|
+
sourcePath = discovered;
|
|
406
|
+
loaded.push(...loadCitationEntriesFromFile(discovered));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const inlineEntries = [];
|
|
410
|
+
if (typeof options.bibtex === 'string' && options.bibtex.trim()) {
|
|
411
|
+
const parsedBib = parseBibtexEntries(options.bibtex);
|
|
412
|
+
inlineEntries.push(...parsedBib);
|
|
413
|
+
loaded.push(...parsedBib);
|
|
414
|
+
}
|
|
415
|
+
const byKey = new Map();
|
|
416
|
+
const byDoi = new Map();
|
|
417
|
+
const byId = new Map();
|
|
418
|
+
for (const entry of loaded) {
|
|
419
|
+
if (entry.bibKey)
|
|
420
|
+
byKey.set(entry.bibKey.toLowerCase(), entry);
|
|
421
|
+
if (entry.doi)
|
|
422
|
+
byDoi.set(entry.doi.toLowerCase(), entry);
|
|
423
|
+
if (entry.id)
|
|
424
|
+
byId.set(entry.id.toLowerCase(), entry);
|
|
425
|
+
}
|
|
426
|
+
if (Array.isArray(options.dois)) {
|
|
427
|
+
for (const rawDoi of options.dois) {
|
|
428
|
+
const doi = normalizeDoi(rawDoi);
|
|
429
|
+
if (!doi)
|
|
430
|
+
continue;
|
|
431
|
+
if (!byDoi.has(doi)) {
|
|
432
|
+
const doiOnly = {
|
|
433
|
+
id: doi,
|
|
434
|
+
bibKey: doi,
|
|
435
|
+
doi,
|
|
436
|
+
title: '',
|
|
437
|
+
authors: [],
|
|
438
|
+
containerTitle: '',
|
|
439
|
+
publisher: '',
|
|
440
|
+
year: 0,
|
|
441
|
+
volume: '',
|
|
442
|
+
issue: '',
|
|
443
|
+
page: '',
|
|
444
|
+
url: `https://doi.org/${doi}`,
|
|
445
|
+
type: 'article',
|
|
446
|
+
};
|
|
447
|
+
byDoi.set(doi, doiOnly);
|
|
448
|
+
byKey.set(doi, doiOnly);
|
|
449
|
+
inlineEntries.push(doiOnly);
|
|
450
|
+
loaded.push(doiOnly);
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
inlineEntries.push(byDoi.get(doi));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const resolveToken = (token) => {
|
|
458
|
+
const t = token.trim().replace(/^@/, '');
|
|
459
|
+
if (!t)
|
|
460
|
+
return undefined;
|
|
461
|
+
const doi = normalizeDoi(t);
|
|
462
|
+
if (doi && byDoi.has(doi))
|
|
463
|
+
return byDoi.get(doi);
|
|
464
|
+
return byKey.get(t.toLowerCase()) || byId.get(t.toLowerCase());
|
|
465
|
+
};
|
|
466
|
+
const orderedEntries = [];
|
|
467
|
+
const numByEntryKey = new Map();
|
|
468
|
+
const missingKeys = [];
|
|
469
|
+
const slideMatches = new Map();
|
|
470
|
+
const registerMatch = (entry) => {
|
|
471
|
+
const mapKey = (entry.doi || entry.bibKey || entry.id).toLowerCase();
|
|
472
|
+
const existing = numByEntryKey.get(mapKey);
|
|
473
|
+
if (existing !== undefined)
|
|
474
|
+
return existing;
|
|
475
|
+
orderedEntries.push(entry);
|
|
476
|
+
const num = orderedEntries.length;
|
|
477
|
+
numByEntryKey.set(mapKey, num);
|
|
478
|
+
return num;
|
|
479
|
+
};
|
|
480
|
+
const slides = Array.isArray(manifest.slides) ? manifest.slides : [];
|
|
481
|
+
for (const slide of slides) {
|
|
482
|
+
if (isReferencesSlide(slide))
|
|
483
|
+
continue;
|
|
484
|
+
const haystack = collectSlideSearchText(slide);
|
|
485
|
+
const foundOnSlide = [];
|
|
486
|
+
const citeRe = /\[@([A-Za-z0-9_.:/-]+(?:\s*[,;]\s*@?[A-Za-z0-9_.:/-]+)*)\]/g;
|
|
487
|
+
let match;
|
|
488
|
+
while ((match = citeRe.exec(haystack)) !== null) {
|
|
489
|
+
const tokens = match[1].split(/[,;]/).map(s => s.trim().replace(/^@/, '')).filter(Boolean);
|
|
490
|
+
for (const tok of tokens) {
|
|
491
|
+
const entry = resolveToken(tok);
|
|
492
|
+
if (entry) {
|
|
493
|
+
registerMatch(entry);
|
|
494
|
+
if (!foundOnSlide.includes(entry))
|
|
495
|
+
foundOnSlide.push(entry);
|
|
496
|
+
}
|
|
497
|
+
else if (!missingKeys.includes(tok)) {
|
|
498
|
+
missingKeys.push(tok);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const doiRe = /\[doi:(10\.\d{4,9}\/[^\s\]]+)\]/gi;
|
|
503
|
+
while ((match = doiRe.exec(haystack)) !== null) {
|
|
504
|
+
const doi = normalizeDoi(match[1]);
|
|
505
|
+
if (!doi)
|
|
506
|
+
continue;
|
|
507
|
+
let entry = byDoi.get(doi);
|
|
508
|
+
if (!entry) {
|
|
509
|
+
entry = {
|
|
510
|
+
id: doi,
|
|
511
|
+
bibKey: doi,
|
|
512
|
+
doi,
|
|
513
|
+
title: '',
|
|
514
|
+
authors: [],
|
|
515
|
+
containerTitle: '',
|
|
516
|
+
publisher: '',
|
|
517
|
+
year: 0,
|
|
518
|
+
volume: '',
|
|
519
|
+
issue: '',
|
|
520
|
+
page: '',
|
|
521
|
+
url: `https://doi.org/${doi}`,
|
|
522
|
+
type: 'article',
|
|
523
|
+
};
|
|
524
|
+
byDoi.set(doi, entry);
|
|
525
|
+
}
|
|
526
|
+
registerMatch(entry);
|
|
527
|
+
if (!foundOnSlide.includes(entry))
|
|
528
|
+
foundOnSlide.push(entry);
|
|
529
|
+
}
|
|
530
|
+
if (foundOnSlide.length)
|
|
531
|
+
slideMatches.set(slide.id, foundOnSlide);
|
|
532
|
+
}
|
|
533
|
+
if (Array.isArray(options.citeKeys)) {
|
|
534
|
+
for (const rawKey of options.citeKeys) {
|
|
535
|
+
const tok = String(rawKey ?? '').trim();
|
|
536
|
+
if (!tok)
|
|
537
|
+
continue;
|
|
538
|
+
const entry = resolveToken(tok);
|
|
539
|
+
if (entry)
|
|
540
|
+
registerMatch(entry);
|
|
541
|
+
else if (!missingKeys.includes(tok))
|
|
542
|
+
missingKeys.push(tok);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
else if (orderedEntries.length === 0 && inlineEntries.length > 0) {
|
|
546
|
+
for (const entry of inlineEntries)
|
|
547
|
+
registerMatch(entry);
|
|
548
|
+
}
|
|
549
|
+
if (orderedEntries.length === 0) {
|
|
550
|
+
return {
|
|
551
|
+
ok: true,
|
|
552
|
+
matchedCount: 0,
|
|
553
|
+
citedKeys: [],
|
|
554
|
+
missingKeys,
|
|
555
|
+
...(sourcePath ? { sourcePath } : {}),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
const edits = [];
|
|
559
|
+
for (const slide of slides) {
|
|
560
|
+
if (isReferencesSlide(slide))
|
|
561
|
+
continue;
|
|
562
|
+
const foundOnSlide = slideMatches.get(slide.id);
|
|
563
|
+
if (!foundOnSlide?.length)
|
|
564
|
+
continue;
|
|
565
|
+
let formatted = foundOnSlide.map(entry => {
|
|
566
|
+
const num = registerMatch(entry);
|
|
567
|
+
return formatShortSourceCitation(entry, num, true);
|
|
568
|
+
});
|
|
569
|
+
if (foundOnSlide.length >= 3 && formatted.join(' · ').length > 115) {
|
|
570
|
+
formatted = foundOnSlide.map(entry => {
|
|
571
|
+
const num = registerMatch(entry);
|
|
572
|
+
return formatShortSourceCitation(entry, num, false);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
const existingSource = cleanStr(slide.source);
|
|
576
|
+
const toAdd = formatted.filter(item => {
|
|
577
|
+
const tagMatch = /^\[\d+\]/.exec(item);
|
|
578
|
+
return tagMatch ? !existingSource.includes(tagMatch[0]) : !existingSource.includes(item);
|
|
579
|
+
});
|
|
580
|
+
if (toAdd.length) {
|
|
581
|
+
edits.push({
|
|
582
|
+
slide: slide.id,
|
|
583
|
+
patch: {
|
|
584
|
+
source: existingSource ? `${existingSource} · ${toAdd.join(' · ')}` : toAdd.join(' · '),
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const append = [];
|
|
590
|
+
let referencesSlideIndex;
|
|
591
|
+
if (options.appendReferences !== false) {
|
|
592
|
+
const refLines = orderedEntries.map((entry, idx) => formatReferenceEntry(entry, idx + 1, style));
|
|
593
|
+
const existingRefIdx = slides.findIndex(isReferencesSlide);
|
|
594
|
+
const refTitle = manifest.language === 'en' ? 'References' : '参考文献 · References';
|
|
595
|
+
if (existingRefIdx >= 0) {
|
|
596
|
+
referencesSlideIndex = existingRefIdx + 1;
|
|
597
|
+
edits.push({
|
|
598
|
+
slide: slides[existingRefIdx].id,
|
|
599
|
+
patch: {
|
|
600
|
+
layout: 'bullets',
|
|
601
|
+
kicker: 'REFERENCES',
|
|
602
|
+
title: refTitle,
|
|
603
|
+
bullets: refLines,
|
|
604
|
+
source: sourcePath ? `dsh-cite · ${basename(sourcePath)}` : 'dsh-cite verified bibliography',
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
referencesSlideIndex = slides.length + 1;
|
|
610
|
+
append.push({
|
|
611
|
+
layout: 'bullets',
|
|
612
|
+
variant: 'clean',
|
|
613
|
+
kicker: 'REFERENCES',
|
|
614
|
+
title: refTitle,
|
|
615
|
+
bullets: refLines,
|
|
616
|
+
source: sourcePath ? `dsh-cite · ${basename(sourcePath)}` : 'dsh-cite verified bibliography',
|
|
617
|
+
notes: manifest.language === 'en'
|
|
618
|
+
? `Verified references (${orderedEntries.length} citations).`
|
|
619
|
+
: `经 dsh-cite 核验的参考文献列表(共 ${orderedEntries.length} 条)。`,
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
let deck;
|
|
624
|
+
if (edits.length > 0 || append.length > 0) {
|
|
625
|
+
deck = await options.engine.editDeck({
|
|
626
|
+
deckPath,
|
|
627
|
+
expectedRevision: options.expectedRevision ?? manifest.revision,
|
|
628
|
+
saveAs: options.saveAs === true,
|
|
629
|
+
...(edits.length ? { edits } : {}),
|
|
630
|
+
...(append.length ? { append } : {}),
|
|
631
|
+
cwd,
|
|
632
|
+
signal: options.signal,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
ok: true,
|
|
637
|
+
matchedCount: orderedEntries.length,
|
|
638
|
+
citedKeys: orderedEntries.map(e => e.bibKey || e.doi || e.id),
|
|
639
|
+
missingKeys,
|
|
640
|
+
...(sourcePath ? { sourcePath } : {}),
|
|
641
|
+
...(referencesSlideIndex !== undefined ? { referencesSlideIndex } : {}),
|
|
642
|
+
...(deck ? { deck } : {}),
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const DIAGRAM_LAYOUTS = new Set([
|
|
646
|
+
'chart', 'chart-split', 'waterfall', 'table', 'harvey', 'marimekko', 'sankey',
|
|
647
|
+
'swot', 'value-chain', 'gantt', 'architecture', 'tam', 'org', 'mermaid', 'flowchart', 'sequence',
|
|
648
|
+
]);
|
|
649
|
+
export function computePaceBudgetFallback(manifest, targetMinutesOverride) {
|
|
650
|
+
const slides = Array.isArray(manifest?.slides) ? manifest.slides : [];
|
|
651
|
+
const rawTarget = targetMinutesOverride ?? manifest?.targetMinutes;
|
|
652
|
+
const targetMinutes = typeof rawTarget === 'number' && Number.isFinite(rawTarget) && rawTarget > 0
|
|
653
|
+
? Math.round(rawTarget * 10) / 10
|
|
654
|
+
: null;
|
|
655
|
+
const rawBudgets = slides.map((slide, idx) => {
|
|
656
|
+
const layout = String(slide?.layout || 'bullets');
|
|
657
|
+
const notesText = cleanStr(slide?.notes);
|
|
658
|
+
const copyText = [
|
|
659
|
+
slide?.title,
|
|
660
|
+
slide?.subtitle,
|
|
661
|
+
slide?.takeaway,
|
|
662
|
+
slide?.text,
|
|
663
|
+
...(Array.isArray(slide?.bullets) ? slide.bullets : []),
|
|
664
|
+
...(Array.isArray(slide?.items) ? slide.items.flatMap((it) => [it?.title, it?.text, ...(it?.bullets ?? [])]) : []),
|
|
665
|
+
].filter(Boolean).join(' ');
|
|
666
|
+
const spoken = notesText || copyText;
|
|
667
|
+
const cjk = (spoken.match(/[\u3400-\u9fff]/g) || []).length;
|
|
668
|
+
const latin = (spoken.replace(/[\u3400-\u9fff]/g, ' ').match(/[A-Za-z0-9]+/g) || []).length;
|
|
669
|
+
let sec = cjk / (220 / 60) + latin / (145 / 60);
|
|
670
|
+
if (DIAGRAM_LAYOUTS.has(layout) || slide?.chart || slide?.rows || slide?.formula || slide?.mermaid)
|
|
671
|
+
sec += 12;
|
|
672
|
+
const isFraming = ['cover', 'closing', 'section'].includes(layout);
|
|
673
|
+
sec = Math.max(isFraming ? 12 : 20, Math.min(240, Math.round(sec)));
|
|
674
|
+
return {
|
|
675
|
+
slide: idx + 1,
|
|
676
|
+
...(typeof slide?.id === 'string' ? { slideId: slide.id } : {}),
|
|
677
|
+
title: cleanStr(slide?.title) || `Slide ${idx + 1}`,
|
|
678
|
+
layout,
|
|
679
|
+
seconds: sec,
|
|
680
|
+
minutes: Math.round((sec / 60) * 100) / 100,
|
|
681
|
+
};
|
|
682
|
+
});
|
|
683
|
+
const estimatedSeconds = rawBudgets.reduce((s, b) => s + b.seconds, 0);
|
|
684
|
+
const estimatedMinutes = Math.round((estimatedSeconds / 60) * 10) / 10;
|
|
685
|
+
const targetTotalSeconds = targetMinutes ? targetMinutes * 60 : estimatedSeconds;
|
|
686
|
+
const perSlideBudget = slides.length > 0 ? targetTotalSeconds / slides.length : 60;
|
|
687
|
+
const evaluated = rawBudgets.map(item => {
|
|
688
|
+
const isOver = item.seconds > 150 || (targetMinutes !== null && item.seconds > perSlideBudget * 1.45);
|
|
689
|
+
const isUnder = targetMinutes !== null && item.seconds < perSlideBudget * 0.45 && !['cover', 'closing', 'section'].includes(item.layout);
|
|
690
|
+
return {
|
|
691
|
+
...item,
|
|
692
|
+
status: isOver ? 'over-budget' : isUnder ? 'under-budget' : 'ok',
|
|
693
|
+
};
|
|
694
|
+
});
|
|
695
|
+
const overrunSlides = evaluated.filter(s => s.status === 'over-budget').map(s => s.slide);
|
|
696
|
+
const deltaMinutes = targetMinutes !== null ? Math.round((estimatedMinutes - targetMinutes) * 10) / 10 : 0;
|
|
697
|
+
const overBudget = targetMinutes !== null ? estimatedMinutes > targetMinutes * 1.05 || overrunSlides.length > 0 : overrunSlides.length > 0;
|
|
698
|
+
return {
|
|
699
|
+
slideCount: slides.length,
|
|
700
|
+
estimatedSeconds,
|
|
701
|
+
estimatedMinutes,
|
|
702
|
+
targetMinutes,
|
|
703
|
+
deltaMinutes,
|
|
704
|
+
deltaSeconds: targetMinutes !== null ? estimatedSeconds - targetMinutes * 60 : 0,
|
|
705
|
+
overBudget,
|
|
706
|
+
overrunSlides,
|
|
707
|
+
overBudgetSlides: overrunSlides,
|
|
708
|
+
status: overBudget ? 'over-budget' : 'on-track',
|
|
709
|
+
slides: evaluated,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
export function renderOnePagerHtmlFallback(manifest, lang) {
|
|
713
|
+
const effectiveLang = lang || manifest?.language || 'zh';
|
|
714
|
+
const en = effectiveLang === 'en';
|
|
715
|
+
const esc = (v) => String(v ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
716
|
+
const title = cleanStr(manifest?.title) || (en ? 'Executive One-Pager' : '高管一页纸摘要');
|
|
717
|
+
const slides = Array.isArray(manifest?.slides) ? manifest.slides : [];
|
|
718
|
+
const pace = computePaceBudgetFallback(manifest);
|
|
719
|
+
const primary = manifest?.brand?.primaryColor || '#0057B8';
|
|
720
|
+
const bg = manifest?.brand?.backgroundColor || '#F8FAFC';
|
|
721
|
+
const fg = manifest?.brand?.textColor || '#0F172A';
|
|
722
|
+
const cardsHtml = slides.map((s, idx) => {
|
|
723
|
+
const items = Array.isArray(s.items) ? s.items.slice(0, 4).map((it) => `<li><strong>${esc([it.tag, it.value, it.title].filter(Boolean).join(' · '))}</strong>${it.text ? ` — ${esc(it.text)}` : ''}</li>`).join('') : '';
|
|
724
|
+
const bullets = Array.isArray(s.bullets) ? s.bullets.slice(0, 4).map((b) => `<li>${esc(b)}</li>`).join('') : '';
|
|
725
|
+
const summary = s.takeaway ? `<p class="takeaway">${esc(s.takeaway)}</p>` : (s.subtitle ? `<p class="sub">${esc(s.subtitle)}</p>` : '');
|
|
726
|
+
return `<article class="card">
|
|
727
|
+
<div class="meta"><span>#${idx + 1}</span><span>${esc(s.layout || 'bullets')}</span><span>${pace.slides[idx]?.seconds || 30}s</span></div>
|
|
728
|
+
<h3>${esc(s.title || `Slide ${idx + 1}`)}</h3>
|
|
729
|
+
${summary}
|
|
730
|
+
${items || bullets ? `<ul>${items || bullets}</ul>` : ''}
|
|
731
|
+
${s.source ? `<div class="src">${esc(s.source)}</div>` : ''}
|
|
732
|
+
</article>`;
|
|
733
|
+
}).join('');
|
|
734
|
+
return `<!doctype html>
|
|
735
|
+
<html lang="${en ? 'en' : 'zh-CN'}">
|
|
736
|
+
<head>
|
|
737
|
+
<meta charset="utf-8">
|
|
738
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
739
|
+
<title>${esc(title)} — ${en ? 'Executive One-Pager' : '高管一页纸'}</title>
|
|
740
|
+
<style>
|
|
741
|
+
:root{--accent:${esc(primary)};--bg:${esc(bg)};--fg:${esc(fg)}}
|
|
742
|
+
*{box-sizing:border-box}
|
|
743
|
+
body{margin:0;padding:24px;background:var(--bg);color:var(--fg);font-family:system-ui,"Microsoft YaHei",sans-serif;line-height:1.5}
|
|
744
|
+
.wrap{max-width:1120px;margin:0 auto}
|
|
745
|
+
.wrap.mobile{max-width:440px}
|
|
746
|
+
.wrap.mobile .grid{grid-template-columns:1fr}
|
|
747
|
+
header{display:flex;justify-content:space-between;align-items:flex-end;gap:12px;border-bottom:3px solid var(--accent);padding-bottom:12px;margin-bottom:16px;flex-wrap:wrap}
|
|
748
|
+
h1{margin:0;font-size:24px}
|
|
749
|
+
.badges{display:flex;gap:8px;flex-wrap:wrap;font-size:12px;color:#475569}
|
|
750
|
+
.badge{padding:3px 10px;border-radius:999px;background:#fff;border:1px solid #cbd5e1}
|
|
751
|
+
.toggle{padding:6px 12px;border-radius:8px;border:1px solid var(--accent);background:var(--accent);color:#fff;cursor:pointer;font-size:12px}
|
|
752
|
+
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:12px}
|
|
753
|
+
.card{background:#fff;border:1px solid #e2e8f0;border-top:3px solid var(--accent);border-radius:8px;padding:12px;display:flex;flex-direction:column;gap:6px}
|
|
754
|
+
.meta{display:flex;justify-content:space-between;font-size:11px;color:#64748b;text-transform:uppercase}
|
|
755
|
+
h3{margin:0;font-size:15px}
|
|
756
|
+
.sub,.takeaway{margin:0;font-size:12.5px;color:#334155}
|
|
757
|
+
.takeaway{font-weight:600;color:var(--accent)}
|
|
758
|
+
ul{margin:4px 0 0;padding-left:18px;font-size:12.5px}
|
|
759
|
+
.src{margin-top:auto;font-size:11px;color:#64748b;border-top:1px dashed #e2e8f0;padding-top:4px}
|
|
760
|
+
@media print{body{padding:0;background:#fff}.toggle{display:none}@page{size:A4 landscape;margin:10mm}}
|
|
761
|
+
</style>
|
|
762
|
+
</head>
|
|
763
|
+
<body>
|
|
764
|
+
<div id="onepager" class="wrap">
|
|
765
|
+
<header>
|
|
766
|
+
<div>
|
|
767
|
+
<h1>${esc(title)}</h1>
|
|
768
|
+
<div class="badges">
|
|
769
|
+
<span class="badge">${slides.length} ${en ? 'slides' : '页'}</span>
|
|
770
|
+
<span class="badge">${en ? 'Est. Pace' : '预计时长'}: ~${pace.estimatedMinutes} ${en ? 'min' : '分钟'}</span>
|
|
771
|
+
${pace.targetMinutes ? `<span class="badge">${en ? 'Target' : '目标'}: ${pace.targetMinutes} ${en ? 'min' : '分钟'}</span>` : ''}
|
|
772
|
+
</div>
|
|
773
|
+
</div>
|
|
774
|
+
<button class="toggle" type="button" onclick="document.getElementById('onepager').classList.toggle('mobile')">${en ? 'Toggle Mobile Long-Card' : '切换长图战报'}</button>
|
|
775
|
+
</header>
|
|
776
|
+
<main class="grid">${cardsHtml}</main>
|
|
777
|
+
</div>
|
|
778
|
+
</body>
|
|
779
|
+
</html>`;
|
|
780
|
+
}
|
|
781
|
+
function parseKpiNumeric(raw) {
|
|
782
|
+
const s = cleanStr(raw);
|
|
783
|
+
const m = /^([^0-9+-]*)([+-]?\d[\d,]*(?:\.\d+)?)(.*)$/.exec(s);
|
|
784
|
+
if (!m)
|
|
785
|
+
return { numericValue: null, prefix: '', suffix: '', decimals: 0 };
|
|
786
|
+
const cleanNum = m[2].replace(/,/g, '');
|
|
787
|
+
const num = Number(cleanNum);
|
|
788
|
+
if (!Number.isFinite(num))
|
|
789
|
+
return { numericValue: null, prefix: '', suffix: '', decimals: 0 };
|
|
790
|
+
const decMatch = /\.(\d+)/.exec(cleanNum);
|
|
791
|
+
return {
|
|
792
|
+
numericValue: num,
|
|
793
|
+
prefix: m[1] || '',
|
|
794
|
+
suffix: m[3] || '',
|
|
795
|
+
decimals: decMatch ? decMatch[1].length : 0,
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function buildTimedCaptions(text, durationFrames, fps) {
|
|
799
|
+
const cleaned = cleanStr(text);
|
|
800
|
+
if (!cleaned)
|
|
801
|
+
return [];
|
|
802
|
+
const rawSegments = cleaned
|
|
803
|
+
.split(/(?<=[。!?.!?;;])\s+|\n+/)
|
|
804
|
+
.map(s => s.trim())
|
|
805
|
+
.filter(Boolean);
|
|
806
|
+
const segments = rawSegments.length > 0 ? rawSegments : [cleaned];
|
|
807
|
+
const usableStart = Math.min(Math.round(fps * 0.25), Math.floor(durationFrames * 0.1));
|
|
808
|
+
const usableEnd = Math.max(usableStart + 10, durationFrames - Math.round(fps * 0.25));
|
|
809
|
+
const totalSpan = Math.max(1, usableEnd - usableStart);
|
|
810
|
+
const weights = segments.map(s => Math.max(4, s.length));
|
|
811
|
+
const totalWeight = weights.reduce((a, b) => a + b, 0);
|
|
812
|
+
let cursor = usableStart;
|
|
813
|
+
return segments.map((seg, idx) => {
|
|
814
|
+
const share = idx === segments.length - 1
|
|
815
|
+
? usableEnd - cursor
|
|
816
|
+
: Math.max(12, Math.round((weights[idx] / totalWeight) * totalSpan));
|
|
817
|
+
const startFrame = cursor;
|
|
818
|
+
const endFrame = Math.min(usableEnd, cursor + share);
|
|
819
|
+
cursor = endFrame;
|
|
820
|
+
return { startFrame, endFrame: Math.max(startFrame + 1, endFrame), text: seg };
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
const FORMAT_DIMENSIONS = {
|
|
824
|
+
landscape: [1920, 1080],
|
|
825
|
+
portrait: [1080, 1920],
|
|
826
|
+
square: [1080, 1080],
|
|
827
|
+
};
|
|
828
|
+
export function buildRemotionBundleFiles(manifest, options = {}) {
|
|
829
|
+
const fps = options.fps && [24, 30, 60].includes(options.fps) ? options.fps : 30;
|
|
830
|
+
const format = options.format && Object.hasOwn(FORMAT_DIMENSIONS, options.format) ? options.format : 'landscape';
|
|
831
|
+
const [width, height] = FORMAT_DIMENSIONS[format];
|
|
832
|
+
const pace = options.paceBudget ?? computePaceBudgetFallback(manifest);
|
|
833
|
+
const slides = Array.isArray(manifest?.slides) ? manifest.slides : [];
|
|
834
|
+
const palette = options.themeTokens || {};
|
|
835
|
+
const themeTokens = {
|
|
836
|
+
themeId: String(manifest?.theme || 'consulting'),
|
|
837
|
+
bg: manifest?.brand?.backgroundColor || palette.bg || '#FFFFFF',
|
|
838
|
+
panel: palette.panel || '#F8FAFC',
|
|
839
|
+
fg: manifest?.brand?.textColor || palette.fg || '#0F172A',
|
|
840
|
+
muted: palette.muted || '#475569',
|
|
841
|
+
accent: manifest?.brand?.primaryColor || palette.accent || '#0057B8',
|
|
842
|
+
accent2: manifest?.brand?.secondaryColor || palette.accent2 || '#0E7490',
|
|
843
|
+
headingFont: manifest?.brand?.headingFont || palette.headingFont || 'Microsoft YaHei, system-ui, sans-serif',
|
|
844
|
+
bodyFont: manifest?.brand?.fontFamily || palette.bodyFont || 'Microsoft YaHei, system-ui, sans-serif',
|
|
845
|
+
};
|
|
846
|
+
let frameCursor = 0;
|
|
847
|
+
const scenes = slides.map((slide, idx) => {
|
|
848
|
+
const budgetSec = pace.slides[idx]?.seconds ?? (['cover', 'closing', 'section'].includes(slide?.layout) ? 12 : 24);
|
|
849
|
+
const clampedSec = Math.max(3, Math.min(30, Math.round(budgetSec)));
|
|
850
|
+
const durationInFrames = clampedSec * fps;
|
|
851
|
+
const startFrame = frameCursor;
|
|
852
|
+
frameCursor += durationInFrames;
|
|
853
|
+
const items = (Array.isArray(slide?.items) ? slide.items : []).map((it) => {
|
|
854
|
+
const kpiParsed = parseKpiNumeric(it?.value);
|
|
855
|
+
return {
|
|
856
|
+
tag: cleanStr(it?.tag),
|
|
857
|
+
title: cleanStr(it?.title),
|
|
858
|
+
text: cleanStr(it?.text),
|
|
859
|
+
value: cleanStr(it?.value),
|
|
860
|
+
unit: cleanStr(it?.unit),
|
|
861
|
+
delta: cleanStr(it?.delta),
|
|
862
|
+
status: cleanStr(it?.status),
|
|
863
|
+
numericValue: kpiParsed.numericValue,
|
|
864
|
+
prefix: kpiParsed.prefix,
|
|
865
|
+
suffix: kpiParsed.suffix,
|
|
866
|
+
decimals: kpiParsed.decimals,
|
|
867
|
+
start: typeof it?.start === 'number' ? it.start : undefined,
|
|
868
|
+
span: typeof it?.span === 'number' ? it.span : undefined,
|
|
869
|
+
bullets: Array.isArray(it?.bullets) ? it.bullets.map((b) => cleanStr(b)).filter(Boolean) : [],
|
|
870
|
+
};
|
|
871
|
+
});
|
|
872
|
+
const chartBars = Array.isArray(slide?.chart?.series?.[0]?.values)
|
|
873
|
+
? slide.chart.series[0].values.map((val, ci) => ({
|
|
874
|
+
label: cleanStr(slide.chart.categories?.[ci] ?? `${ci + 1}`),
|
|
875
|
+
value: Number(val) || 0,
|
|
876
|
+
}))
|
|
877
|
+
: [];
|
|
878
|
+
const captionSource = cleanStr(slide?.notes) || cleanStr(slide?.takeaway) || cleanStr(slide?.subtitle) || cleanStr(slide?.title);
|
|
879
|
+
const captions = buildTimedCaptions(captionSource, durationInFrames, fps);
|
|
880
|
+
return {
|
|
881
|
+
index: idx + 1,
|
|
882
|
+
id: String(slide?.id || `slide-${idx + 1}`),
|
|
883
|
+
layout: String(slide?.layout || 'bullets'),
|
|
884
|
+
variant: cleanStr(slide?.variant),
|
|
885
|
+
kicker: cleanStr(slide?.kicker),
|
|
886
|
+
title: cleanStr(slide?.title) || `Slide ${idx + 1}`,
|
|
887
|
+
subtitle: cleanStr(slide?.subtitle),
|
|
888
|
+
takeaway: cleanStr(slide?.takeaway),
|
|
889
|
+
source: cleanStr(slide?.source),
|
|
890
|
+
formula: typeof slide?.formula === 'string' ? slide.formula.trim() : '',
|
|
891
|
+
mermaid: typeof slide?.mermaid === 'string' ? slide.mermaid.trim() : '',
|
|
892
|
+
bullets: Array.isArray(slide?.bullets) ? slide.bullets.map((b) => cleanStr(b)).filter(Boolean) : [],
|
|
893
|
+
items,
|
|
894
|
+
rows: Array.isArray(slide?.rows) ? slide.rows.slice(0, 8) : [],
|
|
895
|
+
chartBars,
|
|
896
|
+
notes: cleanStr(slide?.notes),
|
|
897
|
+
startFrame,
|
|
898
|
+
durationInFrames,
|
|
899
|
+
durationSeconds: clampedSec,
|
|
900
|
+
captions,
|
|
901
|
+
};
|
|
902
|
+
});
|
|
903
|
+
const totalFrames = Math.max(fps * 3, frameCursor);
|
|
904
|
+
const totalSeconds = Math.round((totalFrames / fps) * 10) / 10;
|
|
905
|
+
const deckTitle = cleanStr(manifest?.title) || 'Presentation Video';
|
|
906
|
+
const slidesData = {
|
|
907
|
+
schemaVersion: 1,
|
|
908
|
+
generator: 'dsh-ppt',
|
|
909
|
+
title: deckTitle,
|
|
910
|
+
language: String(manifest?.language || 'zh'),
|
|
911
|
+
fps,
|
|
912
|
+
width,
|
|
913
|
+
height,
|
|
914
|
+
totalFrames,
|
|
915
|
+
totalSeconds,
|
|
916
|
+
themeTokens,
|
|
917
|
+
slides: scenes,
|
|
918
|
+
};
|
|
919
|
+
const storyboard = {
|
|
920
|
+
schemaVersion: 1,
|
|
921
|
+
generator: 'dsh-ppt',
|
|
922
|
+
targetEngine: 'dsh-remotion',
|
|
923
|
+
compositionId: 'DeckVideo',
|
|
924
|
+
title: deckTitle,
|
|
925
|
+
fps,
|
|
926
|
+
width,
|
|
927
|
+
height,
|
|
928
|
+
totalFrames,
|
|
929
|
+
totalSeconds,
|
|
930
|
+
themeTokens,
|
|
931
|
+
paceBudget: {
|
|
932
|
+
estimatedMinutes: pace.estimatedMinutes,
|
|
933
|
+
targetMinutes: pace.targetMinutes,
|
|
934
|
+
overBudget: pace.overBudget,
|
|
935
|
+
},
|
|
936
|
+
scenes: scenes.map(sc => ({
|
|
937
|
+
index: sc.index,
|
|
938
|
+
id: sc.id,
|
|
939
|
+
layout: sc.layout,
|
|
940
|
+
title: sc.title,
|
|
941
|
+
startFrame: sc.startFrame,
|
|
942
|
+
durationInFrames: sc.durationInFrames,
|
|
943
|
+
durationSeconds: sc.durationSeconds,
|
|
944
|
+
animations: [
|
|
945
|
+
'spring-title-entrance',
|
|
946
|
+
...(sc.layout === 'kpi' ? ['kpi-numeric-countup'] : []),
|
|
947
|
+
...(sc.chartBars.length || ['sankey', 'marimekko', 'gantt', 'process'].includes(sc.layout) ? ['progressive-bar-flow'] : []),
|
|
948
|
+
...(sc.captions.length ? ['synced-subtitle-captions'] : []),
|
|
949
|
+
],
|
|
950
|
+
captions: sc.captions,
|
|
951
|
+
})),
|
|
952
|
+
};
|
|
953
|
+
const deckVideoTsx = `import React from 'react';
|
|
954
|
+
import { AbsoluteFill, Sequence, spring, interpolate, useCurrentFrame, useVideoConfig } from 'remotion';
|
|
955
|
+
import slidesData from './slides-data.json';
|
|
956
|
+
|
|
957
|
+
type SlideScene = (typeof slidesData.slides)[number];
|
|
958
|
+
|
|
959
|
+
const TOKENS = slidesData.themeTokens;
|
|
960
|
+
|
|
961
|
+
const SlideView: React.FC<{ scene: SlideScene }> = ({ scene }) => {
|
|
962
|
+
const frame = useCurrentFrame();
|
|
963
|
+
const { fps } = useVideoConfig();
|
|
964
|
+
|
|
965
|
+
const titleEnter = spring({
|
|
966
|
+
frame,
|
|
967
|
+
fps,
|
|
968
|
+
config: { damping: 15, stiffness: 120, mass: 0.8 },
|
|
969
|
+
});
|
|
970
|
+
const fadeOut = interpolate(
|
|
971
|
+
frame,
|
|
972
|
+
[Math.max(1, scene.durationInFrames - 10), scene.durationInFrames],
|
|
973
|
+
[1, 0],
|
|
974
|
+
{ extrapolateLeft: 'clamp', extrapolateRight: 'clamp' },
|
|
975
|
+
);
|
|
976
|
+
const progressGrowth = interpolate(frame, [8, 36], [0, 1], {
|
|
977
|
+
extrapolateLeft: 'clamp',
|
|
978
|
+
extrapolateRight: 'clamp',
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
const activeCaption = scene.captions.find(
|
|
982
|
+
(c) => frame >= c.startFrame && frame <= c.endFrame,
|
|
983
|
+
)?.text || scene.captions[0]?.text || '';
|
|
984
|
+
|
|
985
|
+
const maxBar = Math.max(1, ...scene.chartBars.map((b) => Math.abs(b.value)));
|
|
986
|
+
const isFraming = scene.layout === 'cover' || scene.layout === 'closing' || scene.layout === 'section';
|
|
987
|
+
|
|
988
|
+
return (
|
|
989
|
+
<AbsoluteFill
|
|
990
|
+
style={{
|
|
991
|
+
backgroundColor: isFraming ? TOKENS.accent : TOKENS.bg,
|
|
992
|
+
color: isFraming ? '#FFFFFF' : TOKENS.fg,
|
|
993
|
+
fontFamily: TOKENS.bodyFont,
|
|
994
|
+
padding: '64px 88px 110px',
|
|
995
|
+
opacity: fadeOut,
|
|
996
|
+
display: 'flex',
|
|
997
|
+
flexDirection: 'column',
|
|
998
|
+
justifyContent: isFraming ? 'center' : 'flex-start',
|
|
999
|
+
}}
|
|
1000
|
+
>
|
|
1001
|
+
<div
|
|
1002
|
+
style={{
|
|
1003
|
+
position: 'absolute',
|
|
1004
|
+
left: 0,
|
|
1005
|
+
top: 0,
|
|
1006
|
+
bottom: 0,
|
|
1007
|
+
width: 12,
|
|
1008
|
+
backgroundColor: isFraming ? TOKENS.accent2 : TOKENS.accent,
|
|
1009
|
+
}}
|
|
1010
|
+
/>
|
|
1011
|
+
|
|
1012
|
+
{scene.kicker ? (
|
|
1013
|
+
<div
|
|
1014
|
+
style={{
|
|
1015
|
+
fontSize: 22,
|
|
1016
|
+
fontWeight: 700,
|
|
1017
|
+
letterSpacing: 3,
|
|
1018
|
+
textTransform: 'uppercase',
|
|
1019
|
+
color: isFraming ? 'rgba(255,255,255,0.85)' : TOKENS.accent,
|
|
1020
|
+
marginBottom: 14,
|
|
1021
|
+
opacity: titleEnter,
|
|
1022
|
+
}}
|
|
1023
|
+
>
|
|
1024
|
+
{scene.kicker}
|
|
1025
|
+
</div>
|
|
1026
|
+
) : null}
|
|
1027
|
+
|
|
1028
|
+
<h1
|
|
1029
|
+
style={{
|
|
1030
|
+
margin: 0,
|
|
1031
|
+
fontFamily: TOKENS.headingFont,
|
|
1032
|
+
fontSize: isFraming ? 68 : 48,
|
|
1033
|
+
lineHeight: 1.18,
|
|
1034
|
+
transform: \`translateY(\${(1 - titleEnter) * 28}px)\`,
|
|
1035
|
+
opacity: titleEnter,
|
|
1036
|
+
}}
|
|
1037
|
+
>
|
|
1038
|
+
{scene.title}
|
|
1039
|
+
</h1>
|
|
1040
|
+
|
|
1041
|
+
{scene.subtitle ? (
|
|
1042
|
+
<p
|
|
1043
|
+
style={{
|
|
1044
|
+
marginTop: 14,
|
|
1045
|
+
fontSize: isFraming ? 30 : 24,
|
|
1046
|
+
color: isFraming ? 'rgba(255,255,255,0.9)' : TOKENS.muted,
|
|
1047
|
+
opacity: titleEnter,
|
|
1048
|
+
}}
|
|
1049
|
+
>
|
|
1050
|
+
{scene.subtitle}
|
|
1051
|
+
</p>
|
|
1052
|
+
) : null}
|
|
1053
|
+
|
|
1054
|
+
{scene.items.length > 0 ? (
|
|
1055
|
+
<div
|
|
1056
|
+
style={{
|
|
1057
|
+
display: 'grid',
|
|
1058
|
+
gridTemplateColumns: \`repeat(\${Math.min(3, Math.max(1, scene.items.length))}, minmax(0, 1fr))\`,
|
|
1059
|
+
gap: 24,
|
|
1060
|
+
marginTop: 32,
|
|
1061
|
+
}}
|
|
1062
|
+
>
|
|
1063
|
+
{scene.items.slice(0, 6).map((item, idx) => {
|
|
1064
|
+
const cardSpring = spring({
|
|
1065
|
+
frame: Math.max(0, frame - idx * 4),
|
|
1066
|
+
fps,
|
|
1067
|
+
config: { damping: 14, stiffness: 110 },
|
|
1068
|
+
});
|
|
1069
|
+
const animatedValue =
|
|
1070
|
+
item.numericValue !== null
|
|
1071
|
+
? (() => {
|
|
1072
|
+
const v = interpolate(frame, [6 + idx * 3, 36 + idx * 3], [0, item.numericValue], {
|
|
1073
|
+
extrapolateLeft: 'clamp',
|
|
1074
|
+
extrapolateRight: 'clamp',
|
|
1075
|
+
});
|
|
1076
|
+
return \`\${item.prefix}\${v.toFixed(item.decimals)}\${item.suffix}\`;
|
|
1077
|
+
})()
|
|
1078
|
+
: item.value;
|
|
1079
|
+
|
|
1080
|
+
return (
|
|
1081
|
+
<div
|
|
1082
|
+
key={idx}
|
|
1083
|
+
style={{
|
|
1084
|
+
backgroundColor: isFraming ? 'rgba(255,255,255,0.12)' : TOKENS.panel,
|
|
1085
|
+
border: \`1px solid \${TOKENS.muted}33\`,
|
|
1086
|
+
borderTop: \`5px solid \${TOKENS.accent}\`,
|
|
1087
|
+
borderRadius: 12,
|
|
1088
|
+
padding: '24px 26px',
|
|
1089
|
+
transform: \`translateY(\${(1 - cardSpring) * 24}px)\`,
|
|
1090
|
+
opacity: cardSpring,
|
|
1091
|
+
}}
|
|
1092
|
+
>
|
|
1093
|
+
{item.tag ? (
|
|
1094
|
+
<div style={{ fontSize: 18, fontWeight: 700, color: TOKENS.accent, marginBottom: 6 }}>
|
|
1095
|
+
{item.tag}
|
|
1096
|
+
</div>
|
|
1097
|
+
) : null}
|
|
1098
|
+
{animatedValue ? (
|
|
1099
|
+
<div style={{ fontSize: 54, fontWeight: 800, color: TOKENS.accent, lineHeight: 1.1 }}>
|
|
1100
|
+
{animatedValue}
|
|
1101
|
+
{item.unit ? <span style={{ fontSize: 24, marginLeft: 4 }}>{item.unit}</span> : null}
|
|
1102
|
+
</div>
|
|
1103
|
+
) : null}
|
|
1104
|
+
{item.title ? <div style={{ fontSize: 26, fontWeight: 700, marginTop: 8 }}>{item.title}</div> : null}
|
|
1105
|
+
{item.text ? (
|
|
1106
|
+
<div style={{ fontSize: 20, color: isFraming ? 'rgba(255,255,255,0.86)' : TOKENS.muted, marginTop: 8 }}>
|
|
1107
|
+
{item.text}
|
|
1108
|
+
</div>
|
|
1109
|
+
) : null}
|
|
1110
|
+
{item.span !== undefined ? (
|
|
1111
|
+
<div style={{ marginTop: 14, height: 12, borderRadius: 99, backgroundColor: \`\${TOKENS.muted}26\`, overflow: 'hidden' }}>
|
|
1112
|
+
<div
|
|
1113
|
+
style={{
|
|
1114
|
+
height: '100%',
|
|
1115
|
+
width: \`\${Math.min(100, Math.max(15, item.span * 25)) * progressGrowth}%\`,
|
|
1116
|
+
backgroundColor: TOKENS.accent2,
|
|
1117
|
+
borderRadius: 99,
|
|
1118
|
+
}}
|
|
1119
|
+
/>
|
|
1120
|
+
</div>
|
|
1121
|
+
) : null}
|
|
1122
|
+
</div>
|
|
1123
|
+
);
|
|
1124
|
+
})}
|
|
1125
|
+
</div>
|
|
1126
|
+
) : null}
|
|
1127
|
+
|
|
1128
|
+
{scene.chartBars.length > 0 ? (
|
|
1129
|
+
<div style={{ marginTop: 32, display: 'flex', flexDirection: 'column', gap: 16 }}>
|
|
1130
|
+
{scene.chartBars.slice(0, 6).map((bar, bi) => (
|
|
1131
|
+
<div key={bi} style={{ display: 'flex', alignItems: 'center', gap: 18 }}>
|
|
1132
|
+
<div style={{ width: 220, fontSize: 22, fontWeight: 600 }}>{bar.label}</div>
|
|
1133
|
+
<div style={{ flex: 1, height: 28, backgroundColor: \`\${TOKENS.muted}22\`, borderRadius: 8, overflow: 'hidden' }}>
|
|
1134
|
+
<div
|
|
1135
|
+
style={{
|
|
1136
|
+
height: '100%',
|
|
1137
|
+
width: \`\${(Math.abs(bar.value) / maxBar) * 100 * progressGrowth}%\`,
|
|
1138
|
+
backgroundColor: bi === 0 ? TOKENS.accent : TOKENS.accent2,
|
|
1139
|
+
}}
|
|
1140
|
+
/>
|
|
1141
|
+
</div>
|
|
1142
|
+
<div style={{ width: 120, fontSize: 22, fontWeight: 700, textAlign: 'right' }}>{bar.value}</div>
|
|
1143
|
+
</div>
|
|
1144
|
+
))}
|
|
1145
|
+
</div>
|
|
1146
|
+
) : null}
|
|
1147
|
+
|
|
1148
|
+
{scene.bullets.length > 0 && scene.items.length === 0 ? (
|
|
1149
|
+
<ul style={{ marginTop: 28, paddingLeft: 32, fontSize: 28, lineHeight: 1.65 }}>
|
|
1150
|
+
{scene.bullets.slice(0, 6).map((b, bi) => {
|
|
1151
|
+
const bulletOpacity = interpolate(frame, [6 + bi * 5, 18 + bi * 5], [0, 1], {
|
|
1152
|
+
extrapolateLeft: 'clamp',
|
|
1153
|
+
extrapolateRight: 'clamp',
|
|
1154
|
+
});
|
|
1155
|
+
return (
|
|
1156
|
+
<li key={bi} style={{ marginBottom: 12, opacity: bulletOpacity }}>
|
|
1157
|
+
{b}
|
|
1158
|
+
</li>
|
|
1159
|
+
);
|
|
1160
|
+
})}
|
|
1161
|
+
</ul>
|
|
1162
|
+
) : null}
|
|
1163
|
+
|
|
1164
|
+
{scene.takeaway ? (
|
|
1165
|
+
<div
|
|
1166
|
+
style={{
|
|
1167
|
+
marginTop: 'auto',
|
|
1168
|
+
padding: '16px 22px',
|
|
1169
|
+
borderRadius: 10,
|
|
1170
|
+
backgroundColor: isFraming ? 'rgba(255,255,255,0.14)' : \`\${TOKENS.accent}14\`,
|
|
1171
|
+
borderLeft: \`6px solid \${TOKENS.accent}\`,
|
|
1172
|
+
fontSize: 24,
|
|
1173
|
+
fontWeight: 600,
|
|
1174
|
+
}}
|
|
1175
|
+
>
|
|
1176
|
+
{scene.takeaway}
|
|
1177
|
+
</div>
|
|
1178
|
+
) : null}
|
|
1179
|
+
|
|
1180
|
+
{activeCaption ? (
|
|
1181
|
+
<div
|
|
1182
|
+
style={{
|
|
1183
|
+
position: 'absolute',
|
|
1184
|
+
left: 88,
|
|
1185
|
+
right: 88,
|
|
1186
|
+
bottom: 28,
|
|
1187
|
+
textAlign: 'center',
|
|
1188
|
+
pointerEvents: 'none',
|
|
1189
|
+
}}
|
|
1190
|
+
>
|
|
1191
|
+
<span
|
|
1192
|
+
style={{
|
|
1193
|
+
display: 'inline-block',
|
|
1194
|
+
padding: '10px 24px',
|
|
1195
|
+
borderRadius: 999,
|
|
1196
|
+
backgroundColor: 'rgba(15, 23, 42, 0.84)',
|
|
1197
|
+
color: '#F8FAFC',
|
|
1198
|
+
fontSize: 24,
|
|
1199
|
+
lineHeight: 1.4,
|
|
1200
|
+
}}
|
|
1201
|
+
>
|
|
1202
|
+
{activeCaption}
|
|
1203
|
+
</span>
|
|
1204
|
+
</div>
|
|
1205
|
+
) : null}
|
|
1206
|
+
</AbsoluteFill>
|
|
1207
|
+
);
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
export const DeckVideo: React.FC = () => {
|
|
1211
|
+
return (
|
|
1212
|
+
<AbsoluteFill style={{ backgroundColor: TOKENS.bg }}>
|
|
1213
|
+
{slidesData.slides.map((scene) => (
|
|
1214
|
+
<Sequence
|
|
1215
|
+
key={scene.id}
|
|
1216
|
+
from={scene.startFrame}
|
|
1217
|
+
durationInFrames={scene.durationInFrames}
|
|
1218
|
+
name={\`Slide-\${scene.index}\`}
|
|
1219
|
+
>
|
|
1220
|
+
<SlideView scene={scene} />
|
|
1221
|
+
</Sequence>
|
|
1222
|
+
))}
|
|
1223
|
+
</AbsoluteFill>
|
|
1224
|
+
);
|
|
1225
|
+
};
|
|
1226
|
+
`;
|
|
1227
|
+
const indexTs = `import React from 'react';
|
|
1228
|
+
import { registerRoot, Composition } from 'remotion';
|
|
1229
|
+
import { DeckVideo } from './DeckVideo';
|
|
1230
|
+
import slidesData from './slides-data.json';
|
|
1231
|
+
|
|
1232
|
+
const RemotionRoot: React.FC = () => {
|
|
1233
|
+
return (
|
|
1234
|
+
<Composition
|
|
1235
|
+
id="DeckVideo"
|
|
1236
|
+
component={DeckVideo}
|
|
1237
|
+
durationInFrames={slidesData.totalFrames}
|
|
1238
|
+
fps={slidesData.fps}
|
|
1239
|
+
width={slidesData.width}
|
|
1240
|
+
height={slidesData.height}
|
|
1241
|
+
/>
|
|
1242
|
+
);
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
registerRoot(RemotionRoot);
|
|
1246
|
+
`;
|
|
1247
|
+
const pkgJson = JSON.stringify({
|
|
1248
|
+
name: 'dsh-ppt-remotion-video',
|
|
1249
|
+
private: true,
|
|
1250
|
+
version: '1.0.0',
|
|
1251
|
+
scripts: {
|
|
1252
|
+
preview: 'remotion studio src/index.ts --no-open',
|
|
1253
|
+
render: 'remotion render src/index.ts DeckVideo out/deck-video.mp4 --concurrency 1 --codec h264',
|
|
1254
|
+
},
|
|
1255
|
+
dependencies: {
|
|
1256
|
+
'@remotion/cli': REMOTION_VERSION,
|
|
1257
|
+
remotion: REMOTION_VERSION,
|
|
1258
|
+
react: '18.3.1',
|
|
1259
|
+
'react-dom': '18.3.1',
|
|
1260
|
+
},
|
|
1261
|
+
devDependencies: {
|
|
1262
|
+
'@types/react': '18.3.12',
|
|
1263
|
+
typescript: '5.6.3',
|
|
1264
|
+
},
|
|
1265
|
+
}, null, 2);
|
|
1266
|
+
const sceneTable = scenes
|
|
1267
|
+
.map(sc => `| ${sc.index} | ${sc.layout} | ${sc.title.replace(/\|/g, '\\|')} | ${sc.startFrame} | ${sc.durationInFrames} (${sc.durationSeconds}s) |`)
|
|
1268
|
+
.join('\n');
|
|
1269
|
+
const readme = `# ${deckTitle} — Remotion Storyboard Bundle
|
|
1270
|
+
|
|
1271
|
+
Generated by **dsh-ppt** for **dsh-remotion** / Remotion ${REMOTION_VERSION}.
|
|
1272
|
+
|
|
1273
|
+
- **Canvas**: \`${width}x${height}\` @ \`${fps} fps\`
|
|
1274
|
+
- **Total Duration**: \`${totalSeconds}s\` (\`${totalFrames}\` frames across ${scenes.length} slides)
|
|
1275
|
+
- **Theme**: \`${themeTokens.themeId}\` (\`accent: ${themeTokens.accent}\`, \`bg: ${themeTokens.bg}\`)
|
|
1276
|
+
|
|
1277
|
+
## Quick Start
|
|
1278
|
+
|
|
1279
|
+
\`\`\`bash
|
|
1280
|
+
npm install
|
|
1281
|
+
npm run preview
|
|
1282
|
+
npm run render
|
|
1283
|
+
\`\`\`
|
|
1284
|
+
|
|
1285
|
+
## Storyboard Timeline
|
|
1286
|
+
|
|
1287
|
+
| # | Layout | Title | Start Frame | Duration |
|
|
1288
|
+
| --- | --- | --- | --- | --- |
|
|
1289
|
+
${sceneTable}
|
|
1290
|
+
`;
|
|
1291
|
+
return {
|
|
1292
|
+
files: {
|
|
1293
|
+
'remotion-storyboard.json': JSON.stringify(storyboard, null, 2),
|
|
1294
|
+
'src/slides-data.json': JSON.stringify(slidesData, null, 2),
|
|
1295
|
+
'src/DeckVideo.tsx': deckVideoTsx,
|
|
1296
|
+
'src/index.ts': indexTs,
|
|
1297
|
+
'package.json': pkgJson,
|
|
1298
|
+
'README.md': readme,
|
|
1299
|
+
},
|
|
1300
|
+
storyboard,
|
|
1301
|
+
fps,
|
|
1302
|
+
totalFrames,
|
|
1303
|
+
totalSeconds,
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
export async function exportRemotionBundle(options) {
|
|
1307
|
+
options.signal?.throwIfAborted();
|
|
1308
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1309
|
+
const deckPath = resolve(cwd, options.deckPath);
|
|
1310
|
+
const { manifest } = readManifestFromDeck(deckPath, options.engine);
|
|
1311
|
+
const resolvedTheme = typeof options.engine.resolveTheme === 'function'
|
|
1312
|
+
? options.engine.resolveTheme(manifest.theme)
|
|
1313
|
+
: undefined;
|
|
1314
|
+
const palette = (resolvedTheme?.palette ?? {});
|
|
1315
|
+
const paceBudget = typeof options.engine.computePaceBudget === 'function'
|
|
1316
|
+
? options.engine.computePaceBudget(manifest, manifest.targetMinutes)
|
|
1317
|
+
: computePaceBudgetFallback(manifest);
|
|
1318
|
+
const bundle = buildRemotionBundleFiles(manifest, {
|
|
1319
|
+
fps: options.fps,
|
|
1320
|
+
format: options.format,
|
|
1321
|
+
themeTokens: palette,
|
|
1322
|
+
paceBudget,
|
|
1323
|
+
});
|
|
1324
|
+
const baseName = basename(deckPath, '.json') + '-remotion';
|
|
1325
|
+
let outDir = options.outputDir?.trim()
|
|
1326
|
+
? resolve(cwd, options.outputDir.trim())
|
|
1327
|
+
: join(dirname(deckPath), baseName);
|
|
1328
|
+
if (!options.overwrite && existsSync(outDir)) {
|
|
1329
|
+
let n = 2;
|
|
1330
|
+
while (existsSync(`${outDir}-${n}`))
|
|
1331
|
+
n++;
|
|
1332
|
+
outDir = `${outDir}-${n}`;
|
|
1333
|
+
}
|
|
1334
|
+
mkdirSync(join(outDir, 'src'), { recursive: true });
|
|
1335
|
+
const writtenFiles = [];
|
|
1336
|
+
for (const [relPath, content] of Object.entries(bundle.files)) {
|
|
1337
|
+
const abs = join(outDir, relPath);
|
|
1338
|
+
mkdirSync(dirname(abs), { recursive: true });
|
|
1339
|
+
writeFileSync(abs, content, 'utf8');
|
|
1340
|
+
writtenFiles.push(abs);
|
|
1341
|
+
}
|
|
1342
|
+
return {
|
|
1343
|
+
ok: true,
|
|
1344
|
+
outputDir: outDir,
|
|
1345
|
+
storyboardPath: join(outDir, 'remotion-storyboard.json'),
|
|
1346
|
+
files: writtenFiles,
|
|
1347
|
+
fps: bundle.fps,
|
|
1348
|
+
totalFrames: bundle.totalFrames,
|
|
1349
|
+
totalSeconds: bundle.totalSeconds,
|
|
1350
|
+
slideCount: Array.isArray(manifest.slides) ? manifest.slides.length : 0,
|
|
1351
|
+
};
|
|
1352
|
+
}
|