@h-rig/cli 0.0.6-alpha.82 → 0.0.6-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/build-rig-binaries.js +40 -8
- package/dist/bin/rig.js +23402 -14577
- package/dist/src/app/board.js +217 -41
- package/dist/src/app-opentui/adapters/command.d.ts +2 -0
- package/dist/src/app-opentui/adapters/command.js +329 -0
- package/dist/src/app-opentui/adapters/common.js +2 -2
- package/dist/src/app-opentui/adapters/doctor.d.ts +0 -2
- package/dist/src/app-opentui/adapters/doctor.js +64 -39
- package/dist/src/app-opentui/adapters/family.d.ts +62 -0
- package/dist/src/app-opentui/adapters/family.js +14305 -0
- package/dist/src/app-opentui/adapters/fleet.d.ts +0 -2
- package/dist/src/app-opentui/adapters/fleet.js +90 -60
- package/dist/src/app-opentui/adapters/inbox.d.ts +12 -2
- package/dist/src/app-opentui/adapters/inbox.js +137 -78
- package/dist/src/app-opentui/adapters/init.d.ts +0 -2
- package/dist/src/app-opentui/adapters/init.js +85 -47
- package/dist/src/app-opentui/adapters/inspect.d.ts +52 -0
- package/dist/src/app-opentui/adapters/inspect.js +1024 -0
- package/dist/src/app-opentui/adapters/pi-attach.d.ts +15 -6
- package/dist/src/app-opentui/adapters/pi-attach.js +442 -125
- package/dist/src/app-opentui/adapters/pi.d.ts +23 -0
- package/dist/src/app-opentui/adapters/pi.js +363 -0
- package/dist/src/app-opentui/adapters/plugin.d.ts +84 -0
- package/dist/src/app-opentui/adapters/plugin.js +544 -0
- package/dist/src/app-opentui/adapters/repo.d.ts +37 -0
- package/dist/src/app-opentui/adapters/repo.js +186 -0
- package/dist/src/app-opentui/adapters/run-detail.d.ts +9 -2
- package/dist/src/app-opentui/adapters/run-detail.js +180 -63
- package/dist/src/app-opentui/adapters/server.d.ts +10 -2
- package/dist/src/app-opentui/adapters/server.js +191 -45
- package/dist/src/app-opentui/adapters/tasks.d.ts +11 -2
- package/dist/src/app-opentui/adapters/tasks.js +1123 -143
- package/dist/src/app-opentui/adapters/workspace.d.ts +49 -0
- package/dist/src/app-opentui/adapters/workspace.js +333 -0
- package/dist/src/app-opentui/autocomplete.d.ts +20 -0
- package/dist/src/app-opentui/autocomplete.js +576 -0
- package/dist/src/app-opentui/bootstrap.d.ts +1 -6
- package/dist/src/app-opentui/bootstrap.js +25252 -16474
- package/dist/src/app-opentui/command-palette.d.ts +3 -0
- package/dist/src/app-opentui/command-palette.js +1010 -0
- package/dist/src/app-opentui/command-pty-host.d.ts +62 -0
- package/dist/src/app-opentui/command-pty-host.js +248 -0
- package/dist/src/app-opentui/drone.js +8 -6
- package/dist/src/app-opentui/events.js +1 -1
- package/dist/src/app-opentui/fleet-stats.d.ts +32 -0
- package/dist/src/app-opentui/fleet-stats.js +114 -0
- package/dist/src/app-opentui/focus-manager.d.ts +14 -0
- package/dist/src/app-opentui/focus-manager.js +24 -0
- package/dist/src/app-opentui/index.js +5431 -2797
- package/dist/src/app-opentui/intent.js +179 -50
- package/dist/src/app-opentui/keymap.d.ts +21 -0
- package/dist/src/app-opentui/keymap.js +1748 -0
- package/dist/src/app-opentui/launch-routing.d.ts +16 -0
- package/dist/src/app-opentui/launch-routing.js +55 -0
- package/dist/src/app-opentui/layout.d.ts +7 -0
- package/dist/src/app-opentui/layout.js +13 -6
- package/dist/src/app-opentui/list-search.d.ts +24 -0
- package/dist/src/app-opentui/list-search.js +88 -1
- package/dist/src/app-opentui/pi-host-child.js +99 -17
- package/dist/src/app-opentui/pi-pty-host.d.ts +14 -0
- package/dist/src/app-opentui/pi-pty-host.js +30 -14
- package/dist/src/app-opentui/react/App.d.ts +9 -0
- package/dist/src/app-opentui/react/App.js +5144 -0
- package/dist/src/app-opentui/react/Backdrop.d.ts +5 -0
- package/dist/src/app-opentui/react/Backdrop.js +1834 -0
- package/dist/src/app-opentui/react/ChromeHost.d.ts +5 -0
- package/dist/src/app-opentui/react/ChromeHost.js +2942 -0
- package/dist/src/app-opentui/react/SceneFrameView.d.ts +7 -0
- package/dist/src/app-opentui/react/SceneFrameView.js +529 -0
- package/dist/src/app-opentui/react/context.d.ts +17 -0
- package/dist/src/app-opentui/react/context.js +37 -0
- package/dist/src/app-opentui/react/launch.d.ts +2 -0
- package/dist/src/app-opentui/react/launch.js +5743 -0
- package/dist/src/app-opentui/react/nav.d.ts +18 -0
- package/dist/src/app-opentui/react/nav.js +54 -0
- package/dist/src/app-opentui/react/scroll.d.ts +12 -0
- package/dist/src/app-opentui/react/scroll.js +21 -0
- package/dist/src/app-opentui/react/syntax.d.ts +2 -0
- package/dist/src/app-opentui/react/syntax.js +64 -0
- package/dist/src/app-opentui/registry.js +20428 -4828
- package/dist/src/app-opentui/render/ascii-fleet.d.ts +15 -0
- package/dist/src/app-opentui/render/ascii-fleet.js +82 -0
- package/dist/src/app-opentui/render/constants.d.ts +31 -0
- package/dist/src/app-opentui/render/constants.js +66 -0
- package/dist/src/app-opentui/render/graphics.d.ts +2 -1
- package/dist/src/app-opentui/render/graphics.js +228 -46
- package/dist/src/app-opentui/render/image-visual-layer-worker.js +469 -930
- package/dist/src/app-opentui/render/image-visual-layer.d.ts +25 -10
- package/dist/src/app-opentui/render/image-visual-layer.js +448 -329
- package/dist/src/app-opentui/render/native-host.d.ts +37 -0
- package/dist/src/app-opentui/render/native-host.js +179 -0
- package/dist/src/app-opentui/render/panel-layout.d.ts +38 -0
- package/dist/src/app-opentui/render/panel-layout.js +48 -0
- package/dist/src/app-opentui/render/panels.d.ts +2 -0
- package/dist/src/app-opentui/render/panels.js +78 -38
- package/dist/src/app-opentui/render/preloader.d.ts +10 -0
- package/dist/src/app-opentui/render/preloader.js +165 -0
- package/dist/src/app-opentui/render/scene.d.ts +53 -1
- package/dist/src/app-opentui/render/scene.js +195 -6
- package/dist/src/app-opentui/render/text.d.ts +7 -1
- package/dist/src/app-opentui/render/text.js +15 -8
- package/dist/src/app-opentui/render/type-bar.d.ts +2 -1
- package/dist/src/app-opentui/render/type-bar.js +113 -39
- package/dist/src/app-opentui/runtime-resources.d.ts +16 -0
- package/dist/src/app-opentui/runtime-resources.js +62 -0
- package/dist/src/app-opentui/runtime.d.ts +44 -1
- package/dist/src/app-opentui/runtime.js +5415 -2738
- package/dist/src/app-opentui/scenes/command.d.ts +3 -0
- package/dist/src/app-opentui/scenes/command.js +117 -0
- package/dist/src/app-opentui/scenes/doctor.d.ts +2 -1
- package/dist/src/app-opentui/scenes/doctor.js +221 -17
- package/dist/src/app-opentui/scenes/error.js +60 -20
- package/dist/src/app-opentui/scenes/family-domains/agent.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/agent.js +348 -0
- package/dist/src/app-opentui/scenes/family-domains/browser.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/browser.js +195 -0
- package/dist/src/app-opentui/scenes/family-domains/dist.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/dist.js +243 -0
- package/dist/src/app-opentui/scenes/family-domains/git.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/git.js +195 -0
- package/dist/src/app-opentui/scenes/family-domains/github.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/github.js +274 -0
- package/dist/src/app-opentui/scenes/family-domains/harness.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/harness.js +152 -0
- package/dist/src/app-opentui/scenes/family-domains/index.d.ts +4 -0
- package/dist/src/app-opentui/scenes/family-domains/index.js +1679 -0
- package/dist/src/app-opentui/scenes/family-domains/kit.d.ts +76 -0
- package/dist/src/app-opentui/scenes/family-domains/kit.js +305 -0
- package/dist/src/app-opentui/scenes/family-domains/profile.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/profile.js +212 -0
- package/dist/src/app-opentui/scenes/family-domains/queue.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/queue.js +146 -0
- package/dist/src/app-opentui/scenes/family-domains/remote.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/remote.js +518 -0
- package/dist/src/app-opentui/scenes/family-domains/review.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/review.js +280 -0
- package/dist/src/app-opentui/scenes/family-domains/setup.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/setup.js +267 -0
- package/dist/src/app-opentui/scenes/family-domains/stats.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/stats.js +370 -0
- package/dist/src/app-opentui/scenes/family.d.ts +3 -0
- package/dist/src/app-opentui/scenes/family.js +2144 -0
- package/dist/src/app-opentui/scenes/fleet.js +552 -43
- package/dist/src/app-opentui/scenes/handoff.js +342 -35
- package/dist/src/app-opentui/scenes/help.js +640 -56
- package/dist/src/app-opentui/scenes/inbox.d.ts +2 -1
- package/dist/src/app-opentui/scenes/inbox.js +329 -21
- package/dist/src/app-opentui/scenes/init.d.ts +2 -1
- package/dist/src/app-opentui/scenes/init.js +120 -34
- package/dist/src/app-opentui/scenes/inspect.d.ts +3 -0
- package/dist/src/app-opentui/scenes/inspect.js +793 -0
- package/dist/src/app-opentui/scenes/main.d.ts +2 -1
- package/dist/src/app-opentui/scenes/main.js +264 -29
- package/dist/src/app-opentui/scenes/pi.d.ts +3 -0
- package/dist/src/app-opentui/scenes/pi.js +508 -0
- package/dist/src/app-opentui/scenes/plugin.d.ts +3 -0
- package/dist/src/app-opentui/scenes/plugin.js +486 -0
- package/dist/src/app-opentui/scenes/repo.d.ts +3 -0
- package/dist/src/app-opentui/scenes/repo.js +424 -0
- package/dist/src/app-opentui/scenes/run-detail.d.ts +2 -1
- package/dist/src/app-opentui/scenes/run-detail.js +362 -35
- package/dist/src/app-opentui/scenes/server.d.ts +2 -1
- package/dist/src/app-opentui/scenes/server.js +243 -26
- package/dist/src/app-opentui/scenes/tasks.js +518 -41
- package/dist/src/app-opentui/scenes/workspace.d.ts +3 -0
- package/dist/src/app-opentui/scenes/workspace.js +426 -0
- package/dist/src/app-opentui/selectable.d.ts +19 -0
- package/dist/src/app-opentui/selectable.js +79 -0
- package/dist/src/app-opentui/state.js +129 -36
- package/dist/src/app-opentui/surface-catalog.d.ts +20 -0
- package/dist/src/app-opentui/surface-catalog.js +540 -0
- package/dist/src/app-opentui/terminal-capabilities.d.ts +7 -0
- package/dist/src/app-opentui/terminal-capabilities.js +15 -0
- package/dist/src/app-opentui/theme.d.ts +28 -6
- package/dist/src/app-opentui/theme.js +61 -8
- package/dist/src/app-opentui/types.d.ts +130 -5
- package/dist/src/commands/_authority-runs.d.ts +1 -1
- package/dist/src/commands/_authority-runs.js +2 -12
- package/dist/src/commands/_doctor-checks.js +62 -13
- package/dist/src/commands/_help-catalog.js +95 -15
- package/dist/src/commands/_operator-view.js +97 -15
- package/dist/src/commands/_pi-frontend.d.ts +2 -0
- package/dist/src/commands/_pi-frontend.js +97 -13
- package/dist/src/commands/_preflight.js +64 -14
- package/dist/src/commands/_server-client.js +82 -18
- package/dist/src/commands/_server-events.d.ts +26 -0
- package/dist/src/commands/_server-events.js +310 -0
- package/dist/src/commands/_snapshot-upload.js +62 -13
- package/dist/src/commands/agent.js +2 -12
- package/dist/src/commands/connect.js +7 -1
- package/dist/src/commands/doctor.js +62 -13
- package/dist/src/commands/github.js +144 -23
- package/dist/src/commands/inbox.js +62 -13
- package/dist/src/commands/init.js +82 -18
- package/dist/src/commands/inspect.js +62 -13
- package/dist/src/commands/run.js +100 -15
- package/dist/src/commands/server.js +71 -26
- package/dist/src/commands/setup.js +62 -13
- package/dist/src/commands/stats.js +157 -28
- package/dist/src/commands/task-run-driver.js +64 -25
- package/dist/src/commands/task.js +196 -43
- package/dist/src/commands.js +419 -123
- package/dist/src/index.js +426 -130
- package/package.json +11 -10
- package/dist/src/app-opentui/render/image-visual-layer-native-canvas.d.ts +0 -2
- package/dist/src/app-opentui/render/image-visual-layer-native-canvas.js +0 -1484
|
@@ -0,0 +1,1834 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/app-opentui/react/Backdrop.tsx
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { useRenderer } from "@opentui/react";
|
|
5
|
+
|
|
6
|
+
// packages/cli/src/app-opentui/layout.ts
|
|
7
|
+
var MIN_TERMINAL_WIDTH = 48;
|
|
8
|
+
var MIN_TERMINAL_HEIGHT = 16;
|
|
9
|
+
function computeStageLayout(width, height) {
|
|
10
|
+
const rawWidth = Math.trunc(width || 80);
|
|
11
|
+
const rawHeight = Math.trunc(height || 24);
|
|
12
|
+
const tooSmall = rawWidth < MIN_TERMINAL_WIDTH || rawHeight < MIN_TERMINAL_HEIGHT;
|
|
13
|
+
const safeWidth = Math.max(40, rawWidth);
|
|
14
|
+
const safeHeight = Math.max(18, rawHeight);
|
|
15
|
+
const compact = safeWidth < 92 || safeHeight < 30;
|
|
16
|
+
const horizontalGutter = compact ? 1 : 2;
|
|
17
|
+
const centerWidth = Math.max(36, safeWidth - horizontalGutter * 2);
|
|
18
|
+
const centerLeft = horizontalGutter;
|
|
19
|
+
const footerTop = Math.max(0, safeHeight - 1);
|
|
20
|
+
const typeBarTop = Math.max(0, footerTop - 1);
|
|
21
|
+
const centerTop = compact ? 1 : Math.max(1, Math.floor(safeHeight * 0.055));
|
|
22
|
+
const centerHeight = Math.max(6, typeBarTop - centerTop);
|
|
23
|
+
return { width: safeWidth, height: safeHeight, centerWidth, centerLeft, centerTop, centerHeight, typeBarTop, footerTop, compact, tooSmall };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// packages/cli/src/app-opentui/render/graphics.ts
|
|
27
|
+
import { FrameBufferRenderable, RGBA } from "@opentui/core";
|
|
28
|
+
|
|
29
|
+
// packages/cli/src/app-opentui/theme.ts
|
|
30
|
+
import {
|
|
31
|
+
bold as otuiBold,
|
|
32
|
+
dim as otuiDim,
|
|
33
|
+
fg as otuiFg,
|
|
34
|
+
t,
|
|
35
|
+
TextAttributes
|
|
36
|
+
} from "@opentui/core";
|
|
37
|
+
var RIG_UI = {
|
|
38
|
+
bg: "#070809",
|
|
39
|
+
bg2: "#0b0c0e",
|
|
40
|
+
panel: "#101115",
|
|
41
|
+
panel2: "#14161b",
|
|
42
|
+
glass: "#1e2230",
|
|
43
|
+
border: "#2a2e3a",
|
|
44
|
+
ink: "#f4f5f8",
|
|
45
|
+
ink2: "#c7c9d3",
|
|
46
|
+
ink3: "#9aa0ae",
|
|
47
|
+
ink4: "#787b86",
|
|
48
|
+
lime: "#ccff4d",
|
|
49
|
+
limeDim: "#a9d63f",
|
|
50
|
+
cyan: "#56d8ff",
|
|
51
|
+
cyanDim: "#3f9fbd",
|
|
52
|
+
red: "#ff5d5d",
|
|
53
|
+
yellow: "#ffd24d",
|
|
54
|
+
magenta: "#ff79b0"
|
|
55
|
+
};
|
|
56
|
+
var styles = {
|
|
57
|
+
ink: otuiFg(RIG_UI.ink),
|
|
58
|
+
ink2: otuiFg(RIG_UI.ink2),
|
|
59
|
+
ink3: otuiFg(RIG_UI.ink3),
|
|
60
|
+
ink4: otuiFg(RIG_UI.ink4),
|
|
61
|
+
lime: otuiFg(RIG_UI.lime),
|
|
62
|
+
limeDim: otuiFg(RIG_UI.limeDim),
|
|
63
|
+
cyan: otuiFg(RIG_UI.cyan),
|
|
64
|
+
red: otuiFg(RIG_UI.red),
|
|
65
|
+
yellow: otuiFg(RIG_UI.yellow),
|
|
66
|
+
magenta: otuiFg(RIG_UI.magenta)
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// packages/cli/src/app-opentui/render/ascii-fleet.ts
|
|
70
|
+
var LEAD_DRONE = [
|
|
71
|
+
" .-=-. .-=-. ",
|
|
72
|
+
" ( !!! ) ( !!! ) ",
|
|
73
|
+
" '-=-'._ _.'-=-' ",
|
|
74
|
+
" '._ _.' ",
|
|
75
|
+
" '=$$$$$$$=.' ",
|
|
76
|
+
" =$$$$$$$$$$$= ",
|
|
77
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
78
|
+
" $$$@@ @@$$$ ",
|
|
79
|
+
" $$@ ? @$$$ ",
|
|
80
|
+
" $$$@ '-' @$$$ ",
|
|
81
|
+
" $$$@@ @@$$$ ",
|
|
82
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
83
|
+
" =$$$$$$$$$$$= ",
|
|
84
|
+
" '=$$$$$$$=.' ",
|
|
85
|
+
" _.' '._ ",
|
|
86
|
+
" .-=-.' '.-=-. ",
|
|
87
|
+
" ( !!! ) ( !!! ) ",
|
|
88
|
+
" '-=-' '-=-' "
|
|
89
|
+
];
|
|
90
|
+
var MINI_DRONE = [
|
|
91
|
+
"(!!!) (!!!)",
|
|
92
|
+
" \\%==%/ ",
|
|
93
|
+
" %%?%% ",
|
|
94
|
+
" /%==%\\ ",
|
|
95
|
+
"(!!!) (!!!)"
|
|
96
|
+
];
|
|
97
|
+
var ROTORS = ["---", "\\\\\\", "|||", "///"];
|
|
98
|
+
var FLEET_GRID_WIDTH = 52;
|
|
99
|
+
var FLEET_GRID_HEIGHT = 27;
|
|
100
|
+
var FLEET = [
|
|
101
|
+
{ art: MINI_DRONE, x: 0, y: 2, amp: 1, speed: 0.05, phase: 0, dx: 1, driftSpeed: 0.02 },
|
|
102
|
+
{ art: MINI_DRONE, x: 39, y: 2, amp: 1, speed: 0.044, phase: 2.1, dx: 1, driftSpeed: 0.017 },
|
|
103
|
+
{ art: MINI_DRONE, x: 1, y: 20, amp: 1, speed: 0.048, phase: 4.2, dx: 1, driftSpeed: 0.023 },
|
|
104
|
+
{ art: MINI_DRONE, x: 38, y: 20, amp: 1, speed: 0.041, phase: 1.3, dx: 1, driftSpeed: 0.015 },
|
|
105
|
+
{ art: LEAD_DRONE, x: 10, y: 5, amp: 2, speed: 0.04, phase: 0, dx: 0, driftSpeed: 0.011 }
|
|
106
|
+
];
|
|
107
|
+
function fleetRows(tick, options = {}) {
|
|
108
|
+
const animate = options.animate ?? true;
|
|
109
|
+
const t2 = animate ? tick : 0;
|
|
110
|
+
const blade = ROTORS[Math.floor(t2 / 4) % ROTORS.length];
|
|
111
|
+
const pulse = Math.sin(t2 * 0.07);
|
|
112
|
+
const eye = pulse > 0.45 ? "@" : pulse > -0.1 ? "o" : ".";
|
|
113
|
+
const grid = Array.from({ length: FLEET_GRID_HEIGHT }, () => Array.from({ length: FLEET_GRID_WIDTH }, () => " "));
|
|
114
|
+
for (const drone of FLEET) {
|
|
115
|
+
const yOffset = drone.y + Math.round(drone.amp * Math.sin(t2 * drone.speed + drone.phase));
|
|
116
|
+
const xOffset = drone.x + Math.round(drone.dx * Math.sin(t2 * drone.driftSpeed + drone.phase));
|
|
117
|
+
for (let row = 0;row < drone.art.length; row += 1) {
|
|
118
|
+
const source = drone.art[row];
|
|
119
|
+
const targetY = yOffset + row;
|
|
120
|
+
if (targetY < 0 || targetY >= FLEET_GRID_HEIGHT)
|
|
121
|
+
continue;
|
|
122
|
+
for (let col = 0;col < source.length; col += 1) {
|
|
123
|
+
let char = source[col];
|
|
124
|
+
if (char === " ")
|
|
125
|
+
continue;
|
|
126
|
+
const targetX = xOffset + col;
|
|
127
|
+
if (targetX < 0 || targetX >= FLEET_GRID_WIDTH)
|
|
128
|
+
continue;
|
|
129
|
+
if (source.slice(col, col + 3) === "!!!") {
|
|
130
|
+
for (let rotorIndex = 0;rotorIndex < 3; rotorIndex += 1) {
|
|
131
|
+
if (targetX + rotorIndex < FLEET_GRID_WIDTH)
|
|
132
|
+
grid[targetY][targetX + rotorIndex] = blade[rotorIndex];
|
|
133
|
+
}
|
|
134
|
+
col += 2;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (char === "?")
|
|
138
|
+
char = eye;
|
|
139
|
+
grid[targetY][targetX] = char;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return grid.map((row) => row.join("").replace(/\s+$/, ""));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// packages/cli/src/app-opentui/render/panel-layout.ts
|
|
147
|
+
function panelCellRect(layout, panel) {
|
|
148
|
+
const left = Math.max(0, Math.min(layout.width - 1, layout.centerLeft + (panel.left ?? 0)));
|
|
149
|
+
const desiredWidth = panel.width ?? layout.centerWidth;
|
|
150
|
+
const width = Math.max(1, Math.min(layout.width - left, desiredWidth));
|
|
151
|
+
const top = Math.max(0, Math.min(layout.height - 1, layout.centerTop + panel.top));
|
|
152
|
+
const height = Math.max(1, Math.min(layout.height - top, panel.height));
|
|
153
|
+
if (width <= 3 || height <= 3)
|
|
154
|
+
return null;
|
|
155
|
+
const right = left + width - 1;
|
|
156
|
+
const bottom = top + height - 1;
|
|
157
|
+
const headerHeight = panel.chrome === "ad-terminal" ? Math.max(3, Math.min(height - 2, panel.headerHeight ?? 3)) : 0;
|
|
158
|
+
const dividerY = headerHeight ? Math.min(bottom - 1, top + headerHeight) : top;
|
|
159
|
+
return { left, top, width, height, right, bottom, headerHeight, dividerY };
|
|
160
|
+
}
|
|
161
|
+
function panelPixelPlacement(layout, panel, size, minPixels = 8) {
|
|
162
|
+
const cellW = size.width / layout.width;
|
|
163
|
+
const cellH = size.height / layout.height;
|
|
164
|
+
const leftCells = layout.centerLeft + (panel.left ?? 0);
|
|
165
|
+
const topCells = layout.centerTop + panel.top;
|
|
166
|
+
const widthCells = panel.width ?? layout.centerWidth;
|
|
167
|
+
const heightCells = panel.height;
|
|
168
|
+
const left = Math.round(leftCells * cellW);
|
|
169
|
+
const top = Math.round(topCells * cellH);
|
|
170
|
+
const width = Math.round(widthCells * cellW);
|
|
171
|
+
const height = Math.round(heightCells * cellH);
|
|
172
|
+
return width > minPixels && height > minPixels ? { left, top, width, height, leftCells, topCells, widthCells, heightCells } : null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// packages/cli/src/app-opentui/render/constants.ts
|
|
176
|
+
var LCG_MULTIPLIER = 1664525;
|
|
177
|
+
var LCG_INCREMENT = 1013904223;
|
|
178
|
+
var LCG_DIVISOR = 4294967295;
|
|
179
|
+
var PACKET_CYAN_PROBABILITY = 0.22;
|
|
180
|
+
var LANE_INTERP_STEPS = 32;
|
|
181
|
+
var LANE_LEN_BASE = 0.32;
|
|
182
|
+
var LANE_LEN_SPREAD = 0.42;
|
|
183
|
+
var LANE_CURVE_RANGE = 0.7;
|
|
184
|
+
var PACKET_SPEED_BASE = 0.003;
|
|
185
|
+
var PACKET_SPEED_SPREAD = 0.009;
|
|
186
|
+
var DISPATCH_LANES_COMPACT = 7;
|
|
187
|
+
var DISPATCH_LANES_WIDE = 12;
|
|
188
|
+
var DISPATCH_PACKETS_COMPACT = 70;
|
|
189
|
+
var DISPATCH_PACKETS_WIDE = 150;
|
|
190
|
+
var CARRIER_NODES_COMPACT = 5;
|
|
191
|
+
var CARRIER_NODES_WIDE = 7;
|
|
192
|
+
var LOOP_GATES_COMPACT = 4;
|
|
193
|
+
var LOOP_GATES_WIDE = 5;
|
|
194
|
+
var DISPATCH_DRONES_COMPACT = 4;
|
|
195
|
+
var DISPATCH_DRONES_WIDE = 8;
|
|
196
|
+
var CORE_DISPATCH_X = 0.3;
|
|
197
|
+
var CORE_DISPATCH_Y = 0.45;
|
|
198
|
+
var CORE_CARRIER_X = 0.5;
|
|
199
|
+
var CORE_CARRIER_Y = 0.54;
|
|
200
|
+
var CORE_LOOP_X = 0.09;
|
|
201
|
+
var CORE_LOOP_Y = 0.56;
|
|
202
|
+
var RAIL_YS_LOOP = [0.18, 0.5, 0.82];
|
|
203
|
+
var RAIL_YS_CARRIER = [0.24, 0.54, 0.82];
|
|
204
|
+
var RAIL_YS_DISPATCH = [0.18, 0.58, 0.82];
|
|
205
|
+
var GLOW_FALLOFF_EXP_ASCII = 2.2;
|
|
206
|
+
var GLOW_FALLOFF_EXP_IMAGE = 2.4;
|
|
207
|
+
|
|
208
|
+
// packages/cli/src/app-opentui/render/graphics.ts
|
|
209
|
+
var BRAILLE_SAMPLES_X = 2;
|
|
210
|
+
var BRAILLE_SAMPLES_Y = 4;
|
|
211
|
+
var TRANSPARENT = RGBA.fromValues(0, 0, 0, 0);
|
|
212
|
+
var BACKDROP = RGBA.fromHex(RIG_UI.bg);
|
|
213
|
+
var PANEL_BG = RGBA.fromInts(16, 17, 21, 184);
|
|
214
|
+
var PANEL_HEADER_BG = RGBA.fromInts(16, 17, 21, 188);
|
|
215
|
+
var PANEL_LINE = RGBA.fromInts(255, 255, 255, 20);
|
|
216
|
+
var PANEL_LINE_DIM = RGBA.fromInts(255, 255, 255, 8);
|
|
217
|
+
var PANEL_TEXT_DIM = RGBA.fromInts(108, 110, 121, 255);
|
|
218
|
+
var AC_RGB = [204, 255, 77];
|
|
219
|
+
var C2_RGB = [86, 216, 255];
|
|
220
|
+
var MG_RGB = [255, 121, 176];
|
|
221
|
+
var INK_RGB = [108, 110, 121];
|
|
222
|
+
var BRAILLE_BITS = [
|
|
223
|
+
[1, 8],
|
|
224
|
+
[2, 16],
|
|
225
|
+
[4, 32],
|
|
226
|
+
[64, 128]
|
|
227
|
+
];
|
|
228
|
+
function sceneKind(scene) {
|
|
229
|
+
if (scene === "tasks")
|
|
230
|
+
return "loop";
|
|
231
|
+
if (scene === "help")
|
|
232
|
+
return "carrier";
|
|
233
|
+
return "dispatch";
|
|
234
|
+
}
|
|
235
|
+
function seeded(seed) {
|
|
236
|
+
let value = seed >>> 0;
|
|
237
|
+
return () => {
|
|
238
|
+
value = value * LCG_MULTIPLIER + LCG_INCREMENT >>> 0;
|
|
239
|
+
return value / LCG_DIVISOR;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function channelBuffer(canvas, channel) {
|
|
243
|
+
switch (channel) {
|
|
244
|
+
case 0:
|
|
245
|
+
return canvas.ac;
|
|
246
|
+
case 1:
|
|
247
|
+
return canvas.c2;
|
|
248
|
+
case 2:
|
|
249
|
+
return canvas.mg;
|
|
250
|
+
case 3:
|
|
251
|
+
return canvas.ink;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function addSample(canvas, channel, x, y, value) {
|
|
255
|
+
const ix = Math.trunc(x);
|
|
256
|
+
const iy = Math.trunc(y);
|
|
257
|
+
if (ix < 0 || iy < 0 || ix >= canvas.width || iy >= canvas.height)
|
|
258
|
+
return;
|
|
259
|
+
const buffer = channelBuffer(canvas, channel);
|
|
260
|
+
const index = iy * canvas.width + ix;
|
|
261
|
+
buffer[index] = Math.min(1, buffer[index] + value);
|
|
262
|
+
}
|
|
263
|
+
function drawDot(canvas, channel, cx, cy, radius, value) {
|
|
264
|
+
const minX = Math.floor(cx - radius);
|
|
265
|
+
const maxX = Math.ceil(cx + radius);
|
|
266
|
+
const minY = Math.floor(cy - radius);
|
|
267
|
+
const maxY = Math.ceil(cy + radius);
|
|
268
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
269
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
270
|
+
const dx = x - cx;
|
|
271
|
+
const dy = y - cy;
|
|
272
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
273
|
+
if (distance > radius)
|
|
274
|
+
continue;
|
|
275
|
+
const falloff = 1 - distance / Math.max(0.001, radius);
|
|
276
|
+
addSample(canvas, channel, x, y, value * (0.28 + falloff * 0.72));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function drawGlow(canvas, channel, cx, cy, radius, value) {
|
|
281
|
+
const minX = Math.floor(cx - radius);
|
|
282
|
+
const maxX = Math.ceil(cx + radius);
|
|
283
|
+
const minY = Math.floor(cy - radius);
|
|
284
|
+
const maxY = Math.ceil(cy + radius);
|
|
285
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
286
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
287
|
+
const dx = x - cx;
|
|
288
|
+
const dy = y - cy;
|
|
289
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
290
|
+
if (distance > radius)
|
|
291
|
+
continue;
|
|
292
|
+
const falloff = Math.pow(1 - distance / Math.max(0.001, radius), GLOW_FALLOFF_EXP_ASCII);
|
|
293
|
+
addSample(canvas, channel, x, y, value * falloff);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function drawLine(canvas, channel, x0, y0, x1, y1, value, width = 0.8) {
|
|
298
|
+
const dx = x1 - x0;
|
|
299
|
+
const dy = y1 - y0;
|
|
300
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(dx, dy) * 1.7));
|
|
301
|
+
for (let step = 0;step <= steps; step += 1) {
|
|
302
|
+
const t2 = step / steps;
|
|
303
|
+
const x = x0 + dx * t2;
|
|
304
|
+
const y = y0 + dy * t2;
|
|
305
|
+
drawDot(canvas, channel, x, y, width, value);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function drawCircleStroke(canvas, channel, cx, cy, radius, value) {
|
|
309
|
+
const steps = Math.max(18, Math.ceil(radius * 8));
|
|
310
|
+
for (let step = 0;step < steps; step += 1) {
|
|
311
|
+
const a = step / steps * Math.PI * 2;
|
|
312
|
+
drawDot(canvas, channel, cx + Math.cos(a) * radius, cy + Math.sin(a) * radius, 0.72, value);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function paletteColor(ac, c2, mg, ink) {
|
|
316
|
+
const total = Math.max(0.001, ac + c2 + mg + ink);
|
|
317
|
+
const r = (AC_RGB[0] * ac + C2_RGB[0] * c2 + MG_RGB[0] * mg + INK_RGB[0] * ink) / total;
|
|
318
|
+
const g = (AC_RGB[1] * ac + C2_RGB[1] * c2 + MG_RGB[1] * mg + INK_RGB[1] * ink) / total;
|
|
319
|
+
const b = (AC_RGB[2] * ac + C2_RGB[2] * c2 + MG_RGB[2] * mg + INK_RGB[2] * ink) / total;
|
|
320
|
+
const intensity = Math.min(1, total / 4);
|
|
321
|
+
const lift = 0.34 + intensity * 0.66;
|
|
322
|
+
return RGBA.fromInts(Math.round(r * lift), Math.round(g * lift), Math.round(b * lift), 255);
|
|
323
|
+
}
|
|
324
|
+
function clearCanvas(canvas) {
|
|
325
|
+
canvas.ac.fill(0);
|
|
326
|
+
canvas.c2.fill(0);
|
|
327
|
+
canvas.mg.fill(0);
|
|
328
|
+
canvas.ink.fill(0);
|
|
329
|
+
}
|
|
330
|
+
function makeCanvas(layout) {
|
|
331
|
+
const width = Math.max(1, layout.width * BRAILLE_SAMPLES_X);
|
|
332
|
+
const height = Math.max(1, layout.height * BRAILLE_SAMPLES_Y);
|
|
333
|
+
const size = width * height;
|
|
334
|
+
return {
|
|
335
|
+
width,
|
|
336
|
+
height,
|
|
337
|
+
ac: new Float32Array(size),
|
|
338
|
+
c2: new Float32Array(size),
|
|
339
|
+
mg: new Float32Array(size),
|
|
340
|
+
ink: new Float32Array(size)
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
class MarketingGlyphCanvas {
|
|
345
|
+
rand = seeded(6221137);
|
|
346
|
+
canvas;
|
|
347
|
+
layout;
|
|
348
|
+
activeKind = null;
|
|
349
|
+
lanes = [];
|
|
350
|
+
motes = [];
|
|
351
|
+
packets = [];
|
|
352
|
+
constructor(layout) {
|
|
353
|
+
this.layout = layout;
|
|
354
|
+
this.canvas = makeCanvas(layout);
|
|
355
|
+
this.reset("dispatch");
|
|
356
|
+
}
|
|
357
|
+
resize(layout) {
|
|
358
|
+
if (layout.width === this.layout.width && layout.height === this.layout.height)
|
|
359
|
+
return;
|
|
360
|
+
this.layout = layout;
|
|
361
|
+
this.canvas = makeCanvas(layout);
|
|
362
|
+
this.reset(this.activeKind ?? "dispatch");
|
|
363
|
+
}
|
|
364
|
+
render(layer, scene, tick) {
|
|
365
|
+
const kind = sceneKind(scene);
|
|
366
|
+
if (kind !== this.activeKind)
|
|
367
|
+
this.reset(kind);
|
|
368
|
+
clearCanvas(this.canvas);
|
|
369
|
+
this.drawMarketingRails(kind, tick);
|
|
370
|
+
if (kind === "loop")
|
|
371
|
+
this.drawLoop(tick);
|
|
372
|
+
else if (kind === "carrier")
|
|
373
|
+
this.drawCarrier(tick);
|
|
374
|
+
else
|
|
375
|
+
this.drawDispatch(tick);
|
|
376
|
+
this.blit(layer);
|
|
377
|
+
}
|
|
378
|
+
reset(kind) {
|
|
379
|
+
this.activeKind = kind;
|
|
380
|
+
this.lanes = [];
|
|
381
|
+
this.motes = [];
|
|
382
|
+
this.packets = [];
|
|
383
|
+
if (kind === "dispatch")
|
|
384
|
+
this.setupDispatch();
|
|
385
|
+
else if (kind === "loop")
|
|
386
|
+
this.setupLoop();
|
|
387
|
+
else
|
|
388
|
+
this.setupCarrier();
|
|
389
|
+
}
|
|
390
|
+
setupDispatch() {
|
|
391
|
+
const count = this.layout.compact ? DISPATCH_LANES_COMPACT : DISPATCH_LANES_WIDE;
|
|
392
|
+
for (let i = 0;i < count; i += 1) {
|
|
393
|
+
const ang = (-0.9 + 1.8 * (i / Math.max(1, count - 1))) * (Math.PI * 0.5);
|
|
394
|
+
this.lanes.push({ ang, len: this.canvas.width * (LANE_LEN_BASE + this.rand() * LANE_LEN_SPREAD), curve: (this.rand() - 0.5) * LANE_CURVE_RANGE, phase: this.rand() * Math.PI * 2 });
|
|
395
|
+
}
|
|
396
|
+
const packets = this.layout.compact ? DISPATCH_PACKETS_COMPACT : DISPATCH_PACKETS_WIDE;
|
|
397
|
+
for (let i = 0;i < packets; i += 1)
|
|
398
|
+
this.packets.push(this.packet(true));
|
|
399
|
+
}
|
|
400
|
+
setupLoop() {
|
|
401
|
+
const lanes = this.layout.compact ? 4 : 7;
|
|
402
|
+
for (let i = 0;i < lanes; i += 1)
|
|
403
|
+
this.packets.push(this.packet(true));
|
|
404
|
+
}
|
|
405
|
+
setupCarrier() {
|
|
406
|
+
const nodes = this.layout.compact ? CARRIER_NODES_COMPACT : CARRIER_NODES_WIDE;
|
|
407
|
+
for (let i = 0;i < nodes * 6; i += 1)
|
|
408
|
+
this.packets.push(this.packet(true));
|
|
409
|
+
}
|
|
410
|
+
packet(random = false) {
|
|
411
|
+
return {
|
|
412
|
+
lane: Math.floor(this.rand() * Math.max(1, this.lanes.length || 7)),
|
|
413
|
+
p: random ? this.rand() : 0,
|
|
414
|
+
spd: PACKET_SPEED_BASE + this.rand() * PACKET_SPEED_SPREAD,
|
|
415
|
+
channel: this.rand() < PACKET_CYAN_PROBABILITY ? 1 : 0,
|
|
416
|
+
wobble: (this.rand() - 0.5) * 7,
|
|
417
|
+
size: 0.8 + this.rand() * 1.3
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
core(kind) {
|
|
421
|
+
if (kind === "dispatch")
|
|
422
|
+
return { x: this.canvas.width * CORE_DISPATCH_X, y: this.canvas.height * CORE_DISPATCH_Y };
|
|
423
|
+
if (kind === "carrier")
|
|
424
|
+
return { x: this.canvas.width * CORE_CARRIER_X, y: this.canvas.height * CORE_CARRIER_Y };
|
|
425
|
+
return { x: this.canvas.width * CORE_LOOP_X, y: this.canvas.height * CORE_LOOP_Y };
|
|
426
|
+
}
|
|
427
|
+
lanePoint(lane, p, kind = "dispatch") {
|
|
428
|
+
const core = this.core(kind);
|
|
429
|
+
const dist = lane.len * p;
|
|
430
|
+
const bend = Math.sin(p * Math.PI) * lane.curve * 28;
|
|
431
|
+
const ux = Math.cos(lane.ang);
|
|
432
|
+
const uy = Math.sin(lane.ang);
|
|
433
|
+
return { x: core.x + ux * dist + -uy * bend, y: core.y + uy * dist + ux * bend };
|
|
434
|
+
}
|
|
435
|
+
drawMotes(tick) {
|
|
436
|
+
for (const mote of this.motes) {
|
|
437
|
+
mote.x += 0.1 * mote.z;
|
|
438
|
+
if (mote.x > this.canvas.width + 2)
|
|
439
|
+
mote.x = -2;
|
|
440
|
+
const alpha = (0.035 + 0.08 * mote.z) * (0.55 + 0.45 * Math.sin(tick * 0.03 + mote.tw));
|
|
441
|
+
drawDot(this.canvas, mote.channel, mote.x, mote.y, 0.45 * mote.z, alpha);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
drawMarketingRails(kind, tick) {
|
|
445
|
+
const ys = kind === "loop" ? RAIL_YS_LOOP : kind === "carrier" ? RAIL_YS_CARRIER : RAIL_YS_DISPATCH;
|
|
446
|
+
ys.forEach((ratio, index) => {
|
|
447
|
+
const y = this.canvas.height * ratio + Math.sin(tick * 0.018 + index) * 1.8;
|
|
448
|
+
drawLine(this.canvas, index === 1 ? 0 : 1, this.canvas.width * 0.06, y, this.canvas.width * 0.94, y + Math.sin(index) * 2, index === 1 ? 0.11 : 0.07, 0.55);
|
|
449
|
+
for (let p = (tick * 0.004 + index * 0.21) % 1;p < 1; p += 0.18 + index * 0.02) {
|
|
450
|
+
const x = this.canvas.width * (0.06 + 0.88 * p);
|
|
451
|
+
drawDot(this.canvas, index === 2 ? 1 : 0, x, y, 1 + index * 0.25, 0.24);
|
|
452
|
+
drawGlow(this.canvas, index === 2 ? 1 : 0, x, y, 3.8, 0.035);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
drawDispatch(tick) {
|
|
457
|
+
const core = this.core("dispatch");
|
|
458
|
+
drawGlow(this.canvas, 0, core.x, core.y, 30, 0.12);
|
|
459
|
+
drawDot(this.canvas, 0, core.x, core.y, 2.2, 0.85);
|
|
460
|
+
for (const lane of this.lanes) {
|
|
461
|
+
let prev = this.lanePoint(lane, 0);
|
|
462
|
+
for (let i = 1;i <= LANE_INTERP_STEPS; i += 1) {
|
|
463
|
+
const next = this.lanePoint(lane, i / LANE_INTERP_STEPS);
|
|
464
|
+
drawLine(this.canvas, lane.phase > Math.PI ? 1 : 0, prev.x, prev.y, next.x, next.y, 0.045, 0.38);
|
|
465
|
+
prev = next;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
for (const packet of this.packets) {
|
|
469
|
+
packet.p += packet.spd;
|
|
470
|
+
if (packet.p > 1)
|
|
471
|
+
Object.assign(packet, this.packet(false));
|
|
472
|
+
const lane = this.lanes[packet.lane % Math.max(1, this.lanes.length)];
|
|
473
|
+
if (!lane)
|
|
474
|
+
continue;
|
|
475
|
+
const pt = this.lanePoint(lane, packet.p);
|
|
476
|
+
const fade = packet.p < 0.1 ? packet.p / 0.1 : packet.p > 0.88 ? (1 - packet.p) / 0.12 : 1;
|
|
477
|
+
const y = pt.y + packet.wobble * Math.sin(packet.p * Math.PI * 2);
|
|
478
|
+
drawLine(this.canvas, packet.channel, pt.x - 4, y - 1, pt.x, y, 0.08 * fade, 0.38);
|
|
479
|
+
drawDot(this.canvas, packet.channel, pt.x, y, packet.size, 0.5 * fade);
|
|
480
|
+
drawGlow(this.canvas, packet.channel, pt.x, y, packet.size * 4, 0.045 * fade);
|
|
481
|
+
}
|
|
482
|
+
for (let i = 0;i < (this.layout.compact ? DISPATCH_DRONES_COMPACT : DISPATCH_DRONES_WIDE); i += 1) {
|
|
483
|
+
const lane = this.lanes[i % Math.max(1, this.lanes.length)];
|
|
484
|
+
if (!lane)
|
|
485
|
+
continue;
|
|
486
|
+
const p = (tick * 0.002 + i * 0.13) % 1;
|
|
487
|
+
const pt = this.lanePoint(lane, p);
|
|
488
|
+
this.drawDrone(pt.x, pt.y + Math.sin(tick * 0.04 + i) * 2, 2.6 + i % 2 * 0.6, tick + i * 11, i % 3 === 0 ? 1 : 0);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
drawLoop(tick) {
|
|
492
|
+
const y = this.canvas.height * 0.56;
|
|
493
|
+
const x0 = this.canvas.width * 0.09;
|
|
494
|
+
const x1 = this.canvas.width * 0.91;
|
|
495
|
+
drawLine(this.canvas, 0, x0, y, x1, y, 0.12, 0.55);
|
|
496
|
+
const gates = this.layout.compact ? LOOP_GATES_COMPACT : LOOP_GATES_WIDE;
|
|
497
|
+
const active = Math.floor(tick / 16) % gates;
|
|
498
|
+
for (let i = 0;i < gates; i += 1) {
|
|
499
|
+
const x = x0 + (x1 - x0) * (i / Math.max(1, gates - 1));
|
|
500
|
+
drawLine(this.canvas, i === active ? 0 : 3, x, y - 22, x, y + 22, i === active ? 0.25 : 0.08, i === active ? 0.7 : 0.42);
|
|
501
|
+
drawDot(this.canvas, i <= active ? 0 : 3, x, y, i === active ? 2.2 : 1.2, i === active ? 0.72 : 0.25);
|
|
502
|
+
drawCircleStroke(this.canvas, i <= active ? 0 : 3, x, y, i === active ? 4.2 : 2.4, i === active ? 0.18 : 0.08);
|
|
503
|
+
}
|
|
504
|
+
for (const packet of this.packets) {
|
|
505
|
+
packet.p += packet.spd * 0.7;
|
|
506
|
+
if (packet.p > 1)
|
|
507
|
+
packet.p = 0;
|
|
508
|
+
const x = x0 + (x1 - x0) * packet.p;
|
|
509
|
+
const segment = Math.min(gates - 1, Math.floor(packet.p * gates));
|
|
510
|
+
const channel = segment < active ? 0 : segment === active ? 1 : 3;
|
|
511
|
+
const py = y + packet.wobble * Math.sin(packet.p * Math.PI * 2);
|
|
512
|
+
drawLine(this.canvas, channel, x - 6, py, x, py, 0.1, 0.42);
|
|
513
|
+
drawDot(this.canvas, channel, x, py, packet.size, channel === 3 ? 0.22 : 0.58);
|
|
514
|
+
drawGlow(this.canvas, channel, x, py, 3.8, channel === 3 ? 0.02 : 0.04);
|
|
515
|
+
}
|
|
516
|
+
this.drawDrone(x0 + (x1 - x0) * (tick * 0.003 % 1), y - 18, 2.7, tick, 0);
|
|
517
|
+
this.drawDrone(x0 + (x1 - x0) * ((tick * 0.002 + 0.5) % 1), y + 16, 2.2, tick + 40, 2);
|
|
518
|
+
}
|
|
519
|
+
drawCarrier(tick) {
|
|
520
|
+
const core = this.core("carrier");
|
|
521
|
+
drawGlow(this.canvas, 0, core.x, core.y, 26, 0.12);
|
|
522
|
+
drawDot(this.canvas, 0, core.x, core.y, 2.4, 0.92);
|
|
523
|
+
drawCircleStroke(this.canvas, 0, core.x, core.y, 8 + Math.sin(tick * 0.06) * 2, 0.14);
|
|
524
|
+
const nodes = this.layout.compact ? CARRIER_NODES_COMPACT : CARRIER_NODES_WIDE;
|
|
525
|
+
const rx = this.canvas.width * 0.36;
|
|
526
|
+
const ry = this.canvas.height * 0.22;
|
|
527
|
+
for (let i = 0;i < nodes; i += 1) {
|
|
528
|
+
const a = i / nodes * Math.PI * 2 - Math.PI / 2 + tick * 0.006;
|
|
529
|
+
const x = core.x + Math.cos(a) * rx;
|
|
530
|
+
const y = core.y + Math.sin(a) * ry;
|
|
531
|
+
drawLine(this.canvas, i % 2 ? 1 : 0, core.x, core.y, x, y, 0.055, 0.36);
|
|
532
|
+
drawCircleStroke(this.canvas, i % 2 ? 1 : 0, x, y, 4.2, 0.15);
|
|
533
|
+
drawDot(this.canvas, i % 2 ? 1 : 0, x, y, 1.7, 0.62);
|
|
534
|
+
this.drawDrone(x, y - 8, 2.1, tick + i * 9, i % 2 ? 1 : 0);
|
|
535
|
+
}
|
|
536
|
+
for (const packet of this.packets) {
|
|
537
|
+
packet.p += packet.spd;
|
|
538
|
+
if (packet.p > 1)
|
|
539
|
+
packet.p = 0;
|
|
540
|
+
const lane = packet.lane % nodes;
|
|
541
|
+
const a = lane / nodes * Math.PI * 2 - Math.PI / 2 + tick * 0.006;
|
|
542
|
+
const nx = core.x + Math.cos(a) * rx;
|
|
543
|
+
const ny = core.y + Math.sin(a) * ry;
|
|
544
|
+
const x = core.x + (nx - core.x) * packet.p;
|
|
545
|
+
const y = core.y + (ny - core.y) * packet.p;
|
|
546
|
+
drawDot(this.canvas, packet.channel, x, y, packet.size, 0.48);
|
|
547
|
+
drawGlow(this.canvas, packet.channel, x, y, 3.2, 0.035);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
drawDrone(x, y, scale, tick, channel) {
|
|
551
|
+
const wobble = Math.sin(tick * 0.08) * 0.7;
|
|
552
|
+
drawDot(this.canvas, channel, x, y + wobble, scale, 0.58);
|
|
553
|
+
drawDot(this.canvas, 3, x, y + wobble, Math.max(0.6, scale * 0.28), 0.42);
|
|
554
|
+
const rotor = scale * 1.75;
|
|
555
|
+
const arms = [
|
|
556
|
+
[-rotor, -rotor * 0.75],
|
|
557
|
+
[rotor, -rotor * 0.75],
|
|
558
|
+
[-rotor, rotor * 0.75],
|
|
559
|
+
[rotor, rotor * 0.75]
|
|
560
|
+
];
|
|
561
|
+
for (const [dx, dy] of arms) {
|
|
562
|
+
drawLine(this.canvas, channel, x, y + wobble, x + dx, y + dy + wobble, 0.11, 0.38);
|
|
563
|
+
drawCircleStroke(this.canvas, channel, x + dx, y + dy + wobble, scale * (0.65 + Math.abs(Math.sin(tick * 0.18)) * 0.25), 0.16);
|
|
564
|
+
drawDot(this.canvas, channel, x + dx, y + dy + wobble, 0.7, 0.25);
|
|
565
|
+
}
|
|
566
|
+
drawLine(this.canvas, channel === 1 ? 0 : 1, x - rotor * 2.4, y + wobble + 1.2, x - rotor * 1.2, y + wobble, 0.05, 0.35);
|
|
567
|
+
}
|
|
568
|
+
blit(layer) {
|
|
569
|
+
const fb = layer.frameBuffer;
|
|
570
|
+
fb.clear(BACKDROP);
|
|
571
|
+
const { width, height, ac, c2, mg, ink } = this.canvas;
|
|
572
|
+
for (let cy = 0;cy < this.layout.height; cy += 1) {
|
|
573
|
+
for (let cx = 0;cx < this.layout.width; cx += 1) {
|
|
574
|
+
let bits = 0;
|
|
575
|
+
let acSum = 0;
|
|
576
|
+
let c2Sum = 0;
|
|
577
|
+
let mgSum = 0;
|
|
578
|
+
let inkSum = 0;
|
|
579
|
+
for (let sy = 0;sy < BRAILLE_SAMPLES_Y; sy += 1) {
|
|
580
|
+
for (let sx = 0;sx < BRAILLE_SAMPLES_X; sx += 1) {
|
|
581
|
+
const px = cx * BRAILLE_SAMPLES_X + sx;
|
|
582
|
+
const py = cy * BRAILLE_SAMPLES_Y + sy;
|
|
583
|
+
if (px >= width || py >= height)
|
|
584
|
+
continue;
|
|
585
|
+
const index = py * width + px;
|
|
586
|
+
const a = ac[index];
|
|
587
|
+
const c = c2[index];
|
|
588
|
+
const m = mg[index];
|
|
589
|
+
const k = ink[index];
|
|
590
|
+
const total2 = a + c + m + k;
|
|
591
|
+
acSum += a;
|
|
592
|
+
c2Sum += c;
|
|
593
|
+
mgSum += m;
|
|
594
|
+
inkSum += k;
|
|
595
|
+
if (total2 > 0.11)
|
|
596
|
+
bits |= BRAILLE_BITS[sy][sx];
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const total = acSum + c2Sum + mgSum + inkSum;
|
|
600
|
+
if (bits === 0 || total <= 0.02)
|
|
601
|
+
continue;
|
|
602
|
+
const char = String.fromCharCode(10240 + bits);
|
|
603
|
+
fb.setCellWithAlphaBlending(cx, cy, char, paletteColor(acSum, c2Sum, mgSum, inkSum), TRANSPARENT);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function createGraphicsLayer(renderer, layout) {
|
|
609
|
+
const layer = new FrameBufferRenderable(renderer, {
|
|
610
|
+
id: "rig-marketing-glyph-canvas",
|
|
611
|
+
width: layout.width,
|
|
612
|
+
height: layout.height,
|
|
613
|
+
position: "absolute",
|
|
614
|
+
left: 0,
|
|
615
|
+
top: 0,
|
|
616
|
+
respectAlpha: true
|
|
617
|
+
});
|
|
618
|
+
layer.__rigMarketingCanvas = new MarketingGlyphCanvas(layout);
|
|
619
|
+
return layer;
|
|
620
|
+
}
|
|
621
|
+
function resizeGraphicsLayer(layer, layout) {
|
|
622
|
+
if (layer.width !== layout.width)
|
|
623
|
+
layer.width = layout.width;
|
|
624
|
+
if (layer.height !== layout.height)
|
|
625
|
+
layer.height = layout.height;
|
|
626
|
+
layer.__rigMarketingCanvas?.resize(layout);
|
|
627
|
+
}
|
|
628
|
+
function clearGraphicsLayer(layer) {
|
|
629
|
+
layer.frameBuffer.clear(BACKDROP);
|
|
630
|
+
layer.__rigAmbientKey = undefined;
|
|
631
|
+
}
|
|
632
|
+
function writeCell(layer, x, y, char, fg, bg) {
|
|
633
|
+
layer.frameBuffer.setCellWithAlphaBlending(x, y, char, fg, bg);
|
|
634
|
+
}
|
|
635
|
+
function drawFullCell(layer, x, y, bg) {
|
|
636
|
+
writeCell(layer, x, y, " ", TRANSPARENT, bg);
|
|
637
|
+
}
|
|
638
|
+
function drawCornerCut(layer, x, y, char, fg) {
|
|
639
|
+
writeCell(layer, x, y, char, fg, BACKDROP);
|
|
640
|
+
}
|
|
641
|
+
function drawRoundedFill(layer, left, top, right, bottom, dividerY) {
|
|
642
|
+
const bgForY = (y) => y < dividerY ? PANEL_HEADER_BG : PANEL_BG;
|
|
643
|
+
for (let y = top;y <= bottom; y += 1) {
|
|
644
|
+
const bg = bgForY(y);
|
|
645
|
+
for (let x = left;x <= right; x += 1)
|
|
646
|
+
drawFullCell(layer, x, y, bg);
|
|
647
|
+
}
|
|
648
|
+
drawCornerCut(layer, left, top, "\u2597", PANEL_HEADER_BG);
|
|
649
|
+
drawCornerCut(layer, right, top, "\u2596", PANEL_HEADER_BG);
|
|
650
|
+
drawCornerCut(layer, left, bottom, "\u259D", PANEL_BG);
|
|
651
|
+
drawCornerCut(layer, right, bottom, "\u2598", PANEL_BG);
|
|
652
|
+
}
|
|
653
|
+
function drawAdTerminalPanel(layer, layout, panel) {
|
|
654
|
+
const rect = panelCellRect(layout, panel);
|
|
655
|
+
if (!rect)
|
|
656
|
+
return;
|
|
657
|
+
const { left, top, width, right, bottom, headerHeight, dividerY } = rect;
|
|
658
|
+
drawRoundedFill(layer, left, top, right, bottom, dividerY);
|
|
659
|
+
if (dividerY > top && dividerY < bottom) {
|
|
660
|
+
for (let x = left + 2;x < right - 1; x += 1) {
|
|
661
|
+
writeCell(layer, x, dividerY, "\u2500", PANEL_LINE_DIM, PANEL_BG);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (panel.headerText) {
|
|
665
|
+
const x = left + Math.max(2, Math.min(5, panel.paddingX ?? 4));
|
|
666
|
+
const y = top + Math.max(1, Math.floor(headerHeight / 2));
|
|
667
|
+
layer.frameBuffer.drawText(panel.headerText.slice(0, Math.max(0, width - 8)), x, y, PANEL_TEXT_DIM, TRANSPARENT);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
function drawPanelChrome(layer, layout, panels) {
|
|
671
|
+
for (const panel of panels) {
|
|
672
|
+
if (panel.chrome === "ad-terminal")
|
|
673
|
+
drawAdTerminalPanel(layer, layout, panel);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function staticFleetTick(scene) {
|
|
677
|
+
let hash = 0;
|
|
678
|
+
for (let index = 0;index < scene.length; index += 1)
|
|
679
|
+
hash = hash * 33 + scene.charCodeAt(index) >>> 0;
|
|
680
|
+
return 11 + hash % 97;
|
|
681
|
+
}
|
|
682
|
+
function withAlpha(hex, alpha) {
|
|
683
|
+
const a = Math.max(0, Math.min(255, Math.round(alpha * 255)));
|
|
684
|
+
const [r, g, b] = RGBA.fromHex(hex).toInts();
|
|
685
|
+
return RGBA.fromInts(r, g, b, a);
|
|
686
|
+
}
|
|
687
|
+
function asciiFleetColor(char, row, alpha) {
|
|
688
|
+
if (char === "@" || char === "$" || char === "o")
|
|
689
|
+
return withAlpha(RIG_UI.lime, alpha);
|
|
690
|
+
if (char === "%" || char === "!" || char === "/" || char === "\\" || char === "|")
|
|
691
|
+
return withAlpha(RIG_UI.cyan, alpha);
|
|
692
|
+
if (char === "." || char === "'" || char === "_" || row < 3 || row > FLEET_GRID_HEIGHT - 4) {
|
|
693
|
+
return RGBA.fromInts(108, 110, 121, Math.min(170, Math.max(0, Math.min(255, Math.round(alpha * 255)))));
|
|
694
|
+
}
|
|
695
|
+
return withAlpha(RIG_UI.limeDim, alpha);
|
|
696
|
+
}
|
|
697
|
+
var AMBIENT_LOAD_BUCKETS = 5;
|
|
698
|
+
function ambientLoadBucket(load) {
|
|
699
|
+
if (!Number.isFinite(load))
|
|
700
|
+
return 0;
|
|
701
|
+
return Math.max(0, Math.min(AMBIENT_LOAD_BUCKETS, Math.round(load * AMBIENT_LOAD_BUCKETS)));
|
|
702
|
+
}
|
|
703
|
+
function drawAmbientField(layer, layout, _tick, scene = "fleet", load = 0, activeRuns = 0) {
|
|
704
|
+
const bucket = ambientLoadBucket(load);
|
|
705
|
+
const rows = fleetRows(staticFleetTick(scene), { animate: true });
|
|
706
|
+
let droneTotal = 0;
|
|
707
|
+
for (const line of rows)
|
|
708
|
+
for (const char of line)
|
|
709
|
+
if (char === "@" || char === "$" || char === "%")
|
|
710
|
+
droneTotal += 1;
|
|
711
|
+
const litTarget = Math.max(0, Math.min(droneTotal, Math.floor(activeRuns)));
|
|
712
|
+
const key = `${layout.width}x${layout.height}|${scene}|l${bucket}|d${litTarget}`;
|
|
713
|
+
if (layer.__rigAmbientKey === key)
|
|
714
|
+
return;
|
|
715
|
+
const fb = layer.frameBuffer;
|
|
716
|
+
fb.clear(BACKDROP);
|
|
717
|
+
const left = Math.floor((layout.width - FLEET_GRID_WIDTH) / 2);
|
|
718
|
+
const top = Math.floor((layout.height - FLEET_GRID_HEIGHT) / 2);
|
|
719
|
+
const baseAlpha = 0.62 + bucket / AMBIENT_LOAD_BUCKETS * 0.18;
|
|
720
|
+
let droneIndex = 0;
|
|
721
|
+
for (let row = 0;row < rows.length; row += 1) {
|
|
722
|
+
const y = top + row;
|
|
723
|
+
if (y < 0 || y >= layout.height)
|
|
724
|
+
continue;
|
|
725
|
+
const line = rows[row];
|
|
726
|
+
for (let col = 0;col < line.length; col += 1) {
|
|
727
|
+
const x = left + col;
|
|
728
|
+
if (x < 0 || x >= layout.width)
|
|
729
|
+
continue;
|
|
730
|
+
const char = line[col];
|
|
731
|
+
if (char === " ")
|
|
732
|
+
continue;
|
|
733
|
+
const isDrone = char === "@" || char === "$" || char === "%";
|
|
734
|
+
const lit = isDrone && droneIndex < litTarget;
|
|
735
|
+
if (isDrone)
|
|
736
|
+
droneIndex += 1;
|
|
737
|
+
const alpha = lit ? 1 : baseAlpha;
|
|
738
|
+
fb.setCellWithAlphaBlending(x, y, char, asciiFleetColor(char, row, alpha), TRANSPARENT);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
layer.__rigAmbientKey = key;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// packages/cli/src/app-opentui/render/image-visual-layer.ts
|
|
745
|
+
import { Worker } from "worker_threads";
|
|
746
|
+
import { deflateSync } from "zlib";
|
|
747
|
+
import { allocateImageId, deleteKittyImage } from "@earendil-works/pi-tui";
|
|
748
|
+
|
|
749
|
+
// packages/cli/src/app-opentui/terminal-capabilities.ts
|
|
750
|
+
import { getCapabilities } from "@earendil-works/pi-tui";
|
|
751
|
+
function getRigTerminalCapabilities() {
|
|
752
|
+
const imageProtocol = getCapabilities().images;
|
|
753
|
+
const supportsKittyImages = imageProtocol === "kitty";
|
|
754
|
+
return {
|
|
755
|
+
imageProtocol,
|
|
756
|
+
supportsKittyImages,
|
|
757
|
+
visualMode: supportsKittyImages ? "kitty-images" : "framebuffer-fallback"
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// packages/cli/src/app-opentui/render/image-visual-layer.ts
|
|
762
|
+
var PANEL_MASK_RADIUS_MIN = 14;
|
|
763
|
+
var PANEL_MASK_RADIUS_MAX = 34;
|
|
764
|
+
var PANEL_MASK_RADIUS_FACTOR = 0.035;
|
|
765
|
+
var PANEL_BLUR_RADIUS_MIN = 8;
|
|
766
|
+
var PANEL_BLUR_RADIUS_MAX = 28;
|
|
767
|
+
var PANEL_BLUR_RADIUS_FACTOR = 0.018;
|
|
768
|
+
var BG = [7, 8, 9, 255];
|
|
769
|
+
var PANEL = [16, 17, 21, 184];
|
|
770
|
+
var PANEL_HEADER = [16, 17, 21, 190];
|
|
771
|
+
var PANEL_LINE2 = [255, 255, 255, 24];
|
|
772
|
+
var LIME = [204, 255, 77, 255];
|
|
773
|
+
var LIME_DIM = [169, 214, 63, 255];
|
|
774
|
+
var CYAN = [86, 216, 255, 255];
|
|
775
|
+
var MAGENTA = [255, 121, 176, 255];
|
|
776
|
+
var INK_DIM = [108, 110, 121, 255];
|
|
777
|
+
var PNG_SIGNATURE = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
778
|
+
var CRC_TABLE = makeCrcTable();
|
|
779
|
+
var MAX_IMAGE_BYTES = 48 * 1024 * 1024;
|
|
780
|
+
var KITTY_CHUNK_SIZE = 4096;
|
|
781
|
+
var PANEL_BLUR_SCALE = 1;
|
|
782
|
+
var PANEL_MASK_CACHE_LIMIT = 16;
|
|
783
|
+
var ZLIB_LEVEL = 1;
|
|
784
|
+
var DEFAULT_IMAGE_RESOLUTION_SCALE = 1;
|
|
785
|
+
var LOAD_BUCKETS = 5;
|
|
786
|
+
function loadBucket(load) {
|
|
787
|
+
if (!Number.isFinite(load ?? NaN))
|
|
788
|
+
return 0;
|
|
789
|
+
return Math.max(0, Math.min(LOAD_BUCKETS, Math.round((load ?? 0) * LOAD_BUCKETS)));
|
|
790
|
+
}
|
|
791
|
+
var panelMaskCache = new Map;
|
|
792
|
+
var BG_WORD = rgbaWord(BG);
|
|
793
|
+
function imageTransport() {
|
|
794
|
+
const forced = process.env.RIG_OPENTUI_IMAGE_TRANSPORT;
|
|
795
|
+
if (forced === "rgba-zlib")
|
|
796
|
+
return "rgba-zlib";
|
|
797
|
+
return "png";
|
|
798
|
+
}
|
|
799
|
+
function imageResolutionScale() {
|
|
800
|
+
const raw = Number.parseFloat(process.env.RIG_OPENTUI_IMAGE_SCALE ?? "");
|
|
801
|
+
if (Number.isFinite(raw) && raw > 0)
|
|
802
|
+
return Math.max(0.25, Math.min(1, raw));
|
|
803
|
+
return DEFAULT_IMAGE_RESOLUTION_SCALE;
|
|
804
|
+
}
|
|
805
|
+
function rgbaWord(color) {
|
|
806
|
+
return (color[3] << 24 | color[2] << 16 | color[1] << 8 | color[0]) >>> 0;
|
|
807
|
+
}
|
|
808
|
+
function fillRgba(data, color, word = rgbaWord(color)) {
|
|
809
|
+
if (data.byteOffset % 4 === 0 && data.byteLength % 4 === 0) {
|
|
810
|
+
new Uint32Array(data.buffer, data.byteOffset, data.byteLength / 4).fill(word);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
for (let i = 0;i < data.length; i += 4) {
|
|
814
|
+
data[i] = color[0];
|
|
815
|
+
data[i + 1] = color[1];
|
|
816
|
+
data[i + 2] = color[2];
|
|
817
|
+
data[i + 3] = color[3];
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
var ASCII_GLYPHS = {
|
|
821
|
+
".": ["00000", "00000", "00000", "00000", "00000", "00100", "00100"],
|
|
822
|
+
"'": ["00100", "00100", "00000", "00000", "00000", "00000", "00000"],
|
|
823
|
+
"-": ["00000", "00000", "00000", "11111", "00000", "00000", "00000"],
|
|
824
|
+
_: ["00000", "00000", "00000", "00000", "00000", "00000", "11111"],
|
|
825
|
+
"=": ["00000", "11111", "00000", "00000", "11111", "00000", "00000"],
|
|
826
|
+
"|": ["00100", "00100", "00100", "00100", "00100", "00100", "00100"],
|
|
827
|
+
"/": ["00001", "00010", "00010", "00100", "01000", "01000", "10000"],
|
|
828
|
+
"\\": ["10000", "01000", "01000", "00100", "00010", "00010", "00001"],
|
|
829
|
+
"(": ["00010", "00100", "01000", "01000", "01000", "00100", "00010"],
|
|
830
|
+
")": ["01000", "00100", "00010", "00010", "00010", "00100", "01000"],
|
|
831
|
+
"!": ["00100", "00100", "00100", "00100", "00100", "00000", "00100"],
|
|
832
|
+
"%": ["11001", "11010", "00100", "01000", "10110", "00110", "00000"],
|
|
833
|
+
$: ["00100", "11110", "10100", "11110", "00101", "11110", "00100"],
|
|
834
|
+
"@": ["01110", "10001", "10111", "10101", "10111", "10000", "01111"],
|
|
835
|
+
o: ["00000", "01110", "10001", "10001", "10001", "01110", "00000"],
|
|
836
|
+
"*": ["00100", "10101", "01110", "11111", "01110", "10101", "00100"]
|
|
837
|
+
};
|
|
838
|
+
function sceneStaticTick(scene) {
|
|
839
|
+
let hash = 0;
|
|
840
|
+
for (let index = 0;index < scene.length; index += 1)
|
|
841
|
+
hash = hash * 33 + scene.charCodeAt(index) >>> 0;
|
|
842
|
+
return 11 + hash % 97;
|
|
843
|
+
}
|
|
844
|
+
function charColor(char, row, totalRows) {
|
|
845
|
+
if (char === "@" || char === "$" || char === "o")
|
|
846
|
+
return LIME;
|
|
847
|
+
if (char === "%" || char === "!" || char === "/" || char === "\\" || char === "|")
|
|
848
|
+
return CYAN;
|
|
849
|
+
if (char === "." || char === "'" || char === "_" || row < 3 || row > totalRows - 4)
|
|
850
|
+
return INK_DIM;
|
|
851
|
+
if (char === "-" || char === "=" || char === "(" || char === ")")
|
|
852
|
+
return LIME_DIM;
|
|
853
|
+
return MAGENTA;
|
|
854
|
+
}
|
|
855
|
+
function fillRectAlpha(data, width, height, left, top, rectWidth, rectHeight, color, alpha) {
|
|
856
|
+
const x0 = Math.max(0, Math.floor(left));
|
|
857
|
+
const y0 = Math.max(0, Math.floor(top));
|
|
858
|
+
const x1 = Math.min(width, Math.ceil(left + rectWidth));
|
|
859
|
+
const y1 = Math.min(height, Math.ceil(top + rectHeight));
|
|
860
|
+
for (let y = y0;y < y1; y += 1) {
|
|
861
|
+
for (let x = x0;x < x1; x += 1)
|
|
862
|
+
blendOver(data, (y * width + x) * 4, color, alpha);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function drawAsciiGlyph(data, width, height, x, y, cellWidth, cellHeight, char, color, alpha) {
|
|
866
|
+
const pattern = ASCII_GLYPHS[char] ?? ASCII_GLYPHS["*"];
|
|
867
|
+
const glyphWidth = Math.max(1, cellWidth * 0.56);
|
|
868
|
+
const glyphHeight = Math.max(1, cellHeight * 0.7);
|
|
869
|
+
const originX = x + (cellWidth - glyphWidth) * 0.5;
|
|
870
|
+
const originY = y + (cellHeight - glyphHeight) * 0.5;
|
|
871
|
+
const pixelWidth = Math.max(1, glyphWidth / pattern[0].length);
|
|
872
|
+
const pixelHeight = Math.max(1, glyphHeight / pattern.length);
|
|
873
|
+
for (let row = 0;row < pattern.length; row += 1) {
|
|
874
|
+
const bits = pattern[row];
|
|
875
|
+
for (let col = 0;col < bits.length; col += 1) {
|
|
876
|
+
if (bits[col] !== "1")
|
|
877
|
+
continue;
|
|
878
|
+
fillRectAlpha(data, width, height, originX + col * pixelWidth, originY + row * pixelHeight, pixelWidth * 0.72, pixelHeight * 0.72, color, alpha);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function drawStaticAsciiFleetBackground(data, width, height, scene, layout, load, activeRuns) {
|
|
883
|
+
const rows = fleetRows(sceneStaticTick(scene), { animate: true });
|
|
884
|
+
const cellWidth = width / Math.max(1, layout.width);
|
|
885
|
+
const cellHeight = height / Math.max(1, layout.height);
|
|
886
|
+
const sideBySide = layout.width >= FLEET_GRID_WIDTH * 1.9;
|
|
887
|
+
const leftCells = sideBySide ? Math.max(1, Math.floor(layout.width * 0.3 - FLEET_GRID_WIDTH / 2)) : Math.floor((layout.width - FLEET_GRID_WIDTH) / 2);
|
|
888
|
+
const topCells = Math.floor((layout.height - FLEET_GRID_HEIGHT) / 2);
|
|
889
|
+
const fleetLeft = leftCells * cellWidth;
|
|
890
|
+
const fleetTop = topCells * cellHeight;
|
|
891
|
+
drawGlow2(data, width, height, width * 0.5, height * 0.5, Math.min(width, height) * 0.4, LIME, 0.022 + load * 0.03);
|
|
892
|
+
drawGlow2(data, width, height, width * 0.18, height * 0.22, Math.min(width, height) * 0.28, CYAN, 0.018 + load * 0.012);
|
|
893
|
+
drawGlow2(data, width, height, width * 0.82, height * 0.78, Math.min(width, height) * 0.22, MAGENTA, 0.012 + load * 0.008);
|
|
894
|
+
let droneTotal = 0;
|
|
895
|
+
for (const line of rows)
|
|
896
|
+
for (const char of line)
|
|
897
|
+
if (char === "@" || char === "$" || char === "%")
|
|
898
|
+
droneTotal += 1;
|
|
899
|
+
const litTarget = Math.max(0, Math.min(droneTotal, activeRuns));
|
|
900
|
+
let droneIndex = 0;
|
|
901
|
+
for (let row = 0;row < rows.length; row += 1) {
|
|
902
|
+
const line = rows[row];
|
|
903
|
+
for (let col = 0;col < line.length; col += 1) {
|
|
904
|
+
const char = line[col];
|
|
905
|
+
if (char === " ")
|
|
906
|
+
continue;
|
|
907
|
+
const x = fleetLeft + col * cellWidth;
|
|
908
|
+
const y = fleetTop + row * cellHeight;
|
|
909
|
+
const color = charColor(char, row, rows.length);
|
|
910
|
+
const isDrone = char === "@" || char === "$" || char === "%";
|
|
911
|
+
const lit = isDrone && droneIndex < litTarget;
|
|
912
|
+
drawAsciiGlyph(data, width, height, x + cellWidth * 0.07, y + cellHeight * 0.05, cellWidth, cellHeight, char, color, lit ? 0.72 : 0.46);
|
|
913
|
+
if (isDrone) {
|
|
914
|
+
droneIndex += 1;
|
|
915
|
+
drawGlow2(data, width, height, x + cellWidth * 0.5, y + cellHeight * 0.5, Math.max(cellWidth, cellHeight) * 0.95, color, lit ? 0.044 : 0.014);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function applyStaticAtmosphere(data, width, height, load) {
|
|
921
|
+
const cx = width * 0.5;
|
|
922
|
+
const cy = height * 0.42;
|
|
923
|
+
const radius = Math.max(width, height) * 0.78;
|
|
924
|
+
const minVignette = 0.1 - load * 0.02;
|
|
925
|
+
for (let y = 0;y < height; y += 1) {
|
|
926
|
+
for (let x = 0;x < width; x += 1) {
|
|
927
|
+
const distance = Math.hypot(x - cx, y - cy) / radius;
|
|
928
|
+
const alpha = Math.max(minVignette, Math.min(0.82, 0.12 + Math.pow(distance, 1.65) * 0.62));
|
|
929
|
+
blendOver(data, (y * width + x) * 4, BG, alpha);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
drawGlow2(data, width, height, width * 0.82, height * 0.04, Math.min(width, height) * 0.2, LIME, 0.024 + load * 0.012);
|
|
933
|
+
drawGlow2(data, width, height, width * 0.12, height * 0.18, Math.min(width, height) * 0.16, CYAN, 0.018 + load * 0.008);
|
|
934
|
+
}
|
|
935
|
+
function makeCrcTable() {
|
|
936
|
+
const table = new Uint32Array(256);
|
|
937
|
+
for (let n = 0;n < 256; n += 1) {
|
|
938
|
+
let c = n;
|
|
939
|
+
for (let k = 0;k < 8; k += 1)
|
|
940
|
+
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
941
|
+
table[n] = c >>> 0;
|
|
942
|
+
}
|
|
943
|
+
return table;
|
|
944
|
+
}
|
|
945
|
+
function crc32(bytes) {
|
|
946
|
+
let c = 4294967295;
|
|
947
|
+
for (let i = 0;i < bytes.length; i += 1)
|
|
948
|
+
c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
|
|
949
|
+
return (c ^ 4294967295) >>> 0;
|
|
950
|
+
}
|
|
951
|
+
function chunk(type, data) {
|
|
952
|
+
const out = new Uint8Array(12 + data.length);
|
|
953
|
+
const view = new DataView(out.buffer);
|
|
954
|
+
view.setUint32(0, data.length);
|
|
955
|
+
out[4] = type.charCodeAt(0);
|
|
956
|
+
out[5] = type.charCodeAt(1);
|
|
957
|
+
out[6] = type.charCodeAt(2);
|
|
958
|
+
out[7] = type.charCodeAt(3);
|
|
959
|
+
out.set(data, 8);
|
|
960
|
+
view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
|
961
|
+
return out;
|
|
962
|
+
}
|
|
963
|
+
function encodePng(width, height, rgba) {
|
|
964
|
+
const ihdr = new Uint8Array(13);
|
|
965
|
+
const ihdrView = new DataView(ihdr.buffer);
|
|
966
|
+
ihdrView.setUint32(0, width);
|
|
967
|
+
ihdrView.setUint32(4, height);
|
|
968
|
+
ihdr[8] = 8;
|
|
969
|
+
ihdr[9] = 6;
|
|
970
|
+
ihdr[10] = 0;
|
|
971
|
+
ihdr[11] = 0;
|
|
972
|
+
ihdr[12] = 0;
|
|
973
|
+
const stride = width * 4;
|
|
974
|
+
const raw = new Uint8Array((stride + 1) * height);
|
|
975
|
+
for (let y = 0;y < height; y += 1) {
|
|
976
|
+
const rawOffset = y * (stride + 1);
|
|
977
|
+
raw[rawOffset] = 0;
|
|
978
|
+
raw.set(rgba.subarray(y * stride, y * stride + stride), rawOffset + 1);
|
|
979
|
+
}
|
|
980
|
+
const compressed = deflateSync(raw, { level: ZLIB_LEVEL });
|
|
981
|
+
return Buffer.concat([
|
|
982
|
+
Buffer.from(PNG_SIGNATURE),
|
|
983
|
+
Buffer.from(chunk("IHDR", ihdr)),
|
|
984
|
+
Buffer.from(chunk("IDAT", compressed)),
|
|
985
|
+
Buffer.from(chunk("IEND", new Uint8Array(0)))
|
|
986
|
+
]);
|
|
987
|
+
}
|
|
988
|
+
function kittyImageSequence(base64, options) {
|
|
989
|
+
const params = [`a=T`, `f=${options.format}`, `q=2`, `C=1`, `c=${options.columns}`, `r=${options.rows}`, `i=${options.imageId}`, `z=${options.zIndex}`];
|
|
990
|
+
if (options.format === 32) {
|
|
991
|
+
params.push(`s=${options.pixelWidth ?? 1}`, `v=${options.pixelHeight ?? 1}`);
|
|
992
|
+
if (options.compressed)
|
|
993
|
+
params.push("o=z");
|
|
994
|
+
}
|
|
995
|
+
if (base64.length <= KITTY_CHUNK_SIZE)
|
|
996
|
+
return `\x1B_G${params.join(",")};${base64}\x1B\\`;
|
|
997
|
+
const chunks = [];
|
|
998
|
+
for (let offset = 0;offset < base64.length; offset += KITTY_CHUNK_SIZE) {
|
|
999
|
+
const part = base64.slice(offset, offset + KITTY_CHUNK_SIZE);
|
|
1000
|
+
const last = offset + KITTY_CHUNK_SIZE >= base64.length;
|
|
1001
|
+
chunks.push(`\x1B_G${offset === 0 ? `${params.join(",")},` : ""}m=${last ? 0 : 1};${part}\x1B\\`);
|
|
1002
|
+
}
|
|
1003
|
+
return chunks.join("");
|
|
1004
|
+
}
|
|
1005
|
+
function clampByte(value) {
|
|
1006
|
+
return Math.max(0, Math.min(255, Math.round(value)));
|
|
1007
|
+
}
|
|
1008
|
+
function blendOver(data, index, color, alphaScale = 1) {
|
|
1009
|
+
const alpha = color[3] / 255 * alphaScale;
|
|
1010
|
+
const inv = 1 - alpha;
|
|
1011
|
+
data[index] = clampByte(color[0] * alpha + data[index] * inv);
|
|
1012
|
+
data[index + 1] = clampByte(color[1] * alpha + data[index + 1] * inv);
|
|
1013
|
+
data[index + 2] = clampByte(color[2] * alpha + data[index + 2] * inv);
|
|
1014
|
+
data[index + 3] = 255;
|
|
1015
|
+
}
|
|
1016
|
+
function drawDisc(data, width, height, cx, cy, radius, color, alpha = 1) {
|
|
1017
|
+
const minX = Math.max(0, Math.floor(cx - radius));
|
|
1018
|
+
const maxX = Math.min(width - 1, Math.ceil(cx + radius));
|
|
1019
|
+
const minY = Math.max(0, Math.floor(cy - radius));
|
|
1020
|
+
const maxY = Math.min(height - 1, Math.ceil(cy + radius));
|
|
1021
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
1022
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
1023
|
+
const dx = x + 0.5 - cx;
|
|
1024
|
+
const dy = y + 0.5 - cy;
|
|
1025
|
+
const d = Math.sqrt(dx * dx + dy * dy);
|
|
1026
|
+
if (d > radius)
|
|
1027
|
+
continue;
|
|
1028
|
+
const edge = Math.max(0, Math.min(1, radius - d));
|
|
1029
|
+
blendOver(data, (y * width + x) * 4, color, alpha * Math.min(1, 0.35 + edge));
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function drawGlow2(data, width, height, cx, cy, radius, color, alpha = 0.18) {
|
|
1034
|
+
const minX = Math.max(0, Math.floor(cx - radius));
|
|
1035
|
+
const maxX = Math.min(width - 1, Math.ceil(cx + radius));
|
|
1036
|
+
const minY = Math.max(0, Math.floor(cy - radius));
|
|
1037
|
+
const maxY = Math.min(height - 1, Math.ceil(cy + radius));
|
|
1038
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
1039
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
1040
|
+
const dx = x + 0.5 - cx;
|
|
1041
|
+
const dy = y + 0.5 - cy;
|
|
1042
|
+
const d = Math.sqrt(dx * dx + dy * dy);
|
|
1043
|
+
if (d > radius)
|
|
1044
|
+
continue;
|
|
1045
|
+
const falloff = Math.pow(1 - d / Math.max(1, radius), GLOW_FALLOFF_EXP_IMAGE);
|
|
1046
|
+
blendOver(data, (y * width + x) * 4, color, alpha * falloff);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
function drawLine2(data, width, height, x0, y0, x1, y1, color, alpha = 0.5, thickness = 1.4) {
|
|
1051
|
+
const dx = x1 - x0;
|
|
1052
|
+
const dy = y1 - y0;
|
|
1053
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(dx, dy) * 1.2));
|
|
1054
|
+
for (let i = 0;i <= steps; i += 1) {
|
|
1055
|
+
const t2 = i / steps;
|
|
1056
|
+
drawDisc(data, width, height, x0 + dx * t2, y0 + dy * t2, thickness, color, alpha);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function roundRectAlpha(px, py, x, y, w, h, r) {
|
|
1060
|
+
const rx = Math.max(x + r, Math.min(px, x + w - r));
|
|
1061
|
+
const ry = Math.max(y + r, Math.min(py, y + h - r));
|
|
1062
|
+
const dx = px - rx;
|
|
1063
|
+
const dy = py - ry;
|
|
1064
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
1065
|
+
return Math.max(0, Math.min(1, r + 0.75 - dist));
|
|
1066
|
+
}
|
|
1067
|
+
function panelRect(layout, panel, size) {
|
|
1068
|
+
return panelPixelPlacement(layout, panel, size);
|
|
1069
|
+
}
|
|
1070
|
+
function downsampleRegion(data, canvasW, canvasH, rect, scale) {
|
|
1071
|
+
const w = Math.max(1, Math.ceil(rect.width / scale));
|
|
1072
|
+
const h = Math.max(1, Math.ceil(rect.height / scale));
|
|
1073
|
+
const out = new Uint8ClampedArray(w * h * 3);
|
|
1074
|
+
for (let y = 0;y < h; y += 1) {
|
|
1075
|
+
for (let x = 0;x < w; x += 1) {
|
|
1076
|
+
let r = 0, g = 0, b = 0, count = 0;
|
|
1077
|
+
const sx0 = rect.left + x * scale;
|
|
1078
|
+
const sy0 = rect.top + y * scale;
|
|
1079
|
+
for (let yy = 0;yy < scale; yy += 1) {
|
|
1080
|
+
const sy = sy0 + yy;
|
|
1081
|
+
if (sy < 0 || sy >= canvasH)
|
|
1082
|
+
continue;
|
|
1083
|
+
for (let xx = 0;xx < scale; xx += 1) {
|
|
1084
|
+
const sx = sx0 + xx;
|
|
1085
|
+
if (sx < 0 || sx >= canvasW)
|
|
1086
|
+
continue;
|
|
1087
|
+
const i = (sy * canvasW + sx) * 4;
|
|
1088
|
+
r += data[i];
|
|
1089
|
+
g += data[i + 1];
|
|
1090
|
+
b += data[i + 2];
|
|
1091
|
+
count += 1;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
const oi = (y * w + x) * 3;
|
|
1095
|
+
out[oi] = count ? r / count : BG[0];
|
|
1096
|
+
out[oi + 1] = count ? g / count : BG[1];
|
|
1097
|
+
out[oi + 2] = count ? b / count : BG[2];
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return { pixels: out, width: w, height: h };
|
|
1101
|
+
}
|
|
1102
|
+
function blurRgb(buffer, width, height, radius) {
|
|
1103
|
+
const tmp = new Uint8ClampedArray(buffer.length);
|
|
1104
|
+
const out = new Uint8ClampedArray(buffer.length);
|
|
1105
|
+
const window = radius * 2 + 1;
|
|
1106
|
+
for (let y = 0;y < height; y += 1) {
|
|
1107
|
+
let r = 0, g = 0, b = 0;
|
|
1108
|
+
for (let x = -radius;x <= radius; x += 1) {
|
|
1109
|
+
const sx = Math.max(0, Math.min(width - 1, x));
|
|
1110
|
+
const i = (y * width + sx) * 3;
|
|
1111
|
+
r += buffer[i];
|
|
1112
|
+
g += buffer[i + 1];
|
|
1113
|
+
b += buffer[i + 2];
|
|
1114
|
+
}
|
|
1115
|
+
for (let x = 0;x < width; x += 1) {
|
|
1116
|
+
const oi = (y * width + x) * 3;
|
|
1117
|
+
tmp[oi] = r / window;
|
|
1118
|
+
tmp[oi + 1] = g / window;
|
|
1119
|
+
tmp[oi + 2] = b / window;
|
|
1120
|
+
const removeX = Math.max(0, x - radius);
|
|
1121
|
+
const addX = Math.min(width - 1, x + radius + 1);
|
|
1122
|
+
const ri = (y * width + removeX) * 3;
|
|
1123
|
+
const ai = (y * width + addX) * 3;
|
|
1124
|
+
r += tmp.length ? buffer[ai] - buffer[ri] : 0;
|
|
1125
|
+
g += tmp.length ? buffer[ai + 1] - buffer[ri + 1] : 0;
|
|
1126
|
+
b += tmp.length ? buffer[ai + 2] - buffer[ri + 2] : 0;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
for (let x = 0;x < width; x += 1) {
|
|
1130
|
+
let r = 0, g = 0, b = 0;
|
|
1131
|
+
for (let y = -radius;y <= radius; y += 1) {
|
|
1132
|
+
const sy = Math.max(0, Math.min(height - 1, y));
|
|
1133
|
+
const i = (sy * width + x) * 3;
|
|
1134
|
+
r += tmp[i];
|
|
1135
|
+
g += tmp[i + 1];
|
|
1136
|
+
b += tmp[i + 2];
|
|
1137
|
+
}
|
|
1138
|
+
for (let y = 0;y < height; y += 1) {
|
|
1139
|
+
const oi = (y * width + x) * 3;
|
|
1140
|
+
out[oi] = r / window;
|
|
1141
|
+
out[oi + 1] = g / window;
|
|
1142
|
+
out[oi + 2] = b / window;
|
|
1143
|
+
const removeY = Math.max(0, y - radius);
|
|
1144
|
+
const addY = Math.min(height - 1, y + radius + 1);
|
|
1145
|
+
const ri = (removeY * width + x) * 3;
|
|
1146
|
+
const ai = (addY * width + x) * 3;
|
|
1147
|
+
r += tmp[ai] - tmp[ri];
|
|
1148
|
+
g += tmp[ai + 1] - tmp[ri + 1];
|
|
1149
|
+
b += tmp[ai + 2] - tmp[ri + 2];
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return out;
|
|
1153
|
+
}
|
|
1154
|
+
function panelMaskKey(width, height, rect, headerPx, blurScale) {
|
|
1155
|
+
return `${width}x${height}:${rect.left},${rect.top},${rect.width},${rect.height}:${Math.round(headerPx * 100) / 100}:${blurScale}`;
|
|
1156
|
+
}
|
|
1157
|
+
function getPanelMask(width, height, rect, headerPx, blurScale) {
|
|
1158
|
+
const key = panelMaskKey(width, height, rect, headerPx, blurScale);
|
|
1159
|
+
const cached = panelMaskCache.get(key);
|
|
1160
|
+
if (cached)
|
|
1161
|
+
return cached;
|
|
1162
|
+
const radius = Math.max(PANEL_MASK_RADIUS_MIN, Math.min(PANEL_MASK_RADIUS_MAX, Math.round(Math.min(rect.width, rect.height) * PANEL_MASK_RADIUS_FACTOR)));
|
|
1163
|
+
const sampledWidth = Math.max(1, Math.ceil(rect.width / blurScale));
|
|
1164
|
+
const sampledHeight = Math.max(1, Math.ceil(rect.height / blurScale));
|
|
1165
|
+
const x0 = Math.max(0, rect.left);
|
|
1166
|
+
const y0 = Math.max(0, rect.top);
|
|
1167
|
+
const x1 = Math.min(width - 1, rect.left + rect.width - 1);
|
|
1168
|
+
const y1 = Math.min(height - 1, rect.top + rect.height - 1);
|
|
1169
|
+
const indices = [];
|
|
1170
|
+
const sampleIndices = [];
|
|
1171
|
+
const panelAlpha = [];
|
|
1172
|
+
const edgeAlpha = [];
|
|
1173
|
+
const headerFlags = [];
|
|
1174
|
+
const dividerIndices = [];
|
|
1175
|
+
for (let y = y0;y <= y1; y += 1) {
|
|
1176
|
+
for (let x = x0;x <= x1; x += 1) {
|
|
1177
|
+
const a = roundRectAlpha(x + 0.5, y + 0.5, rect.left, rect.top, rect.width, rect.height, radius);
|
|
1178
|
+
if (a <= 0)
|
|
1179
|
+
continue;
|
|
1180
|
+
const edge = roundRectAlpha(x + 0.5, y + 0.5, rect.left + 1.2, rect.top + 1.2, rect.width - 2.4, rect.height - 2.4, Math.max(1, radius - 1.2));
|
|
1181
|
+
const sx = Math.max(0, Math.min(sampledWidth - 1, Math.floor((x - rect.left) / blurScale)));
|
|
1182
|
+
const sy = Math.max(0, Math.min(sampledHeight - 1, Math.floor((y - rect.top) / blurScale)));
|
|
1183
|
+
indices.push((y * width + x) * 4);
|
|
1184
|
+
sampleIndices.push((sy * sampledWidth + sx) * 3);
|
|
1185
|
+
panelAlpha.push(a);
|
|
1186
|
+
edgeAlpha.push(edge < 0.96 ? Math.min(1, (1 - edge) * 0.7) : 0);
|
|
1187
|
+
headerFlags.push(y < rect.top + headerPx ? 1 : 0);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
const dividerY = Math.round(rect.top + headerPx);
|
|
1191
|
+
if (dividerY > y0 && dividerY < y1) {
|
|
1192
|
+
for (let x = x0 + radius;x <= x1 - radius; x += 1) {
|
|
1193
|
+
dividerIndices.push((dividerY * width + x) * 4);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
const mask = {
|
|
1197
|
+
key,
|
|
1198
|
+
indices: Uint32Array.from(indices),
|
|
1199
|
+
sampleIndices: Uint32Array.from(sampleIndices),
|
|
1200
|
+
panelAlpha: Float32Array.from(panelAlpha),
|
|
1201
|
+
edgeAlpha: Float32Array.from(edgeAlpha),
|
|
1202
|
+
headerFlags: Uint8Array.from(headerFlags),
|
|
1203
|
+
dividerIndices: Uint32Array.from(dividerIndices)
|
|
1204
|
+
};
|
|
1205
|
+
panelMaskCache.set(key, mask);
|
|
1206
|
+
while (panelMaskCache.size > PANEL_MASK_CACHE_LIMIT) {
|
|
1207
|
+
const oldest = panelMaskCache.keys().next().value;
|
|
1208
|
+
if (!oldest)
|
|
1209
|
+
break;
|
|
1210
|
+
panelMaskCache.delete(oldest);
|
|
1211
|
+
}
|
|
1212
|
+
return mask;
|
|
1213
|
+
}
|
|
1214
|
+
function compositePanel(data, width, height, rect, headerPx) {
|
|
1215
|
+
const blurScale = PANEL_BLUR_SCALE;
|
|
1216
|
+
const sampled = downsampleRegion(data, width, height, rect, blurScale);
|
|
1217
|
+
const blurRadius = Math.max(PANEL_BLUR_RADIUS_MIN, Math.min(PANEL_BLUR_RADIUS_MAX, Math.round(Math.min(rect.width, rect.height) * PANEL_BLUR_RADIUS_FACTOR)));
|
|
1218
|
+
const blurred = blurRgb(sampled.pixels, sampled.width, sampled.height, blurRadius);
|
|
1219
|
+
const mask = getPanelMask(width, height, rect, headerPx, blurScale);
|
|
1220
|
+
for (let i = 0;i < mask.indices.length; i += 1) {
|
|
1221
|
+
const idx = mask.indices[i];
|
|
1222
|
+
const sampleIdx = mask.sampleIndices[i];
|
|
1223
|
+
data[idx] = blurred[sampleIdx];
|
|
1224
|
+
data[idx + 1] = blurred[sampleIdx + 1];
|
|
1225
|
+
data[idx + 2] = blurred[sampleIdx + 2];
|
|
1226
|
+
data[idx + 3] = 255;
|
|
1227
|
+
blendOver(data, idx, mask.headerFlags[i] ? PANEL_HEADER : PANEL, mask.panelAlpha[i]);
|
|
1228
|
+
const edge = mask.edgeAlpha[i];
|
|
1229
|
+
if (edge > 0)
|
|
1230
|
+
blendOver(data, idx, PANEL_LINE2, edge);
|
|
1231
|
+
}
|
|
1232
|
+
for (let i = 0;i < mask.dividerIndices.length; i += 1) {
|
|
1233
|
+
blendOver(data, mask.dividerIndices[i], PANEL_LINE2, 0.28);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
var RIG_GLYPH_STROKES = {
|
|
1237
|
+
R: [[0, 0, 0, 1], [0, 0, 0.82, 0], [0.82, 0, 0.82, 0.5], [0, 0.5, 0.82, 0.5], [0.36, 0.5, 0.92, 1]],
|
|
1238
|
+
I: [[0.5, 0, 0.5, 1], [0.18, 0, 0.82, 0], [0.18, 1, 0.82, 1]],
|
|
1239
|
+
G: [[0.92, 0.08, 0.12, 0], [0.12, 0, 0.12, 1], [0.12, 1, 0.92, 1], [0.92, 0.5, 0.92, 1], [0.5, 0.5, 0.92, 0.5]]
|
|
1240
|
+
};
|
|
1241
|
+
function drawBigRigWordmark(data, width, height, layout, load) {
|
|
1242
|
+
const sideBySide = layout.width >= FLEET_GRID_WIDTH * 1.9;
|
|
1243
|
+
if (!sideBySide)
|
|
1244
|
+
return;
|
|
1245
|
+
const letters = "RIG";
|
|
1246
|
+
const min = Math.min(width, height);
|
|
1247
|
+
const glyphH = height * 0.42;
|
|
1248
|
+
const glyphW = width * 0.13;
|
|
1249
|
+
const gap = glyphW * 0.3;
|
|
1250
|
+
const totalW = letters.length * glyphW + (letters.length - 1) * gap;
|
|
1251
|
+
const centerX = width * 0.71;
|
|
1252
|
+
const startX = centerX - totalW / 2;
|
|
1253
|
+
const top = (height - glyphH) / 2;
|
|
1254
|
+
const stroke = Math.max(2, min * 0.013);
|
|
1255
|
+
drawGlow2(data, width, height, centerX, top + glyphH / 2, Math.max(glyphW, glyphH) * 0.9, LIME, 0.022 + load * 0.02);
|
|
1256
|
+
const strokeAlpha = 0.1 + load * 0.06;
|
|
1257
|
+
letters.split("").forEach((letter, index) => {
|
|
1258
|
+
const segments = RIG_GLYPH_STROKES[letter];
|
|
1259
|
+
if (!segments)
|
|
1260
|
+
return;
|
|
1261
|
+
const ox = startX + index * (glyphW + gap);
|
|
1262
|
+
for (const [x0, y0, x1, y1] of segments) {
|
|
1263
|
+
drawLine2(data, width, height, ox + x0 * glyphW, top + y0 * glyphH, ox + x1 * glyphW, top + y1 * glyphH, LIME_DIM, strokeAlpha, stroke);
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
function drawBackground(data, width, height, _tick, scene, layout, load, activeRuns) {
|
|
1268
|
+
fillRgba(data, BG, BG_WORD);
|
|
1269
|
+
drawStaticAsciiFleetBackground(data, width, height, scene, layout, load, activeRuns);
|
|
1270
|
+
drawBigRigWordmark(data, width, height, layout, load);
|
|
1271
|
+
applyStaticAtmosphere(data, width, height, load);
|
|
1272
|
+
}
|
|
1273
|
+
function imageVisualFrameKey(input) {
|
|
1274
|
+
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
1275
|
+
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
1276
|
+
const layer = "layer" in input ? input.layer ?? "full" : "full";
|
|
1277
|
+
const load = loadBucket(input.load);
|
|
1278
|
+
return `${layer}:${width}x${height}:${input.layout.width}x${input.layout.height}:${input.scene}:${input.tick}:l${load}:${input.panels.map((panel) => `${panel.id}:${panel.top}:${panel.height}:${panel.width ?? ""}:${panel.left ?? ""}:${panel.headerHeight ?? ""}`).join("|")}`;
|
|
1279
|
+
}
|
|
1280
|
+
function encodeKittyFrame(width, height, data, input) {
|
|
1281
|
+
if (input.transport === "png") {
|
|
1282
|
+
const png = encodePng(width, height, data);
|
|
1283
|
+
return kittyImageSequence(png.toString("base64"), { columns: input.layout.width, rows: input.layout.height, imageId: input.imageId, zIndex: input.zIndex, format: 100 });
|
|
1284
|
+
}
|
|
1285
|
+
const compressed = deflateSync(data, { level: ZLIB_LEVEL });
|
|
1286
|
+
return kittyImageSequence(compressed.toString("base64"), {
|
|
1287
|
+
columns: input.layout.width,
|
|
1288
|
+
rows: input.layout.height,
|
|
1289
|
+
imageId: input.imageId,
|
|
1290
|
+
zIndex: input.zIndex,
|
|
1291
|
+
format: 32,
|
|
1292
|
+
pixelWidth: width,
|
|
1293
|
+
pixelHeight: height,
|
|
1294
|
+
compressed: true
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
function cropRgba(data, sourceWidth, rect) {
|
|
1298
|
+
const out = new Uint8ClampedArray(rect.width * rect.height * 4);
|
|
1299
|
+
for (let y = 0;y < rect.height; y += 1) {
|
|
1300
|
+
const sourceStart = ((rect.top + y) * sourceWidth + rect.left) * 4;
|
|
1301
|
+
out.set(data.subarray(sourceStart, sourceStart + rect.width * 4), y * rect.width * 4);
|
|
1302
|
+
}
|
|
1303
|
+
return out;
|
|
1304
|
+
}
|
|
1305
|
+
function encodePanelPatch(data, sourceWidth, placement, imageId, zIndex) {
|
|
1306
|
+
const patch = cropRgba(data, sourceWidth, placement);
|
|
1307
|
+
const png = encodePng(placement.width, placement.height, patch);
|
|
1308
|
+
const sequence = kittyImageSequence(png.toString("base64"), {
|
|
1309
|
+
columns: Math.max(1, Math.round(placement.widthCells)),
|
|
1310
|
+
rows: Math.max(1, Math.round(placement.heightCells)),
|
|
1311
|
+
imageId,
|
|
1312
|
+
zIndex,
|
|
1313
|
+
format: 100
|
|
1314
|
+
});
|
|
1315
|
+
return `\x1B[${Math.max(1, Math.round(placement.topCells) + 1)};${Math.max(1, Math.round(placement.leftCells) + 1)}H${sequence}`;
|
|
1316
|
+
}
|
|
1317
|
+
function renderImageVisualFrame(input) {
|
|
1318
|
+
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
1319
|
+
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
1320
|
+
const byteCount = width * height * 4;
|
|
1321
|
+
if (byteCount > MAX_IMAGE_BYTES)
|
|
1322
|
+
return null;
|
|
1323
|
+
const layer = input.layer ?? "full";
|
|
1324
|
+
const data = new Uint8ClampedArray(byteCount);
|
|
1325
|
+
const load = loadBucket(input.load) / LOAD_BUCKETS;
|
|
1326
|
+
const activeRuns = Math.max(0, Math.floor(input.activeRuns ?? 0));
|
|
1327
|
+
drawBackground(data, width, height, 0, input.scene, input.layout, load, activeRuns);
|
|
1328
|
+
if (layer === "split") {
|
|
1329
|
+
const sequences = [encodeKittyFrame(width, height, data, input)];
|
|
1330
|
+
let panelIndex = 0;
|
|
1331
|
+
for (const panel of input.panels) {
|
|
1332
|
+
if (panel.chrome !== "ad-terminal")
|
|
1333
|
+
continue;
|
|
1334
|
+
const placement = panelPixelPlacement(input.layout, panel, { width, height });
|
|
1335
|
+
if (!placement)
|
|
1336
|
+
continue;
|
|
1337
|
+
const cellH = height / input.layout.height;
|
|
1338
|
+
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
1339
|
+
compositePanel(data, width, height, placement, headerPx);
|
|
1340
|
+
const imageId = input.imageIds?.[panelIndex] ?? (input.imageId + 1000 + panelIndex >>> 0 || panelIndex + 1);
|
|
1341
|
+
sequences.push(encodePanelPatch(data, width, placement, imageId, -12));
|
|
1342
|
+
panelIndex += 1;
|
|
1343
|
+
}
|
|
1344
|
+
return { key: imageVisualFrameKey(input), sequence: sequences.join("") };
|
|
1345
|
+
}
|
|
1346
|
+
if (layer === "panel-chrome")
|
|
1347
|
+
return { key: imageVisualFrameKey(input), sequence: "" };
|
|
1348
|
+
if (layer === "background") {
|
|
1349
|
+
return { key: imageVisualFrameKey(input), sequence: encodeKittyFrame(width, height, data, input) };
|
|
1350
|
+
}
|
|
1351
|
+
if (layer === "panel-patches") {
|
|
1352
|
+
const sequences = [];
|
|
1353
|
+
let panelIndex = 0;
|
|
1354
|
+
for (const panel of input.panels) {
|
|
1355
|
+
if (panel.chrome !== "ad-terminal")
|
|
1356
|
+
continue;
|
|
1357
|
+
const placement = panelPixelPlacement(input.layout, panel, { width, height });
|
|
1358
|
+
if (!placement)
|
|
1359
|
+
continue;
|
|
1360
|
+
const cellH = height / input.layout.height;
|
|
1361
|
+
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
1362
|
+
compositePanel(data, width, height, placement, headerPx);
|
|
1363
|
+
const imageId = input.imageIds?.[panelIndex] ?? (input.imageId + 1000 + panelIndex >>> 0 || panelIndex + 1);
|
|
1364
|
+
sequences.push(encodePanelPatch(data, width, placement, imageId, input.zIndex));
|
|
1365
|
+
panelIndex += 1;
|
|
1366
|
+
}
|
|
1367
|
+
return { key: imageVisualFrameKey(input), sequence: sequences.join("") };
|
|
1368
|
+
}
|
|
1369
|
+
for (const panel of input.panels) {
|
|
1370
|
+
if (panel.chrome !== "ad-terminal")
|
|
1371
|
+
continue;
|
|
1372
|
+
const rect = panelRect(input.layout, panel, { width, height });
|
|
1373
|
+
if (!rect)
|
|
1374
|
+
continue;
|
|
1375
|
+
const cellH = height / input.layout.height;
|
|
1376
|
+
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
1377
|
+
compositePanel(data, width, height, rect, headerPx);
|
|
1378
|
+
}
|
|
1379
|
+
return { key: imageVisualFrameKey(input), sequence: encodeKittyFrame(width, height, data, input) };
|
|
1380
|
+
}
|
|
1381
|
+
function shouldRenderImagesInline() {
|
|
1382
|
+
return process.env.RIG_OPENTUI_IMAGE_WORKER === "0" || import.meta.url.includes("$bunfs");
|
|
1383
|
+
}
|
|
1384
|
+
function createImageWorker() {
|
|
1385
|
+
if (shouldRenderImagesInline())
|
|
1386
|
+
return null;
|
|
1387
|
+
const isTypeScriptRuntime = import.meta.url.endsWith(".ts");
|
|
1388
|
+
const workerUrl = new URL(isTypeScriptRuntime ? "./image-visual-layer-worker.ts" : "./image-visual-layer-worker.js", import.meta.url);
|
|
1389
|
+
try {
|
|
1390
|
+
return new Worker(workerUrl);
|
|
1391
|
+
} catch {
|
|
1392
|
+
if (typeof process.versions.bun === "string") {
|
|
1393
|
+
try {
|
|
1394
|
+
return new Worker("./src/app-opentui/render/image-visual-layer-worker.ts");
|
|
1395
|
+
} catch {}
|
|
1396
|
+
}
|
|
1397
|
+
return null;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
var RECENT_WRITTEN_LIMIT = 24;
|
|
1401
|
+
var DEFAULT_IMAGE_OUTPUT_BACKLOG_BYTES = 256 * 1024;
|
|
1402
|
+
var DEFAULT_IMAGE_OUTPUT_BYTES_PER_SECOND = 850 * 1024;
|
|
1403
|
+
function imageOutputBacklogBytes() {
|
|
1404
|
+
const raw = Number.parseInt(process.env.RIG_OPENTUI_IMAGE_BACKLOG_BYTES ?? "", 10);
|
|
1405
|
+
if (Number.isFinite(raw) && raw > 0)
|
|
1406
|
+
return Math.max(64 * 1024, Math.min(2 * 1024 * 1024, raw));
|
|
1407
|
+
return DEFAULT_IMAGE_OUTPUT_BACKLOG_BYTES;
|
|
1408
|
+
}
|
|
1409
|
+
function imageOutputBytesPerSecond() {
|
|
1410
|
+
const raw = Number.parseInt(process.env.RIG_OPENTUI_IMAGE_BYTES_PER_SECOND ?? "", 10);
|
|
1411
|
+
if (Number.isFinite(raw) && raw > 0)
|
|
1412
|
+
return Math.max(128 * 1024, Math.min(2 * 1024 * 1024, raw));
|
|
1413
|
+
return DEFAULT_IMAGE_OUTPUT_BYTES_PER_SECOND;
|
|
1414
|
+
}
|
|
1415
|
+
function pendingLayerKey(key) {
|
|
1416
|
+
return key.split(":", 1)[0] || "full";
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
class ImageVisualLayer {
|
|
1420
|
+
imageId = allocateImageId();
|
|
1421
|
+
panelImageIds = Array.from({ length: 8 }, () => allocateImageId());
|
|
1422
|
+
panelChromeImageIds = Array.from({ length: 8 }, () => allocateImageId());
|
|
1423
|
+
stdout;
|
|
1424
|
+
onFrameReady;
|
|
1425
|
+
protocol;
|
|
1426
|
+
transport = imageTransport();
|
|
1427
|
+
maxOutputBacklogBytes = imageOutputBacklogBytes();
|
|
1428
|
+
outputBytesPerSecond = imageOutputBytesPerSecond();
|
|
1429
|
+
outputBudgetBytes = imageOutputBytesPerSecond();
|
|
1430
|
+
lastBudgetAtMs = Date.now();
|
|
1431
|
+
motionSlot = this.createSlot();
|
|
1432
|
+
workersStarted = false;
|
|
1433
|
+
pendingFrames = new Map;
|
|
1434
|
+
recentWrittenKeys = [];
|
|
1435
|
+
imagesVisible = false;
|
|
1436
|
+
flushPaused = false;
|
|
1437
|
+
requestId = 0;
|
|
1438
|
+
lastBackgroundKey = "";
|
|
1439
|
+
fatalWorkerError = null;
|
|
1440
|
+
destroyed = false;
|
|
1441
|
+
constructor(stdout = process.stdout, onFrameReady) {
|
|
1442
|
+
this.stdout = stdout;
|
|
1443
|
+
this.onFrameReady = onFrameReady;
|
|
1444
|
+
this.protocol = getRigTerminalCapabilities().imageProtocol;
|
|
1445
|
+
}
|
|
1446
|
+
get enabled() {
|
|
1447
|
+
return this.protocol === "kitty";
|
|
1448
|
+
}
|
|
1449
|
+
clear() {
|
|
1450
|
+
if (this.enabled) {
|
|
1451
|
+
if (this.imagesVisible)
|
|
1452
|
+
this.stdout.write([this.imageId, ...this.panelImageIds, ...this.panelChromeImageIds].map((id) => deleteKittyImage(id)).join("") + "\x1B[?25h");
|
|
1453
|
+
this.imagesVisible = false;
|
|
1454
|
+
this.pendingFrames.clear();
|
|
1455
|
+
this.recentWrittenKeys.length = 0;
|
|
1456
|
+
this.resetSlot(this.motionSlot);
|
|
1457
|
+
this.lastBackgroundKey = "";
|
|
1458
|
+
this.outputBudgetBytes = this.outputBytesPerSecond;
|
|
1459
|
+
this.lastBudgetAtMs = Date.now();
|
|
1460
|
+
this.motionSlot.clearedThroughRequestId = this.requestId;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
destroy() {
|
|
1464
|
+
if (this.destroyed)
|
|
1465
|
+
return;
|
|
1466
|
+
this.clear();
|
|
1467
|
+
this.destroyed = true;
|
|
1468
|
+
const workers = [this.motionSlot.worker];
|
|
1469
|
+
this.motionSlot.worker = null;
|
|
1470
|
+
for (const worker of workers)
|
|
1471
|
+
if (worker)
|
|
1472
|
+
worker.terminate().catch(() => {
|
|
1473
|
+
return;
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
setFlushPaused(paused) {
|
|
1477
|
+
this.flushPaused = paused;
|
|
1478
|
+
}
|
|
1479
|
+
isReady(input) {
|
|
1480
|
+
if (!this.enabled || this.destroyed)
|
|
1481
|
+
return true;
|
|
1482
|
+
this.throwIfFatal();
|
|
1483
|
+
const splitKey = imageVisualFrameKey({ ...input, tick: 0, layer: "split" });
|
|
1484
|
+
return this.recentWrittenKeys.includes(splitKey) || Array.from(this.pendingFrames.values()).some((frame) => frame.key === splitKey);
|
|
1485
|
+
}
|
|
1486
|
+
render(input) {
|
|
1487
|
+
if (!this.enabled || this.destroyed)
|
|
1488
|
+
return;
|
|
1489
|
+
this.throwIfFatal();
|
|
1490
|
+
if (this.transport !== "png")
|
|
1491
|
+
this.failWorker("renderer", new Error("OpenTUI image visuals require PNG transport for static-background rendering."));
|
|
1492
|
+
this.ensureWorkersStarted();
|
|
1493
|
+
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
1494
|
+
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
1495
|
+
if (width * height * 4 > MAX_IMAGE_BYTES)
|
|
1496
|
+
return;
|
|
1497
|
+
if (this.isOutputBackedUp())
|
|
1498
|
+
return;
|
|
1499
|
+
this.refillOutputBudget();
|
|
1500
|
+
const splitInput = { ...input, tick: 0, layer: "split" };
|
|
1501
|
+
const splitKey = imageVisualFrameKey(splitInput);
|
|
1502
|
+
if (input.force || splitKey !== this.lastBackgroundKey) {
|
|
1503
|
+
this.scheduleRender(this.motionSlot, splitInput, this.imageId, -30, input.force, this.panelImageIds);
|
|
1504
|
+
this.lastBackgroundKey = splitKey;
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
flush() {
|
|
1508
|
+
this.throwIfFatal();
|
|
1509
|
+
if (this.flushPaused)
|
|
1510
|
+
return false;
|
|
1511
|
+
if (this.pendingFrames.size === 0)
|
|
1512
|
+
return false;
|
|
1513
|
+
this.refillOutputBudget();
|
|
1514
|
+
if (this.isOutputBackedUp()) {
|
|
1515
|
+
const retainedSplit = this.pendingFrames.get("split");
|
|
1516
|
+
this.pendingFrames.clear();
|
|
1517
|
+
if (retainedSplit)
|
|
1518
|
+
this.pendingFrames.set("split", retainedSplit);
|
|
1519
|
+
return false;
|
|
1520
|
+
}
|
|
1521
|
+
const framePriority = (frame) => {
|
|
1522
|
+
const layer = pendingLayerKey(frame.key);
|
|
1523
|
+
if (layer === "split")
|
|
1524
|
+
return 1;
|
|
1525
|
+
return 4;
|
|
1526
|
+
};
|
|
1527
|
+
const frames = Array.from(this.pendingFrames.values()).sort((a, b) => framePriority(a) - framePriority(b));
|
|
1528
|
+
const prefix = "\x1B[?25l\x1B7\x1B[s\x1B[H";
|
|
1529
|
+
const suffix = "\x1B[u\x1B8";
|
|
1530
|
+
const selected = [];
|
|
1531
|
+
const retained = new Map;
|
|
1532
|
+
let sequence = "";
|
|
1533
|
+
let byteLength = Buffer.byteLength(prefix + suffix);
|
|
1534
|
+
for (const frame of frames) {
|
|
1535
|
+
const candidate = sequence + frame.sequence;
|
|
1536
|
+
const candidateBytes = Buffer.byteLength(prefix + candidate + suffix);
|
|
1537
|
+
const layer = pendingLayerKey(frame.key);
|
|
1538
|
+
const allowOneStaticFrame = selected.length === 0 && layer === "split";
|
|
1539
|
+
if (candidateBytes <= this.outputBudgetBytes || allowOneStaticFrame) {
|
|
1540
|
+
selected.push(frame);
|
|
1541
|
+
sequence = candidate;
|
|
1542
|
+
byteLength = candidateBytes;
|
|
1543
|
+
} else if (layer === "split") {
|
|
1544
|
+
retained.set(layer, frame);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
this.pendingFrames.clear();
|
|
1548
|
+
for (const [layer, frame] of retained)
|
|
1549
|
+
this.pendingFrames.set(layer, frame);
|
|
1550
|
+
if (!sequence || selected.length === 0)
|
|
1551
|
+
return false;
|
|
1552
|
+
const payload = `${prefix}${sequence}${suffix}`;
|
|
1553
|
+
for (const frame of selected)
|
|
1554
|
+
this.markWritten(frame.key);
|
|
1555
|
+
this.outputBudgetBytes -= byteLength;
|
|
1556
|
+
this.stdout.cork?.();
|
|
1557
|
+
const accepted = this.stdout.write(payload);
|
|
1558
|
+
this.stdout.uncork?.();
|
|
1559
|
+
this.imagesVisible = true;
|
|
1560
|
+
return accepted;
|
|
1561
|
+
}
|
|
1562
|
+
createSlot() {
|
|
1563
|
+
return { worker: null, busy: false, queuedRequest: null, inFlightKey: "", queuedKey: "", clearedThroughRequestId: 0, latestRequestId: 0 };
|
|
1564
|
+
}
|
|
1565
|
+
resetSlot(slot) {
|
|
1566
|
+
slot.busy = false;
|
|
1567
|
+
slot.queuedRequest = null;
|
|
1568
|
+
slot.inFlightKey = "";
|
|
1569
|
+
slot.queuedKey = "";
|
|
1570
|
+
}
|
|
1571
|
+
markWritten(key) {
|
|
1572
|
+
this.recentWrittenKeys.push(key);
|
|
1573
|
+
while (this.recentWrittenKeys.length > RECENT_WRITTEN_LIMIT)
|
|
1574
|
+
this.recentWrittenKeys.shift();
|
|
1575
|
+
}
|
|
1576
|
+
refillOutputBudget() {
|
|
1577
|
+
const now = Date.now();
|
|
1578
|
+
const elapsedMs = Math.max(0, now - this.lastBudgetAtMs);
|
|
1579
|
+
this.lastBudgetAtMs = now;
|
|
1580
|
+
this.outputBudgetBytes = Math.min(this.outputBytesPerSecond, this.outputBudgetBytes + elapsedMs / 1000 * this.outputBytesPerSecond);
|
|
1581
|
+
}
|
|
1582
|
+
isOutputBackedUp() {
|
|
1583
|
+
return Boolean(this.stdout.writableNeedDrain) || this.stdout.writableLength > this.maxOutputBacklogBytes;
|
|
1584
|
+
}
|
|
1585
|
+
stageFrame(frame) {
|
|
1586
|
+
this.pendingFrames.set(pendingLayerKey(frame.key), frame);
|
|
1587
|
+
}
|
|
1588
|
+
isKnownKey(slot, key) {
|
|
1589
|
+
return this.recentWrittenKeys.includes(key) || Array.from(this.pendingFrames.values()).some((frame) => frame.key === key) || key === slot.inFlightKey || key === slot.queuedKey;
|
|
1590
|
+
}
|
|
1591
|
+
ensureWorkersStarted() {
|
|
1592
|
+
if (this.workersStarted)
|
|
1593
|
+
return;
|
|
1594
|
+
this.workersStarted = true;
|
|
1595
|
+
this.startWorker(this.motionSlot, "static-visuals");
|
|
1596
|
+
}
|
|
1597
|
+
failWorker(name, error) {
|
|
1598
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1599
|
+
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} failed: ${detail}`);
|
|
1600
|
+
throw this.fatalWorkerError;
|
|
1601
|
+
}
|
|
1602
|
+
throwIfFatal() {
|
|
1603
|
+
if (this.fatalWorkerError)
|
|
1604
|
+
throw this.fatalWorkerError;
|
|
1605
|
+
}
|
|
1606
|
+
scheduleRender(slot, input, imageId, zIndex, force, imageIds) {
|
|
1607
|
+
this.throwIfFatal();
|
|
1608
|
+
const key = imageVisualFrameKey(input);
|
|
1609
|
+
if (!force && this.isKnownKey(slot, key))
|
|
1610
|
+
return;
|
|
1611
|
+
const request = {
|
|
1612
|
+
...input,
|
|
1613
|
+
imageId,
|
|
1614
|
+
...imageIds ? { imageIds } : {},
|
|
1615
|
+
zIndex,
|
|
1616
|
+
transport: this.transport,
|
|
1617
|
+
requestId: ++this.requestId,
|
|
1618
|
+
key
|
|
1619
|
+
};
|
|
1620
|
+
slot.latestRequestId = request.requestId;
|
|
1621
|
+
if (!slot.worker) {
|
|
1622
|
+
this.renderInline(slot, request);
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
this.enqueueWorkerRender(slot, request);
|
|
1626
|
+
}
|
|
1627
|
+
startWorker(slot, name) {
|
|
1628
|
+
const worker = createImageWorker();
|
|
1629
|
+
if (!worker)
|
|
1630
|
+
return;
|
|
1631
|
+
slot.worker = worker;
|
|
1632
|
+
worker.on("message", (message) => this.handleWorkerMessage(slot, message));
|
|
1633
|
+
worker.once("error", (error) => {
|
|
1634
|
+
if (!this.destroyed)
|
|
1635
|
+
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1636
|
+
});
|
|
1637
|
+
worker.once("exit", (code) => {
|
|
1638
|
+
if (!this.destroyed)
|
|
1639
|
+
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} exited unexpectedly with code ${code}.`);
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
renderInline(slot, request) {
|
|
1643
|
+
try {
|
|
1644
|
+
const result = renderImageVisualFrame(request);
|
|
1645
|
+
if (result?.sequence && !this.isKnownKey(slot, result.key) && (!this.isOutputBackedUp() || pendingLayerKey(result.key) === "split")) {
|
|
1646
|
+
this.stageFrame({ key: result.key, sequence: result.sequence });
|
|
1647
|
+
this.onFrameReady?.();
|
|
1648
|
+
}
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
this.failWorker(String(request.layer ?? "visual"), error);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
enqueueWorkerRender(slot, request) {
|
|
1654
|
+
this.throwIfFatal();
|
|
1655
|
+
if (slot.busy) {
|
|
1656
|
+
slot.queuedRequest = request;
|
|
1657
|
+
slot.queuedKey = request.key;
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
this.dispatchWorkerRender(slot, request);
|
|
1661
|
+
}
|
|
1662
|
+
dispatchWorkerRender(slot, request) {
|
|
1663
|
+
this.throwIfFatal();
|
|
1664
|
+
if (!slot.worker)
|
|
1665
|
+
this.failWorker(String(request.layer ?? "visual"), new Error("worker is unavailable"));
|
|
1666
|
+
slot.busy = true;
|
|
1667
|
+
slot.inFlightKey = request.key;
|
|
1668
|
+
try {
|
|
1669
|
+
slot.worker.postMessage(request);
|
|
1670
|
+
} catch (error) {
|
|
1671
|
+
this.failWorker(String(request.layer ?? "visual"), error);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
handleWorkerMessage(slot, message) {
|
|
1675
|
+
if (this.destroyed || !message || typeof message !== "object")
|
|
1676
|
+
return;
|
|
1677
|
+
const response = message;
|
|
1678
|
+
slot.busy = false;
|
|
1679
|
+
slot.inFlightKey = "";
|
|
1680
|
+
const isStale = response.requestId <= slot.clearedThroughRequestId || response.requestId < slot.latestRequestId;
|
|
1681
|
+
if (!isStale) {
|
|
1682
|
+
if (response.error)
|
|
1683
|
+
this.failWorker(pendingLayerKey(response.key), new Error(response.error));
|
|
1684
|
+
if (response.sequence && !this.isKnownKey(slot, response.key) && (!this.isOutputBackedUp() || pendingLayerKey(response.key) === "split")) {
|
|
1685
|
+
this.stageFrame({ key: response.key, sequence: response.sequence });
|
|
1686
|
+
this.onFrameReady?.();
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
const next = slot.queuedRequest;
|
|
1690
|
+
slot.queuedRequest = null;
|
|
1691
|
+
slot.queuedKey = "";
|
|
1692
|
+
if (next && !this.isKnownKey(slot, next.key))
|
|
1693
|
+
this.dispatchWorkerRender(slot, next);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
function pixelSizeForRenderer(renderer) {
|
|
1697
|
+
const resolution = renderer.resolution;
|
|
1698
|
+
const base = resolution?.width && resolution?.height ? resolution : { width: renderer.width * 12, height: renderer.height * 24 };
|
|
1699
|
+
const scale = imageResolutionScale();
|
|
1700
|
+
return {
|
|
1701
|
+
width: Math.max(renderer.width, Math.floor(base.width * scale)),
|
|
1702
|
+
height: Math.max(renderer.height, Math.floor(base.height * scale))
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
function forceModernImageVisuals() {
|
|
1706
|
+
return getRigTerminalCapabilities().supportsKittyImages;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// packages/cli/src/app-opentui/fleet-stats.ts
|
|
1710
|
+
var ACTIVE_STATUSES = new Set([
|
|
1711
|
+
"running",
|
|
1712
|
+
"preparing",
|
|
1713
|
+
"created",
|
|
1714
|
+
"validating",
|
|
1715
|
+
"reviewing",
|
|
1716
|
+
"closing-out",
|
|
1717
|
+
"stopping",
|
|
1718
|
+
"loading"
|
|
1719
|
+
]);
|
|
1720
|
+
function normalizeStatus(status) {
|
|
1721
|
+
return status.replace(/_/g, "-").toLowerCase();
|
|
1722
|
+
}
|
|
1723
|
+
function runsFromState(state) {
|
|
1724
|
+
const fleet = state.data.fleet;
|
|
1725
|
+
if (!fleet || typeof fleet !== "object" || Array.isArray(fleet))
|
|
1726
|
+
return [];
|
|
1727
|
+
const runs = fleet.runs;
|
|
1728
|
+
return Array.isArray(runs) ? runs : [];
|
|
1729
|
+
}
|
|
1730
|
+
function computeFleetStats(runs) {
|
|
1731
|
+
const byStatus = new Map;
|
|
1732
|
+
let active = 0;
|
|
1733
|
+
let succeeded = 0;
|
|
1734
|
+
let failed = 0;
|
|
1735
|
+
for (const run of runs) {
|
|
1736
|
+
const status = normalizeStatus(run.status ?? "");
|
|
1737
|
+
byStatus.set(status, (byStatus.get(status) ?? 0) + 1);
|
|
1738
|
+
if (ACTIVE_STATUSES.has(status))
|
|
1739
|
+
active += 1;
|
|
1740
|
+
else if (status === "success" || status === "completed" || status === "merged")
|
|
1741
|
+
succeeded += 1;
|
|
1742
|
+
else if (status === "failed" || status === "error")
|
|
1743
|
+
failed += 1;
|
|
1744
|
+
}
|
|
1745
|
+
const total = runs.length;
|
|
1746
|
+
const load = total === 0 ? 0 : active / total;
|
|
1747
|
+
const sparkline = buildSparklineSeries(active, succeeded, failed);
|
|
1748
|
+
return { total, active, succeeded, failed, byStatus, load, sparkline };
|
|
1749
|
+
}
|
|
1750
|
+
function buildSparklineSeries(active, succeeded, failed) {
|
|
1751
|
+
const peak = Math.max(1, active, succeeded, failed);
|
|
1752
|
+
const base = [succeeded, Math.round(succeeded * 0.6 + failed * 0.4), failed, Math.round((active + failed) / 2), active];
|
|
1753
|
+
return base.map((value) => Math.max(0, Math.min(peak, value)) / peak);
|
|
1754
|
+
}
|
|
1755
|
+
function fleetStatsFromState(state) {
|
|
1756
|
+
return computeFleetStats(runsFromState(state));
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
// packages/cli/src/app-opentui/react/Backdrop.tsx
|
|
1760
|
+
var ANIMATION_SLOWDOWN = 1;
|
|
1761
|
+
function isTerminalScene(scene) {
|
|
1762
|
+
return scene === "handoff" || scene === "command";
|
|
1763
|
+
}
|
|
1764
|
+
function Backdrop(props) {
|
|
1765
|
+
const renderer = useRenderer();
|
|
1766
|
+
const imageRef = useRef(null);
|
|
1767
|
+
const graphicsRef = useRef(null);
|
|
1768
|
+
useEffect(() => {
|
|
1769
|
+
const imageVisuals = forceModernImageVisuals() ? new ImageVisualLayer(process.stdout, () => renderer.requestRender?.()) : null;
|
|
1770
|
+
if (imageVisuals?.enabled) {
|
|
1771
|
+
imageRef.current = imageVisuals;
|
|
1772
|
+
} else {
|
|
1773
|
+
const layout = computeStageLayout(renderer.width, renderer.height);
|
|
1774
|
+
const graphics = createGraphicsLayer(renderer, layout);
|
|
1775
|
+
renderer.root.add(graphics);
|
|
1776
|
+
graphicsRef.current = graphics;
|
|
1777
|
+
}
|
|
1778
|
+
return () => {
|
|
1779
|
+
imageRef.current?.destroy();
|
|
1780
|
+
const graphics = graphicsRef.current;
|
|
1781
|
+
if (graphics) {
|
|
1782
|
+
try {
|
|
1783
|
+
renderer.root.remove(graphics.id);
|
|
1784
|
+
} catch {}
|
|
1785
|
+
}
|
|
1786
|
+
imageRef.current = null;
|
|
1787
|
+
graphicsRef.current = null;
|
|
1788
|
+
};
|
|
1789
|
+
}, [renderer]);
|
|
1790
|
+
useEffect(() => {
|
|
1791
|
+
const layout = computeStageLayout(renderer.width, renderer.height);
|
|
1792
|
+
const image = imageRef.current;
|
|
1793
|
+
const graphics = graphicsRef.current;
|
|
1794
|
+
if (layout.tooSmall) {
|
|
1795
|
+
image?.clear();
|
|
1796
|
+
if (graphics)
|
|
1797
|
+
clearGraphicsLayer(graphics);
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
const stats = fleetStatsFromState(props.state);
|
|
1801
|
+
const tick = props.state.tick;
|
|
1802
|
+
const animationTick = Math.floor(tick / ANIMATION_SLOWDOWN);
|
|
1803
|
+
const panels = (props.frame.panels ?? []).map((panel) => ({ ...panel }));
|
|
1804
|
+
const terminalActive = props.frame.terminalActive ?? isTerminalScene(props.state.scene);
|
|
1805
|
+
const fullScreen = Boolean(props.frame.fullScreen);
|
|
1806
|
+
if (image) {
|
|
1807
|
+
if (terminalActive || fullScreen) {
|
|
1808
|
+
image.clear();
|
|
1809
|
+
} else {
|
|
1810
|
+
image.render({
|
|
1811
|
+
layout,
|
|
1812
|
+
pixelSize: pixelSizeForRenderer(renderer),
|
|
1813
|
+
panels,
|
|
1814
|
+
scene: props.state.scene,
|
|
1815
|
+
tick,
|
|
1816
|
+
load: stats.load,
|
|
1817
|
+
activeRuns: stats.active
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
} else if (graphics) {
|
|
1821
|
+
resizeGraphicsLayer(graphics, layout);
|
|
1822
|
+
if (terminalActive || fullScreen) {
|
|
1823
|
+
clearGraphicsLayer(graphics);
|
|
1824
|
+
} else {
|
|
1825
|
+
drawAmbientField(graphics, layout, animationTick, props.state.scene, stats.load, stats.active);
|
|
1826
|
+
drawPanelChrome(graphics, layout, panels);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
return null;
|
|
1831
|
+
}
|
|
1832
|
+
export {
|
|
1833
|
+
Backdrop
|
|
1834
|
+
};
|