// THE LAYOUT ENGINE (release 39): every module asks for a SLOT and gets a // rect in the output frame. The slots generalise deckGeometry: the deck's // band at the foot of the frame, the footage box above it (moved for the // feed's column or the side panel), and the boxes the posts, the stamp and // the stats stand in inside it. A module draws in its slot's rect and never // in another's: the geometry is computed here, once, from the render block, // in design units (design.mjs) scaled to the output size. // // Pure. The numbers are deck.mjs's geometry functions' -- those stay the one // arithmetic, and this file is the one place a module asks them. import { deckGeometry, feedGeometry, fxGeometry, instrumentsGeometry, postsGeometry, stampGeometry, statsGeometry, threadsGeometry, } from "../deck.mjs"; import { MODULE_SLOTS } from "./contract.mjs"; import { DESIGN, designScale } from "./design.mjs"; export { DESIGN, designScale }; /** * A slot's rect in the output frame, `{ x, y, width, height }`. * * - `footer`: the deck's band, full width at the foot of the frame. * - `footage`: the picture's box -- the feed's (beside its column) when * `feed`, else the deck's (beside the side panel when that is on). * - `column`: the posts feed's column, flush with the frame's side and top. * - `popup`: where the popup posts stack (in the footage box, or at the * frame's edge when the footage shifts away for them). * - `stamp`: the fact-check stamp's box in the footage, at its position. * - `panel`: the stats panel in the footage, at its position. * - `side`: the side panel (the thread rail, the flips) beside the footage. * - `instruments`: the measure's instruments' column at the frame's right * (the dial, the odometer, the trail; instruments.mjs), the footage moved * to the left for it. * - `full`: the whole frame. * * @param {string} slot * @param {any} render * @param {{ feed?: boolean }} [opts] * @returns {{ x: number, y: number, width: number, height: number }} */ export function slotRect(slot, render, { feed = false } = {}) { switch (slot) { case "footer": return { ...deckGeometry(render).deck }; case "footage": return fxGeometry(render, { feed }); case "column": return { ...feedGeometry(render).column }; case "popup": return postsGeometry(render); case "stamp": return stampGeometry(render, { feed }); case "panel": return statsGeometry(render, { feed }); case "side": { const { cards: _c, ...box } = threadsGeometry(render); return box; } case "instruments": return { ...instrumentsGeometry(render).column }; case "shelf": { // The shelf (`deck.shelf`); without one, an empty strip at the footage's foot. const g = deckGeometry(render); return g.shelf ? { ...g.shelf } : { x: g.footage.x, y: g.footage.y + g.footage.height, width: g.footage.width, height: 0 }; } case "full": return { x: 0, y: 0, width: render?.width ?? DESIGN.width, height: render?.height ?? DESIGN.height }; default: throw new Error(`layout: ${slot} is not a slot (${MODULE_SLOTS.filter((s) => s !== "inline").join(", ")})`); } } /** Every slot's rect at once: what umtool's layout view and the module docs draw. */ export function slotRects(render, opts = {}) { return Object.fromEntries(MODULE_SLOTS.filter((s) => s !== "inline").map((s) => [s, slotRect(s, render, opts)])); } /** A design-unit length in this render's pixels, rounded. */ export const scaled = (v, render) => Math.round(v * designScale(render));