.pragma library // The caller supplies its viewport; focus never guesses a parent hierarchy. function revealIn(item, viewport) { const top = item.mapToItem(viewport.contentItem, 0, 0).y; const target = top < viewport.contentY ? top : Math.max(viewport.contentY, top + item.height - viewport.height); viewport.contentY = Math.max(0, Math.min(target, viewport.contentHeight - viewport.height)); } function parseJson(text, valueWhenInvalid) { try { return JSON.parse(String(text)); } catch (error) { return valueWhenInvalid; } }