@joplo-app/server 0.1.3 → 0.2.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/build.js +9 -9
- package/dist/contract.d.ts +2 -0
- package/dist/dev.js +28 -28
- package/dist/export.d.ts +2 -2
- package/dist/export.js +18 -17
- package/dist/locale.d.ts +4 -0
- package/dist/locale.js +5 -0
- package/dist/page-report.js +8 -8
- package/dist/project.js +1 -1
- package/dist/render.d.ts +1 -0
- package/dist/render.js +13 -11
- package/dist/selection.js +12 -12
- package/dist/vite-shared.js +1 -1
- package/dist/web-assets.js +7 -7
- package/package.json +4 -4
package/dist/build.js
CHANGED
|
@@ -78,18 +78,18 @@ function realish(p) {
|
|
|
78
78
|
export async function buildSite(opts) {
|
|
79
79
|
const projectDir = realProjectDir(opts.projectDir);
|
|
80
80
|
if (!fs.existsSync(projectDir))
|
|
81
|
-
throw new JoploError('NOT_FOUND',
|
|
81
|
+
throw new JoploError('NOT_FOUND', `Project directory does not exist: ${projectDir}`);
|
|
82
82
|
const outDir = realish(opts.outDir ?? path.join(projectDir, 'dist'));
|
|
83
83
|
// 目标目录安全检查(先于任何耗时工作)
|
|
84
84
|
if (outDir === projectDir || projectDir.startsWith(outDir + path.sep) || outDir === os.homedir() || outDir === path.parse(outDir).root)
|
|
85
|
-
throw new JoploError('USAGE',
|
|
85
|
+
throw new JoploError('USAGE', `Cannot write the published site to ${outDir}: it is the project directory or its parent`);
|
|
86
86
|
if (outDir === path.join(projectDir, '.joplo') || outDir.startsWith(path.join(projectDir, '.joplo') + path.sep))
|
|
87
|
-
throw new JoploError('USAGE',
|
|
87
|
+
throw new JoploError('USAGE', `Cannot write to .joplo/: ${outDir}`);
|
|
88
88
|
const nonEmpty = fs.existsSync(outDir) && (!fs.statSync(outDir).isDirectory() || fs.readdirSync(outDir).length > 0);
|
|
89
89
|
if (nonEmpty && !opts.overwrite)
|
|
90
|
-
throw new JoploError('USAGE',
|
|
90
|
+
throw new JoploError('USAGE', `Output directory is not empty: ${outDir}. After confirming it can be cleared, pass overwrite: true (CLI: --overwrite)`);
|
|
91
91
|
if (nonEmpty && fs.existsSync(path.join(outDir, 'joplo.config.ts')))
|
|
92
|
-
throw new JoploError('USAGE',
|
|
92
|
+
throw new JoploError('USAGE', `Output directory appears to be a Joplo project (contains joplo.config.ts); refusing to clear: ${outDir}`);
|
|
93
93
|
const web = locateWebAssets();
|
|
94
94
|
// 1. 编译(publish)
|
|
95
95
|
const loader = await createServer({
|
|
@@ -112,7 +112,7 @@ export async function buildSite(opts) {
|
|
|
112
112
|
}
|
|
113
113
|
if (!compiled.project) {
|
|
114
114
|
const errs = compiled.diagnostics.filter((d) => d.severity === 'error');
|
|
115
|
-
throw new JoploError('EXPORT_FAILED',
|
|
115
|
+
throw new JoploError('EXPORT_FAILED', `Project compilation failed; no published site was generated: \n${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('\n')}`, { diagnostics: compiled.diagnostics });
|
|
116
116
|
}
|
|
117
117
|
const project = compiled.project;
|
|
118
118
|
const inline = publishPayload(project, compiled.home);
|
|
@@ -132,7 +132,7 @@ export async function buildSite(opts) {
|
|
|
132
132
|
fs.rmSync(siteHtml);
|
|
133
133
|
for (const rel of inlined)
|
|
134
134
|
fs.rmSync(path.join(staging, rel));
|
|
135
|
-
fs.writeFileSync(path.join(staging, 'index.html'), html.replace(
|
|
135
|
+
fs.writeFileSync(path.join(staging, 'index.html'), html.replace(/<title>[^<]*<\/title>/i, () => `<title>${escapeHtml(project.name)} · Joplo</title>`));
|
|
136
136
|
// 4. 写入目标目录
|
|
137
137
|
if (fs.existsSync(outDir))
|
|
138
138
|
fs.rmSync(outDir, { recursive: true, force: true });
|
|
@@ -201,14 +201,14 @@ export async function stageDistSite(web, projectDir, staging) {
|
|
|
201
201
|
}));
|
|
202
202
|
const files = (Array.isArray(out) ? out : [out]).flatMap((o) => o.output.map((x) => x.fileName)).filter((f) => f.endsWith('.css'));
|
|
203
203
|
if (files.length !== 1)
|
|
204
|
-
throw new JoploError('EXPORT_FAILED',
|
|
204
|
+
throw new JoploError('EXPORT_FAILED', `Unexpected stylesheet compilation result for author className: ${files.join(', ') || 'No CSS'}`);
|
|
205
205
|
const rel = `assets/${path.basename(files[0])}`;
|
|
206
206
|
fs.mkdirSync(path.join(staging, 'assets'), { recursive: true });
|
|
207
207
|
fs.copyFileSync(path.join(cssOut, files[0]), path.join(staging, rel));
|
|
208
208
|
const siteHtml = path.join(staging, 'site.html');
|
|
209
209
|
const html = fs.readFileSync(siteHtml, 'utf8');
|
|
210
210
|
if (!html.includes('</head>'))
|
|
211
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
211
|
+
throw new JoploError('EXPORT_FAILED', 'Prebuilt site.html is missing </head>');
|
|
212
212
|
fs.writeFileSync(siteHtml, html.replace('</head>', ` <link rel="stylesheet" href="./${rel}">\n </head>`));
|
|
213
213
|
}
|
|
214
214
|
finally {
|
package/dist/contract.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export type RenderOptions = {
|
|
|
42
42
|
stepId?: string;
|
|
43
43
|
/** 主题名(D51):内置主题或项目 themes/<name>.css;缺省用项目配置的主题。 */
|
|
44
44
|
theme?: string;
|
|
45
|
+
/** UI language for the standalone render route. Unsupported values are ignored. */
|
|
46
|
+
locale?: string;
|
|
45
47
|
/** 字体(D55):hand / sans / serif / kai / mono;缺省跟随主题。 */
|
|
46
48
|
font?: AppearanceFont | null;
|
|
47
49
|
/** 线条(D55):rough / clean;缺省跟随主题。 */
|
package/dist/dev.js
CHANGED
|
@@ -56,7 +56,7 @@ function readBody(req) {
|
|
|
56
56
|
size += c.length;
|
|
57
57
|
if (size > MAX_BODY * 16) {
|
|
58
58
|
req.destroy();
|
|
59
|
-
reject(new Error('
|
|
59
|
+
reject(new Error('Request body is too large'));
|
|
60
60
|
}
|
|
61
61
|
else if (size <= MAX_BODY)
|
|
62
62
|
chunks.push(c);
|
|
@@ -196,7 +196,7 @@ export async function createHub(opts = {}) {
|
|
|
196
196
|
slot.payload = { version: prev.version + 1, ok: out.project !== null, project: out.project ?? prev.project, diagnostics: out.diagnostics, home: out.home ?? prev.home };
|
|
197
197
|
const errors = out.diagnostics.filter((d) => d.severity === 'error');
|
|
198
198
|
if (errors.length)
|
|
199
|
-
log(`[joplo] ${path.basename(slot.dir)}
|
|
199
|
+
log(`[joplo] ${path.basename(slot.dir)} compilation failed (${errors.length}): ${errors.map((d) => `${d.at ?? ''} ${d.message}`).join('; ').slice(0, 400)}`);
|
|
200
200
|
if (out.project && out.project.name)
|
|
201
201
|
registry.rename(slot.dir, out.project.name);
|
|
202
202
|
if (!closed)
|
|
@@ -219,7 +219,7 @@ export async function createHub(opts = {}) {
|
|
|
219
219
|
await recompile(slot);
|
|
220
220
|
}
|
|
221
221
|
catch (e) {
|
|
222
|
-
log(`[joplo]
|
|
222
|
+
log(`[joplo] Compilation exception: ${e instanceof Error ? e.message : String(e)}`);
|
|
223
223
|
}
|
|
224
224
|
} while (slot.dirty && !slot.closed);
|
|
225
225
|
})().finally(() => {
|
|
@@ -251,7 +251,7 @@ export async function createHub(opts = {}) {
|
|
|
251
251
|
if (watch && server)
|
|
252
252
|
server.watcher.add(dir);
|
|
253
253
|
await run(slot);
|
|
254
|
-
})().catch((e) => log(`[joplo]
|
|
254
|
+
})().catch((e) => log(`[joplo] Project startup failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
255
255
|
invalidateCss();
|
|
256
256
|
return slot;
|
|
257
257
|
}
|
|
@@ -282,9 +282,9 @@ export async function createHub(opts = {}) {
|
|
|
282
282
|
if (!slot) {
|
|
283
283
|
const rec = recordOf(id);
|
|
284
284
|
if (!rec)
|
|
285
|
-
throw new JoploError('NOT_FOUND',
|
|
285
|
+
throw new JoploError('NOT_FOUND', `Unknown project: ${id}`);
|
|
286
286
|
if (!fs.existsSync(rec.dir))
|
|
287
|
-
throw new JoploError('NOT_FOUND',
|
|
287
|
+
throw new JoploError('NOT_FOUND', `Project directory not found: ${rec.dir}`);
|
|
288
288
|
slot = activate(rec.dir);
|
|
289
289
|
}
|
|
290
290
|
await slot.ready;
|
|
@@ -293,7 +293,7 @@ export async function createHub(opts = {}) {
|
|
|
293
293
|
function addProject(dirIn, o = {}) {
|
|
294
294
|
const dir = realProjectDir(dirIn);
|
|
295
295
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory())
|
|
296
|
-
throw new JoploError('NOT_FOUND',
|
|
296
|
+
throw new JoploError('NOT_FOUND', `Project directory does not exist: ${dir}`);
|
|
297
297
|
const id = projectIdOf(dir);
|
|
298
298
|
const prev = registry.list().find((r) => r.dir === dir);
|
|
299
299
|
registry.touch(dir, prev?.name);
|
|
@@ -313,23 +313,23 @@ export async function createHub(opts = {}) {
|
|
|
313
313
|
const guardWrite = (req, res, tokenStatus = 403, needJson = true) => {
|
|
314
314
|
const origin = req.headers.origin;
|
|
315
315
|
if (origin !== undefined && !allowedOrigins().has(origin))
|
|
316
|
-
return deny(res, 403, `Origin
|
|
316
|
+
return deny(res, 403, `Origin is not allowed: ${origin}`), false;
|
|
317
317
|
const t = req.headers['x-joplo-token'];
|
|
318
318
|
if (typeof t !== 'string' || !safeEqual(t, token))
|
|
319
|
-
return deny(res, tokenStatus, '
|
|
319
|
+
return deny(res, tokenStatus, 'Missing or invalid local token (x-joplo-token)'), false;
|
|
320
320
|
if (needJson && !isJsonContentType(req.headers['content-type']))
|
|
321
|
-
return sendJson(res, 415, { error: { code: 'USAGE', message: 'Content-Type
|
|
321
|
+
return sendJson(res, 415, { error: { code: 'USAGE', message: 'Content-Type must be application/json' } }), false;
|
|
322
322
|
return true;
|
|
323
323
|
};
|
|
324
324
|
const jsonBody = async (req, res) => {
|
|
325
325
|
const raw = await readBody(req);
|
|
326
326
|
if (raw.tooLarge)
|
|
327
|
-
return sendJson(res, 413, { error: { code: 'USAGE', message:
|
|
327
|
+
return sendJson(res, 413, { error: { code: 'USAGE', message: `Request body is too large (limit: ${MAX_BODY} bytes)` } }), { ok: false };
|
|
328
328
|
try {
|
|
329
329
|
return { ok: true, body: JSON.parse(raw.text) };
|
|
330
330
|
}
|
|
331
331
|
catch (e) {
|
|
332
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message:
|
|
332
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: `Request body is not valid JSON: ${e instanceof Error ? e.message : String(e)}` } }), { ok: false };
|
|
333
333
|
}
|
|
334
334
|
};
|
|
335
335
|
const fail = (res, e) => {
|
|
@@ -355,18 +355,18 @@ export async function createHub(opts = {}) {
|
|
|
355
355
|
return;
|
|
356
356
|
const parsed = SelectionBody.safeParse(b.body);
|
|
357
357
|
if (!parsed.success)
|
|
358
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message: '
|
|
358
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'Invalid selection format', issues: parsed.error.issues.map((i) => ({ path: i.path.join('.'), message: i.message })) } });
|
|
359
359
|
const slot = await ensure(id);
|
|
360
360
|
if (parsed.data.selection === null) {
|
|
361
361
|
writeSelection(slot.dir, null);
|
|
362
362
|
return sendJson(res, 200, { ok: true, selection: null });
|
|
363
363
|
}
|
|
364
364
|
const project = slot.payload.project;
|
|
365
|
-
const r = project ? resolveSelection(project, parsed.data.selection) : { ok: false, problem: '
|
|
365
|
+
const r = project ? resolveSelection(project, parsed.data.selection) : { ok: false, problem: 'The project has not compiled successfully yet' };
|
|
366
366
|
if (!r.ok) {
|
|
367
367
|
// 不变量:被拒绝时文件写为 null(不能保留旧选中而界面显示新选中)
|
|
368
368
|
writeSelection(slot.dir, null);
|
|
369
|
-
return sendJson(res, 409, { error: { code: 'INVALID_REFERENCE', message:
|
|
369
|
+
return sendJson(res, 409, { error: { code: 'INVALID_REFERENCE', message: `Selection does not match the current project: ${r.problem}` }, current: null });
|
|
370
370
|
}
|
|
371
371
|
writeSelection(slot.dir, r.selection);
|
|
372
372
|
return sendJson(res, 200, { ok: true, selection: r.selection });
|
|
@@ -381,10 +381,10 @@ export async function createHub(opts = {}) {
|
|
|
381
381
|
const at = b.body?.at;
|
|
382
382
|
const m = typeof at === 'string' ? /^(.+?):(\d+)(?::(\d+))?$/.exec(at) : null;
|
|
383
383
|
if (!m)
|
|
384
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message: 'at
|
|
384
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'at must be file:line[:column]' } });
|
|
385
385
|
const file = path.resolve(slot.dir, m[1]);
|
|
386
386
|
if (!isProjectSource(slot.dir, file) || !fs.existsSync(file))
|
|
387
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message:
|
|
387
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: `Not a project source file: ${m[1]}` } });
|
|
388
388
|
// 交给 Vite 自带的 launch-editor(按 LAUNCH_EDITOR / EDITOR 或正在运行的编辑器打开)
|
|
389
389
|
req.__joploOpen = true;
|
|
390
390
|
req.url = `/__open-in-editor?file=${encodeURIComponent(`${file}:${m[2]}:${m[3] ?? 1}`)}`;
|
|
@@ -395,7 +395,7 @@ export async function createHub(opts = {}) {
|
|
|
395
395
|
const slot = await ensure(id);
|
|
396
396
|
return exportsHub.handle(rest.slice('export/'.length), req, res, { projectId: id, dir: slot.dir, project: slot.payload.project, guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), fail: (e) => fail(res, e) });
|
|
397
397
|
}
|
|
398
|
-
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
398
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown endpoint: ${method} /__joplo/p/${id}/${rest}` } });
|
|
399
399
|
}
|
|
400
400
|
const boardPlugin = {
|
|
401
401
|
name: 'joplo:board',
|
|
@@ -404,13 +404,13 @@ export async function createHub(opts = {}) {
|
|
|
404
404
|
try {
|
|
405
405
|
const host = req.headers.host ?? '';
|
|
406
406
|
if (!allowedHosts().has(host))
|
|
407
|
-
return deny(res, 403, `Host
|
|
407
|
+
return deny(res, 403, `Host header is not allowed: ${host || '(empty)'}`);
|
|
408
408
|
const url = new URL(req.url ?? '/', `http://127.0.0.1:${actualPort}`);
|
|
409
409
|
if (web.mode === 'dist' && (req.method === 'GET' || req.method === 'HEAD') && serveDistAsset(web, url.pathname, res))
|
|
410
410
|
return;
|
|
411
411
|
// Vite 的打开编辑器中间件只能经由 /__joplo/p/<id>/open(校验令牌与路径)进入
|
|
412
412
|
if (url.pathname === '/__open-in-editor')
|
|
413
|
-
return req.__joploOpen ? next() : deny(res, 403, '
|
|
413
|
+
return req.__joploOpen ? next() : deny(res, 403, 'Use Open in editor in the board');
|
|
414
414
|
if (!url.pathname.startsWith('/__joplo/'))
|
|
415
415
|
return next();
|
|
416
416
|
const method = req.method ?? 'GET';
|
|
@@ -439,7 +439,7 @@ export async function createHub(opts = {}) {
|
|
|
439
439
|
return;
|
|
440
440
|
const dir = b.body?.dir;
|
|
441
441
|
if (typeof dir !== 'string' || !path.isAbsolute(dir))
|
|
442
|
-
return sendJson(res, 400, { error: { code: 'USAGE', message: 'dir
|
|
442
|
+
return sendJson(res, 400, { error: { code: 'USAGE', message: 'dir must be an absolute path to the project directory' } });
|
|
443
443
|
const r = addProject(dir);
|
|
444
444
|
return sendJson(res, 200, { id: r.id, url: r.url });
|
|
445
445
|
}
|
|
@@ -450,7 +450,7 @@ export async function createHub(opts = {}) {
|
|
|
450
450
|
const id = decodeURIComponent(del[1]);
|
|
451
451
|
const rec = recordOf(id);
|
|
452
452
|
if (!rec)
|
|
453
|
-
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
453
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown project: ${id}` } });
|
|
454
454
|
const slot = slots.get(id);
|
|
455
455
|
if (slot)
|
|
456
456
|
await deactivate(slot);
|
|
@@ -465,7 +465,7 @@ export async function createHub(opts = {}) {
|
|
|
465
465
|
return next();
|
|
466
466
|
return;
|
|
467
467
|
}
|
|
468
|
-
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
468
|
+
return sendJson(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown endpoint: ${method} ${url.pathname}` } });
|
|
469
469
|
}
|
|
470
470
|
catch (e) {
|
|
471
471
|
if (!res.headersSent)
|
|
@@ -522,7 +522,7 @@ export async function createHub(opts = {}) {
|
|
|
522
522
|
await server.close().catch(() => undefined);
|
|
523
523
|
const err = e;
|
|
524
524
|
if (err.code === 'EADDRINUSE' || /already in use/i.test(err.message ?? ''))
|
|
525
|
-
throw new JoploError('USAGE',
|
|
525
|
+
throw new JoploError('USAGE', `Port ${port} is already in use; choose another port (--port), or stop the process using it`, { details: { code: 'EADDRINUSE' } });
|
|
526
526
|
throw e;
|
|
527
527
|
}
|
|
528
528
|
const addr = server.httpServer?.address();
|
|
@@ -602,8 +602,8 @@ export async function attachToRunning(home, projectDir, log) {
|
|
|
602
602
|
});
|
|
603
603
|
const body = (await res.json().catch(() => null));
|
|
604
604
|
if (!res.ok || !body?.url)
|
|
605
|
-
throw new JoploError('UNSUPPORTED_ACTION',
|
|
606
|
-
log(`[joplo]
|
|
605
|
+
throw new JoploError('UNSUPPORTED_ACTION', `Cannot add the project to the running board (${base}, pid ${info.pid}): ${body?.error?.message ?? `HTTP ${res.status}`}`);
|
|
606
|
+
log(`[joplo] Joined the running board (pid ${info.pid})`);
|
|
607
607
|
return { url: body.url, port: info.port };
|
|
608
608
|
}
|
|
609
609
|
function openBrowser(url, log) {
|
|
@@ -613,7 +613,7 @@ function openBrowser(url, log) {
|
|
|
613
613
|
spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();
|
|
614
614
|
}
|
|
615
615
|
catch {
|
|
616
|
-
log(`[joplo]
|
|
616
|
+
log(`[joplo] Cannot open the browser automatically; visit ${url}`);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
/**
|
|
@@ -625,7 +625,7 @@ export async function startDev(opts) {
|
|
|
625
625
|
const home = opts.home ?? joploHome();
|
|
626
626
|
const projectDir = realProjectDir(opts.projectDir);
|
|
627
627
|
if (!fs.existsSync(projectDir))
|
|
628
|
-
throw new JoploError('NOT_FOUND',
|
|
628
|
+
throw new JoploError('NOT_FOUND', `Project directory does not exist: ${projectDir}`);
|
|
629
629
|
const attach = async () => {
|
|
630
630
|
const a = await attachToRunning(home, projectDir, log);
|
|
631
631
|
if (!a)
|
package/dist/export.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ export type VideoJob = {
|
|
|
14
14
|
id: string;
|
|
15
15
|
projectId: string;
|
|
16
16
|
scenarioId: string;
|
|
17
|
-
status: 'running' | 'done' | 'error';
|
|
17
|
+
status: 'running' | 'done' | 'error' | 'cancelled';
|
|
18
18
|
/** starting 启动浏览器 → recording 录制中 → saving 写文件。 */
|
|
19
|
-
phase: 'starting' | 'recording' | 'saving' | 'done' | 'error';
|
|
19
|
+
phase: 'starting' | 'recording' | 'saving' | 'done' | 'error' | 'cancelled';
|
|
20
20
|
step: number;
|
|
21
21
|
total: number;
|
|
22
22
|
/** 0–100。 */
|
package/dist/export.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import crypto from 'node:crypto';
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
import path from 'node:path';
|
|
19
|
+
import { exportLocale } from "./locale.js";
|
|
19
20
|
import { JoploError, SUBTITLE_HEIGHT, THEME_NAME, displaySceneId, isAppearanceFont, isAppearanceStroke } from '@joplo-app/core';
|
|
20
21
|
import { launch, loadPlaywright } from "./render.js";
|
|
21
22
|
/**
|
|
@@ -39,20 +40,20 @@ export function exportAppearance(body) {
|
|
|
39
40
|
const appearanceParams = (a) => ({ ...(a.font ? { font: a.font } : {}), ...(a.stroke ? { stroke: a.stroke } : {}) });
|
|
40
41
|
function parseRequest(project, body, needPosition) {
|
|
41
42
|
if (!project)
|
|
42
|
-
throw new JoploError('INVALID_SCHEMA', '
|
|
43
|
+
throw new JoploError('INVALID_SCHEMA', 'Cannot export before the project compiles successfully');
|
|
43
44
|
const b = (body ?? {});
|
|
44
45
|
if (typeof b.scenarioId !== 'string' || !project.scenarios[b.scenarioId])
|
|
45
|
-
throw new JoploError('USAGE',
|
|
46
|
+
throw new JoploError('USAGE', `Scenario does not exist: ${String(b.scenarioId)}`);
|
|
46
47
|
const sc = project.scenarios[b.scenarioId];
|
|
47
48
|
const position = needPosition ? Number(b.position ?? 0) : 0;
|
|
48
49
|
if (!Number.isInteger(position) || position < 0 || position > sc.steps.length)
|
|
49
|
-
throw new JoploError('USAGE',
|
|
50
|
+
throw new JoploError('USAGE', `Position must be an integer from 0 to ${sc.steps.length}`);
|
|
50
51
|
// 设备跟随页面自己的 viewport(D44)
|
|
51
52
|
const sceneId = displaySceneId(project, sc.id, position);
|
|
52
53
|
const device = project.scenes[sceneId]?.viewport === 'mobile' ? 'mobile' : 'desktop';
|
|
53
54
|
// 主题(D51):请求里的主题名,没有或不合法时用项目配置的主题
|
|
54
55
|
const theme = typeof b.theme === 'string' && THEME_NAME.test(b.theme) ? b.theme : project.theme;
|
|
55
|
-
return { sc, position, device, look: { theme, ...exportAppearance(body) } };
|
|
56
|
+
return { sc, position, device, look: { theme, ...exportAppearance(body), locale: exportLocale(b.locale) } };
|
|
56
57
|
}
|
|
57
58
|
const fileSafe = (s) => s.replace(/[^\w.-]+/g, '_').slice(0, 80) || 'scenario';
|
|
58
59
|
const stamp = (d = new Date()) => `${d.getFullYear()}${String(d.getMonth() + 1).padStart(2, '0')}${String(d.getDate()).padStart(2, '0')}-${String(d.getHours()).padStart(2, '0')}${String(d.getMinutes()).padStart(2, '0')}${String(d.getSeconds()).padStart(2, '0')}`;
|
|
@@ -60,7 +61,7 @@ async function waitReady(page) {
|
|
|
60
61
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
61
62
|
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
62
63
|
if (err)
|
|
63
|
-
throw new JoploError('RENDER_FAILED',
|
|
64
|
+
throw new JoploError('RENDER_FAILED', `Render route reported an error: ${err}`);
|
|
64
65
|
}
|
|
65
66
|
/** 缺省的录制:Playwright recordVideo + 渲染路由的录制模式(window.__JOPLO_RECORD__)。 */
|
|
66
67
|
export function defaultRecorder(load) {
|
|
@@ -78,22 +79,22 @@ export function defaultRecorder(load) {
|
|
|
78
79
|
const t0 = Date.now();
|
|
79
80
|
for (;;) {
|
|
80
81
|
if (signal.aborted)
|
|
81
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
82
|
+
throw new JoploError('EXPORT_FAILED', 'Export cancelled');
|
|
82
83
|
const p = await page.evaluate(() => window.__JOPLO_RECORD__.progress);
|
|
83
84
|
if (p.error)
|
|
84
|
-
throw new JoploError('EXPORT_FAILED',
|
|
85
|
+
throw new JoploError('EXPORT_FAILED', `Playback failed: ${p.error}`);
|
|
85
86
|
progress(p.step);
|
|
86
87
|
if (p.done)
|
|
87
88
|
break;
|
|
88
89
|
if (Date.now() - t0 > 5 * 60_000)
|
|
89
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
90
|
+
throw new JoploError('EXPORT_FAILED', 'Recording exceeded 5 minutes and was stopped');
|
|
90
91
|
await page.waitForTimeout(150);
|
|
91
92
|
}
|
|
92
93
|
await page.waitForTimeout(900); // 停留在结果画面
|
|
93
94
|
const video = page.video();
|
|
94
95
|
await ctx.close();
|
|
95
96
|
if (!video)
|
|
96
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
97
|
+
throw new JoploError('EXPORT_FAILED', 'The browser did not generate a video');
|
|
97
98
|
await video.saveAs(out);
|
|
98
99
|
}
|
|
99
100
|
finally {
|
|
@@ -122,7 +123,7 @@ export class ExportHub {
|
|
|
122
123
|
const job = this.jobs.get(projectId);
|
|
123
124
|
if (!job || job.status !== 'running')
|
|
124
125
|
return null;
|
|
125
|
-
this.update(job, { status: '
|
|
126
|
+
this.update(job, { status: 'cancelled', phase: 'cancelled', error: 'Cancelled' });
|
|
126
127
|
this.aborts.get(projectId)?.abort();
|
|
127
128
|
this.aborts.delete(projectId);
|
|
128
129
|
return { ...job };
|
|
@@ -161,7 +162,7 @@ export class ExportHub {
|
|
|
161
162
|
const { sc, device, look } = parseRequest(ctx.project, b.body, false);
|
|
162
163
|
const cur = this.jobs.get(ctx.projectId);
|
|
163
164
|
if (cur?.status === 'running')
|
|
164
|
-
return send(res, 409, { error: { code: 'UNSUPPORTED_ACTION', message: '
|
|
165
|
+
return send(res, 409, { error: { code: 'UNSUPPORTED_ACTION', message: 'This project already has a video export in progress; wait for it to finish' }, job: cur });
|
|
165
166
|
const job = this.startVideo(ctx.projectId, ctx.dir, sc.id, sc.steps.length, device, look);
|
|
166
167
|
return send(res, 202, { jobId: job.id, job });
|
|
167
168
|
}
|
|
@@ -171,14 +172,14 @@ export class ExportHub {
|
|
|
171
172
|
if (!ctx.guardWrite(false))
|
|
172
173
|
return;
|
|
173
174
|
const job = this.cancel(ctx.projectId);
|
|
174
|
-
return job ? send(res, 200, { job }) : send(res, 404, { error: { code: 'NOT_FOUND', message: '
|
|
175
|
+
return job ? send(res, 200, { job }) : send(res, 404, { error: { code: 'NOT_FOUND', message: 'This project has no video export in progress' } });
|
|
175
176
|
}
|
|
176
177
|
if (sub === 'video/events' && method === 'GET') {
|
|
177
178
|
if (!ctx.guardWrite(false))
|
|
178
179
|
return;
|
|
179
180
|
return this.sse(ctx.projectId, res);
|
|
180
181
|
}
|
|
181
|
-
return send(res, 404, { error: { code: 'NOT_FOUND', message:
|
|
182
|
+
return send(res, 404, { error: { code: 'NOT_FOUND', message: `Unknown endpoint: ${method} export/${sub}` } });
|
|
182
183
|
}
|
|
183
184
|
catch (e) {
|
|
184
185
|
if (!res.headersSent)
|
|
@@ -192,7 +193,7 @@ export class ExportHub {
|
|
|
192
193
|
const browser = await launch(pw);
|
|
193
194
|
try {
|
|
194
195
|
const page = await browser.newPage({ viewport: EXPORT_SIZE[device], deviceScaleFactor: 2, reducedMotion: 'reduce' });
|
|
195
|
-
await page.goto(this.renderUrl(projectId, { scenario: scenarioId, position: String(position), theme: look.theme, ...appearanceParams(look), frame: '1' }), { waitUntil: 'domcontentloaded' });
|
|
196
|
+
await page.goto(this.renderUrl(projectId, { scenario: scenarioId, position: String(position), theme: look.theme, ...appearanceParams(look), ...(look.locale ? { locale: look.locale } : {}), frame: '1' }), { waitUntil: 'domcontentloaded' });
|
|
196
197
|
await waitReady(page);
|
|
197
198
|
return await page.locator('[data-jexport]').screenshot({ type: 'png', animations: 'disabled' });
|
|
198
199
|
}
|
|
@@ -212,7 +213,7 @@ export class ExportHub {
|
|
|
212
213
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
213
214
|
this.update(job, { phase: 'starting', percent: 2 });
|
|
214
215
|
await this.deps.recordVideo({
|
|
215
|
-
url: this.renderUrl(projectId, { scenario: scenarioId, position: '0', theme: look.theme, ...appearanceParams(look), frame: '1', record: '1' }),
|
|
216
|
+
url: this.renderUrl(projectId, { scenario: scenarioId, position: '0', theme: look.theme, ...appearanceParams(look), ...(look.locale ? { locale: look.locale } : {}), frame: '1', record: '1' }),
|
|
216
217
|
size: EXPORT_SIZE[device],
|
|
217
218
|
out,
|
|
218
219
|
total,
|
|
@@ -230,9 +231,9 @@ export class ExportHub {
|
|
|
230
231
|
return; // 已取消:录制器之后才返回,不改回完成
|
|
231
232
|
this.update(job, { phase: 'saving', percent: 95 });
|
|
232
233
|
if (!fs.existsSync(out))
|
|
233
|
-
throw new JoploError('EXPORT_FAILED', '
|
|
234
|
+
throw new JoploError('EXPORT_FAILED', 'Recording completed, but no video file was generated');
|
|
234
235
|
this.update(job, { status: 'done', phase: 'done', percent: 100, step: total, file: rel });
|
|
235
|
-
this.opts.log(`[joplo]
|
|
236
|
+
this.opts.log(`[joplo] Exported video: ${out}`);
|
|
236
237
|
}
|
|
237
238
|
catch (e) {
|
|
238
239
|
if (job.status === 'running')
|
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Export URLs accept exact supported locale tags; invalid or absent values are omitted. */
|
|
2
|
+
export declare const exportLocales: readonly ["en", "zh-CN", "zh-TW", "ja", "ko", "es", "fr", "de", "pt-BR", "ru"];
|
|
3
|
+
export type ExportLocale = typeof exportLocales[number];
|
|
4
|
+
export declare function exportLocale(value: unknown): ExportLocale | undefined;
|
package/dist/locale.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Export URLs accept exact supported locale tags; invalid or absent values are omitted. */
|
|
2
|
+
export const exportLocales = ['en', 'zh-CN', 'zh-TW', 'ja', 'ko', 'es', 'fr', 'de', 'pt-BR', 'ru'];
|
|
3
|
+
export function exportLocale(value) {
|
|
4
|
+
return typeof value === 'string' && exportLocales.includes(value) ? value : undefined;
|
|
5
|
+
}
|
package/dist/page-report.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const els = Array.from(stage.querySelectorAll('[data-jid]:not([data-jtype="#text"])'));
|
|
9
9
|
const name = (el) => {
|
|
10
10
|
const owner = el.closest('[data-jid]:not([data-jtype="#text"])');
|
|
11
|
-
return owner ?
|
|
11
|
+
return owner ? `"${owner.dataset.jlabel ?? ''}"(${owner.dataset.jid})` : el.closest('[data-jtoast]') ? 'Toast' : el.closest('[data-jbackdrop]') ? 'Modal backdrop' : el.tagName.toLowerCase();
|
|
12
12
|
};
|
|
13
13
|
const elements = els.map((el) => {
|
|
14
14
|
const r = el.getBoundingClientRect();
|
|
@@ -33,7 +33,7 @@
|
|
|
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
|
-
warnings.push(
|
|
36
|
+
warnings.push(`Outside frame: "${e.label}"(${e.id}) has its center outside the frame`);
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
// 视口小于舞台时,视口外的点 elementFromPoint 返回 null——那不是遮挡,单独汇总
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
if (hit && (hit === el || el.contains(hit))) return;
|
|
46
46
|
// 弹窗打开时,背景被遮罩或弹窗面板覆盖是预期的层次,不算遮挡(窄屏下面板常盖住背景按钮)
|
|
47
47
|
if ((hit?.closest('[data-jbackdrop]') || (dialogOpen && hit?.closest('[role="dialog"]'))) && !el.closest('[role="dialog"]')) return;
|
|
48
|
-
warnings.push(
|
|
48
|
+
warnings.push(`Occluded: "${e.label}"(${e.id}) has its center covered by ${hit ? name(hit) : 'content outside the frame'}`);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
if (offViewport.length)
|
|
52
|
-
warnings.push(
|
|
52
|
+
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
53
|
|
|
54
54
|
// 2. 标签文字溢出
|
|
55
55
|
stage.querySelectorAll('[data-jtext], .jtrunc').forEach((t) => {
|
|
56
|
-
if (t.scrollWidth > t.clientWidth + 1) warnings.push(
|
|
56
|
+
if (t.scrollWidth > t.clientWidth + 1) warnings.push(`Label text overflow: ${name(t)} text "${(t.textContent ?? '').slice(0, 40)}" is clipped`);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
// 3. Toast 等浮层(pointer-events:none,elementFromPoint 看不到)与可交互元素按几何相交检测
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
if (dialogOpen && !el.closest('[role="dialog"]')) return; // 被弹窗遮罩盖住的背景本来就不可操作
|
|
66
66
|
const r = el.getBoundingClientRect();
|
|
67
67
|
if (!toasts.some((b) => overlap(b, r))) return;
|
|
68
|
-
warnings.push(e.id === args.nextTargetId ? `Toast
|
|
68
|
+
warnings.push(e.id === args.nextTargetId ? `Toast obscures the next action target: ${name(el)}` : `Toast covers an interactive element: ${name(el)}`);
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
// 主题用到手写字体时(--jp-font 含 Excalifont)检查它们已加载
|
|
74
74
|
if (/Excalifont|Xiaolai/.test(getComputedStyle(stage).fontFamily)) {
|
|
75
75
|
const text = stage.innerText || '中文';
|
|
76
|
-
if (!document.fonts.check('16px "Joplo Excalifont"', text) || !document.fonts.check('16px "Joplo Xiaolai"', text)) warnings.push('
|
|
76
|
+
if (!document.fonts.check('16px "Joplo Excalifont"', text) || !document.fonts.check('16px "Joplo Xiaolai"', text)) warnings.push('Fonts not loaded: Hand-drawn fonts (Excalifont / Xiaolai) are not ready; the screenshot may use fallback fonts');
|
|
77
77
|
}
|
|
78
78
|
const failed = Array.from(document.fonts).filter((f) => f.status === 'error');
|
|
79
|
-
if (failed.length) warnings.push(
|
|
79
|
+
if (failed.length) warnings.push(`Fonts not loaded: ${failed.length} font files failed to load (${failed[0].family})`);
|
|
80
80
|
|
|
81
81
|
return { elements, warnings };
|
|
82
82
|
}
|
package/dist/project.js
CHANGED
|
@@ -50,7 +50,7 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
50
50
|
...d,
|
|
51
51
|
at: precise,
|
|
52
52
|
// 位置已在 at 里,说明只保留第一行的原因
|
|
53
|
-
message: d.message.replace(/\x1b\[[0-9;]*m/g, '').split('\n')[0].replace(
|
|
53
|
+
message: d.message.replace(/\x1b\[[0-9;]*m/g, '').split('\n')[0].replace(`Load failed: ${precise} `, 'Load failed: '),
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
const key = `${out.code}|${out.at}|${out.message}`;
|
package/dist/render.d.ts
CHANGED
package/dist/render.js
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { JoploError, SUBTITLE_HEIGHT, VIEWPORT_SIZE, isAppearanceFont, isAppearanceStroke, displaySceneId, findNode, isNodeDisabled, nodeLabel, positionAfterStep, resolveProps, stateAt, walkNodes } from '@joplo-app/core';
|
|
11
|
+
import { exportLocale } from "./locale.js";
|
|
11
12
|
import { createDev } from "./dev.js";
|
|
12
13
|
import { realProjectDir } from "./vite-shared.js";
|
|
13
14
|
const STAGE_SIZE = VIEWPORT_SIZE;
|
|
14
|
-
const NOT_NEEDED = 'dev
|
|
15
|
+
const NOT_NEEDED = 'dev, check, and build do not require it.';
|
|
15
16
|
const isMissingModule = (e) => {
|
|
16
17
|
const code = e?.code;
|
|
17
18
|
return (code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND') && /playwright/.test(e instanceof Error ? e.message : String(e));
|
|
@@ -24,13 +25,13 @@ export async function loadPlaywright(importer = () => import('playwright')) {
|
|
|
24
25
|
catch (e) {
|
|
25
26
|
if (!isMissingModule(e))
|
|
26
27
|
throw e;
|
|
27
|
-
throw new JoploError('RENDER_FAILED',
|
|
28
|
+
throw new JoploError('RENDER_FAILED', `Screenshots require Playwright and Chromium, which are not installed. Run: npm i -D playwright && npx playwright install chromium (about 150 MB). ${NOT_NEEDED}`);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
/** 浏览器启动失败时的一行提示。 */
|
|
31
32
|
export function launchHint(e) {
|
|
32
33
|
const first = (e instanceof Error ? e.message : String(e)).split('\n')[0].trim();
|
|
33
|
-
return
|
|
34
|
+
return `Screenshots require Chromium; browser launch failed (${first}). Run: npx playwright install chromium (about 150 MB). ${NOT_NEEDED}`;
|
|
34
35
|
}
|
|
35
36
|
export async function launch({ chromium }) {
|
|
36
37
|
try {
|
|
@@ -70,9 +71,9 @@ function assertNotProjectData(projectDir, out) {
|
|
|
70
71
|
const dir = fold(realish(projectDir));
|
|
71
72
|
const dataDir = path.join(dir, '.joplo');
|
|
72
73
|
if (o === dataDir || o.startsWith(dataDir + path.sep))
|
|
73
|
-
throw new JoploError('USAGE',
|
|
74
|
+
throw new JoploError('USAGE', `Cannot write to project data: ${out} (.joplo/ is managed by Joplo)`);
|
|
74
75
|
if (/\.(tsx?|jsx?|mts)$/.test(o) && o.startsWith(dir + path.sep))
|
|
75
|
-
throw new JoploError('USAGE',
|
|
76
|
+
throw new JoploError('USAGE', `Cannot overwrite a project source file with a screenshot: ${out}`);
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
78
79
|
* 渲染路由的参数(纯函数):主题必填(调用方缺省时传项目主题);字体与线条(D55)只在指定且合法时带上,
|
|
@@ -85,6 +86,7 @@ export function renderQuery(q) {
|
|
|
85
86
|
scenario: q.scenarioId,
|
|
86
87
|
position: String(q.position),
|
|
87
88
|
theme: q.theme,
|
|
89
|
+
...(exportLocale(q.locale) ? { locale: exportLocale(q.locale) } : {}),
|
|
88
90
|
...(isAppearanceFont(q.font) ? { font: q.font } : {}),
|
|
89
91
|
...(isAppearanceStroke(q.stroke) ? { stroke: q.stroke } : {}),
|
|
90
92
|
...(q.viewport ? { w: String(q.viewport.width), h: String(q.viewport.height) } : {}),
|
|
@@ -95,7 +97,7 @@ export async function renderStep(opts) {
|
|
|
95
97
|
const out = path.resolve(opts.out);
|
|
96
98
|
assertNotProjectData(projectDir, out);
|
|
97
99
|
if (fs.existsSync(out) && !opts.overwrite)
|
|
98
|
-
throw new JoploError('USAGE',
|
|
100
|
+
throw new JoploError('USAGE', `Output file already exists: ${out}. To overwrite, pass overwrite: true (CLI: --overwrite)`);
|
|
99
101
|
// 先确认 Playwright 可用,再启动编译服务(缺失时尽快失败)
|
|
100
102
|
const playwright = await loadPlaywright();
|
|
101
103
|
const server = await createDev({ projectDir, port: 0, watch: false, log: () => undefined });
|
|
@@ -105,11 +107,11 @@ export async function renderStep(opts) {
|
|
|
105
107
|
const project = payload.project;
|
|
106
108
|
if (!project) {
|
|
107
109
|
const errs = payload.diagnostics.filter((d) => d.severity === 'error');
|
|
108
|
-
throw new JoploError('INVALID_SCHEMA',
|
|
110
|
+
throw new JoploError('INVALID_SCHEMA', `Project compilation failed: ${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('; ')}`, { diagnostics: payload.diagnostics });
|
|
109
111
|
}
|
|
110
112
|
const sc = project.scenarios[opts.scenarioId];
|
|
111
113
|
if (!sc)
|
|
112
|
-
throw new JoploError('NOT_FOUND',
|
|
114
|
+
throw new JoploError('NOT_FOUND', `Scenario does not exist: ${opts.scenarioId} (available: ${Object.keys(project.scenarios).join(', ') || 'none'})`);
|
|
113
115
|
const position = opts.stepId ? positionAfterStep(project, sc.id, opts.stepId) : 0;
|
|
114
116
|
const state = stateAt(project, sc.id, position); // 回放失败会抛出 PLAYBACK_FAILED
|
|
115
117
|
// 有层级的方案:截图与元素索引用这一步导演层的画面(每层一个独立画面)
|
|
@@ -123,12 +125,12 @@ export async function renderStep(opts) {
|
|
|
123
125
|
browser = await launch(playwright);
|
|
124
126
|
const page = await browser.newPage({ viewport, deviceScaleFactor: opts.scale ?? 1, reducedMotion: 'reduce' });
|
|
125
127
|
// D44:舞台宽度固定为页面自己的 viewport;指定 viewport 时它只是截图尺寸(舞台按比例放进去)
|
|
126
|
-
const q = renderQuery({ projectId: server.projectId, scenarioId: sc.id, position, theme, font: opts.font, stroke: opts.stroke, ...(opts.viewport ? { viewport: opts.viewport } : {}) });
|
|
128
|
+
const q = renderQuery({ projectId: server.projectId, scenarioId: sc.id, position, theme, locale: opts.locale, font: opts.font, stroke: opts.stroke, ...(opts.viewport ? { viewport: opts.viewport } : {}) });
|
|
127
129
|
await page.goto(`${server.url}?${q}`, { waitUntil: 'domcontentloaded' });
|
|
128
130
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
|
129
131
|
const err = await page.evaluate(() => window.__JOPLO_ERROR__ ?? null);
|
|
130
132
|
if (err)
|
|
131
|
-
throw new JoploError('RENDER_FAILED',
|
|
133
|
+
throw new JoploError('RENDER_FAILED', `Render route reported an error: ${err}`);
|
|
132
134
|
const report = (await page.evaluate(`(${COLLECT_REPORT})(${JSON.stringify({ nextTargetId, theme })})`));
|
|
133
135
|
const png = await page.locator(opts.viewport ? '[data-jshot]' : '[data-jrender]').screenshot({ type: 'png', animations: 'disabled' });
|
|
134
136
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
@@ -155,7 +157,7 @@ export async function renderStep(opts) {
|
|
|
155
157
|
const elements = [...report.elements, ...hidden];
|
|
156
158
|
const warnings = [...report.warnings];
|
|
157
159
|
if (nextTargetId && findNode(scene, nextTargetId) && !elements.find((e) => e.id === nextTargetId && e.visible))
|
|
158
|
-
warnings.push(
|
|
160
|
+
warnings.push(`Next action target ${nextTargetId} is not visible in the stage`);
|
|
159
161
|
return { path: out, sceneId: scene.id, position, elements, warnings, scale: opts.scale ?? 1 };
|
|
160
162
|
}
|
|
161
163
|
finally {
|
package/dist/selection.js
CHANGED
|
@@ -32,49 +32,49 @@ export function resolveSelection(project, input, now = new Date()) {
|
|
|
32
32
|
if (optionId !== null) {
|
|
33
33
|
const opt = project.options[optionId];
|
|
34
34
|
if (!opt)
|
|
35
|
-
return { ok: false, problem:
|
|
35
|
+
return { ok: false, problem: `Option ${optionId} does not exist` };
|
|
36
36
|
featureId = opt.featureId;
|
|
37
37
|
}
|
|
38
38
|
if (input.scenarioId !== null) {
|
|
39
39
|
const sc = project.scenarios[input.scenarioId];
|
|
40
40
|
if (!sc)
|
|
41
|
-
return { ok: false, problem:
|
|
41
|
+
return { ok: false, problem: `Scenario ${input.scenarioId} does not exist` };
|
|
42
42
|
if (optionId !== sc.optionId)
|
|
43
|
-
return { ok: false, problem:
|
|
43
|
+
return { ok: false, problem: `Scenario ${sc.id} does not belong to option ${optionId ?? '(none)'}` };
|
|
44
44
|
if (input.position > sc.steps.length)
|
|
45
|
-
return { ok: false, problem:
|
|
45
|
+
return { ok: false, problem: `Position ${input.position} is outside scenario ${sc.id} range 0..${sc.steps.length}` };
|
|
46
46
|
try {
|
|
47
47
|
sceneId = stateAt(project, sc.id, input.position).sceneId;
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
return { ok: false, problem:
|
|
50
|
+
return { ok: false, problem: `Scenario ${sc.id} cannot replay to position ${input.position}: ${e instanceof Error ? e.message : String(e)}` };
|
|
51
51
|
}
|
|
52
52
|
// 有层级的方案:用户看的是某一层的画面(各层共享同一份状态),也接受
|
|
53
53
|
const layerScenes = Object.values(project.options[sc.optionId]?.layers ?? {}).map((l) => l.sceneId);
|
|
54
54
|
if (layerScenes.includes(input.sceneId))
|
|
55
55
|
sceneId = input.sceneId;
|
|
56
56
|
if (input.sceneId !== sceneId)
|
|
57
|
-
return { ok: false, problem:
|
|
57
|
+
return { ok: false, problem: `Position ${input.position} has stage ${sceneId}, not ${input.sceneId}` };
|
|
58
58
|
stepId = sc.steps[input.position - 1]?.id ?? null;
|
|
59
59
|
if (input.stepId) {
|
|
60
60
|
if (!sc.steps.some((s) => s.id === input.stepId))
|
|
61
|
-
return { ok: false, problem:
|
|
61
|
+
return { ok: false, problem: `Step ${input.stepId} is not in scenario ${sc.id}` };
|
|
62
62
|
stepId = input.stepId;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
else if (input.position !== 0 || input.stepId)
|
|
66
|
-
return { ok: false, problem: '
|
|
66
|
+
return { ok: false, problem: 'Without a scenario, position must be 0 and no step may be selected' };
|
|
67
67
|
const scene = project.scenes[sceneId];
|
|
68
68
|
if (!scene)
|
|
69
|
-
return { ok: false, problem:
|
|
69
|
+
return { ok: false, problem: `Stage ${sceneId} does not exist` };
|
|
70
70
|
if (input.scenarioId === null && optionId !== null && scene.optionId !== optionId && scene.optionId !== null)
|
|
71
|
-
return { ok: false, problem:
|
|
71
|
+
return { ok: false, problem: `Stage ${sceneId} does not belong to option ${optionId}` };
|
|
72
72
|
let at = null;
|
|
73
73
|
let label = null;
|
|
74
74
|
if (input.nodeId) {
|
|
75
75
|
const hit = findNode(scene, input.nodeId);
|
|
76
76
|
if (!hit)
|
|
77
|
-
return { ok: false, problem:
|
|
77
|
+
return { ok: false, problem: `Element ${input.nodeId} is not in stage ${sceneId}` };
|
|
78
78
|
at = hit.node.source ?? null;
|
|
79
79
|
label = nodeLabel(hit.node); // Mantine 输入组件直接带 label 属性
|
|
80
80
|
}
|
|
@@ -84,7 +84,7 @@ export function resolveSelection(project, input, now = new Date()) {
|
|
|
84
84
|
label = st.caption;
|
|
85
85
|
}
|
|
86
86
|
else
|
|
87
|
-
return { ok: false, problem: '
|
|
87
|
+
return { ok: false, problem: 'Selection must point to an element or a step' };
|
|
88
88
|
return {
|
|
89
89
|
ok: true,
|
|
90
90
|
selection: {
|
package/dist/vite-shared.js
CHANGED
|
@@ -93,7 +93,7 @@ export function joploProjectPlugin(projectDir, web = locateWebAssets()) {
|
|
|
93
93
|
const loc = parseErrorLoc(first, file) ?? { line: 1, column: 1 };
|
|
94
94
|
const rel = path.relative(projectDir, file).split(path.sep).join('/');
|
|
95
95
|
const brief = (first.split('\n')[0] ?? '').replace(/^\s*\[[A-Z_]+\]\s*/, '').trim();
|
|
96
|
-
throw new ProjectSyntaxError(`${rel}:${loc.line}:${loc.column}
|
|
96
|
+
throw new ProjectSyntaxError(`${rel}:${loc.line}:${loc.column} syntax error: ${brief || 'Cannot parse'}`, { file, ...loc });
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
};
|
package/dist/web-assets.js
CHANGED
|
@@ -17,7 +17,7 @@ const require = createRequire(import.meta.url);
|
|
|
17
17
|
const FROM_SOURCE = import.meta.filename.endsWith('.ts');
|
|
18
18
|
const REPO_WEB = path.resolve(import.meta.dirname, '../../web');
|
|
19
19
|
const REPO_KIT = path.resolve(import.meta.dirname, '../../kit/src');
|
|
20
|
-
const broken = (webDir, what) => new JoploError('NOT_FOUND', `@joplo-app/web
|
|
20
|
+
const broken = (webDir, what) => new JoploError('NOT_FOUND', `@joplo-app/web (${webDir}) is missing prebuilt assets: ${what}. Reinstall joplo (npm install), or run pnpm --filter @joplo-app/web build in the Joplo repository`);
|
|
21
21
|
/** 读取并校验 @joplo-app/web 的 dist/manifest.json。 */
|
|
22
22
|
export function readWebDist(webDir) {
|
|
23
23
|
const dist = path.join(webDir, 'dist');
|
|
@@ -30,13 +30,13 @@ export function readWebDist(webDir) {
|
|
|
30
30
|
throw broken(webDir, 'dist/manifest.json');
|
|
31
31
|
}
|
|
32
32
|
if (manifest.format !== 1)
|
|
33
|
-
throw broken(webDir,
|
|
33
|
+
throw broken(webDir, `Unknown manifest format ${String(manifest.format)}`);
|
|
34
34
|
const inside = (rel, label) => {
|
|
35
35
|
if (typeof rel !== 'string' || !rel)
|
|
36
36
|
throw broken(webDir, label);
|
|
37
37
|
const abs = path.resolve(dist, rel);
|
|
38
38
|
if (abs !== dist && !abs.startsWith(dist + path.sep))
|
|
39
|
-
throw broken(webDir, `${label}
|
|
39
|
+
throw broken(webDir, `${label} escapes dist/`);
|
|
40
40
|
if (!fs.existsSync(abs))
|
|
41
41
|
throw broken(webDir, `dist/${rel}`);
|
|
42
42
|
return abs;
|
|
@@ -52,10 +52,10 @@ export function readWebDist(webDir) {
|
|
|
52
52
|
catch (e) {
|
|
53
53
|
if (e instanceof JoploError)
|
|
54
54
|
throw e;
|
|
55
|
-
throw broken(webDir, 'site-files.json
|
|
55
|
+
throw broken(webDir, 'site-files.json is not valid JSON');
|
|
56
56
|
}
|
|
57
57
|
if (!Array.isArray(siteFiles) || !siteFiles.every((f) => typeof f === 'string' && f && !path.isAbsolute(f) && !f.split(/[\\/]/).includes('..')))
|
|
58
|
-
throw broken(webDir, 'site-files.json
|
|
58
|
+
throw broken(webDir, 'site-files.json must be a list of relative paths within appDir');
|
|
59
59
|
return { mode: 'dist', webDir, appDir, siteFiles, projectCss, version: typeof manifest.version === 'string' ? manifest.version : '' };
|
|
60
60
|
}
|
|
61
61
|
let cached = null;
|
|
@@ -73,7 +73,7 @@ export function locateWebAssets(env) {
|
|
|
73
73
|
pkg = require.resolve('@joplo-app/web/package.json');
|
|
74
74
|
}
|
|
75
75
|
catch {
|
|
76
|
-
throw new JoploError('NOT_FOUND', '
|
|
76
|
+
throw new JoploError('NOT_FOUND', 'Cannot find @joplo-app/web (board and published site assets). Reinstall joplo (npm install)');
|
|
77
77
|
}
|
|
78
78
|
out = readWebDist(path.dirname(fs.realpathSync(pkg)));
|
|
79
79
|
}
|
|
@@ -118,7 +118,7 @@ export function kitAliases(web, projectDir) {
|
|
|
118
118
|
const main = fileURLToPath(import.meta.resolve('@joplo-app/kit'));
|
|
119
119
|
const sub = fileURLToPath(import.meta.resolve(`@joplo-app/kit/${KIT_SUBPATHS[0]}`));
|
|
120
120
|
if (path.dirname(main) !== path.dirname(sub))
|
|
121
|
-
throw new JoploError('NOT_FOUND', `@joplo-app/kit
|
|
121
|
+
throw new JoploError('NOT_FOUND', `@joplo-app/kit entry points are not in the same directory: ${main}, ${sub}`);
|
|
122
122
|
const ext = path.extname(main);
|
|
123
123
|
return [
|
|
124
124
|
{ find: /^@joplo-app\/kit$/, replacement: main },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/server",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Joplo 本地服务:dev 看板、build 发布站、render 截图",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@joplo-app/core": "0.1
|
|
19
|
-
"@joplo-app/kit": "0.1
|
|
20
|
-
"@joplo-app/web": "0.1
|
|
18
|
+
"@joplo-app/core": "0.2.1",
|
|
19
|
+
"@joplo-app/kit": "0.2.1",
|
|
20
|
+
"@joplo-app/web": "0.2.1",
|
|
21
21
|
"@tailwindcss/vite": "4.3.4",
|
|
22
22
|
"tailwindcss": "4.3.4",
|
|
23
23
|
"vite": "8.3.5",
|