// THE SOURCE STATUS NEVER DRAWS CUT (lane source-status, review 1 finding 6). // // A deck's source line is one nowrap row that clips what it cannot hold // (chrome-deck.mjs .deck-sub: flex, overflow hidden). The title gives way first; // the channel holds up to 40 % of the line; the date, the clock and the status // never shrink. So in a narrow column (a tally beside the QR, a long channel) the // row's TAIL is cut -- "now members-only (public wh" -- which is worse than no // status at all. This is the page's fit, run once the faces are in (the same // moment the title's fit runs), on every line that carries a status: // // 1. the whole words, when the row holds them and the source's title keeps at // least TITLE_KEEP_EM of itself (or all of itself); // 2. the short form -- the state alone, "now members-only", no parenthesis -- // when the row holds that; // 3. the same with the channel giving way too (it ellipsizes); // 4. nothing: the status and its separator are not drawn. // // The finale's caption (`.cs`, two wrapped lines, the title last) is a block, not // a row: a status that is not wholly inside its two lines takes the short form, // then nothing. Never a cut status, in either. // // `fitStatusLine` is a plain function so the page carries its own source // (`fitStatusLine.toString()`, chrome-deck.mjs / chrome-finale.mjs) and a test can // drive it over a stand-in for the DOM. It touches only what it is given: the // line's `querySelector`, `classList`, `scrollWidth` / `clientWidth`, and the // parts' text, attributes, offsets and style. No closure: the page has none. /** The least of the source's title, in em of the line, that the whole status may squeeze it to. */ export const TITLE_KEEP_EM = 6; /** * The status's short form: its state words, the parenthesis dropped (source-status.mjs * SOURCE_STATUS_WORDS: "now private (public when streamed)" -> "now private"), or * null when it has none to drop. */ export function statusShortForm(words) { const i = String(words ?? "").indexOf(" ("); return i > 0 ? String(words).slice(0, i) : null; } /** * Fit one line's status (see the header). Returns what it drew: "long", "short", * "short-channel" (the channel gave way too), "none" (dropped), or "absent" (no * status on the line). * * @param {any} line a `.deck-sub` / `.dts` row, or a `.cs` block (`mode: "block"`) * @param {number} em the line's font size, px * @param {"row"|"block"} [mode] * @param {number} [keepEm] TITLE_KEEP_EM (passed: the page's copy has no imports) */ export function fitStatusLine(line, em, mode = "row", keepEm = 6) { const st = line.querySelector('.part[data-p="status"]'); if (!st) return "absent"; if (!st.hasAttribute("data-full")) st.setAttribute("data-full", st.textContent); const full = st.getAttribute("data-full"); const short = st.getAttribute("data-short"); // The separator that joins the status to the line: the one before it, else (first in the line) the one after. const prev = st.previousElementSibling; const next = st.nextElementSibling; const sep = prev && prev.classList.contains("sep") ? prev : next && next.classList.contains("sep") ? next : null; // From the start, so a second fit (the live preview's) reads the line as drawn. st.textContent = full; st.style.display = ""; if (sep) sep.style.display = ""; line.classList.remove("st-give"); const holds = mode === "block" ? () => st.offsetWidth <= line.clientWidth + 0.5 && st.offsetTop - line.offsetTop + st.offsetHeight <= line.clientHeight + 0.5 : () => line.scrollWidth <= line.clientWidth + 0.5; const title = mode === "row" ? line.querySelector('.part[data-p="title"]') : null; const titleKept = () => !title || title.clientWidth + 0.5 >= Math.min(title.scrollWidth, keepEm * em); if (holds() && titleKept()) return "long"; if (short && short !== full) { st.textContent = short; if (holds()) return "short"; } if (mode === "row" && line.querySelector('.part[data-p="channel"]')) { line.classList.add("st-give"); if (holds()) return "short-channel"; line.classList.remove("st-give"); } st.style.display = "none"; if (sep) sep.style.display = "none"; return "none"; }