function getCaretAtPoint(textRenderInfo, x, y) {
  let closestCaret = null
  const rows = groupCaretsByRow(textRenderInfo)

  // Find nearest row by y first
  let closestRow = null
  rows.forEach(row => {
    if (!closestRow || Math.abs(y - (row.top + row.bottom) / 2) < Math.abs(y - (closestRow.top + closestRow.bottom) / 2)) {
      closestRow = row
    }
  })

  // Then find closest caret by x within that row
  closestRow.carets.forEach(caret => {
    if (!closestCaret || Math.abs(x - caret.x) < Math.abs(x - closestCaret.x)) {
      closestCaret = caret
    }
  })
  return closestCaret
}
Given a local x/y coordinate in the text block plane, find the nearest caret position.
@param {TroikaTextRenderInfo} textRenderInfo - a result object from TextBuilder#getTextRenderInfo
@param {number} x
@param {number} y
@return {TextCaret | null}