@joplo-app/server 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/binary-assets.d.ts +13 -0
- package/dist/binary-assets.js +42 -3
- package/dist/build.js +5 -2
- package/dist/dev.js +22 -3
- package/dist/export.d.ts +1 -1
- package/dist/export.js +4 -4
- package/dist/film.js +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/media-check.js +3 -3
- package/dist/preview.d.ts +11 -0
- package/dist/preview.js +83 -0
- package/dist/render.js +4 -4
- package/package.json +4 -4
package/dist/binary-assets.d.ts
CHANGED
|
@@ -4,3 +4,16 @@ export declare function binaryAssets<T>(value: T, opts: {
|
|
|
4
4
|
prefix?: string;
|
|
5
5
|
diagnostics?: Diagnostic[];
|
|
6
6
|
}, seen?: Set<string>): T;
|
|
7
|
+
/** 发布素材的扩展名(D98):IR 里这些类型的 data URL 在构建时写成 assets/<sha256>.<ext>。 */
|
|
8
|
+
export declare const SITE_ASSET_TYPES: Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* 发布素材改成独立文件(D98,不再 base64 内联):把 value 里整串是 data URL 的素材写进 directory/<sha256>.<ext>,
|
|
11
|
+
* 换成 prefix + 文件名(页面按相对路径引用)。同一内容只写一次;返回新值与写出的文件名。未知类型原样保留。
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractSiteAssets<T>(value: T, opts: {
|
|
14
|
+
directory: string;
|
|
15
|
+
prefix: string;
|
|
16
|
+
}): {
|
|
17
|
+
value: T;
|
|
18
|
+
files: string[];
|
|
19
|
+
};
|
package/dist/binary-assets.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/** Dev serves binary bytes by content hash;
|
|
1
|
+
/** Dev serves binary bytes by content hash; builds write every embedded asset as its own file (D98). */
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
5
|
export function binaryAssets(value, opts, seen = new Set()) {
|
|
6
|
-
if (typeof value === 'string' && /^data:(model\/gltf-binary|audio\/[a-z0-9.+-]
|
|
6
|
+
if (typeof value === 'string' && /^data:(model\/gltf-binary|audio\/[a-z0-9.+-]+|video\/(?:mp4|webm)|application\/json);base64,/.test(value)) {
|
|
7
7
|
const comma = value.indexOf(','), mime = value.slice(5, comma - 7), bytes = Buffer.from(value.slice(comma + 1), 'base64'), hash = crypto.createHash('sha256').update(bytes).digest('hex');
|
|
8
8
|
if (!seen.has(hash) && mime === 'model/gltf-binary' && bytes.length > 5 * 1024 * 1024)
|
|
9
9
|
opts.diagnostics?.push({ severity: 'warning', source: 'structure', code: 'MODEL_SIZE', message: `GLB model is ${(bytes.length / 1024 / 1024).toFixed(1)} MB; reduce face_limit/textures before publishing (recommended below 5 MB).` });
|
|
@@ -13,7 +13,7 @@ export function binaryAssets(value, opts, seen = new Set()) {
|
|
|
13
13
|
fs.mkdirSync(opts.directory, { recursive: true });
|
|
14
14
|
if (!fs.existsSync(file))
|
|
15
15
|
fs.writeFileSync(file, bytes);
|
|
16
|
-
return `${opts.prefix}${hash}${mime === 'model/gltf-binary' ? '.glb' : '.audio'}`;
|
|
16
|
+
return `${opts.prefix}${hash}${mime === 'model/gltf-binary' ? '.glb' : mime === 'video/mp4' ? '.mp4' : mime === 'video/webm' ? '.webm' : mime === 'application/json' ? '.json' : '.audio'}`;
|
|
17
17
|
}
|
|
18
18
|
return value;
|
|
19
19
|
}
|
|
@@ -23,3 +23,42 @@ export function binaryAssets(value, opts, seen = new Set()) {
|
|
|
23
23
|
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, binaryAssets(v, opts, seen)]));
|
|
24
24
|
return value;
|
|
25
25
|
}
|
|
26
|
+
/** 发布素材的扩展名(D98):IR 里这些类型的 data URL 在构建时写成 assets/<sha256>.<ext>。 */
|
|
27
|
+
export const SITE_ASSET_TYPES = {
|
|
28
|
+
'image/png': '.png', 'image/jpeg': '.jpg', 'image/gif': '.gif', 'image/webp': '.webp', 'image/svg+xml': '.svg', 'image/avif': '.avif',
|
|
29
|
+
'model/gltf-binary': '.glb',
|
|
30
|
+
'audio/mpeg': '.mp3', 'audio/wav': '.wav', 'audio/x-wav': '.wav', 'audio/ogg': '.ogg', 'audio/flac': '.flac', 'audio/mp4': '.m4a', 'audio/aac': '.aac',
|
|
31
|
+
'video/mp4': '.mp4', 'video/webm': '.webm',
|
|
32
|
+
'application/json': '.json',
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 发布素材改成独立文件(D98,不再 base64 内联):把 value 里整串是 data URL 的素材写进 directory/<sha256>.<ext>,
|
|
36
|
+
* 换成 prefix + 文件名(页面按相对路径引用)。同一内容只写一次;返回新值与写出的文件名。未知类型原样保留。
|
|
37
|
+
*/
|
|
38
|
+
export function extractSiteAssets(value, opts) {
|
|
39
|
+
const files = new Set();
|
|
40
|
+
const walk = (v) => {
|
|
41
|
+
if (typeof v === 'string' && v.startsWith('data:')) {
|
|
42
|
+
const m = /^data:([a-z0-9.+/-]+)(;[^,]*)?;base64,/i.exec(v);
|
|
43
|
+
const ext = m ? SITE_ASSET_TYPES[m[1].toLowerCase()] : undefined;
|
|
44
|
+
if (!m || !ext)
|
|
45
|
+
return v;
|
|
46
|
+
const bytes = Buffer.from(v.slice(m[0].length), 'base64');
|
|
47
|
+
const name = `${crypto.createHash('sha256').update(bytes).digest('hex')}${ext}`;
|
|
48
|
+
if (!files.has(name)) {
|
|
49
|
+
fs.mkdirSync(opts.directory, { recursive: true });
|
|
50
|
+
const file = path.join(opts.directory, name);
|
|
51
|
+
if (!fs.existsSync(file))
|
|
52
|
+
fs.writeFileSync(file, bytes);
|
|
53
|
+
files.add(name);
|
|
54
|
+
}
|
|
55
|
+
return `${opts.prefix}${name}`;
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(v))
|
|
58
|
+
return v.map(walk);
|
|
59
|
+
if (v && typeof v === 'object')
|
|
60
|
+
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));
|
|
61
|
+
return v;
|
|
62
|
+
};
|
|
63
|
+
return { value: walk(value), files: [...files] };
|
|
64
|
+
}
|
package/dist/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { binaryAssets } from "./binary-assets.js";
|
|
1
|
+
import { binaryAssets, extractSiteAssets } from "./binary-assets.js";
|
|
2
2
|
import { inlineResources } from "./local-resources.js";
|
|
3
3
|
import { inlinePluginAssets, PLUGIN_ASSET_BASE } from "./plugin-assets.js";
|
|
4
4
|
import sharedModules from '@joplo-app/web/shared-modules.json' with { type: 'json' };
|
|
@@ -174,6 +174,9 @@ export async function buildSite(opts) {
|
|
|
174
174
|
if (voice.index)
|
|
175
175
|
inline.project.voiceIndex = scope ? scopeProject({ ...project, voiceIndex: voice.index }, scope.scenarios).project.voiceIndex : voice.index;
|
|
176
176
|
voiceReport = voice.report;
|
|
177
|
+
// 素材写成独立文件(D98):IR 里的图片、模型、音频、视频 data URL → assets/<sha256>.<ext>,页面按相对路径引用;
|
|
178
|
+
// 构建产物只保证通过 HTTP 打开(Cloud 分享、joplo preview、任意静态服务器),不再支持 file:// 双击。
|
|
179
|
+
inline.project = extractSiteAssets(inline.project, { directory: path.join(staging, 'assets'), prefix: './assets/' }).value;
|
|
177
180
|
// 3. 后处理
|
|
178
181
|
const siteHtml = path.join(staging, 'site.html');
|
|
179
182
|
const { html, inlined } = finalizeHtml(fs.readFileSync(siteHtml, 'utf8'), (rel) => fs.readFileSync(path.join(staging, rel), 'utf8'), inline, stepIdentity(project));
|
|
@@ -194,7 +197,7 @@ export async function buildSite(opts) {
|
|
|
194
197
|
// D59: scan every staged text artifact, then retain only font subsets its content needs.
|
|
195
198
|
subsetSiteFonts(staging, web);
|
|
196
199
|
const siteBytes = listFiles(staging).reduce((n, f) => n + fs.statSync(path.join(staging, f)).size, 0);
|
|
197
|
-
compiled.diagnostics.push({ severity: 'info', source: 'structure', code: 'SITE_BUDGET', message: `Complete site: ${siteBytes} bytes (including
|
|
200
|
+
compiled.diagnostics.push({ severity: 'info', source: 'structure', code: 'SITE_BUDGET', message: `Complete site: ${siteBytes} bytes (including asset files, fonts and narration)` });
|
|
198
201
|
if (siteBytes >= 18 * 1024 * 1024)
|
|
199
202
|
compiled.diagnostics.push({ severity: 'warning', source: 'structure', code: 'SITE_BUDGET_LARGE', message: 'Site approaches the documented Free 20 MiB single-upload budget (18 MiB warning); actual account limits come from the service' });
|
|
200
203
|
// 4. 写入目标目录
|
package/dist/dev.js
CHANGED
|
@@ -558,14 +558,33 @@ export async function createHub(opts = {}) {
|
|
|
558
558
|
return 'next';
|
|
559
559
|
}
|
|
560
560
|
if (rest.startsWith('binary/') && method === 'GET') {
|
|
561
|
-
const slot = await ensure(id), match = /^binary\/([a-f0-9]{64})\.(glb|audio)$/.exec(rest);
|
|
561
|
+
const slot = await ensure(id), match = /^binary\/([a-f0-9]{64})\.(glb|audio|mp4|webm|json)$/.exec(rest);
|
|
562
562
|
if (!match)
|
|
563
563
|
return sendJson(res, 404, { error: 'Unknown binary asset' });
|
|
564
564
|
const file = path.join(slot.dir, '.joplo', 'binary', match[1]);
|
|
565
565
|
if (!fs.existsSync(file))
|
|
566
566
|
return sendJson(res, 404, { error: 'Missing binary asset' });
|
|
567
|
-
|
|
568
|
-
res.
|
|
567
|
+
const type = { glb: 'model/gltf-binary', mp4: 'video/mp4', webm: 'video/webm', json: 'application/json' }[match[2]] ?? 'application/octet-stream';
|
|
568
|
+
res.setHeader('Content-Type', type);
|
|
569
|
+
res.setHeader('Accept-Ranges', 'bytes');
|
|
570
|
+
const bytes = fs.readFileSync(file);
|
|
571
|
+
// 视频拖动(D96 媒体插件):单段 Range
|
|
572
|
+
const range = /^bytes=(\d*)-(\d*)$/.exec(String(req.headers.range ?? ''));
|
|
573
|
+
if (range && (range[1] || range[2])) {
|
|
574
|
+
const start = range[1] ? Number(range[1]) : Math.max(0, bytes.length - Number(range[2]));
|
|
575
|
+
const end = range[1] && range[2] ? Math.min(bytes.length - 1, Number(range[2])) : bytes.length - 1;
|
|
576
|
+
if (start > end || start >= bytes.length) {
|
|
577
|
+
res.statusCode = 416;
|
|
578
|
+
res.setHeader('Content-Range', `bytes */${bytes.length}`);
|
|
579
|
+
res.end();
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
res.statusCode = 206;
|
|
583
|
+
res.setHeader('Content-Range', `bytes ${start}-${end}/${bytes.length}`);
|
|
584
|
+
res.end(bytes.subarray(start, end + 1));
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
res.end(bytes);
|
|
569
588
|
return;
|
|
570
589
|
}
|
|
571
590
|
if (rest.startsWith('resources/') && method === 'POST') {
|
package/dist/export.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type InstallDeps, type InstallProgress, type PlaywrightModule } from '.
|
|
|
4
4
|
export type Device = 'desktop' | 'mobile';
|
|
5
5
|
/**
|
|
6
6
|
* 导出画面的尺寸:电脑 = 舞台 1280×800;手机 = 外框(renderer 的 phoneFrameSize(390, 844) = 446×934)
|
|
7
|
-
* 四周再留 16px(RenderApp 的 frame
|
|
7
|
+
* 四周再留 16px(RenderApp 的 frame 模式)。字幕与步骤标题条浮在舞台上(D97),不另占高度。
|
|
8
8
|
*/
|
|
9
9
|
export declare const EXPORT_SIZE: Record<Device, {
|
|
10
10
|
width: number;
|
package/dist/export.js
CHANGED
|
@@ -23,16 +23,16 @@ import crypto from 'node:crypto';
|
|
|
23
23
|
import fs from 'node:fs';
|
|
24
24
|
import path from 'node:path';
|
|
25
25
|
import { exportLocale } from "./locale.js";
|
|
26
|
-
import { JoploError,
|
|
26
|
+
import { JoploError, THEME_NAME, displaySceneId, isAppearanceFont, isAppearanceStroke } from '@joplo-app/core';
|
|
27
27
|
import { launch } from "./render.js";
|
|
28
28
|
import { exportRuntimeStatus, installExportRuntime, loadPlaywright } from "./export-runtime.js";
|
|
29
29
|
/**
|
|
30
30
|
* 导出画面的尺寸:电脑 = 舞台 1280×800;手机 = 外框(renderer 的 phoneFrameSize(390, 844) = 446×934)
|
|
31
|
-
* 四周再留 16px(RenderApp 的 frame
|
|
31
|
+
* 四周再留 16px(RenderApp 的 frame 模式)。字幕与步骤标题条浮在舞台上(D97),不另占高度。
|
|
32
32
|
*/
|
|
33
33
|
export const EXPORT_SIZE = {
|
|
34
|
-
desktop: { width: 1280, height: 800
|
|
35
|
-
mobile: { width: 446 + 32, height: 934 + 32
|
|
34
|
+
desktop: { width: 1280, height: 800 },
|
|
35
|
+
mobile: { width: 446 + 32, height: 934 + 32 },
|
|
36
36
|
};
|
|
37
37
|
const send = (res, status, body) => {
|
|
38
38
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff' });
|
package/dist/film.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import fs from 'node:fs';
|
|
15
15
|
import path from 'node:path';
|
|
16
|
-
import { JoploError,
|
|
16
|
+
import { JoploError, displaySceneId } from '@joplo-app/core';
|
|
17
17
|
import { createDev } from "./dev.js";
|
|
18
18
|
import { realProjectDir } from "./vite-shared.js";
|
|
19
19
|
import { joploHome } from "./home.js";
|
|
@@ -159,7 +159,9 @@ export async function renderFilm(opts) {
|
|
|
159
159
|
await page.clock.pauseAt(now + 1);
|
|
160
160
|
const helper = await ctx.newPage();
|
|
161
161
|
await helper.setContent(DIFF_PAGE);
|
|
162
|
-
|
|
162
|
+
// 字幕与步骤标题条浮在画面上(D97):胶片条只看画面本身的运动,采样时把它们藏起来,文字换行不算镜头切换
|
|
163
|
+
await page.addStyleTag({ content: '[data-jsubtitle],[data-testid="step-title"]{visibility:hidden!important}' });
|
|
164
|
+
const stageRatio = 1;
|
|
163
165
|
const samples = [];
|
|
164
166
|
let tail = -1;
|
|
165
167
|
// 第一帧在开播之前采(封面 / 第 0 步):开播那一下的切换也要量到
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
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 { startPreview, SITE_CONTENT_TYPES, type PreviewHandle } from './preview.js';
|
|
12
13
|
export { generateProjectVoice, type VoiceRunOptions, type VoiceRunResult } from './voice-run.js';
|
|
13
14
|
export type { CloudSpeechRequest, CloudSpeechResult, CloudVoice, CloudVoiceBridge, CloudVoiceCatalog, CloudVoiceInfo, CloudVoiceStatus, VoiceQuota } from './cloud.js';
|
|
14
15
|
export { renderSheet, renderStep } from './render.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 { startPreview, SITE_CONTENT_TYPES } from "./preview.js";
|
|
3
4
|
export { generateProjectVoice } from "./voice-run.js";
|
|
4
5
|
export { renderSheet, renderStep } from "./render.js";
|
|
5
6
|
export { renderFilm, renderVideo } from "./film.js";
|
package/dist/media-check.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mediaResourceIds, nodeResourceIds } from '@joplo-app/core';
|
|
1
|
+
import { mediaResourceIds, nodeResourceIds, stepAnchorMs } from '@joplo-app/core';
|
|
2
2
|
export async function inspectResources(project, requests, host) {
|
|
3
3
|
const used = project ? mediaResourceIds(project) : new Set();
|
|
4
4
|
for (const id of nodeResourceIds(project))
|
|
@@ -44,8 +44,8 @@ export function mediaDiagnostics(project, info) {
|
|
|
44
44
|
finish(key);
|
|
45
45
|
if (!runs.has(key))
|
|
46
46
|
runs.set(key, { resource: t.resource, offset: t.offsetMs, duration: 0, loop: t.loop, at: step.source });
|
|
47
|
-
runs.get(key).duration += Math.min(step
|
|
48
|
-
if (t.stopAfterMs !== undefined && t.stopAfterMs <= (step
|
|
47
|
+
runs.get(key).duration += Math.min(stepAnchorMs(step), t.stopAfterMs ?? Infinity);
|
|
48
|
+
if (t.stopAfterMs !== undefined && t.stopAfterMs <= stepAnchorMs(step))
|
|
49
49
|
finish(key);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** 构建产物里会出现的文件类型;与 Cloud 分享接受的类型一致(D98 增加视频与 GLB)。 */
|
|
2
|
+
export declare const SITE_CONTENT_TYPES: Record<string, string>;
|
|
3
|
+
export type PreviewHandle = {
|
|
4
|
+
url: string;
|
|
5
|
+
close: () => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare function startPreview(opts: {
|
|
8
|
+
dir: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
host?: string;
|
|
11
|
+
}): Promise<PreviewHandle>;
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* joplo preview(D98):在本机用静态服务器打开构建产物。构建产物的素材是独立文件(assets/),
|
|
3
|
+
* 只保证通过 HTTP 打开,不再支持 file:// 双击。只读、只监听 127.0.0.1、不跟随目录外的路径。
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import http from 'node:http';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { JoploError } from '@joplo-app/core';
|
|
9
|
+
/** 构建产物里会出现的文件类型;与 Cloud 分享接受的类型一致(D98 增加视频与 GLB)。 */
|
|
10
|
+
export const SITE_CONTENT_TYPES = {
|
|
11
|
+
'.html': 'text/html; charset=utf-8', '.css': 'text/css; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8',
|
|
12
|
+
'.json': 'application/json', '.txt': 'text/plain; charset=utf-8',
|
|
13
|
+
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.avif': 'image/avif',
|
|
14
|
+
'.woff2': 'font/woff2', '.woff': 'font/woff', '.ttf': 'font/ttf',
|
|
15
|
+
'.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg', '.flac': 'audio/flac', '.m4a': 'audio/mp4', '.aac': 'audio/aac',
|
|
16
|
+
'.mp4': 'video/mp4', '.webm': 'video/webm',
|
|
17
|
+
'.glb': 'model/gltf-binary',
|
|
18
|
+
};
|
|
19
|
+
export async function startPreview(opts) {
|
|
20
|
+
const root = path.resolve(opts.dir);
|
|
21
|
+
if (!fs.existsSync(path.join(root, 'index.html')))
|
|
22
|
+
throw new JoploError('USAGE', `${root} has no index.html. Run npx joplo build first, then npx joplo preview <output dir> (default: <project>/dist)`);
|
|
23
|
+
const real = fs.realpathSync(root);
|
|
24
|
+
const server = http.createServer((req, res) => {
|
|
25
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
26
|
+
res.writeHead(405, { allow: 'GET, HEAD' }).end();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let rel;
|
|
30
|
+
try {
|
|
31
|
+
rel = decodeURIComponent(new URL(req.url ?? '/', 'http://localhost').pathname);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
res.writeHead(400).end();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (rel.endsWith('/'))
|
|
38
|
+
rel += 'index.html';
|
|
39
|
+
const file = path.resolve(real, '.' + rel);
|
|
40
|
+
const type = SITE_CONTENT_TYPES[path.extname(file).toLowerCase()];
|
|
41
|
+
let resolved;
|
|
42
|
+
try {
|
|
43
|
+
resolved = fs.realpathSync(file);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
res.writeHead(404).end();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!(resolved === real || resolved.startsWith(real + path.sep)) || !type || !fs.statSync(resolved).isFile()) {
|
|
50
|
+
res.writeHead(404).end();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const size = fs.statSync(resolved).size;
|
|
54
|
+
const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range ?? '');
|
|
55
|
+
// 视频 / 音频拖动需要 Range
|
|
56
|
+
if (range && (range[1] || range[2])) {
|
|
57
|
+
const start = range[1] ? Number(range[1]) : Math.max(0, size - Number(range[2]));
|
|
58
|
+
const end = range[1] && range[2] ? Math.min(size - 1, Number(range[2])) : size - 1;
|
|
59
|
+
if (start > end || start >= size) {
|
|
60
|
+
res.writeHead(416, { 'content-range': `bytes */${size}` }).end();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
res.writeHead(206, { 'content-type': type, 'content-length': end - start + 1, 'content-range': `bytes ${start}-${end}/${size}`, 'accept-ranges': 'bytes', 'cache-control': 'no-cache' });
|
|
64
|
+
if (req.method === 'HEAD') {
|
|
65
|
+
res.end();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
fs.createReadStream(resolved, { start, end }).pipe(res);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
res.writeHead(200, { 'content-type': type, 'content-length': size, 'accept-ranges': 'bytes', 'cache-control': 'no-cache' });
|
|
72
|
+
if (req.method === 'HEAD') {
|
|
73
|
+
res.end();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
fs.createReadStream(resolved).pipe(res);
|
|
77
|
+
});
|
|
78
|
+
const host = opts.host ?? '127.0.0.1';
|
|
79
|
+
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(opts.port ?? 0, host, () => resolve()); });
|
|
80
|
+
const address = server.address();
|
|
81
|
+
const port = typeof address === 'object' && address ? address.port : opts.port ?? 0;
|
|
82
|
+
return { url: `http://${host}:${port}/`, close: () => new Promise((resolve) => server.close(() => resolve())) };
|
|
83
|
+
}
|
package/dist/render.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
-
import { JoploError,
|
|
11
|
+
import { JoploError, VIEWPORT_SIZE, isAppearanceFont, isAppearanceStroke, displaySceneId, findNode, isNodeDisabled, nodeLabel, positionAfterStep, resolveProps, scopeProject, stateAt, walkNodes } from '@joplo-app/core';
|
|
12
12
|
import { exportLocale } from "./locale.js";
|
|
13
13
|
import { createDev } from "./dev.js";
|
|
14
14
|
import { realProjectDir } from "./vite-shared.js";
|
|
@@ -115,8 +115,8 @@ export async function renderStep(opts) {
|
|
|
115
115
|
const next = state.completed ? undefined : sc.steps[position];
|
|
116
116
|
const nextTargetId = next && 'target' in next.action ? next.action.target : null;
|
|
117
117
|
const stage = STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
118
|
-
//
|
|
119
|
-
const viewport = opts.viewport ?? { width: stage.width, height: stage.height
|
|
118
|
+
// 字幕与步骤标题条浮在舞台上(D97):页面就是舞台大小
|
|
119
|
+
const viewport = opts.viewport ?? { width: stage.width, height: stage.height };
|
|
120
120
|
browser = await launch(playwright);
|
|
121
121
|
const page = await browser.newPage({ viewport, deviceScaleFactor: opts.scale ?? 1, reducedMotion: 'reduce' });
|
|
122
122
|
// D44:舞台宽度固定为页面自己的 viewport;指定 viewport 时它只是截图尺寸(舞台按比例放进去)
|
|
@@ -199,7 +199,7 @@ export async function renderSheet(opts) {
|
|
|
199
199
|
const stage = STAGE_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'];
|
|
200
200
|
const next = state.completed ? undefined : sc.steps[position];
|
|
201
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
|
|
202
|
+
const page = await browser.newPage({ viewport: { width: stage.width, height: stage.height }, deviceScaleFactor: 1, reducedMotion: 'reduce' });
|
|
203
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
204
|
await page.goto(`${server.url}?${q}`, { waitUntil: 'domcontentloaded' });
|
|
205
205
|
await page.waitForFunction(() => window.__JOPLO_READY__ === true, null, { timeout: 60000 });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Joplo 本地服务:dev 看板、build 发布站、render 截图",
|
|
5
5
|
"license": "PolyForm-Shield-1.0.0",
|
|
6
6
|
"type": "module",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@joplo-app/core": "0.
|
|
19
|
-
"@joplo-app/kit": "0.
|
|
20
|
-
"@joplo-app/web": "0.
|
|
18
|
+
"@joplo-app/core": "0.5.0",
|
|
19
|
+
"@joplo-app/kit": "0.5.0",
|
|
20
|
+
"@joplo-app/web": "0.5.0",
|
|
21
21
|
"@tailwindcss/vite": "4.3.4",
|
|
22
22
|
"mediabunny": "1.65.2",
|
|
23
23
|
"tailwindcss": "4.3.4",
|