Skip to content

Commit

Permalink
Optimization: cache container aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
reindernijhoff committed Jan 6, 2025
1 parent 38e900a commit d3a819d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/FastImageSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export class FastImageSequence {
private initialized: boolean = false;
private posterImage: HTMLImageElement | undefined;
private timeFrameVisible: number = 0;

private inViewport: boolean = false;
private containerWidth: number = 0;
private containerHeight: number = 0;

/**
* Creates an instance of FastImageSequence.
Expand Down Expand Up @@ -126,6 +129,8 @@ export class FastImageSequence {

this.resizeObserver = new ResizeObserver(() => {
this.clearCanvas = true;
this.containerWidth = container.offsetWidth;
this.containerHeight = container.offsetHeight;
if (this.lastFrameDrawn < 0 && this.posterImage) {
this.drawImage(this.posterImage);
}
Expand Down Expand Up @@ -457,7 +462,7 @@ export class FastImageSequence {
// @ts-ignore
const imageHeight = image.naturalHeight || image.height || image.videoHeight;

const containerAspect = this.container.offsetWidth / this.container.offsetHeight;
const containerAspect = this.containerWidth / this.containerHeight;
const imageAspect = imageWidth / imageHeight;

this.width = Math.max(this.width, imageWidth);
Expand Down

0 comments on commit d3a819d

Please sign in to comment.