- const r = chessboard.getBoundingClientRect();
- const newRatio = r.width / r.height;
- let newWidth = r.width,
- newHeight = r.height;
- if (newRatio > this.size.ratio) {
- newWidth = r.height * this.size.ratio;
- chessboard.style.width = newWidth + "px";
- }
- else if (newRatio < this.size.ratio) {
- newHeight = r.width / this.size.ratio;
- chessboard.style.height = newHeight + "px";
- }
+ let r = chessboard.getBoundingClientRect();
+ let [newWidth, newHeight] = [r.width, r.height];
+ // Stay in window:
+ if (newWidth > window.innerWidth)
+ newWidth = window.innerWidth;
+ if (newHeight > window.innerHeight)
+ newHeight = window.innerHeight;
+ const newRatio = newWidth / newHeight;
+ if (newRatio > self.size.ratio)
+ newWidth = newHeight * self.size.ratio;
+ else if (newRatio < self.size.ratio)
+ newHeight = newWidth / self.size.ratio;
+ chessboard.style.width = newWidth + "px";
+ chessboard.style.height = newHeight + "px";