// Theme engine v3, step 8: the layer guard's geometry (pure part). import { test } from 'node:test'; import assert from 'node:assert/strict'; import { clampShift, viewportBox } from '../src/themeGuards.ts'; const box = viewportBox(2000, 1000, { top: 0, bottom: 56 }); test('the account menu that ran 52px past a 2000px window comes back inside, 8px from the edge', () => { // Live 1.0.2: left 1737, width 300 in a 1985px viewport. const shift = clampShift({ left: 1737, top: 822, width: 300, height: 108 }, viewportBox(1985, 1000, { top: 0, bottom: 56 })); assert.equal(1737 + shift.dx + 300, 1985 - 8); assert.equal(shift.dy, 0); }); test('a hover card cut at the bottom moves up above the bar inset', () => { const shift = clampShift({ left: 400, top: 900, width: 300, height: 200 }, box); assert.equal(900 + shift.dy + 200, 1000 - 8 - 56); }); test('inside stays put; taller than the box keeps its top edge and asks to scroll', () => { assert.deepEqual(clampShift({ left: 100, top: 100, width: 200, height: 200 }, box), { dx: 0, dy: 0, overflowY: false }); const tall = clampShift({ left: 100, top: 300, width: 200, height: 2000 }, box); assert.equal(300 + tall.dy, 8); assert.ok(tall.overflowY); const left = clampShift({ left: -40, top: 100, width: 200, height: 100 }, box); assert.equal(-40 + left.dx, 8); });