/**
 * MK2 Phase 1B: Hard Invariant Checks
 *
 * Crash early if layout math is wrong - don't hack around it.
 */
/**
 * Assert that a box fits within safe canvas bounds
 * Rule: x + w <= safeW (ensures maxX = x + w - 1 <= safeW - 1)
 */
export function assertBoxFits(box, safeW, safeH, topGuard = 0) {
    if (box.x < 0 || box.y < topGuard) {
        throw new Error(`Box negative position: x=${box.x} y=${box.y} (must be x>=0, y>=${topGuard})`);
    }
    if (box.w < 1 || box.h < 1) {
        throw new Error(`Box invalid size: w=${box.w} h=${box.h} (must be >= 1)`);
    }
    // Check: x + w <= safeW (ensures maxX = x + w - 1 <= safeW - 1)
    if (box.x + box.w > safeW) {
        throw new Error(`Box overflows X: x+w=${box.x + box.w} > safeW=${safeW} ` +
            `(box: x=${box.x} w=${box.w} overflow=${box.x + box.w - safeW})`);
    }
    const safeMaxY = topGuard + safeH;
    if (box.y + box.h > safeMaxY) {
        throw new Error(`Box overflows Y: y+h=${box.y + box.h} > safeMaxY=${safeMaxY} ` +
            `(box: y=${box.y} h=${box.h} topGuard=${topGuard} overflow=${box.y + box.h - safeMaxY})`);
    }
}
/**
 * Clamp a value between min and max
 */
export function clamp(value, min, max) {
    return Math.max(min, Math.min(max, value));
}
//# sourceMappingURL=invariants.js.map