'use strict'; // 拖边缘改大小的纯计算部分单独放一个文件: // 这段几何运算是最容易出错、但在无边框窗口里只能靠真鼠标才能触发的地方, // 拆出来之后可以在 node 里直接跑用例,不必等到 Windows 上肉眼试。 const MIN_SIZE = { width: 260, height: 150 }; function computeBounds(start, dir, dx, dy, min) { const limit = min || MIN_SIZE; let x = start.x; let y = start.y; let width = start.width; let height = start.height; if (dir.includes('e')) width += dx; if (dir.includes('s')) height += dy; if (dir.includes('w')) { width -= dx; x += dx; } if (dir.includes('n')) { height -= dy; y += dy; } // 顶到最小尺寸后继续拖,被拖的那条边要停住,而不是把整个窗口推走 if (width < limit.width) { if (dir.includes('w')) x = start.x + start.width - limit.width; width = limit.width; } if (height < limit.height) { if (dir.includes('n')) y = start.y + start.height - limit.height; height = limit.height; } return { x: Math.round(x), y: Math.round(y), width: Math.round(width), height: Math.round(height) }; } if (typeof module !== 'undefined' && module.exports) { module.exports = { computeBounds, MIN_SIZE }; }