Commit ·
b411d2a
1
Parent(s): be7997c
proto6
Browse files
app.py
CHANGED
|
@@ -578,29 +578,59 @@ INDEX_JS = r"""
|
|
| 578 |
}
|
| 579 |
|
| 580 |
// Each cell is 2 stones wide; the five cells fill the board's width, so the
|
| 581 |
-
// stone size is
|
| 582 |
-
//
|
| 583 |
function sizeBoard() {
|
| 584 |
const board = document.getElementById("bb-board");
|
| 585 |
const wrap = document.getElementById("bb-wrap");
|
| 586 |
if (!board || !wrap) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
const cs = getComputedStyle(board);
|
| 588 |
const inner = board.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
|
| 589 |
const cellGap = 8, cellPad = 6, colGap = 6; // must match the CSS
|
| 590 |
const cellOuter = (inner - 4 * cellGap) / 5;
|
| 591 |
-
let
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
//
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 601 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
}
|
| 603 |
window.addEventListener("resize", sizeBoard);
|
|
|
|
|
|
|
| 604 |
|
| 605 |
function announceEnd(node) {
|
| 606 |
const titleEl = document.getElementById("bb-end-title");
|
|
|
|
| 578 |
}
|
| 579 |
|
| 580 |
// Each cell is 2 stones wide; the five cells fill the board's width, so the
|
| 581 |
+
// stone size is bounded by width AND by the viewport height. Recomputed on
|
| 582 |
+
// every render and on resize (keeps stones as large as the space allows).
|
| 583 |
function sizeBoard() {
|
| 584 |
const board = document.getElementById("bb-board");
|
| 585 |
const wrap = document.getElementById("bb-wrap");
|
| 586 |
if (!board || !wrap) return;
|
| 587 |
+
// A backgrounded/hidden tab (and an iframe before it is laid out) reports
|
| 588 |
+
// innerHeight 0 and zero-size rects. Measuring then would "fit" nothing and
|
| 589 |
+
// collapse every stone to the minimum, so bail out and keep the current size
|
| 590 |
+
// — the visibilitychange listener below re-runs this once we are visible.
|
| 591 |
+
if (!window.innerHeight || !board.clientWidth) return;
|
| 592 |
const cs = getComputedStyle(board);
|
| 593 |
const inner = board.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
|
| 594 |
const cellGap = 8, cellPad = 6, colGap = 6; // must match the CSS
|
| 595 |
const cellOuter = (inner - 4 * cellGap) / 5;
|
| 596 |
+
let hi = Math.floor((cellOuter - 2 * cellPad - colGap) / 2); // largest that fits the width
|
| 597 |
+
hi = Math.max(14, Math.min(120, hi));
|
| 598 |
+
|
| 599 |
+
// Test the goal itself — "the whole page fits the viewport" — instead of a
|
| 600 |
+
// proxy like "the board fits below its own top edge". Gradio wraps the board
|
| 601 |
+
// in containers whose padding/margins live BELOW it, so a board that fits on
|
| 602 |
+
// its own can still leave the document scrollable. scrollHeight is content
|
| 603 |
+
// height and is independent of scroll position, so this cannot run away.
|
| 604 |
+
const fitsViewport = () => document.documentElement.scrollHeight <= window.innerHeight;
|
| 605 |
+
|
| 606 |
+
// Page height is NOT proportional to --bs (fixed paddings, gaps, numrows and
|
| 607 |
+
// kazan minimums add a constant), so scaling by a ratio only converges by
|
| 608 |
+
// luck. Binary-search the largest --bs that still fits. Monotonic: a larger
|
| 609 |
+
// stone can never make the page shorter.
|
| 610 |
+
wrap.style.setProperty("--bs", hi + "px");
|
| 611 |
+
let bs = hi;
|
| 612 |
+
if (!fitsViewport()) {
|
| 613 |
+
let lo = 14;
|
| 614 |
+
for (let i = 0; i < 16; i++) {
|
| 615 |
+
const mid = (lo + hi) / 2;
|
| 616 |
+
wrap.style.setProperty("--bs", mid + "px");
|
| 617 |
+
if (fitsViewport()) lo = mid; else hi = mid;
|
| 618 |
+
}
|
| 619 |
+
bs = Math.max(14, Math.floor(lo));
|
| 620 |
}
|
| 621 |
+
wrap.style.setProperty("--bs", bs + "px");
|
| 622 |
+
|
| 623 |
+
// The row is as tall as its tallest column, so bounding the board alone is
|
| 624 |
+
// not enough — on a short viewport the sidebar (language, actions, AI panel,
|
| 625 |
+
// history) could be the one that overflows. Hold it to the board's height;
|
| 626 |
+
// its AI card and history list both scroll internally. Side-by-side layout
|
| 627 |
+
// only: stacked mobile scrolls the page normally.
|
| 628 |
+
const side = document.getElementById("bb-side");
|
| 629 |
+
if (side) side.style.maxHeight = window.innerWidth > 860 ? board.offsetHeight + "px" : "";
|
| 630 |
}
|
| 631 |
window.addEventListener("resize", sizeBoard);
|
| 632 |
+
// Sizing is skipped while hidden (no usable measurements) — redo it on return.
|
| 633 |
+
document.addEventListener("visibilitychange", () => { if (!document.hidden) sizeBoard(); });
|
| 634 |
|
| 635 |
function announceEnd(node) {
|
| 636 |
const titleEl = document.getElementById("bb-end-title");
|