import { EventEmitter } from "./EventEmitter";
export class Sizes extends EventEmitter {
  constructor({ canvas }) {
    super();
    this.canvas = canvas;
    this.maxPixelRatio = 1;
    this.handleResize = () => {
      this.init();
      this.emit("resize");
    };
    this.init();
    window.addEventListener("resize", this.handleResize);
  }
  init() {
    const target = this.canvas?.parentNode || this.canvas || document.documentElement;
    this.width = target.offsetWidth || window.innerWidth || 1;
    this.height = target.offsetHeight || window.innerHeight || 1;
    this.pixelRatio = Math.min(window.devicePixelRatio || 1, this.maxPixelRatio);
  }
  destroy() {
    window.removeEventListener("resize", this.handleResize);
    this.off("resize");
  }
}
