Fix init issue

This commit is contained in:
Benjamin Lu
2025-09-06 20:36:55 -07:00
parent cf42355a9f
commit 8586e684a6

View File

@@ -61,5 +61,18 @@ export function getCanvasRect(): Rect {
export function getCanvasClientOrigin() {
ensureContainer()
return { left: x.value || 0, top: y.value || 0 }
const el = containerRef.value
// VueUse refs can be 0 on first read right after binding
// if the element was assigned in the same tick. In that case,
// synchronously read from getBoundingClientRect as a fallback
// to avoid returning a zero offset during initialization.
const lx = x.value || 0
const ly = y.value || 0
// Also check width/height to distinguish a legitimate (0,0)
// from an unmeasured state (all zeros)
if (el && lx === 0 && ly === 0 && width.value === 0 && height.value === 0) {
const rect = el.getBoundingClientRect()
return { left: rect.left, top: rect.top }
}
return { left: lx, top: ly }
}