feat: copy debug values (RAW + calculated) to clipboard with feedback

This commit is contained in:
Hermes Agent committed 2026-09-09 15:19:50 +02:00
1 parent 63a762d002
commit 4f43c5f89c
1 file changed
+40 -6
+40 -6
View File
@@ -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 () {
<Container space="medium" style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Muted>{currentWindowSize.width} × {currentWindowSize.height}</Muted>
<IconButton
title={isMaximized ? 'Свернуть окно' : 'Развернуть окно'}
onClick={toggleWindowSize}
>
{isMaximized ? <IconCollapse24 /> : <IconExpand24 />}
</IconButton>
<div style={{ display: 'flex', gap: '4px', alignItems: 'center' }}>
<Button onClick={copyInfo}>{copied ? '✓ Скопировано' : '📋 Копир.'}</Button>
<IconButton
title={isMaximized ? 'Свернуть окно' : 'Развернуть окно'}
onClick={toggleWindowSize}
>
{isMaximized ? <IconCollapse24 /> : <IconExpand24 />}
</IconButton>
</div>
</div>
<div style={{ display: 'flex', gap: '4px', flexWrap: 'wrap' }}>
<Button onClick={function () { dockWindow('left') }}>◧ Лево</Button>