# we-region

> select region

Latest version **0.0.11** (published 2017-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install we-region
pnpm add we-region
yarn add we-region
bun add we-region
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2017-07-24 |
| First published | 2017-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | zhengjunxin |
| Maintainers | joezheng |
| Keywords | canvas, select-region |

## Links

- npm: https://www.npmjs.com/package/we-region
- Repository: https://github.com/weiying-shenzhen/weRegion
- Homepage: https://github.com/weiying-shenzhen/weRegion#readme
- Issues: https://github.com/weiying-shenzhen/weRegion/issues
- npm.io page: https://npm.io/package/we-region

## Dependencies (1)

- [raf-plus](https://npm.io/package/raf-plus.md) 0.0.5

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.0.11 (latest) — 2017-07-24
- 0.0.8 — 2017-07-08
- 0.0.7 — 2017-07-08
- 0.0.6 — 2017-07-08
- 0.0.5 — 2017-07-08
- 0.0.4 — 2017-07-07
- 0.0.3 — 2017-07-03
- 0.0.2 — 2017-07-02
- 0.0.1 — 2017-07-02

## README

# WeRegion

weRegion 是一个可以不修改原逻辑，增加拉选框的功能的鼠标拉选框库。原理是通过增加一个透明 canvas 绘制拉选框。应用可参考[demo](https://weiying-shenzhen.github.io/weRegion/)

## 下载

```bash
npm install --save we-region
```
或者
```bash
yarn add we-region
```

## 使用

通过传入 DOM 选择器使用

```js
import WeRegion from 'we-region'

const weRegion = new WeRegion('.mask')
```

## 配置

weRegion 可以在实例化时，通过传入第二个参数进行配置

```js
const weRegion = new WeRegion('.mask', {
    borderColor: '#0099FF',
    bodyColor: 'rgba(195, 213, 237, 0.6)',
})
```

配置项包括

### options.move({ startX, startY, width, height })

拉选时的回调。其中 `startX` 和 `startY` 表示鼠标的起始位置，`width` 和 `height` 表示拉选框的宽高

### options.end({ startX, startY, width, height })

拉选结束时的回调，释放鼠标按钮和鼠标移除遮罩层时触发。其中 `startX` 和 `startY` 表示鼠标的起始位置，`width` 和 `height` 表示拉选框的宽高

### options.width

遮罩层的宽度，默认是取其父元素的宽度

### options.height

遮罩层的高度，默认是取其父元素的高度

### options.borderColor

选择框的边框颜色，默认是 #0099FF

### options.bodyColor

选择框的颜色，默认是 rgba(195, 213, 237, 0.6)

### options.zIndex

遮罩层的 z-index（注意需要比被覆盖的元素高），默认是 9527

## 实例方法

weRegion 提供 2 个实例方法

### `clear()`

清除遮罩层中的拉选框

### `isRectCross(rect1, rect2)`

检测给定矩形 rect1 与 rect2 是否相交。rect1 和 rect2 的签名均为 `{ x, y, width, height }`，其中 `x` 和 `y` 表示矩形的横坐标和纵坐标，`width` 和 `height` 表示矩形的宽和高。若 rect2 省略，则默认为当前拉选框的坐标和宽高

## Licence

MIT

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