From b57cda16eca75d5c989ccb74ad8dec7227e25d19 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 9 Sep 2026 18:22:29 +0200 Subject: [PATCH] feat: normalized window position relX/relY relative to viewport (no infinite-canvas coords) --- src/main.ts | 9 +++++++++ src/ui.tsx | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/main.ts b/src/main.ts index 6bf29c6..ca845df 100644 --- a/src/main.ts +++ b/src/main.ts @@ -143,6 +143,13 @@ export default function () { const cx = Math.round(x + wCanvas / 2) const cy = Math.round(y + hCanvas / 2) + // Нормализованная позиция окна относительно видимого viewport (левый верхний угол + // окна в координатах bounds). relX = x − bounds.x, relY = y − bounds.y. Это те же + // значения, что gapL/gapT, но семантически — "где окно внутри видимой области", + // без привязки к абсолютным (бесконечным) координатам canvas. + const relX = Math.round(x - b.x) + const relY = Math.round(y - b.y) + // Максимальный размер окна (экранные px) = весь видимый viewport (bounds * zoom). const maxViewport = { width: Math.max(320, Math.round(b.width * zoom)), @@ -166,6 +173,8 @@ export default function () { gapR, gapT, gapB, + relX, + relY, center: { x: cx, y: cy } }) }) diff --git a/src/ui.tsx b/src/ui.tsx index c773064..dace9c2 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -57,6 +57,7 @@ function Plugin () { viewport: { x: number; y: number; width: number; height: number } maxViewport: { width: number; height: number } gapL: number; gapR: number; gapT: number; gapB: number + relX: number; relY: number center: { x: number; y: number } } | null>(null) const [copied, setCopied] = useState(false) @@ -86,6 +87,7 @@ function Plugin () { viewport: { x: number; y: number; width: number; height: number } maxViewport: { width: number; height: number } gapL: number; gapR: number; gapT: number; gapB: number + relX: number; relY: number center: { x: number; y: number } }) { setWindowInfo(info) @@ -117,6 +119,8 @@ function Plugin () { `figma.viewport.bounds = ${i.viewport.x},${i.viewport.y} · ${i.viewport.width}×${i.viewport.height}`, `lastSize.width = ${i.width}`, `lastSize.height = ${i.height}`, + `relX = ${i.relX} (x − bounds.x)`, + `relY = ${i.relY} (y − bounds.y)`, '', '== РАСЧЁТ · в main.ts ==', `gapL = ${i.gapL} (x − bounds.x)`, @@ -284,6 +288,8 @@ function Plugin () { + + {/* Расчётные — посчитаны в main.ts из вышеперечисленных raw-значений */}