From 837bdfbfae507a288e5f0c7a79c1f376000de691 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 9 Sep 2026 18:51:44 +0200 Subject: [PATCH] feat: dock edges fixed-size (left/right=320w full-h, top/bottom=320h full-w), corners full --- src/main.ts | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8409b28..704fe90 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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