@wbiokr/arrow 0.0.1 → 0.0.2

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 ADDED
@@ -0,0 +1,126 @@
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 { ArrowEditor2 } from '@wbiokr/arrow'
35
+
36
+ const editor = new ArrowEditor2('#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
+ 点击空白处或按 `Esc` 键
60
+
61
+ ## API
62
+
63
+ ### 实例化
64
+
65
+ ```javascript
66
+ const editor = new ArrowEditor2(container)
67
+ ```
68
+
69
+ - `container`: CSS 选择器字符串或 DOM 元素
70
+
71
+ ### 方法
72
+
73
+ #### getData()
74
+
75
+ 获取所有箭头数据
76
+
77
+ ```javascript
78
+ const data = editor.getData()
79
+ // 返回:[{ points: [{x, y}, ...], isCurve: boolean }, ...]
80
+ ```
81
+
82
+ #### setData(data)
83
+
84
+ 设置箭头数据
85
+
86
+ ```javascript
87
+ editor.setData([
88
+ {
89
+ points: [{ x: 100, y: 100 }, { x: 200, y: 200 }],
90
+ isCurve: false
91
+ }
92
+ ])
93
+ ```
94
+
95
+ #### clear()
96
+
97
+ 清空所有箭头
98
+
99
+ ```javascript
100
+ editor.clear()
101
+ ```
102
+
103
+ ## 键盘快捷键
104
+
105
+ | 快捷键 | 功能 |
106
+ |--------|------|
107
+ | `Enter` | 完成绘制 |
108
+ | `Esc` | 取消绘制 / 取消选中 |
109
+ | `Ctrl` / `Shift` | 曲线模式(按住) |
110
+
111
+ ## 开发
112
+
113
+ ```bash
114
+ npm install
115
+ npm run dev
116
+ ```
117
+
118
+ ## 打包
119
+
120
+ ```bash
121
+ npm run build
122
+ ```
123
+
124
+ ## License
125
+
126
+ MIT
@@ -1314,22 +1314,20 @@ var ArrowEditor2 = /*#__PURE__*/function () {
1314
1314
  if (this.selected) {
1315
1315
  this.selected = null;
1316
1316
  }
1317
- this._hideToolbar();
1318
1317
  this.render();
1319
1318
  }
1320
1319
 
1321
1320
  // 删除选中的箭头
1322
1321
  }, {
1323
1322
  key: "deleteSelected",
1324
- value:
1325
- // 删除选中的箭头
1326
- function deleteSelected() {
1323
+ value: function deleteSelected() {
1327
1324
  var _this4 = this;
1328
1325
  if (this.selected) {
1329
1326
  this.arrows = this.arrows.filter(function (a) {
1330
1327
  return a !== _this4.selected;
1331
1328
  });
1332
1329
  this.selected = null;
1330
+ this._hideToolbar();
1333
1331
  this.render();
1334
1332
  }
1335
1333
  }
@@ -1408,7 +1406,6 @@ var ArrowEditor2 = /*#__PURE__*/function () {
1408
1406
  this.drawing = false;
1409
1407
  this.current = null;
1410
1408
  this.selected = null;
1411
- this._hideToolbar();
1412
1409
  this.render();
1413
1410
  }
1414
1411
  }]);