@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,1943 @@
|
|
|
1
|
+
import { m as record, p as object, x as toJSONSchema } from "./schemas.js";
|
|
2
|
+
import { C as error, D as json, E as handleHttp, O as jsonRequested, b as resolveSpace, j as table, k as ok, r as createRealtimeClient, t as createClient } from "./client.js";
|
|
3
|
+
import { $ as BoardAnimationHeaderSchema, G as BOARD_COLOR_TOKENS, K as BOARD_EFFECT_KINDS, W as BOARD_CAMERA_TARGET, X as BOARD_ITEM_TYPES, Y as BOARD_ITEM_SCHEMAS, at as BoardSettingsSchema, bt as BOARD_TEXT_SCALE, f as listBoardProperties, g as resolveBoardProperty, ht as BOARD_DEFAULT_SIZES, it as BoardScriptSchema, lt as isBuiltinItemType, ot as BoardTrackSchema, q as BOARD_EFFECT_KIND_INFO, rt as BoardKeySchema, tt as BoardExtensionItemSchema, vt as BOARD_PAGE_SIZE } from "./id.js";
|
|
4
|
+
import { F as BOARD_SCRIPT_SENSES_EXAMPLE, I as BOARD_SCRIPT_TILT_EXAMPLE, N as BOARD_SCRIPT_DRAWING_EXAMPLE, P as BOARD_SCRIPT_RAIN_EXAMPLE, S as createBoardAnimationSampler, c as boardPathTrack, d as boardSequencePatch, i as boardFrameRegions, l as boardPlacePatch, n as BOARD_THEME_IDS, s as boardRegionStep, w as buildBoardScene } from "./themes.js";
|
|
5
|
+
import { a as settleBoardMediaDurations, i as settleBoardDocument, o as settleBoardPatch, s as loadBoardDocument, t as BOARD_EXPORT_RENDERERS } from "./board-export-resources.js";
|
|
6
|
+
import { n as parseBoardTime, r as parseBoardTimes, t as formatBoardTime } from "./board-time.js";
|
|
7
|
+
import { constants, existsSync } from "node:fs";
|
|
8
|
+
import { basename, dirname, join } from "node:path";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { access, link, mkdir, open, rename, unlink } from "node:fs/promises";
|
|
11
|
+
//#region ../protocol/src/board-schema.ts
|
|
12
|
+
function toJsonSchema(schema) {
|
|
13
|
+
const { $schema: _schema, ...rest } = toJSONSchema(schema, {
|
|
14
|
+
io: "input",
|
|
15
|
+
unrepresentable: "any"
|
|
16
|
+
});
|
|
17
|
+
return rest;
|
|
18
|
+
}
|
|
19
|
+
const BOARD_SCHEMA_TARGETS = [
|
|
20
|
+
"board",
|
|
21
|
+
"animation",
|
|
22
|
+
"track",
|
|
23
|
+
"script",
|
|
24
|
+
"extension",
|
|
25
|
+
BOARD_CAMERA_TARGET,
|
|
26
|
+
...BOARD_ITEM_TYPES
|
|
27
|
+
];
|
|
28
|
+
function boardJsonSchema(target) {
|
|
29
|
+
if (target === "board") return { schema: toJsonSchema(BoardSettingsSchema) };
|
|
30
|
+
if (target === "animation") return {
|
|
31
|
+
schema: toJsonSchema(BoardAnimationHeaderSchema.extend({ tracks: record(BoardKeySchema, BoardTrackSchema).optional() })),
|
|
32
|
+
properties: listBoardProperties("animation")
|
|
33
|
+
};
|
|
34
|
+
if (target === "track") return { schema: toJsonSchema(BoardTrackSchema) };
|
|
35
|
+
if (target === "script") return { schema: toJsonSchema(BoardScriptSchema) };
|
|
36
|
+
if (target === "extension") return { schema: toJsonSchema(BoardExtensionItemSchema) };
|
|
37
|
+
if (target === "camera") {
|
|
38
|
+
const properties = listBoardProperties(target);
|
|
39
|
+
const fields = Object.fromEntries(properties.map(({ property }) => {
|
|
40
|
+
const result = resolveBoardProperty(target, property);
|
|
41
|
+
if (!result.ok) throw new Error(result.message);
|
|
42
|
+
return [property, result.spec.schema];
|
|
43
|
+
}));
|
|
44
|
+
return {
|
|
45
|
+
schema: toJsonSchema(object(fields).partial().strict()),
|
|
46
|
+
properties
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (!isBuiltinItemType(target)) return null;
|
|
50
|
+
return {
|
|
51
|
+
schema: toJsonSchema(BOARD_ITEM_SCHEMAS[target]),
|
|
52
|
+
properties: listBoardProperties(target),
|
|
53
|
+
...target === "effect" ? { kinds: Object.fromEntries(BOARD_EFFECT_KINDS.map((kind) => [kind, BOARD_EFFECT_KIND_INFO[kind]])) } : {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function boardSchemaOverview() {
|
|
57
|
+
return {
|
|
58
|
+
units: {
|
|
59
|
+
time: "milliseconds",
|
|
60
|
+
rotation: "degrees",
|
|
61
|
+
length: "board units (1 = 1 CSS px at zoom 1)"
|
|
62
|
+
},
|
|
63
|
+
coordinates: "Positions, draw points and unbound arrow endpoints are relative to their parent frame; without a parent they are world coordinates. Shape paths are fitted to the item size.",
|
|
64
|
+
scale: {
|
|
65
|
+
guide: "Sizes that read together at 100% zoom. Match the content already nearby; use page for slide frames, a long edge of mediaEdge for media, and fontSizes for text.",
|
|
66
|
+
page: BOARD_PAGE_SIZE,
|
|
67
|
+
mediaEdge: 480,
|
|
68
|
+
fontSizes: BOARD_TEXT_SCALE,
|
|
69
|
+
itemSizes: BOARD_DEFAULT_SIZES
|
|
70
|
+
},
|
|
71
|
+
types: BOARD_ITEM_TYPES,
|
|
72
|
+
extensionTypes: "Namespaced types like acme.order keep props as written; give them a preview (title, excerpt, cover, src) so every client can show them. See schema extension.",
|
|
73
|
+
colors: {
|
|
74
|
+
tokens: BOARD_COLOR_TOKENS,
|
|
75
|
+
css: "any CSS color",
|
|
76
|
+
themed: "{ light, dark }"
|
|
77
|
+
},
|
|
78
|
+
properties: Object.fromEntries([
|
|
79
|
+
...BOARD_ITEM_TYPES,
|
|
80
|
+
BOARD_CAMERA_TARGET,
|
|
81
|
+
"animation"
|
|
82
|
+
].map((target) => [target, listBoardProperties(target).map((entry) => entry.property)]))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region ../sdk/src/board/model/script-api.ts
|
|
87
|
+
/**
|
|
88
|
+
* A compact reference for Board script authors, printed by `cohub boards schema script`.
|
|
89
|
+
* Each group is checked against its type, so a new member fails to compile until it is described.
|
|
90
|
+
*/
|
|
91
|
+
const BOARD_SCRIPT_API = {
|
|
92
|
+
runtime: [
|
|
93
|
+
"Modules are .js or .mjs Space files that import only literal relative paths (at most 64 modules, 2 MB).",
|
|
94
|
+
"They run in a worker with no DOM. Live Boards may fetch() and open WebSockets; exports and simulations have no network. Use Apps for HTML content.",
|
|
95
|
+
"Exports replay deterministically from ctx.onFrame, the frame clock, ctx.random(), Math.random() (seeded like ctx.random while script code runs), ctx.state and a recording of browser input (--inputs); timers, Date.now() and the network do not."
|
|
96
|
+
],
|
|
97
|
+
module: {
|
|
98
|
+
draw: "draw(ctx, frame): synchronous Canvas 2D drawing in item-local units.",
|
|
99
|
+
animated: "true redraws every frame; otherwise draw runs when its inputs change or after invalidate().",
|
|
100
|
+
frameRate: "Updates and redraws at most this many times a second (1–60); onFrame still steps at 60 Hz.",
|
|
101
|
+
pixelated: "true draws one canvas pixel per board unit and scales without smoothing, for crisp pixel art.",
|
|
102
|
+
parameters: "Declares params as { name: { type: number | boolean | string | color, label?, default?, min?, max?, step? } }.",
|
|
103
|
+
default: "Setup function (ctx) for behavior; may return a cleanup function.",
|
|
104
|
+
shader: "GPU passes drawn with the owner: { layer?, inputs?, uniforms?, state?, passes: [{ glsl, sprites?, texel?, blend? }] }. See shader."
|
|
105
|
+
},
|
|
106
|
+
frame: {
|
|
107
|
+
t: "Clock time in milliseconds.",
|
|
108
|
+
dt: "Milliseconds since the previous frame.",
|
|
109
|
+
width: "Item width in board units.",
|
|
110
|
+
height: "Item height in board units.",
|
|
111
|
+
seed: "script.seed, or the item id.",
|
|
112
|
+
params: "script.params merged over parameter defaults.",
|
|
113
|
+
state: "ctx.state."
|
|
114
|
+
},
|
|
115
|
+
context: {
|
|
116
|
+
self: "The owner: id, base (its authored item) and present(patch | null).",
|
|
117
|
+
params: "script.params merged over parameter defaults.",
|
|
118
|
+
targets: "script.targets: names mapped to item ids.",
|
|
119
|
+
items: "Every item in scope, as authored, by id; current after each change event.",
|
|
120
|
+
state: "Mutable state kept across frames and restored in exports.",
|
|
121
|
+
frame: "The latest frame.",
|
|
122
|
+
view: "Camera, width, height and safeRect in screen pixels; null until a viewchange. Exports and profiles send the area they draw, at the output's pixels.",
|
|
123
|
+
env: "The viewer's environment: mode, pointer, orientation, reducedMotion, locale and senses. See env; envchange reports changes.",
|
|
124
|
+
random: "random(): a seeded number in [0, 1); Math.random() draws from the same sequence.",
|
|
125
|
+
on: "on(type, handler): input and host events; returns an unsubscribe function.",
|
|
126
|
+
onFrame: "onFrame(handler): a synchronous 60 Hz fixed step; returns an unsubscribe function.",
|
|
127
|
+
onDispose: "onDispose(handler): cleanup when the instance stops.",
|
|
128
|
+
invalidate: "invalidate(): redraw a non-animated draw().",
|
|
129
|
+
get: "get(id): an item in scope, as authored.",
|
|
130
|
+
present: "present(id, patch | null): temporarily override position, size, rotation, scale, opacity, style, props or z of an item in scope; never saved. Items that leave the scope drop their override.",
|
|
131
|
+
scene: "scene(items, options?): replace this instance's world or screen layer of temporary Board items; never saved. IDs are unique across both layers.",
|
|
132
|
+
hitRegions: "hitRegions(regions): replace the input declarations.",
|
|
133
|
+
emit: "emit(id, type, data?): send a custom event to another scripted item in scope, or to any Board script by its key. Exports deliver it within the same moment, in document order. A handler may answer with emits; past 16 in a row the emit rejects, so emit from onFrame() to send on the next step.",
|
|
134
|
+
commit: "commit(patch): save a Board patch; resolves true once written here. Within 5 s of this viewer's input, outside onFrame steps, it saves undoably; otherwise one live editor saves it and others resolve false. It may edit items in scope, add children to a scoped frame, and attach modules already running in scope. Read-only viewers cannot commit: capabilities.has(\"board.commit\") is false there.",
|
|
135
|
+
layoutText: "layoutText({ text, fontSize?, fontWeight?, font?, lineHeight?, width? }): the size a native text item would take.",
|
|
136
|
+
uniforms: "uniforms(values): set the shader's declared uniforms from numbers or number arrays; kept until changed.",
|
|
137
|
+
passes: "passes({ name: on }): switch named shader passes on or off; kept until changed. Turn heavy passes, such as a full-view filter, on only while they show.",
|
|
138
|
+
capabilities: "has(name) and call(name, input?) for adapters the host provides. The Cohub app provides navigator.vibrate(pattern), haptics({ kind: tick | confirm | reject | longPress }), which also reaches native haptic engines, and fullscreen({ orientation?: portrait | landscape } | { exit: true }), which waits for the viewer's next tap when the browser needs one and works only in play or read-only views. Exports provide neither."
|
|
139
|
+
},
|
|
140
|
+
scope: "The owner, a Frame owner's descendants, and script.targets. A Board script (board.scripts) reaches every item.",
|
|
141
|
+
board: "A script in board.scripts has no box: ctx.self.base is null, frame width and height are 0, and it draws with shader passes or scene(). Its world scene sits over every item; its screen scene starts at the view's top-left. It takes input only on its scene items, and may commit new top-level items.",
|
|
142
|
+
shader: {
|
|
143
|
+
summary: "export const shader = { layer?, surfaces?, uniforms?, state?, passes }: WebGL 2 passes (GLSL ES 3.00) drawn with the owner on the GPU. Export animated = true for motion.",
|
|
144
|
+
descriptor: {
|
|
145
|
+
layer: "above (default) or below the owner and its contents; filter: passes transform the owner's pixels in turn, read with scene(uv). A Board script's filter transforms every item. A pass may set its own layer. A Frame that clips (props.clip, the default) keeps its own passes inside its box; with clip: false sprites may spill out.",
|
|
146
|
+
surfaces: "true provides surface(local): { distance, normal, inside } to the edges of the Board's items (not frames, arrows, drawings, effects, text or screen and add blends), so motion can collide with cards.",
|
|
147
|
+
uniforms: "Declared values set from setup code with ctx.uniforms(): { name: \"float\" | \"int\" | \"vec2\" | \"vec3\" | \"vec4\", optionally \"[length]\" }; at most 128 vectors.",
|
|
148
|
+
state: "{ width, height, glsl, precision?: byte | half, bounds?: { x, y, width, height } }: a texture vec4 simulate(Fragment f) advances in 60 Hz steps from its previous value state(uv); every pass reads stateAt(f.local). It covers bounds in owner units, by default the box, or for a Board script the view (like glass in front of it); give a Board script bounds in world units to keep its state on the Board.",
|
|
149
|
+
passes: "Up to 16, drawn in order."
|
|
150
|
+
},
|
|
151
|
+
pass: {
|
|
152
|
+
glsl: "Defines vec4 effect(Fragment f) returning straight (unpremultiplied) color; with sprites, also Sprite sprite(int id). The same source compiles for both stages: guard stage-only code with #ifdef COHUB_FRAGMENT.",
|
|
153
|
+
sprites: "Draw this many instanced quads (up to 65536, scaled by board.quality) placed by sprite(id), evaluated once per sprite per frame, instead of one quad over the box.",
|
|
154
|
+
texel: "For a box pass that changes only every texel local units, such as pixel art or a map: one sample per texel on a grid from the box's origin, scaled up without smoothing, so zooming in costs no more.",
|
|
155
|
+
blend: "normal (default), add, screen or multiply.",
|
|
156
|
+
layer: "below, above or filter for this pass alone, overriding shader.layer, so one script can paint a background and bend the picture.",
|
|
157
|
+
name: "A name ctx.passes() switches the pass by.",
|
|
158
|
+
enabled: "false starts a named pass off; a pass that is off costs nothing, a filter included."
|
|
159
|
+
},
|
|
160
|
+
glsl: {
|
|
161
|
+
board: "board.time and board.delta (seconds on the script clock), board.frame (60 Hz steps), board.size (box, or the view for Board scripts), board.view (visible rectangle x, y, width, height in local units), board.resolution (device pixels of the box), board.zoom, board.seed (0–1), board.quality (0–1; scale work by it), board.dark (1 in a dark theme).",
|
|
162
|
+
params: "params.<name>: number and boolean parameters as float, color parameters as vec4 resolved for the viewer's theme.",
|
|
163
|
+
uniforms: "uniforms.<name>: the declared uniforms.",
|
|
164
|
+
Fragment: "f.uv (0–1 across the box or sprite), f.local (owner units; world units for Board scripts), f.color and f.data (from the sprite).",
|
|
165
|
+
Sprite: "{ position, size, rotation (radians), color, data, visible } in local units; makeSprite(position, size) fills the rest.",
|
|
166
|
+
helpers: "scene(uv) in filter layers, surface(local) with surfaces, state(uv) across the state's area and stateAt(local) with state.",
|
|
167
|
+
includes: "#include \"cohub:hash\" (hash, hash2 by integer or vec2, identical on every GPU), \"cohub:noise\" (noise, fbm), \"cohub:shapes\" (sdCircle, sdBox, sdRoundBox, sdSegment, fill), \"cohub:color\" (hsv, luminance, srgbToLinear, linearToSrgb).",
|
|
168
|
+
rules: "No uniform, in/out, layout, #version or #extension declarations; no while or do loops; for loops share a budget of 65536 iterations per invocation. Names starting with cohub or holding __ are reserved."
|
|
169
|
+
},
|
|
170
|
+
export: "Web exports and `boards export` draw shaders like the live Board; `boards export --renderer canvas` draws draw() instead, or leaves the shader out, and warns."
|
|
171
|
+
},
|
|
172
|
+
hitRegions: {
|
|
173
|
+
forms: [
|
|
174
|
+
"{ target: \"self\" }: the owner.",
|
|
175
|
+
"{ item: id }: a scene item.",
|
|
176
|
+
"{ x, y, width, height }: a rectangle in owner coordinates."
|
|
177
|
+
],
|
|
178
|
+
options: "label (also a keyboard focus target), cursor, tools: the tools whose presses it takes (default select and hand; hand only taps), and over: true to take presses even where items lie over the region, such as a deck under its cards.",
|
|
179
|
+
rule: "Only declared regions receive input; everything else passes through to the Board. Event target is the region's key. Modifier keys and selection handles always go to the editor."
|
|
180
|
+
},
|
|
181
|
+
sceneOptions: {
|
|
182
|
+
space: "world (default) follows the owner's transform; screen keeps screen-pixel size and is left out of exports.",
|
|
183
|
+
anchor: "{ item, point }: pin a screen scene to an item, point in 0–1 box coordinates."
|
|
184
|
+
},
|
|
185
|
+
events: {
|
|
186
|
+
input: "pointerenter, pointerleave, pointerdown, pointermove, pointerup, pointercancel, click, focus, blur, keydown, keyup. Pointer events carry point in owner coordinates; key events carry key.",
|
|
187
|
+
host: {
|
|
188
|
+
selectionchange: "data.ids: selected items in scope; data.total: all selected items.",
|
|
189
|
+
transformend: "data.ids, data.operation (move | resize | rotate | arrow), data.cancelled.",
|
|
190
|
+
viewchange: "data: the view; also stored in ctx.view.",
|
|
191
|
+
change: "data.added, data.changed, data.removed: item ids in scope; data.source: user, script or remote.",
|
|
192
|
+
gesture: "data: this viewer's draw, shape, frame or arrow gesture over the owner: id, tool, phase (start | update | end | cancel), points in owner coordinates, and on end the item it created.",
|
|
193
|
+
envchange: "data: the new ctx.env.",
|
|
194
|
+
"browser:devicemotion": "data: the DeviceMotionEvent's acceleration, accelerationIncludingGravity, rotationRate (deg/s) and interval, in device axes, with t its timeStamp. One event per reading.",
|
|
195
|
+
"browser:deviceorientation": "data: alpha, beta, gamma, absolute, and on iOS webkitCompassHeading and webkitCompassAccuracy; t.",
|
|
196
|
+
"browser:deviceorientationabsolute": "As deviceorientation, relative to the Earth, where the browser offers it.",
|
|
197
|
+
"browser:gamepads": "data.pads: navigator.getGamepads() as { index, id, mapping, connected, timestamp, buttons: { pressed, touched, value }[], axes }, sent when they change. A pad appears once a button is pressed.",
|
|
198
|
+
"browser:audio": "data: samples (a Float32Array of mono microphone samples, about 20 ms), sampleRate, t.",
|
|
199
|
+
"browser:video": "data: frame (an ImageBitmap from the camera, up to 30 a second, closed when the next arrives), width, height, t. Draw it in draw(); recordings leave it out.",
|
|
200
|
+
"browser:position": "data: the GeolocationPosition: coords { latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed } and timestamp."
|
|
201
|
+
},
|
|
202
|
+
browser: "browser:* events are browser input as the browser reports it. Listening to one starts its source (see env.senses); readings never reach the document unless a script commits them. cohub boards examples senses --module prints helpers for screen-axis motion and audio level, pitch and spectrum.",
|
|
203
|
+
keys: "In play, keydown and keyup without modifiers also reach every listening script when no focused region takes them."
|
|
204
|
+
},
|
|
205
|
+
env: {
|
|
206
|
+
mode: "edit, play (a Board App or Play), view (read-only) or export.",
|
|
207
|
+
pointer: "fine (mouse) or coarse (touch).",
|
|
208
|
+
orientation: "portrait or landscape.",
|
|
209
|
+
angle: "screen.orientation.angle: 0, 90, 180 or 270; turn device-axis motion by it to get screen axes.",
|
|
210
|
+
reducedMotion: "The viewer asks for less motion.",
|
|
211
|
+
locale: "The viewer's BCP 47 locale, or null.",
|
|
212
|
+
senses: "{ motion, gamepad, microphone, camera, location }: on delivers while a script listens; ask waits for a tap (motion on iOS) or the viewer's consent (microphone, camera, location); denied; unavailable on this device and in exports. Listening is what turns a source on and off."
|
|
213
|
+
},
|
|
214
|
+
view: {
|
|
215
|
+
camera: "x, y and zoom.",
|
|
216
|
+
width: "Viewport width in screen pixels.",
|
|
217
|
+
height: "Viewport height in screen pixels.",
|
|
218
|
+
safeRect: "The viewport area not covered by editor chrome."
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region ../sdk/src/board/model/presets.ts
|
|
223
|
+
const OUT = "cubic-bezier(0.22, 1, 0.36, 1)";
|
|
224
|
+
const IN_OUT = "ease-in-out";
|
|
225
|
+
const PRESETS = {
|
|
226
|
+
"fade-in": {
|
|
227
|
+
description: "Fade in.",
|
|
228
|
+
duration: 400,
|
|
229
|
+
ease: "ease-out",
|
|
230
|
+
tracks: [{
|
|
231
|
+
property: "opacity",
|
|
232
|
+
keyframes: [[0, 0], [1, 1]]
|
|
233
|
+
}]
|
|
234
|
+
},
|
|
235
|
+
"fade-out": {
|
|
236
|
+
description: "Fade out.",
|
|
237
|
+
duration: 400,
|
|
238
|
+
ease: "ease-in",
|
|
239
|
+
tracks: [{
|
|
240
|
+
property: "opacity",
|
|
241
|
+
keyframes: [[0, 1], [1, 0]]
|
|
242
|
+
}]
|
|
243
|
+
},
|
|
244
|
+
rise: {
|
|
245
|
+
description: "Fade in while rising into place.",
|
|
246
|
+
duration: 600,
|
|
247
|
+
ease: OUT,
|
|
248
|
+
tracks: [{
|
|
249
|
+
property: "position.y",
|
|
250
|
+
keyframes: [[0, 40], [1, 0]]
|
|
251
|
+
}, {
|
|
252
|
+
property: "opacity",
|
|
253
|
+
keyframes: [[0, 0], [1, 1]]
|
|
254
|
+
}]
|
|
255
|
+
},
|
|
256
|
+
drop: {
|
|
257
|
+
description: "Fade in while dropping into place.",
|
|
258
|
+
duration: 600,
|
|
259
|
+
ease: OUT,
|
|
260
|
+
tracks: [{
|
|
261
|
+
property: "position.y",
|
|
262
|
+
keyframes: [[0, -40], [1, 0]]
|
|
263
|
+
}, {
|
|
264
|
+
property: "opacity",
|
|
265
|
+
keyframes: [[0, 0], [1, 1]]
|
|
266
|
+
}]
|
|
267
|
+
},
|
|
268
|
+
pop: {
|
|
269
|
+
description: "Scale up with a slight overshoot.",
|
|
270
|
+
duration: 500,
|
|
271
|
+
ease: OUT,
|
|
272
|
+
tracks: [{
|
|
273
|
+
property: "scale",
|
|
274
|
+
keyframes: [
|
|
275
|
+
[0, .6],
|
|
276
|
+
[.7, 1.06],
|
|
277
|
+
[1, 1]
|
|
278
|
+
]
|
|
279
|
+
}, {
|
|
280
|
+
property: "opacity",
|
|
281
|
+
keyframes: [[0, 0], [.4, 1]]
|
|
282
|
+
}]
|
|
283
|
+
},
|
|
284
|
+
deal: {
|
|
285
|
+
description: "Slide in like a dealt card.",
|
|
286
|
+
duration: 700,
|
|
287
|
+
ease: OUT,
|
|
288
|
+
tracks: [
|
|
289
|
+
{
|
|
290
|
+
property: "position",
|
|
291
|
+
keyframes: [[0, {
|
|
292
|
+
x: -80,
|
|
293
|
+
y: 40
|
|
294
|
+
}], [1, {
|
|
295
|
+
x: 0,
|
|
296
|
+
y: 0
|
|
297
|
+
}]]
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
property: "rotation",
|
|
301
|
+
keyframes: [[0, -10], [1, 0]]
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
property: "opacity",
|
|
305
|
+
keyframes: [[0, 0], [.3, 1]]
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
draw: {
|
|
310
|
+
description: "Draw the stroke from start to end.",
|
|
311
|
+
duration: 1e3,
|
|
312
|
+
ease: IN_OUT,
|
|
313
|
+
tracks: [{
|
|
314
|
+
property: "style.trim",
|
|
315
|
+
keyframes: [[0, 0], [1, 1]],
|
|
316
|
+
composite: "replace"
|
|
317
|
+
}]
|
|
318
|
+
},
|
|
319
|
+
type: {
|
|
320
|
+
description: "Type the text out character by character.",
|
|
321
|
+
duration: 1200,
|
|
322
|
+
ease: "linear",
|
|
323
|
+
tracks: [{
|
|
324
|
+
property: "props.reveal",
|
|
325
|
+
keyframes: [[0, 0], [1, 1]],
|
|
326
|
+
composite: "replace"
|
|
327
|
+
}]
|
|
328
|
+
},
|
|
329
|
+
pulse: {
|
|
330
|
+
description: "Swell and settle once.",
|
|
331
|
+
duration: 600,
|
|
332
|
+
ease: IN_OUT,
|
|
333
|
+
tracks: [{
|
|
334
|
+
property: "scale",
|
|
335
|
+
keyframes: [
|
|
336
|
+
[0, 1],
|
|
337
|
+
[.5, 1.08],
|
|
338
|
+
[1, 1]
|
|
339
|
+
]
|
|
340
|
+
}]
|
|
341
|
+
},
|
|
342
|
+
float: {
|
|
343
|
+
description: "Bob up and down; loop the animation for an idle drift.",
|
|
344
|
+
duration: 2400,
|
|
345
|
+
ease: IN_OUT,
|
|
346
|
+
tracks: [{
|
|
347
|
+
property: "position.y",
|
|
348
|
+
keyframes: [
|
|
349
|
+
[0, 0],
|
|
350
|
+
[.5, -10],
|
|
351
|
+
[1, 0]
|
|
352
|
+
]
|
|
353
|
+
}]
|
|
354
|
+
},
|
|
355
|
+
shake: {
|
|
356
|
+
description: "Shake side to side.",
|
|
357
|
+
duration: 500,
|
|
358
|
+
ease: "linear",
|
|
359
|
+
tracks: [{
|
|
360
|
+
property: "position.x",
|
|
361
|
+
keyframes: [
|
|
362
|
+
[0, 0],
|
|
363
|
+
[.15, -10],
|
|
364
|
+
[.3, 10],
|
|
365
|
+
[.45, -7],
|
|
366
|
+
[.6, 7],
|
|
367
|
+
[.8, -3],
|
|
368
|
+
[1, 0]
|
|
369
|
+
]
|
|
370
|
+
}]
|
|
371
|
+
},
|
|
372
|
+
spin: {
|
|
373
|
+
description: "Turn one full revolution.",
|
|
374
|
+
duration: 1200,
|
|
375
|
+
ease: "linear",
|
|
376
|
+
tracks: [{
|
|
377
|
+
property: "rotation",
|
|
378
|
+
keyframes: [[0, 0], [1, 360]]
|
|
379
|
+
}]
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
const BOARD_PRESET_NAMES = Object.keys(PRESETS);
|
|
383
|
+
function isBoardPresetName(value) {
|
|
384
|
+
return Object.hasOwn(PRESETS, value);
|
|
385
|
+
}
|
|
386
|
+
function listBoardPresets() {
|
|
387
|
+
return BOARD_PRESET_NAMES.map((name) => {
|
|
388
|
+
const preset = PRESETS[name];
|
|
389
|
+
return {
|
|
390
|
+
name,
|
|
391
|
+
description: preset.description,
|
|
392
|
+
duration: preset.duration,
|
|
393
|
+
properties: preset.tracks.map((track) => track.property)
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
function boardPresetTracks(name, options) {
|
|
398
|
+
const preset = PRESETS[name];
|
|
399
|
+
const duration = options.duration ?? preset.duration;
|
|
400
|
+
const ease = options.ease ?? preset.ease;
|
|
401
|
+
const tracks = {};
|
|
402
|
+
options.targets.forEach((target, index) => {
|
|
403
|
+
const start = Math.max(0, (options.at ?? 0) + index * (options.stagger ?? 0));
|
|
404
|
+
for (const track of preset.tracks) {
|
|
405
|
+
const keyframes = track.keyframes.map(([fraction, value], position) => ({
|
|
406
|
+
at: Math.round(start + fraction * duration),
|
|
407
|
+
value,
|
|
408
|
+
...position > 0 ? { ease: track.ease ?? ease } : {}
|
|
409
|
+
}));
|
|
410
|
+
const suffix = track.property.split(".").at(-1);
|
|
411
|
+
tracks[`${target}-${name}-${suffix}`] = {
|
|
412
|
+
target,
|
|
413
|
+
property: track.property,
|
|
414
|
+
keyframes,
|
|
415
|
+
composite: track.composite ?? "add",
|
|
416
|
+
interpolation: "auto"
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
return tracks;
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/board-command-support.ts
|
|
424
|
+
const BOARD_TRANSACTION_INPUT_MAX_BYTES = 16777216;
|
|
425
|
+
const BOARD_CREATE_INPUT_MAX_BYTES = 33554432;
|
|
426
|
+
const BOARD_DOMAIN_INPUT_MAX_BYTES = 1048576;
|
|
427
|
+
function parseBoardJsonObject(text, source = "input") {
|
|
428
|
+
if (!text.trim()) throw new Error(`${source} is empty`);
|
|
429
|
+
let value;
|
|
430
|
+
try {
|
|
431
|
+
value = JSON.parse(text);
|
|
432
|
+
} catch (cause) {
|
|
433
|
+
throw new Error(`${source} must contain valid JSON`, { cause });
|
|
434
|
+
}
|
|
435
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${source} must contain a JSON object`);
|
|
436
|
+
return value;
|
|
437
|
+
}
|
|
438
|
+
async function readStdinBounded(maxBytes) {
|
|
439
|
+
const chunks = [];
|
|
440
|
+
let size = 0;
|
|
441
|
+
for await (const chunk of process.stdin) {
|
|
442
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
443
|
+
size += bytes.byteLength;
|
|
444
|
+
if (size > maxBytes) throw new Error(`stdin exceeds the ${maxBytes} byte input limit`);
|
|
445
|
+
chunks.push(bytes);
|
|
446
|
+
}
|
|
447
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
448
|
+
}
|
|
449
|
+
async function readBoardJsonObject(source, maxBytes = BOARD_DOMAIN_INPUT_MAX_BYTES) {
|
|
450
|
+
if (source === "-") return parseBoardJsonObject(await readStdinBounded(maxBytes), "stdin");
|
|
451
|
+
const handle = await open(source, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
452
|
+
try {
|
|
453
|
+
const info = await handle.stat();
|
|
454
|
+
if (!info.isFile()) throw new Error(`${source} must be a regular file`);
|
|
455
|
+
if (info.size > maxBytes) throw new Error(`${source} exceeds the ${maxBytes} byte input limit`);
|
|
456
|
+
const chunks = [];
|
|
457
|
+
const buffer = Buffer.allocUnsafe(Math.max(1, Math.min(65536, maxBytes + 1)));
|
|
458
|
+
let size = 0;
|
|
459
|
+
for (;;) {
|
|
460
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.byteLength, null);
|
|
461
|
+
if (bytesRead === 0) break;
|
|
462
|
+
size += bytesRead;
|
|
463
|
+
if (size > maxBytes) throw new Error(`${source} exceeds the ${maxBytes} byte input limit`);
|
|
464
|
+
chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
|
|
465
|
+
}
|
|
466
|
+
return parseBoardJsonObject(Buffer.concat(chunks).toString("utf8"), source);
|
|
467
|
+
} finally {
|
|
468
|
+
await handle.close();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async function writeBoardOutput(path, bytes, force = false) {
|
|
472
|
+
if (!force) await access(path).then(() => {
|
|
473
|
+
throw new Error(`Output already exists: ${path}; use --force to replace it`);
|
|
474
|
+
}, () => void 0);
|
|
475
|
+
const temp = join(dirname(path), `.${basename(path)}.${randomUUID()}.tmp`);
|
|
476
|
+
try {
|
|
477
|
+
const handle = await open(temp, "wx");
|
|
478
|
+
try {
|
|
479
|
+
await handle.writeFile(bytes);
|
|
480
|
+
await handle.sync();
|
|
481
|
+
} finally {
|
|
482
|
+
await handle.close();
|
|
483
|
+
}
|
|
484
|
+
if (force) await rename(temp, path);
|
|
485
|
+
else {
|
|
486
|
+
await link(temp, path);
|
|
487
|
+
await unlink(temp);
|
|
488
|
+
}
|
|
489
|
+
} catch (cause) {
|
|
490
|
+
await unlink(temp).catch(() => void 0);
|
|
491
|
+
throw cause;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/commands/boards/examples.ts
|
|
496
|
+
const MODULES = {
|
|
497
|
+
custom: BOARD_SCRIPT_DRAWING_EXAMPLE,
|
|
498
|
+
rain: BOARD_SCRIPT_RAIN_EXAMPLE,
|
|
499
|
+
tilt: BOARD_SCRIPT_TILT_EXAMPLE,
|
|
500
|
+
senses: BOARD_SCRIPT_SENSES_EXAMPLE
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* Starter documents for `boards create -i` and patches for `boards apply -i`.
|
|
504
|
+
* Every example is a valid Board patch; `boards.test.ts` checks that.
|
|
505
|
+
*/
|
|
506
|
+
const BOARD_EXAMPLES = {
|
|
507
|
+
basic: {
|
|
508
|
+
description: "A title, a note and a shape.",
|
|
509
|
+
value: {
|
|
510
|
+
board: { title: "Launch plan" },
|
|
511
|
+
items: {
|
|
512
|
+
title: {
|
|
513
|
+
type: "text",
|
|
514
|
+
position: {
|
|
515
|
+
x: 80,
|
|
516
|
+
y: 60
|
|
517
|
+
},
|
|
518
|
+
props: {
|
|
519
|
+
text: "Launch plan",
|
|
520
|
+
fontSize: 40,
|
|
521
|
+
fontWeight: 700
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
note: {
|
|
525
|
+
type: "text",
|
|
526
|
+
position: {
|
|
527
|
+
x: 80,
|
|
528
|
+
y: 128
|
|
529
|
+
},
|
|
530
|
+
props: {
|
|
531
|
+
text: "Ship the beta to ten design partners, then widen.",
|
|
532
|
+
width: 420
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
goal: {
|
|
536
|
+
type: "shape",
|
|
537
|
+
position: {
|
|
538
|
+
x: 600,
|
|
539
|
+
y: 60
|
|
540
|
+
},
|
|
541
|
+
size: {
|
|
542
|
+
width: 200,
|
|
543
|
+
height: 140
|
|
544
|
+
},
|
|
545
|
+
style: {
|
|
546
|
+
stroke: "green",
|
|
547
|
+
fill: "green",
|
|
548
|
+
fillOpacity: .12,
|
|
549
|
+
radius: 16
|
|
550
|
+
},
|
|
551
|
+
props: { text: "Beta in March" }
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
workflow: {
|
|
557
|
+
description: "Steps joined by bound arrows with relations.",
|
|
558
|
+
value: { items: {
|
|
559
|
+
request: {
|
|
560
|
+
type: "shape",
|
|
561
|
+
position: {
|
|
562
|
+
x: 80,
|
|
563
|
+
y: 160
|
|
564
|
+
},
|
|
565
|
+
size: {
|
|
566
|
+
width: 200,
|
|
567
|
+
height: 110
|
|
568
|
+
},
|
|
569
|
+
style: { stroke: "brand" },
|
|
570
|
+
props: {
|
|
571
|
+
geometry: "rounded",
|
|
572
|
+
text: "Request"
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
agent: {
|
|
576
|
+
type: "shape",
|
|
577
|
+
position: {
|
|
578
|
+
x: 400,
|
|
579
|
+
y: 160
|
|
580
|
+
},
|
|
581
|
+
size: {
|
|
582
|
+
width: 200,
|
|
583
|
+
height: 110
|
|
584
|
+
},
|
|
585
|
+
style: {
|
|
586
|
+
stroke: "blue",
|
|
587
|
+
fill: "blue",
|
|
588
|
+
fillOpacity: .08
|
|
589
|
+
},
|
|
590
|
+
props: {
|
|
591
|
+
geometry: "rounded",
|
|
592
|
+
text: "Agent"
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
result: {
|
|
596
|
+
type: "shape",
|
|
597
|
+
position: {
|
|
598
|
+
x: 720,
|
|
599
|
+
y: 160
|
|
600
|
+
},
|
|
601
|
+
size: {
|
|
602
|
+
width: 200,
|
|
603
|
+
height: 110
|
|
604
|
+
},
|
|
605
|
+
style: {
|
|
606
|
+
stroke: "green",
|
|
607
|
+
fill: "green",
|
|
608
|
+
fillOpacity: .08
|
|
609
|
+
},
|
|
610
|
+
props: {
|
|
611
|
+
geometry: "rounded",
|
|
612
|
+
text: "Result"
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
"request-agent": {
|
|
616
|
+
type: "arrow",
|
|
617
|
+
props: {
|
|
618
|
+
start: { item: "request" },
|
|
619
|
+
end: { item: "agent" },
|
|
620
|
+
relation: "triggers",
|
|
621
|
+
label: "invoke"
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
"agent-result": {
|
|
625
|
+
type: "arrow",
|
|
626
|
+
props: {
|
|
627
|
+
start: { item: "agent" },
|
|
628
|
+
end: { item: "result" },
|
|
629
|
+
relation: "produces",
|
|
630
|
+
label: "output"
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
} }
|
|
634
|
+
},
|
|
635
|
+
slides: {
|
|
636
|
+
description: "960×540 frames as slides; children move and clip with their frame.",
|
|
637
|
+
value: { items: {
|
|
638
|
+
s1: {
|
|
639
|
+
type: "frame",
|
|
640
|
+
position: {
|
|
641
|
+
x: 0,
|
|
642
|
+
y: 0
|
|
643
|
+
},
|
|
644
|
+
size: {
|
|
645
|
+
width: 960,
|
|
646
|
+
height: 540
|
|
647
|
+
},
|
|
648
|
+
props: { label: "Intro" }
|
|
649
|
+
},
|
|
650
|
+
"s1-title": {
|
|
651
|
+
type: "text",
|
|
652
|
+
parent: "s1",
|
|
653
|
+
position: {
|
|
654
|
+
x: 72,
|
|
655
|
+
y: 72
|
|
656
|
+
},
|
|
657
|
+
props: {
|
|
658
|
+
text: "Special relativity",
|
|
659
|
+
fontSize: 56,
|
|
660
|
+
fontWeight: 700
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
"s1-sub": {
|
|
664
|
+
type: "text",
|
|
665
|
+
parent: "s1",
|
|
666
|
+
position: {
|
|
667
|
+
x: 72,
|
|
668
|
+
y: 160
|
|
669
|
+
},
|
|
670
|
+
props: { text: "Nothing outruns light" }
|
|
671
|
+
},
|
|
672
|
+
s2: {
|
|
673
|
+
type: "frame",
|
|
674
|
+
position: {
|
|
675
|
+
x: 1080,
|
|
676
|
+
y: 0
|
|
677
|
+
},
|
|
678
|
+
size: {
|
|
679
|
+
width: 960,
|
|
680
|
+
height: 540
|
|
681
|
+
},
|
|
682
|
+
props: { label: "Time dilation" }
|
|
683
|
+
},
|
|
684
|
+
"s2-title": {
|
|
685
|
+
type: "text",
|
|
686
|
+
parent: "s2",
|
|
687
|
+
position: {
|
|
688
|
+
x: 72,
|
|
689
|
+
y: 72
|
|
690
|
+
},
|
|
691
|
+
props: {
|
|
692
|
+
text: "Moving clocks run slow",
|
|
693
|
+
fontSize: 40,
|
|
694
|
+
fontWeight: 700
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
} }
|
|
698
|
+
},
|
|
699
|
+
lesson: {
|
|
700
|
+
description: "An animated lesson: entrances, a drawn arrow, typed text and camera moves with pause markers.",
|
|
701
|
+
value: {
|
|
702
|
+
items: {
|
|
703
|
+
s1: {
|
|
704
|
+
type: "frame",
|
|
705
|
+
size: {
|
|
706
|
+
width: 960,
|
|
707
|
+
height: 540
|
|
708
|
+
},
|
|
709
|
+
props: { label: "Length contraction" }
|
|
710
|
+
},
|
|
711
|
+
title: {
|
|
712
|
+
type: "text",
|
|
713
|
+
parent: "s1",
|
|
714
|
+
position: {
|
|
715
|
+
x: 72,
|
|
716
|
+
y: 60
|
|
717
|
+
},
|
|
718
|
+
props: {
|
|
719
|
+
text: "Moving rulers get shorter",
|
|
720
|
+
fontSize: 40,
|
|
721
|
+
fontWeight: 700
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
ruler: {
|
|
725
|
+
type: "shape",
|
|
726
|
+
parent: "s1",
|
|
727
|
+
position: {
|
|
728
|
+
x: 120,
|
|
729
|
+
y: 252
|
|
730
|
+
},
|
|
731
|
+
size: {
|
|
732
|
+
width: 480,
|
|
733
|
+
height: 40
|
|
734
|
+
},
|
|
735
|
+
style: {
|
|
736
|
+
stroke: "blue",
|
|
737
|
+
fill: "blue",
|
|
738
|
+
fillOpacity: .15
|
|
739
|
+
},
|
|
740
|
+
props: {
|
|
741
|
+
text: "1 m",
|
|
742
|
+
fontSize: 16
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
caption: {
|
|
746
|
+
type: "text",
|
|
747
|
+
parent: "s1",
|
|
748
|
+
position: {
|
|
749
|
+
x: 120,
|
|
750
|
+
y: 336
|
|
751
|
+
},
|
|
752
|
+
props: {
|
|
753
|
+
text: "L = L₀ √(1 − v²/c²)",
|
|
754
|
+
font: "serif",
|
|
755
|
+
reveal: 1
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
motion: {
|
|
759
|
+
type: "arrow",
|
|
760
|
+
parent: "s1",
|
|
761
|
+
style: {
|
|
762
|
+
stroke: "rose",
|
|
763
|
+
strokeWidth: 3
|
|
764
|
+
},
|
|
765
|
+
props: {
|
|
766
|
+
start: {
|
|
767
|
+
x: 120,
|
|
768
|
+
y: 216
|
|
769
|
+
},
|
|
770
|
+
end: {
|
|
771
|
+
x: 600,
|
|
772
|
+
y: 216
|
|
773
|
+
},
|
|
774
|
+
label: "v → c"
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
glow: {
|
|
778
|
+
type: "effect",
|
|
779
|
+
parent: "s1",
|
|
780
|
+
position: {
|
|
781
|
+
x: 630,
|
|
782
|
+
y: 224
|
|
783
|
+
},
|
|
784
|
+
size: {
|
|
785
|
+
width: 96,
|
|
786
|
+
height: 96
|
|
787
|
+
},
|
|
788
|
+
style: { fill: "amber" },
|
|
789
|
+
props: { kind: "glow" }
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
animations: { lecture: {
|
|
793
|
+
markers: [{
|
|
794
|
+
at: 1500,
|
|
795
|
+
label: "Ruler",
|
|
796
|
+
pause: true
|
|
797
|
+
}, {
|
|
798
|
+
at: 5e3,
|
|
799
|
+
label: "Formula",
|
|
800
|
+
pause: true
|
|
801
|
+
}],
|
|
802
|
+
tracks: {
|
|
803
|
+
"title-in": {
|
|
804
|
+
target: "title",
|
|
805
|
+
property: "opacity",
|
|
806
|
+
composite: "add",
|
|
807
|
+
keyframes: [{
|
|
808
|
+
at: 0,
|
|
809
|
+
value: 0
|
|
810
|
+
}, {
|
|
811
|
+
at: 600,
|
|
812
|
+
value: 1,
|
|
813
|
+
ease: "ease-out"
|
|
814
|
+
}]
|
|
815
|
+
},
|
|
816
|
+
"arrow-draw": {
|
|
817
|
+
target: "motion",
|
|
818
|
+
property: "style.trim",
|
|
819
|
+
keyframes: [{
|
|
820
|
+
at: 800,
|
|
821
|
+
value: 0
|
|
822
|
+
}, {
|
|
823
|
+
at: 1800,
|
|
824
|
+
value: 1,
|
|
825
|
+
ease: "ease-in-out"
|
|
826
|
+
}]
|
|
827
|
+
},
|
|
828
|
+
"ruler-shrink": {
|
|
829
|
+
target: "ruler",
|
|
830
|
+
property: "scale",
|
|
831
|
+
keyframes: [{
|
|
832
|
+
at: 2e3,
|
|
833
|
+
value: 1
|
|
834
|
+
}, {
|
|
835
|
+
at: 4e3,
|
|
836
|
+
value: {
|
|
837
|
+
x: .45,
|
|
838
|
+
y: 1
|
|
839
|
+
},
|
|
840
|
+
ease: "ease-in-out"
|
|
841
|
+
}]
|
|
842
|
+
},
|
|
843
|
+
"caption-type": {
|
|
844
|
+
target: "caption",
|
|
845
|
+
property: "props.reveal",
|
|
846
|
+
keyframes: [{
|
|
847
|
+
at: 4200,
|
|
848
|
+
value: 0
|
|
849
|
+
}, {
|
|
850
|
+
at: 6e3,
|
|
851
|
+
value: 1
|
|
852
|
+
}]
|
|
853
|
+
},
|
|
854
|
+
"camera-focus": {
|
|
855
|
+
target: "camera",
|
|
856
|
+
property: "focus",
|
|
857
|
+
keyframes: [
|
|
858
|
+
{
|
|
859
|
+
at: 0,
|
|
860
|
+
value: "s1"
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
at: 2e3,
|
|
864
|
+
value: "ruler"
|
|
865
|
+
},
|
|
866
|
+
{
|
|
867
|
+
at: 4500,
|
|
868
|
+
value: "s1"
|
|
869
|
+
}
|
|
870
|
+
]
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
} }
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
custom: {
|
|
877
|
+
description: "Custom Canvas content; use --module to print scripts/wave.js.",
|
|
878
|
+
value: { items: { wave: {
|
|
879
|
+
type: "custom",
|
|
880
|
+
position: {
|
|
881
|
+
x: 0,
|
|
882
|
+
y: 0
|
|
883
|
+
},
|
|
884
|
+
size: {
|
|
885
|
+
width: 480,
|
|
886
|
+
height: 270
|
|
887
|
+
},
|
|
888
|
+
script: {
|
|
889
|
+
src: "scripts/wave.js",
|
|
890
|
+
params: { amplitude: 48 }
|
|
891
|
+
}
|
|
892
|
+
} } }
|
|
893
|
+
},
|
|
894
|
+
rain: {
|
|
895
|
+
description: "A Board script whose shader rains over the view and splashes on cards; use --module to print scripts/rain.js.",
|
|
896
|
+
value: {
|
|
897
|
+
board: { scripts: { rain: {
|
|
898
|
+
src: "scripts/rain.js",
|
|
899
|
+
params: { density: .7 }
|
|
900
|
+
} } },
|
|
901
|
+
items: {
|
|
902
|
+
title: {
|
|
903
|
+
type: "text",
|
|
904
|
+
position: {
|
|
905
|
+
x: 80,
|
|
906
|
+
y: 40
|
|
907
|
+
},
|
|
908
|
+
props: {
|
|
909
|
+
text: "Rainy day",
|
|
910
|
+
fontSize: 48
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
left: {
|
|
914
|
+
type: "shape",
|
|
915
|
+
position: {
|
|
916
|
+
x: 80,
|
|
917
|
+
y: 180
|
|
918
|
+
},
|
|
919
|
+
size: {
|
|
920
|
+
width: 320,
|
|
921
|
+
height: 180
|
|
922
|
+
},
|
|
923
|
+
style: {
|
|
924
|
+
fill: "blue",
|
|
925
|
+
fillOpacity: .16,
|
|
926
|
+
radius: 16
|
|
927
|
+
},
|
|
928
|
+
props: { text: "Drops land on top" }
|
|
929
|
+
},
|
|
930
|
+
right: {
|
|
931
|
+
type: "shape",
|
|
932
|
+
position: {
|
|
933
|
+
x: 480,
|
|
934
|
+
y: 300
|
|
935
|
+
},
|
|
936
|
+
size: {
|
|
937
|
+
width: 280,
|
|
938
|
+
height: 160
|
|
939
|
+
},
|
|
940
|
+
rotation: -6,
|
|
941
|
+
style: {
|
|
942
|
+
fill: "green",
|
|
943
|
+
fillOpacity: .16,
|
|
944
|
+
radius: 16
|
|
945
|
+
},
|
|
946
|
+
props: { text: "and bounce off edges" }
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
},
|
|
951
|
+
tilt: {
|
|
952
|
+
description: "A ball that rolls as the phone tilts; --module tilt prints scripts/tilt.js, --module senses the helpers it imports.",
|
|
953
|
+
value: { items: { table: {
|
|
954
|
+
type: "custom",
|
|
955
|
+
position: {
|
|
956
|
+
x: 0,
|
|
957
|
+
y: 0
|
|
958
|
+
},
|
|
959
|
+
size: {
|
|
960
|
+
width: 360,
|
|
961
|
+
height: 640
|
|
962
|
+
},
|
|
963
|
+
script: { src: "scripts/tilt.js" }
|
|
964
|
+
} } }
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
function registerBoardExampleCommands(boards) {
|
|
968
|
+
boards.command("examples [name]").description("Print a starter Board document or list the examples").option("--module", `Print the example's JavaScript module (${Object.keys(MODULES).join(", ")})`).addHelpText("after", `
|
|
969
|
+
Examples are valid input for create and apply:
|
|
970
|
+
cohub boards examples lesson > lesson.json
|
|
971
|
+
cohub boards create lesson.board -i lesson.json`).action((name, options) => {
|
|
972
|
+
if (options.module) {
|
|
973
|
+
const module = name ? MODULES[name] : void 0;
|
|
974
|
+
if (!module) throw new Error(`--module needs one of these examples: ${Object.keys(MODULES).join(", ")}.`);
|
|
975
|
+
process.stdout.write(module);
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
if (!name) {
|
|
979
|
+
for (const [key, example] of Object.entries(BOARD_EXAMPLES)) console.log(`${key.padEnd(10)} ${example.description}`);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
const example = BOARD_EXAMPLES[name];
|
|
983
|
+
if (!example) throw new Error(`Unknown example ${name}; expected ${Object.keys(BOARD_EXAMPLES).join(", ")}`);
|
|
984
|
+
json(example.value);
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
//#endregion
|
|
988
|
+
//#region src/commands/boards/authoring.ts
|
|
989
|
+
const DIRECTIONS = [
|
|
990
|
+
"left",
|
|
991
|
+
"right",
|
|
992
|
+
"up",
|
|
993
|
+
"down"
|
|
994
|
+
];
|
|
995
|
+
function registerBoardAuthoringCommands(boards) {
|
|
996
|
+
boards.command("inspect <board>").description("Measure items and report visible layout hints without changing the Board").option("--animation <id>", "Animation to sample").option("--at <times>", "Time, comma-separated times, or start:end:step (up to 100 samples)", "0").option("--items <ids>", "Limit measurements to comma-separated item ids").option("--json", "Output as JSON").addHelpText("after", `
|
|
997
|
+
Without --animation, inspects the static document, not playback.
|
|
998
|
+
Bounds use world units with x/y at the top left; worldBounds includes rotation.
|
|
999
|
+
Checks native layout only, not camera cropping or content drawn inside scripts.
|
|
1000
|
+
Example: cohub boards inspect lesson.board --animation lecture --at 0:20s:1s --json`).action(async (target, options) => {
|
|
1001
|
+
try {
|
|
1002
|
+
const spaceId = await resolveSpace(boards);
|
|
1003
|
+
const document = await settleBoardDocument(spaceId, (await loadBoardDocument(spaceId, target)).document);
|
|
1004
|
+
const times = parseBoardTimes(options.at, "--at", 100);
|
|
1005
|
+
const sampler = options.animation ? createBoardAnimationSampler(document, options.animation) : null;
|
|
1006
|
+
const [{ resolveBundledFonts }, { createNodeBoardRenderer, inspectBoardItems }] = await Promise.all([import("./board-export2.js"), import("./board-kernel2.js")]);
|
|
1007
|
+
const renderer = await createNodeBoardRenderer({ fonts: resolveBundledFonts() });
|
|
1008
|
+
try {
|
|
1009
|
+
const ids = options.items ? new Set(options.items.split(",")) : null;
|
|
1010
|
+
json({
|
|
1011
|
+
mode: sampler ? "animation" : "static",
|
|
1012
|
+
animation: options.animation ?? null,
|
|
1013
|
+
coverage: "Native layout in world coordinates; excludes camera cropping and script-drawn content.",
|
|
1014
|
+
samples: times.map((time) => ({
|
|
1015
|
+
time,
|
|
1016
|
+
...inspectBoardItems(sampler?.at(time).scene ?? buildBoardScene(document), ids ?? void 0)
|
|
1017
|
+
}))
|
|
1018
|
+
});
|
|
1019
|
+
} finally {
|
|
1020
|
+
renderer.destroy();
|
|
1021
|
+
}
|
|
1022
|
+
} catch (cause) {
|
|
1023
|
+
handleHttp(cause);
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
boards.command("frames <board>").description("List the frames viewers step through, in order, and where each arrow leads").option("--json", "Output as JSON").addHelpText("after", `
|
|
1027
|
+
Order follows placement: rows top to bottom, each left to right. Move a frame to
|
|
1028
|
+
change where it falls. A plain (decoration: none) frame with a label is a page;
|
|
1029
|
+
without one, the frames inside it count. Frames inside pages do not. Left and right continue in reading order past a row's end.
|
|
1030
|
+
Viewers step with N, the arrow keys and swipes; #focus=<frame>&present presents.`).action(async (target, options) => {
|
|
1031
|
+
try {
|
|
1032
|
+
const { document } = await loadBoardDocument(await resolveSpace(boards), target);
|
|
1033
|
+
const regions = boardFrameRegions(buildBoardScene(document));
|
|
1034
|
+
const frames = regions.map((region, index) => ({
|
|
1035
|
+
index: index + 1,
|
|
1036
|
+
id: region.id,
|
|
1037
|
+
label: region.label ?? null,
|
|
1038
|
+
rect: region.rect,
|
|
1039
|
+
...Object.fromEntries(DIRECTIONS.map((direction) => [direction, boardRegionStep(regions, region, direction)?.id ?? null]))
|
|
1040
|
+
}));
|
|
1041
|
+
if (jsonRequested(options)) return json({ frames });
|
|
1042
|
+
table(frames, [
|
|
1043
|
+
{
|
|
1044
|
+
key: "index",
|
|
1045
|
+
label: "#"
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
key: "id",
|
|
1049
|
+
label: "ID"
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
key: "label",
|
|
1053
|
+
label: "Label",
|
|
1054
|
+
format: (value) => value ?? ""
|
|
1055
|
+
},
|
|
1056
|
+
...DIRECTIONS.map((direction) => ({
|
|
1057
|
+
key: direction,
|
|
1058
|
+
label: direction[0]?.toUpperCase() + direction.slice(1),
|
|
1059
|
+
format: (value) => value ?? "–"
|
|
1060
|
+
}))
|
|
1061
|
+
]);
|
|
1062
|
+
} catch (cause) {
|
|
1063
|
+
handleHttp(cause);
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
boards.command("sequence <board>").description("Compile chapters to an apply-ready animation patch; does not write").requiredOption("-i, --input <file>", "JSON with a chapters array; use - for stdin").requiredOption("--animation <id>", "Parent animation id; recompiling replaces its tracks").action(async (target, options) => {
|
|
1067
|
+
try {
|
|
1068
|
+
const input = await readBoardJsonObject(options.input);
|
|
1069
|
+
if (!Array.isArray(input.chapters) || input.chapters.some((chapter) => !chapter || typeof chapter !== "object" || typeof chapter.animation !== "string")) throw new Error("Input needs a chapters array with animation IDs.");
|
|
1070
|
+
const { document } = await loadBoardDocument(await resolveSpace(boards), target);
|
|
1071
|
+
json(boardSequencePatch(document, options.animation, input.chapters));
|
|
1072
|
+
} catch (cause) {
|
|
1073
|
+
handleHttp(cause);
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
boards.command("place <board>").description("Put items or animations on a timeline as clips; prints a patch for apply, does not write").requiredOption("--animation <id>", "Animation to place them in; created when missing").requiredOption("--targets <ids>", "Comma-separated item or animation ids, laid end to end").option("--at <time>", "Where the first one starts", "0").option("--duration <time>", "Length of each; defaults to what is left of the media or animation, else 3s").option("--from <time>", "Where media or an animation starts playing in its own time", "0").option("--rate <number>", "Playback speed of media and animations", "1").option("--together", "Start them all at --at instead of one after another").addHelpText("after", `
|
|
1077
|
+
Each target is shown only during its clip (a visible track); video, audio and
|
|
1078
|
+
animations also play (a props.time or time track), and sound in exports while
|
|
1079
|
+
their time moves forward. Placing a target that is already on the timeline moves it.
|
|
1080
|
+
cohub boards place cut.board --animation cut --targets intro,talk,outro | cohub boards apply cut.board -i -
|
|
1081
|
+
cohub boards place cut.board --animation cut --targets music --at 0 --duration 30s --from 12s`).action(async (target, options) => {
|
|
1082
|
+
try {
|
|
1083
|
+
const targets = options.targets.split(",").map((id) => id.trim()).filter(Boolean);
|
|
1084
|
+
if (!targets.length) throw new Error("--targets needs at least one id.");
|
|
1085
|
+
const rate = Number(options.rate);
|
|
1086
|
+
if (!Number.isFinite(rate) || rate <= 0) throw new Error("--rate must be a positive number.");
|
|
1087
|
+
const spaceId = await resolveSpace(boards);
|
|
1088
|
+
const { document: loaded } = await loadBoardDocument(spaceId, target);
|
|
1089
|
+
const durations = options.duration ? {} : await settleBoardMediaDurations(spaceId, loaded, targets);
|
|
1090
|
+
const document = {
|
|
1091
|
+
...loaded,
|
|
1092
|
+
items: {
|
|
1093
|
+
...loaded.items,
|
|
1094
|
+
...durations
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
const patch = boardPlacePatch(document, options.animation, targets, {
|
|
1098
|
+
at: parseBoardTime(options.at, "--at"),
|
|
1099
|
+
from: parseBoardTime(options.from, "--from"),
|
|
1100
|
+
rate,
|
|
1101
|
+
...options.duration ? { duration: parseBoardTime(options.duration, "--duration") } : {},
|
|
1102
|
+
together: options.together
|
|
1103
|
+
});
|
|
1104
|
+
const items = Object.fromEntries(Object.entries(durations).map(([id, item]) => [id, { props: { snapshot: { durationMs: item.props.snapshot?.durationMs } } }]));
|
|
1105
|
+
json(Object.keys(items).length ? {
|
|
1106
|
+
...patch,
|
|
1107
|
+
items
|
|
1108
|
+
} : patch);
|
|
1109
|
+
} catch (cause) {
|
|
1110
|
+
handleHttp(cause);
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
boards.command("path <target>").description("Sample a polyline into a position track; does not write").requiredOption("-i, --input <file>", "JSON with points, duration (ms), optional at, samples and orient").action(async (target, options) => {
|
|
1114
|
+
try {
|
|
1115
|
+
const input = await readBoardJsonObject(options.input);
|
|
1116
|
+
if (!Array.isArray(input.points) || input.points.some((point) => !point || typeof point !== "object")) throw new Error("Input needs a points array.");
|
|
1117
|
+
if (typeof input.duration !== "number") throw new Error("Input needs duration in milliseconds.");
|
|
1118
|
+
if (input.orient !== void 0 && typeof input.orient !== "boolean") throw new Error("orient must be boolean.");
|
|
1119
|
+
json(boardPathTrack(target, input.points, {
|
|
1120
|
+
duration: input.duration,
|
|
1121
|
+
...input.at === void 0 ? {} : { at: Number(input.at) },
|
|
1122
|
+
...input.samples === void 0 ? {} : { samples: Number(input.samples) },
|
|
1123
|
+
orient: input.orient
|
|
1124
|
+
}));
|
|
1125
|
+
} catch (cause) {
|
|
1126
|
+
handleHttp(cause);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
//#endregion
|
|
1131
|
+
//#region src/commands/boards.ts
|
|
1132
|
+
function boardSchemaField(schema, path) {
|
|
1133
|
+
let field = schema;
|
|
1134
|
+
for (const part of path.split(".")) {
|
|
1135
|
+
const properties = field?.properties;
|
|
1136
|
+
if (!part || !properties || !Object.hasOwn(properties, part)) throw new Error(`Unknown schema field ${path}.`);
|
|
1137
|
+
field = properties[part];
|
|
1138
|
+
}
|
|
1139
|
+
return field;
|
|
1140
|
+
}
|
|
1141
|
+
function withJson(command) {
|
|
1142
|
+
return command.option("--json", "Output as JSON");
|
|
1143
|
+
}
|
|
1144
|
+
function parseNumber(value, name, options = {}) {
|
|
1145
|
+
if (!value.trim()) throw new Error(`${name} must be a finite number`);
|
|
1146
|
+
const parsed = Number(value);
|
|
1147
|
+
if (!Number.isFinite(parsed)) throw new Error(`${name} must be a finite number`);
|
|
1148
|
+
if (options.integer && !Number.isSafeInteger(parsed)) throw new Error(`${name} must be an integer`);
|
|
1149
|
+
if (options.min !== void 0 && parsed < options.min) throw new Error(`${name} must be at least ${options.min}`);
|
|
1150
|
+
if (options.max !== void 0 && parsed > options.max) throw new Error(`${name} must be at most ${options.max}`);
|
|
1151
|
+
return parsed;
|
|
1152
|
+
}
|
|
1153
|
+
function parseRect(value, name = "--rect") {
|
|
1154
|
+
const parts = value.split(",").map((part) => part.trim());
|
|
1155
|
+
if (parts.length !== 4) throw new Error(`${name} must be x,y,width,height`);
|
|
1156
|
+
const [x, y, width, height] = parts.map((part, index) => parseNumber(part, `${name} ${[
|
|
1157
|
+
"x",
|
|
1158
|
+
"y",
|
|
1159
|
+
"width",
|
|
1160
|
+
"height"
|
|
1161
|
+
][index]}`));
|
|
1162
|
+
if (width <= 0 || height <= 0) throw new Error(`${name} width and height must be greater than zero`);
|
|
1163
|
+
return {
|
|
1164
|
+
x,
|
|
1165
|
+
y,
|
|
1166
|
+
width,
|
|
1167
|
+
height
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function list(value) {
|
|
1171
|
+
const entries = value?.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
1172
|
+
return entries?.length ? entries : void 0;
|
|
1173
|
+
}
|
|
1174
|
+
async function boardClient(boards, target, spaceId) {
|
|
1175
|
+
spaceId ??= await resolveSpace(boards);
|
|
1176
|
+
return createClient().space(spaceId).boards.open(target);
|
|
1177
|
+
}
|
|
1178
|
+
/** A patch from an inline argument, a file, or stdin (`-`). */
|
|
1179
|
+
async function readPatch(inline, input, maxBytes) {
|
|
1180
|
+
if (inline !== void 0 && input !== void 0) throw new Error("Pass the patch inline or with --input, not both.");
|
|
1181
|
+
if (inline !== void 0) return parseBoardJsonObject(inline, "patch");
|
|
1182
|
+
if (input !== void 0) return await readBoardJsonObject(input, maxBytes);
|
|
1183
|
+
throw new Error("Pass a patch inline or with --input <file|->.");
|
|
1184
|
+
}
|
|
1185
|
+
function describeChanges(result) {
|
|
1186
|
+
const parts = [
|
|
1187
|
+
result.changed.board ? "board" : null,
|
|
1188
|
+
result.changed.items.length ? `${result.changed.items.length} item${result.changed.items.length === 1 ? "" : "s"}` : null,
|
|
1189
|
+
result.changed.animations.length ? `${result.changed.animations.length} animation${result.changed.animations.length === 1 ? "" : "s"}` : null
|
|
1190
|
+
].filter(Boolean);
|
|
1191
|
+
return parts.length ? parts.join(", ") : "nothing";
|
|
1192
|
+
}
|
|
1193
|
+
function showApplied(result) {
|
|
1194
|
+
if (result.status === "validated") ok(`Valid: would change ${describeChanges(result)}`);
|
|
1195
|
+
else if (result.status === "unchanged") ok(`Unchanged at version ${result.version}`);
|
|
1196
|
+
else ok(`Applied version ${result.version}${result.replayed ? " (replayed)" : ""}: ${describeChanges(result)}`);
|
|
1197
|
+
for (const diagnostic of result.diagnostics) console.log(` ! ${diagnostic.path}: ${diagnostic.message}`);
|
|
1198
|
+
}
|
|
1199
|
+
function showPlayback(playback) {
|
|
1200
|
+
if (!playback) {
|
|
1201
|
+
ok("Stopped");
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
table([{
|
|
1205
|
+
...playback,
|
|
1206
|
+
position: formatBoardTime(Math.round(playback.position))
|
|
1207
|
+
}], [
|
|
1208
|
+
{
|
|
1209
|
+
key: "animationId",
|
|
1210
|
+
label: "Animation"
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
key: "status",
|
|
1214
|
+
label: "Status"
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
key: "position",
|
|
1218
|
+
label: "Position"
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
key: "timeScale",
|
|
1222
|
+
label: "Speed"
|
|
1223
|
+
}
|
|
1224
|
+
]);
|
|
1225
|
+
}
|
|
1226
|
+
const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
1227
|
+
async function runExportTask(boards, options) {
|
|
1228
|
+
try {
|
|
1229
|
+
const command = ["cohub", ...process.argv.slice(2).filter((arg) => arg !== "--async")].map(shellQuote).join(" ");
|
|
1230
|
+
const { taskRunId } = await createClient().space(await resolveSpace(boards)).runCommand({ command });
|
|
1231
|
+
if (jsonRequested(options)) return json({
|
|
1232
|
+
taskRunId,
|
|
1233
|
+
command
|
|
1234
|
+
});
|
|
1235
|
+
ok(`Exporting as Task ${taskRunId}`);
|
|
1236
|
+
console.log(` Follow it with: cohub tasks get ${taskRunId}`);
|
|
1237
|
+
} catch (cause) {
|
|
1238
|
+
handleHttp(cause);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
async function readBoardInputs(spaceId, path) {
|
|
1242
|
+
const { readSpaceFileBytes } = await import("./board-export2.js");
|
|
1243
|
+
return new TextDecoder().decode((await readSpaceFileBytes(createClient(), spaceId, path)).bytes);
|
|
1244
|
+
}
|
|
1245
|
+
function parseSize(value) {
|
|
1246
|
+
const size = /^(\d+)x(\d+)$/.exec(value);
|
|
1247
|
+
if (!size?.[1] || !size[2]) throw new Error("--size must be widthxheight, e.g. 1600x900.");
|
|
1248
|
+
return {
|
|
1249
|
+
width: parseNumber(size[1], "width", {
|
|
1250
|
+
min: 1,
|
|
1251
|
+
max: 8192
|
|
1252
|
+
}),
|
|
1253
|
+
height: parseNumber(size[2], "height", {
|
|
1254
|
+
min: 1,
|
|
1255
|
+
max: 8192
|
|
1256
|
+
})
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
/** One region flag at most: being told to pick beats guessing which one wins. */
|
|
1260
|
+
function parseExportRegion(options) {
|
|
1261
|
+
const chosen = [
|
|
1262
|
+
options.camera && "--camera",
|
|
1263
|
+
options.frame && "--frame",
|
|
1264
|
+
options.items && "--items",
|
|
1265
|
+
options.rect && "--rect"
|
|
1266
|
+
].filter(Boolean);
|
|
1267
|
+
if (chosen.length > 1) throw new Error(`Pick one region: ${chosen.join(", ")} cannot be combined.`);
|
|
1268
|
+
if (options.frame) return {
|
|
1269
|
+
kind: "frame",
|
|
1270
|
+
id: options.frame
|
|
1271
|
+
};
|
|
1272
|
+
if (options.items) {
|
|
1273
|
+
const ids = list(options.items);
|
|
1274
|
+
if (!ids) throw new Error("--items needs at least one item id.");
|
|
1275
|
+
return {
|
|
1276
|
+
kind: "items",
|
|
1277
|
+
ids
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
if (options.rect) return {
|
|
1281
|
+
kind: "rect",
|
|
1282
|
+
rect: parseRect(options.rect)
|
|
1283
|
+
};
|
|
1284
|
+
return { kind: "all" };
|
|
1285
|
+
}
|
|
1286
|
+
const BOARD_EXPORT_FORMATS = [
|
|
1287
|
+
"png",
|
|
1288
|
+
"jpeg",
|
|
1289
|
+
"webp"
|
|
1290
|
+
];
|
|
1291
|
+
const BOARD_VIDEO_FORMATS = ["mp4", "webm"];
|
|
1292
|
+
function videoFormatFromPath(path) {
|
|
1293
|
+
const lower = path.toLowerCase();
|
|
1294
|
+
return lower.endsWith(".webm") ? "webm" : lower.endsWith(".mp4") ? "mp4" : null;
|
|
1295
|
+
}
|
|
1296
|
+
function formatFromPath(path) {
|
|
1297
|
+
const lower = path.toLowerCase();
|
|
1298
|
+
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "jpeg";
|
|
1299
|
+
if (lower.endsWith(".webp")) return "webp";
|
|
1300
|
+
return "png";
|
|
1301
|
+
}
|
|
1302
|
+
function parseExportFormat(options, outPath) {
|
|
1303
|
+
if (!options.format) return formatFromPath(outPath);
|
|
1304
|
+
const format = options.format.toLowerCase();
|
|
1305
|
+
if (!BOARD_EXPORT_FORMATS.includes(format)) throw new Error(`--format must be one of ${BOARD_EXPORT_FORMATS.join(", ")}.`);
|
|
1306
|
+
return format;
|
|
1307
|
+
}
|
|
1308
|
+
function parseChoice(value, name, choices) {
|
|
1309
|
+
const chosen = value ?? choices[0];
|
|
1310
|
+
if (!choices.includes(chosen)) throw new Error(`${name} must be ${choices.join(" or ")}.`);
|
|
1311
|
+
return chosen;
|
|
1312
|
+
}
|
|
1313
|
+
/** `frames/%04d.png` → `frames/0012.png`; a sequence needs a `%d` placeholder. */
|
|
1314
|
+
function framePath(pattern, index) {
|
|
1315
|
+
return pattern.replace(/%(0?)(\d*)d/, (_match, zero, width) => String(index).padStart(Number(width || 0), zero ? "0" : " "));
|
|
1316
|
+
}
|
|
1317
|
+
function registerExportCommand(boards) {
|
|
1318
|
+
withJson(boards.command("export <board>").description("Render a Board to an image, or an animation to a frame sequence").requiredOption("-o, --out <file>", "Output file; the extension picks the format. Sequences need %d, e.g. frames/%04d.png").option("--at <time>", "A moment, comma-separated moments, or start:end:step").option("--camera", "Follow the animation camera").option("--size <widthxheight>", "Camera output in pixels; frames keep their own size", "1600x900").option("--animation <id>", "Animation the --at times refer to").option("--frame <item-id>", "Export one frame as a page").option("--items <ids>", "Comma-separated item ids").option("--rect <rect>", "World rect as x,y,width,height").option("--scale <factor>", "Output pixels per board unit", "2").option("--padding <units>", "Padding around the content in board units").option("--theme <name>", `Cohub theme: ${BOARD_THEME_IDS.join(", ")}`, "dark").option("--paper <mode>", "Output paper: paper or transparent", "paper").option("--format <format>", `Override the format (${BOARD_EXPORT_FORMATS.join(", ")}, ${BOARD_VIDEO_FORMATS.join(", ")})`).option("--quality <q>", "JPEG/WebP quality from 0 to 1", "0.92").option("--fps <rate>", "Video frame rate; defaults to the --at step").option("--image-memory <mib>", "Decoded image memory budget in MiB", String(256)).option("--no-images", "Draw placeholders instead of downloading images").option("--renderer <renderer>", "auto draws in Node and uses local Chrome for shaders; canvas or gpu forces one", "auto").option("--force", "Replace existing output files").option("--timeout <time>", "Fail a frame that takes longer, naming the scripts still running", "2m").option("--inputs <file>", "A Space file of recorded browser input for scripts to replay from time 0").option("--async", "Run as a Task in the Space's sandbox and return at once; paths are Space paths")).addHelpText("after", `
|
|
1319
|
+
Shaders draw in a shared headless Chrome that stays up a few minutes between calls;
|
|
1320
|
+
Boards without shaders never start it. Set COHUB_BOARD_GPU_DAEMON=0 to start one per call.
|
|
1321
|
+
|
|
1322
|
+
Examples:
|
|
1323
|
+
cohub boards export plan.board -o plan.png
|
|
1324
|
+
cohub boards export plan.board --animation intro --at 0:20s:40ms -o intro.mp4 --async
|
|
1325
|
+
cohub boards export plan.board --frame s2 -o slide-2.png
|
|
1326
|
+
cohub boards export plan.board --animation lecture --at 4.5s -o moment.png
|
|
1327
|
+
cohub boards export plan.board --animation lecture --at 0:6s:40ms -o frames/%04d.png
|
|
1328
|
+
|
|
1329
|
+
Scripts see the exported area as their view (viewchange), and emit() between them is
|
|
1330
|
+
delivered within the same moment, in document order. Exports have no network or
|
|
1331
|
+
device; --inputs replays a recording made with Record input in the Board's Scripts panel. --frame draws the frame as a
|
|
1332
|
+
page: its fill and shaders, without its outline and label.`).action(async (target, options) => {
|
|
1333
|
+
if (options.async) return runExportTask(boards, options);
|
|
1334
|
+
const controller = new AbortController();
|
|
1335
|
+
const cancel = () => controller.abort(/* @__PURE__ */ new Error("Export cancelled."));
|
|
1336
|
+
process.once("SIGINT", cancel);
|
|
1337
|
+
try {
|
|
1338
|
+
const out = options.out;
|
|
1339
|
+
const times = options.at ? parseBoardTimes(options.at) : void 0;
|
|
1340
|
+
let camera;
|
|
1341
|
+
if (options.camera) {
|
|
1342
|
+
if (!options.animation || !times) throw new Error("--camera needs --animation and --at.");
|
|
1343
|
+
camera = parseSize(options.size ?? "1600x900");
|
|
1344
|
+
}
|
|
1345
|
+
const progress = (completed, total) => {
|
|
1346
|
+
if (!jsonRequested(options) && (completed === total || completed % 30 === 0)) process.stderr.write(`Rendered ${completed}/${total} frames\n`);
|
|
1347
|
+
};
|
|
1348
|
+
const imageMemoryMiB = parseNumber(options.imageMemory ?? String(256), "--image-memory", {
|
|
1349
|
+
min: 1,
|
|
1350
|
+
max: 65536,
|
|
1351
|
+
integer: true
|
|
1352
|
+
});
|
|
1353
|
+
const onPlan = ({ width, height, frames }) => {
|
|
1354
|
+
if (!jsonRequested(options)) process.stderr.write(`Rendering ${width}x${height}, ${frames} frame(s)\n`);
|
|
1355
|
+
};
|
|
1356
|
+
const spaceId = await resolveSpace(boards);
|
|
1357
|
+
const inputs = options.inputs ? await readBoardInputs(spaceId, options.inputs) : void 0;
|
|
1358
|
+
const pathVideoFormat = videoFormatFromPath(out);
|
|
1359
|
+
const requestedFormat = options.format?.toLowerCase();
|
|
1360
|
+
if (requestedFormat && ![...BOARD_EXPORT_FORMATS, ...BOARD_VIDEO_FORMATS].includes(requestedFormat)) throw new Error(`--format must be one of ${[...BOARD_EXPORT_FORMATS, ...BOARD_VIDEO_FORMATS].join(", ")}.`);
|
|
1361
|
+
const videoFormat = requestedFormat ? BOARD_VIDEO_FORMATS.includes(requestedFormat) ? requestedFormat : null : pathVideoFormat;
|
|
1362
|
+
const sequence = (times?.length ?? 0) > 1;
|
|
1363
|
+
if (sequence && !videoFormat && !/%0?\d*d/.test(out)) throw new Error("A range needs %d in --out, e.g. frames/%04d.png.");
|
|
1364
|
+
if (videoFormat) {
|
|
1365
|
+
if (!times || times.length < 2) throw new Error("Video export needs an --at range.");
|
|
1366
|
+
const step = times[1] - times[0];
|
|
1367
|
+
const fps = options.fps ? parseNumber(options.fps, "--fps", {
|
|
1368
|
+
min: .01,
|
|
1369
|
+
max: 240
|
|
1370
|
+
}) : 1e3 / step;
|
|
1371
|
+
if (existsSync(out) && !options.force) throw new Error(`${out} already exists; use --force to replace it.`);
|
|
1372
|
+
await mkdir(dirname(out), { recursive: true });
|
|
1373
|
+
const { runBoardVideoExport } = await import("./board-export2.js");
|
|
1374
|
+
const result = await runBoardVideoExport({
|
|
1375
|
+
spaceId,
|
|
1376
|
+
target,
|
|
1377
|
+
...inputs ? { inputs } : {},
|
|
1378
|
+
camera,
|
|
1379
|
+
timeoutMs: parseBoardTime(options.timeout ?? "2m", "--timeout"),
|
|
1380
|
+
onProgress: progress,
|
|
1381
|
+
onPlan,
|
|
1382
|
+
imageMemoryMiB,
|
|
1383
|
+
signal: controller.signal,
|
|
1384
|
+
force: options.force,
|
|
1385
|
+
region: parseExportRegion(options),
|
|
1386
|
+
times,
|
|
1387
|
+
...options.animation ? { animation: options.animation } : {},
|
|
1388
|
+
scale: parseNumber(options.scale ?? "2", "--scale", {
|
|
1389
|
+
min: .01,
|
|
1390
|
+
max: 16
|
|
1391
|
+
}),
|
|
1392
|
+
...options.padding === void 0 ? {} : { padding: parseNumber(options.padding, "--padding", { min: 0 }) },
|
|
1393
|
+
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
1394
|
+
background: parseChoice(options.paper, "--paper", ["paper", "transparent"]),
|
|
1395
|
+
format: videoFormat,
|
|
1396
|
+
fps,
|
|
1397
|
+
output: out,
|
|
1398
|
+
quality: parseNumber(options.quality ?? "0.92", "--quality", {
|
|
1399
|
+
min: 0,
|
|
1400
|
+
max: 1
|
|
1401
|
+
}),
|
|
1402
|
+
withImages: options.images !== false,
|
|
1403
|
+
renderer: parseChoice(options.renderer, "--renderer", BOARD_EXPORT_RENDERERS)
|
|
1404
|
+
});
|
|
1405
|
+
if (jsonRequested(options)) return json({
|
|
1406
|
+
file: out,
|
|
1407
|
+
...result
|
|
1408
|
+
});
|
|
1409
|
+
ok(`Exported ${result.width}×${result.height} ${videoFormat.toUpperCase()} to ${out}`);
|
|
1410
|
+
for (const warning of result.warnings) console.log(` ! ${warning}`);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
const written = [];
|
|
1414
|
+
for (let index = 0; index < (times?.length ?? 1); index++) {
|
|
1415
|
+
const path = sequence ? framePath(out, index) : out;
|
|
1416
|
+
if (!options.force && existsSync(path)) throw new Error(`${path} already exists; use --force to replace it.`);
|
|
1417
|
+
}
|
|
1418
|
+
const { runBoardExport } = await import("./board-export2.js");
|
|
1419
|
+
const result = await runBoardExport({
|
|
1420
|
+
spaceId,
|
|
1421
|
+
target,
|
|
1422
|
+
...inputs ? { inputs } : {},
|
|
1423
|
+
camera,
|
|
1424
|
+
timeoutMs: parseBoardTime(options.timeout ?? "2m", "--timeout"),
|
|
1425
|
+
onProgress: progress,
|
|
1426
|
+
onPlan,
|
|
1427
|
+
imageMemoryMiB,
|
|
1428
|
+
signal: controller.signal,
|
|
1429
|
+
onFrame: async (frame, index) => {
|
|
1430
|
+
const path = sequence ? framePath(out, index) : out;
|
|
1431
|
+
await mkdir(dirname(path), { recursive: true });
|
|
1432
|
+
await writeBoardOutput(path, frame.bytes, Boolean(options.force));
|
|
1433
|
+
written.push({
|
|
1434
|
+
path,
|
|
1435
|
+
time: frame.time,
|
|
1436
|
+
width: frame.width,
|
|
1437
|
+
height: frame.height,
|
|
1438
|
+
bytes: frame.bytes.length
|
|
1439
|
+
});
|
|
1440
|
+
},
|
|
1441
|
+
region: parseExportRegion(options),
|
|
1442
|
+
...times ? { times } : {},
|
|
1443
|
+
...options.animation ? { animation: options.animation } : {},
|
|
1444
|
+
scale: parseNumber(options.scale ?? "2", "--scale", {
|
|
1445
|
+
min: .01,
|
|
1446
|
+
max: 16
|
|
1447
|
+
}),
|
|
1448
|
+
...options.padding === void 0 ? {} : { padding: parseNumber(options.padding, "--padding", { min: 0 }) },
|
|
1449
|
+
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
1450
|
+
background: parseChoice(options.paper, "--paper", ["paper", "transparent"]),
|
|
1451
|
+
format: parseExportFormat(options, out),
|
|
1452
|
+
quality: parseNumber(options.quality ?? "0.92", "--quality", {
|
|
1453
|
+
min: 0,
|
|
1454
|
+
max: 1
|
|
1455
|
+
}),
|
|
1456
|
+
withImages: options.images !== false,
|
|
1457
|
+
renderer: parseChoice(options.renderer, "--renderer", BOARD_EXPORT_RENDERERS)
|
|
1458
|
+
});
|
|
1459
|
+
if (!result) return error("Nothing to export: the region contains no items.");
|
|
1460
|
+
if (jsonRequested(options)) return json({
|
|
1461
|
+
files: written,
|
|
1462
|
+
warnings: result.warnings
|
|
1463
|
+
});
|
|
1464
|
+
const first = written[0];
|
|
1465
|
+
if (first) {
|
|
1466
|
+
const what = sequence ? `${written.length} frames` : parseExportFormat(options, out).toUpperCase();
|
|
1467
|
+
ok(`Exported ${first.width}×${first.height} ${what} to ${sequence ? dirname(out) || "." : out}`);
|
|
1468
|
+
}
|
|
1469
|
+
for (const warning of result.warnings) console.log(` ! ${warning}`);
|
|
1470
|
+
} catch (cause) {
|
|
1471
|
+
handleHttp(cause);
|
|
1472
|
+
} finally {
|
|
1473
|
+
process.removeListener("SIGINT", cancel);
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
function registerSimulateCommand(boards) {
|
|
1478
|
+
withJson(boards.command("simulate <board> [steps]").description("Run a Board's scripts locally through input steps; nothing is saved").option("-i, --input <file>", "Steps JSON; - for stdin").option("-o, --out <file>", "Also render the result, screen UI included; the extension picks the format").option("--follower", "Simulate an editor that does not write autonomous commits").option("--timeout <time>", "Give up after this long and report what is still running", "2m").option("--frame <item-id>", "Render one frame").option("--items <ids>", "Render comma-separated item ids").option("--rect <rect>", "Render a world rect as x,y,width,height").option("--scale <factor>", "Output pixels per board unit", "2").option("--theme <name>", `Cohub theme: ${BOARD_THEME_IDS.join(", ")}`, "dark").option("--no-images", "Draw placeholders instead of downloading images").option("--force", "Replace an existing output file")).addHelpText("after", `
|
|
1479
|
+
Steps are {"steps": [...]}, points in board coordinates, run on a virtual clock:
|
|
1480
|
+
{"wait": "500ms"} {"tool": "draw"} {"tap": [x, y]} {"drag": [[x, y], ...], "pointerType": "pen"}
|
|
1481
|
+
{"pointer": "down", "at": [x, y]} {"key": "Enter"} {"select": ["id"]}
|
|
1482
|
+
{"input": "browser:devicemotion", "data": {...}} {"inputs": "takes/flick.json"}
|
|
1483
|
+
{"tool": "play"} acts like an App visitor: drags move unlocked items, empty space pans,
|
|
1484
|
+
script regions take every press, and keys reach scripts that listen for them.
|
|
1485
|
+
Every source (motion, gamepad, microphone, camera, location) is on. An input step
|
|
1486
|
+
delivers one browser event to the scripts listening, shaped as \`cohub boards schema
|
|
1487
|
+
script\` describes; an inputs step replays a recording on the virtual clock.
|
|
1488
|
+
|
|
1489
|
+
Shaders are compiled with a local Chrome, Chromium or Edge when one is found, before
|
|
1490
|
+
the steps run; their errors join the scripts' errors and stop the run.
|
|
1491
|
+
Each tap and drag reports where it landed (a script's hit region, a selection handle,
|
|
1492
|
+
an item, or empty board) and what took it (a script, move, resize, rotate, select box).
|
|
1493
|
+
|
|
1494
|
+
Examples:
|
|
1495
|
+
cohub boards simulate farm.board '{"steps":[{"wait":"2s"}]}' -o farm.png
|
|
1496
|
+
cohub boards simulate farm.board -i steps.json --json`).action(async (target, inline, options) => {
|
|
1497
|
+
try {
|
|
1498
|
+
if (inline !== void 0 && options.input !== void 0) throw new Error("Pass steps inline or with --input, not both.");
|
|
1499
|
+
const input = inline !== void 0 ? parseBoardJsonObject(inline, "steps") : options.input !== void 0 ? await readBoardJsonObject(options.input) : { steps: [] };
|
|
1500
|
+
const { parseBoardSimulationSteps, runBoardSimulation } = await import("./board-simulate.js");
|
|
1501
|
+
const steps = parseBoardSimulationSteps(input.steps);
|
|
1502
|
+
const out = options.out;
|
|
1503
|
+
if (out && !options.force && existsSync(out)) throw new Error(`${out} already exists; use --force to replace it.`);
|
|
1504
|
+
const result = await runBoardSimulation({
|
|
1505
|
+
spaceId: await resolveSpace(boards),
|
|
1506
|
+
target,
|
|
1507
|
+
steps,
|
|
1508
|
+
leader: !options.follower,
|
|
1509
|
+
timeoutMs: parseBoardTime(options.timeout ?? "2m", "--timeout"),
|
|
1510
|
+
...out ? { image: {
|
|
1511
|
+
region: parseExportRegion(options),
|
|
1512
|
+
scale: parseNumber(options.scale ?? "2", "--scale", {
|
|
1513
|
+
min: .01,
|
|
1514
|
+
max: 16
|
|
1515
|
+
}),
|
|
1516
|
+
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
1517
|
+
format: parseExportFormat(options, out),
|
|
1518
|
+
withImages: options.images !== false
|
|
1519
|
+
} } : {}
|
|
1520
|
+
});
|
|
1521
|
+
if (out && result.image) {
|
|
1522
|
+
await mkdir(dirname(out), { recursive: true });
|
|
1523
|
+
await writeBoardOutput(out, result.image.bytes, Boolean(options.force));
|
|
1524
|
+
}
|
|
1525
|
+
const { image, ...summary } = result;
|
|
1526
|
+
if (jsonRequested(options)) return json({
|
|
1527
|
+
...summary,
|
|
1528
|
+
...out && image ? {
|
|
1529
|
+
file: out,
|
|
1530
|
+
width: image.width,
|
|
1531
|
+
height: image.height
|
|
1532
|
+
} : {}
|
|
1533
|
+
});
|
|
1534
|
+
const changed = Object.keys(result.changes.items ?? {}).length;
|
|
1535
|
+
ok(`Simulated ${formatBoardTime(result.time)}: ${result.commits} commit${result.commits === 1 ? "" : "s"}, ${changed} item${changed === 1 ? "" : "s"} changed (not saved)`);
|
|
1536
|
+
for (const press of result.presses) console.log(` step ${press.step + 1}: ${describePress(press)}`);
|
|
1537
|
+
for (const [id, message] of Object.entries(result.errors)) console.log(` ! ${id}: ${message.split("\n")[0]}`);
|
|
1538
|
+
for (const warning of result.warnings) console.log(` ! ${warning}`);
|
|
1539
|
+
if (result.shaders && !result.shaders.compiled) console.log(" Shaders were checked but not compiled; install Chrome, Chromium or Edge, or set COHUB_CHROME, to compile them.");
|
|
1540
|
+
if (out && image) console.log(` Rendered ${image.width}×${image.height} to ${out}`);
|
|
1541
|
+
else if (out) console.log(" ! Nothing to render: the region contains no items.");
|
|
1542
|
+
} catch (cause) {
|
|
1543
|
+
handleHttp(cause);
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
function describePress({ down, taken }) {
|
|
1548
|
+
return `pressed on ${down.on === "script" ? `script ${down.owner}/${down.target}` : down.on === "handle" ? `${down.handle} handle` : down.on === "item" ? `${down.type} ${down.id}` : `empty board${down.under ? ` over ${down.under}` : ""}`}, taken by ${taken}`;
|
|
1549
|
+
}
|
|
1550
|
+
function registerProfileCommand(boards) {
|
|
1551
|
+
withJson(boards.command("profile <board>").description("Measure what a Board costs to draw, shader by shader, and say what to change").option("--at <time>", "A moment of --animation, or a script time without one", "2s").option("--animation <id>", "Animation --at refers to").option("--frame <item-id>", "Profile one frame").option("--items <ids>", "Profile comma-separated item ids").option("--rect <rect>", "Profile a world rect as x,y,width,height").option("--size <widthxheight>", "Fit the region into this many pixels, like a screen", "1600x900").option("--frames <count>", "Frames to time per measurement", "5").option("--rounds <count>", "Measurements per shader owner; reports their median and range", "3").option("--budget <time>", "Time the measurements may take; past it, size and frames go down", "60s").option("--no-images", "Draw placeholders instead of downloading images")).addHelpText("after", `
|
|
1552
|
+
Draws in a headless Chrome; without a GPU it uses software WebGL (reported as
|
|
1553
|
+
"software"), so compare the numbers with each other rather than with a real display.
|
|
1554
|
+
Scripts receive the profiled view as viewchange, as on a screen of --size.
|
|
1555
|
+
|
|
1556
|
+
Examples:
|
|
1557
|
+
cohub boards profile demo.board
|
|
1558
|
+
cohub boards profile demo.board --rect 0,0,1600,900 --at 8s --json`).action(async (target, options) => {
|
|
1559
|
+
try {
|
|
1560
|
+
const { profileBoard } = await import("./board-profile.js");
|
|
1561
|
+
const profile = await profileBoard({
|
|
1562
|
+
spaceId: await resolveSpace(boards),
|
|
1563
|
+
target,
|
|
1564
|
+
time: parseBoardTime(options.at ?? "2s", "--at"),
|
|
1565
|
+
...options.animation ? { animation: options.animation } : {},
|
|
1566
|
+
region: parseExportRegion(options),
|
|
1567
|
+
size: parseSize(options.size ?? "1600x900"),
|
|
1568
|
+
frames: parseNumber(options.frames ?? "5", "--frames", {
|
|
1569
|
+
min: 3,
|
|
1570
|
+
max: 240,
|
|
1571
|
+
integer: true
|
|
1572
|
+
}),
|
|
1573
|
+
rounds: parseNumber(options.rounds ?? "3", "--rounds", {
|
|
1574
|
+
min: 1,
|
|
1575
|
+
max: 20,
|
|
1576
|
+
integer: true
|
|
1577
|
+
}),
|
|
1578
|
+
budgetMs: parseBoardTime(options.budget ?? "60s", "--budget"),
|
|
1579
|
+
withImages: options.images !== false
|
|
1580
|
+
});
|
|
1581
|
+
if (jsonRequested(options)) return json(profile);
|
|
1582
|
+
const ms = (value) => `${value.toFixed(1)} ms`;
|
|
1583
|
+
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`);
|
|
1584
|
+
if (profile.reduced) 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.`);
|
|
1585
|
+
console.log(` ${profile.rounds} round${profile.rounds === 1 ? "" : "s"} × ${profile.frames} frames in ${(profile.elapsedMs / 1e3).toFixed(1)} s; owner cost is the median, with the range across rounds`);
|
|
1586
|
+
for (const owner of profile.owners) {
|
|
1587
|
+
const traits = [
|
|
1588
|
+
owner.filter !== "none" && `filter ${owner.filter}`,
|
|
1589
|
+
owner.sprites && `${owner.sprites} sprites`,
|
|
1590
|
+
owner.state && `state ${owner.state.width}×${owner.state.height}`
|
|
1591
|
+
].filter(Boolean);
|
|
1592
|
+
const range = profile.rounds > 1 ? ` (${owner.range[0].toFixed(0)}–${owner.range[1].toFixed(0)})` : "";
|
|
1593
|
+
console.log(` ${owner.id.padEnd(24)} ${ms(owner.ms).padStart(9)}${range.padEnd(12)}${traits.length ? ` ${traits.join(", ")}` : ""}`);
|
|
1594
|
+
}
|
|
1595
|
+
for (const hint of profile.hints) console.log(` ! ${hint}`);
|
|
1596
|
+
} catch (cause) {
|
|
1597
|
+
handleHttp(cause);
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
boards.command("gpu-daemon", { hidden: true }).requiredOption("--browser <path>").action(async (options) => {
|
|
1601
|
+
const { serveBoardGpu } = await import("./daemon2.js");
|
|
1602
|
+
await serveBoardGpu(options.browser);
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
function registerBoards(program) {
|
|
1606
|
+
const boards = program.command("boards").description("Read, write, animate and export Boards (by id or .board path)").addHelpText("after", `
|
|
1607
|
+
A Board is one JSON document: { board, items, animations }.
|
|
1608
|
+
get read it
|
|
1609
|
+
apply write it with a JSON Merge Patch; null deletes
|
|
1610
|
+
schema the fields of any part and what they mean; also the script API
|
|
1611
|
+
examples starter documents and a custom script module
|
|
1612
|
+
preset tracks for a preset motion, ready to apply
|
|
1613
|
+
sequence join chapter animations into one timeline
|
|
1614
|
+
path sample a polyline into a position track
|
|
1615
|
+
inspect measure items and report layout hints
|
|
1616
|
+
frames the frames viewers step through, in order
|
|
1617
|
+
export render an image, a frame sequence or a video
|
|
1618
|
+
play shared playback; also pause, resume, next, seek, stop
|
|
1619
|
+
watch stream changes and playback
|
|
1620
|
+
history list versions, or restore one
|
|
1621
|
+
diff what changed between two versions
|
|
1622
|
+
Times are milliseconds; 500ms, 12.5s and 2m also work on the command line.`);
|
|
1623
|
+
withJson(boards.command("create <path>").description("Create a Board file, optionally with an initial document").option("--title <title>", "Board title").option("-i, --input <file>", "Initial document JSON; - for stdin").option("--mutation-id <id>", "Stable id for safe retries")).addHelpText("after", `
|
|
1624
|
+
cohub boards examples lesson > lesson.json
|
|
1625
|
+
cohub boards create lesson.board -i lesson.json`).action(async (path, options) => {
|
|
1626
|
+
try {
|
|
1627
|
+
const spaceId = await resolveSpace(boards);
|
|
1628
|
+
const read = options.input ? await readBoardJsonObject(options.input, BOARD_CREATE_INPUT_MAX_BYTES) : void 0;
|
|
1629
|
+
const document = read && await settleBoardPatch(spaceId, read, async () => ({}));
|
|
1630
|
+
const input = {
|
|
1631
|
+
path,
|
|
1632
|
+
mutationId: options.mutationId ?? randomUUID(),
|
|
1633
|
+
...options.title ? { title: options.title } : {},
|
|
1634
|
+
...document ? { document } : {}
|
|
1635
|
+
};
|
|
1636
|
+
const result = await createClient().space(spaceId).boards.create(input);
|
|
1637
|
+
if (jsonRequested(options)) return json({
|
|
1638
|
+
path,
|
|
1639
|
+
id: result.id,
|
|
1640
|
+
title: result.title,
|
|
1641
|
+
version: result.version
|
|
1642
|
+
});
|
|
1643
|
+
ok(`Created ${path}`);
|
|
1644
|
+
table([{
|
|
1645
|
+
path,
|
|
1646
|
+
id: result.id,
|
|
1647
|
+
title: result.title,
|
|
1648
|
+
version: result.version
|
|
1649
|
+
}], [
|
|
1650
|
+
{
|
|
1651
|
+
key: "path",
|
|
1652
|
+
label: "Path"
|
|
1653
|
+
},
|
|
1654
|
+
{
|
|
1655
|
+
key: "id",
|
|
1656
|
+
label: "ID"
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
key: "title",
|
|
1660
|
+
label: "Title"
|
|
1661
|
+
},
|
|
1662
|
+
{
|
|
1663
|
+
key: "version",
|
|
1664
|
+
label: "Version"
|
|
1665
|
+
}
|
|
1666
|
+
]);
|
|
1667
|
+
} catch (cause) {
|
|
1668
|
+
handleHttp(cause);
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
boards.command("get <board>").description("Print the Board document as JSON").option("--only <sections>", "board, items, animations (comma-separated)").option("--items <ids>", "Only these items").option("--within <frame-id>", "A frame and everything inside it").option("--rect <rect>", "Items intersecting x,y,width,height").option("--animations <ids>", "Only these animations").option("--limit <n>", "Page size for items").option("--cursor <cursor>", "Continue from a previous page's next").option("--since <version>", "Only the changes after this version; the whole Board when they are unavailable").addHelpText("after", `
|
|
1672
|
+
cohub boards get plan.board
|
|
1673
|
+
cohub boards get plan.board --within s2
|
|
1674
|
+
cohub boards get plan.board --only board
|
|
1675
|
+
cohub boards get plan.board --since 12`).action(async (target, options) => {
|
|
1676
|
+
try {
|
|
1677
|
+
const only = list(options.only);
|
|
1678
|
+
if (only?.some((section) => section !== "board" && section !== "items" && section !== "animations")) throw new Error("--only takes board, items, animations, or a combination.");
|
|
1679
|
+
const sections = only ? new Set(only) : null;
|
|
1680
|
+
const input = {
|
|
1681
|
+
...only ? { only: only.filter((section) => section !== "board") } : {},
|
|
1682
|
+
...list(options.items) ? { items: list(options.items) } : {},
|
|
1683
|
+
...options.within ? { within: options.within } : {},
|
|
1684
|
+
...options.rect ? { rect: parseRect(options.rect) } : {},
|
|
1685
|
+
...list(options.animations) ? { animations: list(options.animations) } : {},
|
|
1686
|
+
...options.limit ? { limit: parseNumber(options.limit, "--limit", {
|
|
1687
|
+
min: 1,
|
|
1688
|
+
integer: true
|
|
1689
|
+
}) } : {},
|
|
1690
|
+
...options.cursor ? { cursor: options.cursor } : {},
|
|
1691
|
+
...options.since ? { since: parseNumber(options.since, "--since", {
|
|
1692
|
+
min: 0,
|
|
1693
|
+
integer: true
|
|
1694
|
+
}) } : {}
|
|
1695
|
+
};
|
|
1696
|
+
const result = await (await boardClient(boards, target)).get(input);
|
|
1697
|
+
if (!sections) return json(result);
|
|
1698
|
+
json({
|
|
1699
|
+
id: result.id,
|
|
1700
|
+
title: result.title,
|
|
1701
|
+
version: result.version,
|
|
1702
|
+
updatedAt: result.updatedAt,
|
|
1703
|
+
playback: result.playback,
|
|
1704
|
+
...sections.has("board") ? { board: result.board } : {},
|
|
1705
|
+
...sections.has("items") && result.items ? { items: result.items } : {},
|
|
1706
|
+
...sections.has("animations") && result.animations ? { animations: result.animations } : {},
|
|
1707
|
+
...result.next ? { next: result.next } : {}
|
|
1708
|
+
});
|
|
1709
|
+
} catch (cause) {
|
|
1710
|
+
handleHttp(cause);
|
|
1711
|
+
}
|
|
1712
|
+
});
|
|
1713
|
+
withJson(boards.command("apply <board> [patch]").description("Merge a patch into the Board: fields merge, null deletes").option("-i, --input <file>", "Patch JSON; - for stdin").option("--replace", "Make the document equal to the input instead of merging").option("--cascade", "Also delete children and tracks of deleted items, and tracks of deleted Board scripts").option("--dry-run", "Validate without writing").option("--base-version <n>", "Fail if the Board moved past this version").option("--mutation-id <id>", "Stable id; retries never apply twice")).addHelpText("after", `
|
|
1714
|
+
cohub boards apply plan.board '{"items":{"t1":{"type":"text","props":{"text":"Hi","fontSize":48}}}}'
|
|
1715
|
+
cohub boards apply plan.board '{"items":{"t1":{"position":{"x":200}}}}'
|
|
1716
|
+
cohub boards apply plan.board '{"items":{"t1":null}}'
|
|
1717
|
+
cohub boards preset rise --targets a,b --animation intro | cohub boards apply plan.board -i -`).action(async (target, inline, options) => {
|
|
1718
|
+
try {
|
|
1719
|
+
const spaceId = await resolveSpace(boards);
|
|
1720
|
+
const board = await boardClient(boards, target, spaceId);
|
|
1721
|
+
const read = await readPatch(inline, options.input, BOARD_TRANSACTION_INPUT_MAX_BYTES);
|
|
1722
|
+
const patch = await settleBoardPatch(spaceId, read, async (items) => options.replace ? {} : board.get({
|
|
1723
|
+
only: ["items"],
|
|
1724
|
+
items
|
|
1725
|
+
}).then((result) => result.items ?? {}, () => null));
|
|
1726
|
+
const result = await board.apply(patch, {
|
|
1727
|
+
...options.replace ? { replace: true } : {},
|
|
1728
|
+
...options.cascade ? { cascade: true } : {},
|
|
1729
|
+
...options.dryRun ? { dryRun: true } : {},
|
|
1730
|
+
...options.baseVersion === void 0 ? {} : { baseVersion: parseNumber(options.baseVersion, "--base-version", {
|
|
1731
|
+
min: 0,
|
|
1732
|
+
integer: true
|
|
1733
|
+
}) },
|
|
1734
|
+
...options.mutationId ? { mutationId: options.mutationId } : {}
|
|
1735
|
+
});
|
|
1736
|
+
if (jsonRequested(options)) return json(result);
|
|
1737
|
+
showApplied(result);
|
|
1738
|
+
} catch (cause) {
|
|
1739
|
+
handleHttp(cause);
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
withJson(boards.command("history <board>").description("List Board versions, or restore one").option("--before <version>", "Versions older than this").option("--limit <n>", "Number of versions", "20").option("--restore <version>", "Return the Board to this version as a new write")).action(async (target, options) => {
|
|
1743
|
+
try {
|
|
1744
|
+
const board = await boardClient(boards, target);
|
|
1745
|
+
if (options.restore !== void 0) {
|
|
1746
|
+
const result = await board.restore(parseNumber(options.restore, "--restore", {
|
|
1747
|
+
min: 0,
|
|
1748
|
+
integer: true
|
|
1749
|
+
}));
|
|
1750
|
+
if (jsonRequested(options)) return json(result);
|
|
1751
|
+
return showApplied(result);
|
|
1752
|
+
}
|
|
1753
|
+
const page = await board.history({
|
|
1754
|
+
...options.before ? { before: parseNumber(options.before, "--before", {
|
|
1755
|
+
min: 1,
|
|
1756
|
+
integer: true
|
|
1757
|
+
}) } : {},
|
|
1758
|
+
limit: parseNumber(options.limit ?? "20", "--limit", {
|
|
1759
|
+
min: 1,
|
|
1760
|
+
max: 500,
|
|
1761
|
+
integer: true
|
|
1762
|
+
})
|
|
1763
|
+
});
|
|
1764
|
+
if (jsonRequested(options)) return json(page);
|
|
1765
|
+
table(page.transactions.map((transaction) => ({
|
|
1766
|
+
version: transaction.version,
|
|
1767
|
+
at: transaction.createdAt,
|
|
1768
|
+
actor: transaction.source?.via ?? transaction.actorId,
|
|
1769
|
+
items: Object.keys(transaction.after?.items ?? {}).length,
|
|
1770
|
+
animations: (/* @__PURE__ */ new Set([...Object.keys(transaction.after?.animations ?? {}), ...Object.keys(transaction.after?.tracks ?? {})])).size
|
|
1771
|
+
})), [
|
|
1772
|
+
{
|
|
1773
|
+
key: "version",
|
|
1774
|
+
label: "Version"
|
|
1775
|
+
},
|
|
1776
|
+
{
|
|
1777
|
+
key: "at",
|
|
1778
|
+
label: "At"
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
key: "actor",
|
|
1782
|
+
label: "By"
|
|
1783
|
+
},
|
|
1784
|
+
{
|
|
1785
|
+
key: "items",
|
|
1786
|
+
label: "Items"
|
|
1787
|
+
},
|
|
1788
|
+
{
|
|
1789
|
+
key: "animations",
|
|
1790
|
+
label: "Animations"
|
|
1791
|
+
}
|
|
1792
|
+
]);
|
|
1793
|
+
if (page.nextBefore) console.log(` More: --before ${page.nextBefore}`);
|
|
1794
|
+
} catch (cause) {
|
|
1795
|
+
handleHttp(cause);
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
withJson(boards.command("diff <board>").description("List what changed between two versions, element by element").requiredOption("--from <version>", "The version to compare from").option("--to <version>", "The version to compare to; the latest by default")).addHelpText("after", `
|
|
1799
|
+
Before rewriting a Board with apply --replace, see what others changed since the version you read:
|
|
1800
|
+
cohub boards diff plan.board --from 41
|
|
1801
|
+
cohub boards diff plan.board --from 41 --to 44 --json`).action(async (target, options) => {
|
|
1802
|
+
try {
|
|
1803
|
+
const result = await (await boardClient(boards, target)).diff(parseNumber(options.from, "--from", {
|
|
1804
|
+
min: 0,
|
|
1805
|
+
integer: true
|
|
1806
|
+
}), options.to === void 0 ? void 0 : parseNumber(options.to, "--to", {
|
|
1807
|
+
min: 1,
|
|
1808
|
+
integer: true
|
|
1809
|
+
}));
|
|
1810
|
+
if (jsonRequested(options)) return json(result);
|
|
1811
|
+
const by = /* @__PURE__ */ new Map();
|
|
1812
|
+
for (const { kind } of result.versions) by.set(kind, (by.get(kind) ?? 0) + 1);
|
|
1813
|
+
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(", ")})` : ""}`);
|
|
1814
|
+
const show = (value) => {
|
|
1815
|
+
const text = value === void 0 ? "∅" : JSON.stringify(value);
|
|
1816
|
+
return text.length > 60 ? `${text.slice(0, 57)}…` : text;
|
|
1817
|
+
};
|
|
1818
|
+
for (const change of result.changes) {
|
|
1819
|
+
const sign = change.change === "added" ? "+" : change.change === "removed" ? "-" : "~";
|
|
1820
|
+
const name = change.kind === "board" ? "board" : `${change.kind} ${change.id}${change.type ? ` (${change.type})` : ""}`;
|
|
1821
|
+
console.log(` ${sign} ${name}`);
|
|
1822
|
+
for (const field of change.fields.slice(0, 12)) console.log(` ${field.path}: ${show(field.from)} → ${show(field.to)}`);
|
|
1823
|
+
if (change.fields.length > 12) console.log(` … ${change.fields.length - 12} more fields; --json lists them all`);
|
|
1824
|
+
}
|
|
1825
|
+
} catch (cause) {
|
|
1826
|
+
handleHttp(cause);
|
|
1827
|
+
}
|
|
1828
|
+
});
|
|
1829
|
+
boards.command("schema [target]").description("Print JSON Schema for a part of a Board").option("--field <path>", "Print one field, e.g. props.decoration or props.geometry").addHelpText("after", `
|
|
1830
|
+
Without a target: units, item types, colors and every animatable property.
|
|
1831
|
+
With a target: its fields and what they mean; script also lists the module API.
|
|
1832
|
+
Targets: ${BOARD_SCHEMA_TARGETS.join(", ")}`).action((target, options) => {
|
|
1833
|
+
try {
|
|
1834
|
+
if (options.field && !target) throw new Error("--field needs a schema target, e.g. schema frame --field props.decoration.");
|
|
1835
|
+
if (!target) return json({
|
|
1836
|
+
...boardSchemaOverview(),
|
|
1837
|
+
presets: listBoardPresets()
|
|
1838
|
+
});
|
|
1839
|
+
const schema = boardJsonSchema(target);
|
|
1840
|
+
if (!schema) throw new Error(`Unknown target ${target}; expected ${BOARD_SCHEMA_TARGETS.join(", ")}.`);
|
|
1841
|
+
if (options.field) return json(boardSchemaField(schema.schema, options.field));
|
|
1842
|
+
json(target === "script" ? {
|
|
1843
|
+
...schema,
|
|
1844
|
+
api: BOARD_SCRIPT_API
|
|
1845
|
+
} : schema);
|
|
1846
|
+
} catch (cause) {
|
|
1847
|
+
handleHttp(cause);
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1850
|
+
boards.command("preset <name>").description("Print tracks for a preset motion as a patch for apply").requiredOption("--targets <ids>", "Comma-separated item ids").option("--animation <id>", "Wrap the tracks in this animation; omit to get bare tracks").option("--at <time>", "Start of the first target", "0").option("--stagger <time>", "Delay added per target", "0").option("--duration <time>", "Length of each target's motion").option("--ease <ease>", "CSS easing, e.g. ease-out or cubic-bezier(.2,.8,.2,1)").addHelpText("after", `
|
|
1851
|
+
Presets: ${BOARD_PRESET_NAMES.join(", ")}
|
|
1852
|
+
cohub boards preset rise --targets a,b,c --animation intro --stagger 120ms | cohub boards apply plan.board -i -
|
|
1853
|
+
cohub boards preset float --targets ship | jq -c '{animations:{idle:.}}' | cohub boards apply plan.board -i -`).action((name, options) => {
|
|
1854
|
+
try {
|
|
1855
|
+
if (!isBoardPresetName(name)) throw new Error(`Unknown preset ${name}; expected ${BOARD_PRESET_NAMES.join(", ")}.`);
|
|
1856
|
+
const targets = list(options.targets);
|
|
1857
|
+
if (!targets) throw new Error("--targets needs at least one item id.");
|
|
1858
|
+
const tracks = boardPresetTracks(name, {
|
|
1859
|
+
targets,
|
|
1860
|
+
at: parseBoardTime(options.at, "--at"),
|
|
1861
|
+
stagger: parseBoardTime(options.stagger, "--stagger"),
|
|
1862
|
+
...options.duration ? { duration: parseBoardTime(options.duration, "--duration") } : {},
|
|
1863
|
+
...options.ease ? { ease: options.ease } : {}
|
|
1864
|
+
});
|
|
1865
|
+
json(options.animation ? { animations: { [options.animation]: { tracks } } } : { tracks });
|
|
1866
|
+
} catch (cause) {
|
|
1867
|
+
handleHttp(cause);
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
registerBoardExampleCommands(boards);
|
|
1871
|
+
registerExportCommand(boards);
|
|
1872
|
+
registerSimulateCommand(boards);
|
|
1873
|
+
registerProfileCommand(boards);
|
|
1874
|
+
registerBoardAuthoringCommands(boards);
|
|
1875
|
+
registerPlaybackCommands(boards);
|
|
1876
|
+
withJson(boards.command("watch <board>").description("Stream Board changes and playback as they happen")).action(async (target, options) => {
|
|
1877
|
+
try {
|
|
1878
|
+
const spaceId = await resolveSpace(boards);
|
|
1879
|
+
const client = createRealtimeClient();
|
|
1880
|
+
const board = await client.space(spaceId).boards.open(target);
|
|
1881
|
+
const boardId = board.id;
|
|
1882
|
+
if (!jsonRequested(options)) process.stderr.write(`Watching Board ${boardId}…\n`);
|
|
1883
|
+
const offConnection = client.onConnection((state) => {
|
|
1884
|
+
if (jsonRequested(options)) process.stdout.write(`${JSON.stringify({
|
|
1885
|
+
type: "connection",
|
|
1886
|
+
...state
|
|
1887
|
+
})}\n`);
|
|
1888
|
+
else process.stderr.write(`${state.state}${state.state === "reconnecting" && state.attempt ? ` (attempt ${state.attempt})` : ""}\n`);
|
|
1889
|
+
});
|
|
1890
|
+
const offBoard = board.subscribe({ event(event) {
|
|
1891
|
+
if (jsonRequested(options)) {
|
|
1892
|
+
process.stdout.write(`${JSON.stringify(event)}\n`);
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
if (event.type === "board.changed") {
|
|
1896
|
+
const { changed } = event.payload;
|
|
1897
|
+
process.stdout.write(`version ${event.payload.version} ${[
|
|
1898
|
+
changed.board ? "board" : "",
|
|
1899
|
+
...changed.items,
|
|
1900
|
+
...changed.animations
|
|
1901
|
+
].filter(Boolean).join(", ")}\n`);
|
|
1902
|
+
} else if (event.type === "board.playback.changed") {
|
|
1903
|
+
const { playback } = event.payload;
|
|
1904
|
+
process.stdout.write(playback ? `${playback.status} ${playback.animationId} ${formatBoardTime(Math.round(playback.position))}\n` : "stopped\n");
|
|
1905
|
+
}
|
|
1906
|
+
} });
|
|
1907
|
+
process.once("SIGINT", () => {
|
|
1908
|
+
offBoard();
|
|
1909
|
+
offConnection();
|
|
1910
|
+
process.exit(0);
|
|
1911
|
+
});
|
|
1912
|
+
} catch (cause) {
|
|
1913
|
+
handleHttp(cause);
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
return boards;
|
|
1917
|
+
}
|
|
1918
|
+
function registerPlaybackCommands(boards) {
|
|
1919
|
+
const run = async (target, options, command) => {
|
|
1920
|
+
try {
|
|
1921
|
+
const playback = await command(await boardClient(boards, target));
|
|
1922
|
+
if (jsonRequested(options)) return json({ playback });
|
|
1923
|
+
showPlayback(playback);
|
|
1924
|
+
} catch (cause) {
|
|
1925
|
+
handleHttp(cause);
|
|
1926
|
+
}
|
|
1927
|
+
};
|
|
1928
|
+
withJson(boards.command("play <board> <animation>").description("Play an animation for everyone viewing the Board").option("--at <time>", "Start position, e.g. 2.5s").option("--speed <factor>", "Playback speed, up to 4").option("--seed <seed>", "Seed for procedural effects")).action((target, animation, options) => run(target, options, (board) => board.play(animation, {
|
|
1929
|
+
...options.at ? { position: parseBoardTime(options.at, "--at") } : {},
|
|
1930
|
+
...options.speed ? { timeScale: parseNumber(options.speed, "--speed", {
|
|
1931
|
+
min: Number.EPSILON,
|
|
1932
|
+
max: 4
|
|
1933
|
+
}) } : {},
|
|
1934
|
+
...options.seed ? { seed: options.seed } : {}
|
|
1935
|
+
})));
|
|
1936
|
+
withJson(boards.command("pause <board>").description("Pause playback")).action((target, options) => run(target, options, (board) => board.pause()));
|
|
1937
|
+
withJson(boards.command("resume <board>").description("Resume paused playback")).action((target, options) => run(target, options, (board) => board.resume()));
|
|
1938
|
+
withJson(boards.command("seek <board> <time>").description("Move the playhead, e.g. 12.5s")).action((target, time, options) => run(target, options, (board) => board.seek(parseBoardTime(time))));
|
|
1939
|
+
withJson(boards.command("next <board>").description("Continue past the marker a presentation holds at")).action((target, options) => run(target, options, (board) => board.next()));
|
|
1940
|
+
withJson(boards.command("stop <board>").description("Stop playback")).action((target, options) => run(target, options, (board) => board.stop()));
|
|
1941
|
+
}
|
|
1942
|
+
//#endregion
|
|
1943
|
+
export { registerBoards };
|