@neta-art/cohub-cli 10.24.0 → 10.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/binary-pins.js +5 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +311 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2513 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -121
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -141
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2170
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -10
- package/dist/session-status.js +0 -25
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
|
@@ -0,0 +1,2898 @@
|
|
|
1
|
+
import { A as invertMatrix, C as clampBoardFontSize, I as scaleVector, M as layoutBoardText, N as matrixRotation, T as drawPointsBounds, W as BOARD_CAMERA_TARGET, Z as BOARD_SHADOW_DEFAULTS, _ as IDENTITY_MATRIX, b as arrowBindings, et as BoardColorSchema, g as resolveBoardProperty, nt as BoardIdSchema, r as sameJson, t as createBoardEntityId, u as applyBoardPatchToDocument, w as createBoardLayout, y as applyMatrix } from "./id.js";
|
|
2
|
+
//#region ../sdk/src/board/model/geometry.ts
|
|
3
|
+
function screenPoint(x, y) {
|
|
4
|
+
return {
|
|
5
|
+
x,
|
|
6
|
+
y
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function worldPoint(x, y) {
|
|
10
|
+
return {
|
|
11
|
+
x,
|
|
12
|
+
y
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const MIN_BOARD_ZOOM = .05;
|
|
16
|
+
const DEFAULT_BOARD_VIEWPORT = {
|
|
17
|
+
x: 0,
|
|
18
|
+
y: 0,
|
|
19
|
+
zoom: 1
|
|
20
|
+
};
|
|
21
|
+
function clampZoom(zoom) {
|
|
22
|
+
const value = Number.isFinite(zoom) ? zoom : DEFAULT_BOARD_VIEWPORT.zoom;
|
|
23
|
+
return Math.min(8, Math.max(MIN_BOARD_ZOOM, value));
|
|
24
|
+
}
|
|
25
|
+
function normalizeViewport(viewport, fallback = DEFAULT_BOARD_VIEWPORT) {
|
|
26
|
+
const fallbackX = Number.isFinite(fallback.x) ? fallback.x : DEFAULT_BOARD_VIEWPORT.x;
|
|
27
|
+
const fallbackY = Number.isFinite(fallback.y) ? fallback.y : DEFAULT_BOARD_VIEWPORT.y;
|
|
28
|
+
const fallbackZoom = Number.isFinite(fallback.zoom) ? clampZoom(fallback.zoom) : DEFAULT_BOARD_VIEWPORT.zoom;
|
|
29
|
+
return {
|
|
30
|
+
x: Number.isFinite(viewport.x) ? viewport.x : fallbackX,
|
|
31
|
+
y: Number.isFinite(viewport.y) ? viewport.y : fallbackY,
|
|
32
|
+
zoom: Number.isFinite(viewport.zoom) ? clampZoom(viewport.zoom) : fallbackZoom
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function clamp(value, min, max) {
|
|
36
|
+
return Math.min(max, Math.max(min, value));
|
|
37
|
+
}
|
|
38
|
+
function degToRad(degrees) {
|
|
39
|
+
return degrees * Math.PI / 180;
|
|
40
|
+
}
|
|
41
|
+
function frameRect(frame) {
|
|
42
|
+
return {
|
|
43
|
+
x: frame.x,
|
|
44
|
+
y: frame.y,
|
|
45
|
+
width: frame.width,
|
|
46
|
+
height: frame.height
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function rectCenter(rect) {
|
|
50
|
+
return worldPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
|
|
51
|
+
}
|
|
52
|
+
function rectsIntersect(a, b) {
|
|
53
|
+
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
54
|
+
}
|
|
55
|
+
function rectContainsPoint(rect, point, tolerance = 0) {
|
|
56
|
+
return point.x >= rect.x - tolerance && point.x <= rect.x + rect.width + tolerance && point.y >= rect.y - tolerance && point.y <= rect.y + rect.height + tolerance;
|
|
57
|
+
}
|
|
58
|
+
function unionRects(rects) {
|
|
59
|
+
if (rects.length === 0) return null;
|
|
60
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
61
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
62
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
63
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
64
|
+
for (const rect of rects) {
|
|
65
|
+
minX = Math.min(minX, rect.x);
|
|
66
|
+
minY = Math.min(minY, rect.y);
|
|
67
|
+
maxX = Math.max(maxX, rect.x + rect.width);
|
|
68
|
+
maxY = Math.max(maxY, rect.y + rect.height);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
x: minX,
|
|
72
|
+
y: minY,
|
|
73
|
+
width: maxX - minX,
|
|
74
|
+
height: maxY - minY
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function rotatePointAround(point, center, angleRad) {
|
|
78
|
+
const cos = Math.cos(angleRad);
|
|
79
|
+
const sin = Math.sin(angleRad);
|
|
80
|
+
const dx = point.x - center.x;
|
|
81
|
+
const dy = point.y - center.y;
|
|
82
|
+
return {
|
|
83
|
+
x: center.x + dx * cos - dy * sin,
|
|
84
|
+
y: center.y + dx * sin + dy * cos
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function effectBounds(rect, style) {
|
|
88
|
+
const blur = (style?.filter?.blur ?? 0) * 3;
|
|
89
|
+
const shadow = style?.shadow;
|
|
90
|
+
if (!blur && !shadow) return rect;
|
|
91
|
+
const reach = shadow ? (shadow.blur ?? BOARD_SHADOW_DEFAULTS.blur) * 1.5 : 0;
|
|
92
|
+
const dx = shadow ? shadow.x ?? BOARD_SHADOW_DEFAULTS.x : 0;
|
|
93
|
+
const dy = shadow ? shadow.y ?? BOARD_SHADOW_DEFAULTS.y : 0;
|
|
94
|
+
const left = blur + Math.max(0, reach - dx);
|
|
95
|
+
const top = blur + Math.max(0, reach - dy);
|
|
96
|
+
return {
|
|
97
|
+
x: rect.x - left,
|
|
98
|
+
y: rect.y - top,
|
|
99
|
+
width: rect.width + left + blur + Math.max(0, reach + dx),
|
|
100
|
+
height: rect.height + top + blur + Math.max(0, reach + dy)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function itemBounds(frame) {
|
|
104
|
+
const rotation = frame.rotation || 0;
|
|
105
|
+
if (rotation === 0) return frameRect(frame);
|
|
106
|
+
const center = rectCenter(frameRect(frame));
|
|
107
|
+
const halfW = frame.width / 2;
|
|
108
|
+
const halfH = frame.height / 2;
|
|
109
|
+
const rad = degToRad(rotation);
|
|
110
|
+
const cos = Math.abs(Math.cos(rad));
|
|
111
|
+
const sin = Math.abs(Math.sin(rad));
|
|
112
|
+
const boundW = halfW * cos + halfH * sin;
|
|
113
|
+
const boundH = halfW * sin + halfH * cos;
|
|
114
|
+
return {
|
|
115
|
+
x: center.x - boundW,
|
|
116
|
+
y: center.y - boundH,
|
|
117
|
+
width: boundW * 2,
|
|
118
|
+
height: boundH * 2
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function selectionBounds(frames) {
|
|
122
|
+
return unionRects(frames.map(itemBounds));
|
|
123
|
+
}
|
|
124
|
+
function frameContainsPoint(frame, point) {
|
|
125
|
+
const rect = frameRect(frame);
|
|
126
|
+
const rotation = frame.rotation || 0;
|
|
127
|
+
let local = point;
|
|
128
|
+
if (rotation !== 0) local = rotatePointAround(point, rectCenter(rect), -degToRad(rotation));
|
|
129
|
+
return rectContainsPoint(rect, local);
|
|
130
|
+
}
|
|
131
|
+
function frameHandlePosition(frame, handle) {
|
|
132
|
+
const rect = frameRect(frame);
|
|
133
|
+
const position = handlePosition(rect, handle);
|
|
134
|
+
const rotation = frame.rotation || 0;
|
|
135
|
+
if (rotation === 0) return position;
|
|
136
|
+
return rotatePointAround(position, rectCenter(rect), degToRad(rotation));
|
|
137
|
+
}
|
|
138
|
+
function frameRayIntersection(frame, pointer) {
|
|
139
|
+
const center = rectCenter(frame);
|
|
140
|
+
let dx = pointer.x - center.x;
|
|
141
|
+
let dy = pointer.y - center.y;
|
|
142
|
+
if (Math.hypot(dx, dy) < 1e-4) {
|
|
143
|
+
dx = 0;
|
|
144
|
+
dy = 1;
|
|
145
|
+
}
|
|
146
|
+
const rad = degToRad(frame.rotation || 0);
|
|
147
|
+
const cos = Math.cos(rad);
|
|
148
|
+
const sin = Math.sin(rad);
|
|
149
|
+
const localDx = dx * cos + dy * sin;
|
|
150
|
+
const localDy = -dx * sin + dy * cos;
|
|
151
|
+
const scaleX = Math.abs(localDx) > 1e-4 ? frame.width / 2 / Math.abs(localDx) : Number.POSITIVE_INFINITY;
|
|
152
|
+
const scaleY = Math.abs(localDy) > 1e-4 ? frame.height / 2 / Math.abs(localDy) : Number.POSITIVE_INFINITY;
|
|
153
|
+
const scale = Math.min(scaleX, scaleY);
|
|
154
|
+
return worldPoint(center.x + dx * scale, center.y + dy * scale);
|
|
155
|
+
}
|
|
156
|
+
function rotationHandleAnchor(frame) {
|
|
157
|
+
const center = rectCenter(frame);
|
|
158
|
+
return frameRayIntersection(frame, worldPoint(center.x, center.y + 1));
|
|
159
|
+
}
|
|
160
|
+
function rotationHandlePosition(frame, zoom) {
|
|
161
|
+
const center = rectCenter(frame);
|
|
162
|
+
const anchor = rotationHandleAnchor(frame);
|
|
163
|
+
const offset = 28 / Math.max(zoom, 1e-4);
|
|
164
|
+
return worldPoint(center.x, anchor.y + offset);
|
|
165
|
+
}
|
|
166
|
+
const CORNER_RESIZE_HANDLES = [
|
|
167
|
+
"nw",
|
|
168
|
+
"ne",
|
|
169
|
+
"se",
|
|
170
|
+
"sw"
|
|
171
|
+
];
|
|
172
|
+
function frameCornerRotationHandleAt(frame, point, zoom, screenRadius = 8) {
|
|
173
|
+
const rect = frameRect(frame);
|
|
174
|
+
const center = rectCenter(rect);
|
|
175
|
+
const local = frame.rotation ? rotatePointAround(point, center, -degToRad(frame.rotation)) : point;
|
|
176
|
+
const safeZoom = Math.max(zoom, 1e-4);
|
|
177
|
+
const innerRadius = screenRadius / safeZoom;
|
|
178
|
+
const outerRadius = (screenRadius + 16) / safeZoom;
|
|
179
|
+
for (const handle of CORNER_RESIZE_HANDLES) {
|
|
180
|
+
const corner = handlePosition(rect, handle);
|
|
181
|
+
const direction = HANDLE_DIRECTION[handle];
|
|
182
|
+
const outwardX = (local.x - corner.x) * direction.x;
|
|
183
|
+
const outwardY = (local.y - corner.y) * direction.y;
|
|
184
|
+
if (outwardX < -1e-4 || outwardY < -1e-4) continue;
|
|
185
|
+
const distance = Math.hypot(outwardX, outwardY);
|
|
186
|
+
if (distance > innerRadius && distance <= outerRadius) return handle;
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
function frameEdgeHandleAt(frame, point, zoom, screenRadius = 8) {
|
|
191
|
+
const rect = frameRect(frame);
|
|
192
|
+
const center = rectCenter(rect);
|
|
193
|
+
const local = frame.rotation ? rotatePointAround(point, center, -degToRad(frame.rotation)) : point;
|
|
194
|
+
const radius = screenRadius / Math.max(zoom, 1e-4);
|
|
195
|
+
const insetX = Math.min(rect.width / 3, radius * 1.5);
|
|
196
|
+
const insetY = Math.min(rect.height / 3, radius * 1.5);
|
|
197
|
+
let closest = null;
|
|
198
|
+
let closestDistance = Number.POSITIVE_INFINITY;
|
|
199
|
+
if (local.x >= rect.x + insetX && local.x <= rect.x + rect.width - insetX) {
|
|
200
|
+
const north = Math.abs(local.y - rect.y);
|
|
201
|
+
const south = Math.abs(local.y - (rect.y + rect.height));
|
|
202
|
+
if (north <= radius && north < closestDistance) {
|
|
203
|
+
closest = "n";
|
|
204
|
+
closestDistance = north;
|
|
205
|
+
}
|
|
206
|
+
if (south <= radius && south < closestDistance) {
|
|
207
|
+
closest = "s";
|
|
208
|
+
closestDistance = south;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (local.y >= rect.y + insetY && local.y <= rect.y + rect.height - insetY) {
|
|
212
|
+
const west = Math.abs(local.x - rect.x);
|
|
213
|
+
const east = Math.abs(local.x - (rect.x + rect.width));
|
|
214
|
+
if (west <= radius && west < closestDistance) {
|
|
215
|
+
closest = "w";
|
|
216
|
+
closestDistance = west;
|
|
217
|
+
}
|
|
218
|
+
if (east <= radius && east < closestDistance) closest = "e";
|
|
219
|
+
}
|
|
220
|
+
return closest;
|
|
221
|
+
}
|
|
222
|
+
const HANDLE_DIRECTION = {
|
|
223
|
+
nw: {
|
|
224
|
+
x: -1,
|
|
225
|
+
y: -1
|
|
226
|
+
},
|
|
227
|
+
n: {
|
|
228
|
+
x: 0,
|
|
229
|
+
y: -1
|
|
230
|
+
},
|
|
231
|
+
ne: {
|
|
232
|
+
x: 1,
|
|
233
|
+
y: -1
|
|
234
|
+
},
|
|
235
|
+
e: {
|
|
236
|
+
x: 1,
|
|
237
|
+
y: 0
|
|
238
|
+
},
|
|
239
|
+
se: {
|
|
240
|
+
x: 1,
|
|
241
|
+
y: 1
|
|
242
|
+
},
|
|
243
|
+
s: {
|
|
244
|
+
x: 0,
|
|
245
|
+
y: 1
|
|
246
|
+
},
|
|
247
|
+
sw: {
|
|
248
|
+
x: -1,
|
|
249
|
+
y: 1
|
|
250
|
+
},
|
|
251
|
+
w: {
|
|
252
|
+
x: -1,
|
|
253
|
+
y: 0
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
function handlePosition(rect, handle) {
|
|
257
|
+
const direction = HANDLE_DIRECTION[handle];
|
|
258
|
+
return worldPoint(rect.x + rect.width / 2 + direction.x * rect.width / 2, rect.y + rect.height / 2 + direction.y * rect.height / 2);
|
|
259
|
+
}
|
|
260
|
+
function resizeFrameToSize(frame, handle, width, height) {
|
|
261
|
+
const direction = HANDLE_DIRECTION[handle];
|
|
262
|
+
const rect = frameRect(frame);
|
|
263
|
+
const center = rectCenter(rect);
|
|
264
|
+
const rad = degToRad(frame.rotation || 0);
|
|
265
|
+
const anchorLocal = {
|
|
266
|
+
x: -direction.x * rect.width / 2,
|
|
267
|
+
y: -direction.y * rect.height / 2
|
|
268
|
+
};
|
|
269
|
+
const anchor = rotatePointAround({
|
|
270
|
+
x: center.x + anchorLocal.x,
|
|
271
|
+
y: center.y + anchorLocal.y
|
|
272
|
+
}, center, rad);
|
|
273
|
+
const centerLocal = {
|
|
274
|
+
x: direction.x * width / 2,
|
|
275
|
+
y: direction.y * height / 2
|
|
276
|
+
};
|
|
277
|
+
const nextCenter = rotatePointAround({
|
|
278
|
+
x: anchor.x + centerLocal.x,
|
|
279
|
+
y: anchor.y + centerLocal.y
|
|
280
|
+
}, anchor, rad);
|
|
281
|
+
return {
|
|
282
|
+
x: nextCenter.x - width / 2,
|
|
283
|
+
y: nextCenter.y - height / 2,
|
|
284
|
+
width,
|
|
285
|
+
height,
|
|
286
|
+
rotation: frame.rotation || 0
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function resizeFrame(frame, handle, pointer, minSize = 24, keepAspect = false) {
|
|
290
|
+
const direction = HANDLE_DIRECTION[handle];
|
|
291
|
+
const rect = frameRect(frame);
|
|
292
|
+
const center = rectCenter(rect);
|
|
293
|
+
const rad = degToRad(frame.rotation || 0);
|
|
294
|
+
const aspect = rect.width / Math.max(rect.height, 1e-4);
|
|
295
|
+
const anchorLocal = {
|
|
296
|
+
x: -direction.x * rect.width / 2,
|
|
297
|
+
y: -direction.y * rect.height / 2
|
|
298
|
+
};
|
|
299
|
+
const anchor = rotatePointAround({
|
|
300
|
+
x: center.x + anchorLocal.x,
|
|
301
|
+
y: center.y + anchorLocal.y
|
|
302
|
+
}, center, rad);
|
|
303
|
+
const toLocal = rotatePointAround(pointer, anchor, -rad);
|
|
304
|
+
const local = {
|
|
305
|
+
x: toLocal.x - anchor.x,
|
|
306
|
+
y: toLocal.y - anchor.y
|
|
307
|
+
};
|
|
308
|
+
let width = direction.x !== 0 ? clamp(direction.x * local.x, minSize, Number.POSITIVE_INFINITY) : rect.width;
|
|
309
|
+
let height = direction.y !== 0 ? clamp(direction.y * local.y, minSize, Number.POSITIVE_INFINITY) : rect.height;
|
|
310
|
+
if (keepAspect) {
|
|
311
|
+
if (direction.x !== 0 && direction.y !== 0) {
|
|
312
|
+
if (Math.abs(width / aspect) > height) height = width / aspect;
|
|
313
|
+
else width = height * aspect;
|
|
314
|
+
} else if (direction.x !== 0) height = width / aspect;
|
|
315
|
+
else if (direction.y !== 0) width = height * aspect;
|
|
316
|
+
width = Math.max(minSize, width);
|
|
317
|
+
height = Math.max(minSize, height);
|
|
318
|
+
}
|
|
319
|
+
return resizeFrameToSize(frame, handle, width, height);
|
|
320
|
+
}
|
|
321
|
+
function scaleFrames(frames, bounds, handle, pointer, minSize = 24, scaleRange) {
|
|
322
|
+
const direction = HANDLE_DIRECTION[handle];
|
|
323
|
+
if (direction.x === 0 || direction.y === 0) return frames;
|
|
324
|
+
const anchor = {
|
|
325
|
+
x: bounds.x + bounds.width / 2 - direction.x * bounds.width / 2,
|
|
326
|
+
y: bounds.y + bounds.height / 2 - direction.y * bounds.height / 2
|
|
327
|
+
};
|
|
328
|
+
const original = handlePosition(bounds, handle);
|
|
329
|
+
const originalDist = Math.hypot(original.x - anchor.x, original.y - anchor.y);
|
|
330
|
+
const nextDist = Math.hypot(pointer.x - anchor.x, pointer.y - anchor.y);
|
|
331
|
+
if (originalDist === 0) return frames;
|
|
332
|
+
const frameMinScale = frames.reduce((minimum, frame) => Math.max(minimum, minSize / Math.max(1e-4, Math.min(frame.width, frame.height))), 0);
|
|
333
|
+
const minScale = Math.max(frameMinScale, scaleRange?.min ?? 0);
|
|
334
|
+
const maxScale = Math.max(minScale, scaleRange?.max ?? Number.POSITIVE_INFINITY);
|
|
335
|
+
const scale = clamp(nextDist / originalDist, minScale, maxScale);
|
|
336
|
+
return frames.map((frame) => {
|
|
337
|
+
const center = rectCenter(frameRect(frame));
|
|
338
|
+
const nextCenter = {
|
|
339
|
+
x: anchor.x + (center.x - anchor.x) * scale,
|
|
340
|
+
y: anchor.y + (center.y - anchor.y) * scale
|
|
341
|
+
};
|
|
342
|
+
const width = frame.width * scale;
|
|
343
|
+
const height = frame.height * scale;
|
|
344
|
+
return {
|
|
345
|
+
x: nextCenter.x - width / 2,
|
|
346
|
+
y: nextCenter.y - height / 2,
|
|
347
|
+
width,
|
|
348
|
+
height,
|
|
349
|
+
rotation: frame.rotation || 0
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function rotateFrames(frames, pivot, deltaDeg) {
|
|
354
|
+
const rad = degToRad(deltaDeg);
|
|
355
|
+
return frames.map((frame) => {
|
|
356
|
+
const nextCenter = rotatePointAround(rectCenter(frameRect(frame)), pivot, rad);
|
|
357
|
+
return {
|
|
358
|
+
x: nextCenter.x - frame.width / 2,
|
|
359
|
+
y: nextCenter.y - frame.height / 2,
|
|
360
|
+
width: frame.width,
|
|
361
|
+
height: frame.height,
|
|
362
|
+
rotation: (frame.rotation || 0) + deltaDeg
|
|
363
|
+
};
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function normalizeRotation(degrees) {
|
|
367
|
+
let value = degrees % 360;
|
|
368
|
+
if (value > 180) value -= 360;
|
|
369
|
+
if (value < -180) value += 360;
|
|
370
|
+
return Math.abs(value) < .01 ? 0 : value;
|
|
371
|
+
}
|
|
372
|
+
function pointToWorld(point, viewport) {
|
|
373
|
+
return worldPoint((point.x - viewport.x) / viewport.zoom, (point.y - viewport.y) / viewport.zoom);
|
|
374
|
+
}
|
|
375
|
+
function zoomAround(viewport, anchor, nextZoom) {
|
|
376
|
+
const current = normalizeViewport(viewport);
|
|
377
|
+
const zoom = Number.isFinite(nextZoom) ? clampZoom(nextZoom) : current.zoom;
|
|
378
|
+
const world = pointToWorld(anchor, current);
|
|
379
|
+
return {
|
|
380
|
+
x: anchor.x - world.x * zoom,
|
|
381
|
+
y: anchor.y - world.y * zoom,
|
|
382
|
+
zoom
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function panBy(viewport, dx, dy) {
|
|
386
|
+
return {
|
|
387
|
+
...viewport,
|
|
388
|
+
x: viewport.x + dx,
|
|
389
|
+
y: viewport.y + dy
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function stateForCamera(camera, surface) {
|
|
393
|
+
const { x, y, zoom } = normalizeViewport(camera);
|
|
394
|
+
return {
|
|
395
|
+
centerX: (surface.width / 2 - x) / zoom,
|
|
396
|
+
centerY: (surface.height / 2 - y) / zoom,
|
|
397
|
+
zoom
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function cameraForState(state, surface) {
|
|
401
|
+
const zoom = clampZoom(state.zoom);
|
|
402
|
+
return normalizeViewport({
|
|
403
|
+
x: surface.width / 2 - state.centerX * zoom,
|
|
404
|
+
y: surface.height / 2 - state.centerY * zoom,
|
|
405
|
+
zoom
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function cameraForRect(content, surface, options = {}) {
|
|
409
|
+
const padding = Math.max(0, Number.isFinite(options.padding) ? options.padding : 32);
|
|
410
|
+
const availableW = Math.max(1, surface.width - padding * 2);
|
|
411
|
+
const availableH = Math.max(1, surface.height - padding * 2);
|
|
412
|
+
const fitZoom = options.fit === "cover" ? Math.max(availableW / content.width, availableH / content.height) : Math.min(availableW / content.width, availableH / content.height);
|
|
413
|
+
const minZoom = clampZoom(options.minZoom ?? .05);
|
|
414
|
+
const maxZoom = clampZoom(options.maxZoom ?? 8);
|
|
415
|
+
const zoom = Math.min(Math.max(fitZoom, Math.min(minZoom, maxZoom)), Math.max(minZoom, maxZoom));
|
|
416
|
+
const center = rectCenter(content);
|
|
417
|
+
return cameraForState({
|
|
418
|
+
centerX: center.x,
|
|
419
|
+
centerY: center.y,
|
|
420
|
+
zoom
|
|
421
|
+
}, surface);
|
|
422
|
+
}
|
|
423
|
+
function rectForCameraFocus(focus, getFrame) {
|
|
424
|
+
if (typeof focus !== "string") return focus;
|
|
425
|
+
const frame = getFrame(focus);
|
|
426
|
+
return frame ? itemBounds(frame) : null;
|
|
427
|
+
}
|
|
428
|
+
function cameraForFocus(focus, getFrame, surface, options = {}) {
|
|
429
|
+
const rect = rectForCameraFocus(focus, getFrame);
|
|
430
|
+
return rect ? cameraForRect(rect, surface, options) : null;
|
|
431
|
+
}
|
|
432
|
+
function visibleWorldRect(viewport, surfaceWidth, surfaceHeight) {
|
|
433
|
+
const width = Math.max(0, surfaceWidth);
|
|
434
|
+
const height = Math.max(0, surfaceHeight);
|
|
435
|
+
const zoom = viewport.zoom || 1;
|
|
436
|
+
return {
|
|
437
|
+
x: -viewport.x / zoom,
|
|
438
|
+
y: -viewport.y / zoom,
|
|
439
|
+
width: width / zoom,
|
|
440
|
+
height: height / zoom
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region ../sdk/src/board/model/script-example.ts
|
|
445
|
+
const BOARD_SCRIPT_DRAWING_EXAMPLE = `export const animated = true;
|
|
446
|
+
|
|
447
|
+
export const parameters = {
|
|
448
|
+
amplitude: { type: "number", label: "Amplitude", default: 40, min: 0, max: 120 }
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
export function draw(ctx, { t, width, height, params }) {
|
|
452
|
+
ctx.strokeStyle = "#e67845";
|
|
453
|
+
ctx.lineWidth = 3;
|
|
454
|
+
ctx.beginPath();
|
|
455
|
+
for (let x = 0; x <= width; x += 2) {
|
|
456
|
+
const y = height / 2 + Math.sin(x / 40 - t / 800) * params.amplitude;
|
|
457
|
+
if (x === 0) ctx.moveTo(x, y);
|
|
458
|
+
else ctx.lineTo(x, y);
|
|
459
|
+
}
|
|
460
|
+
ctx.stroke();
|
|
461
|
+
}
|
|
462
|
+
`;
|
|
463
|
+
/**
|
|
464
|
+
* A Board script: rain over the whole view that splashes on the Board's items.
|
|
465
|
+
* Every drop is a pure function of time, so it seeks, replays and exports.
|
|
466
|
+
*/
|
|
467
|
+
const BOARD_SCRIPT_RAIN_EXAMPLE = `export const animated = true;
|
|
468
|
+
|
|
469
|
+
export const parameters = {
|
|
470
|
+
density: { type: "number", label: "Density", default: 0.7, min: 0, max: 1, step: 0.05 },
|
|
471
|
+
wind: { type: "number", label: "Wind", default: 0.15, min: -0.6, max: 0.6, step: 0.05 },
|
|
472
|
+
splash: { type: "boolean", label: "Splash on cards", default: true },
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// Each drop draws a streak and three droplets for its splash.
|
|
476
|
+
const PARTS = 4;
|
|
477
|
+
const DROPS = 2400;
|
|
478
|
+
|
|
479
|
+
const glsl = \`
|
|
480
|
+
#define PARTS \${PARTS}
|
|
481
|
+
#include "cohub:hash"
|
|
482
|
+
|
|
483
|
+
const float SPEED = 1400.0; // screen pixels per second, at any zoom
|
|
484
|
+
const float SPLASH = 0.38; // seconds a splash lasts
|
|
485
|
+
|
|
486
|
+
struct Drop { vec2 start; vec2 heading; float reach; float travelled; float landing; bool lands; };
|
|
487
|
+
|
|
488
|
+
// Drops respawn every cycle at new seeded places, anywhere in view.
|
|
489
|
+
Drop drop(int index, float pixel, bool streak) {
|
|
490
|
+
float speed = SPEED * pixel;
|
|
491
|
+
float cycle = board.view.w * 0.6 / speed + SPLASH;
|
|
492
|
+
float clock = board.time + hash(index, 7) * cycle;
|
|
493
|
+
int key = index * 131 + int(floor(clock / cycle));
|
|
494
|
+
Drop d;
|
|
495
|
+
d.heading = normalize(vec2(params.wind, 1.0));
|
|
496
|
+
d.start = board.view.xy + vec2(hash(key, 1) * 1.2 - 0.1, hash(key, 2) * 0.9 - 0.15) * board.view.zw;
|
|
497
|
+
d.reach = (0.25 + hash(key, 3) * 0.55) * board.view.w;
|
|
498
|
+
d.travelled = mod(clock, cycle) * speed;
|
|
499
|
+
d.lands = false;
|
|
500
|
+
d.landing = d.reach;
|
|
501
|
+
if (surface(d.start).inside) { d.reach = 0.0; return d; }
|
|
502
|
+
float limit = min(d.reach, streak ? d.travelled + 0.15 * d.reach : d.travelled);
|
|
503
|
+
// Sphere-trace the item edges along the drop's path.
|
|
504
|
+
float ahead = 0.0;
|
|
505
|
+
for (int i = 0; i < 40 && params.splash > 0.5; i++) {
|
|
506
|
+
float gap = surface(d.start + d.heading * ahead).distance;
|
|
507
|
+
if (gap < pixel) { d.lands = true; d.landing = ahead; break; }
|
|
508
|
+
ahead += max(gap, 2.0 * pixel);
|
|
509
|
+
if (ahead > limit) break;
|
|
510
|
+
}
|
|
511
|
+
return d;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
Sprite sprite(int id) {
|
|
515
|
+
int index = id / PARTS;
|
|
516
|
+
int part = id - index * PARTS;
|
|
517
|
+
Sprite s = makeSprite(vec2(0.0), vec2(0.0));
|
|
518
|
+
if (hash(index, 11) > params.density || (part > 0 && params.splash < 0.5)) { s.visible = false; return s; }
|
|
519
|
+
float pixel = 1.0 / board.zoom;
|
|
520
|
+
vec4 tint = board.dark > 0.5 ? vec4(0.75, 0.84, 1.0, 0.5) : vec4(0.3, 0.4, 0.55, 0.45);
|
|
521
|
+
Drop d = drop(index, pixel, part == 0);
|
|
522
|
+
if (part == 0) {
|
|
523
|
+
float end = d.lands ? d.landing : d.reach;
|
|
524
|
+
float head = min(d.travelled, end);
|
|
525
|
+
float tail = max(0.0, d.travelled - 34.0 * pixel);
|
|
526
|
+
s.visible = head > tail;
|
|
527
|
+
vec2 a = d.start + d.heading * tail;
|
|
528
|
+
vec2 b = d.start + d.heading * head;
|
|
529
|
+
s.position = (a + b) * 0.5;
|
|
530
|
+
s.size = vec2(1.4 * pixel, distance(a, b));
|
|
531
|
+
s.rotation = -atan(d.heading.x, d.heading.y);
|
|
532
|
+
float fade = d.lands ? 1.0 : 1.0 - smoothstep(0.85, 1.0, head / max(end, 1e-3));
|
|
533
|
+
s.color = vec4(tint.rgb, tint.a * smoothstep(0.0, 0.08 * d.reach, head) * fade);
|
|
534
|
+
return s;
|
|
535
|
+
}
|
|
536
|
+
float age = (d.travelled - d.landing) / (SPEED * pixel);
|
|
537
|
+
if (!d.lands || age < 0.0 || age > SPLASH) { s.visible = false; return s; }
|
|
538
|
+
vec2 hit = d.start + d.heading * d.landing;
|
|
539
|
+
vec2 normal = surface(hit - d.heading * 2.0 * pixel).normal;
|
|
540
|
+
vec2 side = vec2(-normal.y, normal.x);
|
|
541
|
+
vec2 velocity = (normal * (120.0 + 120.0 * hash(index * 7 + part, 6)) + side * (hash(index * 7 + part, 5) - 0.5) * 220.0) * pixel;
|
|
542
|
+
s.position = hit + velocity * age + vec2(0.0, 450.0 * pixel) * age * age;
|
|
543
|
+
s.size = vec2(2.6 * pixel) * (1.0 - 0.5 * age / SPLASH);
|
|
544
|
+
s.color = vec4(tint.rgb, 1.6 * tint.a * (1.0 - age / SPLASH));
|
|
545
|
+
s.data = vec4(1.0);
|
|
546
|
+
return s;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
vec4 effect(Fragment f) {
|
|
550
|
+
vec2 c = f.uv - 0.5;
|
|
551
|
+
float shape = f.data.x > 0.5
|
|
552
|
+
? smoothstep(0.5, 0.2, length(c))
|
|
553
|
+
: smoothstep(0.5, 0.0, abs(c.x)) * (0.5 - c.y);
|
|
554
|
+
return vec4(f.color.rgb, f.color.a * shape);
|
|
555
|
+
}
|
|
556
|
+
\`;
|
|
557
|
+
|
|
558
|
+
export const shader = {
|
|
559
|
+
surfaces: true,
|
|
560
|
+
passes: [{ glsl, sprites: DROPS * PARTS }],
|
|
561
|
+
};
|
|
562
|
+
`;
|
|
563
|
+
const BOARD_SCRIPT_SENSES_EXAMPLE = `// Helpers over raw browser:* input. import { onMotion, onAudio } from "./senses.js";
|
|
564
|
+
|
|
565
|
+
const DEG = Math.PI / 180;
|
|
566
|
+
const vec = (v) => ({ x: v?.x ?? 0, y: v?.y ?? 0, z: v?.z ?? 0 });
|
|
567
|
+
const sub = (a, b) => ({ x: a.x - b.x, y: a.y - b.y, z: a.z - b.z });
|
|
568
|
+
|
|
569
|
+
// Device axes to screen axes: x right, y up, z out of the screen, however it is turned.
|
|
570
|
+
export function toScreen({ x, y, z }, angle) {
|
|
571
|
+
const c = Math.round(Math.cos(angle * DEG));
|
|
572
|
+
const s = Math.round(Math.sin(angle * DEG));
|
|
573
|
+
return { x: x * c - y * s, y: x * s + y * c, z };
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Calls handler once a frame with the samples since the last one: acceleration and
|
|
577
|
+
// gravity in m/s², rotationRate in rad/s, all in screen axes.
|
|
578
|
+
export function onMotion(ctx, handler) {
|
|
579
|
+
let samples = [];
|
|
580
|
+
let up = { x: 0, y: 0, z: 0 };
|
|
581
|
+
const stops = [
|
|
582
|
+
ctx.on("browser:devicemotion", ({ data }) => {
|
|
583
|
+
const total = vec(data.accelerationIncludingGravity);
|
|
584
|
+
let acceleration = data.acceleration && vec(data.acceleration);
|
|
585
|
+
if (acceleration) up = sub(total, acceleration);
|
|
586
|
+
else {
|
|
587
|
+
up = { x: up.x + (total.x - up.x) * 0.1, y: up.y + (total.y - up.y) * 0.1, z: up.z + (total.z - up.z) * 0.1 };
|
|
588
|
+
acceleration = sub(total, up);
|
|
589
|
+
}
|
|
590
|
+
const rate = data.rotationRate ?? {};
|
|
591
|
+
const angle = ctx.env.angle;
|
|
592
|
+
samples.push({
|
|
593
|
+
t: data.t,
|
|
594
|
+
acceleration: toScreen(acceleration, angle),
|
|
595
|
+
gravity: toScreen({ x: -up.x, y: -up.y, z: -up.z }, angle),
|
|
596
|
+
rotationRate: toScreen({ x: (rate.beta ?? 0) * DEG, y: (rate.gamma ?? 0) * DEG, z: (rate.alpha ?? 0) * DEG }, angle),
|
|
597
|
+
});
|
|
598
|
+
}),
|
|
599
|
+
ctx.onFrame(() => {
|
|
600
|
+
if (!samples.length) return;
|
|
601
|
+
const batch = samples;
|
|
602
|
+
samples = [];
|
|
603
|
+
handler(batch);
|
|
604
|
+
}),
|
|
605
|
+
];
|
|
606
|
+
return () => stops.forEach((stop) => stop());
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function fft(re, im) {
|
|
610
|
+
const n = re.length;
|
|
611
|
+
for (let i = 1, j = 0; i < n; i++) {
|
|
612
|
+
let bit = n >> 1;
|
|
613
|
+
for (; j & bit; bit >>= 1) j ^= bit;
|
|
614
|
+
j ^= bit;
|
|
615
|
+
if (i < j) { [re[i], re[j]] = [re[j], re[i]]; [im[i], im[j]] = [im[j], im[i]]; }
|
|
616
|
+
}
|
|
617
|
+
for (let size = 2; size <= n; size <<= 1) {
|
|
618
|
+
const step = (-2 * Math.PI) / size;
|
|
619
|
+
for (let start = 0; start < n; start += size)
|
|
620
|
+
for (let k = 0; k < size / 2; k++) {
|
|
621
|
+
const cos = Math.cos(step * k), sin = Math.sin(step * k);
|
|
622
|
+
const a = start + k, b = a + size / 2;
|
|
623
|
+
const tr = re[b] * cos - im[b] * sin, ti = re[b] * sin + im[b] * cos;
|
|
624
|
+
re[b] = re[a] - tr; im[b] = im[a] - ti; re[a] += tr; im[a] += ti;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Calls handler for each microphone chunk with level (0–1), pitch in Hz or null,
|
|
630
|
+
// onset (a sound started) and spectrum: 32 log-spaced bands from 50 Hz to 12 kHz, 0–1.
|
|
631
|
+
export function onAudio(ctx, handler) {
|
|
632
|
+
let smooth = 0;
|
|
633
|
+
let onsetAt = -Infinity;
|
|
634
|
+
return ctx.on("browser:audio", ({ data: { samples, sampleRate, t } }) => {
|
|
635
|
+
let sum = 0;
|
|
636
|
+
for (const sample of samples) sum += sample * sample;
|
|
637
|
+
const level = Math.min(1, Math.max(0, (20 * Math.log10(Math.sqrt(sum / samples.length) || 1e-6) + 60) / 60));
|
|
638
|
+
const onset = level > 0.3 && level - smooth > 0.15 && t - onsetAt > 100;
|
|
639
|
+
if (onset) onsetAt = t;
|
|
640
|
+
smooth += (level - smooth) * 0.2;
|
|
641
|
+
const re = new Float64Array(1024), im = new Float64Array(1024);
|
|
642
|
+
re.set(samples.subarray(0, 1024));
|
|
643
|
+
fft(re, im);
|
|
644
|
+
const bin = (hz) => Math.min(511, Math.round((hz / sampleRate) * 1024));
|
|
645
|
+
const spectrum = Array.from({ length: 32 }, (_, i) => {
|
|
646
|
+
const from = bin(50 * 240 ** (i / 32)), to = Math.max(from + 1, bin(50 * 240 ** ((i + 1) / 32)));
|
|
647
|
+
let power = 0;
|
|
648
|
+
for (let k = from; k < to; k++) power += re[k] * re[k] + im[k] * im[k];
|
|
649
|
+
return Math.min(1, Math.max(0, (10 * Math.log10(power / (to - from) || 1e-12) + 40) / 70));
|
|
650
|
+
});
|
|
651
|
+
handler({ level, pitch: level > 0.2 ? pitchOf(samples, sampleRate) : null, onset, spectrum });
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function pitchOf(samples, rate) {
|
|
656
|
+
const min = Math.floor(rate / 1000), max = Math.min(samples.length >> 1, Math.ceil(rate / 60));
|
|
657
|
+
let energy = 0, best = 0, lag = 0;
|
|
658
|
+
for (let i = 0; i < max; i++) energy += samples[i] * samples[i];
|
|
659
|
+
for (let offset = min; offset < max; offset++) {
|
|
660
|
+
let sum = 0;
|
|
661
|
+
for (let i = 0; i < max; i++) sum += samples[i] * samples[i + offset];
|
|
662
|
+
if (sum > best) { best = sum; lag = offset; }
|
|
663
|
+
}
|
|
664
|
+
return energy && lag && best / energy > 0.5 ? Math.round(rate / lag) : null;
|
|
665
|
+
}
|
|
666
|
+
`;
|
|
667
|
+
const BOARD_SCRIPT_TILT_EXAMPLE = `import { onMotion } from "./senses.js";
|
|
668
|
+
|
|
669
|
+
export default function (ctx) {
|
|
670
|
+
ctx.state.ball ??= { x: 0.5, y: 0.5 };
|
|
671
|
+
onMotion(ctx, (samples) => {
|
|
672
|
+
const { gravity } = samples.at(-1);
|
|
673
|
+
const ball = ctx.state.ball;
|
|
674
|
+
ball.x = Math.min(1, Math.max(0, ball.x + gravity.x * 0.0015 * samples.length));
|
|
675
|
+
ball.y = Math.min(1, Math.max(0, ball.y - gravity.y * 0.0015 * samples.length));
|
|
676
|
+
ctx.invalidate();
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export function draw(ctx, { width, height, state }) {
|
|
681
|
+
ctx.fillStyle = "#e67845";
|
|
682
|
+
ctx.beginPath();
|
|
683
|
+
ctx.arc(state.ball.x * width, state.ball.y * height, 16, 0, Math.PI * 2);
|
|
684
|
+
ctx.fill();
|
|
685
|
+
}
|
|
686
|
+
`;
|
|
687
|
+
//#endregion
|
|
688
|
+
//#region ../sdk/src/board/model/animation.ts
|
|
689
|
+
const linear = (x) => x;
|
|
690
|
+
function cubicBezier(x1, y1, x2, y2) {
|
|
691
|
+
const cx = 3 * x1;
|
|
692
|
+
const bx = 3 * (x2 - x1) - cx;
|
|
693
|
+
const ax = 1 - cx - bx;
|
|
694
|
+
const cy = 3 * y1;
|
|
695
|
+
const by = 3 * (y2 - y1) - cy;
|
|
696
|
+
const ay = 1 - cy - by;
|
|
697
|
+
const sampleX = (t) => ((ax * t + bx) * t + cx) * t;
|
|
698
|
+
const sampleY = (t) => ((ay * t + by) * t + cy) * t;
|
|
699
|
+
const slopeX = (t) => (3 * ax * t + 2 * bx) * t + cx;
|
|
700
|
+
return (x) => {
|
|
701
|
+
if (x <= 0) return 0;
|
|
702
|
+
if (x >= 1) return 1;
|
|
703
|
+
let t = x;
|
|
704
|
+
for (let index = 0; index < 8; index += 1) {
|
|
705
|
+
const error = sampleX(t) - x;
|
|
706
|
+
if (Math.abs(error) < 1e-6) return sampleY(t);
|
|
707
|
+
const slope = slopeX(t);
|
|
708
|
+
if (Math.abs(slope) < 1e-6) break;
|
|
709
|
+
t -= error / slope;
|
|
710
|
+
}
|
|
711
|
+
let low = 0;
|
|
712
|
+
let high = 1;
|
|
713
|
+
t = x;
|
|
714
|
+
for (let index = 0; index < 32; index += 1) {
|
|
715
|
+
const value = sampleX(t);
|
|
716
|
+
if (Math.abs(value - x) < 1e-6) break;
|
|
717
|
+
if (value < x) low = t;
|
|
718
|
+
else high = t;
|
|
719
|
+
t = (low + high) / 2;
|
|
720
|
+
}
|
|
721
|
+
return sampleY(t);
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function steps(count, position) {
|
|
725
|
+
const jumps = position === "jump-none" ? count - 1 : position === "jump-both" ? count + 1 : count;
|
|
726
|
+
const start = position === "start" || position === "jump-start" || position === "jump-both";
|
|
727
|
+
return (x) => {
|
|
728
|
+
if (x >= 1) return 1;
|
|
729
|
+
const step = Math.floor(x * count) + (start ? 1 : 0);
|
|
730
|
+
return Math.min(1, Math.max(0, step / Math.max(1, jumps)));
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
const KEYWORD_EASES = {
|
|
734
|
+
linear,
|
|
735
|
+
ease: cubicBezier(.25, .1, .25, 1),
|
|
736
|
+
"ease-in": cubicBezier(.42, 0, 1, 1),
|
|
737
|
+
"ease-out": cubicBezier(0, 0, .58, 1),
|
|
738
|
+
"ease-in-out": cubicBezier(.42, 0, .58, 1),
|
|
739
|
+
"step-start": steps(1, "start"),
|
|
740
|
+
"step-end": steps(1, "end")
|
|
741
|
+
};
|
|
742
|
+
const easeCache = /* @__PURE__ */ new Map();
|
|
743
|
+
function boardEase(ease) {
|
|
744
|
+
if (!ease) return linear;
|
|
745
|
+
const key = ease.trim();
|
|
746
|
+
const keyword = KEYWORD_EASES[key];
|
|
747
|
+
if (keyword) return keyword;
|
|
748
|
+
const cached = easeCache.get(key);
|
|
749
|
+
if (cached) return cached;
|
|
750
|
+
let fn = linear;
|
|
751
|
+
const bezier = /^cubic-bezier\(([^)]+)\)$/.exec(key);
|
|
752
|
+
const stepped = /^steps\(\s*(\d+)\s*(?:,\s*([a-z-]+)\s*)?\)$/.exec(key);
|
|
753
|
+
if (bezier?.[1]) {
|
|
754
|
+
const [x1 = 0, y1 = 0, x2 = 1, y2 = 1] = bezier[1].split(",").map(Number);
|
|
755
|
+
fn = cubicBezier(x1, y1, x2, y2);
|
|
756
|
+
} else if (stepped?.[1]) fn = steps(Number(stepped[1]), stepped[2] ?? "end");
|
|
757
|
+
if (easeCache.size > 512) easeCache.clear();
|
|
758
|
+
easeCache.set(key, fn);
|
|
759
|
+
return fn;
|
|
760
|
+
}
|
|
761
|
+
function boardAnimationTime(header, elapsed) {
|
|
762
|
+
const local = Math.max(0, elapsed - header.delay);
|
|
763
|
+
if (header.loop || header.play === "always") return header.duration > 0 ? local % header.duration : 0;
|
|
764
|
+
if (local <= header.duration) return local;
|
|
765
|
+
return header.end === "reset" ? null : header.duration;
|
|
766
|
+
}
|
|
767
|
+
function parameterKind(track) {
|
|
768
|
+
const values = track.keyframes.map((keyframe) => keyframe.value);
|
|
769
|
+
if (values.every((value) => typeof value === "number")) return "number";
|
|
770
|
+
if (values.every((value) => BoardColorSchema.safeParse(value).success)) return "color";
|
|
771
|
+
return "discrete";
|
|
772
|
+
}
|
|
773
|
+
function compileBoardTrack(animationId, id, track, targetType) {
|
|
774
|
+
const resolved = resolveBoardProperty(targetType, track.property);
|
|
775
|
+
if (!resolved.ok) return null;
|
|
776
|
+
const kind = targetType === "script" || track.property.startsWith("script.params.") ? parameterKind(track) : resolved.spec.kind;
|
|
777
|
+
const times = new Float64Array(track.keyframes.length);
|
|
778
|
+
const values = [];
|
|
779
|
+
const eases = [];
|
|
780
|
+
track.keyframes.forEach((keyframe, index) => {
|
|
781
|
+
times[index] = keyframe.at;
|
|
782
|
+
values.push(keyframe.value);
|
|
783
|
+
eases.push(boardEase(keyframe.ease));
|
|
784
|
+
});
|
|
785
|
+
return {
|
|
786
|
+
id,
|
|
787
|
+
animationId,
|
|
788
|
+
target: track.target,
|
|
789
|
+
property: track.property,
|
|
790
|
+
path: track.property.split("."),
|
|
791
|
+
kind,
|
|
792
|
+
multiplicative: Boolean(resolved.spec.multiplicative),
|
|
793
|
+
composite: track.composite,
|
|
794
|
+
spline: track.interpolation === "spline" && kind === "vec2",
|
|
795
|
+
step: track.interpolation === "step" || kind === "discrete",
|
|
796
|
+
orient: Boolean(track.orient) && kind === "vec2" && track.property === "position",
|
|
797
|
+
times,
|
|
798
|
+
values,
|
|
799
|
+
eases,
|
|
800
|
+
start: times[0] ?? 0
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
function compileBoardAnimations(document) {
|
|
804
|
+
const animations = /* @__PURE__ */ new Map();
|
|
805
|
+
for (const [animationId, animation] of Object.entries(document.animations)) animations.set(animationId, compileAnimation(animationId, animation, document));
|
|
806
|
+
const incoming = new Map([...animations.keys()].map((id) => [id, 0]));
|
|
807
|
+
for (const animation of animations.values()) for (const track of animation.children) incoming.set(track.target, (incoming.get(track.target) ?? 0) + 1);
|
|
808
|
+
const order = [...animations.keys()].filter((id) => incoming.get(id) === 0).sort();
|
|
809
|
+
for (let index = 0; index < order.length; index += 1) {
|
|
810
|
+
const animation = animations.get(order[index]);
|
|
811
|
+
for (const track of animation?.children ?? []) {
|
|
812
|
+
const count = (incoming.get(track.target) ?? 1) - 1;
|
|
813
|
+
incoming.set(track.target, count);
|
|
814
|
+
if (count === 0) order.push(track.target);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (order.length !== animations.size) throw new Error("Animation graph contains a cycle");
|
|
818
|
+
return {
|
|
819
|
+
animations,
|
|
820
|
+
document,
|
|
821
|
+
order
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
function compileAnimation(animationId, animation, document) {
|
|
825
|
+
const { tracks, ...header } = animation;
|
|
826
|
+
const compiled = [];
|
|
827
|
+
const children = [];
|
|
828
|
+
for (const [id, track] of Object.entries(tracks).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
829
|
+
const targetType = track.target === "camera" ? BOARD_CAMERA_TARGET : document.animations[track.target] ? "animation" : document.board.scripts?.[track.target] ? "script" : document.items[track.target]?.type;
|
|
830
|
+
if (!targetType) continue;
|
|
831
|
+
const entry = compileBoardTrack(animationId, id, track, targetType);
|
|
832
|
+
if (!entry) continue;
|
|
833
|
+
(targetType === "animation" ? children : compiled).push(entry);
|
|
834
|
+
}
|
|
835
|
+
return {
|
|
836
|
+
id: animationId,
|
|
837
|
+
header,
|
|
838
|
+
tracks: compiled,
|
|
839
|
+
children
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function keyframeIndex(times, time) {
|
|
843
|
+
let low = 0;
|
|
844
|
+
let high = times.length - 1;
|
|
845
|
+
if (time < times[0]) return -1;
|
|
846
|
+
if (time >= times[high]) return high;
|
|
847
|
+
while (low < high) {
|
|
848
|
+
const mid = low + high + 1 >> 1;
|
|
849
|
+
if (times[mid] <= time) low = mid;
|
|
850
|
+
else high = mid - 1;
|
|
851
|
+
}
|
|
852
|
+
return low;
|
|
853
|
+
}
|
|
854
|
+
function isVec(value) {
|
|
855
|
+
return Boolean(value) && typeof value === "object" && typeof value.x === "number" && typeof value.y === "number";
|
|
856
|
+
}
|
|
857
|
+
function toVec(value) {
|
|
858
|
+
if (typeof value === "number") return {
|
|
859
|
+
x: value,
|
|
860
|
+
y: value
|
|
861
|
+
};
|
|
862
|
+
return isVec(value) ? value : {
|
|
863
|
+
x: 0,
|
|
864
|
+
y: 0
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
868
|
+
function catmullRom(p0, p1, p2, p3, t) {
|
|
869
|
+
const t2 = t * t;
|
|
870
|
+
const t3 = t2 * t;
|
|
871
|
+
return .5 * (2 * p1 + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3);
|
|
872
|
+
}
|
|
873
|
+
function hex(color) {
|
|
874
|
+
return `#${Math.max(0, Math.min(16777215, Math.round(color))).toString(16).padStart(6, "0")}`;
|
|
875
|
+
}
|
|
876
|
+
function mixColor(a, b, t, resolve) {
|
|
877
|
+
const left = resolve(a);
|
|
878
|
+
const right = resolve(b);
|
|
879
|
+
if (left === null || right === null) return t < 1 ? a : b;
|
|
880
|
+
const from = typeof left === "number" ? {
|
|
881
|
+
color: left,
|
|
882
|
+
alpha: 1
|
|
883
|
+
} : left;
|
|
884
|
+
const to = typeof right === "number" ? {
|
|
885
|
+
color: right,
|
|
886
|
+
alpha: 1
|
|
887
|
+
} : right;
|
|
888
|
+
const alpha = lerp(from.alpha, to.alpha, t);
|
|
889
|
+
const channel = (shift) => alpha > 0 ? Math.round(lerp((from.color >> shift & 255) * from.alpha, (to.color >> shift & 255) * to.alpha, t) / alpha) : 0;
|
|
890
|
+
const rgb = hex(channel(16) << 16 | channel(8) << 8 | channel(0));
|
|
891
|
+
return alpha >= 1 ? rgb : `${rgb}${Math.round(Math.max(0, alpha) * 255).toString(16).padStart(2, "0")}`;
|
|
892
|
+
}
|
|
893
|
+
function parseHexColor(color) {
|
|
894
|
+
if (typeof color !== "string") return null;
|
|
895
|
+
const match = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim());
|
|
896
|
+
if (!match?.[1]) return null;
|
|
897
|
+
const digits = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join("") : match[1];
|
|
898
|
+
return Number.parseInt(digits, 16);
|
|
899
|
+
}
|
|
900
|
+
function parseAnimationColor(color) {
|
|
901
|
+
if (typeof color === "string") {
|
|
902
|
+
if (color.trim().toLowerCase() === "transparent") return {
|
|
903
|
+
color: 0,
|
|
904
|
+
alpha: 0
|
|
905
|
+
};
|
|
906
|
+
const match = /^#([0-9a-f]{4}|[0-9a-f]{8})$/i.exec(color.trim());
|
|
907
|
+
if (match?.[1]) {
|
|
908
|
+
const digits = match[1].length === 4 ? [...match[1]].map((digit) => digit + digit).join("") : match[1];
|
|
909
|
+
return {
|
|
910
|
+
color: Number.parseInt(digits.slice(0, 6), 16),
|
|
911
|
+
alpha: Number.parseInt(digits.slice(6), 16) / 255
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return parseHexColor(color);
|
|
916
|
+
}
|
|
917
|
+
function blend(track, index, time, resolveColor) {
|
|
918
|
+
const { times, values } = track;
|
|
919
|
+
const from = values[index];
|
|
920
|
+
const to = values[index + 1];
|
|
921
|
+
const t0 = times[index];
|
|
922
|
+
const t1 = times[index + 1];
|
|
923
|
+
if (to === void 0 || t1 <= t0) return from;
|
|
924
|
+
const progress = track.eases[index + 1]((time - t0) / (t1 - t0));
|
|
925
|
+
if (track.step) return progress >= 1 ? to : from;
|
|
926
|
+
switch (track.kind) {
|
|
927
|
+
case "number": return typeof from === "number" && typeof to === "number" ? lerp(from, to, progress) : from;
|
|
928
|
+
case "vec2":
|
|
929
|
+
case "scale": {
|
|
930
|
+
if (track.kind === "scale" && typeof from === "number" && typeof to === "number") return lerp(from, to, progress);
|
|
931
|
+
const a = toVec(from);
|
|
932
|
+
const b = toVec(to);
|
|
933
|
+
if (track.spline) {
|
|
934
|
+
const before = toVec(values[index - 1] ?? from);
|
|
935
|
+
const after = toVec(values[index + 2] ?? to);
|
|
936
|
+
return {
|
|
937
|
+
x: catmullRom(before.x, a.x, b.x, after.x, progress),
|
|
938
|
+
y: catmullRom(before.y, a.y, b.y, after.y, progress)
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
x: lerp(a.x, b.x, progress),
|
|
943
|
+
y: lerp(a.y, b.y, progress)
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
case "color": return mixColor(from, to, progress, resolveColor);
|
|
947
|
+
default: return progress >= 1 ? to : from;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function sampleBoardTrack(track, time, resolveColor = parseAnimationColor) {
|
|
951
|
+
const index = keyframeIndex(track.times, time);
|
|
952
|
+
if (index < 0) return track.values[0];
|
|
953
|
+
return blend(track, index, time, resolveColor);
|
|
954
|
+
}
|
|
955
|
+
function orientation(track, time, resolveColor) {
|
|
956
|
+
const span = Math.max(1, (track.times[track.times.length - 1] - track.start) / 1e3);
|
|
957
|
+
const a = toVec(sampleBoardTrack(track, Math.max(track.start, time - span), resolveColor));
|
|
958
|
+
const b = toVec(sampleBoardTrack(track, time + span, resolveColor));
|
|
959
|
+
if (Math.hypot(b.x - a.x, b.y - a.y) < 1e-6) return null;
|
|
960
|
+
return Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI;
|
|
961
|
+
}
|
|
962
|
+
function readPath(value, path) {
|
|
963
|
+
let current = value;
|
|
964
|
+
for (const segment of path) {
|
|
965
|
+
if (typeof current === "number" && (segment === "x" || segment === "y")) return current;
|
|
966
|
+
if (!current || typeof current !== "object") return void 0;
|
|
967
|
+
current = current[segment];
|
|
968
|
+
}
|
|
969
|
+
return current;
|
|
970
|
+
}
|
|
971
|
+
function writePath(value, path, next, depth = 0) {
|
|
972
|
+
const key = path[depth];
|
|
973
|
+
if (depth === path.length - 1) return {
|
|
974
|
+
...value,
|
|
975
|
+
[key]: next
|
|
976
|
+
};
|
|
977
|
+
let child = value[key];
|
|
978
|
+
if (typeof child === "number") child = {
|
|
979
|
+
x: child,
|
|
980
|
+
y: child
|
|
981
|
+
};
|
|
982
|
+
const base = child && typeof child === "object" ? child : {};
|
|
983
|
+
return {
|
|
984
|
+
...value,
|
|
985
|
+
[key]: writePath(base, path, next, depth + 1)
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function combine(track, base, value) {
|
|
989
|
+
if (track.composite !== "add") return value;
|
|
990
|
+
if (track.kind === "number") {
|
|
991
|
+
if (typeof base !== "number" || typeof value !== "number") return value;
|
|
992
|
+
return track.multiplicative ? base * value : base + value;
|
|
993
|
+
}
|
|
994
|
+
if (track.kind === "vec2" || track.kind === "scale") {
|
|
995
|
+
if (track.multiplicative) {
|
|
996
|
+
if (typeof base === "number" && typeof value === "number") return base * value;
|
|
997
|
+
const a = toVec(base ?? 1);
|
|
998
|
+
const b = toVec(value);
|
|
999
|
+
return {
|
|
1000
|
+
x: a.x * b.x,
|
|
1001
|
+
y: a.y * b.y
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
const a = toVec(base);
|
|
1005
|
+
const b = toVec(value);
|
|
1006
|
+
return {
|
|
1007
|
+
x: a.x + b.x,
|
|
1008
|
+
y: a.y + b.y
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
return value;
|
|
1012
|
+
}
|
|
1013
|
+
function outranks(track, time, other, otherTime) {
|
|
1014
|
+
const elapsed = time - track.start;
|
|
1015
|
+
const otherElapsed = otherTime - other.start;
|
|
1016
|
+
if (elapsed >= 0 !== otherElapsed >= 0) return elapsed >= 0;
|
|
1017
|
+
const distance = Math.abs(elapsed);
|
|
1018
|
+
const otherDistance = Math.abs(otherElapsed);
|
|
1019
|
+
if (distance !== otherDistance) return distance < otherDistance;
|
|
1020
|
+
return track.id > other.id;
|
|
1021
|
+
}
|
|
1022
|
+
function evaluateBoardAnimations(compiled, times, options = {}) {
|
|
1023
|
+
const resolveColor = options.resolveColor ?? parseAnimationColor;
|
|
1024
|
+
const local = new Map(times instanceof Map ? times : Object.entries(times));
|
|
1025
|
+
for (const id of compiled.order) {
|
|
1026
|
+
const animation = compiled.animations.get(id);
|
|
1027
|
+
const time = local.get(id);
|
|
1028
|
+
if (!animation || time === void 0) continue;
|
|
1029
|
+
for (const track of animation.children) {
|
|
1030
|
+
const value = sampleBoardTrack(track, time, resolveColor);
|
|
1031
|
+
if (typeof value === "number") local.set(track.target, Math.max(0, value));
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1035
|
+
for (const [id, time] of local) {
|
|
1036
|
+
const animation = compiled.animations.get(id);
|
|
1037
|
+
if (!animation) continue;
|
|
1038
|
+
for (const track of animation.tracks) {
|
|
1039
|
+
const key = `${track.target}\u0000${track.property}`;
|
|
1040
|
+
let group = groups.get(key);
|
|
1041
|
+
if (!group) {
|
|
1042
|
+
group = {
|
|
1043
|
+
target: track.target,
|
|
1044
|
+
path: track.path,
|
|
1045
|
+
winnerTime: 0,
|
|
1046
|
+
adds: []
|
|
1047
|
+
};
|
|
1048
|
+
groups.set(key, group);
|
|
1049
|
+
}
|
|
1050
|
+
if (track.composite === "add") {
|
|
1051
|
+
group.adds.push([track, time]);
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (!group.winner || outranks(track, time, group.winner, group.winnerTime)) {
|
|
1055
|
+
group.winner = track;
|
|
1056
|
+
group.winnerTime = time;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
const items = /* @__PURE__ */ new Map();
|
|
1061
|
+
const scripts = /* @__PURE__ */ new Map();
|
|
1062
|
+
const camera = {};
|
|
1063
|
+
const ordered = [...groups.values()].sort((a, b) => a.path.length - b.path.length);
|
|
1064
|
+
for (const group of ordered) {
|
|
1065
|
+
const isCamera = group.target === BOARD_CAMERA_TARGET;
|
|
1066
|
+
const rootScript = isCamera ? void 0 : compiled.document.board.scripts?.[group.target];
|
|
1067
|
+
const itemScript = isCamera || rootScript || group.path[0] !== "script" ? void 0 : compiled.document.items[group.target]?.script;
|
|
1068
|
+
const script = rootScript || itemScript ? scripts.get(group.target) ?? rootScript ?? itemScript : void 0;
|
|
1069
|
+
if (group.path[0] === "script" && !itemScript) continue;
|
|
1070
|
+
const path = itemScript ? group.path.slice(1) : group.path;
|
|
1071
|
+
const base = isCamera || script ? void 0 : items.get(group.target) ?? compiled.document.items[group.target];
|
|
1072
|
+
if (!isCamera && !script && !base) continue;
|
|
1073
|
+
let value = isCamera ? camera[path[0]] : readPath(script ?? base, path);
|
|
1074
|
+
let orientTrack = null;
|
|
1075
|
+
if (group.winner) {
|
|
1076
|
+
value = sampleBoardTrack(group.winner, group.winnerTime, resolveColor);
|
|
1077
|
+
if (group.winner.orient) orientTrack = [group.winner, group.winnerTime];
|
|
1078
|
+
}
|
|
1079
|
+
for (const [track, time] of group.adds) {
|
|
1080
|
+
value = combine(track, value, sampleBoardTrack(track, time, resolveColor));
|
|
1081
|
+
if (track.orient && !orientTrack) orientTrack = [track, time];
|
|
1082
|
+
}
|
|
1083
|
+
if (isCamera) {
|
|
1084
|
+
camera[group.path[0]] = value;
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
if (script) {
|
|
1088
|
+
scripts.set(group.target, writePath(script, path, value));
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
let next = writePath(base, group.path, value);
|
|
1092
|
+
if (orientTrack) {
|
|
1093
|
+
const angle = orientation(orientTrack[0], orientTrack[1], resolveColor);
|
|
1094
|
+
if (angle !== null) next = {
|
|
1095
|
+
...next,
|
|
1096
|
+
rotation: base.rotation + angle
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
items.set(group.target, next);
|
|
1100
|
+
}
|
|
1101
|
+
return {
|
|
1102
|
+
items,
|
|
1103
|
+
scripts,
|
|
1104
|
+
camera,
|
|
1105
|
+
times: local
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
const BOARD_SCRIPT_HISTORY_MS = 1e3 / 30;
|
|
1109
|
+
function boardAnimatesScriptParams(document) {
|
|
1110
|
+
return Object.values(document.animations).some((animation) => Object.values(animation.tracks).some((track) => /^(script\.)?params\./.test(track.property)));
|
|
1111
|
+
}
|
|
1112
|
+
function withBoardScripts(document, scripts) {
|
|
1113
|
+
if (scripts.size === 0) return document;
|
|
1114
|
+
const stored = document.board.scripts;
|
|
1115
|
+
let board = document.board;
|
|
1116
|
+
let items = document.items;
|
|
1117
|
+
for (const [id, script] of scripts) {
|
|
1118
|
+
const root = stored?.[id];
|
|
1119
|
+
if (root) {
|
|
1120
|
+
if (board === document.board) board = {
|
|
1121
|
+
...board,
|
|
1122
|
+
scripts: { ...stored }
|
|
1123
|
+
};
|
|
1124
|
+
board.scripts[id] = {
|
|
1125
|
+
...root,
|
|
1126
|
+
params: script.params
|
|
1127
|
+
};
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1130
|
+
const item = items[id];
|
|
1131
|
+
if (!item?.script) continue;
|
|
1132
|
+
if (items === document.items) items = { ...items };
|
|
1133
|
+
items[id] = {
|
|
1134
|
+
...item,
|
|
1135
|
+
script: {
|
|
1136
|
+
...item.script,
|
|
1137
|
+
params: script.params
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
return board === document.board && items === document.items ? document : {
|
|
1142
|
+
...document,
|
|
1143
|
+
board,
|
|
1144
|
+
items
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
function applyBoardEvaluation(document, evaluation) {
|
|
1148
|
+
const scripted = withBoardScripts(document, evaluation.scripts);
|
|
1149
|
+
if (evaluation.items.size === 0) return scripted;
|
|
1150
|
+
const items = { ...scripted.items };
|
|
1151
|
+
for (const [id, item] of evaluation.items) {
|
|
1152
|
+
const script = scripted.items[id]?.script;
|
|
1153
|
+
items[id] = script && script !== document.items[id]?.script ? {
|
|
1154
|
+
...item,
|
|
1155
|
+
script
|
|
1156
|
+
} : item;
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
...scripted,
|
|
1160
|
+
items
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
//#endregion
|
|
1164
|
+
//#region ../sdk/src/board/model/scene.ts
|
|
1165
|
+
const EPSILON = 1e-6;
|
|
1166
|
+
function stripScene(item) {
|
|
1167
|
+
if (!("frame" in item) && !("id" in item)) return item;
|
|
1168
|
+
const { id: _id, frame: _frame, ...rest } = item;
|
|
1169
|
+
return rest;
|
|
1170
|
+
}
|
|
1171
|
+
function orderBoardItems(items) {
|
|
1172
|
+
const children = /* @__PURE__ */ new Map();
|
|
1173
|
+
for (const [id, item] of Object.entries(items)) {
|
|
1174
|
+
const parent = item.parent && items[item.parent] && item.parent !== id ? item.parent : "";
|
|
1175
|
+
const list = children.get(parent) ?? [];
|
|
1176
|
+
list.push(id);
|
|
1177
|
+
children.set(parent, list);
|
|
1178
|
+
}
|
|
1179
|
+
const compare = (a, b) => (items[a]?.z ?? 0) - (items[b]?.z ?? 0) || (a < b ? -1 : a > b ? 1 : 0);
|
|
1180
|
+
for (const list of children.values()) list.sort(compare);
|
|
1181
|
+
const order = [];
|
|
1182
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1183
|
+
const visit = (id) => {
|
|
1184
|
+
if (seen.has(id)) return;
|
|
1185
|
+
seen.add(id);
|
|
1186
|
+
order.push(id);
|
|
1187
|
+
for (const child of children.get(id) ?? []) visit(child);
|
|
1188
|
+
};
|
|
1189
|
+
for (const id of children.get("") ?? []) visit(id);
|
|
1190
|
+
for (const id of Object.keys(items)) visit(id);
|
|
1191
|
+
return order;
|
|
1192
|
+
}
|
|
1193
|
+
function buildBoardScene(document, previous) {
|
|
1194
|
+
const items = document.items;
|
|
1195
|
+
const children = /* @__PURE__ */ new Map();
|
|
1196
|
+
const binders = /* @__PURE__ */ new Map();
|
|
1197
|
+
for (const [id, item] of Object.entries(items)) {
|
|
1198
|
+
const parent = item.parent && items[item.parent] ? item.parent : "";
|
|
1199
|
+
const list = children.get(parent) ?? [];
|
|
1200
|
+
list.push(id);
|
|
1201
|
+
children.set(parent, list);
|
|
1202
|
+
for (const bound of arrowBindings(item)) binders.set(bound, [...binders.get(bound) ?? [], id]);
|
|
1203
|
+
}
|
|
1204
|
+
const layout = createBoardLayout((id) => items[id], (id) => [...children.get(id) ?? [], ...binders.get(id) ?? []]);
|
|
1205
|
+
const stable = /* @__PURE__ */ new Map();
|
|
1206
|
+
const isStable = (id, depth = 0) => {
|
|
1207
|
+
const known = stable.get(id);
|
|
1208
|
+
if (known !== void 0) return known;
|
|
1209
|
+
const item = items[id];
|
|
1210
|
+
const before = previous?.get(id);
|
|
1211
|
+
let result = Boolean(item && before && stripSceneSource(before) === item) && depth < 64;
|
|
1212
|
+
if (result && item?.parent && items[item.parent]) result = isStable(item.parent, depth + 1);
|
|
1213
|
+
if (result && item) {
|
|
1214
|
+
for (const bound of arrowBindings(item)) if (items[bound] && !isStable(bound, depth + 1)) result = false;
|
|
1215
|
+
}
|
|
1216
|
+
stable.set(id, result);
|
|
1217
|
+
return result;
|
|
1218
|
+
};
|
|
1219
|
+
const ordered = orderBoardItems(items);
|
|
1220
|
+
const sceneItems = [];
|
|
1221
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1222
|
+
const indexById = /* @__PURE__ */ new Map();
|
|
1223
|
+
for (const id of ordered) {
|
|
1224
|
+
const item = items[id];
|
|
1225
|
+
const scene = (isStable(id) ? previous?.get(id) : void 0) ?? toSceneItem(id, item, layout);
|
|
1226
|
+
indexById.set(id, sceneItems.length);
|
|
1227
|
+
sceneItems.push(scene);
|
|
1228
|
+
byId.set(id, scene);
|
|
1229
|
+
}
|
|
1230
|
+
return {
|
|
1231
|
+
items: sceneItems,
|
|
1232
|
+
get: (id) => byId.get(id),
|
|
1233
|
+
indexOf: (id) => indexById.get(id) ?? -1,
|
|
1234
|
+
layout,
|
|
1235
|
+
children: (id) => children.get(id ?? "") ?? [],
|
|
1236
|
+
descendants: (id) => {
|
|
1237
|
+
const result = [];
|
|
1238
|
+
const seen = /* @__PURE__ */ new Set([id]);
|
|
1239
|
+
const stack = [...children.get(id) ?? []];
|
|
1240
|
+
while (stack.length) {
|
|
1241
|
+
const next = stack.pop();
|
|
1242
|
+
if (seen.has(next)) continue;
|
|
1243
|
+
seen.add(next);
|
|
1244
|
+
result.push(next);
|
|
1245
|
+
stack.push(...children.get(next) ?? []);
|
|
1246
|
+
}
|
|
1247
|
+
return result;
|
|
1248
|
+
},
|
|
1249
|
+
binders: (id) => binders.get(id) ?? [],
|
|
1250
|
+
opacity: (id) => cumulativeOpacity((key) => items[key], id),
|
|
1251
|
+
shown: (id) => cumulativeOpacity((key) => items[key], id, true) > 0
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function cumulativeOpacity(lookup, id, presence = false) {
|
|
1255
|
+
let value = 1;
|
|
1256
|
+
let cursor = id;
|
|
1257
|
+
for (let depth = 0; cursor && depth < 64; depth += 1) {
|
|
1258
|
+
const item = lookup(cursor);
|
|
1259
|
+
if (!item) break;
|
|
1260
|
+
if (item.visible === false) return 0;
|
|
1261
|
+
if (!presence) value *= item.opacity;
|
|
1262
|
+
cursor = item.parent;
|
|
1263
|
+
}
|
|
1264
|
+
return value;
|
|
1265
|
+
}
|
|
1266
|
+
function refreshBoardScene(previous, lookup, ids) {
|
|
1267
|
+
const changedIds = [...ids];
|
|
1268
|
+
if (changedIds.length === 0) return previous;
|
|
1269
|
+
const dependents = (id) => [...previous.children(id), ...previous.binders(id)];
|
|
1270
|
+
const layout = previous.layout;
|
|
1271
|
+
layout.setLookup(lookup);
|
|
1272
|
+
layout.invalidate(changedIds);
|
|
1273
|
+
const affected = /* @__PURE__ */ new Set();
|
|
1274
|
+
const stack = [...changedIds];
|
|
1275
|
+
while (stack.length) {
|
|
1276
|
+
const id = stack.pop();
|
|
1277
|
+
if (affected.has(id) || !lookup(id)) continue;
|
|
1278
|
+
affected.add(id);
|
|
1279
|
+
stack.push(...dependents(id));
|
|
1280
|
+
}
|
|
1281
|
+
if (affected.size === 0) return previous;
|
|
1282
|
+
const sceneItems = previous.items.slice();
|
|
1283
|
+
const chain = refreshed.get(previous);
|
|
1284
|
+
const base = chain?.base ?? previous;
|
|
1285
|
+
const overrides = new Map(chain?.overrides);
|
|
1286
|
+
for (const id of affected) {
|
|
1287
|
+
const index = previous.indexOf(id);
|
|
1288
|
+
const scene = toSceneItem(id, lookup(id), layout);
|
|
1289
|
+
overrides.set(id, scene);
|
|
1290
|
+
if (index >= 0) sceneItems[index] = scene;
|
|
1291
|
+
}
|
|
1292
|
+
const scene = {
|
|
1293
|
+
...base,
|
|
1294
|
+
items: sceneItems,
|
|
1295
|
+
get: (id) => overrides.get(id) ?? base.get(id),
|
|
1296
|
+
layout,
|
|
1297
|
+
opacity: (id) => cumulativeOpacity(lookup, id),
|
|
1298
|
+
shown: (id) => cumulativeOpacity(lookup, id, true) > 0
|
|
1299
|
+
};
|
|
1300
|
+
refreshed.set(scene, {
|
|
1301
|
+
base,
|
|
1302
|
+
overrides
|
|
1303
|
+
});
|
|
1304
|
+
return scene;
|
|
1305
|
+
}
|
|
1306
|
+
const refreshed = /* @__PURE__ */ new WeakMap();
|
|
1307
|
+
const sources = /* @__PURE__ */ new WeakMap();
|
|
1308
|
+
function stripSceneSource(scene) {
|
|
1309
|
+
return sources.get(scene);
|
|
1310
|
+
}
|
|
1311
|
+
function toSceneItem(id, item, layout) {
|
|
1312
|
+
const scene = {
|
|
1313
|
+
...item,
|
|
1314
|
+
id,
|
|
1315
|
+
frame: layout.frame(id)
|
|
1316
|
+
};
|
|
1317
|
+
sources.set(scene, item);
|
|
1318
|
+
return scene;
|
|
1319
|
+
}
|
|
1320
|
+
function sameFrame(a, b) {
|
|
1321
|
+
return Math.abs(a.x - b.x) < EPSILON && Math.abs(a.y - b.y) < EPSILON && Math.abs(a.width - b.width) < EPSILON && Math.abs(a.height - b.height) < EPSILON && Math.abs(a.rotation - b.rotation) < EPSILON;
|
|
1322
|
+
}
|
|
1323
|
+
function sceneItemToItem(scene, layout) {
|
|
1324
|
+
const source = sources.get(scene);
|
|
1325
|
+
if (source) return source;
|
|
1326
|
+
const item = stripScene(scene);
|
|
1327
|
+
const frame = scene.frame;
|
|
1328
|
+
if (!frame) return item;
|
|
1329
|
+
if (layout.has(scene.id) && sameFrame(frame, layout.frame(scene.id))) return item;
|
|
1330
|
+
return placeItem(item, frame, item.parent && layout.has(item.parent) ? layout.matrix(item.parent) : IDENTITY_MATRIX, itemBox(item, layout, scene.id));
|
|
1331
|
+
}
|
|
1332
|
+
function itemBox(item, layout, id) {
|
|
1333
|
+
if ("size" in item && item.size) return {
|
|
1334
|
+
x: 0,
|
|
1335
|
+
y: 0,
|
|
1336
|
+
width: item.size.width,
|
|
1337
|
+
height: item.size.height
|
|
1338
|
+
};
|
|
1339
|
+
if (item.type === "text") {
|
|
1340
|
+
const text = layoutBoardText(item.props);
|
|
1341
|
+
return {
|
|
1342
|
+
x: 0,
|
|
1343
|
+
y: 0,
|
|
1344
|
+
width: text.width,
|
|
1345
|
+
height: text.height
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
if (item.type === "draw") return drawPointsBounds(item.props.points, item.style.strokeWidth ?? 4);
|
|
1349
|
+
return layout.box(id);
|
|
1350
|
+
}
|
|
1351
|
+
function placeItem(item, frame, parent, box) {
|
|
1352
|
+
const [a, b] = parent;
|
|
1353
|
+
const parentScale = Math.hypot(a, b) || 1;
|
|
1354
|
+
const { rotation: parentRotation, mirrored: parentMirrored } = matrixRotation(parent);
|
|
1355
|
+
const center = applyMatrix(invertMatrix(parent), {
|
|
1356
|
+
x: frame.x + frame.width / 2,
|
|
1357
|
+
y: frame.y + frame.height / 2
|
|
1358
|
+
});
|
|
1359
|
+
const scale = scaleVector(item.scale);
|
|
1360
|
+
const width = frame.width / parentScale / (Math.abs(scale.x) || 1);
|
|
1361
|
+
const height = frame.height / parentScale / (Math.abs(scale.y) || 1);
|
|
1362
|
+
if (item.type === "arrow") {
|
|
1363
|
+
const currentCenter = {
|
|
1364
|
+
x: item.position.x + box.x + box.width / 2,
|
|
1365
|
+
y: item.position.y + box.y + box.height / 2
|
|
1366
|
+
};
|
|
1367
|
+
const dx = center.x - currentCenter.x;
|
|
1368
|
+
const dy = center.y - currentCenter.y;
|
|
1369
|
+
if (Math.abs(dx) < EPSILON && Math.abs(dy) < EPSILON) return item;
|
|
1370
|
+
return {
|
|
1371
|
+
...item,
|
|
1372
|
+
position: {
|
|
1373
|
+
x: item.position.x + dx,
|
|
1374
|
+
y: item.position.y + dy
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
let next = item;
|
|
1379
|
+
let nextBox = box;
|
|
1380
|
+
if (Math.abs(width - box.width) > EPSILON || Math.abs(height - box.height) > EPSILON) {
|
|
1381
|
+
if (item.type === "text") {
|
|
1382
|
+
const factor = Math.abs(width - box.width) > EPSILON ? width / box.width : height / box.height;
|
|
1383
|
+
const props = {
|
|
1384
|
+
...item.props,
|
|
1385
|
+
fontSize: clampBoardFontSize(item.props.fontSize * factor),
|
|
1386
|
+
...item.props.width ? { width: item.props.width * factor } : {}
|
|
1387
|
+
};
|
|
1388
|
+
next = {
|
|
1389
|
+
...item,
|
|
1390
|
+
props
|
|
1391
|
+
};
|
|
1392
|
+
const text = layoutBoardText(props);
|
|
1393
|
+
nextBox = {
|
|
1394
|
+
x: 0,
|
|
1395
|
+
y: 0,
|
|
1396
|
+
width: text.width,
|
|
1397
|
+
height: text.height
|
|
1398
|
+
};
|
|
1399
|
+
} else if (item.type === "draw") {
|
|
1400
|
+
const sx = width / box.width;
|
|
1401
|
+
const sy = height / box.height;
|
|
1402
|
+
const points = item.props.points.map((point) => ({
|
|
1403
|
+
...point,
|
|
1404
|
+
x: box.x + (point.x - box.x) * sx,
|
|
1405
|
+
y: box.y + (point.y - box.y) * sy
|
|
1406
|
+
}));
|
|
1407
|
+
next = {
|
|
1408
|
+
...item,
|
|
1409
|
+
props: {
|
|
1410
|
+
...item.props,
|
|
1411
|
+
points
|
|
1412
|
+
}
|
|
1413
|
+
};
|
|
1414
|
+
nextBox = drawPointsBounds(points, item.style.strokeWidth ?? 4);
|
|
1415
|
+
} else if ("size" in item && item.size) {
|
|
1416
|
+
next = {
|
|
1417
|
+
...item,
|
|
1418
|
+
size: {
|
|
1419
|
+
width,
|
|
1420
|
+
height
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
nextBox = {
|
|
1424
|
+
x: 0,
|
|
1425
|
+
y: 0,
|
|
1426
|
+
width,
|
|
1427
|
+
height
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const turned = frame.rotation - parentRotation - (scale.y < 0 ? 180 : 0);
|
|
1432
|
+
const rotation = parentMirrored ? -turned : turned;
|
|
1433
|
+
const radians = rotation * Math.PI / 180;
|
|
1434
|
+
const origin = {
|
|
1435
|
+
x: nextBox.x + item.origin.x * nextBox.width,
|
|
1436
|
+
y: nextBox.y + item.origin.y * nextBox.height
|
|
1437
|
+
};
|
|
1438
|
+
const boxCenter = {
|
|
1439
|
+
x: nextBox.x + nextBox.width / 2,
|
|
1440
|
+
y: nextBox.y + nextBox.height / 2
|
|
1441
|
+
};
|
|
1442
|
+
const dx = (boxCenter.x - origin.x) * scale.x;
|
|
1443
|
+
const dy = (boxCenter.y - origin.y) * scale.y;
|
|
1444
|
+
const rotated = {
|
|
1445
|
+
x: dx * Math.cos(radians) - dy * Math.sin(radians),
|
|
1446
|
+
y: dx * Math.sin(radians) + dy * Math.cos(radians)
|
|
1447
|
+
};
|
|
1448
|
+
const position = {
|
|
1449
|
+
x: center.x - origin.x - rotated.x,
|
|
1450
|
+
y: center.y - origin.y - rotated.y
|
|
1451
|
+
};
|
|
1452
|
+
return {
|
|
1453
|
+
...next,
|
|
1454
|
+
position,
|
|
1455
|
+
rotation: normalizeDegrees(rotation)
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
function normalizeDegrees(value) {
|
|
1459
|
+
const normalized = (value % 360 + 540) % 360 - 180;
|
|
1460
|
+
return Math.abs(normalized) < EPSILON ? 0 : Number(normalized.toFixed(6));
|
|
1461
|
+
}
|
|
1462
|
+
//#endregion
|
|
1463
|
+
//#region ../sdk/src/board/model/sampling.ts
|
|
1464
|
+
function createBoardAnimationSampler(document, animation, options = {}) {
|
|
1465
|
+
const selected = animation ? document.animations[animation] : void 0;
|
|
1466
|
+
if (animation && !selected) throw new Error(`Animation ${animation} does not exist.`);
|
|
1467
|
+
const compiled = compileBoardAnimations(document);
|
|
1468
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1469
|
+
const geometry = /* @__PURE__ */ new Map();
|
|
1470
|
+
function sample(time) {
|
|
1471
|
+
const times = /* @__PURE__ */ new Map();
|
|
1472
|
+
for (const [id, entry] of compiled.animations) if (entry.header.play === "always") times.set(id, boardAnimationTime(entry.header, time) ?? 0);
|
|
1473
|
+
if (animation && selected) times.set(animation, Math.min(time, selected.duration));
|
|
1474
|
+
const evaluation = evaluateBoardAnimations(compiled, times, options);
|
|
1475
|
+
return {
|
|
1476
|
+
document: applyBoardEvaluation(document, evaluation),
|
|
1477
|
+
evaluation
|
|
1478
|
+
};
|
|
1479
|
+
}
|
|
1480
|
+
function stateAt(time) {
|
|
1481
|
+
if (!Number.isFinite(time) || time < 0) throw new Error("Animation time must be finite and non-negative.");
|
|
1482
|
+
let value = cache.get(time);
|
|
1483
|
+
if (!value) {
|
|
1484
|
+
value = sample(time);
|
|
1485
|
+
const oldest = cache.keys().next().value;
|
|
1486
|
+
if (cache.size >= 64 && oldest !== void 0) cache.delete(oldest);
|
|
1487
|
+
cache.set(time, value);
|
|
1488
|
+
}
|
|
1489
|
+
return value;
|
|
1490
|
+
}
|
|
1491
|
+
let current;
|
|
1492
|
+
return {
|
|
1493
|
+
frameAt(id, time) {
|
|
1494
|
+
const key = `${time}:${id}`;
|
|
1495
|
+
if (geometry.has(key)) return geometry.get(key);
|
|
1496
|
+
const sampled = stateAt(time).document;
|
|
1497
|
+
const items = {};
|
|
1498
|
+
const pending = [id];
|
|
1499
|
+
while (pending.length) {
|
|
1500
|
+
const next = pending.pop();
|
|
1501
|
+
if (!next || items[next]) continue;
|
|
1502
|
+
const item = sampled.items[next];
|
|
1503
|
+
if (!item) continue;
|
|
1504
|
+
items[next] = item;
|
|
1505
|
+
if (item.parent) pending.push(item.parent);
|
|
1506
|
+
pending.push(...arrowBindings(item));
|
|
1507
|
+
}
|
|
1508
|
+
const frame = buildBoardScene({
|
|
1509
|
+
...sampled,
|
|
1510
|
+
items
|
|
1511
|
+
}).get(id)?.frame;
|
|
1512
|
+
if (geometry.size >= 2048) geometry.clear();
|
|
1513
|
+
geometry.set(key, frame);
|
|
1514
|
+
return frame;
|
|
1515
|
+
},
|
|
1516
|
+
at(time) {
|
|
1517
|
+
if (current?.time === time) return current.value;
|
|
1518
|
+
const sampled = stateAt(time);
|
|
1519
|
+
const value = {
|
|
1520
|
+
...sampled,
|
|
1521
|
+
scene: buildBoardScene(sampled.document)
|
|
1522
|
+
};
|
|
1523
|
+
current = {
|
|
1524
|
+
time,
|
|
1525
|
+
value
|
|
1526
|
+
};
|
|
1527
|
+
return value;
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
function resolveBoardAnimationCamera(override, bounds, surface, time, base = {
|
|
1532
|
+
x: 0,
|
|
1533
|
+
y: 0,
|
|
1534
|
+
zoom: 1
|
|
1535
|
+
}) {
|
|
1536
|
+
let camera = override.focus === void 0 ? base : cameraForFocus(override.focus, bounds, surface, { padding: 48 }) ?? base;
|
|
1537
|
+
if (override.zoom !== void 0) camera = {
|
|
1538
|
+
...camera,
|
|
1539
|
+
zoom: override.zoom
|
|
1540
|
+
};
|
|
1541
|
+
if (override.center) camera = cameraForState({
|
|
1542
|
+
centerX: override.center.x,
|
|
1543
|
+
centerY: override.center.y,
|
|
1544
|
+
zoom: camera.zoom
|
|
1545
|
+
}, surface);
|
|
1546
|
+
if (override.shake) camera = {
|
|
1547
|
+
...camera,
|
|
1548
|
+
x: camera.x + Math.sin(time / 1e3 * 91.3) * override.shake,
|
|
1549
|
+
y: camera.y + Math.cos(time / 1e3 * 77.9) * override.shake
|
|
1550
|
+
};
|
|
1551
|
+
return camera;
|
|
1552
|
+
}
|
|
1553
|
+
const VISIBLE = "visible";
|
|
1554
|
+
function newBoardTrackId(tracks, target, property) {
|
|
1555
|
+
const id = `${target}-${property.replaceAll(".", "-")}`;
|
|
1556
|
+
return id.length <= 160 && !Object.hasOwn(tracks, id) ? id : createBoardEntityId();
|
|
1557
|
+
}
|
|
1558
|
+
function findBoardKeyTrack(tracks, target, property) {
|
|
1559
|
+
return Object.entries(tracks).find(([, track]) => track.target === target && track.property === property && track.composite === "replace");
|
|
1560
|
+
}
|
|
1561
|
+
function targetType(document, target) {
|
|
1562
|
+
if (target === "camera") return BOARD_CAMERA_TARGET;
|
|
1563
|
+
if (document.animations[target]) return "animation";
|
|
1564
|
+
if (document.board.scripts?.[target]) return "script";
|
|
1565
|
+
return document.items[target]?.type ?? null;
|
|
1566
|
+
}
|
|
1567
|
+
function boardPlayProperty(document, target) {
|
|
1568
|
+
const type = targetType(document, target);
|
|
1569
|
+
return type === "video" || type === "audio" ? "props.time" : type === "animation" ? "time" : null;
|
|
1570
|
+
}
|
|
1571
|
+
function boardPlayLength(document, target) {
|
|
1572
|
+
const item = document.items[target];
|
|
1573
|
+
if (item?.type === "video" || item?.type === "audio") return item.props.snapshot?.durationMs || null;
|
|
1574
|
+
return document.animations[target]?.duration ?? null;
|
|
1575
|
+
}
|
|
1576
|
+
function visibleSpan(track, duration) {
|
|
1577
|
+
let start = null;
|
|
1578
|
+
let lastShown = -1;
|
|
1579
|
+
let end = null;
|
|
1580
|
+
for (const keyframe of track.keyframes) if (keyframe.value !== false) {
|
|
1581
|
+
start ??= keyframe.at;
|
|
1582
|
+
lastShown = keyframe.at;
|
|
1583
|
+
end = null;
|
|
1584
|
+
} else if (start !== null && end === null) end = keyframe.at;
|
|
1585
|
+
return start === null ? null : {
|
|
1586
|
+
start,
|
|
1587
|
+
end: end ?? Math.max(duration, lastShown)
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
function boardClipSpan(tracks, duration) {
|
|
1591
|
+
if (tracks.visible) return visibleSpan(tracks.visible, duration);
|
|
1592
|
+
const first = tracks.play?.keyframes[0];
|
|
1593
|
+
const last = tracks.play?.keyframes.at(-1);
|
|
1594
|
+
return first && last && last.at > first.at ? {
|
|
1595
|
+
start: first.at,
|
|
1596
|
+
end: last.at
|
|
1597
|
+
} : null;
|
|
1598
|
+
}
|
|
1599
|
+
function boardTargetSpan(document, animation, target) {
|
|
1600
|
+
const property = boardPlayProperty(document, target);
|
|
1601
|
+
return boardClipSpan({
|
|
1602
|
+
visible: findBoardKeyTrack(animation.tracks, target, VISIBLE)?.[1],
|
|
1603
|
+
play: property ? findBoardKeyTrack(animation.tracks, target, property)?.[1] : void 0
|
|
1604
|
+
}, animation.duration);
|
|
1605
|
+
}
|
|
1606
|
+
function visibleKeyframes(start, end) {
|
|
1607
|
+
if (end <= start) return [{
|
|
1608
|
+
at: 0,
|
|
1609
|
+
value: false
|
|
1610
|
+
}];
|
|
1611
|
+
return [
|
|
1612
|
+
...start > 0 ? [{
|
|
1613
|
+
at: 0,
|
|
1614
|
+
value: false
|
|
1615
|
+
}] : [],
|
|
1616
|
+
{
|
|
1617
|
+
at: start,
|
|
1618
|
+
value: true
|
|
1619
|
+
},
|
|
1620
|
+
{
|
|
1621
|
+
at: end,
|
|
1622
|
+
value: false
|
|
1623
|
+
}
|
|
1624
|
+
];
|
|
1625
|
+
}
|
|
1626
|
+
function normalizeVisible(keyframes) {
|
|
1627
|
+
const sorted = keyframes.map((keyframe, index) => ({
|
|
1628
|
+
keyframe,
|
|
1629
|
+
index
|
|
1630
|
+
})).sort((a, b) => a.keyframe.at - b.keyframe.at || a.index - b.index);
|
|
1631
|
+
const result = [];
|
|
1632
|
+
for (const { keyframe } of sorted) {
|
|
1633
|
+
if (result.at(-1)?.at === keyframe.at) result.pop();
|
|
1634
|
+
if (result.at(-1)?.value === keyframe.value) continue;
|
|
1635
|
+
result.push(keyframe);
|
|
1636
|
+
}
|
|
1637
|
+
if (result[0]?.value !== false && (result[0]?.at ?? 0) > 0) result.unshift({
|
|
1638
|
+
at: 0,
|
|
1639
|
+
value: false
|
|
1640
|
+
});
|
|
1641
|
+
return result;
|
|
1642
|
+
}
|
|
1643
|
+
function withDuration(animation, end) {
|
|
1644
|
+
return end > animation.duration ? {
|
|
1645
|
+
...animation,
|
|
1646
|
+
duration: Math.ceil(end)
|
|
1647
|
+
} : animation;
|
|
1648
|
+
}
|
|
1649
|
+
function setTrack(tracks, target, property, keyframes, interpolation = "auto") {
|
|
1650
|
+
const existing = findBoardKeyTrack(tracks, target, property);
|
|
1651
|
+
const id = existing?.[0] ?? newBoardTrackId(tracks, target, property);
|
|
1652
|
+
tracks[id] = existing ? {
|
|
1653
|
+
...existing[1],
|
|
1654
|
+
keyframes
|
|
1655
|
+
} : {
|
|
1656
|
+
target,
|
|
1657
|
+
property,
|
|
1658
|
+
keyframes,
|
|
1659
|
+
composite: "replace",
|
|
1660
|
+
interpolation
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
function sampleTrack(document, track, time) {
|
|
1664
|
+
const type = targetType(document, track.target);
|
|
1665
|
+
const compiled = type ? compileBoardTrack("", "", track, type) : null;
|
|
1666
|
+
if (compiled) return sampleBoardTrack(compiled, time);
|
|
1667
|
+
return [...track.keyframes].reverse().find((keyframe) => keyframe.at <= time)?.value ?? track.keyframes[0]?.value;
|
|
1668
|
+
}
|
|
1669
|
+
function slope(a, b) {
|
|
1670
|
+
if (!a || !b || b.at <= a.at || typeof a.value !== "number" || typeof b.value !== "number") return 0;
|
|
1671
|
+
return (b.value - a.value) / (b.at - a.at);
|
|
1672
|
+
}
|
|
1673
|
+
function playValue(document, track, time) {
|
|
1674
|
+
const { keyframes } = track;
|
|
1675
|
+
const first = keyframes[0];
|
|
1676
|
+
const last = keyframes.at(-1);
|
|
1677
|
+
if (time < first.at) return Math.max(0, first.value - slope(first, keyframes[1]) * (first.at - time));
|
|
1678
|
+
if (time > last.at) return Math.max(0, last.value + slope(keyframes.at(-2), last) * (time - last.at));
|
|
1679
|
+
const value = sampleTrack(document, track, time);
|
|
1680
|
+
return typeof value === "number" ? value : 0;
|
|
1681
|
+
}
|
|
1682
|
+
function shiftKeyframes(keyframes, shift) {
|
|
1683
|
+
return keyframes.map((keyframe) => ({
|
|
1684
|
+
...keyframe,
|
|
1685
|
+
at: keyframe.at + shift
|
|
1686
|
+
}));
|
|
1687
|
+
}
|
|
1688
|
+
function withoutAnchor(track) {
|
|
1689
|
+
const [first, second] = track.keyframes;
|
|
1690
|
+
return track.property === VISIBLE && first?.at === 0 && first.value === false && second ? track.keyframes.slice(1) : track.keyframes;
|
|
1691
|
+
}
|
|
1692
|
+
function boardPlaceTarget(document, animation, target, placement) {
|
|
1693
|
+
const at = Math.max(0, Math.round(placement.at));
|
|
1694
|
+
const existing = boardTargetSpan(document, animation, target);
|
|
1695
|
+
if (existing) return boardShiftTargets(document, animation, [target], at - existing.start);
|
|
1696
|
+
const rate = placement.rate && placement.rate > 0 ? placement.rate : 1;
|
|
1697
|
+
const from = Math.max(0, placement.from ?? 0);
|
|
1698
|
+
const length = boardPlayLength(document, target);
|
|
1699
|
+
const remaining = length !== null && length > from ? (length - from) / rate : null;
|
|
1700
|
+
const duration = Math.max(40, Math.round(placement.duration ?? remaining ?? 3e3));
|
|
1701
|
+
const tracks = { ...animation.tracks };
|
|
1702
|
+
if (document.items[target]) setTrack(tracks, target, VISIBLE, visibleKeyframes(at, at + duration), "step");
|
|
1703
|
+
const property = boardPlayProperty(document, target);
|
|
1704
|
+
if (property) setTrack(tracks, target, property, [{
|
|
1705
|
+
at,
|
|
1706
|
+
value: from
|
|
1707
|
+
}, {
|
|
1708
|
+
at: at + duration,
|
|
1709
|
+
value: from + duration * rate
|
|
1710
|
+
}]);
|
|
1711
|
+
return withDuration({
|
|
1712
|
+
...animation,
|
|
1713
|
+
tracks
|
|
1714
|
+
}, at + duration);
|
|
1715
|
+
}
|
|
1716
|
+
function boardShiftTargets(document, animation, targets, delta) {
|
|
1717
|
+
const owned = Object.entries(animation.tracks).filter(([, track]) => targets.includes(track.target));
|
|
1718
|
+
const spans = targets.map((target) => boardTargetSpan(document, animation, target));
|
|
1719
|
+
const keyed = Math.min(...owned.map(([, track]) => withoutAnchor(track)[0]?.at ?? Number.POSITIVE_INFINITY));
|
|
1720
|
+
const earliest = Math.min(...spans.map((span) => span?.start ?? keyed));
|
|
1721
|
+
if (!Number.isFinite(earliest)) return animation;
|
|
1722
|
+
const shift = Math.round(Math.max(delta, -earliest));
|
|
1723
|
+
if (shift === 0) return animation;
|
|
1724
|
+
const tracks = { ...animation.tracks };
|
|
1725
|
+
let end = Math.max(0, ...spans.map((span) => span ? span.end + shift : 0));
|
|
1726
|
+
for (const [id, track] of owned) {
|
|
1727
|
+
let body = withoutAnchor(track);
|
|
1728
|
+
if ((body[0]?.at ?? 0) < -shift) {
|
|
1729
|
+
const after = cutTrack(document, {
|
|
1730
|
+
...track,
|
|
1731
|
+
keyframes: [...body]
|
|
1732
|
+
}, -shift).after;
|
|
1733
|
+
body = after.length ? after : [{
|
|
1734
|
+
...body.at(-1),
|
|
1735
|
+
at: -shift
|
|
1736
|
+
}];
|
|
1737
|
+
}
|
|
1738
|
+
const moved = shiftKeyframes(body, shift);
|
|
1739
|
+
const keyframes = track.property === VISIBLE ? normalizeVisible(moved) : moved;
|
|
1740
|
+
tracks[id] = {
|
|
1741
|
+
...track,
|
|
1742
|
+
keyframes
|
|
1743
|
+
};
|
|
1744
|
+
if (!spans.some(Boolean)) end = Math.max(end, keyframes.at(-1)?.at ?? 0);
|
|
1745
|
+
}
|
|
1746
|
+
return withDuration({
|
|
1747
|
+
...animation,
|
|
1748
|
+
tracks
|
|
1749
|
+
}, end);
|
|
1750
|
+
}
|
|
1751
|
+
function boardTrimLimits(document, animation, target) {
|
|
1752
|
+
const property = boardPlayProperty(document, target);
|
|
1753
|
+
const play = property ? findBoardKeyTrack(animation.tracks, target, property)?.[1] : void 0;
|
|
1754
|
+
const first = play?.keyframes[0];
|
|
1755
|
+
const last = play?.keyframes.at(-1);
|
|
1756
|
+
if (!play || !first || !last) return {
|
|
1757
|
+
start: 0,
|
|
1758
|
+
end: Number.POSITIVE_INFINITY
|
|
1759
|
+
};
|
|
1760
|
+
const head = slope(first, play.keyframes[1]);
|
|
1761
|
+
const tail = slope(play.keyframes.at(-2), last);
|
|
1762
|
+
const length = boardPlayLength(document, target);
|
|
1763
|
+
const start = head > 0 && typeof first.value === "number" ? first.at - first.value / head : 0;
|
|
1764
|
+
const end = tail > 0 && length !== null && typeof last.value === "number" ? last.at + (length - last.value) / tail : Number.POSITIVE_INFINITY;
|
|
1765
|
+
return {
|
|
1766
|
+
start: Math.max(0, Math.ceil(start)),
|
|
1767
|
+
end: Math.max(last.at, Math.floor(end))
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
function boardTrimTarget(document, animation, target, edge, at) {
|
|
1771
|
+
const span = boardTargetSpan(document, animation, target);
|
|
1772
|
+
if (!span) return animation;
|
|
1773
|
+
const limits = boardTrimLimits(document, animation, target);
|
|
1774
|
+
const time = edge === "start" ? Math.round(Math.min(Math.max(at, limits.start), span.end - 40)) : Math.round(Math.max(Math.min(at, limits.end), span.start + 40));
|
|
1775
|
+
if (time === span[edge]) return animation;
|
|
1776
|
+
const next = edge === "start" ? {
|
|
1777
|
+
start: time,
|
|
1778
|
+
end: span.end
|
|
1779
|
+
} : {
|
|
1780
|
+
start: span.start,
|
|
1781
|
+
end: time
|
|
1782
|
+
};
|
|
1783
|
+
const tracks = { ...animation.tracks };
|
|
1784
|
+
if (findBoardKeyTrack(tracks, target, VISIBLE)) setTrack(tracks, target, VISIBLE, visibleKeyframes(next.start, next.end), "step");
|
|
1785
|
+
const property = boardPlayProperty(document, target);
|
|
1786
|
+
const play = property ? findBoardKeyTrack(tracks, target, property) : void 0;
|
|
1787
|
+
if (play) {
|
|
1788
|
+
const [id, track] = play;
|
|
1789
|
+
const first = track.keyframes[0];
|
|
1790
|
+
const last = track.keyframes.at(-1);
|
|
1791
|
+
let keyframes;
|
|
1792
|
+
if (time > first.at && time < last.at) keyframes = cutTrack(document, track, time)[edge === "start" ? "after" : "before"];
|
|
1793
|
+
else {
|
|
1794
|
+
const cut = {
|
|
1795
|
+
at: time,
|
|
1796
|
+
value: playValue(document, track, time)
|
|
1797
|
+
};
|
|
1798
|
+
keyframes = edge === "start" ? [cut, ...track.keyframes.filter((keyframe) => keyframe.at > time)] : [...track.keyframes.filter((keyframe) => keyframe.at < time), cut];
|
|
1799
|
+
}
|
|
1800
|
+
tracks[id] = {
|
|
1801
|
+
...track,
|
|
1802
|
+
keyframes
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
return withDuration({
|
|
1806
|
+
...animation,
|
|
1807
|
+
tracks
|
|
1808
|
+
}, next.end);
|
|
1809
|
+
}
|
|
1810
|
+
function cutValue(document, track, at) {
|
|
1811
|
+
return {
|
|
1812
|
+
at,
|
|
1813
|
+
value: sampleTrack(document, track, at)
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
const CURVES = {
|
|
1817
|
+
ease: [
|
|
1818
|
+
.25,
|
|
1819
|
+
.1,
|
|
1820
|
+
.25,
|
|
1821
|
+
1
|
|
1822
|
+
],
|
|
1823
|
+
"ease-in": [
|
|
1824
|
+
.42,
|
|
1825
|
+
0,
|
|
1826
|
+
1,
|
|
1827
|
+
1
|
|
1828
|
+
],
|
|
1829
|
+
"ease-out": [
|
|
1830
|
+
0,
|
|
1831
|
+
0,
|
|
1832
|
+
.58,
|
|
1833
|
+
1
|
|
1834
|
+
],
|
|
1835
|
+
"ease-in-out": [
|
|
1836
|
+
.42,
|
|
1837
|
+
0,
|
|
1838
|
+
.58,
|
|
1839
|
+
1
|
|
1840
|
+
]
|
|
1841
|
+
};
|
|
1842
|
+
function curveOf(ease) {
|
|
1843
|
+
const key = ease.trim();
|
|
1844
|
+
const known = CURVES[key];
|
|
1845
|
+
if (known) return known;
|
|
1846
|
+
const numbers = /^cubic-bezier\(([^)]+)\)$/.exec(key)?.[1]?.split(",").map(Number);
|
|
1847
|
+
return numbers?.length === 4 && numbers.every(Number.isFinite) ? numbers : null;
|
|
1848
|
+
}
|
|
1849
|
+
const format = (curve) => `cubic-bezier(${curve.map((value) => Number(value.toFixed(4))).join(", ")})`;
|
|
1850
|
+
function splitEase(ease, progress) {
|
|
1851
|
+
const curve = ease && ease.trim() !== "linear" ? curveOf(ease) : null;
|
|
1852
|
+
if (!ease || !curve) return [ease, ease];
|
|
1853
|
+
const [x1, y1, x2, y2] = curve;
|
|
1854
|
+
const bezier = (a, b, t) => 3 * a * t * (1 - t) ** 2 + 3 * b * t ** 2 * (1 - t) + t ** 3;
|
|
1855
|
+
let low = 0;
|
|
1856
|
+
let high = 1;
|
|
1857
|
+
for (let index = 0; index < 40; index += 1) {
|
|
1858
|
+
const mid = (low + high) / 2;
|
|
1859
|
+
if (bezier(x1, x2, mid) < progress) low = mid;
|
|
1860
|
+
else high = mid;
|
|
1861
|
+
}
|
|
1862
|
+
const t = (low + high) / 2;
|
|
1863
|
+
const lerp = (a, b) => a + (b - a) * t;
|
|
1864
|
+
const p01 = [lerp(0, x1), lerp(0, y1)];
|
|
1865
|
+
const p12 = [lerp(x1, x2), lerp(y1, y2)];
|
|
1866
|
+
const p23 = [lerp(x2, 1), lerp(y2, 1)];
|
|
1867
|
+
const p012 = [lerp(p01[0], p12[0]), lerp(p01[1], p12[1])];
|
|
1868
|
+
const p123 = [lerp(p12[0], p23[0]), lerp(p12[1], p23[1])];
|
|
1869
|
+
const [x, y] = [lerp(p012[0], p123[0]), lerp(p012[1], p123[1])];
|
|
1870
|
+
if (x <= 0 || x >= 1 || Math.abs(y) < 1e-9 || Math.abs(1 - y) < 1e-9) return [ease, ease];
|
|
1871
|
+
return [format([
|
|
1872
|
+
p01[0] / x,
|
|
1873
|
+
p01[1] / y,
|
|
1874
|
+
p012[0] / x,
|
|
1875
|
+
p012[1] / y
|
|
1876
|
+
]), format([
|
|
1877
|
+
(p123[0] - x) / (1 - x),
|
|
1878
|
+
(p123[1] - y) / (1 - y),
|
|
1879
|
+
(p23[0] - x) / (1 - x),
|
|
1880
|
+
(p23[1] - y) / (1 - y)
|
|
1881
|
+
])];
|
|
1882
|
+
}
|
|
1883
|
+
function withEase(keyframe, ease) {
|
|
1884
|
+
const { ease: _ease, ...rest } = keyframe;
|
|
1885
|
+
return ease && ease !== "linear" ? {
|
|
1886
|
+
...rest,
|
|
1887
|
+
ease
|
|
1888
|
+
} : rest;
|
|
1889
|
+
}
|
|
1890
|
+
function cutTrack(document, track, time) {
|
|
1891
|
+
const { keyframes } = track;
|
|
1892
|
+
const index = keyframes.findIndex((keyframe) => keyframe.at >= time);
|
|
1893
|
+
const before = keyframes.filter((keyframe) => keyframe.at <= time);
|
|
1894
|
+
const after = keyframes.filter((keyframe) => keyframe.at >= time);
|
|
1895
|
+
const a = keyframes[index - 1];
|
|
1896
|
+
const b = keyframes[index];
|
|
1897
|
+
if (!a || !b || b.at === time) return {
|
|
1898
|
+
before,
|
|
1899
|
+
after
|
|
1900
|
+
};
|
|
1901
|
+
const value = cutValue(document, track, time).value;
|
|
1902
|
+
const [left, right] = track.interpolation === "step" ? [b.ease, b.ease] : splitEase(b.ease, (time - a.at) / (b.at - a.at));
|
|
1903
|
+
return {
|
|
1904
|
+
before: [...before, withEase({
|
|
1905
|
+
at: time,
|
|
1906
|
+
value
|
|
1907
|
+
}, left)],
|
|
1908
|
+
after: [
|
|
1909
|
+
{
|
|
1910
|
+
at: time,
|
|
1911
|
+
value
|
|
1912
|
+
},
|
|
1913
|
+
withEase(b, right),
|
|
1914
|
+
...after.slice(1)
|
|
1915
|
+
]
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
function boardSplitTarget(document, animation, target, copies, at) {
|
|
1919
|
+
const span = boardTargetSpan(document, animation, target);
|
|
1920
|
+
const time = Math.round(at);
|
|
1921
|
+
if (!span || time < span.start + 40 || time > span.end - 40) return null;
|
|
1922
|
+
const tracks = { ...animation.tracks };
|
|
1923
|
+
for (const [id, track] of Object.entries(animation.tracks)) {
|
|
1924
|
+
const copy = copies.get(track.target);
|
|
1925
|
+
if (!copy) continue;
|
|
1926
|
+
const own = track.property === VISIBLE ? boardTargetSpan(document, animation, track.target) : null;
|
|
1927
|
+
let before;
|
|
1928
|
+
let after;
|
|
1929
|
+
if (own) {
|
|
1930
|
+
before = visibleKeyframes(own.start, Math.min(own.end, time));
|
|
1931
|
+
after = visibleKeyframes(Math.max(own.start, time), own.end);
|
|
1932
|
+
} else {
|
|
1933
|
+
const index = track.keyframes.findIndex((keyframe) => keyframe.at >= time);
|
|
1934
|
+
const next = index < 0 ? track.keyframes.length : index;
|
|
1935
|
+
before = track.keyframes.slice(0, next + 2);
|
|
1936
|
+
after = track.keyframes.slice(Math.max(0, next - 2));
|
|
1937
|
+
}
|
|
1938
|
+
tracks[id] = {
|
|
1939
|
+
...track,
|
|
1940
|
+
keyframes: before
|
|
1941
|
+
};
|
|
1942
|
+
tracks[newBoardTrackId(tracks, copy, track.property)] = {
|
|
1943
|
+
...structuredClone(track),
|
|
1944
|
+
target: copy,
|
|
1945
|
+
keyframes: after
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
const copy = copies.get(target);
|
|
1949
|
+
if (document.items[target] && !findBoardKeyTrack(animation.tracks, target, VISIBLE)) {
|
|
1950
|
+
setTrack(tracks, target, VISIBLE, visibleKeyframes(span.start, time), "step");
|
|
1951
|
+
setTrack(tracks, copy, VISIBLE, visibleKeyframes(time, span.end), "step");
|
|
1952
|
+
}
|
|
1953
|
+
return {
|
|
1954
|
+
...animation,
|
|
1955
|
+
tracks
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
function boardRemoveTarget(animation, target) {
|
|
1959
|
+
const tracks = Object.fromEntries(Object.entries(animation.tracks).filter(([, track]) => track.target !== target));
|
|
1960
|
+
return Object.keys(tracks).length === Object.keys(animation.tracks).length ? animation : {
|
|
1961
|
+
...animation,
|
|
1962
|
+
tracks
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1965
|
+
function retime(animation, keyframes, markers, duration) {
|
|
1966
|
+
const tracks = {};
|
|
1967
|
+
for (const [id, track] of Object.entries(animation.tracks)) {
|
|
1968
|
+
const next = track.property === VISIBLE ? normalizeVisible(keyframes(track)) : keyframes(track);
|
|
1969
|
+
if (track.property === VISIBLE) tracks[id] = {
|
|
1970
|
+
...track,
|
|
1971
|
+
keyframes: next.length ? next : [{
|
|
1972
|
+
at: 0,
|
|
1973
|
+
value: false
|
|
1974
|
+
}]
|
|
1975
|
+
};
|
|
1976
|
+
else if (next.length) tracks[id] = {
|
|
1977
|
+
...track,
|
|
1978
|
+
keyframes: next
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
return {
|
|
1982
|
+
...animation,
|
|
1983
|
+
tracks,
|
|
1984
|
+
markers,
|
|
1985
|
+
duration: Math.max(1, Math.round(duration))
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
function join(before, after) {
|
|
1989
|
+
const last = before.at(-1);
|
|
1990
|
+
const [first, second] = after;
|
|
1991
|
+
if (!last || !first || first.at !== last.at) return [...before, ...after];
|
|
1992
|
+
if (sameJson(first.value, last.value) || second && second.at <= first.at + 1) return [...before, ...after.slice(1)];
|
|
1993
|
+
return [
|
|
1994
|
+
...before,
|
|
1995
|
+
{
|
|
1996
|
+
...first,
|
|
1997
|
+
at: first.at + 1
|
|
1998
|
+
},
|
|
1999
|
+
...after.slice(1)
|
|
2000
|
+
];
|
|
2001
|
+
}
|
|
2002
|
+
function boardRemoveTime(document, animation, from, to) {
|
|
2003
|
+
const start = Math.max(0, Math.round(Math.min(from, to)));
|
|
2004
|
+
const end = Math.round(Math.max(from, to));
|
|
2005
|
+
const length = end - start;
|
|
2006
|
+
if (length <= 0) return animation;
|
|
2007
|
+
return retime(animation, (track) => {
|
|
2008
|
+
const { before } = cutTrack(document, track, start);
|
|
2009
|
+
const after = shiftKeyframes(cutTrack(document, track, end).after, -length);
|
|
2010
|
+
return track.property === VISIBLE ? [...before, ...after] : join(before, after);
|
|
2011
|
+
}, animation.markers.filter((marker) => marker.at <= start || marker.at >= end).map((marker) => marker.at >= end ? {
|
|
2012
|
+
...marker,
|
|
2013
|
+
at: marker.at - length
|
|
2014
|
+
} : marker), animation.duration - (Math.min(end, animation.duration) - Math.min(start, animation.duration)));
|
|
2015
|
+
}
|
|
2016
|
+
function boardInsertTime(document, animation, at, length) {
|
|
2017
|
+
const time = Math.max(0, Math.round(at));
|
|
2018
|
+
const gap = Math.round(length);
|
|
2019
|
+
if (gap <= 0) return animation;
|
|
2020
|
+
return retime(animation, (track) => {
|
|
2021
|
+
const body = withoutAnchor(track);
|
|
2022
|
+
const anchor = track.keyframes.slice(0, track.keyframes.length - body.length);
|
|
2023
|
+
if ((body[0]?.at ?? 0) >= time) return [...anchor, ...shiftKeyframes(body, gap)];
|
|
2024
|
+
const { before, after } = cutTrack(document, track, time);
|
|
2025
|
+
return after.some((keyframe) => keyframe.at > time) ? [...before, ...shiftKeyframes(after, gap)] : before;
|
|
2026
|
+
}, animation.markers.map((marker) => marker.at > time ? {
|
|
2027
|
+
...marker,
|
|
2028
|
+
at: marker.at + gap
|
|
2029
|
+
} : marker), time < animation.duration ? animation.duration + gap : animation.duration);
|
|
2030
|
+
}
|
|
2031
|
+
//#endregion
|
|
2032
|
+
//#region ../sdk/src/board/model/authoring.ts
|
|
2033
|
+
function validateChapterComposition(document, chapters) {
|
|
2034
|
+
const uses = /* @__PURE__ */ new Map();
|
|
2035
|
+
for (const [index, chapter] of chapters.entries()) for (const track of Object.values(document.animations[chapter.animation]?.tracks ?? {})) {
|
|
2036
|
+
let properties = uses.get(track.target);
|
|
2037
|
+
if (!properties) {
|
|
2038
|
+
properties = /* @__PURE__ */ new Map();
|
|
2039
|
+
uses.set(track.target, properties);
|
|
2040
|
+
}
|
|
2041
|
+
for (const [property, usage] of properties) if ((property === track.property || property.startsWith(`${track.property}.`) || track.property.startsWith(`${property}.`)) && (usage.additive || track.composite === "add") && [...usage.chapters].some((other) => other !== index)) throw new Error(`Chapters share additive tracks on ${track.target}.${track.property}; use distinct items or combine the tracks before sequencing.`);
|
|
2042
|
+
const usage = properties.get(track.property) ?? {
|
|
2043
|
+
chapters: /* @__PURE__ */ new Set(),
|
|
2044
|
+
additive: false
|
|
2045
|
+
};
|
|
2046
|
+
usage.chapters.add(index);
|
|
2047
|
+
usage.additive ||= track.composite === "add";
|
|
2048
|
+
properties.set(track.property, usage);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
function boardSequence(document, chapters) {
|
|
2052
|
+
if (!chapters.length) throw new Error("A sequence needs at least one chapter.");
|
|
2053
|
+
validateChapterComposition(document, chapters);
|
|
2054
|
+
const tracks = {};
|
|
2055
|
+
const markers = [];
|
|
2056
|
+
let cursor = 0;
|
|
2057
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2058
|
+
const seenFrames = /* @__PURE__ */ new Set();
|
|
2059
|
+
for (const [index, chapter] of chapters.entries()) {
|
|
2060
|
+
const animation = document.animations[chapter.animation];
|
|
2061
|
+
if (!animation) throw new Error(`Animation ${chapter.animation} does not exist.`);
|
|
2062
|
+
if (animation.play !== "manual") throw new Error(`Chapter ${chapter.animation} must use manual playback.`);
|
|
2063
|
+
if (!Number.isFinite(animation.duration) || animation.duration <= 0) throw new Error("Chapter duration must be positive and finite.");
|
|
2064
|
+
if (seen.has(chapter.animation)) throw new Error(`Animation ${chapter.animation} appears more than once; use separate animation IDs.`);
|
|
2065
|
+
seen.add(chapter.animation);
|
|
2066
|
+
if (chapter.frame && document.items[chapter.frame]?.type !== "frame") throw new Error(`Chapter ${chapter.animation} needs a valid frame.`);
|
|
2067
|
+
if (chapter.frame && seenFrames.has(chapter.frame)) throw new Error("Each chapter needs a separate frame, or omit frame visibility control.");
|
|
2068
|
+
if (chapter.frame) seenFrames.add(chapter.frame);
|
|
2069
|
+
const gap = chapter.gap ?? 0;
|
|
2070
|
+
if (!Number.isFinite(gap) || gap < 0) throw new Error("Chapter gap must be finite and non-negative.");
|
|
2071
|
+
cursor += gap;
|
|
2072
|
+
const start = cursor;
|
|
2073
|
+
const end = start + animation.duration;
|
|
2074
|
+
const rankWidth = String(Object.keys(animation.tracks).length).length;
|
|
2075
|
+
const ranks = new Map(Object.keys(animation.tracks).sort().map((id, rank) => [id, String(rank).padStart(rankWidth, "0")]));
|
|
2076
|
+
const chapterIndex = String(index).padStart(String(chapters.length).length, "0");
|
|
2077
|
+
for (const [id, track] of Object.entries(animation.tracks)) {
|
|
2078
|
+
if (document.animations[track.target]) throw new Error(`Chapter ${chapter.animation} contains nested clocks; compose its leaf animations instead.`);
|
|
2079
|
+
tracks[`chapter-${chapterIndex}-${ranks.get(id)}`] = {
|
|
2080
|
+
...track,
|
|
2081
|
+
keyframes: track.keyframes.map((keyframe) => ({
|
|
2082
|
+
...keyframe,
|
|
2083
|
+
at: start + keyframe.at
|
|
2084
|
+
}))
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
const boundary = end + (chapter.pause && index < chapters.length - 1 ? 1 : 0);
|
|
2088
|
+
if (chapter.frame) {
|
|
2089
|
+
tracks[`visibility-${index}`] = {
|
|
2090
|
+
target: chapter.frame,
|
|
2091
|
+
property: "opacity",
|
|
2092
|
+
composite: "add",
|
|
2093
|
+
interpolation: "step",
|
|
2094
|
+
keyframes: [
|
|
2095
|
+
...start > 0 ? [{
|
|
2096
|
+
at: 0,
|
|
2097
|
+
value: 0
|
|
2098
|
+
}] : [],
|
|
2099
|
+
{
|
|
2100
|
+
at: start,
|
|
2101
|
+
value: 1
|
|
2102
|
+
},
|
|
2103
|
+
...index < chapters.length - 1 ? [{
|
|
2104
|
+
at: boundary + (chapters[index + 1]?.gap ?? 0),
|
|
2105
|
+
value: 0
|
|
2106
|
+
}] : []
|
|
2107
|
+
]
|
|
2108
|
+
};
|
|
2109
|
+
tracks[`chapter-${chapterIndex}--camera`] = {
|
|
2110
|
+
target: "camera",
|
|
2111
|
+
property: "focus",
|
|
2112
|
+
composite: "replace",
|
|
2113
|
+
interpolation: "step",
|
|
2114
|
+
keyframes: [{
|
|
2115
|
+
at: start,
|
|
2116
|
+
value: chapter.frame
|
|
2117
|
+
}]
|
|
2118
|
+
};
|
|
2119
|
+
}
|
|
2120
|
+
markers.push({
|
|
2121
|
+
at: start,
|
|
2122
|
+
label: chapter.label ?? animation.name ?? chapter.animation
|
|
2123
|
+
});
|
|
2124
|
+
for (const marker of animation.markers) markers.push({
|
|
2125
|
+
...marker,
|
|
2126
|
+
at: start + marker.at
|
|
2127
|
+
});
|
|
2128
|
+
if (chapter.pause) markers.push({
|
|
2129
|
+
at: end,
|
|
2130
|
+
pause: true
|
|
2131
|
+
});
|
|
2132
|
+
cursor = boundary;
|
|
2133
|
+
}
|
|
2134
|
+
const byTime = /* @__PURE__ */ new Map();
|
|
2135
|
+
for (const marker of markers) {
|
|
2136
|
+
const previous = byTime.get(marker.at);
|
|
2137
|
+
byTime.set(marker.at, {
|
|
2138
|
+
...previous,
|
|
2139
|
+
...marker,
|
|
2140
|
+
pause: Boolean(previous?.pause || marker.pause)
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
return {
|
|
2144
|
+
duration: cursor,
|
|
2145
|
+
play: "manual",
|
|
2146
|
+
end: "hold",
|
|
2147
|
+
delay: 0,
|
|
2148
|
+
loop: false,
|
|
2149
|
+
tracks,
|
|
2150
|
+
markers: [...byTime.values()].sort((a, b) => a.at - b.at)
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
2153
|
+
function boardSequencePatch(document, id, chapters) {
|
|
2154
|
+
BoardIdSchema.parse(id);
|
|
2155
|
+
if (chapters.some((chapter) => chapter.animation === id)) throw new Error("A sequence cannot overwrite one of its source chapters.");
|
|
2156
|
+
const animation = boardSequence(document, chapters);
|
|
2157
|
+
const tracks = { ...animation.tracks };
|
|
2158
|
+
for (const key of Object.keys(document.animations[id]?.tracks ?? {})) if (!(key in tracks)) tracks[key] = null;
|
|
2159
|
+
const patch = { animations: { [id]: {
|
|
2160
|
+
...animation,
|
|
2161
|
+
tracks
|
|
2162
|
+
} } };
|
|
2163
|
+
const result = applyBoardPatchToDocument(document, patch);
|
|
2164
|
+
if (!result.ok) throw new Error(result.diagnostics.map((entry) => `${entry.path}: ${entry.message}`).join("; "));
|
|
2165
|
+
return patch;
|
|
2166
|
+
}
|
|
2167
|
+
function boardPlacePatch(document, id, targets, placement) {
|
|
2168
|
+
BoardIdSchema.parse(id);
|
|
2169
|
+
const existing = document.animations[id];
|
|
2170
|
+
let animation = existing ?? {
|
|
2171
|
+
duration: 1,
|
|
2172
|
+
play: "manual",
|
|
2173
|
+
delay: 0,
|
|
2174
|
+
loop: false,
|
|
2175
|
+
end: "hold",
|
|
2176
|
+
markers: [],
|
|
2177
|
+
tracks: {}
|
|
2178
|
+
};
|
|
2179
|
+
let at = placement.at;
|
|
2180
|
+
for (const target of targets) {
|
|
2181
|
+
if (target === id || !document.items[target] && !document.animations[target]) throw new Error(`${target} is not an item or animation on this Board.`);
|
|
2182
|
+
animation = boardPlaceTarget(document, animation, target, {
|
|
2183
|
+
...placement,
|
|
2184
|
+
at
|
|
2185
|
+
});
|
|
2186
|
+
if (!placement.together) at = boardTargetSpan(document, animation, target)?.end ?? at;
|
|
2187
|
+
}
|
|
2188
|
+
const tracks = Object.fromEntries(Object.entries(animation.tracks).filter(([key, track]) => existing?.tracks[key] !== track));
|
|
2189
|
+
const patch = { animations: { [id]: existing ? {
|
|
2190
|
+
duration: animation.duration,
|
|
2191
|
+
tracks
|
|
2192
|
+
} : {
|
|
2193
|
+
...animation,
|
|
2194
|
+
tracks
|
|
2195
|
+
} } };
|
|
2196
|
+
const result = applyBoardPatchToDocument(document, patch);
|
|
2197
|
+
if (!result.ok) throw new Error(result.diagnostics.map((entry) => `${entry.path}: ${entry.message}`).join("; "));
|
|
2198
|
+
return patch;
|
|
2199
|
+
}
|
|
2200
|
+
function boardPathTrack(target, points, options) {
|
|
2201
|
+
const { duration, at = 0, samples = 64, orient = false } = options;
|
|
2202
|
+
if (points.length < 2 || points.length > 1e4 || points.some((p) => !Number.isFinite(p.x) || !Number.isFinite(p.y))) throw new Error("A path needs 2 to 10000 finite points.");
|
|
2203
|
+
if (!Number.isFinite(duration) || duration <= 0 || !Number.isFinite(at) || at < 0) throw new Error("Path duration must be positive and start time non-negative.");
|
|
2204
|
+
if (!Number.isInteger(samples) || samples < 2 || samples > 1e4) throw new Error("Path samples must be an integer from 2 to 10000.");
|
|
2205
|
+
const segments = [];
|
|
2206
|
+
let total = 0;
|
|
2207
|
+
let previous = points[0];
|
|
2208
|
+
for (const point of points.slice(1)) {
|
|
2209
|
+
if (!previous) break;
|
|
2210
|
+
const start = total;
|
|
2211
|
+
total += Math.hypot(point.x - previous.x, point.y - previous.y);
|
|
2212
|
+
segments.push({
|
|
2213
|
+
a: previous,
|
|
2214
|
+
b: point,
|
|
2215
|
+
start,
|
|
2216
|
+
end: total
|
|
2217
|
+
});
|
|
2218
|
+
previous = point;
|
|
2219
|
+
}
|
|
2220
|
+
const distances = [.../* @__PURE__ */ new Set([...segments.map((segment) => segment.end), ...Array.from({ length: samples }, (_, index) => total * index / (samples - 1))])].sort((a, b) => a - b);
|
|
2221
|
+
let segmentIndex = 0;
|
|
2222
|
+
return {
|
|
2223
|
+
target,
|
|
2224
|
+
property: "position",
|
|
2225
|
+
composite: "replace",
|
|
2226
|
+
interpolation: "auto",
|
|
2227
|
+
orient,
|
|
2228
|
+
keyframes: distances.map((distance) => {
|
|
2229
|
+
const progress = total > 0 ? distance / total : 0;
|
|
2230
|
+
while (segmentIndex < segments.length - 1 && (segments[segmentIndex]?.end ?? 0) < distance) segmentIndex++;
|
|
2231
|
+
const segment = segments[segmentIndex];
|
|
2232
|
+
if (!segment) throw new Error("Path has no segments.");
|
|
2233
|
+
const { a, b, start, end } = segment;
|
|
2234
|
+
const fraction = end > start ? (distance - start) / (end - start) : 0;
|
|
2235
|
+
return {
|
|
2236
|
+
at: at + duration * progress,
|
|
2237
|
+
value: {
|
|
2238
|
+
x: a.x + (b.x - a.x) * fraction,
|
|
2239
|
+
y: a.y + (b.y - a.y) * fraction
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
})
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
//#endregion
|
|
2246
|
+
//#region ../sdk/src/board/model/frames.ts
|
|
2247
|
+
const SAME_ROW = .5;
|
|
2248
|
+
const CROSS_WEIGHT = 2;
|
|
2249
|
+
const CENTER_WEIGHT = .1;
|
|
2250
|
+
function boardNavigableFrames(scene) {
|
|
2251
|
+
const frames = [];
|
|
2252
|
+
const visit = (ids) => {
|
|
2253
|
+
for (const id of ids) {
|
|
2254
|
+
const item = scene.get(id);
|
|
2255
|
+
if (item?.type !== "frame") continue;
|
|
2256
|
+
if (item.props.decoration !== "none" || item.props.label.trim()) frames.push(item);
|
|
2257
|
+
else visit(scene.children(id));
|
|
2258
|
+
}
|
|
2259
|
+
};
|
|
2260
|
+
visit(scene.children(void 0));
|
|
2261
|
+
return frames;
|
|
2262
|
+
}
|
|
2263
|
+
function boardFrameRegion(item) {
|
|
2264
|
+
const label = item.type === "frame" ? item.props.label.trim() : "";
|
|
2265
|
+
return {
|
|
2266
|
+
id: item.id,
|
|
2267
|
+
rect: itemBounds(item.frame),
|
|
2268
|
+
...label ? { label } : {}
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
function boardFrameRegions(scene) {
|
|
2272
|
+
return boardReadingOrder(boardNavigableFrames(scene).map(boardFrameRegion));
|
|
2273
|
+
}
|
|
2274
|
+
const byId = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
2275
|
+
function boardReadingOrder(regions) {
|
|
2276
|
+
const sorted = [...regions].sort((a, b) => a.rect.y - b.rect.y || a.rect.x - b.rect.x || byId(a, b));
|
|
2277
|
+
const rows = [];
|
|
2278
|
+
for (const region of sorted) {
|
|
2279
|
+
const { y, height } = region.rect;
|
|
2280
|
+
const row = rows.at(-1);
|
|
2281
|
+
const overlap = row ? Math.min(row.bottom, y + height) - Math.max(row.top, y) : -1;
|
|
2282
|
+
if (row && overlap >= SAME_ROW * Math.min(height, row.bottom - row.top)) row.regions.push(region);
|
|
2283
|
+
else rows.push({
|
|
2284
|
+
top: y,
|
|
2285
|
+
bottom: y + height,
|
|
2286
|
+
regions: [region]
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
return rows.flatMap((row) => row.regions.sort((a, b) => a.rect.x - b.rect.x || a.rect.y - b.rect.y || byId(a, b)));
|
|
2290
|
+
}
|
|
2291
|
+
function axis(rect, horizontal) {
|
|
2292
|
+
return horizontal ? {
|
|
2293
|
+
start: rect.x,
|
|
2294
|
+
end: rect.x + rect.width,
|
|
2295
|
+
crossStart: rect.y,
|
|
2296
|
+
crossEnd: rect.y + rect.height
|
|
2297
|
+
} : {
|
|
2298
|
+
start: rect.y,
|
|
2299
|
+
end: rect.y + rect.height,
|
|
2300
|
+
crossStart: rect.x,
|
|
2301
|
+
crossEnd: rect.x + rect.width
|
|
2302
|
+
};
|
|
2303
|
+
}
|
|
2304
|
+
/** Left and right stay within regions sharing some height; up and down may reach regions offset sideways. */
|
|
2305
|
+
function boardRegionNeighbor(regions, from, direction) {
|
|
2306
|
+
const horizontal = direction === "left" || direction === "right";
|
|
2307
|
+
const sign = direction === "right" || direction === "down" ? 1 : -1;
|
|
2308
|
+
const origin = axis(from.rect, horizontal);
|
|
2309
|
+
const center = (origin.start + origin.end) / 2;
|
|
2310
|
+
const crossCenter = (origin.crossStart + origin.crossEnd) / 2;
|
|
2311
|
+
let best = null;
|
|
2312
|
+
let bestScore = Number.POSITIVE_INFINITY;
|
|
2313
|
+
for (const region of regions) {
|
|
2314
|
+
if (region.id === from.id) continue;
|
|
2315
|
+
const other = axis(region.rect, horizontal);
|
|
2316
|
+
if (!(sign > 0 ? other.end > origin.end && other.start + other.end > center * 2 : other.start < origin.start && other.start + other.end < center * 2)) continue;
|
|
2317
|
+
const gap = Math.max(0, sign > 0 ? other.start - origin.end : origin.start - other.end);
|
|
2318
|
+
const cross = Math.max(0, other.crossStart - origin.crossEnd, origin.crossStart - other.crossEnd);
|
|
2319
|
+
if (horizontal && cross > 0) continue;
|
|
2320
|
+
const drift = Math.abs((other.crossStart + other.crossEnd) / 2 - crossCenter);
|
|
2321
|
+
const score = gap + CROSS_WEIGHT * cross + CENTER_WEIGHT * drift;
|
|
2322
|
+
if (score < bestScore) {
|
|
2323
|
+
best = region;
|
|
2324
|
+
bestScore = score;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
return best;
|
|
2328
|
+
}
|
|
2329
|
+
function boardRegionStep(regions, from, step) {
|
|
2330
|
+
const index = regions.findIndex((region) => region.id === from.id);
|
|
2331
|
+
switch (step) {
|
|
2332
|
+
case "next": return index < 0 ? null : regions[index + 1] ?? null;
|
|
2333
|
+
case "previous": return index > 0 ? regions[index - 1] ?? null : null;
|
|
2334
|
+
case "first": return regions[0] ?? null;
|
|
2335
|
+
case "last": return regions.at(-1) ?? null;
|
|
2336
|
+
default: return boardRegionNeighbor(regions, from, step) ?? (step === "right" ? boardRegionStep(regions, from, "next") : step === "left" ? boardRegionStep(regions, from, "previous") : null);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
//#endregion
|
|
2340
|
+
//#region ../sdk/src/board/model/themes.ts
|
|
2341
|
+
const BOARD_THEME_IDS = [
|
|
2342
|
+
"dark",
|
|
2343
|
+
"light",
|
|
2344
|
+
"solarized-dark",
|
|
2345
|
+
"solarized-light",
|
|
2346
|
+
"neta-studio",
|
|
2347
|
+
"neta-pixel",
|
|
2348
|
+
"neta-pixel-dark"
|
|
2349
|
+
];
|
|
2350
|
+
const BOARD_THEME_DATA = {
|
|
2351
|
+
dark: {
|
|
2352
|
+
colorScheme: "dark",
|
|
2353
|
+
palette: {
|
|
2354
|
+
bg: 1053203,
|
|
2355
|
+
surface: 2369321,
|
|
2356
|
+
hover: 2500907,
|
|
2357
|
+
border: 3158838,
|
|
2358
|
+
brand: 14564909,
|
|
2359
|
+
activity: 14564909,
|
|
2360
|
+
error: 15950429,
|
|
2361
|
+
warning: 15580004,
|
|
2362
|
+
text: 15330286,
|
|
2363
|
+
muted: 10198947,
|
|
2364
|
+
rare: 6009047,
|
|
2365
|
+
epic: 2070983,
|
|
2366
|
+
legendary: 15580004
|
|
2367
|
+
},
|
|
2368
|
+
colors: {
|
|
2369
|
+
brand: {
|
|
2370
|
+
stroke: 14564909,
|
|
2371
|
+
fill: 14564909,
|
|
2372
|
+
label: 15330286
|
|
2373
|
+
},
|
|
2374
|
+
neutral: {
|
|
2375
|
+
stroke: 10198947,
|
|
2376
|
+
fill: 10198947,
|
|
2377
|
+
label: 15330286
|
|
2378
|
+
},
|
|
2379
|
+
black: {
|
|
2380
|
+
stroke: 0,
|
|
2381
|
+
fill: 0,
|
|
2382
|
+
label: 15330286
|
|
2383
|
+
},
|
|
2384
|
+
white: {
|
|
2385
|
+
stroke: 16777215,
|
|
2386
|
+
fill: 16777215,
|
|
2387
|
+
label: 15330286
|
|
2388
|
+
},
|
|
2389
|
+
blue: {
|
|
2390
|
+
stroke: 6009047,
|
|
2391
|
+
fill: 6009047,
|
|
2392
|
+
label: 15330286
|
|
2393
|
+
},
|
|
2394
|
+
green: {
|
|
2395
|
+
stroke: 7065501,
|
|
2396
|
+
fill: 7065501,
|
|
2397
|
+
label: 15330286
|
|
2398
|
+
},
|
|
2399
|
+
amber: {
|
|
2400
|
+
stroke: 15580004,
|
|
2401
|
+
fill: 15580004,
|
|
2402
|
+
label: 15330286
|
|
2403
|
+
},
|
|
2404
|
+
violet: {
|
|
2405
|
+
stroke: 11971577,
|
|
2406
|
+
fill: 11971577,
|
|
2407
|
+
label: 15330286
|
|
2408
|
+
},
|
|
2409
|
+
rose: {
|
|
2410
|
+
stroke: 15950429,
|
|
2411
|
+
fill: 15950429,
|
|
2412
|
+
label: 15330286
|
|
2413
|
+
}
|
|
2414
|
+
},
|
|
2415
|
+
style: {},
|
|
2416
|
+
backdrop: { pattern: {
|
|
2417
|
+
kind: "dots",
|
|
2418
|
+
pitch: 24,
|
|
2419
|
+
color: 2566444,
|
|
2420
|
+
size: 2
|
|
2421
|
+
} }
|
|
2422
|
+
},
|
|
2423
|
+
light: {
|
|
2424
|
+
colorScheme: "light",
|
|
2425
|
+
palette: {
|
|
2426
|
+
bg: 16251130,
|
|
2427
|
+
surface: 16777215,
|
|
2428
|
+
hover: 15330029,
|
|
2429
|
+
border: 14409442,
|
|
2430
|
+
brand: 13582898,
|
|
2431
|
+
activity: 13582898,
|
|
2432
|
+
error: 10165794,
|
|
2433
|
+
warning: 8804608,
|
|
2434
|
+
text: 66050,
|
|
2435
|
+
muted: 6251625,
|
|
2436
|
+
rare: 24458,
|
|
2437
|
+
epic: 19325,
|
|
2438
|
+
legendary: 8804608
|
|
2439
|
+
},
|
|
2440
|
+
colors: {
|
|
2441
|
+
brand: {
|
|
2442
|
+
stroke: 13582898,
|
|
2443
|
+
fill: 13582898,
|
|
2444
|
+
label: 66050
|
|
2445
|
+
},
|
|
2446
|
+
neutral: {
|
|
2447
|
+
stroke: 6251625,
|
|
2448
|
+
fill: 6251625,
|
|
2449
|
+
label: 66050
|
|
2450
|
+
},
|
|
2451
|
+
black: {
|
|
2452
|
+
stroke: 0,
|
|
2453
|
+
fill: 0,
|
|
2454
|
+
label: 66050
|
|
2455
|
+
},
|
|
2456
|
+
white: {
|
|
2457
|
+
stroke: 16777215,
|
|
2458
|
+
fill: 16777215,
|
|
2459
|
+
label: 66050
|
|
2460
|
+
},
|
|
2461
|
+
blue: {
|
|
2462
|
+
stroke: 24458,
|
|
2463
|
+
fill: 24458,
|
|
2464
|
+
label: 66050
|
|
2465
|
+
},
|
|
2466
|
+
green: {
|
|
2467
|
+
stroke: 26685,
|
|
2468
|
+
fill: 26685,
|
|
2469
|
+
label: 66050
|
|
2470
|
+
},
|
|
2471
|
+
amber: {
|
|
2472
|
+
stroke: 8804608,
|
|
2473
|
+
fill: 8804608,
|
|
2474
|
+
label: 66050
|
|
2475
|
+
},
|
|
2476
|
+
violet: {
|
|
2477
|
+
stroke: 6904238,
|
|
2478
|
+
fill: 6904238,
|
|
2479
|
+
label: 66050
|
|
2480
|
+
},
|
|
2481
|
+
rose: {
|
|
2482
|
+
stroke: 10165794,
|
|
2483
|
+
fill: 10165794,
|
|
2484
|
+
label: 66050
|
|
2485
|
+
}
|
|
2486
|
+
},
|
|
2487
|
+
style: {},
|
|
2488
|
+
backdrop: { pattern: {
|
|
2489
|
+
kind: "dots",
|
|
2490
|
+
pitch: 24,
|
|
2491
|
+
color: 15001321,
|
|
2492
|
+
size: 2
|
|
2493
|
+
} }
|
|
2494
|
+
},
|
|
2495
|
+
"solarized-dark": {
|
|
2496
|
+
colorScheme: "dark",
|
|
2497
|
+
palette: {
|
|
2498
|
+
bg: 70677,
|
|
2499
|
+
surface: 859936,
|
|
2500
|
+
hover: 1057828,
|
|
2501
|
+
border: 1582887,
|
|
2502
|
+
brand: 34240,
|
|
2503
|
+
activity: 34240,
|
|
2504
|
+
error: 15950429,
|
|
2505
|
+
warning: 14790474,
|
|
2506
|
+
text: 12572374,
|
|
2507
|
+
muted: 6848639,
|
|
2508
|
+
rare: 2206648,
|
|
2509
|
+
epic: 38821,
|
|
2510
|
+
legendary: 14790474
|
|
2511
|
+
},
|
|
2512
|
+
colors: {
|
|
2513
|
+
brand: {
|
|
2514
|
+
stroke: 34240,
|
|
2515
|
+
fill: 34240,
|
|
2516
|
+
label: 12572374
|
|
2517
|
+
},
|
|
2518
|
+
neutral: {
|
|
2519
|
+
stroke: 6848639,
|
|
2520
|
+
fill: 6848639,
|
|
2521
|
+
label: 12572374
|
|
2522
|
+
},
|
|
2523
|
+
black: {
|
|
2524
|
+
stroke: 0,
|
|
2525
|
+
fill: 0,
|
|
2526
|
+
label: 12572374
|
|
2527
|
+
},
|
|
2528
|
+
white: {
|
|
2529
|
+
stroke: 16777215,
|
|
2530
|
+
fill: 16777215,
|
|
2531
|
+
label: 12572374
|
|
2532
|
+
},
|
|
2533
|
+
blue: {
|
|
2534
|
+
stroke: 2206648,
|
|
2535
|
+
fill: 2206648,
|
|
2536
|
+
label: 12572374
|
|
2537
|
+
},
|
|
2538
|
+
green: {
|
|
2539
|
+
stroke: 9481815,
|
|
2540
|
+
fill: 9481815,
|
|
2541
|
+
label: 12572374
|
|
2542
|
+
},
|
|
2543
|
+
amber: {
|
|
2544
|
+
stroke: 14790474,
|
|
2545
|
+
fill: 14790474,
|
|
2546
|
+
label: 12572374
|
|
2547
|
+
},
|
|
2548
|
+
violet: {
|
|
2549
|
+
stroke: 11182560,
|
|
2550
|
+
fill: 11182560,
|
|
2551
|
+
label: 12572374
|
|
2552
|
+
},
|
|
2553
|
+
rose: {
|
|
2554
|
+
stroke: 15950429,
|
|
2555
|
+
fill: 15950429,
|
|
2556
|
+
label: 12572374
|
|
2557
|
+
}
|
|
2558
|
+
},
|
|
2559
|
+
style: {},
|
|
2560
|
+
backdrop: { pattern: {
|
|
2561
|
+
kind: "dots",
|
|
2562
|
+
pitch: 24,
|
|
2563
|
+
color: 1122594,
|
|
2564
|
+
size: 2
|
|
2565
|
+
} }
|
|
2566
|
+
},
|
|
2567
|
+
"solarized-light": {
|
|
2568
|
+
colorScheme: "light",
|
|
2569
|
+
palette: {
|
|
2570
|
+
bg: 16775902,
|
|
2571
|
+
surface: 16446169,
|
|
2572
|
+
hover: 15920337,
|
|
2573
|
+
border: 14341313,
|
|
2574
|
+
brand: 31924,
|
|
2575
|
+
activity: 31924,
|
|
2576
|
+
error: 10363429,
|
|
2577
|
+
warning: 8936704,
|
|
2578
|
+
text: 2110772,
|
|
2579
|
+
muted: 5860973,
|
|
2580
|
+
rare: 28541,
|
|
2581
|
+
epic: 23659,
|
|
2582
|
+
legendary: 8936704
|
|
2583
|
+
},
|
|
2584
|
+
colors: {
|
|
2585
|
+
brand: {
|
|
2586
|
+
stroke: 31924,
|
|
2587
|
+
fill: 31924,
|
|
2588
|
+
label: 2110772
|
|
2589
|
+
},
|
|
2590
|
+
neutral: {
|
|
2591
|
+
stroke: 5860973,
|
|
2592
|
+
fill: 5860973,
|
|
2593
|
+
label: 2110772
|
|
2594
|
+
},
|
|
2595
|
+
black: {
|
|
2596
|
+
stroke: 0,
|
|
2597
|
+
fill: 0,
|
|
2598
|
+
label: 2110772
|
|
2599
|
+
},
|
|
2600
|
+
white: {
|
|
2601
|
+
stroke: 16777215,
|
|
2602
|
+
fill: 16777215,
|
|
2603
|
+
label: 2110772
|
|
2604
|
+
},
|
|
2605
|
+
blue: {
|
|
2606
|
+
stroke: 28541,
|
|
2607
|
+
fill: 28541,
|
|
2608
|
+
label: 2110772
|
|
2609
|
+
},
|
|
2610
|
+
green: {
|
|
2611
|
+
stroke: 4809217,
|
|
2612
|
+
fill: 4809217,
|
|
2613
|
+
label: 2110772
|
|
2614
|
+
},
|
|
2615
|
+
amber: {
|
|
2616
|
+
stroke: 8936704,
|
|
2617
|
+
fill: 8936704,
|
|
2618
|
+
label: 2110772
|
|
2619
|
+
},
|
|
2620
|
+
violet: {
|
|
2621
|
+
stroke: 6904995,
|
|
2622
|
+
fill: 6904995,
|
|
2623
|
+
label: 2110772
|
|
2624
|
+
},
|
|
2625
|
+
rose: {
|
|
2626
|
+
stroke: 10363429,
|
|
2627
|
+
fill: 10363429,
|
|
2628
|
+
label: 2110772
|
|
2629
|
+
}
|
|
2630
|
+
},
|
|
2631
|
+
style: {},
|
|
2632
|
+
backdrop: { pattern: {
|
|
2633
|
+
kind: "dots",
|
|
2634
|
+
pitch: 24,
|
|
2635
|
+
color: 15130570,
|
|
2636
|
+
size: 2
|
|
2637
|
+
} }
|
|
2638
|
+
},
|
|
2639
|
+
"neta-studio": {
|
|
2640
|
+
colorScheme: "dark",
|
|
2641
|
+
palette: {
|
|
2642
|
+
bg: 329221,
|
|
2643
|
+
surface: 1249814,
|
|
2644
|
+
hover: 1973788,
|
|
2645
|
+
border: 1842202,
|
|
2646
|
+
brand: 3900150,
|
|
2647
|
+
activity: 15524306,
|
|
2648
|
+
error: 15562341,
|
|
2649
|
+
warning: 15449187,
|
|
2650
|
+
text: 16314853,
|
|
2651
|
+
muted: 7630695,
|
|
2652
|
+
rare: 9235170,
|
|
2653
|
+
epic: 7266776,
|
|
2654
|
+
legendary: 15449187
|
|
2655
|
+
},
|
|
2656
|
+
colors: {
|
|
2657
|
+
brand: {
|
|
2658
|
+
stroke: 15524306,
|
|
2659
|
+
fill: 15524306,
|
|
2660
|
+
label: 16314853
|
|
2661
|
+
},
|
|
2662
|
+
neutral: {
|
|
2663
|
+
stroke: 15524306,
|
|
2664
|
+
fill: 15524306,
|
|
2665
|
+
label: 16314853
|
|
2666
|
+
},
|
|
2667
|
+
black: {
|
|
2668
|
+
stroke: 0,
|
|
2669
|
+
fill: 0,
|
|
2670
|
+
label: 16314853
|
|
2671
|
+
},
|
|
2672
|
+
white: {
|
|
2673
|
+
stroke: 16777215,
|
|
2674
|
+
fill: 16777215,
|
|
2675
|
+
label: 16314853
|
|
2676
|
+
},
|
|
2677
|
+
blue: {
|
|
2678
|
+
stroke: 9235170,
|
|
2679
|
+
fill: 9235170,
|
|
2680
|
+
label: 16314853
|
|
2681
|
+
},
|
|
2682
|
+
green: {
|
|
2683
|
+
stroke: 8177036,
|
|
2684
|
+
fill: 8177036,
|
|
2685
|
+
label: 16314853
|
|
2686
|
+
},
|
|
2687
|
+
amber: {
|
|
2688
|
+
stroke: 15449187,
|
|
2689
|
+
fill: 15449187,
|
|
2690
|
+
label: 16314853
|
|
2691
|
+
},
|
|
2692
|
+
violet: {
|
|
2693
|
+
stroke: 11971327,
|
|
2694
|
+
fill: 11971327,
|
|
2695
|
+
label: 16314853
|
|
2696
|
+
},
|
|
2697
|
+
rose: {
|
|
2698
|
+
stroke: 15562341,
|
|
2699
|
+
fill: 15562341,
|
|
2700
|
+
label: 16314853
|
|
2701
|
+
}
|
|
2702
|
+
},
|
|
2703
|
+
style: {
|
|
2704
|
+
selection: { outset: 0 },
|
|
2705
|
+
frameLabelSize: 16
|
|
2706
|
+
}
|
|
2707
|
+
},
|
|
2708
|
+
"neta-pixel": {
|
|
2709
|
+
colorScheme: "light",
|
|
2710
|
+
palette: {
|
|
2711
|
+
bg: 16185078,
|
|
2712
|
+
surface: 16777215,
|
|
2713
|
+
hover: 16185078,
|
|
2714
|
+
border: 15527149,
|
|
2715
|
+
brand: 1824230,
|
|
2716
|
+
activity: 434355,
|
|
2717
|
+
error: 13705029,
|
|
2718
|
+
warning: 9725440,
|
|
2719
|
+
text: 1447704,
|
|
2720
|
+
muted: 7566452,
|
|
2721
|
+
rare: 31378,
|
|
2722
|
+
epic: 31378,
|
|
2723
|
+
legendary: 9725440
|
|
2724
|
+
},
|
|
2725
|
+
colors: {
|
|
2726
|
+
brand: {
|
|
2727
|
+
stroke: 1447704,
|
|
2728
|
+
fill: 1447704,
|
|
2729
|
+
label: 1447704
|
|
2730
|
+
},
|
|
2731
|
+
neutral: {
|
|
2732
|
+
stroke: 7566452,
|
|
2733
|
+
fill: 7566452,
|
|
2734
|
+
label: 1447704
|
|
2735
|
+
},
|
|
2736
|
+
black: {
|
|
2737
|
+
stroke: 0,
|
|
2738
|
+
fill: 0,
|
|
2739
|
+
label: 1447704
|
|
2740
|
+
},
|
|
2741
|
+
white: {
|
|
2742
|
+
stroke: 16777215,
|
|
2743
|
+
fill: 16777215,
|
|
2744
|
+
label: 1447704
|
|
2745
|
+
},
|
|
2746
|
+
blue: {
|
|
2747
|
+
stroke: 6010853,
|
|
2748
|
+
fill: 6010853,
|
|
2749
|
+
label: 1447704
|
|
2750
|
+
},
|
|
2751
|
+
green: {
|
|
2752
|
+
stroke: 9683613,
|
|
2753
|
+
fill: 9683613,
|
|
2754
|
+
label: 1447704
|
|
2755
|
+
},
|
|
2756
|
+
amber: {
|
|
2757
|
+
stroke: 14264410,
|
|
2758
|
+
fill: 14264410,
|
|
2759
|
+
label: 1447704
|
|
2760
|
+
},
|
|
2761
|
+
violet: {
|
|
2762
|
+
stroke: 11441117,
|
|
2763
|
+
fill: 11441117,
|
|
2764
|
+
label: 1447704
|
|
2765
|
+
},
|
|
2766
|
+
rose: {
|
|
2767
|
+
stroke: 15043210,
|
|
2768
|
+
fill: 15043210,
|
|
2769
|
+
label: 1447704
|
|
2770
|
+
}
|
|
2771
|
+
},
|
|
2772
|
+
style: {
|
|
2773
|
+
corner: "pixel",
|
|
2774
|
+
shadow: {
|
|
2775
|
+
color: 1447704,
|
|
2776
|
+
alpha: .1,
|
|
2777
|
+
blur: 20,
|
|
2778
|
+
y: 0
|
|
2779
|
+
},
|
|
2780
|
+
selection: {
|
|
2781
|
+
width: 1.5,
|
|
2782
|
+
outset: 0,
|
|
2783
|
+
dash: 0,
|
|
2784
|
+
handle: "square",
|
|
2785
|
+
handleSize: 8
|
|
2786
|
+
},
|
|
2787
|
+
media: "framed",
|
|
2788
|
+
progress: "mosaic",
|
|
2789
|
+
icons: "pixel",
|
|
2790
|
+
motion: "stepped",
|
|
2791
|
+
font: "\"Figtree Variable\", \"PingFang SC\", \"Noto Sans CJK SC\", \"Microsoft YaHei\", system-ui, sans-serif",
|
|
2792
|
+
frameLabelSize: 16
|
|
2793
|
+
},
|
|
2794
|
+
backdrop: { pattern: {
|
|
2795
|
+
kind: "dots",
|
|
2796
|
+
pitch: 24,
|
|
2797
|
+
color: 14935011,
|
|
2798
|
+
size: 2,
|
|
2799
|
+
shape: "square"
|
|
2800
|
+
} }
|
|
2801
|
+
},
|
|
2802
|
+
"neta-pixel-dark": {
|
|
2803
|
+
colorScheme: "dark",
|
|
2804
|
+
palette: {
|
|
2805
|
+
bg: 1118739,
|
|
2806
|
+
surface: 1842463,
|
|
2807
|
+
hover: 2237220,
|
|
2808
|
+
border: 2763565,
|
|
2809
|
+
brand: 1824230,
|
|
2810
|
+
activity: 3142143,
|
|
2811
|
+
error: 16740488,
|
|
2812
|
+
warning: 16766287,
|
|
2813
|
+
text: 16185078,
|
|
2814
|
+
muted: 9079436,
|
|
2815
|
+
rare: 1824230,
|
|
2816
|
+
epic: 1824230,
|
|
2817
|
+
legendary: 16766287
|
|
2818
|
+
},
|
|
2819
|
+
colors: {
|
|
2820
|
+
brand: {
|
|
2821
|
+
stroke: 16185078,
|
|
2822
|
+
fill: 16185078,
|
|
2823
|
+
label: 16185078
|
|
2824
|
+
},
|
|
2825
|
+
neutral: {
|
|
2826
|
+
stroke: 9079436,
|
|
2827
|
+
fill: 9079436,
|
|
2828
|
+
label: 16185078
|
|
2829
|
+
},
|
|
2830
|
+
black: {
|
|
2831
|
+
stroke: 0,
|
|
2832
|
+
fill: 0,
|
|
2833
|
+
label: 16185078
|
|
2834
|
+
},
|
|
2835
|
+
white: {
|
|
2836
|
+
stroke: 16777215,
|
|
2837
|
+
fill: 16777215,
|
|
2838
|
+
label: 16185078
|
|
2839
|
+
},
|
|
2840
|
+
blue: {
|
|
2841
|
+
stroke: 6010853,
|
|
2842
|
+
fill: 6010853,
|
|
2843
|
+
label: 16185078
|
|
2844
|
+
},
|
|
2845
|
+
green: {
|
|
2846
|
+
stroke: 9683613,
|
|
2847
|
+
fill: 9683613,
|
|
2848
|
+
label: 16185078
|
|
2849
|
+
},
|
|
2850
|
+
amber: {
|
|
2851
|
+
stroke: 14264410,
|
|
2852
|
+
fill: 14264410,
|
|
2853
|
+
label: 16185078
|
|
2854
|
+
},
|
|
2855
|
+
violet: {
|
|
2856
|
+
stroke: 11441117,
|
|
2857
|
+
fill: 11441117,
|
|
2858
|
+
label: 16185078
|
|
2859
|
+
},
|
|
2860
|
+
rose: {
|
|
2861
|
+
stroke: 15043210,
|
|
2862
|
+
fill: 15043210,
|
|
2863
|
+
label: 16185078
|
|
2864
|
+
}
|
|
2865
|
+
},
|
|
2866
|
+
style: {
|
|
2867
|
+
corner: "pixel",
|
|
2868
|
+
shadow: {
|
|
2869
|
+
color: 0,
|
|
2870
|
+
alpha: .4,
|
|
2871
|
+
blur: 20,
|
|
2872
|
+
y: 0
|
|
2873
|
+
},
|
|
2874
|
+
selection: {
|
|
2875
|
+
width: 1.5,
|
|
2876
|
+
outset: 0,
|
|
2877
|
+
dash: 0,
|
|
2878
|
+
handle: "square",
|
|
2879
|
+
handleSize: 8
|
|
2880
|
+
},
|
|
2881
|
+
media: "framed",
|
|
2882
|
+
progress: "mosaic",
|
|
2883
|
+
icons: "pixel",
|
|
2884
|
+
motion: "stepped",
|
|
2885
|
+
font: "\"Figtree Variable\", \"PingFang SC\", \"Noto Sans CJK SC\", \"Microsoft YaHei\", system-ui, sans-serif",
|
|
2886
|
+
frameLabelSize: 16
|
|
2887
|
+
},
|
|
2888
|
+
backdrop: { pattern: {
|
|
2889
|
+
kind: "dots",
|
|
2890
|
+
pitch: 24,
|
|
2891
|
+
color: 3816512,
|
|
2892
|
+
size: 2,
|
|
2893
|
+
shape: "square"
|
|
2894
|
+
} }
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
//#endregion
|
|
2898
|
+
export { rectCenter as $, compileBoardAnimations as A, clampZoom as B, resolveBoardAnimationCamera as C, sceneItemToItem as D, refreshBoardScene as E, BOARD_SCRIPT_SENSES_EXAMPLE as F, frameEdgeHandleAt as G, effectBounds as H, BOARD_SCRIPT_TILT_EXAMPLE as I, itemBounds as J, frameHandlePosition as K, CORNER_RESIZE_HANDLES as L, withBoardScripts as M, BOARD_SCRIPT_DRAWING_EXAMPLE as N, BOARD_SCRIPT_HISTORY_MS as O, BOARD_SCRIPT_RAIN_EXAMPLE as P, pointToWorld as Q, cameraForRect as R, createBoardAnimationSampler as S, placeItem as T, frameContainsPoint as U, degToRad as V, frameCornerRotationHandleAt as W, normalizeViewport as X, normalizeRotation as Y, panBy as Z, boardSplitTarget as _, boardNavigableFrames as a, rotationHandlePosition as at, findBoardKeyTrack as b, boardPathTrack as c, selectionBounds as ct, boardSequencePatch as d, visibleWorldRect as dt, rectContainsPoint as et, boardInsertTime as f, worldPoint as ft, boardShiftTargets as g, boardRemoveTime as h, boardFrameRegions as i, rotatePointAround as it, evaluateBoardAnimations as j, boardAnimatesScriptParams as k, boardPlacePatch as l, stateForCamera as lt, boardRemoveTarget as m, BOARD_THEME_IDS as n, resizeFrame as nt, boardReadingOrder as o, scaleFrames as ot, boardPlaceTarget as p, zoomAround as pt, frameRect as q, boardFrameRegion as r, rotateFrames as rt, boardRegionStep as s, screenPoint as st, BOARD_THEME_DATA as t, rectsIntersect as tt, boardSequence as u, unionRects as ut, boardTargetSpan as v, buildBoardScene as w, newBoardTrackId as x, boardTrimTarget as y, cameraForState as z };
|