feat: dock edges fixed-size (left/right=320w full-h, top/bottom=320h full-w), corners full

This commit is contained in:
Hermes Agent committed 2026-09-09 18:51:44 +02:00
1 parent a38f7188ee
commit 837bdfbfae
1 file changed
+26 -11
+26 -11
View File
@@ -26,20 +26,35 @@ export default function () {
const PLUGIN_HEADER_PX = 38
// Вычислить целевое состояние окна для позиции докинга:
// имитация настоящего дока — края/углы РАСТЯГИВАЮТ окно на всю соответствующую
// сторону viewport (по ширине тянутся лево/право/углы, по высоте — верх/низ/углы),
// центр НЕ растягивает (оставляет текущий размер). Возвращает размер (экранные px)
// и позицию (canvas-space, прижатую к нужному краю).
// - Лево/Право: ширина 320px, высота = макс (весь viewport по вертикали минус шапка)
// - Верх/Низ: высота 320px, ширина = макс (весь viewport по горизонтали)
// - Углы: ширина и высота = макс (растянуть обе оси на весь viewport)
// - Центр: текущий размер, только центрирует (не трогает размеры)
// Возвращает размер (экранные px) и позицию (canvas-space, прижатую к нужному краю).
const DOCK_EDGE_SIZE = 320
function computeDock (position: DockPosition, currentWidth: number, currentHeight: number) {
const b = figma.viewport.bounds
const zoom = figma.viewport.zoom || 1
// Растягивать ли по осям:
const stretchX = position !== 'center' // всё кроме центра тянется по ширине
const stretchY =
position === 'top-left' || position === 'top-center' || position === 'top-right' ||
position === 'bottom-left' || position === 'bottom-center' || position === 'bottom-right'
const targetW = stretchX ? Math.round(b.width * zoom) : currentWidth
const targetH = stretchY ? Math.round(b.height * zoom) - PLUGIN_HEADER_PX : currentHeight
const maxW = Math.round(b.width * zoom)
const maxH = Math.round(b.height * zoom) - PLUGIN_HEADER_PX
const isCorner =
position === 'top-left' || position === 'top-right' ||
position === 'bottom-left' || position === 'bottom-right'
const isLeftRight = position === 'center-left' || position === 'center-right'
const isTopBottom = position === 'top-center' || position === 'bottom-center'
let targetW = currentWidth
let targetH = currentHeight
if (isCorner) {
targetW = maxW
targetH = maxH
} else if (isLeftRight) {
targetW = DOCK_EDGE_SIZE
targetH = maxH
} else if (isTopBottom) {
targetW = maxW
targetH = DOCK_EDGE_SIZE
}
// canvas-units от целевого размера
const wCanvas = targetW / zoom
const hCanvas = (PLUGIN_HEADER_PX + targetH) / zoom