@joplo-app/server 0.6.2 → 0.7.1
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/asset-usage.d.ts +48 -0
- package/dist/asset-usage.js +174 -0
- package/dist/capture.d.ts +15 -0
- package/dist/capture.js +49 -0
- package/dist/checkpoint.d.ts +10 -0
- package/dist/checkpoint.js +75 -0
- package/dist/contract.d.ts +62 -0
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +9 -4
- package/dist/export.d.ts +6 -0
- package/dist/export.js +5 -2
- package/dist/film.d.ts +10 -1
- package/dist/film.js +201 -25
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -1
- package/dist/layout-audit-browser.js +114 -0
- package/dist/layout-audit.d.ts +94 -0
- package/dist/layout-audit.js +86 -0
- package/dist/local-resources.js +2 -0
- package/dist/media-check.d.ts +2 -0
- package/dist/media-check.js +31 -1
- package/dist/output-file.d.ts +3 -0
- package/dist/output-file.js +23 -0
- package/dist/project.d.ts +1 -0
- package/dist/project.js +3 -1
- package/dist/render.d.ts +2 -0
- package/dist/render.js +24 -10
- package/dist/timeline.d.ts +76 -0
- package/dist/timeline.js +139 -0
- package/dist/video-format.d.ts +2 -0
- package/dist/video-format.js +12 -0
- package/dist/vite-shared.d.ts +1 -1
- package/dist/vite-shared.js +2 -2
- package/dist/voice-http.js +2 -2
- package/dist/voice-run.d.ts +16 -1
- package/dist/voice-run.js +45 -6
- package/dist/voice.js +2 -2
- package/dist/watch-config.d.ts +3 -0
- package/dist/watch-config.js +10 -0
- package/package.json +4 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Browser geometry diagnostics. No Core layout rules, resource generation or automatic edits. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { JoploError } from '@joplo-app/core';
|
|
5
|
+
const browserSource = fs.readFileSync(path.join(import.meta.dirname, 'layout-audit-browser.js'), 'utf8').replace(/^\/\*[\s\S]*?\*\/\s*/, '');
|
|
6
|
+
function area(value) {
|
|
7
|
+
if (typeof value === 'string')
|
|
8
|
+
return value.trim().length > 0;
|
|
9
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
|
+
return false;
|
|
11
|
+
const v = value;
|
|
12
|
+
return Object.keys(v).every(k => ['x', 'y', 'width', 'height'].includes(k)) && ['x', 'y', 'width', 'height'].every(k => typeof v[k] === 'number' && Number.isFinite(v[k])) && v.width > 0 && v.height > 0;
|
|
13
|
+
}
|
|
14
|
+
export function layoutAuditOptions(value) {
|
|
15
|
+
const options = value === true ? {} : value;
|
|
16
|
+
if (!options || typeof options !== 'object' || Array.isArray(options) || Object.keys(options).some(k => !['content', 'safeAreas', 'important', 'exclude', 'everyMs'].includes(k)))
|
|
17
|
+
throw new JoploError('USAGE', 'Invalid layout audit options');
|
|
18
|
+
if (options.content !== undefined && !area(options.content) || options.safeAreas !== undefined && (!Array.isArray(options.safeAreas) || !options.safeAreas.every(area)))
|
|
19
|
+
throw new JoploError('USAGE', 'Layout content/safe areas must be CSS selectors or finite positive CSS rectangles');
|
|
20
|
+
if (options.everyMs !== undefined && (!Number.isFinite(options.everyMs) || options.everyMs < 20 || options.everyMs > 1000))
|
|
21
|
+
throw new JoploError('USAGE', 'Layout audit everyMs must be 20–1000 engine milliseconds');
|
|
22
|
+
for (const key of ['important', 'exclude'])
|
|
23
|
+
if (options[key] !== undefined && (!Array.isArray(options[key]) || !options[key].every(selector => typeof selector === 'string' && selector.trim())))
|
|
24
|
+
throw new JoploError('USAGE', `Layout audit ${key} must contain CSS selectors`);
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
export async function auditLayout(page, options, crop) {
|
|
28
|
+
layoutAuditOptions(options);
|
|
29
|
+
await page.evaluate(() => document.fonts.ready);
|
|
30
|
+
try {
|
|
31
|
+
return await page.evaluate(`(${browserSource})(${JSON.stringify({ ...options, crop })})`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new JoploError('RENDER_FAILED', `Layout geometry audit failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function writeLayoutReport(file, samples, overwrite = false, sampleToleranceMs = null) {
|
|
38
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
39
|
+
const report = { schemaVersion: 1, kind: 'layout-audit', sampling: 'actual-rendered-css-geometry', sampleToleranceMs, findings: samples.reduce((n, s) => n + s.findings.length, 0), samples, limitations: [
|
|
40
|
+
'Bounds are page CSS pixels after actual fonts and transforms. Evidence may be cropped/scaled; root/content bounds provide the coordinate origin. Static samples have no engine timestamp and do not verify motion.',
|
|
41
|
+
'Importance is explicitly selected, never inferred from semantic meaning. Excluded decorations and intentional overlaps are not diagnosed. Geometry overlap is only a warning and does not prove paint occlusion.',
|
|
42
|
+
'No contrast, screen-reader, reading-order or copyright assessment. Rotation, masks and nonrectangular clipping remain unknown. Transparent/hidden important elements are reported as unknown rather than guessed visible.',
|
|
43
|
+
'Playback samples use the existing export engine clock. Commit and declared plugin/entry phase deadlines are observed on the export sample grid within sampleToleranceMs; phases interrupted by a later step or absent from plugin hints are not guaranteed. Unobserved intervals can contain additional problems.',
|
|
44
|
+
] };
|
|
45
|
+
fs.writeFileSync(file, JSON.stringify(report, null, 2), overwrite ? undefined : { flag: 'wx' });
|
|
46
|
+
return { path: file, findings: report.findings, samples: samples.length };
|
|
47
|
+
}
|
|
48
|
+
export function layoutReportPath(out) { return out.replace(/\.[^.]+$/, '') + '.layout.json'; }
|
|
49
|
+
export function createLayoutAuditSession(config) {
|
|
50
|
+
const options = layoutAuditOptions(config.options), reportPath = layoutReportPath(config.out), samples = [];
|
|
51
|
+
if (config.sampleMs > 50)
|
|
52
|
+
throw new JoploError('USAGE', 'Motion layout audit requires sampleMs <= 50 to observe commit and animation phases');
|
|
53
|
+
if (fs.existsSync(reportPath) && !config.overwrite)
|
|
54
|
+
throw new JoploError('USAGE', `Layout report already exists: ${reportPath}`);
|
|
55
|
+
let nextInterval = 0, previous = '', pending = [];
|
|
56
|
+
return {
|
|
57
|
+
async sample(page, frame) {
|
|
58
|
+
const identity = `${frame.scenarioId}#${frame.position}`, changed = identity !== previous;
|
|
59
|
+
if (changed)
|
|
60
|
+
pending = [];
|
|
61
|
+
const due = pending.filter(p => p.identity === identity && p.atMs <= frame.atMs + .01);
|
|
62
|
+
pending = pending.filter(p => !due.includes(p));
|
|
63
|
+
if (!changed && !due.length && frame.atMs < nextInterval)
|
|
64
|
+
return;
|
|
65
|
+
const measured = await auditLayout(page, options, config.crop);
|
|
66
|
+
const phaseNames = [...new Set([...(changed ? [frame.position ? 'post-commit' : 'initial'] : []), ...due.map(p => p.phase), ...(!changed && !due.length ? ['interval'] : [])])];
|
|
67
|
+
for (const hint of measured.phases) {
|
|
68
|
+
const atMs = frame.atMs + hint.afterMs;
|
|
69
|
+
if (hint.afterMs > .01 && !pending.some(p => p.identity === identity && p.phase === hint.phase && Math.abs(p.atMs - atMs) <= config.sampleMs))
|
|
70
|
+
pending.push({ atMs, phase: hint.phase, identity });
|
|
71
|
+
}
|
|
72
|
+
let evidence = null;
|
|
73
|
+
if (measured.findings.length || measured.unknowns.length) {
|
|
74
|
+
const directory = config.out.replace(/\.[^.]+$/, '') + '.layout-evidence';
|
|
75
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
76
|
+
evidence = path.join(directory, `${String(Math.round(frame.atMs)).padStart(8, '0')}.jpg`);
|
|
77
|
+
fs.writeFileSync(evidence, Buffer.from(frame.jpg, 'base64'), config.overwrite ? undefined : { flag: 'wx' });
|
|
78
|
+
}
|
|
79
|
+
const scenario = config.project.scenarios[frame.scenarioId];
|
|
80
|
+
samples.push({ ...measured, phaseHints: measured.phases, phases: phaseNames, atMs: frame.atMs, timeBasis: 'engine-clock', scenarioId: frame.scenarioId, position: frame.position, stepId: scenario?.steps[frame.position - 1]?.id ?? null, workId: scenario?.workId ?? null, evidence });
|
|
81
|
+
previous = identity;
|
|
82
|
+
nextInterval = frame.atMs + (options.everyMs ?? 250);
|
|
83
|
+
},
|
|
84
|
+
finish() { return writeLayoutReport(reportPath, samples, config.overwrite, config.sampleMs); },
|
|
85
|
+
};
|
|
86
|
+
}
|
package/dist/local-resources.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Node-only resource host. Work runs in a disposable process, never the browser. */
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import { mediaBudgetDiagnostics } from "./media-check.js";
|
|
3
4
|
import { PluginKeyStore, compilerEnvironment } from "./plugin-keys.js";
|
|
4
5
|
import { joploHome } from "./home.js";
|
|
5
6
|
import path from 'node:path';
|
|
@@ -370,6 +371,7 @@ export async function inlineResources(project, requests, host) {
|
|
|
370
371
|
}
|
|
371
372
|
if (rawBytes)
|
|
372
373
|
diagnostics.push({ severity: 'info', source: 'structure', code: 'MEDIA_BUDGET', message: `All audio: ${rawBytes} raw bytes, ${embeddedBytes} embedded base64/data-URI bytes` });
|
|
374
|
+
diagnostics.push(...mediaBudgetDiagnostics(project, audioInfo));
|
|
373
375
|
return { assets, audioInfo, diagnostics, credits: [...credits], licenses: [...licenses], rawBytes, embeddedBytes };
|
|
374
376
|
}
|
|
375
377
|
export { nodeResourceIds as referencedResources, resolveResourceProps } from '@joplo-app/core';
|
package/dist/media-check.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export declare function inspectResources(project: Project | null, requests: Reso
|
|
|
7
7
|
}>;
|
|
8
8
|
/** Measure uninterrupted runs, not each individual step. Stop/replacement ends a run. */
|
|
9
9
|
export declare function mediaDiagnostics(project: Project, info: Record<string, LocalResourceInfo>): Diagnostic[];
|
|
10
|
+
/** PCM memory is charged per resource, including both sides of an active crossfade. */
|
|
11
|
+
export declare function mediaBudgetDiagnostics(project: Project, info: Record<string, LocalResourceInfo | import('@joplo-app/kit/plugin').AudioRegion>): Diagnostic[];
|
package/dist/media-check.js
CHANGED
|
@@ -16,7 +16,7 @@ export async function inspectResources(project, requests, host) {
|
|
|
16
16
|
}
|
|
17
17
|
/** Measure uninterrupted runs, not each individual step. Stop/replacement ends a run. */
|
|
18
18
|
export function mediaDiagnostics(project, info) {
|
|
19
|
-
const diagnostics =
|
|
19
|
+
const diagnostics = mediaBudgetDiagnostics(project, info);
|
|
20
20
|
for (const sc of Object.values(project.scenarios)) {
|
|
21
21
|
const runs = new Map();
|
|
22
22
|
const finish = (key) => {
|
|
@@ -56,3 +56,33 @@ export function mediaDiagnostics(project, info) {
|
|
|
56
56
|
}
|
|
57
57
|
return diagnostics;
|
|
58
58
|
}
|
|
59
|
+
/** PCM memory is charged per resource, including both sides of an active crossfade. */
|
|
60
|
+
export function mediaBudgetDiagnostics(project, info) {
|
|
61
|
+
const out = [], budget = 32 * 1024 * 1024;
|
|
62
|
+
for (const sc of Object.values(project.scenarios)) {
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
for (const [position, snapshot, at] of [[0, sc.media, undefined], ...sc.steps.map((s, i) => [i + 1, s.media, s.source])]) {
|
|
65
|
+
const ids = [...new Set(Object.values(snapshot ?? {}).filter(t => t.stopAfterMs === undefined || t.stopAfterMs > 0).map(t => t.resource))].sort();
|
|
66
|
+
const key = ids.join(',');
|
|
67
|
+
if (!key || seen.has(key))
|
|
68
|
+
continue;
|
|
69
|
+
seen.add(key);
|
|
70
|
+
let known = 0;
|
|
71
|
+
const bytes = (rate) => ids.reduce((sum, id) => {
|
|
72
|
+
const m = info[id];
|
|
73
|
+
if (!m)
|
|
74
|
+
return sum;
|
|
75
|
+
const seconds = 'decodedFrames' in m ? m.decodedFrames / m.sourceSampleRate : (m.durationMs ?? 0) / 1000;
|
|
76
|
+
if (seconds > 0 && rate === 48000)
|
|
77
|
+
known++;
|
|
78
|
+
return sum + Math.ceil(seconds * rate) * ('channels' in m ? m.channels : 2) * 4;
|
|
79
|
+
}, 0);
|
|
80
|
+
const at48 = bytes(48000), at96 = bytes(96000);
|
|
81
|
+
const code = at48 > budget ? 'MEDIA_DECODE_BUDGET' : at96 > budget ? 'MEDIA_DECODE_HEADROOM' : null;
|
|
82
|
+
if (code)
|
|
83
|
+
out.push({ code, severity: 'warning', source: 'structure', at,
|
|
84
|
+
message: `${sc.id} position ${position}: simultaneous audio [${ids.join(', ')}] needs ${(at48 / 1048576).toFixed(2)} MiB at 48 kHz and ${(at96 / 1048576).toFixed(2)} MiB at 96 kHz (32 MiB decoded budget${known < ids.length ? '; some resources unknown' : ''}). Shorten overlapping tracks or avoid crossfading them; actual device sample rate and decoder padding affect usage.` });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Publish only complete files; exclusive link avoids an overwrite race between CLI processes. */
|
|
2
|
+
export declare function commitOutput(temporary: string, destination: string, overwrite?: boolean): Promise<void>;
|
|
3
|
+
export declare function writeOutput(destination: string, bytes: Uint8Array | string, overwrite?: boolean): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
/** Publish only complete files; exclusive link avoids an overwrite race between CLI processes. */
|
|
5
|
+
export async function commitOutput(temporary, destination, overwrite = false) {
|
|
6
|
+
if (overwrite)
|
|
7
|
+
await fs.rename(temporary, destination);
|
|
8
|
+
else {
|
|
9
|
+
await fs.link(temporary, destination);
|
|
10
|
+
await fs.unlink(temporary);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function writeOutput(destination, bytes, overwrite = false) {
|
|
14
|
+
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
15
|
+
const temporary = path.join(path.dirname(destination), `.${path.basename(destination)}.${randomUUID()}.tmp`);
|
|
16
|
+
try {
|
|
17
|
+
await fs.writeFile(temporary, bytes, { flag: 'wx' });
|
|
18
|
+
await commitOutput(temporary, destination, overwrite);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await fs.rm(temporary, { force: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/project.d.ts
CHANGED
package/dist/project.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* dev(看板、截图)与 build(发布站)共用这一条路径。
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
+
import { watchConfigDiagnostics } from "./watch-config.js";
|
|
6
7
|
import path from 'node:path';
|
|
7
8
|
import { inspectResources, mediaDiagnostics } from "./media-check.js";
|
|
8
9
|
import { LocalResources, referencedResources } from "./local-resources.js";
|
|
@@ -100,6 +101,7 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
100
101
|
}
|
|
101
102
|
if (!loaded.authoring)
|
|
102
103
|
return { project: null, diagnostics, home: null, pluginRuntimes: {} };
|
|
104
|
+
diagnostics.push(...watchConfigDiagnostics(loaded.authoring.config.watch, loaded.authoring.config.source));
|
|
103
105
|
const home = loaded.authoring.config.home ?? null;
|
|
104
106
|
const pluginRuntimes = pluginRuntimesOf(loaded.authoring.config.plugins);
|
|
105
107
|
if (diagnostics.some((d) => d.severity === 'error'))
|
|
@@ -146,7 +148,7 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
146
148
|
if (result.diagnostic)
|
|
147
149
|
diagnostics.push(result.diagnostic);
|
|
148
150
|
}
|
|
149
|
-
return { project: extra.length ? null : r.project, diagnostics: [...diagnostics, ...r.diagnostics, ...extra], home, pluginRuntimes, resources };
|
|
151
|
+
return { watchIgnore: loaded.authoring.config.watch?.ignore, project: extra.length ? null : r.project, diagnostics: [...diagnostics, ...r.diagnostics, ...extra], home, pluginRuntimes, resources };
|
|
150
152
|
}
|
|
151
153
|
const requestKey = (request) => JSON.stringify([request.plugin, request.compiler, request.input]);
|
|
152
154
|
/** 项目目录 → 上一次编译检查到的资源元数据(按请求内容)。只是让第一遍编译用得上的提示;每次编译仍会重新检查并核对。 */
|
package/dist/render.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { loadPlaywright, type PlaywrightModule } from './export-runtime.js';
|
|
|
6
6
|
/** 浏览器启动失败时的一行提示(托管运行时与项目里的 Playwright 都适用:重装 Joplo 自己的导出组件)。 */
|
|
7
7
|
export declare function launchHint(e: unknown): string;
|
|
8
8
|
export declare function launch({ chromium }: PlaywrightModule): Promise<Browser>;
|
|
9
|
+
/** 截图不得覆盖项目源文件或 .joplo/(即使传了 overwrite)。 */
|
|
10
|
+
export declare function assertNotProjectData(projectDir: string, out: string): void;
|
|
9
11
|
/**
|
|
10
12
|
* 渲染路由的参数(纯函数):主题必填(调用方缺省时传项目主题);字体与线条(D55)只在指定且合法时带上,
|
|
11
13
|
* 缺省 = 跟随主题,与 D55 之前的截图一致。
|
package/dist/render.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { auditLayout, layoutAuditOptions, layoutReportPath, writeLayoutReport } from "./layout-audit.js";
|
|
1
2
|
/**
|
|
2
3
|
* renderStep:用随机端口启动一次性的 dev 服务(只编译一次、不监听),Playwright 打开渲染路由,
|
|
3
4
|
* 截取舞台并返回元素索引(带 at)与渲染告警:遮挡、溢出、Toast 重叠、字体(PRD 8.8 / AC-22)。
|
|
@@ -8,12 +9,13 @@
|
|
|
8
9
|
*/
|
|
9
10
|
import fs from 'node:fs';
|
|
10
11
|
import path from 'node:path';
|
|
11
|
-
import { JoploError, VIEWPORT_SIZE, isAppearanceFont, isAppearanceStroke, displaySceneId, findNode, isNodeDisabled, nodeLabel, positionAfterStep, resolveProps, scopeProject, stateAt, walkNodes } from '@joplo-app/core';
|
|
12
|
+
import { JoploError, narrationText, VIEWPORT_SIZE, isAppearanceFont, isAppearanceStroke, displaySceneId, findNode, isNodeDisabled, nodeLabel, positionAfterStep, resolveProps, scopeProject, stateAt, walkNodes } from '@joplo-app/core';
|
|
12
13
|
import { exportLocale } from "./locale.js";
|
|
13
14
|
import { createDev } from "./dev.js";
|
|
14
15
|
import { realProjectDir } from "./vite-shared.js";
|
|
15
16
|
import { joploHome } from "./home.js";
|
|
16
17
|
import { EXPORT_DOWNLOAD_MB, NOT_NEEDED, SETUP_COMMAND, loadPlaywright } from "./export-runtime.js";
|
|
18
|
+
import { capture, geometryQuery } from "./capture.js";
|
|
17
19
|
const STAGE_SIZE = VIEWPORT_SIZE;
|
|
18
20
|
export { loadPlaywright } from "./export-runtime.js";
|
|
19
21
|
/** 浏览器启动失败时的一行提示(托管运行时与项目里的 Playwright 都适用:重装 Joplo 自己的导出组件)。 */
|
|
@@ -53,7 +55,7 @@ function realish(p) {
|
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
/** 截图不得覆盖项目源文件或 .joplo/(即使传了 overwrite)。 */
|
|
56
|
-
function assertNotProjectData(projectDir, out) {
|
|
58
|
+
export function assertNotProjectData(projectDir, out) {
|
|
57
59
|
const fold = (p) => (process.platform === 'darwin' || process.platform === 'win32' ? p.toLowerCase() : p);
|
|
58
60
|
const o = fold(realish(out));
|
|
59
61
|
const dir = fold(realish(projectDir));
|
|
@@ -87,6 +89,11 @@ export async function renderStep(opts) {
|
|
|
87
89
|
assertNotProjectData(projectDir, out);
|
|
88
90
|
if (fs.existsSync(out) && !opts.overwrite)
|
|
89
91
|
throw new JoploError('USAGE', `Output file already exists: ${out}. To overwrite, pass overwrite: true (CLI: --overwrite)`);
|
|
92
|
+
if (opts.auditLayout) {
|
|
93
|
+
layoutAuditOptions(opts.auditLayout);
|
|
94
|
+
if (fs.existsSync(layoutReportPath(out)) && !opts.overwrite)
|
|
95
|
+
throw new JoploError('USAGE', `Layout report already exists: ${layoutReportPath(out)}`);
|
|
96
|
+
}
|
|
90
97
|
// 先确认 Playwright 可用,再启动编译服务(缺失时尽快失败)
|
|
91
98
|
const playwright = await loadPlaywright({ home: joploHome(), projectDir });
|
|
92
99
|
const server = await createDev({ projectDir, port: 0, watch: false, log: () => undefined });
|
|
@@ -114,20 +121,23 @@ export async function renderStep(opts) {
|
|
|
114
121
|
const theme = opts.theme ?? project.theme ?? 'sketch';
|
|
115
122
|
const next = state.completed ? undefined : sc.steps[position];
|
|
116
123
|
const nextTargetId = next && 'target' in next.action ? next.action.target : null;
|
|
117
|
-
const stage = STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
124
|
+
const stage = opts.logicalViewport ?? STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
118
125
|
// 字幕与步骤标题条浮在舞台上(D97):页面就是舞台大小
|
|
119
126
|
const viewport = opts.viewport ?? { width: stage.width, height: stage.height };
|
|
120
127
|
browser = await launch(playwright);
|
|
121
128
|
const page = await browser.newPage({ viewport, deviceScaleFactor: opts.scale ?? 1, reducedMotion: 'reduce' });
|
|
122
129
|
// D44:舞台宽度固定为页面自己的 viewport;指定 viewport 时它只是截图尺寸(舞台按比例放进去)
|
|
123
|
-
const
|
|
130
|
+
const q0 = renderQuery({ projectId: server.projectId, scenarioId: sc.id, position, theme, locale: opts.locale, content: opts.content, font: opts.font, stroke: opts.stroke, ...(opts.viewport ? { viewport: opts.viewport } : {}) });
|
|
131
|
+
const q = new URLSearchParams(q0);
|
|
132
|
+
for (const [key, value] of Object.entries(geometryQuery(opts)))
|
|
133
|
+
q.set(key, value);
|
|
124
134
|
await page.goto(`${server.url}?${q}`, { waitUntil: 'domcontentloaded' });
|
|
125
135
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
126
136
|
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
127
137
|
if (err)
|
|
128
138
|
throw new JoploError('RENDER_FAILED', `Render route reported an error: ${err}`);
|
|
129
139
|
const report = (await page.evaluate(`(${COLLECT_REPORT})(${JSON.stringify({ nextTargetId, theme })})`));
|
|
130
|
-
const png = await page
|
|
140
|
+
const png = await capture(page, opts.viewport ? '[data-jshot]' : '[data-jrender]', opts.crop);
|
|
131
141
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
132
142
|
if (opts.overwrite)
|
|
133
143
|
fs.writeFileSync(out, png);
|
|
@@ -149,11 +159,12 @@ export async function renderStep(opts) {
|
|
|
149
159
|
box: { x: 0, y: 0, width: 0, height: 0 },
|
|
150
160
|
});
|
|
151
161
|
});
|
|
162
|
+
const audit = opts.auditLayout ? writeLayoutReport(layoutReportPath(out), [{ ...await auditLayout(page, layoutAuditOptions(opts.auditLayout), opts.crop), phases: ['static-final'], atMs: null, timeBasis: 'static-final-state', scenarioId: sc.id, position, stepId: sc.steps[position - 1]?.id ?? null, workId: sc.workId, evidence: out }], opts.overwrite) : undefined;
|
|
152
163
|
const elements = [...report.elements, ...hidden];
|
|
153
164
|
const warnings = [...report.warnings];
|
|
154
165
|
if (nextTargetId && findNode(scene, nextTargetId) && !elements.find((e) => e.id === nextTargetId && e.visible))
|
|
155
166
|
warnings.push(`Next action target ${nextTargetId} is not visible in the stage`);
|
|
156
|
-
return { path: out, sceneId: scene.id, position, elements, warnings, scale: opts.scale ?? 1 };
|
|
167
|
+
return { ...(audit ? { audit } : {}), path: out, sceneId: scene.id, position, elements, warnings, scale: opts.scale ?? 1 };
|
|
157
168
|
}
|
|
158
169
|
finally {
|
|
159
170
|
await browser?.close().catch(() => undefined);
|
|
@@ -196,11 +207,14 @@ export async function renderSheet(opts) {
|
|
|
196
207
|
for (let position = 0; position <= sc.steps.length; position++) {
|
|
197
208
|
const state = stateAt(project, sc.id, position);
|
|
198
209
|
const scene = project.scenes[displaySceneId(project, sc.id, position)];
|
|
199
|
-
const stage = STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
210
|
+
const stage = opts.logicalViewport ?? STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
200
211
|
const next = state.completed ? undefined : sc.steps[position];
|
|
201
212
|
const nextTargetId = next && 'target' in next.action ? next.action.target : null;
|
|
202
213
|
const page = await browser.newPage({ viewport: { width: stage.width, height: stage.height }, deviceScaleFactor: 1, reducedMotion: 'reduce' });
|
|
203
|
-
const
|
|
214
|
+
const q0 = renderQuery({ projectId: server.projectId, scenarioId: sc.id, position, theme, locale: opts.locale, content: opts.content, font: opts.font, stroke: opts.stroke });
|
|
215
|
+
const q = new URLSearchParams(q0);
|
|
216
|
+
for (const [key, value] of Object.entries(geometryQuery(opts)))
|
|
217
|
+
q.set(key, value);
|
|
204
218
|
await page.goto(`${server.url}?${q}`, { waitUntil: 'domcontentloaded' });
|
|
205
219
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
206
220
|
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
@@ -209,14 +223,14 @@ export async function renderSheet(opts) {
|
|
|
209
223
|
const report = (await page.evaluate(`(${COLLECT_REPORT})(${JSON.stringify({ nextTargetId, theme })})`));
|
|
210
224
|
for (const w of report.warnings)
|
|
211
225
|
warnings.push(`Step ${position}: ${w}`);
|
|
212
|
-
const png = await page
|
|
226
|
+
const png = await capture(page, '[data-jrender]', opts.crop);
|
|
213
227
|
await page.close();
|
|
214
228
|
const step = position > 0 ? sc.steps[position - 1] : undefined;
|
|
215
229
|
cells.push({
|
|
216
230
|
png: png.toString('base64'),
|
|
217
231
|
label: position === 0 ? '0 · start' : `${position} · ${step.kind}`,
|
|
218
232
|
caption: step?.caption ?? sc.description ?? sc.name,
|
|
219
|
-
voice: step
|
|
233
|
+
voice: step ? narrationText(step, step.caption) : '',
|
|
220
234
|
});
|
|
221
235
|
}
|
|
222
236
|
const html = `<!doctype html><meta charset="utf-8"><style>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AudioRegion } from '@joplo-app/kit/plugin';
|
|
2
|
+
/** Versioned actual-playback observation schema. Times are milliseconds, never outline estimates. */
|
|
3
|
+
export type TimelineStep = {
|
|
4
|
+
scenarioId: string;
|
|
5
|
+
stepId: string;
|
|
6
|
+
position: number;
|
|
7
|
+
commitMs: number;
|
|
8
|
+
outputCommitMs: number;
|
|
9
|
+
endMs: number;
|
|
10
|
+
outputEndMs: number;
|
|
11
|
+
camera: unknown;
|
|
12
|
+
media: unknown;
|
|
13
|
+
text: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type TimelineMediaEvent = {
|
|
16
|
+
track: string;
|
|
17
|
+
action: 'play' | 'stop' | 'seek' | 'volume';
|
|
18
|
+
engineMs: number;
|
|
19
|
+
outputMs: number;
|
|
20
|
+
resource: string;
|
|
21
|
+
offsetMs: number;
|
|
22
|
+
volume: number;
|
|
23
|
+
fadeMs: number;
|
|
24
|
+
snapshot: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
export type PlaybackTimeline = {
|
|
27
|
+
completion?: {
|
|
28
|
+
completed: boolean;
|
|
29
|
+
scenarioId: string | null;
|
|
30
|
+
engineMs: number;
|
|
31
|
+
outputMs: number;
|
|
32
|
+
};
|
|
33
|
+
mediaEvents: TimelineMediaEvent[];
|
|
34
|
+
assets?: {
|
|
35
|
+
id: string;
|
|
36
|
+
kind: 'narration' | 'media';
|
|
37
|
+
file: string;
|
|
38
|
+
audioInfo?: AudioRegion;
|
|
39
|
+
}[];
|
|
40
|
+
steps: TimelineStep[];
|
|
41
|
+
chapters: {
|
|
42
|
+
scenarioId: string;
|
|
43
|
+
startMs: number;
|
|
44
|
+
endMs: number;
|
|
45
|
+
}[];
|
|
46
|
+
schemaVersion: 1;
|
|
47
|
+
origin: 'playback';
|
|
48
|
+
timing: {
|
|
49
|
+
sampleToleranceMs: number;
|
|
50
|
+
outputOriginMs: number;
|
|
51
|
+
};
|
|
52
|
+
events: PlaybackEvent[];
|
|
53
|
+
};
|
|
54
|
+
export type PlaybackEvent = {
|
|
55
|
+
at: number;
|
|
56
|
+
engineMs: number;
|
|
57
|
+
outputMs: number;
|
|
58
|
+
scenarioId?: string | null;
|
|
59
|
+
position?: number;
|
|
60
|
+
stepId?: string | null;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
};
|
|
63
|
+
export type RawTimeline = {
|
|
64
|
+
completed?: boolean;
|
|
65
|
+
schemaVersion: 1;
|
|
66
|
+
startedAt: number | null;
|
|
67
|
+
events: (Record<string, unknown> & {
|
|
68
|
+
at: number;
|
|
69
|
+
engineMs: number;
|
|
70
|
+
})[];
|
|
71
|
+
};
|
|
72
|
+
export declare function playbackTimeline(raw: RawTimeline, outputOriginMs?: number, sampleToleranceMs?: number): PlaybackTimeline;
|
|
73
|
+
/** Accumulated integer targets avoid ceil(1000 / fps) drift in Playwright runFor. */
|
|
74
|
+
export declare function frameTime(index: number, fps: number): number;
|
|
75
|
+
/** Make the timeline useful after its temporary recording server has closed. Only referenced audio is copied. */
|
|
76
|
+
export declare function persistTimeline(file: string, timeline: PlaybackTimeline, mediaAssets: Readonly<Record<string, string>>, baseUrl: string, overwrite?: boolean, localToken?: string, mediaInfo?: Readonly<Record<string, AudioRegion>>): Promise<void>;
|
package/dist/timeline.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { writeOutput } from "./output-file.js";
|
|
2
|
+
export function playbackTimeline(raw, outputOriginMs = raw.startedAt ?? 0, sampleToleranceMs = 50) {
|
|
3
|
+
const steps = [], chapters = [];
|
|
4
|
+
const ended = new Set(), dwelled = new Set();
|
|
5
|
+
for (const e of raw.events) {
|
|
6
|
+
const sid = typeof e.scenarioId === 'string' ? e.scenarioId : null;
|
|
7
|
+
if (!sid)
|
|
8
|
+
continue;
|
|
9
|
+
if (chapters.at(-1)?.scenarioId !== sid) {
|
|
10
|
+
if (chapters.length)
|
|
11
|
+
chapters.at(-1).endMs = e.engineMs;
|
|
12
|
+
chapters.push({ scenarioId: sid, startMs: e.engineMs, endMs: e.engineMs });
|
|
13
|
+
}
|
|
14
|
+
chapters.at(-1).endMs = e.engineMs;
|
|
15
|
+
if (typeof e.stepId === 'string' && !steps.some(s => s.stepId === e.stepId)) {
|
|
16
|
+
if (steps.length && !ended.has(steps.at(-1).stepId)) {
|
|
17
|
+
steps.at(-1).endMs = e.engineMs;
|
|
18
|
+
steps.at(-1).outputEndMs = e.at - outputOriginMs;
|
|
19
|
+
}
|
|
20
|
+
steps.push({ scenarioId: sid, stepId: e.stepId, position: Number(e.position), commitMs: e.engineMs, outputCommitMs: e.at - outputOriginMs, endMs: e.engineMs, outputEndMs: e.at - outputOriginMs, camera: e.camera, media: e.media, text: e.text });
|
|
21
|
+
}
|
|
22
|
+
const current = steps.at(-1);
|
|
23
|
+
if (current && !ended.has(current.stepId)) {
|
|
24
|
+
current.endMs = e.engineMs;
|
|
25
|
+
current.outputEndMs = e.at - outputOriginMs;
|
|
26
|
+
if (e.dwell && e.stepId === current.stepId)
|
|
27
|
+
dwelled.add(current.stepId);
|
|
28
|
+
if ((dwelled.has(current.stepId) && e.dwell === null && e.activeStep === null) || (e.position === current.position && e.activeStep === e.position) || e.playing === false)
|
|
29
|
+
ended.add(current.stepId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const mediaEvents = [];
|
|
33
|
+
let previous = {}, previousCommit = '';
|
|
34
|
+
for (const e of raw.events) {
|
|
35
|
+
if (!e.media || typeof e.media !== 'object')
|
|
36
|
+
continue;
|
|
37
|
+
const key = `${e.scenarioId}:${e.position}`;
|
|
38
|
+
if (key === previousCommit)
|
|
39
|
+
continue;
|
|
40
|
+
previousCommit = key;
|
|
41
|
+
const current = e.media;
|
|
42
|
+
const emit = (track, action, value, fadeMs = 0) => mediaEvents.push({ track, action, engineMs: e.engineMs, outputMs: e.at - outputOriginMs, resource: String(value.resource), offsetMs: Number(value.offsetMs ?? 0), volume: Number(value.volume ?? 1), fadeMs, snapshot: value });
|
|
43
|
+
for (const [track, value] of Object.entries(current)) {
|
|
44
|
+
const before = previous[track];
|
|
45
|
+
if (!before || before.resource !== value.resource)
|
|
46
|
+
emit(track, 'play', value, Number(value.fadeInMs ?? 0));
|
|
47
|
+
else if (value.startOffsetMs !== undefined && value.startOffsetMs !== before.startOffsetMs)
|
|
48
|
+
emit(track, 'seek', value, Number(value.fadeInMs ?? 0));
|
|
49
|
+
if (value.stopAfterMs !== undefined && before?.stopAfterMs === undefined)
|
|
50
|
+
emit(track, 'stop', value, Number(value.stopAfterMs));
|
|
51
|
+
else if (before && value.volume !== before.volume && value.stopAfterMs === undefined)
|
|
52
|
+
emit(track, 'volume', value);
|
|
53
|
+
}
|
|
54
|
+
for (const [track, value] of Object.entries(previous))
|
|
55
|
+
if (!current[track] && value.stopAfterMs === undefined && value.endAfterMs === undefined)
|
|
56
|
+
emit(track, 'stop', value);
|
|
57
|
+
previous = current;
|
|
58
|
+
}
|
|
59
|
+
const final = raw.events.at(-1);
|
|
60
|
+
return { completion: { completed: raw.completed ?? false, scenarioId: typeof final?.scenarioId === 'string' ? final.scenarioId : null, engineMs: final?.engineMs ?? 0, outputMs: final ? final.at - outputOriginMs : 0 }, mediaEvents, steps, chapters, schemaVersion: 1, origin: 'playback', timing: { sampleToleranceMs, outputOriginMs }, events: raw.events.map(e => ({ ...e, at: e.at - (raw.startedAt ?? 0), outputMs: e.at - outputOriginMs, ...(typeof e.endAt === 'number' ? { endAt: e.endAt - (raw.startedAt ?? 0), outputEndMs: e.endAt - outputOriginMs } : {}) })) };
|
|
61
|
+
}
|
|
62
|
+
/** Accumulated integer targets avoid ceil(1000 / fps) drift in Playwright runFor. */
|
|
63
|
+
export function frameTime(index, fps) { return Math.round(index * 1000 / fps); }
|
|
64
|
+
/** Make the timeline useful after its temporary recording server has closed. Only referenced audio is copied. */
|
|
65
|
+
export async function persistTimeline(file, timeline, mediaAssets, baseUrl, overwrite = false, localToken, mediaInfo = {}) {
|
|
66
|
+
const fs = await import('node:fs/promises'), path = await import('node:path'), crypto = await import('node:crypto');
|
|
67
|
+
const directory = `${file.replace(/\.json$/i, '')}.assets`, assets = [];
|
|
68
|
+
const copy = async (id, kind, source, audioInfo) => {
|
|
69
|
+
const url = new URL(source, baseUrl);
|
|
70
|
+
let response;
|
|
71
|
+
if (localToken && url.origin === new URL(baseUrl).origin && /^\/__joplo\/p\/[^/]+\/resources\//.test(url.pathname)) {
|
|
72
|
+
const resolved = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', 'x-joplo-token': localToken }, body: '{}' });
|
|
73
|
+
if (!resolved.ok)
|
|
74
|
+
throw new Error(`Timeline media resource ${id} could not be resolved (${resolved.status})`);
|
|
75
|
+
const result = await resolved.json();
|
|
76
|
+
audioInfo = result.audio ?? audioInfo;
|
|
77
|
+
if (!result.url?.startsWith('data:'))
|
|
78
|
+
throw new Error(`Timeline media resource ${id} is unavailable; prepare local resources first`);
|
|
79
|
+
response = await fetch(result.url);
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
response = await fetch(url);
|
|
83
|
+
if (!response.ok)
|
|
84
|
+
throw new Error(`Timeline audio asset ${id} could not be read (${response.status})`);
|
|
85
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
86
|
+
const mime = response.headers.get('content-type') ?? '';
|
|
87
|
+
const suffix = mime.includes('wav') ? '.wav' : mime.includes('ogg') ? '.ogg' : mime.includes('flac') ? '.flac' : mime.includes('webm') ? '.webm' : '.mp3';
|
|
88
|
+
const name = crypto.createHash('sha256').update(bytes).digest('hex') + suffix;
|
|
89
|
+
await fs.mkdir(directory, { recursive: true });
|
|
90
|
+
const destination = path.join(directory, name);
|
|
91
|
+
let existing = null;
|
|
92
|
+
try {
|
|
93
|
+
existing = await fs.readFile(destination);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (e.code !== 'ENOENT')
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
99
|
+
const valid = existing?.length === bytes.length && crypto.createHash('sha256').update(existing).digest('hex') === name.split('.')[0];
|
|
100
|
+
if (existing && !valid && !overwrite)
|
|
101
|
+
throw new Error(`Timeline asset ${name} is incomplete or corrupt; use --overwrite to replace it`);
|
|
102
|
+
if (!valid) {
|
|
103
|
+
try {
|
|
104
|
+
await writeOutput(destination, bytes, !!existing && overwrite);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
if (e.code !== 'EEXIST')
|
|
108
|
+
throw e;
|
|
109
|
+
const raced = await fs.readFile(destination);
|
|
110
|
+
if (raced.length !== bytes.length || crypto.createHash('sha256').update(raced).digest('hex') !== name.split('.')[0])
|
|
111
|
+
throw new Error(`Concurrent timeline asset ${name} failed content validation`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const relative = `${path.basename(directory)}/${name}`;
|
|
115
|
+
if (!assets.some(a => a.id === id && a.kind === kind))
|
|
116
|
+
assets.push({ id, kind, file: relative, ...(audioInfo ? { audioInfo } : {}) });
|
|
117
|
+
return relative;
|
|
118
|
+
};
|
|
119
|
+
const voiceFiles = new Map();
|
|
120
|
+
for (const event of timeline.events)
|
|
121
|
+
if (event.type === 'narration' && event.source === 'clip' && typeof event.file === 'string') {
|
|
122
|
+
const source = event.file;
|
|
123
|
+
if (!voiceFiles.has(source))
|
|
124
|
+
voiceFiles.set(source, await copy(String(event.clipId ?? source), 'narration', source));
|
|
125
|
+
event.file = voiceFiles.get(source);
|
|
126
|
+
}
|
|
127
|
+
const resources = new Set();
|
|
128
|
+
for (const event of timeline.events)
|
|
129
|
+
if (event.media && typeof event.media === 'object')
|
|
130
|
+
for (const track of Object.values(event.media))
|
|
131
|
+
if (track.resource)
|
|
132
|
+
resources.add(track.resource);
|
|
133
|
+
for (const id of resources)
|
|
134
|
+
if (mediaAssets[id])
|
|
135
|
+
await copy(id, 'media', mediaAssets[id], mediaInfo[id]);
|
|
136
|
+
timeline.assets = assets;
|
|
137
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
138
|
+
await writeOutput(file, JSON.stringify(timeline, null, 2), overwrite);
|
|
139
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { JoploError } from '@joplo-app/core';
|
|
3
|
+
/** Optional local encoder. Capture and sample-clock calibration always happen before conversion. */
|
|
4
|
+
export async function encodeMp4(input, output, overwrite = false) {
|
|
5
|
+
await new Promise((resolve, reject) => {
|
|
6
|
+
const child = spawn('ffmpeg', ['-nostdin', '-v', 'error', overwrite ? '-y' : '-n', '-i', input, '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-movflags', '+faststart', output], { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
7
|
+
let stderr = '';
|
|
8
|
+
child.stderr.on('data', b => { stderr = (stderr + String(b)).slice(-16000); });
|
|
9
|
+
child.once('error', e => reject(new JoploError('EXPORT_FAILED', `MP4 needs local ffmpeg with H.264/AAC support: ${e.message}. Use .webm to export without it.`)));
|
|
10
|
+
child.once('close', code => code === 0 ? resolve() : reject(new JoploError('EXPORT_FAILED', `MP4 encoding failed (exit ${code}): ${stderr}`)));
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/vite-shared.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { kitAliases, locateWebAssets } from './web-assets.js';
|
|
|
5
5
|
export declare function realProjectDir(dir: string): string;
|
|
6
6
|
/** 不参与编译的项目子目录。 */
|
|
7
7
|
export declare const IGNORED_DIRS: string[];
|
|
8
|
-
export declare function isProjectSource(projectDir: string, file: string): boolean;
|
|
8
|
+
export declare function isProjectSource(projectDir: string, file: string, ignored?: readonly string[]): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* 项目目录之外、不在 node_modules 里的源文件(例如一个仓库里多个 Joplo 项目共用的上层组件):
|
|
11
11
|
* 最近的 tsconfig.json 声明了 jsxImportSource "@joplo-app/kit" 时,同样按 Joplo 的 JSX 运行时转译(#61)。
|
package/dist/vite-shared.js
CHANGED
|
@@ -23,12 +23,12 @@ export function realProjectDir(dir) {
|
|
|
23
23
|
}
|
|
24
24
|
/** 不参与编译的项目子目录。 */
|
|
25
25
|
export const IGNORED_DIRS = ['.joplo', 'dist', 'node_modules', '.git'];
|
|
26
|
-
export function isProjectSource(projectDir, file) {
|
|
26
|
+
export function isProjectSource(projectDir, file, ignored = []) {
|
|
27
27
|
if (!file.startsWith(projectDir + path.sep))
|
|
28
28
|
return false;
|
|
29
29
|
const rel = file.slice(projectDir.length + 1);
|
|
30
30
|
const first = rel.split(path.sep)[0] ?? '';
|
|
31
|
-
return !IGNORED_DIRS.includes(first);
|
|
31
|
+
return !IGNORED_DIRS.includes(first) && !ignored.some(p => rel.split(path.sep).join('/') === p || rel.split(path.sep).join('/').startsWith(p + '/'));
|
|
32
32
|
}
|
|
33
33
|
/** 读 tsconfig(允许注释与尾逗号),沿相对路径的 extends 找 compilerOptions.jsxImportSource。 */
|
|
34
34
|
function tsconfigJsxSource(file, depth = 0) {
|
package/dist/voice-http.js
CHANGED
|
@@ -302,7 +302,7 @@ export class VoiceHub {
|
|
|
302
302
|
this.jobs.set(projectId, job);
|
|
303
303
|
let summary;
|
|
304
304
|
try {
|
|
305
|
-
summary = await cache.generate(segs, content ?? (typeof body.locale === 'string' ? body.locale.slice(0, 20) : '
|
|
305
|
+
summary = await cache.generate(segs, content ?? project?.i18n?.default ?? (typeof body.locale === 'string' ? body.locale.slice(0, 20) : 'und'), resolved, this.store, {
|
|
306
306
|
fetch: this.opts.fetch,
|
|
307
307
|
signal: job.abort.signal,
|
|
308
308
|
inflight: this.inflightOf(projectId),
|
|
@@ -347,7 +347,7 @@ export class VoiceHub {
|
|
|
347
347
|
// Joplo Cloud 朗读不在播放时现场生成(会花用户的字数):只有「生成缺少的音频」或 joplo voice 才请求云端;缺音频的步骤用浏览器朗读
|
|
348
348
|
if (resolved.profile?.kind === 'cloud')
|
|
349
349
|
return ctx.send(409, { error: { code: 'CLOUD_GENERATE_ONLY', message: 'Joplo Cloud narration is generated only with Generate missing audio (or npx joplo voice); this step uses the browser voice' } }), true;
|
|
350
|
-
const p = cache.generateOne(seg, content ?? (typeof body.locale === 'string' ? body.locale.slice(0, 20) : '
|
|
350
|
+
const p = cache.generateOne(seg, content ?? project?.i18n?.default ?? (typeof body.locale === 'string' ? body.locale.slice(0, 20) : 'und'), resolved, this.store, {
|
|
351
351
|
fetch: this.opts.fetch,
|
|
352
352
|
inflight: this.inflightOf(projectId),
|
|
353
353
|
cloud: this.opts.cloud,
|