/**
 * MK1 Layout Engine - Pure math, no blessed imports
 *
 * Computes panel rectangles based on canvas size and layout mode.
 * All rectangles are clamped to prevent overflow.
 */
/**
 * Clamp rectangle to canvas bounds
 * Returns null if clamped size would be invalid
 * - Header/command: minimum w >= 1, h >= 1
 * - Other panels: minimum w >= 3, h >= 3
 */
export function clampRect(rect, canvasCols, canvasRows, isThin = false) {
    let { x, y, w, h } = rect;
    // Clamp position
    x = Math.max(0, Math.min(x, canvasCols - 1));
    y = Math.max(0, Math.min(y, canvasRows - 1));
    // Clamp width
    const maxW = canvasCols - x;
    w = Math.min(w, maxW);
    // Clamp height
    const maxH = canvasRows - y;
    h = Math.min(h, maxH);
    // Check minimums
    // Header and command line are thin (1 line), allow h >= 1
    const minSize = isThin ? 1 : 3;
    if (w < minSize || h < minSize) {
        return null; // Invalid after clamping
    }
    return { x, y, w, h };
}
/**
 * Assert no overflow - throws if any rect exceeds canvas
 */
export function assertNoOverflow(spec, canvas) {
    for (const [name, rect] of Object.entries(spec.rects)) {
        const rightEdge = rect.x + rect.w;
        const bottomEdge = rect.y + rect.h;
        if (rect.x < 0 || rect.y < 0 || rightEdge > canvas.cols || bottomEdge > canvas.rows) {
            throw new Error(`Layout overflow: ${name} at (${rect.x},${rect.y}) size ${rect.w}x${rect.h} ` +
                `exceeds canvas ${canvas.cols}x${canvas.rows}`);
        }
    }
}
/**
 * Compute wide layout (3-column grid)
 *
 * Rule: sum of widths + gutters <= safeCols
 * Rule: nothing ends at x == safeCols (1-col air gap)
 * Rule: borders consume 2 cols (left + right) and 2 rows (top + bottom)
 *       So we need to account for border space when computing panel sizes
 */
function computeWideLayout(canvas) {
    // Phase A: Use safeCols/safeRows from canvas (already computed by getSafeViewport)
    // Phase A: No more RIGHT_GAP here - getSafeViewport already applied it
    // canvas.cols is already safeCols (after RIGHT_GAP), canvas.rows is already safeRows (after BOTTOM_GAP)
    const safeCols = canvas.cols; // Already has RIGHT_GAP applied
    const safeRows = canvas.rows; // Already has BOTTOM_GAP applied
    const GUTTER = 1; // Gap between columns
    const COMMAND_HEIGHT = 3;
    const HEADER_HEIGHT = 1;
    const MIN_MAIN_H = 20;
    const MIN_ROWS = 24;
    // Step 1: SAFE_COLS = screen.cols - 1 (or use canvas.cols which already has RIGHT_GAP applied)
    // canvas.cols is already safeCols (from getSafeViewport with RIGHT_GAP applied)
    const SAFE_COLS = safeCols; // Already has RIGHT_GAP applied in getSafeViewport
    // Step 2: Use fixed widths for left/right, cap OPS width
    // Rule: LEFT_W + GUTTER + OPS_W + GUTTER + RIGHT_W <= SAFE_COLS - 5 (5 unit safety margin)
    // Use outer widths (border included) - all calculations use outer width
    const MIN_LEFT_W = 28; // Minimum outer width for left column
    const MAX_LEFT_W = 50; // Maximum outer width for left column (increased to use space freed from operations)
    const MIN_RIGHT_W = 28; // Minimum outer width for right column
    const MAX_RIGHT_W = 50; // Maximum outer width for right column (increased to use space freed from operations)
    // Step 2: Cap OPS width - user: "operations section smaller its too big"
    const OPS_MAX_W = 140; // Maximum outer width for operations (reduced from 180 to make it smaller)
    const OPS_MIN_W = 60; // Minimum outer width for operations (must be readable)
    // Step 2: Calculate available space for OPS first (operations is capped at OPS_MAX_W)
    // Leave 5 unit safety margin: RIGHT_EDGE <= SAFE_COLS - 5
    // So: LEFT_W + GUTTER + OPS_W + GUTTER + RIGHT_W <= SAFE_COLS - 5
    // Rearranging: LEFT_W + RIGHT_W <= SAFE_COLS - OPS_W - (GUTTER * 2) - 5
    const SAFE_GAP = 5; // 5 unit safety margin for wiggle room
    const maxAvailableForLeftRight = SAFE_COLS - OPS_MAX_W - (GUTTER * 2) - SAFE_GAP;
    // Step 2: Distribute available space to left and right columns (user: "other sections should be bigger")
    // Split the available space 50/50 between left and right
    let leftW = Math.round(maxAvailableForLeftRight / 2);
    let rightW = Math.round(maxAvailableForLeftRight / 2);
    // Step 2: Clamp to min/max bounds
    leftW = Math.max(MIN_LEFT_W, Math.min(MAX_LEFT_W, leftW));
    rightW = Math.max(MIN_RIGHT_W, Math.min(MAX_RIGHT_W, rightW));
    // Step 2: Use these as fixed widths
    const LEFT_W = leftW;
    const RIGHT_W = rightW;
    // Phase A: Validate canvas size (use safeRows directly)
    if (safeRows < MIN_ROWS) {
        throw new Error(`Canvas too small for wide layout: safeRows=${safeRows} < ${MIN_ROWS}`);
    }
    const mainHeight = safeRows - HEADER_HEIGHT - COMMAND_HEIGHT;
    if (mainHeight < MIN_MAIN_H) {
        throw new Error(`Main area too small: height=${mainHeight} < ${MIN_MAIN_H}`);
    }
    // Step 2: Calculate OPS width - operations stays at perfect size (180)
    // Remaining space after left+right+gutters
    const availableForOps = SAFE_COLS - LEFT_W - RIGHT_W - (GUTTER * 2);
    // OPS width is the smaller of available space and OPS_MAX_W
    // User: "operation section is perfect sized" - keep at 180
    let opsW = Math.max(OPS_MIN_W, Math.min(OPS_MAX_W, availableForOps));
    // Step 3: Recompute positions using capped OPS width
    // Step 1: Use explicit x positions, not right: 0 anchoring
    const LEFT_X = 0;
    let OPS_X = LEFT_X + LEFT_W + GUTTER;
    let RIGHT_X = OPS_X + opsW + GUTTER;
    // Step 3: Assert no overflow with 5 unit safety margin
    // RIGHT_EDGE must be <= SAFE_COLS - SAFE_GAP (5 unit safety margin for wiggle room)
    const maxRightEdge = SAFE_COLS - SAFE_GAP;
    if (RIGHT_X + RIGHT_W > maxRightEdge) {
        // Emergency clamp: reduce OPS width to fit with 5 unit gap
        const maxOpsW = maxRightEdge - LEFT_W - RIGHT_W - (GUTTER * 2);
        if (maxOpsW < OPS_MIN_W) {
            throw new Error(`Cannot fit panels with 5 unit safety margin: maxOpsW=${maxOpsW} < OPS_MIN_W=${OPS_MIN_W} ` +
                `(SAFE_COLS=${SAFE_COLS} SAFE_GAP=${SAFE_GAP} LEFT_W=${LEFT_W} RIGHT_W=${RIGHT_W} GUTTER=${GUTTER})`);
        }
        opsW = Math.max(OPS_MIN_W, maxOpsW);
        // Recalculate positions with clamped opsW
        OPS_X = LEFT_X + LEFT_W + GUTTER;
        RIGHT_X = OPS_X + opsW + GUTTER;
        // Verify emergency clamp worked (with 5 unit safety margin)
        if (RIGHT_X + RIGHT_W > maxRightEdge) {
            throw new Error(`Emergency clamp failed: RIGHT_X=${RIGHT_X} RIGHT_W=${RIGHT_W} RIGHT_EDGE=${RIGHT_X + RIGHT_W} > maxRightEdge=${maxRightEdge} (SAFE_COLS=${SAFE_COLS} - SAFE_GAP=${SAFE_GAP})`);
        }
    }
    // Use fixed widths (already set above) - these are outer widths including borders
    // leftW and rightW already declared above, just use them
    const centerW = opsW; // Use the capped OPS width (outer width including borders)
    // Step 3: Final positions (already calculated and verified above)
    const leftX = LEFT_X; // 0
    const centerX = OPS_X;
    const rightX = RIGHT_X;
    // Final verification - ensure right edge has 5 unit safety margin
    // maxRightEdge already declared above, reuse it
    const rightEdge = rightX + rightW;
    if (rightEdge > maxRightEdge) {
        throw new Error(`[LAYOUT ERROR] rightEdge=${rightEdge} > maxRightEdge=${maxRightEdge} (SAFE_COLS=${SAFE_COLS} - SAFE_GAP=${SAFE_GAP}) ` +
            `(LEFT_W=${leftW} OPS_W=${centerW} RIGHT_W=${rightW} GUTTER=${GUTTER} ` +
            `LEFT_X=${leftX} OPS_X=${centerX} RIGHT_X=${rightX})`);
    }
    // Verify we have the 5 unit gap
    const gapCheck = SAFE_COLS - rightEdge;
    if (gapCheck < SAFE_GAP) {
        throw new Error(`[LAYOUT ERROR] Gap too small: gap=${gapCheck} < SAFE_GAP=${SAFE_GAP} ` +
            `(rightEdge=${rightEdge} SAFE_COLS=${SAFE_COLS})`);
    }
    // Build layout spec with final widths (normal or emergency-clamped)
    // Left column panels (split vertically with gaps to prevent double borders)
    const VERTICAL_GAP = 1; // Gap between vertically stacked panels to prevent double borders
    const availableHeightForLeft = mainHeight - (VERTICAL_GAP * 2); // Account for 2 gaps between 3 panels
    const leftPanelH = Math.floor(availableHeightForLeft / 3);
    const leftRemainder = availableHeightForLeft - (leftPanelH * 3);
    // Right column panels (split vertically with gap)
    const availableHeightForRight = mainHeight - VERTICAL_GAP; // Account for 1 gap between 2 panels
    const rightPanelH = Math.floor(availableHeightForRight / 2);
    const rightRemainder = availableHeightForRight - (rightPanelH * 2);
    const headerY = 0;
    const mainY = HEADER_HEIGHT;
    const commandY = canvas.rows - COMMAND_HEIGHT; // Use canvas.rows to position at very bottom
    // Phase E: Header and command span full safeCols width (not beyond)
    const headerW = safeCols; // Use full safeCols (already has RIGHT_GAP applied in getSafeViewport)
    const commandW = safeCols;
    const spec = {
        mode: 'wide',
        reason: 'wide',
        rects: {
            header: {
                x: 0,
                y: headerY,
                w: headerW,
                h: HEADER_HEIGHT,
            },
            posture: {
                x: leftX,
                y: mainY,
                w: leftW,
                h: leftPanelH + (leftRemainder > 0 ? 1 : 0),
            },
            resources: {
                x: leftX,
                y: mainY + leftPanelH + (leftRemainder > 0 ? 1 : 0) + VERTICAL_GAP,
                w: leftW,
                h: leftPanelH + (leftRemainder > 1 ? 1 : 0),
            },
            assets: {
                x: leftX,
                y: mainY + (leftPanelH * 2) + Math.min(leftRemainder, 2) + (VERTICAL_GAP * 2),
                w: leftW,
                h: leftPanelH + (leftRemainder > 2 ? 1 : 0),
            },
            operations: {
                x: centerX,
                y: mainY,
                w: centerW,
                h: mainHeight,
            },
            network: {
                x: rightX,
                y: mainY,
                w: rightW,
                h: rightPanelH + (rightRemainder > 0 ? 1 : 0),
            },
            capabilities: {
                x: rightX,
                y: mainY + rightPanelH + (rightRemainder > 0 ? 1 : 0) + VERTICAL_GAP,
                w: rightW,
                h: rightPanelH + (rightRemainder > 1 ? 1 : 0),
            },
            command: {
                x: 0,
                y: commandY,
                w: commandW, // Use commandW (usableCols), not canvas.cols
                h: COMMAND_HEIGHT,
            },
        },
    };
    // Step 5: Acceptance test data - store debug info for logging
    const totalUsedWidth = leftW + GUTTER + centerW + GUTTER + rightW;
    const safetyMargin = SAFE_COLS - rightEdge; // Actual safety margin from right edge (should be >= SAFE_GAP)
    // Phase A/B: Store debug info for logging and offender scanner
    // Step 5: All values for acceptance test verification
    spec._debug = {
        cols: canvas.cols, // This is safeCols (already has RIGHT_GAP)
        rows: canvas.rows, // This is safeRows (already has BOTTOM_GAP)
        safeCols: SAFE_COLS,
        safeRows,
        GUTTER,
        SAFE_GAP,
        LEFT_W,
        RIGHT_W,
        OPS_MAX_W,
        OPS_MIN_W,
        availableForOps,
        leftX,
        leftW,
        centerX,
        centerW,
        rightX,
        rightW,
        rightEdge: rightEdge,
        gap: safetyMargin, // Safety margin from right edge (should be >= SAFE_GAP)
        status: rightEdge <= (SAFE_COLS - SAFE_GAP) ? 'OK' : 'ERROR',
    };
    // Final safety check already done above - rightEdge verified <= SAFE_COLS
    // Phase E: Clamp all rects to ensure no element exceeds safe bounds
    // Use safeCols/safeRows (already has gaps applied from getSafeViewport)
    for (const [name, rect] of Object.entries(spec.rects)) {
        const isThin = name === 'header' || name === 'command';
        const clamped = clampRect(rect, safeCols, safeRows, isThin);
        if (!clamped) {
            throw new Error(`Panel ${name} invalid after clamping (rect=${rect.x},${rect.y} ${rect.w}x${rect.h} safeCols=${safeCols} safeRows=${safeRows})`);
        }
        // Phase E: Critical anti-scroll rule - verify clamped rect
        if (clamped.x + clamped.w > safeCols || clamped.y + clamped.h > safeRows) {
            throw new Error(`Panel ${name} still exceeds bounds after clamping: ` +
                `rightEdge=${clamped.x + clamped.w} > safeCols=${safeCols} OR ` +
                `bottomEdge=${clamped.y + clamped.h} > safeRows=${safeRows}`);
        }
        spec.rects[name] = clamped;
    }
    // Phase E: Final overflow assertion
    assertNoOverflow(spec, { cols: safeCols, rows: safeRows });
    return spec;
}
/**
 * Compute standard layout (same as wide but with adjusted widths)
 */
function computeStandardLayout(canvas) {
    const GAP = 1;
    const COMMAND_HEIGHT = 3;
    const HEADER_HEIGHT = 1;
    const AIR_GAP = 1; // 1-col air gap on right and bottom
    const MIN_CENTER_W = 60;
    const MIN_RIGHT_W = 26;
    const MIN_LEFT_W = 26;
    const MIN_MAIN_H = 20;
    const MIN_ROWS = 24;
    // Use safeCols/safeRows (already accounts for padding)
    // Subtract AIR_GAP to ensure nothing ends at safeCols
    const usableCols = canvas.cols - AIR_GAP;
    const usableRows = canvas.rows - AIR_GAP;
    if (usableRows < MIN_ROWS) {
        throw new Error(`Canvas too small for standard layout: rows=${usableRows} < ${MIN_ROWS}`);
    }
    const mainHeight = usableRows - HEADER_HEIGHT - COMMAND_HEIGHT;
    if (mainHeight < MIN_MAIN_H) {
        throw new Error(`Main area too small: height=${mainHeight} < ${MIN_MAIN_H}`);
    }
    // Calculate column widths with priority: center >= 60, right >= 26, left >= 26
    const availableW = usableCols - (GAP * 2);
    const centerW = Math.max(MIN_CENTER_W, Math.floor(availableW * 0.5));
    const rightW = Math.max(MIN_RIGHT_W, Math.floor((availableW - centerW) * 0.4));
    const leftW = availableW - centerW - rightW;
    if (leftW < MIN_LEFT_W) {
        // Adjust: reduce right first, then center if needed
        const needed = MIN_LEFT_W - leftW;
        if (rightW - needed >= MIN_RIGHT_W) {
            const newRightW = rightW - needed;
            const newLeftW = availableW - centerW - newRightW;
            return computeStandardLayoutWithWidths(canvas, newLeftW, centerW, newRightW, GAP, HEADER_HEIGHT, COMMAND_HEIGHT, mainHeight, AIR_GAP);
        }
        else {
            // Must reduce center
            const newCenterW = Math.max(MIN_CENTER_W, centerW - (MIN_LEFT_W - leftW));
            const newRightW = Math.max(MIN_RIGHT_W, rightW);
            const newLeftW = availableW - newCenterW - newRightW;
            return computeStandardLayoutWithWidths(canvas, newLeftW, newCenterW, newRightW, GAP, HEADER_HEIGHT, COMMAND_HEIGHT, mainHeight, AIR_GAP);
        }
    }
    return computeStandardLayoutWithWidths(canvas, leftW, centerW, rightW, GAP, HEADER_HEIGHT, COMMAND_HEIGHT, mainHeight, AIR_GAP);
}
function computeStandardLayoutWithWidths(canvas, leftW, centerW, rightW, gap, headerHeight, commandHeight, mainHeight, airGap) {
    const usableCols = canvas.cols - airGap;
    const usableRows = canvas.rows - airGap;
    // Left column panels (split vertically)
    const leftPanelH = Math.floor(mainHeight / 3);
    const leftRemainder = mainHeight - (leftPanelH * 3);
    // Right column panels (split vertically)
    const rightPanelH = Math.floor(mainHeight / 2);
    const rightRemainder = mainHeight - (rightPanelH * 2);
    const headerY = 0;
    const mainY = headerHeight;
    const commandY = canvas.rows - commandHeight; // Use canvas.rows to position at very bottom
    // Compute explicit positions (never use right: 0 or bottom: 0)
    const headerW = usableCols;
    const commandW = usableCols;
    const spec = {
        mode: 'standard',
        reason: 'standard',
        rects: {
            header: {
                x: 0,
                y: headerY,
                w: headerW,
                h: headerHeight,
            },
            posture: {
                x: 0,
                y: mainY,
                w: leftW,
                h: leftPanelH + (leftRemainder > 0 ? 1 : 0),
            },
            resources: {
                x: 0,
                y: mainY + leftPanelH + (leftRemainder > 0 ? 1 : 0),
                w: leftW,
                h: leftPanelH + (leftRemainder > 1 ? 1 : 0),
            },
            assets: {
                x: 0,
                y: mainY + (leftPanelH * 2) + Math.min(leftRemainder, 2),
                w: leftW,
                h: leftPanelH + (leftRemainder > 2 ? 1 : 0),
            },
            operations: {
                x: leftW + gap,
                y: mainY,
                w: centerW,
                h: mainHeight,
            },
            network: {
                x: leftW + gap + centerW + gap,
                y: mainY,
                w: rightW,
                h: rightPanelH + (rightRemainder > 0 ? 1 : 0),
            },
            capabilities: {
                x: leftW + gap + centerW + gap,
                y: mainY + rightPanelH + (rightRemainder > 0 ? 1 : 0),
                w: rightW,
                h: rightPanelH + (rightRemainder > 1 ? 1 : 0),
            },
            command: {
                x: 0,
                y: commandY,
                w: commandW,
                h: commandHeight,
            },
        },
    };
    // Clamp all rects (header and command are thin, allow h=1)
    // Use usableCols/usableRows for clamping
    for (const [name, rect] of Object.entries(spec.rects)) {
        const isThin = name === 'header' || name === 'command';
        const clamped = clampRect(rect, usableCols, usableRows, isThin);
        if (!clamped) {
            throw new Error(`Panel ${name} invalid after clamping`);
        }
        spec.rects[name] = clamped;
    }
    assertNoOverflow(spec, { cols: usableCols, rows: usableRows });
    return spec;
}
/**
 * Compute stack layout (everything stacked vertically)
 */
function computeStackLayout(canvas) {
    const HEADER_HEIGHT = 1;
    const COMMAND_HEIGHT = 3;
    const GAP = 1;
    const AIR_GAP = 1; // 1-col air gap on right and bottom
    // Use safeCols/safeRows (already accounts for padding)
    // Subtract AIR_GAP to ensure nothing ends at safeCols
    const usableCols = canvas.cols - AIR_GAP;
    const usableRows = canvas.rows - AIR_GAP;
    const usableHeight = usableRows - HEADER_HEIGHT - COMMAND_HEIGHT;
    const panelCount = 6; // posture, resources, assets, operations, network, capabilities
    const panelHeight = Math.max(3, Math.floor(usableHeight / panelCount));
    const remainder = usableHeight - (panelHeight * panelCount);
    const headerY = 0;
    const commandY = canvas.rows - COMMAND_HEIGHT; // Use canvas.rows to position at very bottom
    // Compute explicit positions (never use right: 0 or bottom: 0)
    const headerW = usableCols;
    const commandW = usableCols;
    let currentY = HEADER_HEIGHT;
    const spec = {
        mode: 'stack',
        reason: 'stack',
        rects: {
            header: {
                x: 0,
                y: headerY,
                w: headerW, // Use headerW (usableCols), not canvas.cols
                h: HEADER_HEIGHT,
            },
            posture: {
                x: 0,
                y: currentY,
                w: usableCols, // Use usableCols, not canvas.cols
                h: panelHeight + (remainder > 0 ? 1 : 0),
            },
            resources: {
                x: 0,
                y: currentY += panelHeight + (remainder > 0 ? 1 : 0),
                w: usableCols, // Use usableCols, not canvas.cols
                h: panelHeight + (remainder > 1 ? 1 : 0),
            },
            assets: {
                x: 0,
                y: currentY += panelHeight + (remainder > 1 ? 1 : 0),
                w: usableCols, // Use usableCols, not canvas.cols
                h: panelHeight + (remainder > 2 ? 1 : 0),
            },
            operations: {
                x: 0,
                y: currentY += panelHeight + (remainder > 2 ? 1 : 0),
                w: usableCols, // Use usableCols, not canvas.cols
                h: panelHeight + (remainder > 3 ? 1 : 0),
            },
            network: {
                x: 0,
                y: currentY += panelHeight + (remainder > 3 ? 1 : 0),
                w: usableCols, // Use usableCols, not canvas.cols
                h: panelHeight + (remainder > 4 ? 1 : 0),
            },
            capabilities: {
                x: 0,
                y: currentY += panelHeight + (remainder > 4 ? 1 : 0),
                w: usableCols, // Use usableCols, not canvas.cols
                h: panelHeight + (remainder > 5 ? 1 : 0),
            },
            command: {
                x: 0,
                y: commandY,
                w: commandW, // Use commandW (usableCols), not canvas.cols
                h: COMMAND_HEIGHT,
            },
        },
    };
    // Clamp all rects (header and command are thin, allow h=1)
    // Use usableCols/usableRows for clamping (already accounts for air gap)
    for (const [name, rect] of Object.entries(spec.rects)) {
        const isThin = name === 'header' || name === 'command';
        const clamped = clampRect(rect, usableCols, usableRows, isThin);
        if (!clamped) {
            throw new Error(`Panel ${name} invalid after clamping`);
        }
        spec.rects[name] = clamped;
    }
    assertNoOverflow(spec, canvas);
    return spec;
}
/**
 * Get layout mode from environment or auto-detect
 */
function getLayoutMode(canvas) {
    const envMode = process.env.TUI_LAYOUT;
    if (envMode === 'wide') {
        return { mode: 'wide', reason: 'env=wide' };
    }
    if (envMode === 'standard') {
        return { mode: 'standard', reason: 'env=standard' };
    }
    if (envMode === 'stack') {
        return { mode: 'stack', reason: 'env=stack' };
    }
    // Auto-detect: try wide first, then standard, then stack
    try {
        computeWideLayout(canvas);
        return { mode: 'wide', reason: 'auto' };
    }
    catch {
        // Wide failed, try standard
        try {
            computeStandardLayout(canvas);
            return { mode: 'standard', reason: 'auto' };
        }
        catch {
            // Both failed, use stack
            return { mode: 'stack', reason: 'auto-fallback' };
        }
    }
}
/**
 * Compute layout - main entry point
 */
export function computeLayout(canvas) {
    const { mode, reason } = getLayoutMode(canvas);
    try {
        if (mode === 'wide') {
            const spec = computeWideLayout(canvas);
            spec.reason = reason;
            return spec;
        }
        else if (mode === 'standard') {
            const spec = computeStandardLayout(canvas);
            spec.reason = reason;
            return spec;
        }
        else {
            const spec = computeStackLayout(canvas);
            spec.reason = reason;
            return spec;
        }
    }
    catch (error) {
        // If requested mode fails, fallback to stack
        if (mode !== 'stack') {
            const spec = computeStackLayout(canvas);
            spec.reason = `${reason}→fallback-stack`;
            return spec;
        }
        throw error;
    }
}
//# sourceMappingURL=layoutEngine.js.map