// docs/DESIGN.md "Text stays selectable": a click that ends a text selection does nothing. The // mouseup of a drag-select fires a click on whatever the drag started in, so a title that opens its // video on click would play it the moment the reader finished selecting its words to copy them. // A plain click collapses any selection on mousedown, so a non-empty selection that touches the // element at click time can only be the one this gesture just made. /** True when the page's selection is non-empty and starts or ends inside `el`. */ export function endsTextSelection(el: Element): boolean { const sel = typeof window === "undefined" ? null : window.getSelection(); if (!sel || sel.isCollapsed || !sel.toString().trim()) return false; return ( (!!sel.anchorNode && el.contains(sel.anchorNode)) || (!!sel.focusNode && el.contains(sel.focusNode)) ); }