@neta-art/cohub-cli 10.24.0 → 10.25.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/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/binary-pins.js +5 -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 +311 -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 +2513 -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 -121
- 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 -141
- 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 -2170
- 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 -10
- package/dist/session-status.js +0 -25
- 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
package/dist/commands/boards.js
DELETED
|
@@ -1,836 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { mkdir } from "node:fs/promises";
|
|
4
|
-
import { dirname } from "node:path";
|
|
5
|
-
import { BOARD_PRESET_NAMES, BOARD_SCHEMA_TARGETS, BOARD_SCRIPT_API, BOARD_THEME_IDS, boardJsonSchema, boardPresetTracks, boardSchemaOverview, isBoardPresetName, listBoardPresets, } from "@neta-art/cohub/board";
|
|
6
|
-
import { BOARD_CREATE_INPUT_MAX_BYTES, BOARD_TRANSACTION_INPUT_MAX_BYTES, parseBoardJsonObject, readBoardJsonObject, writeBoardOutput, } from "../board-command-support.js";
|
|
7
|
-
import { BOARD_EXPORT_IMAGE_MEMORY_MIB, BOARD_EXPORT_RENDERERS } from "../board-export-resources.js";
|
|
8
|
-
import { settleBoardPatch } from "../board-media.js";
|
|
9
|
-
import { formatBoardTime, parseBoardTime, parseBoardTimes } from "../board-time.js";
|
|
10
|
-
import { createClient, createRealtimeClient } from "../client.js";
|
|
11
|
-
import { error, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
|
|
12
|
-
import { resolveSpace } from "../space.js";
|
|
13
|
-
import { registerBoardExampleCommands } from "./boards/examples.js";
|
|
14
|
-
import { registerBoardAuthoringCommands } from "./boards/authoring.js";
|
|
15
|
-
export const parseJsonObject = parseBoardJsonObject;
|
|
16
|
-
export function boardSchemaField(schema, path) {
|
|
17
|
-
let field = schema;
|
|
18
|
-
for (const part of path.split(".")) {
|
|
19
|
-
const properties = field?.properties;
|
|
20
|
-
if (!part || !properties || !Object.hasOwn(properties, part))
|
|
21
|
-
throw new Error(`Unknown schema field ${path}.`);
|
|
22
|
-
field = properties[part];
|
|
23
|
-
}
|
|
24
|
-
return field;
|
|
25
|
-
}
|
|
26
|
-
function withJson(command) {
|
|
27
|
-
return command.option("--json", "Output as JSON");
|
|
28
|
-
}
|
|
29
|
-
function parseNumber(value, name, options = {}) {
|
|
30
|
-
if (!value.trim())
|
|
31
|
-
throw new Error(`${name} must be a finite number`);
|
|
32
|
-
const parsed = Number(value);
|
|
33
|
-
if (!Number.isFinite(parsed))
|
|
34
|
-
throw new Error(`${name} must be a finite number`);
|
|
35
|
-
if (options.integer && !Number.isSafeInteger(parsed))
|
|
36
|
-
throw new Error(`${name} must be an integer`);
|
|
37
|
-
if (options.min !== undefined && parsed < options.min)
|
|
38
|
-
throw new Error(`${name} must be at least ${options.min}`);
|
|
39
|
-
if (options.max !== undefined && parsed > options.max)
|
|
40
|
-
throw new Error(`${name} must be at most ${options.max}`);
|
|
41
|
-
return parsed;
|
|
42
|
-
}
|
|
43
|
-
export function parseRect(value, name = "--rect") {
|
|
44
|
-
const parts = value.split(",").map((part) => part.trim());
|
|
45
|
-
if (parts.length !== 4)
|
|
46
|
-
throw new Error(`${name} must be x,y,width,height`);
|
|
47
|
-
const [x, y, width, height] = parts.map((part, index) => parseNumber(part, `${name} ${["x", "y", "width", "height"][index]}`));
|
|
48
|
-
if (width <= 0 || height <= 0)
|
|
49
|
-
throw new Error(`${name} width and height must be greater than zero`);
|
|
50
|
-
return { x, y, width, height };
|
|
51
|
-
}
|
|
52
|
-
function list(value) {
|
|
53
|
-
const entries = value?.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
54
|
-
return entries?.length ? entries : undefined;
|
|
55
|
-
}
|
|
56
|
-
async function boardClient(boards, target, spaceId) {
|
|
57
|
-
spaceId ??= await resolveSpace(boards);
|
|
58
|
-
return createClient().space(spaceId).boards.open(target);
|
|
59
|
-
}
|
|
60
|
-
/** A patch from an inline argument, a file, or stdin (`-`). */
|
|
61
|
-
async function readPatch(inline, input, maxBytes) {
|
|
62
|
-
if (inline !== undefined && input !== undefined)
|
|
63
|
-
throw new Error("Pass the patch inline or with --input, not both.");
|
|
64
|
-
if (inline !== undefined)
|
|
65
|
-
return parseBoardJsonObject(inline, "patch");
|
|
66
|
-
if (input !== undefined)
|
|
67
|
-
return (await readBoardJsonObject(input, maxBytes));
|
|
68
|
-
throw new Error("Pass a patch inline or with --input <file|->.");
|
|
69
|
-
}
|
|
70
|
-
function describeChanges(result) {
|
|
71
|
-
const parts = [
|
|
72
|
-
result.changed.board ? "board" : null,
|
|
73
|
-
result.changed.items.length ? `${result.changed.items.length} item${result.changed.items.length === 1 ? "" : "s"}` : null,
|
|
74
|
-
result.changed.animations.length ? `${result.changed.animations.length} animation${result.changed.animations.length === 1 ? "" : "s"}` : null,
|
|
75
|
-
].filter(Boolean);
|
|
76
|
-
return parts.length ? parts.join(", ") : "nothing";
|
|
77
|
-
}
|
|
78
|
-
function showApplied(result) {
|
|
79
|
-
if (result.status === "validated")
|
|
80
|
-
ok(`Valid: would change ${describeChanges(result)}`);
|
|
81
|
-
else if (result.status === "unchanged")
|
|
82
|
-
ok(`Unchanged at version ${result.version}`);
|
|
83
|
-
else
|
|
84
|
-
ok(`Applied version ${result.version}${result.replayed ? " (replayed)" : ""}: ${describeChanges(result)}`);
|
|
85
|
-
for (const diagnostic of result.diagnostics)
|
|
86
|
-
console.log(` ! ${diagnostic.path}: ${diagnostic.message}`);
|
|
87
|
-
}
|
|
88
|
-
function showPlayback(playback) {
|
|
89
|
-
if (!playback) {
|
|
90
|
-
ok("Stopped");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
table([{ ...playback, position: formatBoardTime(Math.round(playback.position)) }], [
|
|
94
|
-
{ key: "animationId", label: "Animation" },
|
|
95
|
-
{ key: "status", label: "Status" },
|
|
96
|
-
{ key: "position", label: "Position" },
|
|
97
|
-
{ key: "timeScale", label: "Speed" },
|
|
98
|
-
]);
|
|
99
|
-
}
|
|
100
|
-
const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
101
|
-
async function runExportTask(boards, options) {
|
|
102
|
-
try {
|
|
103
|
-
const command = ["cohub", ...process.argv.slice(2).filter((arg) => arg !== "--async")].map(shellQuote).join(" ");
|
|
104
|
-
const { taskRunId } = await createClient().space(await resolveSpace(boards)).runCommand({ command });
|
|
105
|
-
if (jsonRequested(options))
|
|
106
|
-
return outJson({ taskRunId, command });
|
|
107
|
-
ok(`Exporting as Task ${taskRunId}`);
|
|
108
|
-
console.log(` Follow it with: cohub tasks get ${taskRunId}`);
|
|
109
|
-
}
|
|
110
|
-
catch (cause) {
|
|
111
|
-
handleHttp(cause);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function parseSize(value) {
|
|
115
|
-
const size = /^(\d+)x(\d+)$/.exec(value);
|
|
116
|
-
if (!size?.[1] || !size[2])
|
|
117
|
-
throw new Error("--size must be widthxheight, e.g. 1600x900.");
|
|
118
|
-
return { width: parseNumber(size[1], "width", { min: 1, max: 8192 }), height: parseNumber(size[2], "height", { min: 1, max: 8192 }) };
|
|
119
|
-
}
|
|
120
|
-
/** One region flag at most: being told to pick beats guessing which one wins. */
|
|
121
|
-
function parseExportRegion(options) {
|
|
122
|
-
const chosen = [options.camera && "--camera", options.frame && "--frame", options.items && "--items", options.rect && "--rect"].filter(Boolean);
|
|
123
|
-
if (chosen.length > 1)
|
|
124
|
-
throw new Error(`Pick one region: ${chosen.join(", ")} cannot be combined.`);
|
|
125
|
-
if (options.frame)
|
|
126
|
-
return { kind: "frame", id: options.frame };
|
|
127
|
-
if (options.items) {
|
|
128
|
-
const ids = list(options.items);
|
|
129
|
-
if (!ids)
|
|
130
|
-
throw new Error("--items needs at least one item id.");
|
|
131
|
-
return { kind: "items", ids };
|
|
132
|
-
}
|
|
133
|
-
if (options.rect)
|
|
134
|
-
return { kind: "rect", rect: parseRect(options.rect) };
|
|
135
|
-
return { kind: "all" };
|
|
136
|
-
}
|
|
137
|
-
const BOARD_EXPORT_FORMATS = ["png", "jpeg", "webp"];
|
|
138
|
-
const BOARD_VIDEO_FORMATS = ["mp4", "webm"];
|
|
139
|
-
function videoFormatFromPath(path) {
|
|
140
|
-
const lower = path.toLowerCase();
|
|
141
|
-
return lower.endsWith(".webm") ? "webm" : lower.endsWith(".mp4") ? "mp4" : null;
|
|
142
|
-
}
|
|
143
|
-
function formatFromPath(path) {
|
|
144
|
-
const lower = path.toLowerCase();
|
|
145
|
-
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg"))
|
|
146
|
-
return "jpeg";
|
|
147
|
-
if (lower.endsWith(".webp"))
|
|
148
|
-
return "webp";
|
|
149
|
-
return "png";
|
|
150
|
-
}
|
|
151
|
-
function parseExportFormat(options, outPath) {
|
|
152
|
-
if (!options.format)
|
|
153
|
-
return formatFromPath(outPath);
|
|
154
|
-
const format = options.format.toLowerCase();
|
|
155
|
-
if (!BOARD_EXPORT_FORMATS.includes(format))
|
|
156
|
-
throw new Error(`--format must be one of ${BOARD_EXPORT_FORMATS.join(", ")}.`);
|
|
157
|
-
return format;
|
|
158
|
-
}
|
|
159
|
-
function parseChoice(value, name, choices) {
|
|
160
|
-
const chosen = (value ?? choices[0]);
|
|
161
|
-
if (!choices.includes(chosen))
|
|
162
|
-
throw new Error(`${name} must be ${choices.join(" or ")}.`);
|
|
163
|
-
return chosen;
|
|
164
|
-
}
|
|
165
|
-
/** `frames/%04d.png` → `frames/0012.png`; a sequence needs a `%d` placeholder. */
|
|
166
|
-
export function framePath(pattern, index) {
|
|
167
|
-
return pattern.replace(/%(0?)(\d*)d/, (_match, zero, width) => String(index).padStart(Number(width || 0), zero ? "0" : " "));
|
|
168
|
-
}
|
|
169
|
-
function registerExportCommand(boards) {
|
|
170
|
-
withJson(boards.command("export <board>")
|
|
171
|
-
.description("Render a Board to an image, or an animation to a frame sequence")
|
|
172
|
-
.requiredOption("-o, --out <file>", "Output file; the extension picks the format. Sequences need %d, e.g. frames/%04d.png")
|
|
173
|
-
.option("--at <time>", "A moment, comma-separated moments, or start:end:step")
|
|
174
|
-
.option("--camera", "Follow the animation camera")
|
|
175
|
-
.option("--size <widthxheight>", "Camera output in pixels; frames keep their own size", "1600x900")
|
|
176
|
-
.option("--animation <id>", "Animation the --at times refer to")
|
|
177
|
-
.option("--frame <item-id>", "Export one frame as a page")
|
|
178
|
-
.option("--items <ids>", "Comma-separated item ids")
|
|
179
|
-
.option("--rect <rect>", "World rect as x,y,width,height")
|
|
180
|
-
.option("--scale <factor>", "Output pixels per board unit", "2")
|
|
181
|
-
.option("--padding <units>", "Padding around the content in board units")
|
|
182
|
-
.option("--theme <name>", `Cohub theme: ${BOARD_THEME_IDS.join(", ")}`, "dark")
|
|
183
|
-
.option("--paper <mode>", "Output paper: paper or transparent", "paper")
|
|
184
|
-
.option("--format <format>", `Override the format (${BOARD_EXPORT_FORMATS.join(", ")}, ${BOARD_VIDEO_FORMATS.join(", ")})`)
|
|
185
|
-
.option("--quality <q>", "JPEG/WebP quality from 0 to 1", "0.92")
|
|
186
|
-
.option("--fps <rate>", "Video frame rate; defaults to the --at step")
|
|
187
|
-
.option("--image-memory <mib>", "Decoded image memory budget in MiB", String(BOARD_EXPORT_IMAGE_MEMORY_MIB))
|
|
188
|
-
.option("--no-images", "Draw placeholders instead of downloading images")
|
|
189
|
-
.option("--renderer <renderer>", "auto draws in Node and uses local Chrome for shaders; canvas or gpu forces one", "auto")
|
|
190
|
-
.option("--force", "Replace existing output files")
|
|
191
|
-
.option("--timeout <time>", "Fail a frame that takes longer, naming the scripts still running", "2m")
|
|
192
|
-
.option("--async", "Run as a Task in the Space's sandbox and return at once; paths are Space paths"))
|
|
193
|
-
.addHelpText("after", `
|
|
194
|
-
Shaders draw in a shared headless Chrome that stays up a few minutes between calls;
|
|
195
|
-
Boards without shaders never start it. Set COHUB_BOARD_GPU_DAEMON=0 to start one per call.
|
|
196
|
-
|
|
197
|
-
Examples:
|
|
198
|
-
cohub boards export plan.board -o plan.png
|
|
199
|
-
cohub boards export plan.board --animation intro --at 0:20s:40ms -o intro.mp4 --async
|
|
200
|
-
cohub boards export plan.board --frame s2 -o slide-2.png
|
|
201
|
-
cohub boards export plan.board --animation lecture --at 4.5s -o moment.png
|
|
202
|
-
cohub boards export plan.board --animation lecture --at 0:6s:40ms -o frames/%04d.png
|
|
203
|
-
|
|
204
|
-
Scripts see the exported area as their view (viewchange), and emit() between them is
|
|
205
|
-
delivered within the same moment, in document order. --frame draws the frame as a
|
|
206
|
-
page: its fill and shaders, without its outline and label.`)
|
|
207
|
-
.action(async (target, options) => {
|
|
208
|
-
if (options.async)
|
|
209
|
-
return runExportTask(boards, options);
|
|
210
|
-
const controller = new AbortController();
|
|
211
|
-
const cancel = () => controller.abort(new Error("Export cancelled."));
|
|
212
|
-
process.once("SIGINT", cancel);
|
|
213
|
-
try {
|
|
214
|
-
const out = options.out;
|
|
215
|
-
const times = options.at ? parseBoardTimes(options.at) : undefined;
|
|
216
|
-
let camera;
|
|
217
|
-
if (options.camera) {
|
|
218
|
-
if (!options.animation || !times)
|
|
219
|
-
throw new Error("--camera needs --animation and --at.");
|
|
220
|
-
camera = parseSize(options.size ?? "1600x900");
|
|
221
|
-
}
|
|
222
|
-
const progress = (completed, total) => {
|
|
223
|
-
if (!jsonRequested(options) && (completed === total || completed % 30 === 0))
|
|
224
|
-
process.stderr.write(`Rendered ${completed}/${total} frames\n`);
|
|
225
|
-
};
|
|
226
|
-
const imageMemoryMiB = parseNumber(options.imageMemory ?? String(BOARD_EXPORT_IMAGE_MEMORY_MIB), "--image-memory", { min: 1, max: 65536, integer: true });
|
|
227
|
-
const onPlan = ({ width, height, frames }) => {
|
|
228
|
-
if (!jsonRequested(options))
|
|
229
|
-
process.stderr.write(`Rendering ${width}x${height}, ${frames} frame(s)\n`);
|
|
230
|
-
};
|
|
231
|
-
const pathVideoFormat = videoFormatFromPath(out);
|
|
232
|
-
const requestedFormat = options.format?.toLowerCase();
|
|
233
|
-
if (requestedFormat && ![...BOARD_EXPORT_FORMATS, ...BOARD_VIDEO_FORMATS].includes(requestedFormat))
|
|
234
|
-
throw new Error(`--format must be one of ${[...BOARD_EXPORT_FORMATS, ...BOARD_VIDEO_FORMATS].join(", ")}.`);
|
|
235
|
-
const videoFormat = requestedFormat
|
|
236
|
-
? BOARD_VIDEO_FORMATS.includes(requestedFormat) ? requestedFormat : null
|
|
237
|
-
: pathVideoFormat;
|
|
238
|
-
const sequence = (times?.length ?? 0) > 1;
|
|
239
|
-
if (sequence && !videoFormat && !/%0?\d*d/.test(out))
|
|
240
|
-
throw new Error("A range needs %d in --out, e.g. frames/%04d.png.");
|
|
241
|
-
if (videoFormat) {
|
|
242
|
-
if (!times || times.length < 2)
|
|
243
|
-
throw new Error("Video export needs an --at range.");
|
|
244
|
-
const step = times[1] - times[0];
|
|
245
|
-
const fps = options.fps ? parseNumber(options.fps, "--fps", { min: 0.01, max: 240 }) : 1000 / step;
|
|
246
|
-
if (existsSync(out) && !options.force)
|
|
247
|
-
throw new Error(`${out} already exists; use --force to replace it.`);
|
|
248
|
-
await mkdir(dirname(out), { recursive: true });
|
|
249
|
-
const { runBoardVideoExport } = await import("../board-export.js");
|
|
250
|
-
const result = await runBoardVideoExport({
|
|
251
|
-
spaceId: await resolveSpace(boards),
|
|
252
|
-
target,
|
|
253
|
-
camera,
|
|
254
|
-
timeoutMs: parseBoardTime(options.timeout ?? "2m", "--timeout"),
|
|
255
|
-
onProgress: progress,
|
|
256
|
-
onPlan,
|
|
257
|
-
imageMemoryMiB,
|
|
258
|
-
signal: controller.signal,
|
|
259
|
-
force: options.force,
|
|
260
|
-
region: parseExportRegion(options),
|
|
261
|
-
times,
|
|
262
|
-
...(options.animation ? { animation: options.animation } : {}),
|
|
263
|
-
scale: parseNumber(options.scale ?? "2", "--scale", { min: 0.01, max: 16 }),
|
|
264
|
-
...(options.padding === undefined ? {} : { padding: parseNumber(options.padding, "--padding", { min: 0 }) }),
|
|
265
|
-
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
266
|
-
background: parseChoice(options.paper, "--paper", ["paper", "transparent"]),
|
|
267
|
-
format: videoFormat,
|
|
268
|
-
fps,
|
|
269
|
-
output: out,
|
|
270
|
-
quality: parseNumber(options.quality ?? "0.92", "--quality", { min: 0, max: 1 }),
|
|
271
|
-
withImages: options.images !== false,
|
|
272
|
-
renderer: parseChoice(options.renderer, "--renderer", BOARD_EXPORT_RENDERERS),
|
|
273
|
-
});
|
|
274
|
-
if (jsonRequested(options))
|
|
275
|
-
return outJson({ file: out, ...result });
|
|
276
|
-
ok(`Exported ${result.width}×${result.height} ${videoFormat.toUpperCase()} to ${out}`);
|
|
277
|
-
for (const warning of result.warnings)
|
|
278
|
-
console.log(` ! ${warning}`);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
const written = [];
|
|
282
|
-
for (let index = 0; index < (times?.length ?? 1); index++) {
|
|
283
|
-
const path = sequence ? framePath(out, index) : out;
|
|
284
|
-
if (!options.force && existsSync(path))
|
|
285
|
-
throw new Error(`${path} already exists; use --force to replace it.`);
|
|
286
|
-
}
|
|
287
|
-
const { runBoardExport } = await import("../board-export.js");
|
|
288
|
-
const result = await runBoardExport({
|
|
289
|
-
spaceId: await resolveSpace(boards),
|
|
290
|
-
target,
|
|
291
|
-
camera,
|
|
292
|
-
timeoutMs: parseBoardTime(options.timeout ?? "2m", "--timeout"),
|
|
293
|
-
onProgress: progress,
|
|
294
|
-
onPlan,
|
|
295
|
-
imageMemoryMiB,
|
|
296
|
-
signal: controller.signal,
|
|
297
|
-
onFrame: async (frame, index) => {
|
|
298
|
-
const path = sequence ? framePath(out, index) : out;
|
|
299
|
-
await mkdir(dirname(path), { recursive: true });
|
|
300
|
-
await writeBoardOutput(path, frame.bytes, Boolean(options.force));
|
|
301
|
-
written.push({ path, time: frame.time, width: frame.width, height: frame.height, bytes: frame.bytes.length });
|
|
302
|
-
},
|
|
303
|
-
region: parseExportRegion(options),
|
|
304
|
-
...(times ? { times } : {}),
|
|
305
|
-
...(options.animation ? { animation: options.animation } : {}),
|
|
306
|
-
scale: parseNumber(options.scale ?? "2", "--scale", { min: 0.01, max: 16 }),
|
|
307
|
-
...(options.padding === undefined ? {} : { padding: parseNumber(options.padding, "--padding", { min: 0 }) }),
|
|
308
|
-
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
309
|
-
background: parseChoice(options.paper, "--paper", ["paper", "transparent"]),
|
|
310
|
-
format: parseExportFormat(options, out),
|
|
311
|
-
quality: parseNumber(options.quality ?? "0.92", "--quality", { min: 0, max: 1 }),
|
|
312
|
-
withImages: options.images !== false,
|
|
313
|
-
renderer: parseChoice(options.renderer, "--renderer", BOARD_EXPORT_RENDERERS),
|
|
314
|
-
});
|
|
315
|
-
if (!result)
|
|
316
|
-
return error("Nothing to export: the region contains no items.");
|
|
317
|
-
if (jsonRequested(options))
|
|
318
|
-
return outJson({ files: written, warnings: result.warnings });
|
|
319
|
-
const first = written[0];
|
|
320
|
-
if (first) {
|
|
321
|
-
const what = sequence ? `${written.length} frames` : parseExportFormat(options, out).toUpperCase();
|
|
322
|
-
ok(`Exported ${first.width}×${first.height} ${what} to ${sequence ? dirname(out) || "." : out}`);
|
|
323
|
-
}
|
|
324
|
-
for (const warning of result.warnings)
|
|
325
|
-
console.log(` ! ${warning}`);
|
|
326
|
-
}
|
|
327
|
-
catch (cause) {
|
|
328
|
-
handleHttp(cause);
|
|
329
|
-
}
|
|
330
|
-
finally {
|
|
331
|
-
process.removeListener("SIGINT", cancel);
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
function registerSimulateCommand(boards) {
|
|
336
|
-
withJson(boards.command("simulate <board> [steps]")
|
|
337
|
-
.description("Run a Board's scripts locally through input steps; nothing is saved")
|
|
338
|
-
.option("-i, --input <file>", "Steps JSON; - for stdin")
|
|
339
|
-
.option("-o, --out <file>", "Also render the result, screen UI included; the extension picks the format")
|
|
340
|
-
.option("--follower", "Simulate an editor that does not write autonomous commits")
|
|
341
|
-
.option("--timeout <time>", "Give up after this long and report what is still running", "2m")
|
|
342
|
-
.option("--frame <item-id>", "Render one frame")
|
|
343
|
-
.option("--items <ids>", "Render comma-separated item ids")
|
|
344
|
-
.option("--rect <rect>", "Render a world rect as x,y,width,height")
|
|
345
|
-
.option("--scale <factor>", "Output pixels per board unit", "2")
|
|
346
|
-
.option("--theme <name>", `Cohub theme: ${BOARD_THEME_IDS.join(", ")}`, "dark")
|
|
347
|
-
.option("--no-images", "Draw placeholders instead of downloading images")
|
|
348
|
-
.option("--force", "Replace an existing output file"))
|
|
349
|
-
.addHelpText("after", `
|
|
350
|
-
Steps are {"steps": [...]}, points in board coordinates, run on a virtual clock:
|
|
351
|
-
{"wait": "500ms"} {"tool": "draw"} {"tap": [x, y]} {"drag": [[x, y], ...], "pointerType": "pen"}
|
|
352
|
-
{"pointer": "down", "at": [x, y]} {"key": "Enter"} {"select": ["id"]}
|
|
353
|
-
{"tool": "play"} acts like an App visitor: drags move unlocked items, empty space pans,
|
|
354
|
-
and script regions take every press.
|
|
355
|
-
|
|
356
|
-
Shaders are compiled with a local Chrome, Chromium or Edge when one is found, before
|
|
357
|
-
the steps run; their errors join the scripts' errors and stop the run.
|
|
358
|
-
Each tap and drag reports where it landed (a script's hit region, a selection handle,
|
|
359
|
-
an item, or empty board) and what took it (a script, move, resize, rotate, select box).
|
|
360
|
-
|
|
361
|
-
Examples:
|
|
362
|
-
cohub boards simulate farm.board '{"steps":[{"wait":"2s"}]}' -o farm.png
|
|
363
|
-
cohub boards simulate farm.board -i steps.json --json`)
|
|
364
|
-
.action(async (target, inline, options) => {
|
|
365
|
-
try {
|
|
366
|
-
if (inline !== undefined && options.input !== undefined)
|
|
367
|
-
throw new Error("Pass steps inline or with --input, not both.");
|
|
368
|
-
const input = inline !== undefined
|
|
369
|
-
? parseBoardJsonObject(inline, "steps")
|
|
370
|
-
: options.input !== undefined ? await readBoardJsonObject(options.input) : { steps: [] };
|
|
371
|
-
const { parseBoardSimulationSteps, runBoardSimulation } = await import("../board-simulate.js");
|
|
372
|
-
const steps = parseBoardSimulationSteps(input.steps);
|
|
373
|
-
const out = options.out;
|
|
374
|
-
if (out && !options.force && existsSync(out))
|
|
375
|
-
throw new Error(`${out} already exists; use --force to replace it.`);
|
|
376
|
-
const result = await runBoardSimulation({
|
|
377
|
-
spaceId: await resolveSpace(boards),
|
|
378
|
-
target,
|
|
379
|
-
steps,
|
|
380
|
-
leader: !options.follower,
|
|
381
|
-
timeoutMs: parseBoardTime(options.timeout ?? "2m", "--timeout"),
|
|
382
|
-
...(out ? { image: {
|
|
383
|
-
region: parseExportRegion(options),
|
|
384
|
-
scale: parseNumber(options.scale ?? "2", "--scale", { min: 0.01, max: 16 }),
|
|
385
|
-
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
386
|
-
format: parseExportFormat(options, out),
|
|
387
|
-
withImages: options.images !== false,
|
|
388
|
-
} } : {}),
|
|
389
|
-
});
|
|
390
|
-
if (out && result.image) {
|
|
391
|
-
await mkdir(dirname(out), { recursive: true });
|
|
392
|
-
await writeBoardOutput(out, result.image.bytes, Boolean(options.force));
|
|
393
|
-
}
|
|
394
|
-
const { image, ...summary } = result;
|
|
395
|
-
if (jsonRequested(options))
|
|
396
|
-
return outJson({ ...summary, ...(out && image ? { file: out, width: image.width, height: image.height } : {}) });
|
|
397
|
-
const changed = Object.keys(result.changes.items ?? {}).length;
|
|
398
|
-
ok(`Simulated ${formatBoardTime(result.time)}: ${result.commits} commit${result.commits === 1 ? "" : "s"}, ${changed} item${changed === 1 ? "" : "s"} changed (not saved)`);
|
|
399
|
-
for (const press of result.presses)
|
|
400
|
-
console.log(` step ${press.step + 1}: ${describePress(press)}`);
|
|
401
|
-
for (const [id, message] of Object.entries(result.errors))
|
|
402
|
-
console.log(` ! ${id}: ${message.split("\n")[0]}`);
|
|
403
|
-
for (const warning of result.warnings)
|
|
404
|
-
console.log(` ! ${warning}`);
|
|
405
|
-
if (result.shaders && !result.shaders.compiled)
|
|
406
|
-
console.log(" Shaders were checked but not compiled; install Chrome, Chromium or Edge, or set COHUB_CHROME, to compile them.");
|
|
407
|
-
if (out && image)
|
|
408
|
-
console.log(` Rendered ${image.width}×${image.height} to ${out}`);
|
|
409
|
-
else if (out)
|
|
410
|
-
console.log(" ! Nothing to render: the region contains no items.");
|
|
411
|
-
}
|
|
412
|
-
catch (cause) {
|
|
413
|
-
handleHttp(cause);
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
function describePress({ down, taken }) {
|
|
418
|
-
const where = down.on === "script" ? `script ${down.owner}/${down.target}`
|
|
419
|
-
: down.on === "handle" ? `${down.handle} handle`
|
|
420
|
-
: down.on === "item" ? `${down.type} ${down.id}`
|
|
421
|
-
: `empty board${down.under ? ` over ${down.under}` : ""}`;
|
|
422
|
-
return `pressed on ${where}, taken by ${taken}`;
|
|
423
|
-
}
|
|
424
|
-
function registerProfileCommand(boards) {
|
|
425
|
-
withJson(boards.command("profile <board>")
|
|
426
|
-
.description("Measure what a Board costs to draw, shader by shader, and say what to change")
|
|
427
|
-
.option("--at <time>", "A moment of --animation, or a script time without one", "2s")
|
|
428
|
-
.option("--animation <id>", "Animation --at refers to")
|
|
429
|
-
.option("--frame <item-id>", "Profile one frame")
|
|
430
|
-
.option("--items <ids>", "Profile comma-separated item ids")
|
|
431
|
-
.option("--rect <rect>", "Profile a world rect as x,y,width,height")
|
|
432
|
-
.option("--size <widthxheight>", "Fit the region into this many pixels, like a screen", "1600x900")
|
|
433
|
-
.option("--frames <count>", "Frames to time per measurement", "5")
|
|
434
|
-
.option("--rounds <count>", "Measurements per shader owner; reports their median and range", "3")
|
|
435
|
-
.option("--budget <time>", "Time the measurements may take; past it, size and frames go down", "60s")
|
|
436
|
-
.option("--no-images", "Draw placeholders instead of downloading images"))
|
|
437
|
-
.addHelpText("after", `
|
|
438
|
-
Draws in a headless Chrome; without a GPU it uses software WebGL (reported as
|
|
439
|
-
"software"), so compare the numbers with each other rather than with a real display.
|
|
440
|
-
Scripts receive the profiled view as viewchange, as on a screen of --size.
|
|
441
|
-
|
|
442
|
-
Examples:
|
|
443
|
-
cohub boards profile demo.board
|
|
444
|
-
cohub boards profile demo.board --rect 0,0,1600,900 --at 8s --json`)
|
|
445
|
-
.action(async (target, options) => {
|
|
446
|
-
try {
|
|
447
|
-
const { profileBoard } = await import("../board-profile.js");
|
|
448
|
-
const profile = await profileBoard({
|
|
449
|
-
spaceId: await resolveSpace(boards),
|
|
450
|
-
target,
|
|
451
|
-
time: parseBoardTime(options.at ?? "2s", "--at"),
|
|
452
|
-
...(options.animation ? { animation: options.animation } : {}),
|
|
453
|
-
region: parseExportRegion(options),
|
|
454
|
-
size: parseSize(options.size ?? "1600x900"),
|
|
455
|
-
frames: parseNumber(options.frames ?? "5", "--frames", { min: 3, max: 240, integer: true }),
|
|
456
|
-
rounds: parseNumber(options.rounds ?? "3", "--rounds", { min: 1, max: 20, integer: true }),
|
|
457
|
-
budgetMs: parseBoardTime(options.budget ?? "60s", "--budget"),
|
|
458
|
-
withImages: options.images !== false,
|
|
459
|
-
});
|
|
460
|
-
if (jsonRequested(options))
|
|
461
|
-
return outJson(profile);
|
|
462
|
-
const ms = (value) => `${value.toFixed(1)} ms`;
|
|
463
|
-
ok(`${profile.width}×${profile.height} on ${profile.gpu} WebGL (${profile.renderer}): ${ms(profile.frame.p50)} a frame (p95 ${ms(profile.frame.p95)}), ${profile.items} items`);
|
|
464
|
-
if (profile.reduced)
|
|
465
|
-
console.log(` ! ${profile.reduced.width}×${profile.reduced.height} × ${profile.reduced.frames} frames took ${ms(profile.reduced.frameMs)} a frame, past the budget; measured ${profile.width}×${profile.height} × ${profile.frames} frames instead.`);
|
|
466
|
-
console.log(` ${profile.rounds} round${profile.rounds === 1 ? "" : "s"} × ${profile.frames} frames in ${(profile.elapsedMs / 1000).toFixed(1)} s; owner cost is the median, with the range across rounds`);
|
|
467
|
-
for (const owner of profile.owners) {
|
|
468
|
-
const traits = [owner.filter !== "none" && `filter ${owner.filter}`, owner.sprites && `${owner.sprites} sprites`, owner.state && `state ${owner.state.width}×${owner.state.height}`].filter(Boolean);
|
|
469
|
-
const range = profile.rounds > 1 ? ` (${owner.range[0].toFixed(0)}–${owner.range[1].toFixed(0)})` : "";
|
|
470
|
-
console.log(` ${owner.id.padEnd(24)} ${ms(owner.ms).padStart(9)}${range.padEnd(12)}${traits.length ? ` ${traits.join(", ")}` : ""}`);
|
|
471
|
-
}
|
|
472
|
-
for (const hint of profile.hints)
|
|
473
|
-
console.log(` ! ${hint}`);
|
|
474
|
-
}
|
|
475
|
-
catch (cause) {
|
|
476
|
-
handleHttp(cause);
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
boards.command("gpu-daemon", { hidden: true })
|
|
480
|
-
.requiredOption("--browser <path>")
|
|
481
|
-
.action(async (options) => {
|
|
482
|
-
const { serveBoardGpu } = await import("../board-gpu/daemon.js");
|
|
483
|
-
await serveBoardGpu(options.browser);
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
// ─── Commands ────────────────────────────────────────────────────────────────
|
|
487
|
-
export function registerBoards(program) {
|
|
488
|
-
const boards = program
|
|
489
|
-
.command("boards")
|
|
490
|
-
.description("Read, write, animate and export Boards (by id or .board path)")
|
|
491
|
-
.addHelpText("after", `
|
|
492
|
-
A Board is one JSON document: { board, items, animations }.
|
|
493
|
-
get read it
|
|
494
|
-
apply write it with a JSON Merge Patch; null deletes
|
|
495
|
-
schema the fields of any part and what they mean; also the script API
|
|
496
|
-
examples starter documents and a custom script module
|
|
497
|
-
preset tracks for a preset motion, ready to apply
|
|
498
|
-
sequence join chapter animations into one timeline
|
|
499
|
-
path sample a polyline into a position track
|
|
500
|
-
inspect measure items and report layout hints
|
|
501
|
-
frames the frames viewers step through, in order
|
|
502
|
-
export render an image, a frame sequence or a video
|
|
503
|
-
play shared playback; also pause, resume, next, seek, stop
|
|
504
|
-
watch stream changes and playback
|
|
505
|
-
history list versions, or restore one
|
|
506
|
-
diff what changed between two versions
|
|
507
|
-
Times are milliseconds; 500ms, 12.5s and 2m also work on the command line.`);
|
|
508
|
-
withJson(boards.command("create <path>")
|
|
509
|
-
.description("Create a Board file, optionally with an initial document")
|
|
510
|
-
.option("--title <title>", "Board title")
|
|
511
|
-
.option("-i, --input <file>", "Initial document JSON; - for stdin")
|
|
512
|
-
.option("--mutation-id <id>", "Stable id for safe retries"))
|
|
513
|
-
.addHelpText("after", `
|
|
514
|
-
cohub boards examples lesson > lesson.json
|
|
515
|
-
cohub boards create lesson.board -i lesson.json`)
|
|
516
|
-
.action(async (path, options) => {
|
|
517
|
-
try {
|
|
518
|
-
const spaceId = await resolveSpace(boards);
|
|
519
|
-
const read = options.input ? await readBoardJsonObject(options.input, BOARD_CREATE_INPUT_MAX_BYTES) : undefined;
|
|
520
|
-
const document = read && await settleBoardPatch(spaceId, read, async () => ({}));
|
|
521
|
-
const input = {
|
|
522
|
-
path,
|
|
523
|
-
mutationId: options.mutationId ?? randomUUID(),
|
|
524
|
-
...(options.title ? { title: options.title } : {}),
|
|
525
|
-
...(document ? { document: document } : {}),
|
|
526
|
-
};
|
|
527
|
-
const result = await createClient().space(spaceId).boards.create(input);
|
|
528
|
-
if (jsonRequested(options))
|
|
529
|
-
return outJson({ path, id: result.id, title: result.title, version: result.version });
|
|
530
|
-
ok(`Created ${path}`);
|
|
531
|
-
table([{ path, id: result.id, title: result.title, version: result.version }], [
|
|
532
|
-
{ key: "path", label: "Path" },
|
|
533
|
-
{ key: "id", label: "ID" },
|
|
534
|
-
{ key: "title", label: "Title" },
|
|
535
|
-
{ key: "version", label: "Version" },
|
|
536
|
-
]);
|
|
537
|
-
}
|
|
538
|
-
catch (cause) {
|
|
539
|
-
handleHttp(cause);
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
boards.command("get <board>")
|
|
543
|
-
.description("Print the Board document as JSON")
|
|
544
|
-
.option("--only <sections>", "board, items, animations (comma-separated)")
|
|
545
|
-
.option("--items <ids>", "Only these items")
|
|
546
|
-
.option("--within <frame-id>", "A frame and everything inside it")
|
|
547
|
-
.option("--rect <rect>", "Items intersecting x,y,width,height")
|
|
548
|
-
.option("--animations <ids>", "Only these animations")
|
|
549
|
-
.option("--limit <n>", "Page size for items")
|
|
550
|
-
.option("--cursor <cursor>", "Continue from a previous page's next")
|
|
551
|
-
.option("--since <version>", "Only the changes after this version; the whole Board when they are unavailable")
|
|
552
|
-
.addHelpText("after", `
|
|
553
|
-
cohub boards get plan.board
|
|
554
|
-
cohub boards get plan.board --within s2
|
|
555
|
-
cohub boards get plan.board --only board
|
|
556
|
-
cohub boards get plan.board --since 12`)
|
|
557
|
-
.action(async (target, options) => {
|
|
558
|
-
try {
|
|
559
|
-
const only = list(options.only);
|
|
560
|
-
if (only?.some((section) => section !== "board" && section !== "items" && section !== "animations"))
|
|
561
|
-
throw new Error("--only takes board, items, animations, or a combination.");
|
|
562
|
-
const sections = only ? new Set(only) : null;
|
|
563
|
-
const input = {
|
|
564
|
-
...(only ? { only: only.filter((section) => section !== "board") } : {}),
|
|
565
|
-
...(list(options.items) ? { items: list(options.items) } : {}),
|
|
566
|
-
...(options.within ? { within: options.within } : {}),
|
|
567
|
-
...(options.rect ? { rect: parseRect(options.rect) } : {}),
|
|
568
|
-
...(list(options.animations) ? { animations: list(options.animations) } : {}),
|
|
569
|
-
...(options.limit ? { limit: parseNumber(options.limit, "--limit", { min: 1, integer: true }) } : {}),
|
|
570
|
-
...(options.cursor ? { cursor: options.cursor } : {}),
|
|
571
|
-
...(options.since ? { since: parseNumber(options.since, "--since", { min: 0, integer: true }) } : {}),
|
|
572
|
-
};
|
|
573
|
-
const result = await (await boardClient(boards, target)).get(input);
|
|
574
|
-
if (!sections)
|
|
575
|
-
return outJson(result);
|
|
576
|
-
outJson({
|
|
577
|
-
id: result.id,
|
|
578
|
-
title: result.title,
|
|
579
|
-
version: result.version,
|
|
580
|
-
updatedAt: result.updatedAt,
|
|
581
|
-
playback: result.playback,
|
|
582
|
-
...(sections.has("board") ? { board: result.board } : {}),
|
|
583
|
-
...(sections.has("items") && result.items ? { items: result.items } : {}),
|
|
584
|
-
...(sections.has("animations") && result.animations ? { animations: result.animations } : {}),
|
|
585
|
-
...(result.next ? { next: result.next } : {}),
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
catch (cause) {
|
|
589
|
-
handleHttp(cause);
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
withJson(boards.command("apply <board> [patch]")
|
|
593
|
-
.description("Merge a patch into the Board: fields merge, null deletes")
|
|
594
|
-
.option("-i, --input <file>", "Patch JSON; - for stdin")
|
|
595
|
-
.option("--replace", "Make the document equal to the input instead of merging")
|
|
596
|
-
.option("--cascade", "Also delete children and tracks of deleted items, and tracks of deleted Board scripts")
|
|
597
|
-
.option("--dry-run", "Validate without writing")
|
|
598
|
-
.option("--base-version <n>", "Fail if the Board moved past this version")
|
|
599
|
-
.option("--mutation-id <id>", "Stable id; retries never apply twice"))
|
|
600
|
-
.addHelpText("after", `
|
|
601
|
-
cohub boards apply plan.board '{"items":{"t1":{"type":"text","props":{"text":"Hi","fontSize":48}}}}'
|
|
602
|
-
cohub boards apply plan.board '{"items":{"t1":{"position":{"x":200}}}}'
|
|
603
|
-
cohub boards apply plan.board '{"items":{"t1":null}}'
|
|
604
|
-
cohub boards preset rise --targets a,b --animation intro | cohub boards apply plan.board -i -`)
|
|
605
|
-
.action(async (target, inline, options) => {
|
|
606
|
-
try {
|
|
607
|
-
const spaceId = await resolveSpace(boards);
|
|
608
|
-
const board = await boardClient(boards, target, spaceId);
|
|
609
|
-
const read = await readPatch(inline, options.input, BOARD_TRANSACTION_INPUT_MAX_BYTES);
|
|
610
|
-
const patch = await settleBoardPatch(spaceId, read, async (items) => options.replace ? {} : board.get({ only: ["items"], items }).then((result) => result.items ?? {}, () => null));
|
|
611
|
-
const result = await board.apply(patch, {
|
|
612
|
-
...(options.replace ? { replace: true } : {}),
|
|
613
|
-
...(options.cascade ? { cascade: true } : {}),
|
|
614
|
-
...(options.dryRun ? { dryRun: true } : {}),
|
|
615
|
-
...(options.baseVersion === undefined ? {} : { baseVersion: parseNumber(options.baseVersion, "--base-version", { min: 0, integer: true }) }),
|
|
616
|
-
...(options.mutationId ? { mutationId: options.mutationId } : {}),
|
|
617
|
-
});
|
|
618
|
-
if (jsonRequested(options))
|
|
619
|
-
return outJson(result);
|
|
620
|
-
showApplied(result);
|
|
621
|
-
}
|
|
622
|
-
catch (cause) {
|
|
623
|
-
handleHttp(cause);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
withJson(boards.command("history <board>")
|
|
627
|
-
.description("List Board versions, or restore one")
|
|
628
|
-
.option("--before <version>", "Versions older than this")
|
|
629
|
-
.option("--limit <n>", "Number of versions", "20")
|
|
630
|
-
.option("--restore <version>", "Return the Board to this version as a new write"))
|
|
631
|
-
.action(async (target, options) => {
|
|
632
|
-
try {
|
|
633
|
-
const board = await boardClient(boards, target);
|
|
634
|
-
if (options.restore !== undefined) {
|
|
635
|
-
const result = await board.restore(parseNumber(options.restore, "--restore", { min: 0, integer: true }));
|
|
636
|
-
if (jsonRequested(options))
|
|
637
|
-
return outJson(result);
|
|
638
|
-
return showApplied(result);
|
|
639
|
-
}
|
|
640
|
-
const page = await board.history({
|
|
641
|
-
...(options.before ? { before: parseNumber(options.before, "--before", { min: 1, integer: true }) } : {}),
|
|
642
|
-
limit: parseNumber(options.limit ?? "20", "--limit", { min: 1, max: 500, integer: true }),
|
|
643
|
-
});
|
|
644
|
-
if (jsonRequested(options))
|
|
645
|
-
return outJson(page);
|
|
646
|
-
table(page.transactions.map((transaction) => ({
|
|
647
|
-
version: transaction.version,
|
|
648
|
-
at: transaction.createdAt,
|
|
649
|
-
actor: transaction.source?.via ?? transaction.actorId,
|
|
650
|
-
items: Object.keys(transaction.after?.items ?? {}).length,
|
|
651
|
-
animations: new Set([...Object.keys(transaction.after?.animations ?? {}), ...Object.keys(transaction.after?.tracks ?? {})]).size,
|
|
652
|
-
})), [
|
|
653
|
-
{ key: "version", label: "Version" },
|
|
654
|
-
{ key: "at", label: "At" },
|
|
655
|
-
{ key: "actor", label: "By" },
|
|
656
|
-
{ key: "items", label: "Items" },
|
|
657
|
-
{ key: "animations", label: "Animations" },
|
|
658
|
-
]);
|
|
659
|
-
if (page.nextBefore)
|
|
660
|
-
console.log(` More: --before ${page.nextBefore}`);
|
|
661
|
-
}
|
|
662
|
-
catch (cause) {
|
|
663
|
-
handleHttp(cause);
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
withJson(boards.command("diff <board>")
|
|
667
|
-
.description("List what changed between two versions, element by element")
|
|
668
|
-
.requiredOption("--from <version>", "The version to compare from")
|
|
669
|
-
.option("--to <version>", "The version to compare to; the latest by default"))
|
|
670
|
-
.addHelpText("after", `
|
|
671
|
-
Before rewriting a Board with apply --replace, see what others changed since the version you read:
|
|
672
|
-
cohub boards diff plan.board --from 41
|
|
673
|
-
cohub boards diff plan.board --from 41 --to 44 --json`)
|
|
674
|
-
.action(async (target, options) => {
|
|
675
|
-
try {
|
|
676
|
-
const board = await boardClient(boards, target);
|
|
677
|
-
const result = await board.diff(parseNumber(options.from, "--from", { min: 0, integer: true }), options.to === undefined ? undefined : parseNumber(options.to, "--to", { min: 1, integer: true }));
|
|
678
|
-
if (jsonRequested(options))
|
|
679
|
-
return outJson(result);
|
|
680
|
-
const by = new Map();
|
|
681
|
-
for (const { kind } of result.versions)
|
|
682
|
-
by.set(kind, (by.get(kind) ?? 0) + 1);
|
|
683
|
-
ok(`v${result.from} → v${result.to}: ${result.changes.length} element${result.changes.length === 1 ? "" : "s"} changed in ${result.versions.length} version${result.versions.length === 1 ? "" : "s"}${by.size ? ` (${[...by].map(([kind, count]) => `${count} by ${kind}`).join(", ")})` : ""}`);
|
|
684
|
-
const show = (value) => {
|
|
685
|
-
const text = value === undefined ? "∅" : JSON.stringify(value);
|
|
686
|
-
return text.length > 60 ? `${text.slice(0, 57)}…` : text;
|
|
687
|
-
};
|
|
688
|
-
for (const change of result.changes) {
|
|
689
|
-
const sign = change.change === "added" ? "+" : change.change === "removed" ? "-" : "~";
|
|
690
|
-
const name = change.kind === "board" ? "board" : `${change.kind} ${change.id}${change.type ? ` (${change.type})` : ""}`;
|
|
691
|
-
console.log(` ${sign} ${name}`);
|
|
692
|
-
for (const field of change.fields.slice(0, 12))
|
|
693
|
-
console.log(` ${field.path}: ${show(field.from)} → ${show(field.to)}`);
|
|
694
|
-
if (change.fields.length > 12)
|
|
695
|
-
console.log(` … ${change.fields.length - 12} more fields; --json lists them all`);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
catch (cause) {
|
|
699
|
-
handleHttp(cause);
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
boards.command("schema [target]")
|
|
703
|
-
.description("Print JSON Schema for a part of a Board")
|
|
704
|
-
.option("--field <path>", "Print one field, e.g. props.decoration or props.geometry")
|
|
705
|
-
.addHelpText("after", `
|
|
706
|
-
Without a target: units, item types, colors and every animatable property.
|
|
707
|
-
With a target: its fields and what they mean; script also lists the module API.
|
|
708
|
-
Targets: ${BOARD_SCHEMA_TARGETS.join(", ")}`)
|
|
709
|
-
.action((target, options) => {
|
|
710
|
-
try {
|
|
711
|
-
if (options.field && !target)
|
|
712
|
-
throw new Error("--field needs a schema target, e.g. schema frame --field props.decoration.");
|
|
713
|
-
if (!target)
|
|
714
|
-
return outJson({ ...boardSchemaOverview(), presets: listBoardPresets() });
|
|
715
|
-
const schema = boardJsonSchema(target);
|
|
716
|
-
if (!schema)
|
|
717
|
-
throw new Error(`Unknown target ${target}; expected ${BOARD_SCHEMA_TARGETS.join(", ")}.`);
|
|
718
|
-
if (options.field)
|
|
719
|
-
return outJson(boardSchemaField(schema.schema, options.field));
|
|
720
|
-
outJson(target === "script" ? { ...schema, api: BOARD_SCRIPT_API } : schema);
|
|
721
|
-
}
|
|
722
|
-
catch (cause) {
|
|
723
|
-
handleHttp(cause);
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
boards.command("preset <name>")
|
|
727
|
-
.description("Print tracks for a preset motion as a patch for apply")
|
|
728
|
-
.requiredOption("--targets <ids>", "Comma-separated item ids")
|
|
729
|
-
.option("--animation <id>", "Wrap the tracks in this animation; omit to get bare tracks")
|
|
730
|
-
.option("--at <time>", "Start of the first target", "0")
|
|
731
|
-
.option("--stagger <time>", "Delay added per target", "0")
|
|
732
|
-
.option("--duration <time>", "Length of each target's motion")
|
|
733
|
-
.option("--ease <ease>", "CSS easing, e.g. ease-out or cubic-bezier(.2,.8,.2,1)")
|
|
734
|
-
.addHelpText("after", `
|
|
735
|
-
Presets: ${BOARD_PRESET_NAMES.join(", ")}
|
|
736
|
-
cohub boards preset rise --targets a,b,c --animation intro --stagger 120ms | cohub boards apply plan.board -i -
|
|
737
|
-
cohub boards preset float --targets ship | jq -c '{animations:{idle:.}}' | cohub boards apply plan.board -i -`)
|
|
738
|
-
.action((name, options) => {
|
|
739
|
-
try {
|
|
740
|
-
if (!isBoardPresetName(name))
|
|
741
|
-
throw new Error(`Unknown preset ${name}; expected ${BOARD_PRESET_NAMES.join(", ")}.`);
|
|
742
|
-
const targets = list(options.targets);
|
|
743
|
-
if (!targets)
|
|
744
|
-
throw new Error("--targets needs at least one item id.");
|
|
745
|
-
const tracks = boardPresetTracks(name, {
|
|
746
|
-
targets,
|
|
747
|
-
at: parseBoardTime(options.at, "--at"),
|
|
748
|
-
stagger: parseBoardTime(options.stagger, "--stagger"),
|
|
749
|
-
...(options.duration ? { duration: parseBoardTime(options.duration, "--duration") } : {}),
|
|
750
|
-
...(options.ease ? { ease: options.ease } : {}),
|
|
751
|
-
});
|
|
752
|
-
outJson(options.animation ? { animations: { [options.animation]: { tracks } } } : { tracks });
|
|
753
|
-
}
|
|
754
|
-
catch (cause) {
|
|
755
|
-
handleHttp(cause);
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
registerBoardExampleCommands(boards);
|
|
759
|
-
registerExportCommand(boards);
|
|
760
|
-
registerSimulateCommand(boards);
|
|
761
|
-
registerProfileCommand(boards);
|
|
762
|
-
registerBoardAuthoringCommands(boards);
|
|
763
|
-
registerPlaybackCommands(boards);
|
|
764
|
-
withJson(boards.command("watch <board>")
|
|
765
|
-
.description("Stream Board changes and playback as they happen"))
|
|
766
|
-
.action(async (target, options) => {
|
|
767
|
-
try {
|
|
768
|
-
const spaceId = await resolveSpace(boards);
|
|
769
|
-
const client = createRealtimeClient();
|
|
770
|
-
const board = await client.space(spaceId).boards.open(target);
|
|
771
|
-
const boardId = board.id;
|
|
772
|
-
if (!jsonRequested(options))
|
|
773
|
-
process.stderr.write(`Watching Board ${boardId}…\n`);
|
|
774
|
-
const offConnection = client.onConnection((state) => {
|
|
775
|
-
if (jsonRequested(options))
|
|
776
|
-
process.stdout.write(`${JSON.stringify({ type: "connection", ...state })}\n`);
|
|
777
|
-
else
|
|
778
|
-
process.stderr.write(`${state.state}${state.state === "reconnecting" && state.attempt ? ` (attempt ${state.attempt})` : ""}\n`);
|
|
779
|
-
});
|
|
780
|
-
const offBoard = board.subscribe({
|
|
781
|
-
event(event) {
|
|
782
|
-
if (jsonRequested(options)) {
|
|
783
|
-
process.stdout.write(`${JSON.stringify(event)}\n`);
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
if (event.type === "board.changed") {
|
|
787
|
-
const { changed } = event.payload;
|
|
788
|
-
process.stdout.write(`version ${event.payload.version} ${[changed.board ? "board" : "", ...changed.items, ...changed.animations].filter(Boolean).join(", ")}\n`);
|
|
789
|
-
}
|
|
790
|
-
else if (event.type === "board.playback.changed") {
|
|
791
|
-
const { playback } = event.payload;
|
|
792
|
-
process.stdout.write(playback ? `${playback.status} ${playback.animationId} ${formatBoardTime(Math.round(playback.position))}\n` : "stopped\n");
|
|
793
|
-
}
|
|
794
|
-
},
|
|
795
|
-
});
|
|
796
|
-
process.once("SIGINT", () => {
|
|
797
|
-
offBoard();
|
|
798
|
-
offConnection();
|
|
799
|
-
process.exit(0);
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
catch (cause) {
|
|
803
|
-
handleHttp(cause);
|
|
804
|
-
}
|
|
805
|
-
});
|
|
806
|
-
return boards;
|
|
807
|
-
}
|
|
808
|
-
function registerPlaybackCommands(boards) {
|
|
809
|
-
const run = async (target, options, command) => {
|
|
810
|
-
try {
|
|
811
|
-
const playback = await command(await boardClient(boards, target));
|
|
812
|
-
if (jsonRequested(options))
|
|
813
|
-
return outJson({ playback });
|
|
814
|
-
showPlayback(playback);
|
|
815
|
-
}
|
|
816
|
-
catch (cause) {
|
|
817
|
-
handleHttp(cause);
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
withJson(boards.command("play <board> <animation>")
|
|
821
|
-
.description("Play an animation for everyone viewing the Board")
|
|
822
|
-
.option("--at <time>", "Start position, e.g. 2.5s")
|
|
823
|
-
.option("--speed <factor>", "Playback speed, up to 4")
|
|
824
|
-
.option("--seed <seed>", "Seed for procedural effects"))
|
|
825
|
-
.action((target, animation, options) => run(target, options, (board) => board.play(animation, {
|
|
826
|
-
...(options.at ? { position: parseBoardTime(options.at, "--at") } : {}),
|
|
827
|
-
...(options.speed ? { timeScale: parseNumber(options.speed, "--speed", { min: Number.EPSILON, max: 4 }) } : {}),
|
|
828
|
-
...(options.seed ? { seed: options.seed } : {}),
|
|
829
|
-
})));
|
|
830
|
-
withJson(boards.command("pause <board>").description("Pause playback")).action((target, options) => run(target, options, (board) => board.pause()));
|
|
831
|
-
withJson(boards.command("resume <board>").description("Resume paused playback")).action((target, options) => run(target, options, (board) => board.resume()));
|
|
832
|
-
withJson(boards.command("seek <board> <time>").description("Move the playhead, e.g. 12.5s"))
|
|
833
|
-
.action((target, time, options) => run(target, options, (board) => board.seek(parseBoardTime(time))));
|
|
834
|
-
withJson(boards.command("next <board>").description("Continue past the marker a presentation holds at")).action((target, options) => run(target, options, (board) => board.next()));
|
|
835
|
-
withJson(boards.command("stop <board>").description("Stop playback")).action((target, options) => run(target, options, (board) => board.stop()));
|
|
836
|
-
}
|