@joplo-app/server 0.2.17 → 0.3.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/dist/binary-assets.d.ts +6 -0
- package/dist/binary-assets.js +25 -0
- package/dist/build.d.ts +8 -1
- package/dist/build.js +90 -5
- package/dist/cloud.d.ts +129 -2
- package/dist/cloud.js +29 -6
- package/dist/contract.d.ts +73 -0
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +140 -5
- package/dist/export.d.ts +2 -1
- package/dist/export.js +22 -3
- package/dist/film.d.ts +27 -0
- package/dist/film.js +263 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -1
- package/dist/local-resources.d.ts +47 -0
- package/dist/local-resources.js +368 -0
- package/dist/local-review.js +2 -1
- package/dist/media-calibration.d.ts +8 -0
- package/dist/media-calibration.js +67 -0
- package/dist/media-check.d.ts +9 -0
- package/dist/media-check.js +56 -0
- package/dist/media-mux.d.ts +9 -0
- package/dist/media-mux.js +68 -0
- package/dist/page-report.js +9 -0
- package/dist/plugin-assets.d.ts +5 -0
- package/dist/plugin-assets.js +35 -0
- package/dist/plugin-keys.d.ts +35 -0
- package/dist/plugin-keys.js +66 -0
- package/dist/project.d.ts +10 -0
- package/dist/project.js +33 -6
- package/dist/render.d.ts +7 -1
- package/dist/render.js +80 -0
- package/dist/resources-run.d.ts +31 -0
- package/dist/resources-run.js +43 -0
- package/dist/voice-http.d.ts +53 -4
- package/dist/voice-http.js +167 -39
- package/dist/voice-run.d.ts +71 -0
- package/dist/voice-run.js +98 -0
- package/dist/voice.d.ts +188 -62
- package/dist/voice.js +492 -274
- package/dist/web-assets.js +3 -3
- package/package.json +5 -5
package/dist/dev.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { PluginKeyStore } from "./plugin-keys.js";
|
|
2
|
+
import { binaryAssets } from "./binary-assets.js";
|
|
3
|
+
import { inlineResources, referencedResources } from "./local-resources.js";
|
|
1
4
|
/**
|
|
2
5
|
* `joplo dev`:本机只运行一个看板进程(D39),同时服务多个项目。
|
|
3
6
|
*
|
|
@@ -13,6 +16,7 @@
|
|
|
13
16
|
* 端口被占用时直接报错(strictPort),不静默换端口。
|
|
14
17
|
*/
|
|
15
18
|
import { spawn } from 'node:child_process';
|
|
19
|
+
import { bundlePluginRuntimes } from "./build.js";
|
|
16
20
|
import crypto from 'node:crypto';
|
|
17
21
|
import fs from 'node:fs';
|
|
18
22
|
import path from 'node:path';
|
|
@@ -27,6 +31,17 @@ import { Registry, clearServerInfo, joploHome, normalizeSettings, pidAlive, proj
|
|
|
27
31
|
import { compileProject, invalidateProjectModules } from "./project.js";
|
|
28
32
|
import { SelectionBody, readSelection, resolveSelection, writeSelection } from "./selection.js";
|
|
29
33
|
import { IGNORED_DIRS, cssSourcePlugin, isProjectSource, joploProjectPlugin, kitAliases, locateWebAssets, realProjectDir } from "./vite-shared.js";
|
|
34
|
+
/** 文件绝对路径 → Vite 的 /@fs/ 地址。 */
|
|
35
|
+
const fsUrl = (abs) => `/@fs${abs.split(path.sep).join('/').replace(/^(?!\/)/, '/')}`;
|
|
36
|
+
/** 离文件最近的 package.json 所在目录(插件包根目录);没有时用文件所在目录。 */
|
|
37
|
+
function packageRootOf(file) {
|
|
38
|
+
for (let d = path.dirname(file);; d = path.dirname(d)) {
|
|
39
|
+
if (fs.existsSync(path.join(d, 'package.json')))
|
|
40
|
+
return d;
|
|
41
|
+
if (path.dirname(d) === d)
|
|
42
|
+
return path.dirname(file);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
30
45
|
export const IR_EVENT = 'joplo:ir';
|
|
31
46
|
export const PROJECTS_EVENT = 'joplo:projects';
|
|
32
47
|
/** 朗读状态变化(D74):{ projectId, state }。 */
|
|
@@ -201,7 +216,7 @@ export async function createHub(opts = {}) {
|
|
|
201
216
|
root: slot.dir,
|
|
202
217
|
appType: 'custom',
|
|
203
218
|
customLogger: makeLogger(log),
|
|
204
|
-
resolve: { alias: kitAliases(web, slot.dir) },
|
|
219
|
+
resolve: { dedupe: ['react', 'react-dom'], alias: kitAliases(web, slot.dir) },
|
|
205
220
|
plugins: [joploProjectPlugin(slot.dir, web)],
|
|
206
221
|
// 只在服务端载入模块:不开 HMR、不开 WebSocket(多个项目同时运行时不能争用端口)、不监听
|
|
207
222
|
server: { middlewareMode: true, hmr: false, ws: false, watch: null },
|
|
@@ -209,12 +224,60 @@ export async function createHub(opts = {}) {
|
|
|
209
224
|
cacheDir: path.join(slot.dir, '.joplo/vite'),
|
|
210
225
|
});
|
|
211
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* 插件运行时由看板的 Vite 服务以 /@fs/ 提供(D86)。dist 形态的 fs.allow 只有 @joplo-app/web:
|
|
229
|
+
* 把项目目录(npm 安装的插件与它的依赖在 node_modules 里)和插件包目录加进去。source 形态也可能打开工作区外的项目,同样补齐其显式启用的插件目录。
|
|
230
|
+
*/
|
|
231
|
+
function allowPluginFiles(projectDir, runtimes) {
|
|
232
|
+
if (!server)
|
|
233
|
+
return;
|
|
234
|
+
const allow = server.config.server.fs.allow;
|
|
235
|
+
for (const dir of [projectDir, ...runtimes.map(packageRootOf)])
|
|
236
|
+
if (!allow.some((a) => dir === a || dir.startsWith(a + path.sep)))
|
|
237
|
+
allow.push(dir);
|
|
238
|
+
}
|
|
239
|
+
const localResources = new Map();
|
|
240
|
+
const resourceWarnings = new Map();
|
|
212
241
|
async function recompile(slot) {
|
|
213
242
|
const loader = slot.loader;
|
|
214
243
|
invalidateProjectModules(loader, slot.dir);
|
|
215
244
|
const out = await compileProject(loader, slot.dir, 'dev');
|
|
245
|
+
if (out.resources)
|
|
246
|
+
localResources.set(slot.id, out.resources);
|
|
247
|
+
else
|
|
248
|
+
localResources.delete(slot.id);
|
|
249
|
+
resourceWarnings.set(slot.id, new Map());
|
|
250
|
+
if (out.project && out.resources?.requests.length)
|
|
251
|
+
out.project.mediaAssets = Object.fromEntries(out.resources.requests.map(r => [r.id, `/__joplo/p/${encodeURIComponent(slot.id)}/resources/${encodeURIComponent(r.id)}`]));
|
|
252
|
+
if (out.project) {
|
|
253
|
+
if (out.resources) {
|
|
254
|
+
const resources = await inlineResources(out.project, out.resources.requests.filter(r => referencedResources(out.project).has(r.id)), out.resources.host);
|
|
255
|
+
out.project.mediaAssets = { ...out.project.mediaAssets, ...resources.assets };
|
|
256
|
+
}
|
|
257
|
+
out.project = binaryAssets(out.project, { directory: path.join(slot.dir, '.joplo', 'binary'), prefix: `/__joplo/p/${encodeURIComponent(slot.id)}/binary/`, diagnostics: out.diagnostics });
|
|
258
|
+
}
|
|
216
259
|
const prev = slot.payload;
|
|
217
|
-
|
|
260
|
+
const plugins = out.pluginRuntimes;
|
|
261
|
+
let runtimeUrls = {};
|
|
262
|
+
if (web.mode === 'dist' && out.project) {
|
|
263
|
+
// A prebuilt board owns React. Bundle npm/CommonJS dependencies and bridge
|
|
264
|
+
// React to that exact host instance, just as the file:// publish path does.
|
|
265
|
+
const ids = Object.keys(plugins).sort();
|
|
266
|
+
const modules = await bundlePluginRuntimes(plugins, slot.dir, web, 'module');
|
|
267
|
+
const next = new Map();
|
|
268
|
+
ids.forEach((id, i) => {
|
|
269
|
+
const code = modules[i];
|
|
270
|
+
const key = `${id}-${crypto.createHash('sha256').update(code).digest('hex').slice(0, 20)}.js`;
|
|
271
|
+
next.set(key, code);
|
|
272
|
+
runtimeUrls[id] = `/__joplo/p/${encodeURIComponent(slot.id)}/runtime/${key}`;
|
|
273
|
+
});
|
|
274
|
+
slot.runtimeModules = next;
|
|
275
|
+
}
|
|
276
|
+
else if (web.mode === 'source') {
|
|
277
|
+
allowPluginFiles(slot.dir, Object.values(plugins));
|
|
278
|
+
runtimeUrls = Object.fromEntries(Object.entries(plugins).map(([id, f]) => [id, fsUrl(f)]));
|
|
279
|
+
}
|
|
280
|
+
slot.payload = { version: prev.version + 1, ok: out.project !== null, project: out.project ?? prev.project, diagnostics: out.diagnostics, home: out.home ?? prev.home, plugins: out.project ? runtimeUrls : prev.plugins ?? runtimeUrls };
|
|
218
281
|
const errors = out.diagnostics.filter((d) => d.severity === 'error');
|
|
219
282
|
if (errors.length)
|
|
220
283
|
log(`[joplo] ${path.basename(slot.dir)} compilation failed (${errors.length}): ${errors.map((d) => `${d.at ?? ''} ${d.message}`).join('; ').slice(0, 400)}`);
|
|
@@ -265,6 +328,7 @@ export async function createHub(opts = {}) {
|
|
|
265
328
|
loader: null,
|
|
266
329
|
ready: Promise.resolve(),
|
|
267
330
|
payload: { version: 0, ok: false, project: null, diagnostics: [], home: null },
|
|
331
|
+
runtimeModules: new Map(),
|
|
268
332
|
compiling: true,
|
|
269
333
|
closed: false,
|
|
270
334
|
running: null,
|
|
@@ -336,7 +400,10 @@ export async function createHub(opts = {}) {
|
|
|
336
400
|
onEvent: () => undefined,
|
|
337
401
|
});
|
|
338
402
|
// 朗读(D74):声音供应商 profile(本机)与项目音频缓存;状态变化推 joplo:voice
|
|
403
|
+
const pluginKeys = new PluginKeyStore(opts.home ?? joploHome());
|
|
339
404
|
const voiceHub = new VoiceHub(opts.home ?? joploHome(), {
|
|
405
|
+
// 托管朗读(D85):CLI 注入的登录与合成;旧 CLI 没有时只用浏览器朗读与自带 Key 的供应商
|
|
406
|
+
cloud: opts.cloud?.voice,
|
|
340
407
|
emit: (projectId, state) => {
|
|
341
408
|
if (!closed)
|
|
342
409
|
server?.ws.send({ type: 'custom', event: VOICE_EVENT, data: { projectId, state } });
|
|
@@ -373,8 +440,10 @@ export async function createHub(opts = {}) {
|
|
|
373
440
|
try {
|
|
374
441
|
return { ok: true, body: JSON.parse(raw.text) };
|
|
375
442
|
}
|
|
376
|
-
catch
|
|
377
|
-
|
|
443
|
+
catch {
|
|
444
|
+
// SyntaxError messages can include request fragments, including unsaved credentials.
|
|
445
|
+
// Keep the shared parser safe for every caller; never return or log the original error.
|
|
446
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'Request body is not valid JSON' } }), { ok: false };
|
|
378
447
|
}
|
|
379
448
|
};
|
|
380
449
|
const fail = (res, e) => {
|
|
@@ -384,6 +453,30 @@ export async function createHub(opts = {}) {
|
|
|
384
453
|
};
|
|
385
454
|
async function handleProject(id, rest, req, res) {
|
|
386
455
|
const method = req.method ?? 'GET';
|
|
456
|
+
if (rest === 'plugin-keys' || rest.startsWith('plugin-keys/')) {
|
|
457
|
+
if (!guardWrite(req, res, 403, method === 'PUT'))
|
|
458
|
+
return;
|
|
459
|
+
await ensure(id);
|
|
460
|
+
const declarations = localResources.get(id)?.host.keys ?? {};
|
|
461
|
+
if (rest === 'plugin-keys' && method === 'GET')
|
|
462
|
+
return sendJson(res, 200, Object.entries(declarations).flatMap(([plugin, keys]) => keys.map(key => pluginKeys.status(plugin, key))));
|
|
463
|
+
const match = /^plugin-keys\/([a-z][a-z0-9-]*)\/([a-z][a-z0-9-]*)$/.exec(rest);
|
|
464
|
+
const declaration = match && Object.hasOwn(declarations, match[1]) ? declarations[match[1]].find(key => key.id === match[2]) : undefined;
|
|
465
|
+
if (!match || !declaration)
|
|
466
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: 'Plugin key is not declared by this project' } });
|
|
467
|
+
if (method === 'PUT') {
|
|
468
|
+
const parsed = await jsonBody(req, res);
|
|
469
|
+
if (!parsed.ok)
|
|
470
|
+
return;
|
|
471
|
+
try {
|
|
472
|
+
return sendJson(res, 200, pluginKeys.save(match[1], declaration, parsed.body?.key));
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
return sendJson(res, 400, { error: { code: 'INVALID_KEY', message: 'Invalid plugin API key' } });
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return sendJson(res, 405, { error: { code: 'METHOD_NOT_ALLOWED', message: 'Method not allowed' } });
|
|
479
|
+
}
|
|
387
480
|
if (rest === 'review' && (method === 'GET' || method === 'POST')) {
|
|
388
481
|
if (!guardWrite(req, res, 403, method === 'POST'))
|
|
389
482
|
return;
|
|
@@ -404,6 +497,14 @@ export async function createHub(opts = {}) {
|
|
|
404
497
|
throw new JoploError('USAGE', 'Invalid review request: include a sessionId, requestId, type, and page context for feedback (1–10000 characters)');
|
|
405
498
|
return sendJson(res, 200, reviewHub.write(slot.dir, slot.payload.project, input.data));
|
|
406
499
|
}
|
|
500
|
+
if (rest.startsWith('runtime/') && method === 'GET') {
|
|
501
|
+
const slot = await ensure(id), code = slot.runtimeModules.get(rest.slice('runtime/'.length));
|
|
502
|
+
if (code === undefined)
|
|
503
|
+
throw new JoploError('NOT_FOUND', 'Plugin runtime is not available for this project revision');
|
|
504
|
+
res.writeHead(200, { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'no-cache', 'x-content-type-options': 'nosniff' });
|
|
505
|
+
res.end(code);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
407
508
|
if (rest === 'ir' && method === 'GET') {
|
|
408
509
|
const slot = await ensure(id);
|
|
409
510
|
return sendJson(res, 200, { projectId: id, ...slot.payload });
|
|
@@ -456,6 +557,40 @@ export async function createHub(opts = {}) {
|
|
|
456
557
|
req.method = 'GET';
|
|
457
558
|
return 'next';
|
|
458
559
|
}
|
|
560
|
+
if (rest.startsWith('binary/') && method === 'GET') {
|
|
561
|
+
const slot = await ensure(id), match = /^binary\/([a-f0-9]{64})\.(glb|audio)$/.exec(rest);
|
|
562
|
+
if (!match)
|
|
563
|
+
return sendJson(res, 404, { error: 'Unknown binary asset' });
|
|
564
|
+
const file = path.join(slot.dir, '.joplo', 'binary', match[1]);
|
|
565
|
+
if (!fs.existsSync(file))
|
|
566
|
+
return sendJson(res, 404, { error: 'Missing binary asset' });
|
|
567
|
+
res.setHeader('Content-Type', match[2] === 'glb' ? 'model/gltf-binary' : 'application/octet-stream');
|
|
568
|
+
res.end(fs.readFileSync(file));
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (rest.startsWith('resources/') && method === 'POST') {
|
|
572
|
+
if (!guardWrite(req, res))
|
|
573
|
+
return;
|
|
574
|
+
const slot = await ensure(id), local = localResources.get(id);
|
|
575
|
+
const request = local?.requests.find(r => r.id === rest.slice('resources/'.length));
|
|
576
|
+
if (!request || !local)
|
|
577
|
+
return sendJson(res, 404, { error: 'Unknown resource' });
|
|
578
|
+
const version = slot.payload.version;
|
|
579
|
+
const result = await local.host.ensure(request);
|
|
580
|
+
if (slot.payload.version === version) {
|
|
581
|
+
const warnings = resourceWarnings.get(id);
|
|
582
|
+
if (result.diagnostic)
|
|
583
|
+
warnings.set(request.id, result.diagnostic);
|
|
584
|
+
else
|
|
585
|
+
warnings.delete(request.id);
|
|
586
|
+
const diagnostics = [...slot.payload.diagnostics.filter(d => !d.code.startsWith('LOCAL_RESOURCE_')), ...warnings.values()];
|
|
587
|
+
if (JSON.stringify(diagnostics) !== JSON.stringify(slot.payload.diagnostics)) {
|
|
588
|
+
slot.payload = { ...slot.payload, diagnostics };
|
|
589
|
+
server?.ws.send({ type: 'custom', event: 'joplo:diagnostics', data: { projectId: id, version, diagnostics } });
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return sendJson(res, 200, result);
|
|
593
|
+
}
|
|
459
594
|
if (rest === 'voice' || rest.startsWith('voice/')) {
|
|
460
595
|
const slot = await ensure(id);
|
|
461
596
|
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
@@ -587,7 +722,7 @@ export async function createHub(opts = {}) {
|
|
|
587
722
|
appType: 'spa',
|
|
588
723
|
clearScreen: false,
|
|
589
724
|
customLogger: makeLogger(log),
|
|
590
|
-
resolve: { alias: web.mode === 'source' ? kitAliases(web, web.webDir) : [] },
|
|
725
|
+
resolve: { dedupe: ['react', 'react-dom'], alias: web.mode === 'source' ? kitAliases(web, web.webDir) : [] },
|
|
591
726
|
plugins: [cssSourcePlugin(activeDirs, web), boardPlugin, ...(await webPlugins(web))],
|
|
592
727
|
// dist 形态不往 node_modules 里写缓存(可能只读,或被多个项目共享)
|
|
593
728
|
cacheDir: web.mode === 'dist' ? path.join(opts.home ?? path.join(process.cwd(), '.joplo'), 'vite') : path.join(web.webDir, 'node_modules/.vite-joplo'),
|
package/dist/export.d.ts
CHANGED
|
@@ -36,7 +36,8 @@ export type VideoRecorder = (input: {
|
|
|
36
36
|
out: string;
|
|
37
37
|
total: number;
|
|
38
38
|
progress: (step: number) => void;
|
|
39
|
-
signal: AbortSignal;
|
|
39
|
+
signal: AbortSignal; /** 最长录制时长(毫秒,默认 5 分钟)。 */
|
|
40
|
+
maxMs?: number;
|
|
40
41
|
}) => Promise<void>;
|
|
41
42
|
export type ExportDeps = {
|
|
42
43
|
/** 按项目解析 Playwright(托管运行时优先,其次项目里已有的)。 */
|
package/dist/export.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
*
|
|
18
18
|
* 字段流向:job(写入点:这里的 runJob)→ jobs Map(存储)→ SSE / GET(读取点)→ 看板的导出视频弹窗(消费者)。
|
|
19
19
|
*/
|
|
20
|
+
import { recordedCalibration } from "./media-calibration.js";
|
|
21
|
+
import { muxRecordedAudio } from "./media-mux.js";
|
|
20
22
|
import crypto from 'node:crypto';
|
|
21
23
|
import fs from 'node:fs';
|
|
22
24
|
import path from 'node:path';
|
|
@@ -70,7 +72,7 @@ async function waitReady(page) {
|
|
|
70
72
|
}
|
|
71
73
|
/** 缺省的录制:Playwright recordVideo + 渲染路由的录制模式(window.__JOPLO_RECORD__)。 */
|
|
72
74
|
export function defaultRecorder(load) {
|
|
73
|
-
return async ({ projectDir, url, size, out, progress, signal }) => {
|
|
75
|
+
return async ({ projectDir, url, size, out, progress, signal, maxMs = 5 * 60_000 }) => {
|
|
74
76
|
const pw = await load(projectDir);
|
|
75
77
|
const browser = await launch(pw);
|
|
76
78
|
const tmp = fs.mkdtempSync(path.join(path.dirname(out), '.rec-'));
|
|
@@ -91,16 +93,33 @@ export function defaultRecorder(load) {
|
|
|
91
93
|
progress(p.step);
|
|
92
94
|
if (p.done)
|
|
93
95
|
break;
|
|
94
|
-
if (Date.now() - t0 >
|
|
95
|
-
throw new JoploError('EXPORT_FAILED',
|
|
96
|
+
if (Date.now() - t0 > maxMs)
|
|
97
|
+
throw new JoploError('EXPORT_FAILED', `Recording exceeded ${Math.round(maxMs / 60000)} minutes and was stopped`);
|
|
96
98
|
await page.waitForTimeout(150);
|
|
97
99
|
}
|
|
98
100
|
await page.waitForTimeout(900); // 停留在结果画面
|
|
101
|
+
const calibrated = await page.evaluate(() => window.__JOPLO_RECORD__.calibrate?.() ?? false);
|
|
102
|
+
const audio = await page.evaluate(() => window.__JOPLO_RECORD__.stopAudio?.() ?? null);
|
|
99
103
|
const video = page.video();
|
|
100
104
|
await ctx.close();
|
|
101
105
|
if (!video)
|
|
102
106
|
throw new JoploError('EXPORT_FAILED', 'The browser did not generate a video');
|
|
103
107
|
await video.saveAs(out);
|
|
108
|
+
if (audio) {
|
|
109
|
+
if (!calibrated)
|
|
110
|
+
throw new Error('Audio/video calibration unavailable');
|
|
111
|
+
const analysis = await browser.newContext();
|
|
112
|
+
const probe = await analysis.newPage();
|
|
113
|
+
await probe.goto(url, { waitUntil: 'domcontentloaded' });
|
|
114
|
+
try {
|
|
115
|
+
const bytes = Buffer.from(audio.data, 'base64');
|
|
116
|
+
const timing = await recordedCalibration(probe, out, bytes);
|
|
117
|
+
await muxRecordedAudio(out, bytes, timing.offsetSeconds, { videoEnd: timing.videoPTS, audioEnd: timing.audioPTS, audioDurations: timing.audioDurations });
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
await analysis.close();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
104
123
|
}
|
|
105
124
|
finally {
|
|
106
125
|
await browser.close().catch(() => undefined);
|
package/dist/film.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FilmOptions, FilmResult, FilmCut, FilmStill, FilmBoundary, VideoOptions, VideoResult } from './contract.js';
|
|
2
|
+
/** 单帧整屏突变:变化像素占比至少这么多,且是前后帧的 CUT_RATIO 倍以上(排除持续的快速运镜)。 */
|
|
3
|
+
export declare const CUT_CHANGED = 0.3;
|
|
4
|
+
export declare const CUT_RATIO = 2.5;
|
|
5
|
+
/** 静止:与静止起点那一帧相比,变化像素占比低于这个值。 */
|
|
6
|
+
export declare const STILL_CHANGED = 0.004;
|
|
7
|
+
type Sample = {
|
|
8
|
+
t: number;
|
|
9
|
+
diff: number;
|
|
10
|
+
changed: number;
|
|
11
|
+
still: number;
|
|
12
|
+
scenarioId: string | null;
|
|
13
|
+
position: number;
|
|
14
|
+
activeStep: number | null;
|
|
15
|
+
jpg?: string;
|
|
16
|
+
};
|
|
17
|
+
/** 纯函数:从逐帧的相邻差找出硬切。changed[i] 是第 i 帧与第 i-1 帧之间变化像素的占比。 */
|
|
18
|
+
export declare function findCuts(samples: readonly Pick<Sample, 't' | 'changed' | 'diff' | 'scenarioId' | 'position'>[]): FilmCut[];
|
|
19
|
+
/** 纯函数:still[i] = 第 i 帧距离“上一次明显变化”的毫秒数;找出至少 minMs 的静止段。 */
|
|
20
|
+
export declare function findStills(samples: readonly Pick<Sample, 't' | 'still' | 'scenarioId' | 'position'>[], minMs: number): FilmStill[];
|
|
21
|
+
/** 纯函数:每次提交一步(或换场景)前后窗口里的最大相邻帧差,章节衔接是否硬切一眼可见。 */
|
|
22
|
+
export declare function stepBoundaries(samples: readonly Pick<Sample, 't' | 'diff' | 'changed' | 'scenarioId' | 'position'>[], before?: number, after?: number): FilmBoundary[];
|
|
23
|
+
/** 胶片条:按引擎时间逐帧定格取样。 */
|
|
24
|
+
export declare function renderFilm(opts: FilmOptions): Promise<FilmResult>;
|
|
25
|
+
/** 视频:与看板导出相同的录制器(真实时间)。 */
|
|
26
|
+
export declare function renderVideo(opts: VideoOptions): Promise<VideoResult>;
|
|
27
|
+
export {};
|
package/dist/film.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 胶片条与视频(`joplo render --film / --video`):让 Agent 看见“运动”,而不只是每一步的终态。
|
|
3
|
+
*
|
|
4
|
+
* - renderFilm:Playwright 假时钟(page.clock)接管页面的 setTimeout / rAF / performance.now,演示控制器与引擎时钟
|
|
5
|
+
* 因此按固定步长(sampleMs,默认 50 ms ≈ 20 fps)逐帧前进;每帧截一张图、在辅助页里用 canvas 算与上一帧的像素差。
|
|
6
|
+
* 每隔 every(默认 250 ms)取一帧放进胶片条,标注时间、场景、步号与相邻帧差;同时客观地标出
|
|
7
|
+
* 硬切(单帧整屏突变,前后帧都平静)与长时间静止(≥ stillMs 画面几乎不变)。结果确定、可复现,与墙钟无关。
|
|
8
|
+
* - renderVideo:复用看板导出的录制器(defaultRecorder,Playwright recordVideo,按真实时间),得到可以直接看的 webm。
|
|
9
|
+
*
|
|
10
|
+
* 两者都走渲染路由的录制模式(record=1&frame=1):与看板导出视频同一套演示控制器、鼠标、字幕;
|
|
11
|
+
* chain=1 按发布站的顺序连续播放到方案的最后一个场景;voice=estimate 让旁白按估算时长“读”(不出声、不调用朗读服务),
|
|
12
|
+
* 停留时间与开着朗读的发布站一致。
|
|
13
|
+
*/
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { JoploError, SUBTITLE_HEIGHT, displaySceneId } from '@joplo-app/core';
|
|
17
|
+
import { createDev } from "./dev.js";
|
|
18
|
+
import { realProjectDir } from "./vite-shared.js";
|
|
19
|
+
import { joploHome } from "./home.js";
|
|
20
|
+
import { loadPlaywright } from "./export-runtime.js";
|
|
21
|
+
import { launch } from "./render.js";
|
|
22
|
+
import { EXPORT_SIZE, defaultRecorder } from "./export.js";
|
|
23
|
+
/** 单帧整屏突变:变化像素占比至少这么多,且是前后帧的 CUT_RATIO 倍以上(排除持续的快速运镜)。 */
|
|
24
|
+
export const CUT_CHANGED = 0.3;
|
|
25
|
+
export const CUT_RATIO = 2.5;
|
|
26
|
+
/** 静止:与静止起点那一帧相比,变化像素占比低于这个值。 */
|
|
27
|
+
export const STILL_CHANGED = 0.004;
|
|
28
|
+
/** 一个像素的 RGB 平均差超过这个值才算“变了”(0–1)。 */
|
|
29
|
+
const PIXEL_THRESHOLD = 0.08;
|
|
30
|
+
const MAX_MS = 10 * 60_000;
|
|
31
|
+
/** 纯函数:从逐帧的相邻差找出硬切。changed[i] 是第 i 帧与第 i-1 帧之间变化像素的占比。 */
|
|
32
|
+
export function findCuts(samples) {
|
|
33
|
+
const cuts = [];
|
|
34
|
+
for (let i = 1; i < samples.length; i++) {
|
|
35
|
+
const c = samples[i].changed;
|
|
36
|
+
if (c < CUT_CHANGED)
|
|
37
|
+
continue;
|
|
38
|
+
const around = Math.max(samples[i - 1]?.changed ?? 0, samples[i + 1]?.changed ?? 0, i > 1 ? 0 : 0);
|
|
39
|
+
if (c >= CUT_RATIO * Math.max(around, 0.02))
|
|
40
|
+
cuts.push({ atMs: samples[i].t, diff: round(samples[i].diff), changed: round(c), scenarioId: samples[i].scenarioId, position: samples[i].position });
|
|
41
|
+
}
|
|
42
|
+
return cuts;
|
|
43
|
+
}
|
|
44
|
+
/** 纯函数:still[i] = 第 i 帧距离“上一次明显变化”的毫秒数;找出至少 minMs 的静止段。 */
|
|
45
|
+
export function findStills(samples, minMs) {
|
|
46
|
+
const out = [];
|
|
47
|
+
let run = null;
|
|
48
|
+
for (const s of samples) {
|
|
49
|
+
if (s.still >= minMs) {
|
|
50
|
+
const from = s.t - s.still;
|
|
51
|
+
if (run && run.fromMs === from) {
|
|
52
|
+
run.toMs = s.t;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
run = { fromMs: from, toMs: s.t, scenarioId: s.scenarioId, position: s.position };
|
|
56
|
+
out.push(run);
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
run = null;
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** 纯函数:每次提交一步(或换场景)前后窗口里的最大相邻帧差,章节衔接是否硬切一眼可见。 */
|
|
64
|
+
export function stepBoundaries(samples, before = 200, after = 1500) {
|
|
65
|
+
const out = [];
|
|
66
|
+
for (let i = 1; i < samples.length; i++) {
|
|
67
|
+
const a = samples[i - 1], b = samples[i];
|
|
68
|
+
if (a.scenarioId === b.scenarioId && a.position === b.position)
|
|
69
|
+
continue;
|
|
70
|
+
const win = samples.filter((s) => s.t >= b.t - before && s.t <= b.t + after);
|
|
71
|
+
out.push({ atMs: b.t, scenarioId: b.scenarioId, position: b.position, chapter: a.scenarioId !== b.scenarioId, maxDiff: round(Math.max(0, ...win.map((s) => s.diff))), maxChanged: round(Math.max(0, ...win.map((s) => s.changed))) });
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
const round = (n) => Math.round(n * 10000) / 10000;
|
|
76
|
+
const esc = (t) => t.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
77
|
+
/** 辅助页:解码 JPEG、裁掉字幕区,与上一帧、静止起点比较。状态留在页面里,每帧只传一次图片。 */
|
|
78
|
+
const DIFF_PAGE = `<!doctype html><canvas id=c></canvas><script>
|
|
79
|
+
let prev=null, anchor=null, anchorT=0;
|
|
80
|
+
async function load(b64){ const img=new Image(); img.src='data:image/jpeg;base64,'+b64; await img.decode(); return img; }
|
|
81
|
+
function pixels(img, h){ const c=document.getElementById('c'); c.width=img.width; c.height=h; const g=c.getContext('2d',{willReadFrequently:true}); g.drawImage(img,0,0); return g.getImageData(0,0,img.width,h).data; }
|
|
82
|
+
function compare(a,b,th){ let sum=0, changed=0; const n=a.length/4; for(let i=0;i<a.length;i+=4){ const d=(Math.abs(a[i]-b[i])+Math.abs(a[i+1]-b[i+1])+Math.abs(a[i+2]-b[i+2]))/765; sum+=d; if(d>th) changed++; } return { diff: sum/n, changed: changed/n }; }
|
|
83
|
+
window.step = async (b64, cropRatio, t, th, stillTh) => {
|
|
84
|
+
const img = await load(b64); const d = pixels(img, Math.max(1, Math.round(img.height*cropRatio)));
|
|
85
|
+
const adj = prev ? compare(prev, d, th) : { diff: 0, changed: 0 };
|
|
86
|
+
prev = d;
|
|
87
|
+
if (!anchor || compare(anchor, d, th).changed > stillTh) { anchor = d; anchorT = t; }
|
|
88
|
+
return { ...adj, still: t - anchorT };
|
|
89
|
+
};
|
|
90
|
+
</script>`;
|
|
91
|
+
async function flush(page) {
|
|
92
|
+
// React 用 MessageChannel 调度提交;假时钟不接管它。等两轮,让这一帧的状态都画出来。
|
|
93
|
+
for (let i = 0; i < 2; i++)
|
|
94
|
+
await page.evaluate(() => new Promise((r) => { const c = new MessageChannel(); c.port1.onmessage = () => r(); c.port2.postMessage(0); }));
|
|
95
|
+
}
|
|
96
|
+
function check(opts) {
|
|
97
|
+
const out = path.resolve(opts.out);
|
|
98
|
+
if (fs.existsSync(out) && !opts.overwrite)
|
|
99
|
+
throw new JoploError('USAGE', `Output file already exists: ${out}. To overwrite, pass overwrite: true (CLI: --overwrite)`);
|
|
100
|
+
const dataDir = path.join(realProjectDir(opts.projectDir), '.joplo');
|
|
101
|
+
if (out === dataDir || out.startsWith(dataDir + path.sep))
|
|
102
|
+
throw new JoploError('USAGE', `Cannot write to project data: ${out} (.joplo/ is managed by Joplo)`);
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
async function compiled(projectDir) {
|
|
106
|
+
const server = await createDev({ projectDir, port: 0, watch: false, log: () => undefined });
|
|
107
|
+
const payload = server.payload();
|
|
108
|
+
if (!payload.project) {
|
|
109
|
+
await server.close();
|
|
110
|
+
const errs = payload.diagnostics.filter((d) => d.severity === 'error');
|
|
111
|
+
throw new JoploError('INVALID_SCHEMA', `Project compilation failed: ${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('; ')}`, { diagnostics: payload.diagnostics });
|
|
112
|
+
}
|
|
113
|
+
return { server, project: payload.project };
|
|
114
|
+
}
|
|
115
|
+
function recordUrl(base, projectId, project, o) {
|
|
116
|
+
if (!project.scenarios[o.scenarioId])
|
|
117
|
+
throw new JoploError('NOT_FOUND', `Scenario does not exist: ${o.scenarioId} (available: ${Object.keys(project.scenarios).join(', ') || 'none'})`);
|
|
118
|
+
if (o.content !== undefined && !project.i18n?.locales.includes(o.content))
|
|
119
|
+
throw new JoploError('USAGE', project.i18n ? `--content ${o.content} is not in config locales (${project.i18n.locales.join(', ')})` : `--content needs config({ locales }); this project has a single language`);
|
|
120
|
+
const q = new URLSearchParams({ render: '1', project: projectId, scenario: o.scenarioId, position: '0', theme: o.theme ?? project.theme ?? 'sketch', frame: '1', record: '1', voice: 'estimate', ...(o.chain ? { chain: '1' } : {}), ...(o.audio === false ? { audio: '0' } : {}), ...(o.locale ? { locale: o.locale } : {}), ...(o.content ? { content: o.content } : {}) });
|
|
121
|
+
const device = project.scenes[displaySceneId(project, o.scenarioId, 0)]?.viewport === 'mobile' ? 'mobile' : 'desktop';
|
|
122
|
+
return { url: `${base}?${q}`, size: EXPORT_SIZE[device] };
|
|
123
|
+
}
|
|
124
|
+
/** 胶片条:按引擎时间逐帧定格取样。 */
|
|
125
|
+
export async function renderFilm(opts) {
|
|
126
|
+
const projectDir = realProjectDir(opts.projectDir);
|
|
127
|
+
const out = check({ ...opts, projectDir });
|
|
128
|
+
const sampleMs = Math.max(20, Math.min(250, Math.round(opts.sampleMs ?? 50)));
|
|
129
|
+
const every = Math.max(sampleMs, Math.round((opts.every ?? 250) / sampleMs) * sampleMs);
|
|
130
|
+
const stillMs = opts.stillMs ?? 1500;
|
|
131
|
+
const columns = Math.max(1, Math.min(16, Math.round(opts.columns ?? 8)));
|
|
132
|
+
const cellWidth = Math.max(120, Math.min(640, Math.round(opts.cellWidth ?? 224)));
|
|
133
|
+
const playwright = await loadPlaywright({ home: joploHome(), projectDir });
|
|
134
|
+
const { server, project } = await compiled(projectDir);
|
|
135
|
+
let browser = null;
|
|
136
|
+
try {
|
|
137
|
+
const { url, size } = recordUrl(server.url, server.projectId, project, { ...opts, audio: false });
|
|
138
|
+
browser = await launch(playwright);
|
|
139
|
+
const ctx = await browser.newContext({ viewport: size, deviceScaleFactor: 0.5 });
|
|
140
|
+
const page = await ctx.newPage();
|
|
141
|
+
await page.clock.install({ time: 0 });
|
|
142
|
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
143
|
+
// 载入阶段:真实时间里等网络与字体,假时间一点点往前推,直到渲染路由报告就绪
|
|
144
|
+
const t0 = Date.now();
|
|
145
|
+
for (;;) {
|
|
146
|
+
const ready = await page.evaluate(() => window.__JOPLO_READY__ === true);
|
|
147
|
+
if (ready)
|
|
148
|
+
break;
|
|
149
|
+
if (Date.now() - t0 > 60_000)
|
|
150
|
+
throw new JoploError('RENDER_FAILED', 'Render route did not become ready within 60 seconds');
|
|
151
|
+
await page.clock.runFor(16);
|
|
152
|
+
await page.waitForTimeout(10);
|
|
153
|
+
}
|
|
154
|
+
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
155
|
+
if (err)
|
|
156
|
+
throw new JoploError('RENDER_FAILED', `Render route reported an error: ${err}`);
|
|
157
|
+
// 就绪后冻结时钟:之后只由 runFor 推进,截图与像素比较花的真实时间不再混进引擎时间
|
|
158
|
+
const now = await page.evaluate(() => Date.now());
|
|
159
|
+
await page.clock.pauseAt(now + 1);
|
|
160
|
+
const helper = await ctx.newPage();
|
|
161
|
+
await helper.setContent(DIFF_PAGE);
|
|
162
|
+
const stageRatio = (size.height - SUBTITLE_HEIGHT) / size.height;
|
|
163
|
+
const samples = [];
|
|
164
|
+
let tail = -1;
|
|
165
|
+
// 第一帧在开播之前采(封面 / 第 0 步):开播那一下的切换也要量到
|
|
166
|
+
for (let t = 0; t <= MAX_MS; t += sampleMs) {
|
|
167
|
+
if (t === sampleMs)
|
|
168
|
+
await page.evaluate(() => window.__JOPLO_RECORD__.play());
|
|
169
|
+
if (t > 0)
|
|
170
|
+
await page.clock.runFor(sampleMs);
|
|
171
|
+
await flush(page);
|
|
172
|
+
const p = await page.evaluate(() => window.__JOPLO_RECORD__.progress);
|
|
173
|
+
if (p.error)
|
|
174
|
+
throw new JoploError('RENDER_FAILED', `Playback failed at ${t} ms: ${p.error}`);
|
|
175
|
+
const jpg = (await page.locator('[data-jexport]').screenshot({ type: 'jpeg', quality: 72 })).toString('base64');
|
|
176
|
+
const d = await helper.evaluate(([b64, crop, time, th, st]) => window.step(b64, crop, time, th, st), [jpg, stageRatio, t, PIXEL_THRESHOLD, STILL_CHANGED]);
|
|
177
|
+
samples.push({ t, ...d, scenarioId: p.scenarioId, position: p.position, activeStep: p.activeStep, ...(t % every === 0 ? { jpg } : {}) });
|
|
178
|
+
if (opts.frames && t % every === 0) {
|
|
179
|
+
fs.mkdirSync(opts.frames, { recursive: true });
|
|
180
|
+
fs.writeFileSync(path.join(opts.frames, `${String(t).padStart(7, '0')}.jpg`), Buffer.from(jpg, 'base64'));
|
|
181
|
+
}
|
|
182
|
+
if (p.done && tail < 0)
|
|
183
|
+
tail = t + 1000;
|
|
184
|
+
if (tail >= 0 && t >= tail)
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
if (tail < 0)
|
|
188
|
+
throw new JoploError('RENDER_FAILED', `Playback did not finish within ${MAX_MS / 60000} minutes of engine time`);
|
|
189
|
+
const cuts = findCuts(samples);
|
|
190
|
+
const stills = findStills(samples, stillMs);
|
|
191
|
+
const boundaries = stepBoundaries(samples);
|
|
192
|
+
const durationMs = samples[samples.length - 1].t;
|
|
193
|
+
// 胶片条:每个场景一页,避免一张图太长被缩得看不清
|
|
194
|
+
const pages = new Map();
|
|
195
|
+
for (const s of samples)
|
|
196
|
+
if (s.jpg) {
|
|
197
|
+
const k = s.scenarioId ?? '';
|
|
198
|
+
if (!pages.has(k))
|
|
199
|
+
pages.set(k, []);
|
|
200
|
+
pages.get(k).push(s);
|
|
201
|
+
}
|
|
202
|
+
const name = (sid) => project.scenarios[sid]?.name ?? sid;
|
|
203
|
+
const files = [];
|
|
204
|
+
let index = 0;
|
|
205
|
+
for (const [sid, cells] of pages) {
|
|
206
|
+
index++;
|
|
207
|
+
const file = pages.size === 1 ? out : out.replace(/(\.png)?$/i, `-${index}.png`);
|
|
208
|
+
const cutAt = (s) => cuts.find((c) => c.atMs > s.t - every && c.atMs <= s.t);
|
|
209
|
+
const stillAt = (s) => s.still >= stillMs;
|
|
210
|
+
const body = cells.map((s) => {
|
|
211
|
+
const cut = cutAt(s);
|
|
212
|
+
const step = s.position > 0 ? project.scenarios[sid]?.steps[s.position - 1] : undefined;
|
|
213
|
+
const first = cells.find((c) => c.position === s.position) === s;
|
|
214
|
+
const peak = Math.max(...samples.filter((x) => x.t > s.t - every && x.t <= s.t).map((x) => x.changed), 0);
|
|
215
|
+
return `<div class="cell${cut ? ' cut' : ''}${stillAt(s) ? ' still' : ''}"><img src="data:image/jpeg;base64,${s.jpg}"><div class="meta"><b>${(s.t / 1000).toFixed(2)}s</b> · ${s.position}${s.activeStep !== null ? `→${s.activeStep + 1}` : ''} <span class="bar"><i style="width:${Math.min(100, Math.round(peak * 100))}%"></i></span>${cut ? ` <em>CUT ${(cut.changed * 100).toFixed(0)}%</em>` : ''}${stillAt(s) ? ` <u>STILL ${(s.still / 1000).toFixed(1)}s</u>` : ''}${first && step ? `<div class="cap">${esc(step.caption)}</div>` : ''}</div></div>`;
|
|
216
|
+
}).join('');
|
|
217
|
+
const summary = `${cuts.filter((c) => c.scenarioId === sid).length} cuts · ${stills.filter((x) => x.scenarioId === sid).length} stills ≥ ${(stillMs / 1000).toFixed(1)}s · every ${every} ms, diff sampled every ${sampleMs} ms`;
|
|
218
|
+
const html = `<!doctype html><meta charset="utf-8"><style>
|
|
219
|
+
body{margin:0;padding:18px;background:#16181d;color:#e8e8ea;font:12px/1.35 -apple-system,"PingFang SC","Noto Sans SC",system-ui,sans-serif}
|
|
220
|
+
h1{font-size:16px;margin:0 0 4px} p{margin:0 0 12px;color:#a0a4b0} .grid{display:grid;grid-template-columns:repeat(${columns},${cellWidth}px);gap:8px}
|
|
221
|
+
.cell img{width:100%;display:block;border-radius:3px;border:2px solid #2c2f38} .cut img{border-color:#ff4d4f} .still img{border-color:#8a8f9c;filter:grayscale(.6)}
|
|
222
|
+
.meta{padding:2px 1px 0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} b{color:#ffb020} em{color:#ff6b6b;font-style:normal;font-weight:700} u{color:#c0c4cf;text-decoration:none}
|
|
223
|
+
.bar{display:inline-block;width:40px;height:5px;background:#2c2f38;vertical-align:middle}.bar i{display:block;height:100%;background:#5b8cff}
|
|
224
|
+
.cap{color:#c9ccd4;overflow:hidden;text-overflow:ellipsis}
|
|
225
|
+
</style><h1>${esc(name(sid))} · ${esc(sid)}</h1><p>${esc(summary)}. Red = one-frame full-screen change (hard cut); grey = no visible change for ≥ ${(stillMs / 1000).toFixed(1)}s; blue bar = largest adjacent-frame change in the cell.</p><div class="grid">${body}</div>`;
|
|
226
|
+
const sheet = await ctx.newPage();
|
|
227
|
+
await sheet.setViewportSize({ width: columns * cellWidth + (columns - 1) * 8 + 36, height: 600 });
|
|
228
|
+
await sheet.setContent(html, { waitUntil: 'load' });
|
|
229
|
+
const png = await sheet.screenshot({ type: 'png', fullPage: true });
|
|
230
|
+
await sheet.close();
|
|
231
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
232
|
+
fs.writeFileSync(file, png, opts.overwrite ? undefined : { flag: 'wx' });
|
|
233
|
+
files.push(file);
|
|
234
|
+
}
|
|
235
|
+
await ctx.close();
|
|
236
|
+
const result = { path: files[0], files, durationMs, sampleMs, every, samples: samples.length, cuts, stills, boundaries, maxDiff: round(Math.max(0, ...samples.map((s) => s.diff))), warnings: [] };
|
|
237
|
+
// 完整的判读数据(每一步提交前后的最大帧差、硬切、静止)放在胶片条旁边,评审时可以引用具体数字
|
|
238
|
+
fs.writeFileSync(out.replace(/(\.png)?$/i, '.json'), JSON.stringify({ ...result, frames: samples.map(({ jpg: _jpg, ...rest }) => rest) }, null, 1));
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
finally {
|
|
242
|
+
await browser?.close().catch(() => undefined);
|
|
243
|
+
await server.close();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/** 视频:与看板导出相同的录制器(真实时间)。 */
|
|
247
|
+
export async function renderVideo(opts) {
|
|
248
|
+
const projectDir = realProjectDir(opts.projectDir);
|
|
249
|
+
const out = check({ ...opts, projectDir });
|
|
250
|
+
const { server, project } = await compiled(projectDir);
|
|
251
|
+
try {
|
|
252
|
+
const { url, size } = recordUrl(server.url, server.projectId, project, opts);
|
|
253
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
254
|
+
if (opts.overwrite)
|
|
255
|
+
fs.rmSync(out, { force: true });
|
|
256
|
+
const started = Date.now();
|
|
257
|
+
await defaultRecorder((dir) => loadPlaywright({ home: joploHome(), projectDir: dir }))({ projectDir, url, size, out, total: 0, progress: () => undefined, signal: new AbortController().signal, maxMs: MAX_MS });
|
|
258
|
+
return { path: out, durationMs: Date.now() - started };
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
await server.close();
|
|
262
|
+
}
|
|
263
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
export type { BuildOptions, BuildResult, CloudAccount, CloudBridge, CloudJob, CloudJobError, CloudPublishRequest, CloudPublishResult, DevHandle, DevOptions, RenderOptions, RenderResult, RenderedElement } from './contract.js';
|
|
10
10
|
export { startDev } from './dev.js';
|
|
11
11
|
export { buildSite } from './build.js';
|
|
12
|
-
export {
|
|
12
|
+
export { generateProjectVoice, type VoiceRunOptions, type VoiceRunResult } from './voice-run.js';
|
|
13
|
+
export type { CloudSpeechRequest, CloudSpeechResult, CloudVoice, CloudVoiceBridge, CloudVoiceCatalog, CloudVoiceInfo, CloudVoiceStatus, VoiceQuota } from './cloud.js';
|
|
14
|
+
export { renderSheet, renderStep } from './render.js';
|
|
15
|
+
export { renderFilm, renderVideo } from './film.js';
|
|
13
16
|
export { EXPORT_DOWNLOAD_MB, PLAYWRIGHT_VERSION, SETUP_COMMAND, exportRuntimeStatus, installExportRuntime, uninstallExportRuntime, type ExportRuntimeStatus, type InstallProgress, type InstallResult } from './export-runtime.js';
|
|
14
17
|
export { buildFeatureDiff, publicIRFromHtml, type DiffBuildOptions, type DiffBuildResult } from './feature-diff.js';
|
|
18
|
+
export { generateResources } from './resources-run.js';
|
|
19
|
+
export { LocalResources } from './local-resources.js';
|
|
20
|
+
export { inspectResources, mediaDiagnostics } from './media-check.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { startDev } from "./dev.js";
|
|
2
2
|
export { buildSite } from "./build.js";
|
|
3
|
-
export {
|
|
3
|
+
export { generateProjectVoice } from "./voice-run.js";
|
|
4
|
+
export { renderSheet, renderStep } from "./render.js";
|
|
5
|
+
export { renderFilm, renderVideo } from "./film.js";
|
|
4
6
|
export { EXPORT_DOWNLOAD_MB, PLAYWRIGHT_VERSION, SETUP_COMMAND, exportRuntimeStatus, installExportRuntime, uninstallExportRuntime } from "./export-runtime.js";
|
|
5
7
|
export { buildFeatureDiff, publicIRFromHtml } from "./feature-diff.js";
|
|
8
|
+
export { generateResources } from "./resources-run.js";
|
|
9
|
+
export { LocalResources } from "./local-resources.js";
|
|
10
|
+
export { inspectResources, mediaDiagnostics } from "./media-check.js";
|