# selection-range-enhancer

> Helpers to work with window.Selection and Range. Allows to subscribe, find intersections, set and remove selections

Latest version **1.0.3** (published 2020-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install selection-range-enhancer
pnpm add selection-range-enhancer
yarn add selection-range-enhancer
bun add selection-range-enhancer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-10-26 |
| First published | 2020-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 10.0.0 |
| Dependencies | 0 |
| Unpacked size | 24 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Nik Mostovoy |
| Maintainers | xnimorz |
| Keywords | selection, range, selection-subscribe, handle-selection, caret |

## Links

- npm: https://www.npmjs.com/package/selection-range-enhancer
- Repository: https://github.com/xnimorz/selection-range-enhancer
- Homepage: https://github.com/xnimorz/selection-range-enhancer#readme
- Issues: https://github.com/xnimorz/selection-range-enhancer/issues
- npm.io page: https://npm.io/package/selection-range-enhancer

## Recent versions

- 1.0.3 (latest) — 2020-10-26
- 0.0.1-beta5 (beta) — 2020-10-20
- 1.0.2 — 2020-10-25
- 1.0.1 — 2020-10-21
- 1.0.0 — 2020-10-20
- 0.0.1-beta4 — 2020-10-20
- 0.0.1-beta2 — 2020-10-20
- 0.0.1-beta — 2020-10-20

## README

# Enhance window.Selection

Demo: https://codesandbox.io/s/selection-range-enhancer-fwuy8?file=/src/index.js

This project is dedicated to adding some functions when you work with selection.

Here are the possibilities:

1. tracks user selection throughout mouse, keyboard, touch, and mouse events
2. finds intersections between selection and target node
3. proxies addRange, removeAllRange funcs

## API

### track

This function allows you to subscribe to selection changes

| _Argument_                   | _Type_                                                                                                                                            | _Description_                                                                                                                                                                  |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `htmlElement`                | Node                                                                                                                                              | will be used to subscriptions, if `subsscribeToDocument` is false                                                                                                              |
| `config.callback`            | `(selection: Selection, additional?: { kind?: OneOf['mouse', 'keyboard', 'pointer', 'touch']; reason?: oneOf['move', 'down', 'up'] }) => unknown` | will be called on every selection change                                                                                                                                       |
| `config.useBubbling`         | `boolean`                                                                                                                                         | by default track subscribes with capture flag, you are able to turn off it providing this param                                                                                |
| `config.trackDynamically`    | `boolean`                                                                                                                                         | will call `config.callback` on every touch \ mouse \ pointer`move` if this param switched to true. Otherwise, callback is called only when touch \ mouse \ pointer is released. Warning: it could reduce the performance of your application. For better UX use debouncing with this callback! |
| `config.trackMouse`          | `boolean`                                                                                                                                         | should track mouse events                                                                                                                                                      |
| `config.trackKeyBoard`       | `boolean`                                                                                                                                         | should track keyboard events                                                                                                                                                   |
| `config.trackPointer`        | `boolean`                                                                                                                                         | should track pointer events                                                                                                                                                    |
| `config.trackTouch`          | `boolean`                                                                                                                                         | should track touch events                                                                                                                                                      |
| `config.subscribeToDocument` | `boolean`                                                                                                                                         | should subscribe events to the document instead of provided htmlElement                                                                                                        |

---
_Source: https://npm.io/package/selection-range-enhancer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
