@neta-art/cohub-cli 10.23.0 → 10.25.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/README.md +18 -5
- package/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +309 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2511 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -118
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -64
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2139
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -6
- package/dist/session-status.js +0 -16
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
import { t as packagePath } from "./package-paths.js";
|
|
2
|
+
import { t as createClient } from "./client.js";
|
|
3
|
+
import { dt as parseBoardMediaSource } from "./id.js";
|
|
4
|
+
import { E as boardTimedMedia, S as boardTexturePixels, T as boardMediaSpans, _ as selectBoardExportAssets, a as describeBoardScriptLanes, b as boardMediaNaturalSize, c as boardRenderTheme, g as planBoardExport, h as boardExportView, i as createNodeBoardScriptHost, j as hasBoardScripts, k as parseBoardScriptInputs, m as boardAutoplayLoops, n as createNodeBoardRenderer, o as describeBoardExportWarning, p as createBoardRenderSampler, r as exportBoardImageBytes, s as prepareBoardExport, v as boardAssetKey, w as boardMediaRate, x as boardTextureEdge, y as boardAssetKeySource } from "./board-kernel.js";
|
|
5
|
+
import { k as boardAnimatesScriptParams, w as buildBoardScene } from "./themes.js";
|
|
6
|
+
import { i as mediaVariantSize, n as imageVariantUrl, s as videoFrameUrl } from "./media.js";
|
|
7
|
+
import { i as settleBoardDocument, n as BoardExportResourceError, r as createBoardExportImageBudget, s as loadBoardDocument } from "./board-export-resources.js";
|
|
8
|
+
import { n as downloadPublicImage, r as downloadPublicVideo, t as downloadPublicAudio } from "./safe-remote-image.js";
|
|
9
|
+
import { a as findBoardGpuBrowser, r as openBoardGpu } from "./daemon.js";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import { execFile } from "node:child_process";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { constants as constants$1, existsSync } from "node:fs";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
import { copyFile, link, mkdir, mkdtemp, readFile, rename, rm, unlink, writeFile } from "node:fs/promises";
|
|
17
|
+
import { debuglog, promisify } from "node:util";
|
|
18
|
+
//#region src/board-fonts.ts
|
|
19
|
+
const BOARD_EXPORT_FONTS = [
|
|
20
|
+
{
|
|
21
|
+
pkg: "@fontsource-variable/geist",
|
|
22
|
+
file: "geist-latin-wght-normal.woff2",
|
|
23
|
+
family: "Geist Variable"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
pkg: "@fontsource-variable/geist-mono",
|
|
27
|
+
file: "geist-mono-latin-wght-normal.woff2",
|
|
28
|
+
family: "Geist Mono Variable"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
pkg: "@fontsource-variable/figtree",
|
|
32
|
+
file: "figtree-latin-wght-normal.woff2",
|
|
33
|
+
family: "Figtree Variable"
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/board-media-export.ts
|
|
38
|
+
const execFile$2 = promisify(execFile);
|
|
39
|
+
const CHUNK_SECONDS = 4;
|
|
40
|
+
const MAX_DECODE_FPS = 60;
|
|
41
|
+
async function ffmpeg(args, signal) {
|
|
42
|
+
try {
|
|
43
|
+
return await execFile$2("ffmpeg", [
|
|
44
|
+
"-v",
|
|
45
|
+
"error",
|
|
46
|
+
...args
|
|
47
|
+
], {
|
|
48
|
+
encoding: "utf8",
|
|
49
|
+
maxBuffer: 2097152,
|
|
50
|
+
signal
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const cause = error;
|
|
54
|
+
if (cause.code === "ENOENT") throw new Error("Exporting video and audio needs ffmpeg. Install ffmpeg and try again.");
|
|
55
|
+
throw new Error(`ffmpeg failed: ${(cause.stderr ?? cause.message ?? "unknown error").trim().split("\n").slice(-4).join("\n")}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function createBoardMediaFiles(spaceId, dir, signal) {
|
|
59
|
+
const files = /* @__PURE__ */ new Map();
|
|
60
|
+
const audible = /* @__PURE__ */ new Map();
|
|
61
|
+
const durations = /* @__PURE__ */ new Map();
|
|
62
|
+
const client = createClient();
|
|
63
|
+
return {
|
|
64
|
+
path(src, kind) {
|
|
65
|
+
let pending = files.get(src);
|
|
66
|
+
if (!pending) {
|
|
67
|
+
const path = join(dir, `media-${files.size}`);
|
|
68
|
+
pending = (async () => {
|
|
69
|
+
const source = parseBoardMediaSource(src);
|
|
70
|
+
if (!source) throw new Error(`Invalid media source ${src}`);
|
|
71
|
+
const { bytes } = source.kind === "file" ? { bytes: new Uint8Array(await (await client.space(spaceId).files.download(source.value)).blob.arrayBuffer()) } : await (kind === "video" ? downloadPublicVideo : downloadPublicAudio)(source.value);
|
|
72
|
+
await writeFile(path, bytes);
|
|
73
|
+
return path;
|
|
74
|
+
})();
|
|
75
|
+
files.set(src, pending);
|
|
76
|
+
}
|
|
77
|
+
return pending;
|
|
78
|
+
},
|
|
79
|
+
async audible(src, kind) {
|
|
80
|
+
let pending = audible.get(src);
|
|
81
|
+
if (!pending) {
|
|
82
|
+
pending = this.path(src, kind).then(async (path) => {
|
|
83
|
+
const { stdout } = await execFile$2("ffprobe", [
|
|
84
|
+
"-v",
|
|
85
|
+
"error",
|
|
86
|
+
"-select_streams",
|
|
87
|
+
"a",
|
|
88
|
+
"-show_entries",
|
|
89
|
+
"stream=index",
|
|
90
|
+
"-of",
|
|
91
|
+
"csv=p=0",
|
|
92
|
+
path
|
|
93
|
+
], { signal });
|
|
94
|
+
return stdout.trim().length > 0;
|
|
95
|
+
});
|
|
96
|
+
audible.set(src, pending);
|
|
97
|
+
}
|
|
98
|
+
return pending;
|
|
99
|
+
},
|
|
100
|
+
async duration(src) {
|
|
101
|
+
let pending = durations.get(src);
|
|
102
|
+
if (!pending) {
|
|
103
|
+
pending = this.path(src, "video").then(async (path) => {
|
|
104
|
+
const { stdout } = await execFile$2("ffprobe", [
|
|
105
|
+
"-v",
|
|
106
|
+
"error",
|
|
107
|
+
"-show_entries",
|
|
108
|
+
"format=duration",
|
|
109
|
+
"-of",
|
|
110
|
+
"csv=p=0",
|
|
111
|
+
path
|
|
112
|
+
], { signal });
|
|
113
|
+
return Math.max(0, Number(stdout.trim()) * 1e3 || 0);
|
|
114
|
+
}).catch(() => 0);
|
|
115
|
+
durations.set(src, pending);
|
|
116
|
+
}
|
|
117
|
+
return pending;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function createBoardVideoFrames(files, dir, options) {
|
|
122
|
+
const chunks = /* @__PURE__ */ new Map();
|
|
123
|
+
let decoded = 0;
|
|
124
|
+
function lookup(chunk, time, edge) {
|
|
125
|
+
if (!chunk || edge > chunk.edge) return null;
|
|
126
|
+
const index = chunk.count === 1 ? Math.abs(time - chunk.start) < 1 ? 0 : -1 : Math.round((time - chunk.start) * chunk.fps / 1e3);
|
|
127
|
+
return index >= 0 && index < chunk.count ? join(chunk.dir, `${String(index + 1).padStart(5, "0")}.jpg`) : null;
|
|
128
|
+
}
|
|
129
|
+
async function decode(state, rate, edge) {
|
|
130
|
+
const path = await files.path(state.src, "video");
|
|
131
|
+
const previous = chunks.get(state.id);
|
|
132
|
+
if (previous) await rm(previous.dir, {
|
|
133
|
+
recursive: true,
|
|
134
|
+
force: true
|
|
135
|
+
});
|
|
136
|
+
const chunkDir = join(dir, `frames-${decoded++}`);
|
|
137
|
+
await mkdir(chunkDir);
|
|
138
|
+
const fps = rate > 0 ? Math.min(MAX_DECODE_FPS, Math.max(1, Math.ceil(options.fps * rate))) : 0;
|
|
139
|
+
const scale = `scale=w=${edge}:h=${edge}:force_original_aspect_ratio=decrease`;
|
|
140
|
+
await ffmpeg([
|
|
141
|
+
"-ss",
|
|
142
|
+
(state.time / 1e3).toFixed(3),
|
|
143
|
+
"-i",
|
|
144
|
+
path,
|
|
145
|
+
...fps ? [
|
|
146
|
+
"-t",
|
|
147
|
+
String(CHUNK_SECONDS),
|
|
148
|
+
"-vf",
|
|
149
|
+
`fps=${fps},${scale}`
|
|
150
|
+
] : [
|
|
151
|
+
"-frames:v",
|
|
152
|
+
"1",
|
|
153
|
+
"-vf",
|
|
154
|
+
scale
|
|
155
|
+
],
|
|
156
|
+
"-q:v",
|
|
157
|
+
"3",
|
|
158
|
+
join(chunkDir, "%05d.jpg")
|
|
159
|
+
], options.signal);
|
|
160
|
+
const count = fps ? Math.max(1, Math.round(CHUNK_SECONDS * fps)) : 1;
|
|
161
|
+
const chunk = {
|
|
162
|
+
src: state.src,
|
|
163
|
+
start: state.time,
|
|
164
|
+
fps: fps || 1,
|
|
165
|
+
count,
|
|
166
|
+
edge,
|
|
167
|
+
dir: chunkDir
|
|
168
|
+
};
|
|
169
|
+
chunks.set(state.id, chunk);
|
|
170
|
+
return chunk;
|
|
171
|
+
}
|
|
172
|
+
return { async frame(state, rate, edge) {
|
|
173
|
+
if (state.loop) {
|
|
174
|
+
const duration = await files.duration(state.src);
|
|
175
|
+
if (duration > 0) state = {
|
|
176
|
+
...state,
|
|
177
|
+
time: state.time % duration
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const current = chunks.get(state.id);
|
|
181
|
+
let file = current?.src === state.src ? lookup(current, state.time, edge) : null;
|
|
182
|
+
if (!file) file = lookup(await decode(state, rate, edge), state.time, edge);
|
|
183
|
+
return file ? new Uint8Array(await readFile(file).catch(() => Buffer.alloc(0))) : null;
|
|
184
|
+
} };
|
|
185
|
+
}
|
|
186
|
+
function volumeExpression(span) {
|
|
187
|
+
const points = span.volume.map((point) => ({
|
|
188
|
+
t: (point.at - span.start) / 1e3,
|
|
189
|
+
v: point.value
|
|
190
|
+
}));
|
|
191
|
+
if (points.every((point) => point.v === points[0]?.v)) return String(points[0]?.v ?? 1);
|
|
192
|
+
let expression = String(points.at(-1)?.v ?? 1);
|
|
193
|
+
for (let index = points.length - 2; index >= 0; index -= 1) {
|
|
194
|
+
const a = points[index];
|
|
195
|
+
const b = points[index + 1];
|
|
196
|
+
const slope = b.t > a.t ? (b.v - a.v) / (b.t - a.t) : 0;
|
|
197
|
+
expression = `if(lt(t,${b.t.toFixed(4)}),${a.v.toFixed(4)}+${slope.toFixed(6)}*(t-${a.t.toFixed(4)}),${expression})`;
|
|
198
|
+
}
|
|
199
|
+
return `'${expression}'`;
|
|
200
|
+
}
|
|
201
|
+
function tempo(rate) {
|
|
202
|
+
const stages = [];
|
|
203
|
+
let rest = rate;
|
|
204
|
+
while (rest > 2) {
|
|
205
|
+
stages.push("atempo=2");
|
|
206
|
+
rest /= 2;
|
|
207
|
+
}
|
|
208
|
+
while (rest < .5) {
|
|
209
|
+
stages.push("atempo=0.5");
|
|
210
|
+
rest /= .5;
|
|
211
|
+
}
|
|
212
|
+
if (Math.abs(rest - 1) > 1e-4) stages.push(`atempo=${rest.toFixed(6)}`);
|
|
213
|
+
return stages;
|
|
214
|
+
}
|
|
215
|
+
async function boardAudioMix(spans, files, firstInput) {
|
|
216
|
+
const inputs = [];
|
|
217
|
+
const chains = [];
|
|
218
|
+
for (const span of spans) {
|
|
219
|
+
if (!await files.audible(span.src, span.kind)) continue;
|
|
220
|
+
const index = firstInput + chains.length;
|
|
221
|
+
inputs.push("-i", await files.path(span.src, span.kind));
|
|
222
|
+
const length = (span.end - span.start) * span.rate / 1e3;
|
|
223
|
+
const delay = Math.max(0, Math.round(span.start));
|
|
224
|
+
const filters = [
|
|
225
|
+
`atrim=start=${(span.from / 1e3).toFixed(4)}:duration=${length.toFixed(4)}`,
|
|
226
|
+
"asetpts=PTS-STARTPTS",
|
|
227
|
+
...tempo(span.rate),
|
|
228
|
+
`volume=${volumeExpression(span)}:eval=frame`,
|
|
229
|
+
`adelay=${delay}:all=1`
|
|
230
|
+
];
|
|
231
|
+
chains.push(`[${index}:a]${filters.join(",")}[a${chains.length}]`);
|
|
232
|
+
}
|
|
233
|
+
if (!chains.length) return null;
|
|
234
|
+
const mixed = chains.map((_, index) => `[a${index}]`).join("");
|
|
235
|
+
return {
|
|
236
|
+
inputs,
|
|
237
|
+
filter: `${chains.join(";")};${mixed}amix=inputs=${chains.length}:duration=longest:dropout_transition=0:normalize=0[aout]`
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/board-export.ts
|
|
242
|
+
const execFile$1 = promisify(execFile);
|
|
243
|
+
const debugExport = debuglog("cohub:board-export");
|
|
244
|
+
function resolveBundledFonts() {
|
|
245
|
+
const require = createRequire(import.meta.url);
|
|
246
|
+
const bundled = packagePath("dist", "fonts");
|
|
247
|
+
const locate = ({ pkg, file }) => {
|
|
248
|
+
const copied = join(bundled, file);
|
|
249
|
+
if (existsSync(copied)) return copied;
|
|
250
|
+
try {
|
|
251
|
+
const path = join(dirname(require.resolve(`${pkg}/package.json`)), "files", file);
|
|
252
|
+
return existsSync(path) ? path : null;
|
|
253
|
+
} catch {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return BOARD_EXPORT_FONTS.flatMap((font) => {
|
|
258
|
+
const path = locate(font);
|
|
259
|
+
return path ? [{
|
|
260
|
+
path,
|
|
261
|
+
family: font.family
|
|
262
|
+
}] : [];
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/** Texture keys Node can draw; 3D model stills need a browser. */
|
|
266
|
+
function boardExportAssetKey(item) {
|
|
267
|
+
const key = boardAssetKey(item);
|
|
268
|
+
return key && boardAssetKeySource(key)?.media !== "model" ? key : null;
|
|
269
|
+
}
|
|
270
|
+
function textureEdge(item, scale) {
|
|
271
|
+
const edge = boardTextureEdge(item, scale);
|
|
272
|
+
return Number.isFinite(edge) ? edge : Math.ceil(boardTexturePixels(item, scale));
|
|
273
|
+
}
|
|
274
|
+
const textureBytes = (texture) => texture.width * texture.height * 4;
|
|
275
|
+
/**
|
|
276
|
+
* Previews for `items` within what the image budget leaves after other images,
|
|
277
|
+
* such as the background. A preview that still does not fit is omitted.
|
|
278
|
+
*/
|
|
279
|
+
async function loadBoardTextures(images, spaceId, items, options) {
|
|
280
|
+
const { textures, edges, missed } = options.cache ?? {
|
|
281
|
+
textures: /* @__PURE__ */ new Map(),
|
|
282
|
+
edges: /* @__PURE__ */ new Map(),
|
|
283
|
+
missed: /* @__PURE__ */ new Map()
|
|
284
|
+
};
|
|
285
|
+
let previewBytes = 0;
|
|
286
|
+
for (const texture of textures.values()) previewBytes += textureBytes(texture);
|
|
287
|
+
const maxBytes = options.maxBytes - (images.usedBytes - previewBytes);
|
|
288
|
+
const selection = selectBoardExportAssets([...items], boardExportAssetKey, {
|
|
289
|
+
scale: options.scale,
|
|
290
|
+
maxBytes
|
|
291
|
+
});
|
|
292
|
+
const wanted = new Set(selection.keys);
|
|
293
|
+
for (const [key, texture] of textures) {
|
|
294
|
+
if (wanted.has(key)) continue;
|
|
295
|
+
texture.destroy(true);
|
|
296
|
+
textures.delete(key);
|
|
297
|
+
edges.delete(key);
|
|
298
|
+
}
|
|
299
|
+
for (const key of missed.keys()) if (!wanted.has(key)) missed.delete(key);
|
|
300
|
+
const pending = selection.items.flatMap((item, index) => {
|
|
301
|
+
const key = selection.keys[index];
|
|
302
|
+
const edge = textureEdge(item, options.scale);
|
|
303
|
+
return missed.has(key) || (edges.get(key) ?? 0) >= edge ? [] : [{
|
|
304
|
+
key,
|
|
305
|
+
item,
|
|
306
|
+
edge
|
|
307
|
+
}];
|
|
308
|
+
});
|
|
309
|
+
const concurrency = Math.max(1, Math.min(options.concurrency ?? 2, 16));
|
|
310
|
+
const client = createClient();
|
|
311
|
+
async function worker() {
|
|
312
|
+
for (let task = pending.shift(); task; task = pending.shift()) {
|
|
313
|
+
const { key, item, edge } = task;
|
|
314
|
+
let miss = "unavailable";
|
|
315
|
+
try {
|
|
316
|
+
const source = boardAssetKeySource(key);
|
|
317
|
+
const picture = source && await fetchBoardPicture(client, spaceId, source, item, edge);
|
|
318
|
+
if (picture) {
|
|
319
|
+
const texture = await images.decodeImage(picture.bytes, picture.mimeType, edge);
|
|
320
|
+
textures.get(key)?.destroy(true);
|
|
321
|
+
textures.set(key, texture);
|
|
322
|
+
edges.set(key, Math.max(texture.width, texture.height) < edge ? Number.POSITIVE_INFINITY : edge);
|
|
323
|
+
miss = null;
|
|
324
|
+
}
|
|
325
|
+
} catch (error) {
|
|
326
|
+
miss = error instanceof BoardExportResourceError ? "omitted" : "error";
|
|
327
|
+
}
|
|
328
|
+
if (miss && textures.has(key)) edges.set(key, Number.POSITIVE_INFINITY);
|
|
329
|
+
else if (miss) missed.set(key, miss);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, pending.length) }, worker));
|
|
333
|
+
const keys = (reason) => [...missed].flatMap(([key, value]) => value === reason ? [key] : []);
|
|
334
|
+
return {
|
|
335
|
+
textures,
|
|
336
|
+
failed: keys("error"),
|
|
337
|
+
unavailable: keys("unavailable"),
|
|
338
|
+
omitted: [...selection.omittedKeys, ...keys("omitted")]
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The picture for a texture, `edge` pixels on its long edge where the host can
|
|
343
|
+
* resize: a CDN variant of an image, or the first frame of a video. Null when
|
|
344
|
+
* there is none, as for videos outside Cohub's media hosts.
|
|
345
|
+
*/
|
|
346
|
+
async function fetchBoardPicture(client, spaceId, source, item, edge) {
|
|
347
|
+
const variantEdge = Number.isFinite(edge) && edge <= 1536 ? mediaVariantSize(edge) : null;
|
|
348
|
+
const video = source.media === "video";
|
|
349
|
+
const url = source.kind === "url" ? source.value : video || variantEdge ? (await client.space(spaceId).files.resolve(source.value, { purpose: "playback" }).catch(() => null))?.url : null;
|
|
350
|
+
if (video) {
|
|
351
|
+
const frame = url && videoFrameUrl(url, mediaVariantSize(edge), { natural: boardMediaNaturalSize(item) });
|
|
352
|
+
return frame ? downloadPublicImage(frame) : null;
|
|
353
|
+
}
|
|
354
|
+
const variant = url && variantEdge && imageVariantUrl(url, variantEdge);
|
|
355
|
+
if (variant) try {
|
|
356
|
+
return await downloadPublicImage(variant);
|
|
357
|
+
} catch {}
|
|
358
|
+
return source.kind === "url" ? downloadPublicImage(source.value) : readSpaceFileBytes(client, spaceId, source.value);
|
|
359
|
+
}
|
|
360
|
+
async function readSpaceFileBytes(client, spaceId, path) {
|
|
361
|
+
const { blob, mimeType } = await client.space(spaceId).files.download(path);
|
|
362
|
+
return {
|
|
363
|
+
bytes: new Uint8Array(await blob.arrayBuffer()),
|
|
364
|
+
mimeType
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
async function runBoardVideoExport(options) {
|
|
368
|
+
if (!options.animation) throw new Error("Video export needs --animation.");
|
|
369
|
+
if (!options.times || options.times.length < 2) throw new Error("Video export needs an --at range with at least two frames.");
|
|
370
|
+
const times = options.times;
|
|
371
|
+
const step = times[1] - times[0];
|
|
372
|
+
if (!Number.isFinite(step) || step <= 0) throw new Error("Video export needs an increasing --at range.");
|
|
373
|
+
const derivedFps = 1e3 / step;
|
|
374
|
+
if (Math.abs(options.fps - derivedFps) > .01) throw new Error(`--fps must match the --at step (${derivedFps.toFixed(3)} fps).`);
|
|
375
|
+
if (times.some((time, index) => index > 0 && Math.abs(time - times[index - 1] - step) > .001)) throw new Error("Video export needs evenly spaced times.");
|
|
376
|
+
await execFile$1("ffmpeg", ["-version"], { signal: options.signal }).catch(() => {
|
|
377
|
+
throw new Error("Video export needs ffmpeg. Install ffmpeg and try again.");
|
|
378
|
+
});
|
|
379
|
+
const document = options.document ?? await settleBoardDocument(options.spaceId, (await loadBoardDocument(options.spaceId, options.target)).document);
|
|
380
|
+
const tempDir = await mkdtemp(join(tmpdir(), "cohub-board-export-"));
|
|
381
|
+
try {
|
|
382
|
+
let count = 0;
|
|
383
|
+
let dimensions = {
|
|
384
|
+
width: 0,
|
|
385
|
+
height: 0
|
|
386
|
+
};
|
|
387
|
+
const mediaFiles = createBoardMediaFiles(options.spaceId, tempDir, options.signal);
|
|
388
|
+
const result = await runBoardExport({
|
|
389
|
+
...options,
|
|
390
|
+
document,
|
|
391
|
+
format: "png",
|
|
392
|
+
mediaFiles,
|
|
393
|
+
onFrame: async (frame, index) => {
|
|
394
|
+
if (count && (frame.width !== dimensions.width || frame.height !== dimensions.height)) throw new Error("Video frame dimensions changed. Use a fixed export region or a smaller camera viewport.");
|
|
395
|
+
await writeFile(join(tempDir, `${String(index + 1).padStart(6, "0")}.png`), frame.bytes, { signal: options.signal });
|
|
396
|
+
dimensions = {
|
|
397
|
+
width: frame.width,
|
|
398
|
+
height: frame.height
|
|
399
|
+
};
|
|
400
|
+
count++;
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
if (!result || !count) throw new Error("Nothing to export: the region contains no items.");
|
|
404
|
+
const start = times[0];
|
|
405
|
+
const sampled = boardMediaSpans(result.media.map((sample) => ({
|
|
406
|
+
...sample,
|
|
407
|
+
at: sample.at - start
|
|
408
|
+
})));
|
|
409
|
+
const mix = await boardAudioMix(sampled.map((span) => sampled.some((next) => next.id === span.id && next.start === span.end) ? span : {
|
|
410
|
+
...span,
|
|
411
|
+
end: span.end + step
|
|
412
|
+
}), mediaFiles, 1);
|
|
413
|
+
const duration = Math.max(.001, count / options.fps);
|
|
414
|
+
const args = [
|
|
415
|
+
"-y",
|
|
416
|
+
"-f",
|
|
417
|
+
"image2",
|
|
418
|
+
"-framerate",
|
|
419
|
+
String(options.fps),
|
|
420
|
+
"-i",
|
|
421
|
+
join(tempDir, "%06d.png"),
|
|
422
|
+
...mix?.inputs ?? []
|
|
423
|
+
];
|
|
424
|
+
if (mix) args.push("-filter_complex", mix.filter, "-map", "0:v:0", "-map", "[aout]");
|
|
425
|
+
else args.push("-map", "0:v:0");
|
|
426
|
+
if (options.format === "mp4" && (dimensions.width % 2 || dimensions.height % 2)) args.push("-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2");
|
|
427
|
+
if (options.format === "mp4") args.push("-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-movflags", "+faststart", "-f", "mp4");
|
|
428
|
+
else args.push("-c:v", "libvpx-vp9", "-crf", "32", "-b:v", "0", "-c:a", "libopus", "-f", "webm");
|
|
429
|
+
const encoded = join(tempDir, `video.${options.format}`);
|
|
430
|
+
args.push("-t", duration.toFixed(3), encoded);
|
|
431
|
+
debugExport("%j", {
|
|
432
|
+
stage: "encode",
|
|
433
|
+
width: dimensions.width,
|
|
434
|
+
height: dimensions.height,
|
|
435
|
+
frames: count,
|
|
436
|
+
memory: process.memoryUsage()
|
|
437
|
+
});
|
|
438
|
+
try {
|
|
439
|
+
await execFile$1("ffmpeg", args, {
|
|
440
|
+
encoding: "utf8",
|
|
441
|
+
maxBuffer: 2097152,
|
|
442
|
+
signal: options.signal
|
|
443
|
+
});
|
|
444
|
+
} catch (error) {
|
|
445
|
+
const cause = error;
|
|
446
|
+
if (cause.code === "ENOENT") throw new Error("Video export needs ffmpeg. Install ffmpeg and try again.");
|
|
447
|
+
throw new Error(`ffmpeg could not encode the video: ${(cause.stderr ?? cause.message ?? "unknown error").trim().split("\n").slice(-6).join("\n")}`);
|
|
448
|
+
}
|
|
449
|
+
options.signal?.throwIfAborted();
|
|
450
|
+
const staged = `${options.output}.${randomUUID()}.tmp`;
|
|
451
|
+
try {
|
|
452
|
+
await copyFile(encoded, staged, constants$1.COPYFILE_EXCL);
|
|
453
|
+
options.signal?.throwIfAborted();
|
|
454
|
+
if (options.force) await rename(staged, options.output);
|
|
455
|
+
else await link(staged, options.output);
|
|
456
|
+
} finally {
|
|
457
|
+
await unlink(staged).catch(() => void 0);
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
...dimensions,
|
|
461
|
+
frames: count,
|
|
462
|
+
warnings: result.warnings
|
|
463
|
+
};
|
|
464
|
+
} finally {
|
|
465
|
+
await rm(tempDir, {
|
|
466
|
+
recursive: true,
|
|
467
|
+
force: true
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async function runBoardExport(options) {
|
|
472
|
+
options.signal?.throwIfAborted();
|
|
473
|
+
const document = options.document ?? await settleBoardDocument(options.spaceId, (await loadBoardDocument(options.spaceId, options.target)).document);
|
|
474
|
+
const inputs = options.inputs ? parseBoardScriptInputs(options.inputs) : void 0;
|
|
475
|
+
if (options.animation && !document.animations[options.animation]) throw new Error(`Animation ${options.animation} does not exist.`);
|
|
476
|
+
const times = options.times?.length ? options.times : [null];
|
|
477
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
478
|
+
const imageMemoryBytes = (options.imageMemoryMiB ?? 256) * 1024 ** 2;
|
|
479
|
+
if (!Number.isSafeInteger(imageMemoryBytes) || imageMemoryBytes <= 0) throw new Error("Image memory budget must be a positive integer.");
|
|
480
|
+
const nodeRenderer = await createNodeBoardRenderer({ fonts: resolveBundledFonts() });
|
|
481
|
+
const images = createBoardExportImageBudget(nodeRenderer, imageMemoryBytes);
|
|
482
|
+
const renderer = {
|
|
483
|
+
...nodeRenderer,
|
|
484
|
+
decodeImage: images.decodeImage
|
|
485
|
+
};
|
|
486
|
+
const STAGES = {
|
|
487
|
+
prepare: "running the scripts",
|
|
488
|
+
gpu: "drawing in the browser",
|
|
489
|
+
images: "loading images",
|
|
490
|
+
render: "drawing"
|
|
491
|
+
};
|
|
492
|
+
let doing = "preparing";
|
|
493
|
+
const trace = (stage, completed, dimensions) => {
|
|
494
|
+
doing = STAGES[stage] ?? doing;
|
|
495
|
+
if (!debugExport.enabled || completed % 30 !== 0) return;
|
|
496
|
+
debugExport("%j", {
|
|
497
|
+
stage,
|
|
498
|
+
completed,
|
|
499
|
+
total: times.length,
|
|
500
|
+
...dimensions ? {
|
|
501
|
+
width: dimensions.width,
|
|
502
|
+
height: dimensions.height
|
|
503
|
+
} : {},
|
|
504
|
+
imageBytes: images.usedBytes,
|
|
505
|
+
memory: process.memoryUsage(),
|
|
506
|
+
availableMemory: process.availableMemory(),
|
|
507
|
+
constrainedMemory: process.constrainedMemory()
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
let scriptHost = null;
|
|
511
|
+
let gpu = null;
|
|
512
|
+
const textureCache = {
|
|
513
|
+
textures: /* @__PURE__ */ new Map(),
|
|
514
|
+
edges: /* @__PURE__ */ new Map(),
|
|
515
|
+
missed: /* @__PURE__ */ new Map()
|
|
516
|
+
};
|
|
517
|
+
const frameTextures = /* @__PURE__ */ new Map();
|
|
518
|
+
let mediaDir = null;
|
|
519
|
+
let backgroundTexture;
|
|
520
|
+
try {
|
|
521
|
+
const theme = boardRenderTheme(options.theme);
|
|
522
|
+
const sampler = createBoardRenderSampler(document, options.animation ?? null, theme);
|
|
523
|
+
const documentAt = (time) => time === null ? document : sampler.at(time).document;
|
|
524
|
+
const history = options.animation !== void 0 && boardAnimatesScriptParams(document);
|
|
525
|
+
const plan = planBoardExport({
|
|
526
|
+
scene: buildBoardScene(documentAt(times[0] ?? null)),
|
|
527
|
+
region: options.region,
|
|
528
|
+
scale: options.scale,
|
|
529
|
+
...options.padding === void 0 ? {} : { padding: options.padding }
|
|
530
|
+
});
|
|
531
|
+
if (!plan) return null;
|
|
532
|
+
const region = times.length > 1 && !options.camera ? {
|
|
533
|
+
kind: "rect",
|
|
534
|
+
rect: plan.world
|
|
535
|
+
} : options.region;
|
|
536
|
+
const firstTime = times[0] ?? null;
|
|
537
|
+
const first = prepareBoardExport(document, {
|
|
538
|
+
sampler,
|
|
539
|
+
region,
|
|
540
|
+
camera: options.camera,
|
|
541
|
+
scale: options.scale,
|
|
542
|
+
padding: times.length > 1 ? 0 : options.padding,
|
|
543
|
+
...firstTime === null ? {} : { at: {
|
|
544
|
+
animation: options.animation,
|
|
545
|
+
time: firstTime
|
|
546
|
+
} }
|
|
547
|
+
});
|
|
548
|
+
if (!first) return null;
|
|
549
|
+
options.onPlan?.({
|
|
550
|
+
width: first.plan.width,
|
|
551
|
+
height: first.plan.height,
|
|
552
|
+
frames: times.length
|
|
553
|
+
});
|
|
554
|
+
trace("plan", 0, first.plan);
|
|
555
|
+
const warnings = [];
|
|
556
|
+
const textures = textureCache.textures;
|
|
557
|
+
let omittedKeys = /* @__PURE__ */ new Set();
|
|
558
|
+
const backgroundSource = document.board.background.image && parseBoardMediaSource(document.board.background.image.src);
|
|
559
|
+
if (options.withImages && options.background === "paper" && backgroundSource) try {
|
|
560
|
+
const { bytes, mimeType } = backgroundSource.kind === "url" ? await downloadPublicImage(backgroundSource.value) : await readSpaceFileBytes(createClient(), options.spaceId, backgroundSource.value);
|
|
561
|
+
backgroundTexture = await renderer.decodeImage(bytes, mimeType);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
if (error instanceof BoardExportResourceError) throw error;
|
|
564
|
+
warnings.push("The board background image could not be loaded; the fallback color was exported.");
|
|
565
|
+
}
|
|
566
|
+
if (!options.scripts && options.renderer !== "gpu" && hasBoardScripts(document)) scriptHost = createNodeBoardScriptHost(renderer, {
|
|
567
|
+
concurrency: 2,
|
|
568
|
+
readModule: async (src) => {
|
|
569
|
+
const { bytes } = await readSpaceFileBytes(createClient(), options.spaceId, src);
|
|
570
|
+
return new TextDecoder().decode(bytes);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
const assetKey = (item) => {
|
|
574
|
+
const key = boardExportAssetKey(item);
|
|
575
|
+
return key && omittedKeys.has(key) ? null : key;
|
|
576
|
+
};
|
|
577
|
+
const frames = [];
|
|
578
|
+
const media = [];
|
|
579
|
+
const fps = times.length > 1 && times[0] !== null && times[1] !== null ? 1e3 / (times[1] - times[0]) : 30;
|
|
580
|
+
const lastMedia = /* @__PURE__ */ new Map();
|
|
581
|
+
const framePictures = /* @__PURE__ */ new Map();
|
|
582
|
+
let videoFrames = null;
|
|
583
|
+
const frameOf = async (state, rate, edge) => {
|
|
584
|
+
if (!videoFrames) {
|
|
585
|
+
mediaDir = await mkdtemp(join(tmpdir(), "cohub-board-media-"));
|
|
586
|
+
videoFrames = createBoardVideoFrames(options.mediaFiles ?? createBoardMediaFiles(options.spaceId, mediaDir, options.signal), mediaDir, {
|
|
587
|
+
fps,
|
|
588
|
+
signal: options.signal
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
return videoFrames.frame(state, rate, edge);
|
|
592
|
+
};
|
|
593
|
+
const reported = /* @__PURE__ */ new Set();
|
|
594
|
+
const report = (text) => {
|
|
595
|
+
if (reported.has(text)) return;
|
|
596
|
+
reported.add(text);
|
|
597
|
+
warnings.push(text);
|
|
598
|
+
};
|
|
599
|
+
let completed = 0;
|
|
600
|
+
let decided = options.renderer === "canvas";
|
|
601
|
+
const emit = async (frame) => {
|
|
602
|
+
if (options.onFrame) await options.onFrame(frame, completed);
|
|
603
|
+
else frames.push(frame);
|
|
604
|
+
completed++;
|
|
605
|
+
options.onProgress?.(completed, times.length);
|
|
606
|
+
};
|
|
607
|
+
const launchGpu = async (browser) => {
|
|
608
|
+
doing = "starting the browser";
|
|
609
|
+
const exporter = await openBoardGpu(gpuResources(options.spaceId, document, (key) => framePictures.get(key)), {
|
|
610
|
+
browser,
|
|
611
|
+
signal: options.signal
|
|
612
|
+
});
|
|
613
|
+
try {
|
|
614
|
+
await exporter.init({
|
|
615
|
+
document,
|
|
616
|
+
animation: options.animation ?? null,
|
|
617
|
+
theme: options.theme,
|
|
618
|
+
...options.snapshots ? { snapshots: options.snapshots } : {},
|
|
619
|
+
...options.inputs ? { inputs: options.inputs } : {}
|
|
620
|
+
});
|
|
621
|
+
} catch (error) {
|
|
622
|
+
await exporter.close();
|
|
623
|
+
throw error;
|
|
624
|
+
}
|
|
625
|
+
scriptHost?.destroy();
|
|
626
|
+
scriptHost = null;
|
|
627
|
+
return exporter;
|
|
628
|
+
};
|
|
629
|
+
if (options.renderer === "gpu") {
|
|
630
|
+
const browser = findBoardGpuBrowser();
|
|
631
|
+
if (!browser) throw new Error("GPU export needs Chrome, Chromium or Edge. Install one, or set COHUB_CHROME to its path.");
|
|
632
|
+
gpu = await launchGpu(browser);
|
|
633
|
+
}
|
|
634
|
+
const renderFrame = async (time) => {
|
|
635
|
+
options.signal?.throwIfAborted();
|
|
636
|
+
const host = scriptHost;
|
|
637
|
+
host?.clearFrames();
|
|
638
|
+
const frameOptions = {
|
|
639
|
+
sampler,
|
|
640
|
+
camera: options.camera,
|
|
641
|
+
...time === null ? {} : { at: {
|
|
642
|
+
animation: options.animation,
|
|
643
|
+
time
|
|
644
|
+
} },
|
|
645
|
+
region,
|
|
646
|
+
scale: options.scale,
|
|
647
|
+
padding: times.length > 1 ? 0 : options.padding
|
|
648
|
+
};
|
|
649
|
+
const initial = prepareBoardExport(document, frameOptions);
|
|
650
|
+
if (!initial) return;
|
|
651
|
+
let prepared = initial;
|
|
652
|
+
trace("prepare", completed, initial.plan);
|
|
653
|
+
const prepareScripts = async (scripts, shaders) => {
|
|
654
|
+
await scripts.prepare(initial.scene.items, [time ?? 0], initial.plan.scale, initial.document.board, {
|
|
655
|
+
shaders,
|
|
656
|
+
view: boardExportView(initial.plan),
|
|
657
|
+
...inputs ? { inputs } : {},
|
|
658
|
+
...history ? { history: (at) => documentAt(at) } : {}
|
|
659
|
+
});
|
|
660
|
+
for (const [id, message] of scripts.emitFailures) report(`${id}: ${message}`);
|
|
661
|
+
for (const id of [...Object.keys(initial.document.board.scripts ?? {}), ...initial.scene.items.map((item) => item.id)]) {
|
|
662
|
+
const error = scripts.error(id);
|
|
663
|
+
if (error) throw new Error(`${initial.document.board.scripts?.[id]?.src ?? initial.scene.get(id)?.script?.src ?? id}: ${error}`);
|
|
664
|
+
}
|
|
665
|
+
return prepareBoardExport(document, {
|
|
666
|
+
...frameOptions,
|
|
667
|
+
scripts
|
|
668
|
+
});
|
|
669
|
+
};
|
|
670
|
+
if (host && !gpu) {
|
|
671
|
+
const scripted = await prepareScripts(host, !decided);
|
|
672
|
+
if (!scripted) return;
|
|
673
|
+
prepared = scripted;
|
|
674
|
+
}
|
|
675
|
+
if (!decided) {
|
|
676
|
+
decided = true;
|
|
677
|
+
const shaded = (host?.shaders?.(prepared.document, time ?? 0) ?? []).map((owner) => owner.id);
|
|
678
|
+
const browser = shaded.length ? findBoardGpuBrowser() : null;
|
|
679
|
+
if (browser) gpu = await launchGpu(browser);
|
|
680
|
+
else if (host && shaded.length) {
|
|
681
|
+
report(`Shaders in ${shaded.join(", ")} need Chrome, Chromium or Edge; install one or set COHUB_CHROME to draw them.`);
|
|
682
|
+
host.clearFrames();
|
|
683
|
+
const scripted = await prepareScripts(host, false);
|
|
684
|
+
if (!scripted) return;
|
|
685
|
+
prepared = scripted;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
const timed = boardTimedMedia(prepared.scene);
|
|
689
|
+
media.push({
|
|
690
|
+
at: time ?? 0,
|
|
691
|
+
media: timed
|
|
692
|
+
});
|
|
693
|
+
const frameKeys = {};
|
|
694
|
+
for (const texture of frameTextures.values()) texture.destroy(true);
|
|
695
|
+
frameTextures.clear();
|
|
696
|
+
framePictures.clear();
|
|
697
|
+
if (options.withImages) {
|
|
698
|
+
const planned = new Set(prepared.plan.items.map((item) => item.id));
|
|
699
|
+
const loops = time === null ? [] : boardAutoplayLoops(prepared.scene, time);
|
|
700
|
+
for (const state of [...timed, ...loops]) {
|
|
701
|
+
const item = prepared.scene.get(state.id);
|
|
702
|
+
const base = item && state.kind === "video" && state.shown && planned.has(state.id) ? boardExportAssetKey(item) : null;
|
|
703
|
+
if (!item || !base) continue;
|
|
704
|
+
const before = lastMedia.get(state.id);
|
|
705
|
+
if (time !== null) lastMedia.set(state.id, {
|
|
706
|
+
at: time,
|
|
707
|
+
time: state.time
|
|
708
|
+
});
|
|
709
|
+
const rate = times.length === 1 ? 0 : before && time !== null ? boardMediaRate(before, {
|
|
710
|
+
at: time,
|
|
711
|
+
time: state.time
|
|
712
|
+
}) : 1;
|
|
713
|
+
const edge = Math.min(4096, textureEdge(item, prepared.plan.scale));
|
|
714
|
+
const bytes = await frameOf(state, rate, edge).catch((error) => {
|
|
715
|
+
report(`Frames of ${state.src} could not be decoded; its cover was drawn instead. ${error instanceof Error ? error.message : ""}`.trim());
|
|
716
|
+
return null;
|
|
717
|
+
});
|
|
718
|
+
if (!bytes?.length) continue;
|
|
719
|
+
const key = `${base}@${Math.round(state.time)}`;
|
|
720
|
+
frameKeys[state.id] = key;
|
|
721
|
+
framePictures.set(key, bytes);
|
|
722
|
+
if (!gpu) frameTextures.set(key, await nodeRenderer.decodeImage(bytes, "image/jpeg"));
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (gpu) {
|
|
726
|
+
trace("gpu", completed, prepared.plan);
|
|
727
|
+
const result = await gpu.render({
|
|
728
|
+
time,
|
|
729
|
+
region,
|
|
730
|
+
...options.camera ? { camera: options.camera } : {},
|
|
731
|
+
scale: options.scale,
|
|
732
|
+
...times.length > 1 || options.padding === void 0 ? {} : { padding: options.padding },
|
|
733
|
+
background: options.background,
|
|
734
|
+
format: options.format,
|
|
735
|
+
...options.quality === void 0 ? {} : { quality: options.quality },
|
|
736
|
+
withImages: options.withImages,
|
|
737
|
+
imageMemory: imageMemoryBytes,
|
|
738
|
+
assetKeys: frameKeys
|
|
739
|
+
});
|
|
740
|
+
for (const warning of result.warnings) report(options.withImages && warning.kind === "images-missing" ? describeBoardExportWarning(warning) : describeWarning(warning));
|
|
741
|
+
await emit({
|
|
742
|
+
time,
|
|
743
|
+
bytes: result.bytes,
|
|
744
|
+
width: result.width,
|
|
745
|
+
height: result.height,
|
|
746
|
+
scale: result.scale,
|
|
747
|
+
itemCount: result.itemCount,
|
|
748
|
+
format: options.format
|
|
749
|
+
});
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
trace("images", completed, prepared.plan);
|
|
753
|
+
if (options.withImages) {
|
|
754
|
+
const visible = prepared.plan.items.filter((item) => prepared.scene.opacity(item.id) > 0 && !frameKeys[item.id]);
|
|
755
|
+
const loaded = await loadBoardTextures(images, options.spaceId, visible, {
|
|
756
|
+
scale: prepared.plan.scale,
|
|
757
|
+
maxBytes: imageMemoryBytes,
|
|
758
|
+
cache: textureCache
|
|
759
|
+
});
|
|
760
|
+
omittedKeys = new Set(loaded.omitted);
|
|
761
|
+
const sources = (keys) => keys.slice(0, 3).map((key) => boardAssetKeySource(key)?.value ?? key).join(", ");
|
|
762
|
+
const plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
763
|
+
const assetWarnings = [
|
|
764
|
+
loaded.failed.length ? `${plural(loaded.failed.length, "preview")} could not be loaded: ${sources(loaded.failed)}` : null,
|
|
765
|
+
loaded.unavailable.length ? `${plural(loaded.unavailable.length, "video")} drawn without a cover; Node exports take covers from Cohub-hosted media only.` : null,
|
|
766
|
+
loaded.omitted.length ? `${plural(loaded.omitted.length, "preview")} drawn as placeholders to stay within the ${imageMemoryBytes / 1024 ** 2} MiB image budget; raise --image-memory to include them.` : null
|
|
767
|
+
];
|
|
768
|
+
for (const warning of assetWarnings) if (warning && !reported.has(warning)) {
|
|
769
|
+
warnings.push(warning);
|
|
770
|
+
reported.add(warning);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
trace("render", completed, prepared.plan);
|
|
774
|
+
const result = exportBoardImageBytes(renderer, document, {
|
|
775
|
+
...frameOptions,
|
|
776
|
+
...theme,
|
|
777
|
+
background: options.background,
|
|
778
|
+
textures: frameTextures.size ? new Map([...textures, ...frameTextures]) : textures,
|
|
779
|
+
scripts: options.scripts ?? scriptHost ?? void 0,
|
|
780
|
+
backgroundTexture,
|
|
781
|
+
assetKey: (item) => frameKeys[item.id] ?? assetKey(item),
|
|
782
|
+
format: options.format,
|
|
783
|
+
quality: options.quality
|
|
784
|
+
});
|
|
785
|
+
if (!result) return;
|
|
786
|
+
for (const warning of result.warnings) {
|
|
787
|
+
if (warning.kind === "images-missing" && options.withImages) continue;
|
|
788
|
+
if (warning.kind === "shaders-unsupported" && options.renderer !== "canvas") continue;
|
|
789
|
+
report(describeWarning(warning));
|
|
790
|
+
}
|
|
791
|
+
await emit({
|
|
792
|
+
time,
|
|
793
|
+
bytes: result.bytes,
|
|
794
|
+
width: result.plan.width,
|
|
795
|
+
height: result.plan.height,
|
|
796
|
+
scale: result.plan.scale,
|
|
797
|
+
itemCount: result.plan.items.length,
|
|
798
|
+
format: result.format
|
|
799
|
+
});
|
|
800
|
+
trace("rendered", completed, result.plan);
|
|
801
|
+
};
|
|
802
|
+
for (const time of times) {
|
|
803
|
+
let timer;
|
|
804
|
+
const stalled = new Promise((_resolve, reject) => {
|
|
805
|
+
timer = setTimeout(() => reject(new Error(describeStall(time, timeoutMs, doing, scriptHost?.status() ?? null))), timeoutMs);
|
|
806
|
+
});
|
|
807
|
+
try {
|
|
808
|
+
await Promise.race([renderFrame(time), stalled]);
|
|
809
|
+
} finally {
|
|
810
|
+
clearTimeout(timer);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return completed ? {
|
|
814
|
+
frames,
|
|
815
|
+
warnings,
|
|
816
|
+
media
|
|
817
|
+
} : null;
|
|
818
|
+
} finally {
|
|
819
|
+
await gpu?.close();
|
|
820
|
+
scriptHost?.destroy();
|
|
821
|
+
for (const texture of textureCache.textures.values()) texture.destroy(true);
|
|
822
|
+
backgroundTexture?.destroy(true);
|
|
823
|
+
for (const texture of frameTextures.values()) texture.destroy(true);
|
|
824
|
+
if (mediaDir) await rm(mediaDir, {
|
|
825
|
+
recursive: true,
|
|
826
|
+
force: true
|
|
827
|
+
});
|
|
828
|
+
renderer.destroy();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function gpuResources(spaceId, document, framePicture = () => void 0) {
|
|
832
|
+
const client = createClient();
|
|
833
|
+
const scene = buildBoardScene(document);
|
|
834
|
+
return {
|
|
835
|
+
fonts: resolveBundledFonts().flatMap(({ path, family }) => family ? [{
|
|
836
|
+
path,
|
|
837
|
+
family
|
|
838
|
+
}] : []),
|
|
839
|
+
readModule: async (path) => new TextDecoder().decode((await readSpaceFileBytes(client, spaceId, path)).bytes),
|
|
840
|
+
async readPicture(request) {
|
|
841
|
+
if ("background" in request) {
|
|
842
|
+
const source = document.board.background.image && parseBoardMediaSource(document.board.background.image.src);
|
|
843
|
+
if (!source) return null;
|
|
844
|
+
return source.kind === "url" ? downloadPublicImage(source.value) : readSpaceFileBytes(client, spaceId, source.value);
|
|
845
|
+
}
|
|
846
|
+
const frame = framePicture(request.key);
|
|
847
|
+
if (frame) return {
|
|
848
|
+
bytes: frame,
|
|
849
|
+
mimeType: "image/jpeg"
|
|
850
|
+
};
|
|
851
|
+
const source = boardAssetKeySource(request.key);
|
|
852
|
+
const item = scene.items.find((entry) => boardAssetKey(entry) === request.key);
|
|
853
|
+
return source && item ? fetchBoardPicture(client, spaceId, source, item, request.edge) : null;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
const BOARD_EXPORT_FRAME_TIMEOUT_MS = 12e4;
|
|
858
|
+
function describeStall(time, timeoutMs, doing, lanes) {
|
|
859
|
+
const at = time === null ? "The export" : `The frame at ${time} ms`;
|
|
860
|
+
const busy = lanes ? describeBoardScriptLanes(lanes) : [];
|
|
861
|
+
const hint = doing === "drawing in the browser" ? " The browser runs the scripts and shaders there; a shader may be too heavy." : "";
|
|
862
|
+
return [`${at} did not finish in ${timeoutMs / 1e3} s, while ${doing}.${hint}`, ...busy.map((line) => ` ${line}`)].join("\n");
|
|
863
|
+
}
|
|
864
|
+
function describeWarning(warning) {
|
|
865
|
+
if (warning.kind === "scale-clamped") return `Scale reduced from ${warning.requested}x to ${Number(warning.applied).toFixed(2)}x to stay within the size limit.`;
|
|
866
|
+
if (warning.kind === "images-missing") {
|
|
867
|
+
const keys = warning.keys;
|
|
868
|
+
return `${keys.length} preview${keys.length === 1 ? "" : "s"} drawn as placeholders; omit --no-images to fetch them.`;
|
|
869
|
+
}
|
|
870
|
+
if (warning.kind === "many-items") return `${warning.count} items exported.`;
|
|
871
|
+
return describeBoardExportWarning(warning);
|
|
872
|
+
}
|
|
873
|
+
//#endregion
|
|
874
|
+
export { readSpaceFileBytes as a, runBoardVideoExport as c, loadBoardTextures as i, boardExportAssetKey as n, resolveBundledFonts as o, gpuResources as r, runBoardExport as s, BOARD_EXPORT_FRAME_TIMEOUT_MS as t };
|