feat: show live window x/y/size debug readout inside plugin

- main.ts: track lastSize; GET_WINDOW_INFO handler returns x/y via
  figma.ui.getPosition().canvasSpace (typed as any) + stored width/height
- ui.tsx: WINDOW_INFO listener, '🔍 Инфо' button, render x/y/w/h block
This commit is contained in:
Hermes Agent committed 2026-09-09 13:12:17 +02:00
1 parent bc9b2e60e9
commit ecbbd5d8c1
2 files changed
+48 -1

No files matched your search

+26
View File
@@ -4,9 +4,14 @@ export default function () {
// Глобальный ярлык relaunch в правой панели Figma (команда runAI из manifest.json)
figma.root.setRelaunchData({ runAI: '' })
// Последнее известное состояние окна (позиция в canvas-space + размер),
// чтобы UI могла запросить его через GET_WINDOW_INFO.
let lastSize = { width: 320, height: 200 }
// Ресайз окна плагина (drag за угол в UI -> useWindowResize -> RESIZE_WINDOW)
on('RESIZE_WINDOW', function (windowSize: { width: number; height: number }) {
const { width, height } = windowSize
lastSize = { width, height }
figma.ui.resize(width, height)
})
@@ -15,6 +20,7 @@ export default function () {
// Ширину панелей Figma API не отдаёт, поэтому прижимаем к bounds видимой области.
on('DOCK_WINDOW', function (payload: { position: 'left' | 'right' | 'center'; width: number; height: number }) {
const { position, width, height } = payload
lastSize = { width, height }
figma.ui.resize(width, height)
const b = figma.viewport.bounds
let x = b.x
@@ -28,5 +34,25 @@ export default function () {
figma.ui.reposition(x, y)
})
// UI запрашивает текущие x/y (canvas-space) и размеры окна для отладочного вывода.
on('GET_WINDOW_INFO', function () {
let x = 0
let y = 0
try {
// getPosition() есть в рантайме Figma, но отсутствует в @figma/plugin-typings
const pos = (figma.ui as any).getPosition()
x = Math.round(pos.canvasSpace.x)
y = Math.round(pos.canvasSpace.y)
} catch (e) {
// getPosition может быть недоступен в некоторых версиях — оставляем 0
}
emit('WINDOW_INFO', {
x,
y,
width: lastSize.width,
height: lastSize.height
})
})
showUI({ width: 320, height: 200, themeColors: true, title: 'AI assistant (MVP)' })
}