getCaretRect()
You need the caret geometry now.
Browser primitive · 0 runtime dependencies
Reliable viewport coordinates for inputs, textareas and editable DOM, with virtual references for floating UI.
npm install @nipe-solutions/caret-geometry
Caret rectPositioned popup
Measured live in your browser. Text stays on this page.01 / API layers
getCaretRect()You need the caret geometry now.
createCaretVirtualElement()
Another library expects a live
getBoundingClientRect() reference.
observeCaretGeometry()You need to know when the caret itself changes.
02 / Responsibility boundary
Caret Geometry tracks the caret. Your positioning engine tracks the world around it.
Typing · arrow keys · selection · mouse caret movement · internal input/textarea scroll · composition / IME
Caret Geometry → updatePage or modal scroll · ancestor scroll · window resize · layout shift · floating-content resize · collision / flip / shift
Positioning engine → update
Both feed one updatePosition() function.
03 / Why compose them?
Floating-positioning libraries answer: “Given this reference rectangle, where should the floating element go?” They handle placement, collision, scroll, resize and layout movement.
Inputs and textareas have no native caret element. The browser
exposes a value and selection indices—not
caretElement.getBoundingClientRect(). Caret Geometry
supplies that missing reference.
input → caret moves → observeCaretGeometry() → update
ancestor scroll → positioner auto-update → update
autoUpdate() alone is not enough: typing
can move the virtual reference while the textarea, viewport and
ancestors stay still. The reverse is also true: caret observation
alone cannot see the page move around it.
04 / Correct integration
createCaretVirtualElement() provides live
geometry.observeCaretGeometry() detects
caret-local changes.autoUpdate() detects
environmental changes.computePosition() places
the popup.
05 / Positioning stress test
Type, move the caret, scroll either surface, or change its typography. Cyan is geometry; orange is positioning.
If Caret Geometry helps you build interfaces around the caret, a GitHub star helps other developers discover it. Explore more tools from NIPE Open Source for your next project.
06 / Responsibility matrix
| Concern | Caret Geometry | Positioning / overlay layer |
|---|---|---|
| Locate input, textarea or editable caret | ✓ | — |
| Typing, selection and internal-control scroll | ✓ | — |
| Page/ancestor scroll and layout shift | — | ✓ |
| Collision, flip and shift | — | ✓ |
| Portal rendering and interaction semantics | — | Framework / application |
Popup next to the input box? No. Use the element directly.
Popup next to the caret inside it? Yes.
Need collision, flip or portals? Add a positioning or overlay layer.
07 / Continue
No React required. No Floating UI required. No runtime dependencies.