feat: normalized window position relX/relY relative to viewport (no infinite-canvas coords)

This commit is contained in:
Hermes Agent committed 2026-09-09 18:22:29 +02:00
1 parent 153da94fde
commit b57cda16ec
2 files changed
+15

No files matched your search

+9
View File
@@ -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 }
})
})
+6
View File
@@ -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 () {
<Field name="lastSize.width" value={windowInfo.width} />
<Field name="lastSize.height" value={windowInfo.height} />
<Field name="maxViewport (bounds·zoom)" formula="bounds.width*zoom, bounds.height*zoom" value={`${windowInfo.maxViewport.width}×${windowInfo.maxViewport.height}`} />
<Field name="relX (x − bounds.x)" formula="нормализованная X окна в viewport" value={windowInfo.relX} />
<Field name="relY (y − bounds.y)" formula="нормализованная Y окна в viewport" value={windowInfo.relY} />
</Section>
{/* Расчётные — посчитаны в main.ts из вышеперечисленных raw-значений */}
<Section title="РАСЧЁТ · в main.ts">