feat(simulation): record viewport resizes (#36306)

This commit is contained in:
James Long 2026-07-10 15:08:43 -04:00 committed by GitHub
commit be18f22842
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 90 additions and 11 deletions

View file

@ -21,7 +21,15 @@ export const Output = Schema.Struct({
})
export interface Output extends Schema.Schema.Type<typeof Output> {}
export const Event = Schema.Union([Header, Output])
export const Resize = Schema.Struct({
type: Schema.Literal("resize"),
at_ms: Schema.Number,
cols: Schema.Number,
rows: Schema.Number,
})
export interface Resize extends Schema.Schema.Type<typeof Resize> {}
export const Event = Schema.Union([Header, Output, Resize])
export type Event = Schema.Schema.Type<typeof Event>
export class Timeline extends Writable {
@ -98,6 +106,12 @@ export class Timeline extends Writable {
return this.done
}
resize(cols: number, rows: number) {
if (this.writableEnded) return
const event = { type: "resize", at_ms: this.elapsed(), cols, rows } satisfies Resize
this.output.write(`${JSON.stringify(event)}\n`)
}
private elapsed() {
return Math.max(0, Math.round(performance.now() - this.started))
}