@wbiokr/arrow 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -0
- package/dist/bundle.cjs.js +109 -1384
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.esm.js +399 -1346
- package/dist/bundle.esm.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @wbiokr/arrow
|
|
2
|
+
|
|
3
|
+
箭头绘制编辑器 - 在网页上绘制可编辑的箭头
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @wbiokr/arrow
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
### HTML
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<div id="container"></div>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### CSS(可选)
|
|
20
|
+
|
|
21
|
+
```css
|
|
22
|
+
#container {
|
|
23
|
+
position: relative;
|
|
24
|
+
width: 1000px;
|
|
25
|
+
height: 600px;
|
|
26
|
+
background: #fff;
|
|
27
|
+
margin: 50px auto;
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### JavaScript
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import { ArrowEditor } from '@wbiokr/arrow'
|
|
35
|
+
|
|
36
|
+
const editor = new ArrowEditor('#container')
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 使用方法
|
|
40
|
+
|
|
41
|
+
### 绘制箭头
|
|
42
|
+
|
|
43
|
+
1. 点击空白处开始绘制
|
|
44
|
+
2. 移动鼠标添加拐点
|
|
45
|
+
3. 双击或按 `Enter` 完成绘制
|
|
46
|
+
4. 按 `Esc` 取消绘制
|
|
47
|
+
|
|
48
|
+
### 曲线模式
|
|
49
|
+
|
|
50
|
+
按住 `Ctrl` 或 `Shift` 键绘制曲线箭头
|
|
51
|
+
|
|
52
|
+
### 移动箭头
|
|
53
|
+
|
|
54
|
+
1. 点击箭头选中
|
|
55
|
+
2. 拖拽移动箭头
|
|
56
|
+
|
|
57
|
+
### 旋转箭头
|
|
58
|
+
|
|
59
|
+
1. 点击箭头选中
|
|
60
|
+
2. 拖拽顶部的橙色旋转手柄
|
|
61
|
+
|
|
62
|
+
### 缩放箭头
|
|
63
|
+
|
|
64
|
+
1. 点击箭头选中
|
|
65
|
+
2. 拖拽右下角的蓝色缩放手柄
|
|
66
|
+
|
|
67
|
+
### 取消选中
|
|
68
|
+
|
|
69
|
+
点击空白处或按 `Esc` 键
|
|
70
|
+
|
|
71
|
+
## API
|
|
72
|
+
|
|
73
|
+
### 实例化
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const editor = new ArrowEditor(container)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- `container`: CSS 选择器字符串或 DOM 元素
|
|
80
|
+
|
|
81
|
+
### 方法
|
|
82
|
+
|
|
83
|
+
#### getData()
|
|
84
|
+
|
|
85
|
+
获取所有箭头数据
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const data = editor.getData()
|
|
89
|
+
// 返回:[{ points: [{x, y}, ...], isCurve: boolean }, ...]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### setData(data)
|
|
93
|
+
|
|
94
|
+
设置箭头数据
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
editor.setData([
|
|
98
|
+
{
|
|
99
|
+
points: [{ x: 100, y: 100 }, { x: 200, y: 200 }],
|
|
100
|
+
isCurve: false
|
|
101
|
+
}
|
|
102
|
+
])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### clear()
|
|
106
|
+
|
|
107
|
+
清空所有箭头
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
editor.clear()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 键盘快捷键
|
|
114
|
+
|
|
115
|
+
| 快捷键 | 功能 |
|
|
116
|
+
|--------|------|
|
|
117
|
+
| `Enter` | 完成绘制 |
|
|
118
|
+
| `Esc` | 取消绘制 / 取消选中 |
|
|
119
|
+
| `Ctrl` / `Shift` | 曲线模式(按住) |
|
|
120
|
+
|
|
121
|
+
## 开发
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npm install
|
|
125
|
+
npm run dev
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 打包
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run build
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT
|