@joplo-app/server 0.2.17 → 0.2.18
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/build.js +4 -2
- package/dist/cloud.d.ts +129 -2
- package/dist/cloud.js +29 -6
- package/dist/contract.d.ts +16 -0
- package/dist/dev.js +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/page-report.js +7 -0
- package/dist/render.d.ts +7 -1
- package/dist/render.js +80 -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/package.json +4 -4
package/dist/build.js
CHANGED
|
@@ -45,6 +45,8 @@ export const jsonForHtml = (v) => JSON.stringify(v).replace(/</g, '\\u003c').rep
|
|
|
45
45
|
export function finalizeHtml(html, readAsset, inline, identity) {
|
|
46
46
|
const inlined = [];
|
|
47
47
|
let out = html.replace(/\s+crossorigin(?:="[^"]*")?/g, '');
|
|
48
|
+
// 作者标记只由 Cloud 注入,不能随本地构建或导出传播。
|
|
49
|
+
out = out.replace(/<meta\b[^>]*\bname\s*=\s*["']joplo-author["'][^>]*>/gi, '');
|
|
48
50
|
out = out.replace(/<link rel="modulepreload"[^>]*>\s*/g, '');
|
|
49
51
|
out = out.replace(/<script type="module" src="\.\/([^"]+)"><\/script>/g, (_m, rel) => {
|
|
50
52
|
inlined.push(rel);
|
|
@@ -148,8 +150,8 @@ export async function buildSite(opts) {
|
|
|
148
150
|
// 朗读(D74):当前声音已生成的音频拷进 voice/,IR 带上 voiceIndex;Key 不进产物
|
|
149
151
|
const store = new ProfileStore(opts.home ?? joploHome());
|
|
150
152
|
// 重新发布(D84):先从上一次的分享沿用本机没有的音频(同样的文字与声音),不重新生成
|
|
151
|
-
const reused = opts.sharedVoice ? await reuseSharedVoice(projectDir, project, opts.sharedVoice, store) : 0;
|
|
152
|
-
const voice = bundleVoice(projectDir, project, staging, store, undefined, opts.sharedVoice?.index);
|
|
153
|
+
const reused = opts.sharedVoice ? await reuseSharedVoice(projectDir, project, opts.sharedVoice, store, undefined, opts.voiceDefault) : 0;
|
|
154
|
+
const voice = bundleVoice(projectDir, project, staging, store, undefined, opts.sharedVoice?.index, opts.voiceDefault);
|
|
153
155
|
if (reused)
|
|
154
156
|
voice.report.reused = reused;
|
|
155
157
|
// 朗读角色只留范围内功能的(scopeProject 对 voiceIndex 的同一规则;bundleVoice 按声音配置生成全部角色)
|
package/dist/cloud.d.ts
CHANGED
|
@@ -12,45 +12,172 @@
|
|
|
12
12
|
import type http from 'node:http';
|
|
13
13
|
import type { ScopeInfo } from '@joplo-app/core';
|
|
14
14
|
export declare const CLOUD_EVENT = "joplo:cloud";
|
|
15
|
+
export type CloudVisibility = 'public' | 'private';
|
|
16
|
+
export type CloudPortfolio = {
|
|
17
|
+
workUrl: string | null;
|
|
18
|
+
profileUrl: string | null;
|
|
19
|
+
needsUsername: boolean;
|
|
20
|
+
setupPath: string;
|
|
21
|
+
};
|
|
22
|
+
export type CloudLinks = {
|
|
23
|
+
main: {
|
|
24
|
+
visibility?: CloudVisibility;
|
|
25
|
+
passwordProtected?: boolean;
|
|
26
|
+
} | null;
|
|
27
|
+
scoped?: Record<string, {
|
|
28
|
+
visibility?: CloudVisibility;
|
|
29
|
+
passwordProtected?: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
15
32
|
export type CloudAccount = {
|
|
16
33
|
signedIn: true;
|
|
17
34
|
server: string;
|
|
18
35
|
email: string;
|
|
19
36
|
plan: 'free' | 'pro' | null;
|
|
37
|
+
/** 账号容量(C27);云端连不上或旧云端时没有。 */
|
|
38
|
+
storage?: CloudStorage;
|
|
39
|
+
/** 托管朗读额度(D85,`GET /api/v1/voice` 的 quota);云端连不上或旧云端(404)时没有。 */
|
|
40
|
+
voice?: VoiceQuota;
|
|
41
|
+
username?: string | null;
|
|
42
|
+
portfolioUrl?: string | null;
|
|
20
43
|
} | {
|
|
21
44
|
signedIn: false;
|
|
22
45
|
server: string;
|
|
23
46
|
loginCommand: string;
|
|
24
47
|
message?: string;
|
|
25
48
|
};
|
|
49
|
+
/** 托管朗读额度(D85,与 Cloud 契约 `GET /api/v1/voice` 的 quota 一致):免费是一次性的体验额度(trial),Pro 按月(month)。字数 = Array.from(文字).length。 */
|
|
50
|
+
export type VoiceQuota = {
|
|
51
|
+
plan: string;
|
|
52
|
+
period: 'trial' | 'month';
|
|
53
|
+
allowanceChars: number;
|
|
54
|
+
usedChars: number;
|
|
55
|
+
remainingChars: number;
|
|
56
|
+
/** 本月额度的重置时间(ISO);体验额度为 null。 */
|
|
57
|
+
resetsAt: string | null;
|
|
58
|
+
/** 加油包:各自剩余与到期时间。 */
|
|
59
|
+
packs: {
|
|
60
|
+
remainingChars: number;
|
|
61
|
+
expiresAt: string;
|
|
62
|
+
}[];
|
|
63
|
+
/** 当月(或体验)剩余 + 加油包剩余。看板与 CLI 显示的“剩 N 字”就是它。 */
|
|
64
|
+
totalRemainingChars: number;
|
|
65
|
+
};
|
|
66
|
+
/** Joplo 音色(Cloud 固定 6 个,都是多语言):labels / samples 按界面语言(10 种之一)。 */
|
|
67
|
+
export type CloudVoice = {
|
|
68
|
+
id: string;
|
|
69
|
+
gender: 'female' | 'male';
|
|
70
|
+
labels: Record<string, string>;
|
|
71
|
+
samples: Record<string, string>;
|
|
72
|
+
};
|
|
73
|
+
/** `GET /api/v1/voice` 去掉 quota 之后的部分:音色表、每种语言的推荐音色、默认音色。 */
|
|
74
|
+
export type CloudVoiceCatalog = {
|
|
75
|
+
model: string;
|
|
76
|
+
voices: CloudVoice[];
|
|
77
|
+
recommended: Record<string, string[]>;
|
|
78
|
+
defaultVoice: string;
|
|
79
|
+
};
|
|
80
|
+
export type CloudVoiceInfo = CloudVoiceCatalog & {
|
|
81
|
+
quota: VoiceQuota;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* 托管朗读的状态:没登录时给登录命令;已登录时 voice 是 `GET /api/v1/voice` 的内容,云端连不上或旧云端(404)时为 null(看板退回浏览器朗读)。
|
|
85
|
+
*/
|
|
86
|
+
export type CloudVoiceStatus = {
|
|
87
|
+
signedIn: false;
|
|
88
|
+
server: string;
|
|
89
|
+
loginCommand: string;
|
|
90
|
+
} | {
|
|
91
|
+
signedIn: true;
|
|
92
|
+
server: string;
|
|
93
|
+
voice: CloudVoiceInfo | null;
|
|
94
|
+
};
|
|
95
|
+
/** `POST /api/v1/voice/speech` 的请求:locale 是内容语言(D84,不知道时不带),project 是项目名(控制台明细用)。 */
|
|
96
|
+
export type CloudSpeechRequest = {
|
|
97
|
+
text: string;
|
|
98
|
+
voice: string;
|
|
99
|
+
locale?: string;
|
|
100
|
+
project?: string;
|
|
101
|
+
};
|
|
102
|
+
/** 合成结果:音频与响应头(X-Joplo-Chars-Charged / -Remaining、X-Joplo-Cache、X-Joplo-Audio-Sha256),头缺失或不合法时为 null。 */
|
|
103
|
+
export type CloudSpeechResult = {
|
|
104
|
+
audio: Uint8Array;
|
|
105
|
+
contentType: string;
|
|
106
|
+
charged: number | null;
|
|
107
|
+
remaining: number | null;
|
|
108
|
+
cache: 'hit' | 'miss' | null;
|
|
109
|
+
sha256: string | null;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 托管朗读(D85)的 CLI 一侧:看板与 `joplo voice` 共用。server 包不依赖 CLI,由 CLI 注入(与 publish 一样)。
|
|
113
|
+
* speech 失败时抛 `{ code, message, data? }`:TTS_QUOTA_EXCEEDED(data: neededChars / remainingChars / usageUrl)、AUTH_REQUIRED、AUTH_EXPIRED、
|
|
114
|
+
* EMAIL_UNVERIFIED、FORBIDDEN、RATE_LIMITED、TTS_UNAVAILABLE、BAD_REQUEST、NOT_FOUND(旧云端)、NETWORK。
|
|
115
|
+
*/
|
|
116
|
+
export type CloudVoiceBridge = {
|
|
117
|
+
status(): Promise<CloudVoiceStatus>;
|
|
118
|
+
speech(req: CloudSpeechRequest): Promise<CloudSpeechResult>;
|
|
119
|
+
};
|
|
120
|
+
/** 账号容量(C27):已用 / 上限,字节。 */
|
|
121
|
+
export type CloudStorage = {
|
|
122
|
+
usedBytes: number;
|
|
123
|
+
quotaBytes: number;
|
|
124
|
+
};
|
|
125
|
+
/** 容量不足(QUOTA_EXCEEDED,kind: storage):数字可能缺;两个链接已拼好当前 server。 */
|
|
126
|
+
export type CloudStorageFull = {
|
|
127
|
+
usedBytes?: number;
|
|
128
|
+
quotaBytes?: number;
|
|
129
|
+
shareBytes?: number;
|
|
130
|
+
replacedBytes?: number;
|
|
131
|
+
manageUrl: string;
|
|
132
|
+
upgradeUrl: string;
|
|
133
|
+
};
|
|
26
134
|
/** 范围:都为空 = 整个项目(D75)。 */
|
|
27
135
|
export type CloudPublishRequest = {
|
|
136
|
+
password?: string | null;
|
|
137
|
+
visibility?: CloudVisibility;
|
|
138
|
+
review?: boolean;
|
|
28
139
|
scenarios?: string[];
|
|
29
140
|
features?: string[];
|
|
30
141
|
};
|
|
31
142
|
export type CloudPublishResult = {
|
|
143
|
+
passwordProtected?: boolean;
|
|
144
|
+
mode?: 'review';
|
|
145
|
+
visibility?: CloudVisibility;
|
|
146
|
+
portfolio?: CloudPortfolio;
|
|
147
|
+
review?: {
|
|
148
|
+
url: string;
|
|
149
|
+
shareId: string;
|
|
150
|
+
};
|
|
32
151
|
shareId: string;
|
|
33
152
|
url: string;
|
|
34
153
|
expiresAt: string | null;
|
|
35
154
|
version: number;
|
|
36
155
|
plan: 'free' | 'pro';
|
|
37
|
-
scope?: ScopeInfo;
|
|
156
|
+
scope?: ScopeInfo; /** 发布后的账号容量与这次大小(C27)。 */
|
|
157
|
+
storage?: CloudStorage & {
|
|
158
|
+
shareBytes: number;
|
|
159
|
+
};
|
|
38
160
|
};
|
|
39
161
|
/** CLI 实现:account 只读本机登录(必要时问一次云端套餐);publish 就是 share(),progress 是它写给终端的每一行。 */
|
|
40
162
|
export type CloudBridge = {
|
|
41
163
|
account(): Promise<CloudAccount>;
|
|
164
|
+
links?(projectDir: string): Promise<CloudLinks>;
|
|
42
165
|
publish(projectDir: string, request: CloudPublishRequest, progress: (line: string) => void): Promise<CloudPublishResult>;
|
|
166
|
+
/** 托管朗读(D85);旧 CLI 没有这一项时看板只用浏览器朗读与自带 Key 的供应商。 */
|
|
167
|
+
voice?: CloudVoiceBridge;
|
|
43
168
|
};
|
|
44
169
|
/** 发布失败:code 来自 CLI(AUTH_REQUIRED、NOT_FOUND、NETWORK…);需要登录时带 loginCommand。 */
|
|
45
170
|
export type CloudJobError = {
|
|
46
171
|
code: string;
|
|
47
172
|
message: string;
|
|
48
173
|
loginCommand?: string;
|
|
174
|
+
upgradeUrl?: string; /** 容量不足时的数字与链接(C27)。 */
|
|
175
|
+
storage?: CloudStorageFull;
|
|
49
176
|
};
|
|
50
177
|
export type CloudJob = {
|
|
51
178
|
id: string;
|
|
52
179
|
state: 'running' | 'done' | 'failed';
|
|
53
|
-
request: CloudPublishRequest
|
|
180
|
+
request: Omit<CloudPublishRequest, 'password'>;
|
|
54
181
|
startedAt: number;
|
|
55
182
|
/** 进度:CLI 写给终端的行(英文,页面按开头识别阶段)。 */
|
|
56
183
|
lines: string[];
|
package/dist/cloud.js
CHANGED
|
@@ -37,6 +37,12 @@ export class CloudHub {
|
|
|
37
37
|
}
|
|
38
38
|
/** `/__joplo/p/<id>/cloud/<sub>`:sub = 'publish'(GET 读任务,POST 开始发布)。 */
|
|
39
39
|
async handleProject(projectId, dir, sub, req, ctx) {
|
|
40
|
+
if (sub === 'links' && req.method === 'GET') {
|
|
41
|
+
if (!ctx.guardWrite(false))
|
|
42
|
+
return true;
|
|
43
|
+
ctx.send(200, { links: await this.bridge?.links?.(dir) ?? { main: null } });
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
40
46
|
if (sub !== 'publish')
|
|
41
47
|
return false;
|
|
42
48
|
const method = req.method ?? 'GET';
|
|
@@ -60,7 +66,19 @@ export class CloudHub {
|
|
|
60
66
|
const body = (b.body ?? {});
|
|
61
67
|
const scenarios = strings(body.scenarios, 'scenarios');
|
|
62
68
|
const features = strings(body.features, 'features');
|
|
63
|
-
|
|
69
|
+
if (body.visibility !== 'public' && body.visibility !== 'private')
|
|
70
|
+
throw new Error('Choose visibility: public / private');
|
|
71
|
+
if (typeof body.review !== 'boolean')
|
|
72
|
+
throw new Error('Choose review: true / false');
|
|
73
|
+
if (body.visibility === 'public' && (scenarios?.length || features?.length))
|
|
74
|
+
throw new Error('Scoped shares must be private');
|
|
75
|
+
if (body.password !== undefined) {
|
|
76
|
+
if (body.visibility !== 'private')
|
|
77
|
+
throw new Error('Passwords require a private share');
|
|
78
|
+
if (body.password !== null && (typeof body.password !== 'string' || Array.from(body.password).length < 8 || Array.from(body.password).length > 128))
|
|
79
|
+
throw new Error('Access password must contain 8–128 characters');
|
|
80
|
+
}
|
|
81
|
+
request = { ...(body.password !== undefined ? { password: body.password } : {}), visibility: body.visibility, review: body.review, ...(scenarios?.length ? { scenarios } : {}), ...(features?.length ? { features } : {}) };
|
|
64
82
|
}
|
|
65
83
|
catch (e) {
|
|
66
84
|
return ctx.send(400, { error: { code: 'USAGE', message: e instanceof Error ? e.message : String(e) } }), true;
|
|
@@ -72,27 +90,32 @@ export class CloudHub {
|
|
|
72
90
|
return true;
|
|
73
91
|
}
|
|
74
92
|
start(projectId, dir, request) {
|
|
75
|
-
const
|
|
93
|
+
const { password, ...safeRequest } = request;
|
|
94
|
+
const redact = (text) => typeof password === 'string' && password ? text.split(password).join('[REDACTED]') : text;
|
|
95
|
+
const safe = (value) => JSON.parse(JSON.stringify(value, (_key, v) => typeof v === 'string' ? redact(v) : v));
|
|
96
|
+
const job = { id: `c${++this.seq}`, state: 'running', request: safe(safeRequest), startedAt: Date.now(), lines: [] };
|
|
76
97
|
this.jobs.set(projectId, job);
|
|
77
98
|
const push = () => this.emit(projectId, job);
|
|
78
99
|
push();
|
|
79
100
|
void this.bridge
|
|
80
101
|
.publish(dir, request, (line) => {
|
|
81
|
-
job.lines = [...job.lines, line].slice(-MAX_LINES);
|
|
102
|
+
job.lines = [...job.lines, redact(line)].slice(-MAX_LINES);
|
|
82
103
|
push();
|
|
83
104
|
})
|
|
84
105
|
.then((result) => {
|
|
85
106
|
job.state = 'done';
|
|
86
|
-
job.result = result;
|
|
107
|
+
job.result = safe(result);
|
|
87
108
|
})
|
|
88
109
|
.catch((e) => {
|
|
89
110
|
const err = e;
|
|
90
111
|
job.state = 'failed';
|
|
91
|
-
job.error = {
|
|
112
|
+
job.error = safe({
|
|
92
113
|
code: typeof err.code === 'string' ? err.code : 'INTERNAL',
|
|
93
114
|
message: typeof err.message === 'string' ? err.message : String(e),
|
|
94
115
|
...(typeof err.loginCommand === 'string' ? { loginCommand: err.loginCommand } : {}),
|
|
95
|
-
|
|
116
|
+
...(err.storage && typeof err.storage === 'object' ? { storage: err.storage } : {}),
|
|
117
|
+
...(typeof err.upgradeUrl === 'string' ? { upgradeUrl: err.upgradeUrl } : {}),
|
|
118
|
+
});
|
|
96
119
|
})
|
|
97
120
|
.finally(push);
|
|
98
121
|
return job;
|
package/dist/contract.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ export type BuildOptions = {
|
|
|
52
52
|
index: VoiceIndex;
|
|
53
53
|
fetch: (file: string) => Promise<Uint8Array | null>;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* 项目没选过声音来源、config 也没写时用哪个(D85):CLI 已登录 Joplo Cloud 时传 'cloud'(与看板同一规则),
|
|
57
|
+
* 这样看板里默认用 cloud 生成的音频也会带上。缺省 null:只用看板里选过的(与原来一致)。
|
|
58
|
+
*/
|
|
59
|
+
voiceDefault?: string | null;
|
|
55
60
|
};
|
|
56
61
|
/** 静态发布站:只含选定方案(compile 的 publish 模式),离线可打开,可直接 `wrangler deploy`。 */
|
|
57
62
|
/**
|
|
@@ -126,3 +131,14 @@ export type RenderResult = {
|
|
|
126
131
|
warnings: string[];
|
|
127
132
|
};
|
|
128
133
|
export declare function renderStep(opts: RenderOptions): Promise<RenderResult>;
|
|
134
|
+
/** 分镜(storyboard):一个场景的每一步拼成一张图,每格下面是步号、字幕与旁白。 */
|
|
135
|
+
export type SheetOptions = Omit<RenderOptions, 'stepId' | 'viewport' | 'scope'> & {
|
|
136
|
+
columns?: number; /** 每格宽度(像素),默认 480。 */
|
|
137
|
+
cellWidth?: number;
|
|
138
|
+
};
|
|
139
|
+
export type SheetResult = {
|
|
140
|
+
path: string;
|
|
141
|
+
steps: number;
|
|
142
|
+
warnings: string[];
|
|
143
|
+
};
|
|
144
|
+
export declare function renderSheet(opts: SheetOptions): Promise<SheetResult>;
|
package/dist/dev.js
CHANGED
|
@@ -337,6 +337,8 @@ export async function createHub(opts = {}) {
|
|
|
337
337
|
});
|
|
338
338
|
// 朗读(D74):声音供应商 profile(本机)与项目音频缓存;状态变化推 joplo:voice
|
|
339
339
|
const voiceHub = new VoiceHub(opts.home ?? joploHome(), {
|
|
340
|
+
// 托管朗读(D85):CLI 注入的登录与合成;旧 CLI 没有时只用浏览器朗读与自带 Key 的供应商
|
|
341
|
+
cloud: opts.cloud?.voice,
|
|
340
342
|
emit: (projectId, state) => {
|
|
341
343
|
if (!closed)
|
|
342
344
|
server?.ws.send({ type: 'custom', event: VOICE_EVENT, data: { projectId, state } });
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
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';
|
|
13
15
|
export { EXPORT_DOWNLOAD_MB, PLAYWRIGHT_VERSION, SETUP_COMMAND, exportRuntimeStatus, installExportRuntime, uninstallExportRuntime, type ExportRuntimeStatus, type InstallProgress, type InstallResult } from './export-runtime.js';
|
|
14
16
|
export { buildFeatureDiff, publicIRFromHtml, type DiffBuildOptions, type DiffBuildResult } from './feature-diff.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
4
5
|
export { EXPORT_DOWNLOAD_MB, PLAYWRIGHT_VERSION, SETUP_COMMAND, exportRuntimeStatus, installExportRuntime, uninstallExportRuntime } from "./export-runtime.js";
|
|
5
6
|
export { buildFeatureDiff, publicIRFromHtml } from "./feature-diff.js";
|
package/dist/page-report.js
CHANGED
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
const cx = r.left + r.width / 2;
|
|
34
34
|
const cy = r.top + r.height / 2;
|
|
35
35
|
if (cx < sr.left || cx > sr.right || cy < sr.top || cy > sr.bottom) {
|
|
36
|
+
// 画布(Canvas)里的元素被镜头移出画面是常态:只在它是下一步要操作的目标时才提示
|
|
37
|
+
if (el.closest('[data-jcanvas-world]') && el.dataset.jid !== args.nextTargetId) return;
|
|
36
38
|
warnings.push(`Outside frame: "${e.label}"(${e.id}) has its center outside the frame`);
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
@@ -51,6 +53,11 @@
|
|
|
51
53
|
if (offViewport.length)
|
|
52
54
|
warnings.push(`Outside viewport: viewport ${vw}×${vh} is smaller than the stage; ${offViewport.length} interactive elements have centers outside the viewport; occlusion checks skipped (${offViewport.join(', ')})`);
|
|
53
55
|
|
|
56
|
+
// 1b. 画布(Canvas)没有尺寸:放在没有宽 / 高的容器里时整块不可见
|
|
57
|
+
stage.querySelectorAll('[data-jcanvas]').forEach((c) => {
|
|
58
|
+
if (c.clientWidth < 1 || c.clientHeight < 1) warnings.push(`Canvas has no size: ${name(c)} is ${c.clientWidth}×${c.clientHeight}px, so nothing in it is visible; give its container a width and height (h="100%" in a layer) or let it size from its view ratio`);
|
|
59
|
+
});
|
|
60
|
+
|
|
54
61
|
// 2. 标签文字溢出
|
|
55
62
|
stage.querySelectorAll('[data-jtext], .jtrunc').forEach((t) => {
|
|
56
63
|
if (t.scrollWidth > t.clientWidth + 1) warnings.push(`Label text overflow: ${name(t)} text "${(t.textContent ?? '').slice(0, 40)}" is clipped`);
|
package/dist/render.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Browser } from 'playwright-core';
|
|
2
2
|
import { type AppearanceFont, type AppearanceStroke } from '@joplo-app/core';
|
|
3
|
-
import type { RenderOptions, RenderResult } from './contract.js';
|
|
3
|
+
import type { RenderOptions, RenderResult, SheetOptions, SheetResult } from './contract.js';
|
|
4
4
|
import { type PlaywrightModule } from './export-runtime.js';
|
|
5
5
|
export { loadPlaywright, type PlaywrightModule } from './export-runtime.js';
|
|
6
6
|
/** 浏览器启动失败时的一行提示(托管运行时与项目里的 Playwright 都适用:重装 Joplo 自己的导出组件)。 */
|
|
@@ -25,3 +25,9 @@ export declare function renderQuery(q: {
|
|
|
25
25
|
};
|
|
26
26
|
}): string;
|
|
27
27
|
export declare function renderStep(opts: RenderOptions): Promise<RenderResult>;
|
|
28
|
+
/**
|
|
29
|
+
* 分镜(storyboard):一个场景从初始画面到最后一步,每一步截一张(与 renderStep 同一渲染路由),
|
|
30
|
+
* 拼成网格;每格下面写步号、字幕、旁白(narrate,没有时是台词 say)。Agent 一张图看完整场的画面与节奏,
|
|
31
|
+
* 检查空镜、出画、遮挡、字太小,再对照旁白读一遍。告警按步号前缀汇总。
|
|
32
|
+
*/
|
|
33
|
+
export declare function renderSheet(opts: SheetOptions): Promise<SheetResult>;
|
package/dist/render.js
CHANGED
|
@@ -160,4 +160,84 @@ export async function renderStep(opts) {
|
|
|
160
160
|
await server.close();
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
+
const esc = (t) => t.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
164
|
+
/**
|
|
165
|
+
* 分镜(storyboard):一个场景从初始画面到最后一步,每一步截一张(与 renderStep 同一渲染路由),
|
|
166
|
+
* 拼成网格;每格下面写步号、字幕、旁白(narrate,没有时是台词 say)。Agent 一张图看完整场的画面与节奏,
|
|
167
|
+
* 检查空镜、出画、遮挡、字太小,再对照旁白读一遍。告警按步号前缀汇总。
|
|
168
|
+
*/
|
|
169
|
+
export async function renderSheet(opts) {
|
|
170
|
+
const projectDir = realProjectDir(opts.projectDir);
|
|
171
|
+
const out = path.resolve(opts.out);
|
|
172
|
+
assertNotProjectData(projectDir, out);
|
|
173
|
+
if (fs.existsSync(out) && !opts.overwrite)
|
|
174
|
+
throw new JoploError('USAGE', `Output file already exists: ${out}. To overwrite, pass overwrite: true (CLI: --overwrite)`);
|
|
175
|
+
const columns = Math.max(1, Math.min(6, Math.round(opts.columns ?? 3)));
|
|
176
|
+
const cellWidth = Math.max(240, Math.min(1280, Math.round(opts.cellWidth ?? 480)));
|
|
177
|
+
const playwright = await loadPlaywright({ home: joploHome(), projectDir });
|
|
178
|
+
const server = await createDev({ projectDir, port: 0, watch: false, log: () => undefined });
|
|
179
|
+
let browser = null;
|
|
180
|
+
try {
|
|
181
|
+
const payload = server.payload();
|
|
182
|
+
if (!payload.project) {
|
|
183
|
+
const errs = payload.diagnostics.filter((d) => d.severity === 'error');
|
|
184
|
+
throw new JoploError('INVALID_SCHEMA', `Project compilation failed: ${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('; ')}`, { diagnostics: payload.diagnostics });
|
|
185
|
+
}
|
|
186
|
+
const project = payload.project;
|
|
187
|
+
const sc = project.scenarios[opts.scenarioId];
|
|
188
|
+
if (!sc)
|
|
189
|
+
throw new JoploError('NOT_FOUND', `Scenario does not exist: ${opts.scenarioId} (available: ${Object.keys(project.scenarios).join(', ') || 'none'})`);
|
|
190
|
+
if (opts.content !== undefined && !project.i18n?.locales.includes(opts.content))
|
|
191
|
+
throw new JoploError('USAGE', project.i18n ? `--content ${opts.content} is not in config locales (${project.i18n.locales.join(', ')})` : `--content needs config({ locales }); this project has a single language`);
|
|
192
|
+
const theme = opts.theme ?? project.theme ?? 'sketch';
|
|
193
|
+
browser = await launch(playwright);
|
|
194
|
+
const cells = [];
|
|
195
|
+
const warnings = [];
|
|
196
|
+
for (let position = 0; position <= sc.steps.length; position++) {
|
|
197
|
+
const state = stateAt(project, sc.id, position);
|
|
198
|
+
const scene = project.scenes[displaySceneId(project, sc.id, position)];
|
|
199
|
+
const stage = STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
200
|
+
const next = state.completed ? undefined : sc.steps[position];
|
|
201
|
+
const nextTargetId = next && 'target' in next.action ? next.action.target : null;
|
|
202
|
+
const page = await browser.newPage({ viewport: { width: stage.width, height: stage.height + SUBTITLE_HEIGHT }, deviceScaleFactor: 1, reducedMotion: 'reduce' });
|
|
203
|
+
const q = renderQuery({ projectId: server.projectId, scenarioId: sc.id, position, theme, locale: opts.locale, content: opts.content, font: opts.font, stroke: opts.stroke });
|
|
204
|
+
await page.goto(`${server.url}?${q}`, { waitUntil: 'domcontentloaded' });
|
|
205
|
+
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
206
|
+
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
207
|
+
if (err)
|
|
208
|
+
throw new JoploError('RENDER_FAILED', `Render route reported an error at step ${position}: ${err}`);
|
|
209
|
+
const report = (await page.evaluate(`(${COLLECT_REPORT})(${JSON.stringify({ nextTargetId, theme })})`));
|
|
210
|
+
for (const w of report.warnings)
|
|
211
|
+
warnings.push(`Step ${position}: ${w}`);
|
|
212
|
+
const png = await page.locator('[data-jrender]').screenshot({ type: 'png', animations: 'disabled' });
|
|
213
|
+
await page.close();
|
|
214
|
+
const step = position > 0 ? sc.steps[position - 1] : undefined;
|
|
215
|
+
cells.push({
|
|
216
|
+
png: png.toString('base64'),
|
|
217
|
+
label: position === 0 ? '0 · start' : `${position} · ${step.kind}`,
|
|
218
|
+
caption: step?.caption ?? sc.description ?? sc.name,
|
|
219
|
+
voice: step?.narrate ?? step?.say ?? '',
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
const html = `<!doctype html><meta charset="utf-8"><style>
|
|
223
|
+
body{margin:0;padding:24px;background:#16181d;color:#e8e8ea;font:14px/1.45 -apple-system,"PingFang SC","Noto Sans SC",system-ui,sans-serif}
|
|
224
|
+
h1{font-size:18px;margin:0 0 16px} .grid{display:grid;grid-template-columns:repeat(${columns},${cellWidth}px);gap:18px}
|
|
225
|
+
.cell img{width:100%;display:block;border-radius:6px;border:1px solid #2c2f38} .meta{padding:6px 2px 0}
|
|
226
|
+
.n{color:#ffb020;font-weight:700} .cap{font-weight:600} .voice{color:#a0a4b0;margin-top:2px}
|
|
227
|
+
</style><h1>${esc(sc.name)} · ${esc(sc.id)} · ${sc.steps.length} steps</h1><div class="grid">${cells.map((c) => `<div class="cell"><img src="data:image/png;base64,${c.png}"><div class="meta"><span class="n">${esc(c.label)}</span> <span class="cap">${esc(c.caption)}</span>${c.voice ? `<div class="voice">${esc(c.voice)}</div>` : ''}</div></div>`).join('')}</div>`;
|
|
228
|
+
const sheet = await browser.newPage({ viewport: { width: columns * cellWidth + (columns - 1) * 18 + 48, height: 800 }, deviceScaleFactor: 1 });
|
|
229
|
+
await sheet.setContent(html, { waitUntil: 'load' });
|
|
230
|
+
const png = await sheet.screenshot({ type: 'png', fullPage: true });
|
|
231
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
232
|
+
if (opts.overwrite)
|
|
233
|
+
fs.writeFileSync(out, png);
|
|
234
|
+
else
|
|
235
|
+
fs.writeFileSync(out, png, { flag: 'wx' });
|
|
236
|
+
return { path: out, steps: sc.steps.length, warnings };
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
await browser?.close().catch(() => undefined);
|
|
240
|
+
await server.close();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
163
243
|
const COLLECT_REPORT = fs.readFileSync(path.join(import.meta.dirname, 'page-report.js'), 'utf8').replace(/^\/\*[\s\S]*?\*\/\s*/, '');
|
package/dist/voice-http.d.ts
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import type http from 'node:http';
|
|
2
2
|
import type { Project } from '@joplo-app/core';
|
|
3
|
-
import {
|
|
3
|
+
import type { CloudVoiceBridge, VoiceQuota } from './cloud.js';
|
|
4
|
+
import { ProfileStore, type FetchLike, type PublicProfile, type ResolvedVoices } from './voice.js';
|
|
5
|
+
/** 看板里托管朗读的状态(D85)。null = 这个看板没有 bridge(旧 CLI 启动),只能用浏览器朗读与自带 Key 的供应商。 */
|
|
6
|
+
export type VoiceCloudView = {
|
|
7
|
+
signedIn: boolean;
|
|
8
|
+
server: string | null;
|
|
9
|
+
/** 没登录时给的登录命令(看板里可复制)。 */
|
|
10
|
+
loginCommand: string | null;
|
|
11
|
+
/** 已登录且云端给了 /api/v1/voice(连不上或旧云端 404 时为 false,看板不显示数字)。 */
|
|
12
|
+
available: boolean;
|
|
13
|
+
/** 额度:云端给的,每段合成后用响应头里的剩余字数更新。 */
|
|
14
|
+
quota: VoiceQuota | null;
|
|
15
|
+
/** 控制台的用量页(`<server>/usage`,买加油包也在这里)。 */
|
|
16
|
+
usageUrl: string | null;
|
|
17
|
+
/** 上一次 cloud 合成收到 402:需要多少、还剩多少。 */
|
|
18
|
+
exhausted: {
|
|
19
|
+
neededChars: number | null;
|
|
20
|
+
remainingChars: number | null;
|
|
21
|
+
} | null;
|
|
22
|
+
};
|
|
4
23
|
export type VoiceState = {
|
|
5
24
|
/**
|
|
6
25
|
* 版本:每次算状态时递增(以微秒时钟为下限,dev 重启后也不会变小)。看板只接受 rev 不比当前小的状态:
|
|
7
26
|
* 推送、选择 / 生成的返回、profilesChanged 之后的重新读取可能乱序到达,晚到的旧状态不能覆盖新的。
|
|
8
27
|
*/
|
|
9
28
|
rev: number;
|
|
10
|
-
/** 看板里选的 profile(config 写了 voice.profile 时以 config 为准,见 source
|
|
29
|
+
/** 看板里选的 profile(config 写了 voice.profile 时以 config 为准,见 source);没选过为 null,看 source 是否为 default。 */
|
|
11
30
|
selected: string | null;
|
|
12
|
-
|
|
31
|
+
/** config / board / default(没选过,已登录时默认 cloud)/ null(浏览器朗读)。 */
|
|
32
|
+
source: ResolvedVoices['source'];
|
|
13
33
|
/** config 里写了、本机没有的 profile 名。 */
|
|
14
34
|
missing: string | null;
|
|
15
35
|
profile: PublicProfile | null;
|
|
@@ -41,6 +61,8 @@ export type VoiceState = {
|
|
|
41
61
|
roles: Record<string, string>;
|
|
42
62
|
};
|
|
43
63
|
}>;
|
|
64
|
+
/** 托管朗读(D85)。 */
|
|
65
|
+
cloud: VoiceCloudView | null;
|
|
44
66
|
};
|
|
45
67
|
type Ctx = {
|
|
46
68
|
guardWrite: (needJson?: boolean) => boolean;
|
|
@@ -61,17 +83,44 @@ export declare class VoiceHub {
|
|
|
61
83
|
/** 正在生成的段:项目 → (片段键 → 结果)。批量生成与边放边生成共用,同一段只请求一次。 */
|
|
62
84
|
private inflight;
|
|
63
85
|
private inflightOf;
|
|
86
|
+
/** 托管朗读状态(内存,CLOUD_TTL_MS):status = null 表示问云端时出错(当作连不上)。 */
|
|
87
|
+
private cloudCache;
|
|
88
|
+
private exhausted;
|
|
64
89
|
constructor(home: string, opts: {
|
|
65
90
|
emit: (projectId: string, state: VoiceState) => void;
|
|
66
91
|
profilesChanged?: () => void;
|
|
67
92
|
fetch?: FetchLike;
|
|
68
93
|
env?: Record<string, string | undefined>;
|
|
94
|
+
cloud?: CloudVoiceBridge;
|
|
95
|
+
now?: () => number;
|
|
69
96
|
});
|
|
97
|
+
private now;
|
|
98
|
+
private liveInfo;
|
|
99
|
+
/** 托管朗读的状态:内存里有、没过期就直接用;否则问一次 bridge(并发的请求共用一次)。出错不抛,当作连不上。 */
|
|
100
|
+
private cloudStatus;
|
|
101
|
+
private cloudView;
|
|
102
|
+
/** 没选过来源时的默认(D85):已登录用 cloud,否则浏览器朗读。云端暂时连不上时仍算已登录(音色用本机记下的)。 */
|
|
103
|
+
private fallbackOf;
|
|
104
|
+
/** 每段 cloud 合成成功:剩余字数以响应头为准(不在本地估算)。 */
|
|
105
|
+
private receipt;
|
|
106
|
+
/** 402:记下需要 / 剩余,剩余字数也以 402 里的为准。 */
|
|
107
|
+
private quotaHit;
|
|
70
108
|
private profiles;
|
|
71
109
|
private error;
|
|
72
110
|
/** /__joplo/voice/<rest>;不认识的路径返回 false。 */
|
|
73
111
|
handleGlobal(rest: string, req: http.IncomingMessage, ctx: Ctx): Promise<boolean>;
|
|
74
|
-
|
|
112
|
+
/** 项目的声音状态(看板浮层、播放时找音频)。refresh:重新问一次云端额度。 */
|
|
113
|
+
state(projectId: string, dir: string, project: Project | null, refresh?: boolean): Promise<VoiceState>;
|
|
114
|
+
private emitState;
|
|
115
|
+
/** 生成用的声音:与 state() 同一套默认来源。 */
|
|
116
|
+
private resolveFor;
|
|
117
|
+
/**
|
|
118
|
+
* cloud 现在能不能生成(P1-4):没登录 → AUTH_REQUIRED;云端连不上或旧云端没有朗读(404)→ TTS_UNAVAILABLE。
|
|
119
|
+
* 这时不请求云端(否则每一段都要经 CLI 重试好几秒),已有的音频照常按 cloud 指纹播放与打包。能生成时返回 null。
|
|
120
|
+
*/
|
|
121
|
+
private cloudBlocked;
|
|
122
|
+
/** cloud 请求的内容语言(D84):项目写了 locales 时是当前内容语言(没传时是默认语言);没写时不带,由云端按文字判断。 */
|
|
123
|
+
private speechLocaleOf;
|
|
75
124
|
/** /__joplo/p/:id/voice[/…];不认识的路径返回 false。 */
|
|
76
125
|
handleProject(projectId: string, dir: string, project: Project | null, rest: string, req: http.IncomingMessage, res: http.ServerResponse, ctx: Ctx): Promise<boolean>;
|
|
77
126
|
/** 关闭看板时停掉正在生成的任务。 */
|