From 4f43c5f89c1f833bbdcf6f0c21c88a4a9a966ad9 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 9 Sep 2026 15:19:50 +0200 Subject: [PATCH] feat: copy debug values (RAW + calculated) to clipboard with feedback --- src/ui.tsx | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/ui.tsx b/src/ui.tsx index f68276b..52e0a61 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -50,6 +50,7 @@ function Plugin () { gapL: number; gapR: number; gapT: number; gapB: number center: { x: number; y: number } } | null>(null) + const [copied, setCopied] = useState(false) // Нативный drag-ресайз окна Figma (тянуть за правый нижний угол). // Опции min/max обязательны: без них хук берёт базу из window.innerWidth на момент @@ -85,6 +86,36 @@ function Plugin () { emit('GET_WINDOW_INFO') } + // Копирует все debug-значения (RAW + расчёт) в буфер обмена как текст. + function copyInfo () { + if (windowInfo == null) return + const i = windowInfo + const lines = [ + '== RAW · Figma API ==', + `figma.ui.getPosition().canvasSpace.x = ${i.x}`, + `figma.ui.getPosition().canvasSpace.y = ${i.y}`, + `figma.viewport.zoom = ${i.zoom}`, + `figma.viewport.bounds = ${i.viewport.x},${i.viewport.y} · ${i.viewport.width}×${i.viewport.height}`, + `lastSize.width = ${i.width}`, + `lastSize.height = ${i.height}`, + '', + '== РАСЧЁТ · в main.ts ==', + `gapL = ${i.gapL} (x − bounds.x)`, + `gapR = ${i.gapR} (bounds.x + bounds.width − (x + w))`, + `gapT = ${i.gapT} (y − bounds.y)`, + `gapB = ${i.gapB} (bounds.y + bounds.height − (y + h))`, + `center.x = ${i.center.x} (x + w / 2)`, + `center.y = ${i.center.y} (y + h / 2)` + ] + const text = lines.join('\n') + if (navigator.clipboard != null && navigator.clipboard.writeText != null) { + navigator.clipboard.writeText(text).then(function () { + setCopied(true) + setTimeout(function () { setCopied(false) }, 1200) + }).catch(function () { /* тихо */ }) + } + } + // Обновляем цифры размера и инфо ТОЛЬКО после окончания drag'а (отпускание кнопки). // К моменту pointerup Figma уже применила новый размер окна. useEffect(function () { @@ -134,12 +165,15 @@ function Plugin () {
{currentWindowSize.width} × {currentWindowSize.height} - - {isMaximized ? : } - +
+ + + {isMaximized ? : } + +