feat(simulation): record viewport resizes (#36306)
This commit is contained in:
parent
6216dbae15
commit
be18f22842
8 changed files with 90 additions and 11 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue