Convert JSDoc to line comments

This commit is contained in:
Anthony Kim
2026-02-15 19:21:27 -08:00
parent ee85a1da9e
commit 5efff43e93
3 changed files with 36 additions and 62 deletions
@@ -35,9 +35,7 @@ const MAX_CONTROL_DATA_SIZE = 512;
// Semicolon codepoint // Semicolon codepoint
const SEMICOLON = 0x3B; const SEMICOLON = 0x3B;
/** // Kitty graphics protocol handler with streaming base64 decoding.
* Kitty graphics protocol handler with streaming base64 decoding.
*/
export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDisposable { export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDisposable {
private _aborted = false; private _aborted = false;
private _decodeError = false; private _decodeError = false;
@@ -48,28 +46,26 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
// Streaming related states // Streaming related states
/** True while receiving control data (before semicolon). */ // True while receiving control data (before semicolon).
private _inControlData = true; private _inControlData = true;
/** Buffer for control data. */ // Buffer for control data.
private _controlData = new Uint32Array(MAX_CONTROL_DATA_SIZE); private _controlData = new Uint32Array(MAX_CONTROL_DATA_SIZE);
private _controlLength = 0; private _controlLength = 0;
/** Pre-calculated encoded size limit */ // Pre-calculated encoded size limit
private _encodedSizeLimit = 0; private _encodedSizeLimit = 0;
private _totalEncodedSize = 0; private _totalEncodedSize = 0;
/** Parsed command. These are the control data before semicolon. */ // Parsed command. These are the control data before semicolon.
private _parsedCommand: IKittyCommand | null = null; private _parsedCommand: IKittyCommand | null = null;
// Storage related states // Storage related states
private _pendingTransmissions: Map<number, IPendingTransmission> = new Map(); private _pendingTransmissions: Map<number, IPendingTransmission> = new Map();
/** // Tracks the pending key of the most recently started chunked upload.
* Tracks the pending key of the most recently started chunked upload. // Per spec, subsequent chunks only need m= (and optionally q=), without i=.
* Per spec, subsequent chunks only need m= (and optionally q=), without i=. // When a chunk arrives with no i=, this key is used to find the pending upload.
* When a chunk arrives with no i=, this key is used to find the pending upload.
*/
private _lastPendingKey: number | undefined; private _lastPendingKey: number | undefined;
constructor( constructor(
@@ -163,9 +159,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
} }
} }
/** // Stream payload bytes into the base64 decoder.
* Stream payload bytes into the base64 decoder.
*/
private _streamPayload(data: Uint32Array, start: number, end: number): void { private _streamPayload(data: Uint32Array, start: number, end: number): void {
if (this._aborted) return; if (this._aborted) return;
@@ -601,9 +595,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
} }
} }
/** // Create ImageBitmap from already-decoded image data.
* Create ImageBitmap from already-decoded image data.
*/
private async _createBitmap(image: IKittyImageData): Promise<ImageBitmap> { private async _createBitmap(image: IKittyImageData): Promise<ImageBitmap> {
let bytes: Uint8Array = new Uint8Array(await image.data.arrayBuffer()); let bytes: Uint8Array = new Uint8Array(await image.data.arrayBuffer());
@@ -7,10 +7,8 @@
import type Base64Decoder from 'xterm-wasm-parts/lib/base64/Base64Decoder.wasm'; import type Base64Decoder from 'xterm-wasm-parts/lib/base64/Base64Decoder.wasm';
/** // Kitty graphics protocol action types.
* Kitty graphics protocol action types. // See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference under key 'a'.
* See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference under key 'a'.
*/
export const enum KittyAction { export const enum KittyAction {
TRANSMIT = 't', TRANSMIT = 't',
TRANSMIT_DISPLAY = 'T', TRANSMIT_DISPLAY = 'T',
@@ -19,29 +17,23 @@ export const enum KittyAction {
DELETE = 'd' DELETE = 'd'
} }
/** // Kitty graphics protocol format types.
* Kitty graphics protocol format types. // See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference
* See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference
*/
export const enum KittyFormat { export const enum KittyFormat {
RGB = 24, RGB = 24,
RGBA = 32, RGBA = 32,
PNG = 100 PNG = 100
} }
/** // Kitty graphics protocol compression types.
* Kitty graphics protocol compression types. // See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference under key 'o'.
* See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference under key 'o'.
*/
export const enum KittyCompression { export const enum KittyCompression {
NONE = '', NONE = '',
ZLIB = 'z' ZLIB = 'z'
} }
/** // Kitty graphics protocol control data keys.
* Kitty graphics protocol control data keys. // See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference
* See: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference
*/
export const enum KittyKey { export const enum KittyKey {
// Action to perform (t=transmit, T=transmit+display, q=query, p=placement, d=delete) // Action to perform (t=transmit, T=transmit+display, q=query, p=placement, d=delete)
ACTION = 'a', ACTION = 'a',
@@ -86,9 +78,7 @@ export const BYTES_PER_PIXEL_RGB = 3;
export const BYTES_PER_PIXEL_RGBA = 4; export const BYTES_PER_PIXEL_RGBA = 4;
export const ALPHA_OPAQUE = 255; export const ALPHA_OPAQUE = 255;
/** // Parsed Kitty graphics command.
* Parsed Kitty graphics command.
*/
export interface IKittyCommand { export interface IKittyCommand {
action?: string; action?: string;
format?: number; format?: number;
@@ -111,27 +101,23 @@ export interface IKittyCommand {
payload?: string; payload?: string;
} }
/** // Pending chunked transmission state.
* Pending chunked transmission state. // Stores metadata from the first chunk while accumulating decoded payload data.
* Stores metadata from the first chunk while accumulating decoded payload data.
*/
export interface IPendingTransmission { export interface IPendingTransmission {
/** The parsed command from the first chunk (contains action, format, dimensions, etc.) */ // The parsed command from the first chunk (contains action, format, dimensions, etc.)
cmd: IKittyCommand; cmd: IKittyCommand;
/** Decoder used across chunked payloads */ // Decoder used across chunked payloads
decoder: Base64Decoder; decoder: Base64Decoder;
/** Total encoded (base64) bytes received across all chunks - for size limit enforcement */ // Total encoded (base64) bytes received across all chunks - for size limit enforcement
totalEncodedSize: number; totalEncodedSize: number;
/** Whether any chunk has failed to decode */ // Whether any chunk has failed to decode
decodeError: boolean; decodeError: boolean;
} }
/** // Stored Kitty image data.
* Stored Kitty image data.
*/
export interface IKittyImageData { export interface IKittyImageData {
id: number; id: number;
/** Decoded image data stored as Blob (off JS heap) to avoid 2GB heap limit */ // Decoded image data stored as Blob (off JS heap) to avoid 2GB heap limit
data: Blob; data: Blob;
width: number; width: number;
height: number; height: number;
@@ -139,9 +125,7 @@ export interface IKittyImageData {
compression?: string; compression?: string;
} }
/** // Parses Kitty graphics control data into a command object.
* Parses Kitty graphics control data into a command object.
*/
export function parseKittyCommand(data: string): IKittyCommand { export function parseKittyCommand(data: string): IKittyCommand {
const cmd: IKittyCommand = {}; const cmd: IKittyCommand = {};
const parts = data.split(','); const parts = data.split(',');
@@ -8,15 +8,13 @@ import { ImageStorage } from '../ImageStorage';
import { ImageLayer } from '../Types'; import { ImageLayer } from '../Types';
import { IKittyImageData } from './KittyGraphicsTypes'; import { IKittyImageData } from './KittyGraphicsTypes';
/** // Kitty-specific image storage controller.
* Kitty-specific image storage controller. //
* // Wraps shared ImageStorage with kitty protocol semantics:
* Wraps shared ImageStorage with kitty protocol semantics: // - tracks transmitted image payloads by kitty image id
* - tracks transmitted image payloads by kitty image id // - tracks kitty image id -> shared ImageStorage id mapping for displayed images
* - tracks kitty image id -> shared ImageStorage id mapping for displayed images // - mirrors shared-storage evictions into kitty maps
* - mirrors shared-storage evictions into kitty maps // - applies protocol-level undisplayed-image eviction policy
* - applies protocol-level undisplayed-image eviction policy
*/
export class KittyImageStorage implements IDisposable { export class KittyImageStorage implements IDisposable {
private static readonly _maxStoredImages = 256; private static readonly _maxStoredImages = 256;
@@ -128,4 +126,4 @@ export class KittyImageStorage implements IDisposable {
} }
} }
} }
} }