@h-rig/cli 0.0.6-alpha.84 → 0.0.6-alpha.86
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/rig.js +27 -1063
- package/dist/src/app-opentui/bootstrap.js +27 -1063
- package/dist/src/app-opentui/index.js +7 -1024
- package/dist/src/app-opentui/react/App.js +20 -1032
- package/dist/src/app-opentui/react/Backdrop.js +20 -1032
- package/dist/src/app-opentui/react/ChromeHost.js +0 -1039
- package/dist/src/app-opentui/react/launch.js +20 -1032
- package/dist/src/app-opentui/render/constants.d.ts +0 -1
- package/dist/src/app-opentui/render/constants.js +0 -2
- package/dist/src/app-opentui/render/graphics.js +2 -9
- package/dist/src/app-opentui/runtime.js +8 -1025
- package/package.json +8 -8
- package/dist/src/app-opentui/render/image-visual-layer-worker.d.ts +0 -1
- package/dist/src/app-opentui/render/image-visual-layer-worker.js +0 -1084
- package/dist/src/app-opentui/render/image-visual-layer.d.ts +0 -109
- package/dist/src/app-opentui/render/image-visual-layer.js +0 -1068
- package/dist/src/app-opentui/terminal-capabilities.d.ts +0 -7
- package/dist/src/app-opentui/terminal-capabilities.js +0 -15
|
@@ -2540,19 +2540,6 @@ function panelContentRect(layout, panel) {
|
|
|
2540
2540
|
const contentWidth = Math.max(1, width - paddingX * 2 - 1);
|
|
2541
2541
|
return { left, top, width, height, paddingX, paddingY, contentWidth };
|
|
2542
2542
|
}
|
|
2543
|
-
function panelPixelPlacement(layout, panel, size, minPixels = 8) {
|
|
2544
|
-
const cellW = size.width / layout.width;
|
|
2545
|
-
const cellH = size.height / layout.height;
|
|
2546
|
-
const leftCells = layout.centerLeft + (panel.left ?? 0);
|
|
2547
|
-
const topCells = layout.centerTop + panel.top;
|
|
2548
|
-
const widthCells = panel.width ?? layout.centerWidth;
|
|
2549
|
-
const heightCells = panel.height;
|
|
2550
|
-
const left = Math.round(leftCells * cellW);
|
|
2551
|
-
const top = Math.round(topCells * cellH);
|
|
2552
|
-
const width = Math.round(widthCells * cellW);
|
|
2553
|
-
const height = Math.round(heightCells * cellH);
|
|
2554
|
-
return width > minPixels && height > minPixels ? { left, top, width, height, leftCells, topCells, widthCells, heightCells } : null;
|
|
2555
|
-
}
|
|
2556
2543
|
|
|
2557
2544
|
// packages/cli/src/app-opentui/render/constants.ts
|
|
2558
2545
|
var LCG_MULTIPLIER = 1664525;
|
|
@@ -2585,7 +2572,6 @@ var RAIL_YS_LOOP = [0.18, 0.5, 0.82];
|
|
|
2585
2572
|
var RAIL_YS_CARRIER = [0.24, 0.54, 0.82];
|
|
2586
2573
|
var RAIL_YS_DISPATCH = [0.18, 0.58, 0.82];
|
|
2587
2574
|
var GLOW_FALLOFF_EXP_ASCII = 2.2;
|
|
2588
|
-
var GLOW_FALLOFF_EXP_IMAGE = 2.4;
|
|
2589
2575
|
|
|
2590
2576
|
// packages/cli/src/app-opentui/render/graphics.ts
|
|
2591
2577
|
var BRAILLE_SAMPLES_X = 2;
|
|
@@ -3017,27 +3003,20 @@ function writeCell(layer, x, y, char, fg, bg) {
|
|
|
3017
3003
|
function drawFullCell(layer, x, y, bg) {
|
|
3018
3004
|
writeCell(layer, x, y, " ", TRANSPARENT, bg);
|
|
3019
3005
|
}
|
|
3020
|
-
function
|
|
3021
|
-
writeCell(layer, x, y, char, fg, BACKDROP);
|
|
3022
|
-
}
|
|
3023
|
-
function drawRoundedFill(layer, left, top, right, bottom, dividerY) {
|
|
3006
|
+
function drawPanelFill(layer, left, top, right, bottom, dividerY) {
|
|
3024
3007
|
const bgForY = (y) => y < dividerY ? PANEL_HEADER_BG : PANEL_BG;
|
|
3025
3008
|
for (let y = top;y <= bottom; y += 1) {
|
|
3026
3009
|
const bg = bgForY(y);
|
|
3027
3010
|
for (let x = left;x <= right; x += 1)
|
|
3028
3011
|
drawFullCell(layer, x, y, bg);
|
|
3029
3012
|
}
|
|
3030
|
-
drawCornerCut(layer, left, top, "\u2597", PANEL_HEADER_BG);
|
|
3031
|
-
drawCornerCut(layer, right, top, "\u2596", PANEL_HEADER_BG);
|
|
3032
|
-
drawCornerCut(layer, left, bottom, "\u259D", PANEL_BG);
|
|
3033
|
-
drawCornerCut(layer, right, bottom, "\u2598", PANEL_BG);
|
|
3034
3013
|
}
|
|
3035
3014
|
function drawAdTerminalPanel(layer, layout, panel) {
|
|
3036
3015
|
const rect = panelCellRect(layout, panel);
|
|
3037
3016
|
if (!rect)
|
|
3038
3017
|
return;
|
|
3039
3018
|
const { left, top, width, right, bottom, headerHeight, dividerY } = rect;
|
|
3040
|
-
|
|
3019
|
+
drawPanelFill(layer, left, top, right, bottom, dividerY);
|
|
3041
3020
|
if (dividerY > top && dividerY < bottom) {
|
|
3042
3021
|
for (let x = left + 2;x < right - 1; x += 1) {
|
|
3043
3022
|
writeCell(layer, x, dividerY, "\u2500", PANEL_LINE_DIM, PANEL_BG);
|
|
@@ -3123,971 +3102,6 @@ function drawAmbientField(layer, layout, _tick, scene = "fleet", load = 0, activ
|
|
|
3123
3102
|
layer.__rigAmbientKey = key;
|
|
3124
3103
|
}
|
|
3125
3104
|
|
|
3126
|
-
// packages/cli/src/app-opentui/render/image-visual-layer.ts
|
|
3127
|
-
import { Worker } from "worker_threads";
|
|
3128
|
-
import { deflateSync } from "zlib";
|
|
3129
|
-
import { allocateImageId, deleteKittyImage } from "@earendil-works/pi-tui";
|
|
3130
|
-
|
|
3131
|
-
// packages/cli/src/app-opentui/terminal-capabilities.ts
|
|
3132
|
-
import { getCapabilities } from "@earendil-works/pi-tui";
|
|
3133
|
-
function getRigTerminalCapabilities() {
|
|
3134
|
-
const imageProtocol = getCapabilities().images;
|
|
3135
|
-
const supportsKittyImages = imageProtocol === "kitty";
|
|
3136
|
-
return {
|
|
3137
|
-
imageProtocol,
|
|
3138
|
-
supportsKittyImages,
|
|
3139
|
-
visualMode: supportsKittyImages ? "kitty-images" : "framebuffer-fallback"
|
|
3140
|
-
};
|
|
3141
|
-
}
|
|
3142
|
-
|
|
3143
|
-
// packages/cli/src/app-opentui/render/image-visual-layer.ts
|
|
3144
|
-
var PANEL_MASK_RADIUS_MIN = 14;
|
|
3145
|
-
var PANEL_MASK_RADIUS_MAX = 34;
|
|
3146
|
-
var PANEL_MASK_RADIUS_FACTOR = 0.035;
|
|
3147
|
-
var PANEL_BLUR_RADIUS_MIN = 8;
|
|
3148
|
-
var PANEL_BLUR_RADIUS_MAX = 28;
|
|
3149
|
-
var PANEL_BLUR_RADIUS_FACTOR = 0.018;
|
|
3150
|
-
var BG = [7, 8, 9, 255];
|
|
3151
|
-
var PANEL = [16, 17, 21, 184];
|
|
3152
|
-
var PANEL_HEADER = [16, 17, 21, 190];
|
|
3153
|
-
var PANEL_LINE2 = [255, 255, 255, 24];
|
|
3154
|
-
var LIME = [204, 255, 77, 255];
|
|
3155
|
-
var LIME_DIM = [169, 214, 63, 255];
|
|
3156
|
-
var CYAN = [86, 216, 255, 255];
|
|
3157
|
-
var MAGENTA = [255, 121, 176, 255];
|
|
3158
|
-
var INK_DIM = [108, 110, 121, 255];
|
|
3159
|
-
var PNG_SIGNATURE = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
3160
|
-
var CRC_TABLE = makeCrcTable();
|
|
3161
|
-
var MAX_IMAGE_BYTES = 48 * 1024 * 1024;
|
|
3162
|
-
var KITTY_CHUNK_SIZE = 4096;
|
|
3163
|
-
var PANEL_BLUR_SCALE = 1;
|
|
3164
|
-
var PANEL_MASK_CACHE_LIMIT = 16;
|
|
3165
|
-
var ZLIB_LEVEL = 1;
|
|
3166
|
-
var DEFAULT_IMAGE_RESOLUTION_SCALE = 1;
|
|
3167
|
-
var LOAD_BUCKETS = 5;
|
|
3168
|
-
function loadBucket(load) {
|
|
3169
|
-
if (!Number.isFinite(load ?? NaN))
|
|
3170
|
-
return 0;
|
|
3171
|
-
return Math.max(0, Math.min(LOAD_BUCKETS, Math.round((load ?? 0) * LOAD_BUCKETS)));
|
|
3172
|
-
}
|
|
3173
|
-
var panelMaskCache = new Map;
|
|
3174
|
-
var BG_WORD = rgbaWord(BG);
|
|
3175
|
-
function imageTransport() {
|
|
3176
|
-
const forced = process.env.RIG_OPENTUI_IMAGE_TRANSPORT;
|
|
3177
|
-
if (forced === "rgba-zlib")
|
|
3178
|
-
return "rgba-zlib";
|
|
3179
|
-
return "png";
|
|
3180
|
-
}
|
|
3181
|
-
function imageResolutionScale() {
|
|
3182
|
-
const raw = Number.parseFloat(process.env.RIG_OPENTUI_IMAGE_SCALE ?? "");
|
|
3183
|
-
if (Number.isFinite(raw) && raw > 0)
|
|
3184
|
-
return Math.max(0.25, Math.min(1, raw));
|
|
3185
|
-
return DEFAULT_IMAGE_RESOLUTION_SCALE;
|
|
3186
|
-
}
|
|
3187
|
-
function rgbaWord(color) {
|
|
3188
|
-
return (color[3] << 24 | color[2] << 16 | color[1] << 8 | color[0]) >>> 0;
|
|
3189
|
-
}
|
|
3190
|
-
function fillRgba(data, color, word = rgbaWord(color)) {
|
|
3191
|
-
if (data.byteOffset % 4 === 0 && data.byteLength % 4 === 0) {
|
|
3192
|
-
new Uint32Array(data.buffer, data.byteOffset, data.byteLength / 4).fill(word);
|
|
3193
|
-
return;
|
|
3194
|
-
}
|
|
3195
|
-
for (let i = 0;i < data.length; i += 4) {
|
|
3196
|
-
data[i] = color[0];
|
|
3197
|
-
data[i + 1] = color[1];
|
|
3198
|
-
data[i + 2] = color[2];
|
|
3199
|
-
data[i + 3] = color[3];
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
var ASCII_GLYPHS = {
|
|
3203
|
-
".": ["00000", "00000", "00000", "00000", "00000", "00100", "00100"],
|
|
3204
|
-
"'": ["00100", "00100", "00000", "00000", "00000", "00000", "00000"],
|
|
3205
|
-
"-": ["00000", "00000", "00000", "11111", "00000", "00000", "00000"],
|
|
3206
|
-
_: ["00000", "00000", "00000", "00000", "00000", "00000", "11111"],
|
|
3207
|
-
"=": ["00000", "11111", "00000", "00000", "11111", "00000", "00000"],
|
|
3208
|
-
"|": ["00100", "00100", "00100", "00100", "00100", "00100", "00100"],
|
|
3209
|
-
"/": ["00001", "00010", "00010", "00100", "01000", "01000", "10000"],
|
|
3210
|
-
"\\": ["10000", "01000", "01000", "00100", "00010", "00010", "00001"],
|
|
3211
|
-
"(": ["00010", "00100", "01000", "01000", "01000", "00100", "00010"],
|
|
3212
|
-
")": ["01000", "00100", "00010", "00010", "00010", "00100", "01000"],
|
|
3213
|
-
"!": ["00100", "00100", "00100", "00100", "00100", "00000", "00100"],
|
|
3214
|
-
"%": ["11001", "11010", "00100", "01000", "10110", "00110", "00000"],
|
|
3215
|
-
$: ["00100", "11110", "10100", "11110", "00101", "11110", "00100"],
|
|
3216
|
-
"@": ["01110", "10001", "10111", "10101", "10111", "10000", "01111"],
|
|
3217
|
-
o: ["00000", "01110", "10001", "10001", "10001", "01110", "00000"],
|
|
3218
|
-
"*": ["00100", "10101", "01110", "11111", "01110", "10101", "00100"]
|
|
3219
|
-
};
|
|
3220
|
-
function sceneStaticTick(scene) {
|
|
3221
|
-
let hash = 0;
|
|
3222
|
-
for (let index = 0;index < scene.length; index += 1)
|
|
3223
|
-
hash = hash * 33 + scene.charCodeAt(index) >>> 0;
|
|
3224
|
-
return 11 + hash % 97;
|
|
3225
|
-
}
|
|
3226
|
-
function charColor(char, row, totalRows) {
|
|
3227
|
-
if (char === "@" || char === "$" || char === "o")
|
|
3228
|
-
return LIME;
|
|
3229
|
-
if (char === "%" || char === "!" || char === "/" || char === "\\" || char === "|")
|
|
3230
|
-
return CYAN;
|
|
3231
|
-
if (char === "." || char === "'" || char === "_" || row < 3 || row > totalRows - 4)
|
|
3232
|
-
return INK_DIM;
|
|
3233
|
-
if (char === "-" || char === "=" || char === "(" || char === ")")
|
|
3234
|
-
return LIME_DIM;
|
|
3235
|
-
return MAGENTA;
|
|
3236
|
-
}
|
|
3237
|
-
function fillRectAlpha(data, width, height, left, top, rectWidth, rectHeight, color, alpha) {
|
|
3238
|
-
const x0 = Math.max(0, Math.floor(left));
|
|
3239
|
-
const y0 = Math.max(0, Math.floor(top));
|
|
3240
|
-
const x1 = Math.min(width, Math.ceil(left + rectWidth));
|
|
3241
|
-
const y1 = Math.min(height, Math.ceil(top + rectHeight));
|
|
3242
|
-
for (let y = y0;y < y1; y += 1) {
|
|
3243
|
-
for (let x = x0;x < x1; x += 1)
|
|
3244
|
-
blendOver(data, (y * width + x) * 4, color, alpha);
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
3247
|
-
function drawAsciiGlyph(data, width, height, x, y, cellWidth, cellHeight, char, color, alpha) {
|
|
3248
|
-
const pattern = ASCII_GLYPHS[char] ?? ASCII_GLYPHS["*"];
|
|
3249
|
-
const glyphWidth = Math.max(1, cellWidth * 0.56);
|
|
3250
|
-
const glyphHeight = Math.max(1, cellHeight * 0.7);
|
|
3251
|
-
const originX = x + (cellWidth - glyphWidth) * 0.5;
|
|
3252
|
-
const originY = y + (cellHeight - glyphHeight) * 0.5;
|
|
3253
|
-
const pixelWidth = Math.max(1, glyphWidth / pattern[0].length);
|
|
3254
|
-
const pixelHeight = Math.max(1, glyphHeight / pattern.length);
|
|
3255
|
-
for (let row = 0;row < pattern.length; row += 1) {
|
|
3256
|
-
const bits = pattern[row];
|
|
3257
|
-
for (let col = 0;col < bits.length; col += 1) {
|
|
3258
|
-
if (bits[col] !== "1")
|
|
3259
|
-
continue;
|
|
3260
|
-
fillRectAlpha(data, width, height, originX + col * pixelWidth, originY + row * pixelHeight, pixelWidth * 0.72, pixelHeight * 0.72, color, alpha);
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3263
|
-
}
|
|
3264
|
-
function drawStaticAsciiFleetBackground(data, width, height, scene, layout, load, activeRuns) {
|
|
3265
|
-
const rows = fleetRows(sceneStaticTick(scene), { animate: true });
|
|
3266
|
-
const cellWidth = width / Math.max(1, layout.width);
|
|
3267
|
-
const cellHeight = height / Math.max(1, layout.height);
|
|
3268
|
-
const sideBySide = layout.width >= FLEET_GRID_WIDTH * 1.9;
|
|
3269
|
-
const leftCells = sideBySide ? Math.max(1, Math.floor(layout.width * 0.3 - FLEET_GRID_WIDTH / 2)) : Math.floor((layout.width - FLEET_GRID_WIDTH) / 2);
|
|
3270
|
-
const topCells = Math.floor((layout.height - FLEET_GRID_HEIGHT) / 2);
|
|
3271
|
-
const fleetLeft = leftCells * cellWidth;
|
|
3272
|
-
const fleetTop = topCells * cellHeight;
|
|
3273
|
-
drawGlow2(data, width, height, width * 0.5, height * 0.5, Math.min(width, height) * 0.4, LIME, 0.022 + load * 0.03);
|
|
3274
|
-
drawGlow2(data, width, height, width * 0.18, height * 0.22, Math.min(width, height) * 0.28, CYAN, 0.018 + load * 0.012);
|
|
3275
|
-
drawGlow2(data, width, height, width * 0.82, height * 0.78, Math.min(width, height) * 0.22, MAGENTA, 0.012 + load * 0.008);
|
|
3276
|
-
let droneTotal = 0;
|
|
3277
|
-
for (const line2 of rows)
|
|
3278
|
-
for (const char of line2)
|
|
3279
|
-
if (char === "@" || char === "$" || char === "%")
|
|
3280
|
-
droneTotal += 1;
|
|
3281
|
-
const litTarget = Math.max(0, Math.min(droneTotal, activeRuns));
|
|
3282
|
-
let droneIndex = 0;
|
|
3283
|
-
for (let row = 0;row < rows.length; row += 1) {
|
|
3284
|
-
const line2 = rows[row];
|
|
3285
|
-
for (let col = 0;col < line2.length; col += 1) {
|
|
3286
|
-
const char = line2[col];
|
|
3287
|
-
if (char === " ")
|
|
3288
|
-
continue;
|
|
3289
|
-
const x = fleetLeft + col * cellWidth;
|
|
3290
|
-
const y = fleetTop + row * cellHeight;
|
|
3291
|
-
const color = charColor(char, row, rows.length);
|
|
3292
|
-
const isDrone = char === "@" || char === "$" || char === "%";
|
|
3293
|
-
const lit = isDrone && droneIndex < litTarget;
|
|
3294
|
-
drawAsciiGlyph(data, width, height, x + cellWidth * 0.07, y + cellHeight * 0.05, cellWidth, cellHeight, char, color, lit ? 0.72 : 0.46);
|
|
3295
|
-
if (isDrone) {
|
|
3296
|
-
droneIndex += 1;
|
|
3297
|
-
drawGlow2(data, width, height, x + cellWidth * 0.5, y + cellHeight * 0.5, Math.max(cellWidth, cellHeight) * 0.95, color, lit ? 0.044 : 0.014);
|
|
3298
|
-
}
|
|
3299
|
-
}
|
|
3300
|
-
}
|
|
3301
|
-
}
|
|
3302
|
-
function applyStaticAtmosphere(data, width, height, load) {
|
|
3303
|
-
const cx = width * 0.5;
|
|
3304
|
-
const cy = height * 0.42;
|
|
3305
|
-
const radius = Math.max(width, height) * 0.78;
|
|
3306
|
-
const minVignette = 0.1 - load * 0.02;
|
|
3307
|
-
for (let y = 0;y < height; y += 1) {
|
|
3308
|
-
for (let x = 0;x < width; x += 1) {
|
|
3309
|
-
const distance = Math.hypot(x - cx, y - cy) / radius;
|
|
3310
|
-
const alpha = Math.max(minVignette, Math.min(0.82, 0.12 + Math.pow(distance, 1.65) * 0.62));
|
|
3311
|
-
blendOver(data, (y * width + x) * 4, BG, alpha);
|
|
3312
|
-
}
|
|
3313
|
-
}
|
|
3314
|
-
drawGlow2(data, width, height, width * 0.82, height * 0.04, Math.min(width, height) * 0.2, LIME, 0.024 + load * 0.012);
|
|
3315
|
-
drawGlow2(data, width, height, width * 0.12, height * 0.18, Math.min(width, height) * 0.16, CYAN, 0.018 + load * 0.008);
|
|
3316
|
-
}
|
|
3317
|
-
function makeCrcTable() {
|
|
3318
|
-
const table = new Uint32Array(256);
|
|
3319
|
-
for (let n = 0;n < 256; n += 1) {
|
|
3320
|
-
let c = n;
|
|
3321
|
-
for (let k = 0;k < 8; k += 1)
|
|
3322
|
-
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
3323
|
-
table[n] = c >>> 0;
|
|
3324
|
-
}
|
|
3325
|
-
return table;
|
|
3326
|
-
}
|
|
3327
|
-
function crc32(bytes) {
|
|
3328
|
-
let c = 4294967295;
|
|
3329
|
-
for (let i = 0;i < bytes.length; i += 1)
|
|
3330
|
-
c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
|
|
3331
|
-
return (c ^ 4294967295) >>> 0;
|
|
3332
|
-
}
|
|
3333
|
-
function chunk2(type, data) {
|
|
3334
|
-
const out = new Uint8Array(12 + data.length);
|
|
3335
|
-
const view = new DataView(out.buffer);
|
|
3336
|
-
view.setUint32(0, data.length);
|
|
3337
|
-
out[4] = type.charCodeAt(0);
|
|
3338
|
-
out[5] = type.charCodeAt(1);
|
|
3339
|
-
out[6] = type.charCodeAt(2);
|
|
3340
|
-
out[7] = type.charCodeAt(3);
|
|
3341
|
-
out.set(data, 8);
|
|
3342
|
-
view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
|
3343
|
-
return out;
|
|
3344
|
-
}
|
|
3345
|
-
function encodePng(width, height, rgba) {
|
|
3346
|
-
const ihdr = new Uint8Array(13);
|
|
3347
|
-
const ihdrView = new DataView(ihdr.buffer);
|
|
3348
|
-
ihdrView.setUint32(0, width);
|
|
3349
|
-
ihdrView.setUint32(4, height);
|
|
3350
|
-
ihdr[8] = 8;
|
|
3351
|
-
ihdr[9] = 6;
|
|
3352
|
-
ihdr[10] = 0;
|
|
3353
|
-
ihdr[11] = 0;
|
|
3354
|
-
ihdr[12] = 0;
|
|
3355
|
-
const stride = width * 4;
|
|
3356
|
-
const raw = new Uint8Array((stride + 1) * height);
|
|
3357
|
-
for (let y = 0;y < height; y += 1) {
|
|
3358
|
-
const rawOffset = y * (stride + 1);
|
|
3359
|
-
raw[rawOffset] = 0;
|
|
3360
|
-
raw.set(rgba.subarray(y * stride, y * stride + stride), rawOffset + 1);
|
|
3361
|
-
}
|
|
3362
|
-
const compressed = deflateSync(raw, { level: ZLIB_LEVEL });
|
|
3363
|
-
return Buffer.concat([
|
|
3364
|
-
Buffer.from(PNG_SIGNATURE),
|
|
3365
|
-
Buffer.from(chunk2("IHDR", ihdr)),
|
|
3366
|
-
Buffer.from(chunk2("IDAT", compressed)),
|
|
3367
|
-
Buffer.from(chunk2("IEND", new Uint8Array(0)))
|
|
3368
|
-
]);
|
|
3369
|
-
}
|
|
3370
|
-
function kittyImageSequence(base64, options) {
|
|
3371
|
-
const params = [`a=T`, `f=${options.format}`, `q=2`, `C=1`, `c=${options.columns}`, `r=${options.rows}`, `i=${options.imageId}`, `z=${options.zIndex}`];
|
|
3372
|
-
if (options.format === 32) {
|
|
3373
|
-
params.push(`s=${options.pixelWidth ?? 1}`, `v=${options.pixelHeight ?? 1}`);
|
|
3374
|
-
if (options.compressed)
|
|
3375
|
-
params.push("o=z");
|
|
3376
|
-
}
|
|
3377
|
-
if (base64.length <= KITTY_CHUNK_SIZE)
|
|
3378
|
-
return `\x1B_G${params.join(",")};${base64}\x1B\\`;
|
|
3379
|
-
const chunks = [];
|
|
3380
|
-
for (let offset = 0;offset < base64.length; offset += KITTY_CHUNK_SIZE) {
|
|
3381
|
-
const part = base64.slice(offset, offset + KITTY_CHUNK_SIZE);
|
|
3382
|
-
const last = offset + KITTY_CHUNK_SIZE >= base64.length;
|
|
3383
|
-
chunks.push(`\x1B_G${offset === 0 ? `${params.join(",")},` : ""}m=${last ? 0 : 1};${part}\x1B\\`);
|
|
3384
|
-
}
|
|
3385
|
-
return chunks.join("");
|
|
3386
|
-
}
|
|
3387
|
-
function clampByte(value) {
|
|
3388
|
-
return Math.max(0, Math.min(255, Math.round(value)));
|
|
3389
|
-
}
|
|
3390
|
-
function blendOver(data, index, color, alphaScale = 1) {
|
|
3391
|
-
const alpha = color[3] / 255 * alphaScale;
|
|
3392
|
-
const inv = 1 - alpha;
|
|
3393
|
-
data[index] = clampByte(color[0] * alpha + data[index] * inv);
|
|
3394
|
-
data[index + 1] = clampByte(color[1] * alpha + data[index + 1] * inv);
|
|
3395
|
-
data[index + 2] = clampByte(color[2] * alpha + data[index + 2] * inv);
|
|
3396
|
-
data[index + 3] = 255;
|
|
3397
|
-
}
|
|
3398
|
-
function drawDisc(data, width, height, cx, cy, radius, color, alpha = 1) {
|
|
3399
|
-
const minX = Math.max(0, Math.floor(cx - radius));
|
|
3400
|
-
const maxX = Math.min(width - 1, Math.ceil(cx + radius));
|
|
3401
|
-
const minY = Math.max(0, Math.floor(cy - radius));
|
|
3402
|
-
const maxY = Math.min(height - 1, Math.ceil(cy + radius));
|
|
3403
|
-
for (let y = minY;y <= maxY; y += 1) {
|
|
3404
|
-
for (let x = minX;x <= maxX; x += 1) {
|
|
3405
|
-
const dx = x + 0.5 - cx;
|
|
3406
|
-
const dy = y + 0.5 - cy;
|
|
3407
|
-
const d = Math.sqrt(dx * dx + dy * dy);
|
|
3408
|
-
if (d > radius)
|
|
3409
|
-
continue;
|
|
3410
|
-
const edge = Math.max(0, Math.min(1, radius - d));
|
|
3411
|
-
blendOver(data, (y * width + x) * 4, color, alpha * Math.min(1, 0.35 + edge));
|
|
3412
|
-
}
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
|
-
function drawGlow2(data, width, height, cx, cy, radius, color, alpha = 0.18) {
|
|
3416
|
-
const minX = Math.max(0, Math.floor(cx - radius));
|
|
3417
|
-
const maxX = Math.min(width - 1, Math.ceil(cx + radius));
|
|
3418
|
-
const minY = Math.max(0, Math.floor(cy - radius));
|
|
3419
|
-
const maxY = Math.min(height - 1, Math.ceil(cy + radius));
|
|
3420
|
-
for (let y = minY;y <= maxY; y += 1) {
|
|
3421
|
-
for (let x = minX;x <= maxX; x += 1) {
|
|
3422
|
-
const dx = x + 0.5 - cx;
|
|
3423
|
-
const dy = y + 0.5 - cy;
|
|
3424
|
-
const d = Math.sqrt(dx * dx + dy * dy);
|
|
3425
|
-
if (d > radius)
|
|
3426
|
-
continue;
|
|
3427
|
-
const falloff = Math.pow(1 - d / Math.max(1, radius), GLOW_FALLOFF_EXP_IMAGE);
|
|
3428
|
-
blendOver(data, (y * width + x) * 4, color, alpha * falloff);
|
|
3429
|
-
}
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
function drawLine2(data, width, height, x0, y0, x1, y1, color, alpha = 0.5, thickness = 1.4) {
|
|
3433
|
-
const dx = x1 - x0;
|
|
3434
|
-
const dy = y1 - y0;
|
|
3435
|
-
const steps = Math.max(1, Math.ceil(Math.hypot(dx, dy) * 1.2));
|
|
3436
|
-
for (let i = 0;i <= steps; i += 1) {
|
|
3437
|
-
const t2 = i / steps;
|
|
3438
|
-
drawDisc(data, width, height, x0 + dx * t2, y0 + dy * t2, thickness, color, alpha);
|
|
3439
|
-
}
|
|
3440
|
-
}
|
|
3441
|
-
function roundRectAlpha(px, py, x, y, w, h, r) {
|
|
3442
|
-
const rx = Math.max(x + r, Math.min(px, x + w - r));
|
|
3443
|
-
const ry = Math.max(y + r, Math.min(py, y + h - r));
|
|
3444
|
-
const dx = px - rx;
|
|
3445
|
-
const dy = py - ry;
|
|
3446
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
3447
|
-
return Math.max(0, Math.min(1, r + 0.75 - dist));
|
|
3448
|
-
}
|
|
3449
|
-
function panelRect(layout, panel, size) {
|
|
3450
|
-
return panelPixelPlacement(layout, panel, size);
|
|
3451
|
-
}
|
|
3452
|
-
function downsampleRegion(data, canvasW, canvasH, rect, scale) {
|
|
3453
|
-
const w = Math.max(1, Math.ceil(rect.width / scale));
|
|
3454
|
-
const h = Math.max(1, Math.ceil(rect.height / scale));
|
|
3455
|
-
const out = new Uint8ClampedArray(w * h * 3);
|
|
3456
|
-
for (let y = 0;y < h; y += 1) {
|
|
3457
|
-
for (let x = 0;x < w; x += 1) {
|
|
3458
|
-
let r = 0, g = 0, b = 0, count = 0;
|
|
3459
|
-
const sx0 = rect.left + x * scale;
|
|
3460
|
-
const sy0 = rect.top + y * scale;
|
|
3461
|
-
for (let yy = 0;yy < scale; yy += 1) {
|
|
3462
|
-
const sy = sy0 + yy;
|
|
3463
|
-
if (sy < 0 || sy >= canvasH)
|
|
3464
|
-
continue;
|
|
3465
|
-
for (let xx = 0;xx < scale; xx += 1) {
|
|
3466
|
-
const sx = sx0 + xx;
|
|
3467
|
-
if (sx < 0 || sx >= canvasW)
|
|
3468
|
-
continue;
|
|
3469
|
-
const i = (sy * canvasW + sx) * 4;
|
|
3470
|
-
r += data[i];
|
|
3471
|
-
g += data[i + 1];
|
|
3472
|
-
b += data[i + 2];
|
|
3473
|
-
count += 1;
|
|
3474
|
-
}
|
|
3475
|
-
}
|
|
3476
|
-
const oi = (y * w + x) * 3;
|
|
3477
|
-
out[oi] = count ? r / count : BG[0];
|
|
3478
|
-
out[oi + 1] = count ? g / count : BG[1];
|
|
3479
|
-
out[oi + 2] = count ? b / count : BG[2];
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
return { pixels: out, width: w, height: h };
|
|
3483
|
-
}
|
|
3484
|
-
function blurRgb(buffer, width, height, radius) {
|
|
3485
|
-
const tmp = new Uint8ClampedArray(buffer.length);
|
|
3486
|
-
const out = new Uint8ClampedArray(buffer.length);
|
|
3487
|
-
const window = radius * 2 + 1;
|
|
3488
|
-
for (let y = 0;y < height; y += 1) {
|
|
3489
|
-
let r = 0, g = 0, b = 0;
|
|
3490
|
-
for (let x = -radius;x <= radius; x += 1) {
|
|
3491
|
-
const sx = Math.max(0, Math.min(width - 1, x));
|
|
3492
|
-
const i = (y * width + sx) * 3;
|
|
3493
|
-
r += buffer[i];
|
|
3494
|
-
g += buffer[i + 1];
|
|
3495
|
-
b += buffer[i + 2];
|
|
3496
|
-
}
|
|
3497
|
-
for (let x = 0;x < width; x += 1) {
|
|
3498
|
-
const oi = (y * width + x) * 3;
|
|
3499
|
-
tmp[oi] = r / window;
|
|
3500
|
-
tmp[oi + 1] = g / window;
|
|
3501
|
-
tmp[oi + 2] = b / window;
|
|
3502
|
-
const removeX = Math.max(0, x - radius);
|
|
3503
|
-
const addX = Math.min(width - 1, x + radius + 1);
|
|
3504
|
-
const ri = (y * width + removeX) * 3;
|
|
3505
|
-
const ai = (y * width + addX) * 3;
|
|
3506
|
-
r += tmp.length ? buffer[ai] - buffer[ri] : 0;
|
|
3507
|
-
g += tmp.length ? buffer[ai + 1] - buffer[ri + 1] : 0;
|
|
3508
|
-
b += tmp.length ? buffer[ai + 2] - buffer[ri + 2] : 0;
|
|
3509
|
-
}
|
|
3510
|
-
}
|
|
3511
|
-
for (let x = 0;x < width; x += 1) {
|
|
3512
|
-
let r = 0, g = 0, b = 0;
|
|
3513
|
-
for (let y = -radius;y <= radius; y += 1) {
|
|
3514
|
-
const sy = Math.max(0, Math.min(height - 1, y));
|
|
3515
|
-
const i = (sy * width + x) * 3;
|
|
3516
|
-
r += tmp[i];
|
|
3517
|
-
g += tmp[i + 1];
|
|
3518
|
-
b += tmp[i + 2];
|
|
3519
|
-
}
|
|
3520
|
-
for (let y = 0;y < height; y += 1) {
|
|
3521
|
-
const oi = (y * width + x) * 3;
|
|
3522
|
-
out[oi] = r / window;
|
|
3523
|
-
out[oi + 1] = g / window;
|
|
3524
|
-
out[oi + 2] = b / window;
|
|
3525
|
-
const removeY = Math.max(0, y - radius);
|
|
3526
|
-
const addY = Math.min(height - 1, y + radius + 1);
|
|
3527
|
-
const ri = (removeY * width + x) * 3;
|
|
3528
|
-
const ai = (addY * width + x) * 3;
|
|
3529
|
-
r += tmp[ai] - tmp[ri];
|
|
3530
|
-
g += tmp[ai + 1] - tmp[ri + 1];
|
|
3531
|
-
b += tmp[ai + 2] - tmp[ri + 2];
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
return out;
|
|
3535
|
-
}
|
|
3536
|
-
function panelMaskKey(width, height, rect, headerPx, blurScale) {
|
|
3537
|
-
return `${width}x${height}:${rect.left},${rect.top},${rect.width},${rect.height}:${Math.round(headerPx * 100) / 100}:${blurScale}`;
|
|
3538
|
-
}
|
|
3539
|
-
function getPanelMask(width, height, rect, headerPx, blurScale) {
|
|
3540
|
-
const key = panelMaskKey(width, height, rect, headerPx, blurScale);
|
|
3541
|
-
const cached = panelMaskCache.get(key);
|
|
3542
|
-
if (cached)
|
|
3543
|
-
return cached;
|
|
3544
|
-
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)));
|
|
3545
|
-
const sampledWidth = Math.max(1, Math.ceil(rect.width / blurScale));
|
|
3546
|
-
const sampledHeight = Math.max(1, Math.ceil(rect.height / blurScale));
|
|
3547
|
-
const x0 = Math.max(0, rect.left);
|
|
3548
|
-
const y0 = Math.max(0, rect.top);
|
|
3549
|
-
const x1 = Math.min(width - 1, rect.left + rect.width - 1);
|
|
3550
|
-
const y1 = Math.min(height - 1, rect.top + rect.height - 1);
|
|
3551
|
-
const indices = [];
|
|
3552
|
-
const sampleIndices = [];
|
|
3553
|
-
const panelAlpha = [];
|
|
3554
|
-
const edgeAlpha = [];
|
|
3555
|
-
const headerFlags = [];
|
|
3556
|
-
const dividerIndices = [];
|
|
3557
|
-
for (let y = y0;y <= y1; y += 1) {
|
|
3558
|
-
for (let x = x0;x <= x1; x += 1) {
|
|
3559
|
-
const a = roundRectAlpha(x + 0.5, y + 0.5, rect.left, rect.top, rect.width, rect.height, radius);
|
|
3560
|
-
if (a <= 0)
|
|
3561
|
-
continue;
|
|
3562
|
-
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));
|
|
3563
|
-
const sx = Math.max(0, Math.min(sampledWidth - 1, Math.floor((x - rect.left) / blurScale)));
|
|
3564
|
-
const sy = Math.max(0, Math.min(sampledHeight - 1, Math.floor((y - rect.top) / blurScale)));
|
|
3565
|
-
indices.push((y * width + x) * 4);
|
|
3566
|
-
sampleIndices.push((sy * sampledWidth + sx) * 3);
|
|
3567
|
-
panelAlpha.push(a);
|
|
3568
|
-
edgeAlpha.push(edge < 0.96 ? Math.min(1, (1 - edge) * 0.7) : 0);
|
|
3569
|
-
headerFlags.push(y < rect.top + headerPx ? 1 : 0);
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
const dividerY = Math.round(rect.top + headerPx);
|
|
3573
|
-
if (dividerY > y0 && dividerY < y1) {
|
|
3574
|
-
for (let x = x0 + radius;x <= x1 - radius; x += 1) {
|
|
3575
|
-
dividerIndices.push((dividerY * width + x) * 4);
|
|
3576
|
-
}
|
|
3577
|
-
}
|
|
3578
|
-
const mask = {
|
|
3579
|
-
key,
|
|
3580
|
-
indices: Uint32Array.from(indices),
|
|
3581
|
-
sampleIndices: Uint32Array.from(sampleIndices),
|
|
3582
|
-
panelAlpha: Float32Array.from(panelAlpha),
|
|
3583
|
-
edgeAlpha: Float32Array.from(edgeAlpha),
|
|
3584
|
-
headerFlags: Uint8Array.from(headerFlags),
|
|
3585
|
-
dividerIndices: Uint32Array.from(dividerIndices)
|
|
3586
|
-
};
|
|
3587
|
-
panelMaskCache.set(key, mask);
|
|
3588
|
-
while (panelMaskCache.size > PANEL_MASK_CACHE_LIMIT) {
|
|
3589
|
-
const oldest = panelMaskCache.keys().next().value;
|
|
3590
|
-
if (!oldest)
|
|
3591
|
-
break;
|
|
3592
|
-
panelMaskCache.delete(oldest);
|
|
3593
|
-
}
|
|
3594
|
-
return mask;
|
|
3595
|
-
}
|
|
3596
|
-
function compositePanel(data, width, height, rect, headerPx) {
|
|
3597
|
-
const blurScale = PANEL_BLUR_SCALE;
|
|
3598
|
-
const sampled = downsampleRegion(data, width, height, rect, blurScale);
|
|
3599
|
-
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)));
|
|
3600
|
-
const blurred = blurRgb(sampled.pixels, sampled.width, sampled.height, blurRadius);
|
|
3601
|
-
const mask = getPanelMask(width, height, rect, headerPx, blurScale);
|
|
3602
|
-
for (let i = 0;i < mask.indices.length; i += 1) {
|
|
3603
|
-
const idx = mask.indices[i];
|
|
3604
|
-
const sampleIdx = mask.sampleIndices[i];
|
|
3605
|
-
data[idx] = blurred[sampleIdx];
|
|
3606
|
-
data[idx + 1] = blurred[sampleIdx + 1];
|
|
3607
|
-
data[idx + 2] = blurred[sampleIdx + 2];
|
|
3608
|
-
data[idx + 3] = 255;
|
|
3609
|
-
blendOver(data, idx, mask.headerFlags[i] ? PANEL_HEADER : PANEL, mask.panelAlpha[i]);
|
|
3610
|
-
const edge = mask.edgeAlpha[i];
|
|
3611
|
-
if (edge > 0)
|
|
3612
|
-
blendOver(data, idx, PANEL_LINE2, edge);
|
|
3613
|
-
}
|
|
3614
|
-
for (let i = 0;i < mask.dividerIndices.length; i += 1) {
|
|
3615
|
-
blendOver(data, mask.dividerIndices[i], PANEL_LINE2, 0.28);
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
var RIG_GLYPH_STROKES = {
|
|
3619
|
-
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]],
|
|
3620
|
-
I: [[0.5, 0, 0.5, 1], [0.18, 0, 0.82, 0], [0.18, 1, 0.82, 1]],
|
|
3621
|
-
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]]
|
|
3622
|
-
};
|
|
3623
|
-
function drawBigRigWordmark(data, width, height, layout, load) {
|
|
3624
|
-
const sideBySide = layout.width >= FLEET_GRID_WIDTH * 1.9;
|
|
3625
|
-
if (!sideBySide)
|
|
3626
|
-
return;
|
|
3627
|
-
const letters = "RIG";
|
|
3628
|
-
const min = Math.min(width, height);
|
|
3629
|
-
const glyphH = height * 0.42;
|
|
3630
|
-
const glyphW = width * 0.13;
|
|
3631
|
-
const gap = glyphW * 0.3;
|
|
3632
|
-
const totalW = letters.length * glyphW + (letters.length - 1) * gap;
|
|
3633
|
-
const centerX = width * 0.71;
|
|
3634
|
-
const startX = centerX - totalW / 2;
|
|
3635
|
-
const top = (height - glyphH) / 2;
|
|
3636
|
-
const stroke = Math.max(2, min * 0.013);
|
|
3637
|
-
drawGlow2(data, width, height, centerX, top + glyphH / 2, Math.max(glyphW, glyphH) * 0.9, LIME, 0.022 + load * 0.02);
|
|
3638
|
-
const strokeAlpha = 0.1 + load * 0.06;
|
|
3639
|
-
letters.split("").forEach((letter, index) => {
|
|
3640
|
-
const segments = RIG_GLYPH_STROKES[letter];
|
|
3641
|
-
if (!segments)
|
|
3642
|
-
return;
|
|
3643
|
-
const ox = startX + index * (glyphW + gap);
|
|
3644
|
-
for (const [x0, y0, x1, y1] of segments) {
|
|
3645
|
-
drawLine2(data, width, height, ox + x0 * glyphW, top + y0 * glyphH, ox + x1 * glyphW, top + y1 * glyphH, LIME_DIM, strokeAlpha, stroke);
|
|
3646
|
-
}
|
|
3647
|
-
});
|
|
3648
|
-
}
|
|
3649
|
-
function drawBackground(data, width, height, _tick, scene, layout, load, activeRuns) {
|
|
3650
|
-
fillRgba(data, BG, BG_WORD);
|
|
3651
|
-
drawStaticAsciiFleetBackground(data, width, height, scene, layout, load, activeRuns);
|
|
3652
|
-
drawBigRigWordmark(data, width, height, layout, load);
|
|
3653
|
-
applyStaticAtmosphere(data, width, height, load);
|
|
3654
|
-
}
|
|
3655
|
-
function imageVisualFrameKey(input) {
|
|
3656
|
-
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
3657
|
-
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
3658
|
-
const layer = "layer" in input ? input.layer ?? "full" : "full";
|
|
3659
|
-
const load = loadBucket(input.load);
|
|
3660
|
-
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("|")}`;
|
|
3661
|
-
}
|
|
3662
|
-
function encodeKittyFrame(width, height, data, input) {
|
|
3663
|
-
if (input.transport === "png") {
|
|
3664
|
-
const png = encodePng(width, height, data);
|
|
3665
|
-
return kittyImageSequence(png.toString("base64"), { columns: input.layout.width, rows: input.layout.height, imageId: input.imageId, zIndex: input.zIndex, format: 100 });
|
|
3666
|
-
}
|
|
3667
|
-
const compressed = deflateSync(data, { level: ZLIB_LEVEL });
|
|
3668
|
-
return kittyImageSequence(compressed.toString("base64"), {
|
|
3669
|
-
columns: input.layout.width,
|
|
3670
|
-
rows: input.layout.height,
|
|
3671
|
-
imageId: input.imageId,
|
|
3672
|
-
zIndex: input.zIndex,
|
|
3673
|
-
format: 32,
|
|
3674
|
-
pixelWidth: width,
|
|
3675
|
-
pixelHeight: height,
|
|
3676
|
-
compressed: true
|
|
3677
|
-
});
|
|
3678
|
-
}
|
|
3679
|
-
function cropRgba(data, sourceWidth, rect) {
|
|
3680
|
-
const out = new Uint8ClampedArray(rect.width * rect.height * 4);
|
|
3681
|
-
for (let y = 0;y < rect.height; y += 1) {
|
|
3682
|
-
const sourceStart = ((rect.top + y) * sourceWidth + rect.left) * 4;
|
|
3683
|
-
out.set(data.subarray(sourceStart, sourceStart + rect.width * 4), y * rect.width * 4);
|
|
3684
|
-
}
|
|
3685
|
-
return out;
|
|
3686
|
-
}
|
|
3687
|
-
function encodePanelPatch(data, sourceWidth, placement, imageId, zIndex) {
|
|
3688
|
-
const patch = cropRgba(data, sourceWidth, placement);
|
|
3689
|
-
const png = encodePng(placement.width, placement.height, patch);
|
|
3690
|
-
const sequence = kittyImageSequence(png.toString("base64"), {
|
|
3691
|
-
columns: Math.max(1, Math.round(placement.widthCells)),
|
|
3692
|
-
rows: Math.max(1, Math.round(placement.heightCells)),
|
|
3693
|
-
imageId,
|
|
3694
|
-
zIndex,
|
|
3695
|
-
format: 100
|
|
3696
|
-
});
|
|
3697
|
-
return `\x1B[${Math.max(1, Math.round(placement.topCells) + 1)};${Math.max(1, Math.round(placement.leftCells) + 1)}H${sequence}`;
|
|
3698
|
-
}
|
|
3699
|
-
function renderImageVisualFrame(input) {
|
|
3700
|
-
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
3701
|
-
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
3702
|
-
const byteCount = width * height * 4;
|
|
3703
|
-
if (byteCount > MAX_IMAGE_BYTES)
|
|
3704
|
-
return null;
|
|
3705
|
-
const layer = input.layer ?? "full";
|
|
3706
|
-
const data = new Uint8ClampedArray(byteCount);
|
|
3707
|
-
const load = loadBucket(input.load) / LOAD_BUCKETS;
|
|
3708
|
-
const activeRuns = Math.max(0, Math.floor(input.activeRuns ?? 0));
|
|
3709
|
-
drawBackground(data, width, height, 0, input.scene, input.layout, load, activeRuns);
|
|
3710
|
-
if (layer === "split") {
|
|
3711
|
-
const sequences = [encodeKittyFrame(width, height, data, input)];
|
|
3712
|
-
let panelIndex = 0;
|
|
3713
|
-
for (const panel of input.panels) {
|
|
3714
|
-
if (panel.chrome !== "ad-terminal")
|
|
3715
|
-
continue;
|
|
3716
|
-
const placement = panelPixelPlacement(input.layout, panel, { width, height });
|
|
3717
|
-
if (!placement)
|
|
3718
|
-
continue;
|
|
3719
|
-
const cellH = height / input.layout.height;
|
|
3720
|
-
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
3721
|
-
compositePanel(data, width, height, placement, headerPx);
|
|
3722
|
-
const imageId = input.imageIds?.[panelIndex] ?? (input.imageId + 1000 + panelIndex >>> 0 || panelIndex + 1);
|
|
3723
|
-
sequences.push(encodePanelPatch(data, width, placement, imageId, -12));
|
|
3724
|
-
panelIndex += 1;
|
|
3725
|
-
}
|
|
3726
|
-
return { key: imageVisualFrameKey(input), sequence: sequences.join("") };
|
|
3727
|
-
}
|
|
3728
|
-
if (layer === "panel-chrome")
|
|
3729
|
-
return { key: imageVisualFrameKey(input), sequence: "" };
|
|
3730
|
-
if (layer === "background") {
|
|
3731
|
-
return { key: imageVisualFrameKey(input), sequence: encodeKittyFrame(width, height, data, input) };
|
|
3732
|
-
}
|
|
3733
|
-
if (layer === "panel-patches") {
|
|
3734
|
-
const sequences = [];
|
|
3735
|
-
let panelIndex = 0;
|
|
3736
|
-
for (const panel of input.panels) {
|
|
3737
|
-
if (panel.chrome !== "ad-terminal")
|
|
3738
|
-
continue;
|
|
3739
|
-
const placement = panelPixelPlacement(input.layout, panel, { width, height });
|
|
3740
|
-
if (!placement)
|
|
3741
|
-
continue;
|
|
3742
|
-
const cellH = height / input.layout.height;
|
|
3743
|
-
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
3744
|
-
compositePanel(data, width, height, placement, headerPx);
|
|
3745
|
-
const imageId = input.imageIds?.[panelIndex] ?? (input.imageId + 1000 + panelIndex >>> 0 || panelIndex + 1);
|
|
3746
|
-
sequences.push(encodePanelPatch(data, width, placement, imageId, input.zIndex));
|
|
3747
|
-
panelIndex += 1;
|
|
3748
|
-
}
|
|
3749
|
-
return { key: imageVisualFrameKey(input), sequence: sequences.join("") };
|
|
3750
|
-
}
|
|
3751
|
-
for (const panel of input.panels) {
|
|
3752
|
-
if (panel.chrome !== "ad-terminal")
|
|
3753
|
-
continue;
|
|
3754
|
-
const rect = panelRect(input.layout, panel, { width, height });
|
|
3755
|
-
if (!rect)
|
|
3756
|
-
continue;
|
|
3757
|
-
const cellH = height / input.layout.height;
|
|
3758
|
-
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
3759
|
-
compositePanel(data, width, height, rect, headerPx);
|
|
3760
|
-
}
|
|
3761
|
-
return { key: imageVisualFrameKey(input), sequence: encodeKittyFrame(width, height, data, input) };
|
|
3762
|
-
}
|
|
3763
|
-
function shouldRenderImagesInline() {
|
|
3764
|
-
return process.env.RIG_OPENTUI_IMAGE_WORKER === "0" || import.meta.url.includes("$bunfs");
|
|
3765
|
-
}
|
|
3766
|
-
function createImageWorker() {
|
|
3767
|
-
if (shouldRenderImagesInline())
|
|
3768
|
-
return null;
|
|
3769
|
-
const isTypeScriptRuntime = import.meta.url.endsWith(".ts");
|
|
3770
|
-
const workerUrl = new URL(isTypeScriptRuntime ? "./image-visual-layer-worker.ts" : "./image-visual-layer-worker.js", import.meta.url);
|
|
3771
|
-
try {
|
|
3772
|
-
return new Worker(workerUrl);
|
|
3773
|
-
} catch {
|
|
3774
|
-
if (typeof process.versions.bun === "string") {
|
|
3775
|
-
try {
|
|
3776
|
-
return new Worker("./src/app-opentui/render/image-visual-layer-worker.ts");
|
|
3777
|
-
} catch {}
|
|
3778
|
-
}
|
|
3779
|
-
return null;
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
var RECENT_WRITTEN_LIMIT = 24;
|
|
3783
|
-
var DEFAULT_IMAGE_OUTPUT_BACKLOG_BYTES = 256 * 1024;
|
|
3784
|
-
var DEFAULT_IMAGE_OUTPUT_BYTES_PER_SECOND = 850 * 1024;
|
|
3785
|
-
function imageOutputBacklogBytes() {
|
|
3786
|
-
const raw = Number.parseInt(process.env.RIG_OPENTUI_IMAGE_BACKLOG_BYTES ?? "", 10);
|
|
3787
|
-
if (Number.isFinite(raw) && raw > 0)
|
|
3788
|
-
return Math.max(64 * 1024, Math.min(2 * 1024 * 1024, raw));
|
|
3789
|
-
return DEFAULT_IMAGE_OUTPUT_BACKLOG_BYTES;
|
|
3790
|
-
}
|
|
3791
|
-
function imageOutputBytesPerSecond() {
|
|
3792
|
-
const raw = Number.parseInt(process.env.RIG_OPENTUI_IMAGE_BYTES_PER_SECOND ?? "", 10);
|
|
3793
|
-
if (Number.isFinite(raw) && raw > 0)
|
|
3794
|
-
return Math.max(128 * 1024, Math.min(2 * 1024 * 1024, raw));
|
|
3795
|
-
return DEFAULT_IMAGE_OUTPUT_BYTES_PER_SECOND;
|
|
3796
|
-
}
|
|
3797
|
-
function pendingLayerKey(key) {
|
|
3798
|
-
return key.split(":", 1)[0] || "full";
|
|
3799
|
-
}
|
|
3800
|
-
|
|
3801
|
-
class ImageVisualLayer {
|
|
3802
|
-
imageId = allocateImageId();
|
|
3803
|
-
panelImageIds = Array.from({ length: 8 }, () => allocateImageId());
|
|
3804
|
-
panelChromeImageIds = Array.from({ length: 8 }, () => allocateImageId());
|
|
3805
|
-
stdout;
|
|
3806
|
-
onFrameReady;
|
|
3807
|
-
protocol;
|
|
3808
|
-
transport = imageTransport();
|
|
3809
|
-
maxOutputBacklogBytes = imageOutputBacklogBytes();
|
|
3810
|
-
outputBytesPerSecond = imageOutputBytesPerSecond();
|
|
3811
|
-
outputBudgetBytes = imageOutputBytesPerSecond();
|
|
3812
|
-
lastBudgetAtMs = Date.now();
|
|
3813
|
-
motionSlot = this.createSlot();
|
|
3814
|
-
workersStarted = false;
|
|
3815
|
-
pendingFrames = new Map;
|
|
3816
|
-
recentWrittenKeys = [];
|
|
3817
|
-
imagesVisible = false;
|
|
3818
|
-
flushPaused = false;
|
|
3819
|
-
requestId = 0;
|
|
3820
|
-
lastBackgroundKey = "";
|
|
3821
|
-
fatalWorkerError = null;
|
|
3822
|
-
destroyed = false;
|
|
3823
|
-
constructor(stdout = process.stdout, onFrameReady) {
|
|
3824
|
-
this.stdout = stdout;
|
|
3825
|
-
this.onFrameReady = onFrameReady;
|
|
3826
|
-
this.protocol = getRigTerminalCapabilities().imageProtocol;
|
|
3827
|
-
}
|
|
3828
|
-
get enabled() {
|
|
3829
|
-
return this.protocol === "kitty";
|
|
3830
|
-
}
|
|
3831
|
-
clear() {
|
|
3832
|
-
if (this.enabled) {
|
|
3833
|
-
if (this.imagesVisible)
|
|
3834
|
-
this.stdout.write([this.imageId, ...this.panelImageIds, ...this.panelChromeImageIds].map((id) => deleteKittyImage(id)).join("") + "\x1B[?25h");
|
|
3835
|
-
this.imagesVisible = false;
|
|
3836
|
-
this.pendingFrames.clear();
|
|
3837
|
-
this.recentWrittenKeys.length = 0;
|
|
3838
|
-
this.resetSlot(this.motionSlot);
|
|
3839
|
-
this.lastBackgroundKey = "";
|
|
3840
|
-
this.outputBudgetBytes = this.outputBytesPerSecond;
|
|
3841
|
-
this.lastBudgetAtMs = Date.now();
|
|
3842
|
-
this.motionSlot.clearedThroughRequestId = this.requestId;
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
destroy() {
|
|
3846
|
-
if (this.destroyed)
|
|
3847
|
-
return;
|
|
3848
|
-
this.clear();
|
|
3849
|
-
this.destroyed = true;
|
|
3850
|
-
const workers = [this.motionSlot.worker];
|
|
3851
|
-
this.motionSlot.worker = null;
|
|
3852
|
-
for (const worker of workers)
|
|
3853
|
-
if (worker)
|
|
3854
|
-
worker.terminate().catch(() => {
|
|
3855
|
-
return;
|
|
3856
|
-
});
|
|
3857
|
-
}
|
|
3858
|
-
setFlushPaused(paused) {
|
|
3859
|
-
this.flushPaused = paused;
|
|
3860
|
-
}
|
|
3861
|
-
isReady(input) {
|
|
3862
|
-
if (!this.enabled || this.destroyed)
|
|
3863
|
-
return true;
|
|
3864
|
-
this.throwIfFatal();
|
|
3865
|
-
const splitKey = imageVisualFrameKey({ ...input, tick: 0, layer: "split" });
|
|
3866
|
-
return this.recentWrittenKeys.includes(splitKey) || Array.from(this.pendingFrames.values()).some((frame) => frame.key === splitKey);
|
|
3867
|
-
}
|
|
3868
|
-
render(input) {
|
|
3869
|
-
if (!this.enabled || this.destroyed)
|
|
3870
|
-
return;
|
|
3871
|
-
this.throwIfFatal();
|
|
3872
|
-
if (this.transport !== "png")
|
|
3873
|
-
this.failWorker("renderer", new Error("OpenTUI image visuals require PNG transport for static-background rendering."));
|
|
3874
|
-
this.ensureWorkersStarted();
|
|
3875
|
-
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
3876
|
-
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
3877
|
-
if (width * height * 4 > MAX_IMAGE_BYTES)
|
|
3878
|
-
return;
|
|
3879
|
-
if (this.isOutputBackedUp())
|
|
3880
|
-
return;
|
|
3881
|
-
this.refillOutputBudget();
|
|
3882
|
-
const splitInput = { ...input, tick: 0, layer: "split" };
|
|
3883
|
-
const splitKey = imageVisualFrameKey(splitInput);
|
|
3884
|
-
if (input.force || splitKey !== this.lastBackgroundKey) {
|
|
3885
|
-
this.scheduleRender(this.motionSlot, splitInput, this.imageId, -30, input.force, this.panelImageIds);
|
|
3886
|
-
this.lastBackgroundKey = splitKey;
|
|
3887
|
-
}
|
|
3888
|
-
}
|
|
3889
|
-
flush() {
|
|
3890
|
-
this.throwIfFatal();
|
|
3891
|
-
if (this.flushPaused)
|
|
3892
|
-
return false;
|
|
3893
|
-
if (this.pendingFrames.size === 0)
|
|
3894
|
-
return false;
|
|
3895
|
-
this.refillOutputBudget();
|
|
3896
|
-
if (this.isOutputBackedUp()) {
|
|
3897
|
-
const retainedSplit = this.pendingFrames.get("split");
|
|
3898
|
-
this.pendingFrames.clear();
|
|
3899
|
-
if (retainedSplit)
|
|
3900
|
-
this.pendingFrames.set("split", retainedSplit);
|
|
3901
|
-
return false;
|
|
3902
|
-
}
|
|
3903
|
-
const framePriority = (frame) => {
|
|
3904
|
-
const layer = pendingLayerKey(frame.key);
|
|
3905
|
-
if (layer === "split")
|
|
3906
|
-
return 1;
|
|
3907
|
-
return 4;
|
|
3908
|
-
};
|
|
3909
|
-
const frames = Array.from(this.pendingFrames.values()).sort((a, b) => framePriority(a) - framePriority(b));
|
|
3910
|
-
const prefix = "\x1B[?25l\x1B7\x1B[s\x1B[H";
|
|
3911
|
-
const suffix = "\x1B[u\x1B8";
|
|
3912
|
-
const selected = [];
|
|
3913
|
-
const retained = new Map;
|
|
3914
|
-
let sequence = "";
|
|
3915
|
-
let byteLength = Buffer.byteLength(prefix + suffix);
|
|
3916
|
-
for (const frame of frames) {
|
|
3917
|
-
const candidate = sequence + frame.sequence;
|
|
3918
|
-
const candidateBytes = Buffer.byteLength(prefix + candidate + suffix);
|
|
3919
|
-
const layer = pendingLayerKey(frame.key);
|
|
3920
|
-
const allowOneStaticFrame = selected.length === 0 && layer === "split";
|
|
3921
|
-
if (candidateBytes <= this.outputBudgetBytes || allowOneStaticFrame) {
|
|
3922
|
-
selected.push(frame);
|
|
3923
|
-
sequence = candidate;
|
|
3924
|
-
byteLength = candidateBytes;
|
|
3925
|
-
} else if (layer === "split") {
|
|
3926
|
-
retained.set(layer, frame);
|
|
3927
|
-
}
|
|
3928
|
-
}
|
|
3929
|
-
this.pendingFrames.clear();
|
|
3930
|
-
for (const [layer, frame] of retained)
|
|
3931
|
-
this.pendingFrames.set(layer, frame);
|
|
3932
|
-
if (!sequence || selected.length === 0)
|
|
3933
|
-
return false;
|
|
3934
|
-
const payload = `${prefix}${sequence}${suffix}`;
|
|
3935
|
-
for (const frame of selected)
|
|
3936
|
-
this.markWritten(frame.key);
|
|
3937
|
-
this.outputBudgetBytes -= byteLength;
|
|
3938
|
-
this.stdout.cork?.();
|
|
3939
|
-
const accepted = this.stdout.write(payload);
|
|
3940
|
-
this.stdout.uncork?.();
|
|
3941
|
-
this.imagesVisible = true;
|
|
3942
|
-
return accepted;
|
|
3943
|
-
}
|
|
3944
|
-
createSlot() {
|
|
3945
|
-
return { worker: null, busy: false, queuedRequest: null, inFlightKey: "", queuedKey: "", clearedThroughRequestId: 0, latestRequestId: 0 };
|
|
3946
|
-
}
|
|
3947
|
-
resetSlot(slot) {
|
|
3948
|
-
slot.busy = false;
|
|
3949
|
-
slot.queuedRequest = null;
|
|
3950
|
-
slot.inFlightKey = "";
|
|
3951
|
-
slot.queuedKey = "";
|
|
3952
|
-
}
|
|
3953
|
-
markWritten(key) {
|
|
3954
|
-
this.recentWrittenKeys.push(key);
|
|
3955
|
-
while (this.recentWrittenKeys.length > RECENT_WRITTEN_LIMIT)
|
|
3956
|
-
this.recentWrittenKeys.shift();
|
|
3957
|
-
}
|
|
3958
|
-
refillOutputBudget() {
|
|
3959
|
-
const now = Date.now();
|
|
3960
|
-
const elapsedMs = Math.max(0, now - this.lastBudgetAtMs);
|
|
3961
|
-
this.lastBudgetAtMs = now;
|
|
3962
|
-
this.outputBudgetBytes = Math.min(this.outputBytesPerSecond, this.outputBudgetBytes + elapsedMs / 1000 * this.outputBytesPerSecond);
|
|
3963
|
-
}
|
|
3964
|
-
isOutputBackedUp() {
|
|
3965
|
-
return Boolean(this.stdout.writableNeedDrain) || this.stdout.writableLength > this.maxOutputBacklogBytes;
|
|
3966
|
-
}
|
|
3967
|
-
stageFrame(frame) {
|
|
3968
|
-
this.pendingFrames.set(pendingLayerKey(frame.key), frame);
|
|
3969
|
-
}
|
|
3970
|
-
isKnownKey(slot, key) {
|
|
3971
|
-
return this.recentWrittenKeys.includes(key) || Array.from(this.pendingFrames.values()).some((frame) => frame.key === key) || key === slot.inFlightKey || key === slot.queuedKey;
|
|
3972
|
-
}
|
|
3973
|
-
ensureWorkersStarted() {
|
|
3974
|
-
if (this.workersStarted)
|
|
3975
|
-
return;
|
|
3976
|
-
this.workersStarted = true;
|
|
3977
|
-
this.startWorker(this.motionSlot, "static-visuals");
|
|
3978
|
-
}
|
|
3979
|
-
failWorker(name, error) {
|
|
3980
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
3981
|
-
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} failed: ${detail}`);
|
|
3982
|
-
throw this.fatalWorkerError;
|
|
3983
|
-
}
|
|
3984
|
-
throwIfFatal() {
|
|
3985
|
-
if (this.fatalWorkerError)
|
|
3986
|
-
throw this.fatalWorkerError;
|
|
3987
|
-
}
|
|
3988
|
-
scheduleRender(slot, input, imageId, zIndex, force, imageIds) {
|
|
3989
|
-
this.throwIfFatal();
|
|
3990
|
-
const key = imageVisualFrameKey(input);
|
|
3991
|
-
if (!force && this.isKnownKey(slot, key))
|
|
3992
|
-
return;
|
|
3993
|
-
const request = {
|
|
3994
|
-
...input,
|
|
3995
|
-
imageId,
|
|
3996
|
-
...imageIds ? { imageIds } : {},
|
|
3997
|
-
zIndex,
|
|
3998
|
-
transport: this.transport,
|
|
3999
|
-
requestId: ++this.requestId,
|
|
4000
|
-
key
|
|
4001
|
-
};
|
|
4002
|
-
slot.latestRequestId = request.requestId;
|
|
4003
|
-
if (!slot.worker) {
|
|
4004
|
-
this.renderInline(slot, request);
|
|
4005
|
-
return;
|
|
4006
|
-
}
|
|
4007
|
-
this.enqueueWorkerRender(slot, request);
|
|
4008
|
-
}
|
|
4009
|
-
startWorker(slot, name) {
|
|
4010
|
-
const worker = createImageWorker();
|
|
4011
|
-
if (!worker)
|
|
4012
|
-
return;
|
|
4013
|
-
slot.worker = worker;
|
|
4014
|
-
worker.on("message", (message) => this.handleWorkerMessage(slot, message));
|
|
4015
|
-
worker.once("error", (error) => {
|
|
4016
|
-
if (!this.destroyed)
|
|
4017
|
-
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
4018
|
-
});
|
|
4019
|
-
worker.once("exit", (code) => {
|
|
4020
|
-
if (!this.destroyed)
|
|
4021
|
-
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} exited unexpectedly with code ${code}.`);
|
|
4022
|
-
});
|
|
4023
|
-
}
|
|
4024
|
-
renderInline(slot, request) {
|
|
4025
|
-
try {
|
|
4026
|
-
const result = renderImageVisualFrame(request);
|
|
4027
|
-
if (result?.sequence && !this.isKnownKey(slot, result.key) && (!this.isOutputBackedUp() || pendingLayerKey(result.key) === "split")) {
|
|
4028
|
-
this.stageFrame({ key: result.key, sequence: result.sequence });
|
|
4029
|
-
this.onFrameReady?.();
|
|
4030
|
-
}
|
|
4031
|
-
} catch (error) {
|
|
4032
|
-
this.failWorker(String(request.layer ?? "visual"), error);
|
|
4033
|
-
}
|
|
4034
|
-
}
|
|
4035
|
-
enqueueWorkerRender(slot, request) {
|
|
4036
|
-
this.throwIfFatal();
|
|
4037
|
-
if (slot.busy) {
|
|
4038
|
-
slot.queuedRequest = request;
|
|
4039
|
-
slot.queuedKey = request.key;
|
|
4040
|
-
return;
|
|
4041
|
-
}
|
|
4042
|
-
this.dispatchWorkerRender(slot, request);
|
|
4043
|
-
}
|
|
4044
|
-
dispatchWorkerRender(slot, request) {
|
|
4045
|
-
this.throwIfFatal();
|
|
4046
|
-
if (!slot.worker)
|
|
4047
|
-
this.failWorker(String(request.layer ?? "visual"), new Error("worker is unavailable"));
|
|
4048
|
-
slot.busy = true;
|
|
4049
|
-
slot.inFlightKey = request.key;
|
|
4050
|
-
try {
|
|
4051
|
-
slot.worker.postMessage(request);
|
|
4052
|
-
} catch (error) {
|
|
4053
|
-
this.failWorker(String(request.layer ?? "visual"), error);
|
|
4054
|
-
}
|
|
4055
|
-
}
|
|
4056
|
-
handleWorkerMessage(slot, message) {
|
|
4057
|
-
if (this.destroyed || !message || typeof message !== "object")
|
|
4058
|
-
return;
|
|
4059
|
-
const response = message;
|
|
4060
|
-
slot.busy = false;
|
|
4061
|
-
slot.inFlightKey = "";
|
|
4062
|
-
const isStale = response.requestId <= slot.clearedThroughRequestId || response.requestId < slot.latestRequestId;
|
|
4063
|
-
if (!isStale) {
|
|
4064
|
-
if (response.error)
|
|
4065
|
-
this.failWorker(pendingLayerKey(response.key), new Error(response.error));
|
|
4066
|
-
if (response.sequence && !this.isKnownKey(slot, response.key) && (!this.isOutputBackedUp() || pendingLayerKey(response.key) === "split")) {
|
|
4067
|
-
this.stageFrame({ key: response.key, sequence: response.sequence });
|
|
4068
|
-
this.onFrameReady?.();
|
|
4069
|
-
}
|
|
4070
|
-
}
|
|
4071
|
-
const next = slot.queuedRequest;
|
|
4072
|
-
slot.queuedRequest = null;
|
|
4073
|
-
slot.queuedKey = "";
|
|
4074
|
-
if (next && !this.isKnownKey(slot, next.key))
|
|
4075
|
-
this.dispatchWorkerRender(slot, next);
|
|
4076
|
-
}
|
|
4077
|
-
}
|
|
4078
|
-
function pixelSizeForRenderer(renderer) {
|
|
4079
|
-
const resolution = renderer.resolution;
|
|
4080
|
-
const base = resolution?.width && resolution?.height ? resolution : { width: renderer.width * 12, height: renderer.height * 24 };
|
|
4081
|
-
const scale = imageResolutionScale();
|
|
4082
|
-
return {
|
|
4083
|
-
width: Math.max(renderer.width, Math.floor(base.width * scale)),
|
|
4084
|
-
height: Math.max(renderer.height, Math.floor(base.height * scale))
|
|
4085
|
-
};
|
|
4086
|
-
}
|
|
4087
|
-
function forceModernImageVisuals() {
|
|
4088
|
-
return getRigTerminalCapabilities().supportsKittyImages;
|
|
4089
|
-
}
|
|
4090
|
-
|
|
4091
3105
|
// packages/cli/src/app-opentui/render/text.ts
|
|
4092
3106
|
import { RGBA as RGBA4, TextAttributes as TextAttributes4, TextRenderable } from "@opentui/core";
|
|
4093
3107
|
var TRANSPARENT2 = RGBA4.fromInts(0, 0, 0, 0);
|
|
@@ -4723,68 +3737,42 @@ function isTerminalScene(scene) {
|
|
|
4723
3737
|
}
|
|
4724
3738
|
function Backdrop(props) {
|
|
4725
3739
|
const renderer = useRenderer();
|
|
4726
|
-
const imageRef = useRef(null);
|
|
4727
3740
|
const graphicsRef = useRef(null);
|
|
4728
3741
|
useEffect(() => {
|
|
4729
|
-
const
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
const layout = computeStageLayout(renderer.width, renderer.height);
|
|
4734
|
-
const graphics = createGraphicsLayer(renderer, layout);
|
|
4735
|
-
renderer.root.add(graphics);
|
|
4736
|
-
graphicsRef.current = graphics;
|
|
4737
|
-
}
|
|
3742
|
+
const layout = computeStageLayout(renderer.width, renderer.height);
|
|
3743
|
+
const graphics = createGraphicsLayer(renderer, layout);
|
|
3744
|
+
renderer.root.add(graphics);
|
|
3745
|
+
graphicsRef.current = graphics;
|
|
4738
3746
|
return () => {
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
if (graphics) {
|
|
3747
|
+
const g = graphicsRef.current;
|
|
3748
|
+
if (g) {
|
|
4742
3749
|
try {
|
|
4743
|
-
renderer.root.remove(
|
|
3750
|
+
renderer.root.remove(g.id);
|
|
4744
3751
|
} catch {}
|
|
4745
3752
|
}
|
|
4746
|
-
imageRef.current = null;
|
|
4747
3753
|
graphicsRef.current = null;
|
|
4748
3754
|
};
|
|
4749
3755
|
}, [renderer]);
|
|
4750
3756
|
useEffect(() => {
|
|
4751
|
-
const layout = computeStageLayout(renderer.width, renderer.height);
|
|
4752
|
-
const image = imageRef.current;
|
|
4753
3757
|
const graphics = graphicsRef.current;
|
|
3758
|
+
if (!graphics)
|
|
3759
|
+
return;
|
|
3760
|
+
const layout = computeStageLayout(renderer.width, renderer.height);
|
|
4754
3761
|
if (layout.tooSmall) {
|
|
4755
|
-
|
|
4756
|
-
if (graphics)
|
|
4757
|
-
clearGraphicsLayer(graphics);
|
|
3762
|
+
clearGraphicsLayer(graphics);
|
|
4758
3763
|
return;
|
|
4759
3764
|
}
|
|
4760
3765
|
const stats = fleetStatsFromState(props.state);
|
|
4761
|
-
const
|
|
4762
|
-
const animationTick = Math.floor(tick / ANIMATION_SLOWDOWN);
|
|
3766
|
+
const animationTick = Math.floor(props.state.tick / ANIMATION_SLOWDOWN);
|
|
4763
3767
|
const panels = (props.frame.panels ?? []).map((panel) => ({ ...panel }));
|
|
4764
3768
|
const terminalActive = props.frame.terminalActive ?? isTerminalScene(props.state.scene);
|
|
4765
3769
|
const fullScreen = Boolean(props.frame.fullScreen);
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
pixelSize: pixelSizeForRenderer(renderer),
|
|
4773
|
-
panels,
|
|
4774
|
-
scene: props.state.scene,
|
|
4775
|
-
tick,
|
|
4776
|
-
load: stats.load,
|
|
4777
|
-
activeRuns: stats.active
|
|
4778
|
-
});
|
|
4779
|
-
}
|
|
4780
|
-
} else if (graphics) {
|
|
4781
|
-
resizeGraphicsLayer(graphics, layout);
|
|
4782
|
-
if (terminalActive || fullScreen) {
|
|
4783
|
-
clearGraphicsLayer(graphics);
|
|
4784
|
-
} else {
|
|
4785
|
-
drawAmbientField(graphics, layout, animationTick, props.state.scene, stats.load, stats.active);
|
|
4786
|
-
drawPanelChrome(graphics, layout, panels);
|
|
4787
|
-
}
|
|
3770
|
+
resizeGraphicsLayer(graphics, layout);
|
|
3771
|
+
if (terminalActive || fullScreen) {
|
|
3772
|
+
clearGraphicsLayer(graphics);
|
|
3773
|
+
} else {
|
|
3774
|
+
drawAmbientField(graphics, layout, animationTick, props.state.scene, stats.load, stats.active);
|
|
3775
|
+
drawPanelChrome(graphics, layout, panels);
|
|
4788
3776
|
}
|
|
4789
3777
|
});
|
|
4790
3778
|
return null;
|