The closest I’ve found is rangy, are there others?
Annotran implements https://github.com/birkbeckOLH/annotran/blob/1572cf301633821446f49c53dd39fe0305be9561/annotran/static/scripts/annotator/plugin/sentenceselection.coffee which lives in this neighborhood.