fix: floor resize width/height at 1 so Figma validation never sees 0

This commit is contained in:
Hermes Agent committed 2026-09-11 14:30:29 +02:00
1 parent a06802a9fc
commit 029806f5e0
1 file changed
+9 -8
+9 -8
View File
@@ -151,7 +151,7 @@ export default function () {
function applyDock (position: DockPosition, width: number, height: number, canonical: boolean = false) {
const state = computeDock(position, width, height, canonical)
// Размер меняем, только если канон (иначе ручной ресайз сбросится на отпускании).
if (canonical) figma.ui.resize(state.width, state.height)
if (canonical) figma.ui.resize(Math.max(1, state.width), Math.max(1, state.height))
const pos = canonical ? { x: state.x, y: state.y } : computeDockPos(position, width, height)
figma.ui.reposition(pos.x, pos.y)
lastSize = { width: canonical ? state.width : width, height: canonical ? state.height : height }
@@ -258,7 +258,8 @@ export default function () {
if (dir.indexOf('top') !== -1) h = resizeAnchor.h - dy
}
const size = clampWindowSize({ width: w, height: h })
figma.ui.resize(size.width, size.height)
// Figma rejects resize with width/height < 1 (validation: ">= 0"), so floor both.
figma.ui.resize(Math.max(1, size.width), Math.max(1, size.height))
lastSize = { width: size.width, height: size.height }
// reposition НЕ вызываем: при resize Figma сама держит противоположный угол на месте
// (для left/top окно сдвигается автоматически). Явный reposition конфликтует с этим
@@ -271,7 +272,7 @@ export default function () {
resizeAnchor = null
const { width, height } = clampWindowSize(windowSize)
lastSize = { width, height }
figma.ui.resize(width, height)
figma.ui.resize(Math.max(1, width), Math.max(1, height))
// Если окно задокено/в центре — переприжимаем ПОЗИЦИЮ к краю/центру, но размер
// НЕ трогаем (canonical=false), чтобы ручной ресайз не сбрасывался на отпускании.
// ИСКЛЮЧЕНИЕ: single-axis ресайз из дока (fixedAxis!='none') — окно "выезжает" из
@@ -329,7 +330,7 @@ export default function () {
}
// Попытка растяжения до канона (Figma клампит до лимита при видимом UI).
const state = computeDock(position, payload.width, payload.height, true)
figma.ui.resize(state.width, state.height)
figma.ui.resize(Math.max(1, state.width), Math.max(1, state.height))
lastSize = { width: clampWindowSize(state).width, height: clampWindowSize(state).height }
// reposition откладываем на DOCK_REFINE (UI пришлёт реальный размер после клампа).
// Сохранение позиции тоже в DOCK_REFINE (там известен реальный размер после клампа).
@@ -367,7 +368,7 @@ export default function () {
if (hWasFixed) targetW = Math.round(maxW / 2) // меняем ширину -> 50%
else if (wWasFixed) targetH = Math.round(maxH / 2) // меняем высоту -> 50%
const size = clampWindowSize({ width: targetW, height: targetH })
figma.ui.resize(size.width, size.height)
figma.ui.resize(Math.max(1, size.width), Math.max(1, size.height))
// Выходим из дока: чистый клик = телепорт в угол без удержания.
dockedPosition = null
maximizedState = false
@@ -489,7 +490,7 @@ export default function () {
const maxH = Math.round(b.height * zoom) - PLUGIN_HEADER_PX
const cw = Math.round(maxW / 2)
const ch = Math.round(maxH / 2)
figma.ui.resize(cw, ch)
figma.ui.resize(Math.max(1, cw), Math.max(1, ch))
lastSize = { width: cw, height: ch }
requestAnimationFrame(function () {
requestAnimationFrame(function () {
@@ -512,7 +513,7 @@ export default function () {
dockedPosition = saved.position
maximizedState = false
const state = computeDock(saved.position, 320, 200, true)
figma.ui.resize(state.width, state.height)
figma.ui.resize(Math.max(1, state.width), Math.max(1, state.height))
lastSize = { width: clampWindowSize(state).width, height: clampWindowSize(state).height }
requestAnimationFrame(function () {
requestAnimationFrame(function () {
@@ -523,7 +524,7 @@ export default function () {
}
} else {
// Free placement: restore exact canvas-space position + size.
figma.ui.resize(saved.w, saved.h)
figma.ui.resize(Math.max(1, saved.w), Math.max(1, saved.h))
figma.ui.reposition(saved.x, saved.y)
lastSize = { width: saved.w, height: saved.h }
// If it was maximized, remember it (so the poller re-persists the flag) and tell