@leafer-in/arrow 1.9.4 → 1.9.6
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/dist/arrow.cjs +36 -10
- package/dist/arrow.esm.js +37 -11
- package/dist/arrow.esm.min.js +1 -1
- package/dist/arrow.esm.min.js.map +1 -1
- package/dist/arrow.js +36 -10
- package/dist/arrow.min.cjs +1 -1
- package/dist/arrow.min.cjs.map +1 -1
- package/dist/arrow.min.js +1 -1
- package/dist/arrow.min.js.map +1 -1
- package/package.json +4 -4
- package/src/Arrow.ts +7 -3
- package/src/PathArrowModule.ts +25 -7
- package/src/data/arrows.ts +20 -5
- package/types/index.d.ts +3 -2
package/src/PathArrowModule.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IPathArrowModule, IUI, IPathCommandData, IPointData } from '@leafer-ui/interface'
|
|
1
|
+
import { IPathArrowModule, IUI, IPathCommandData, IPointData, IPathDataArrow } from '@leafer-ui/interface'
|
|
2
2
|
import { PathCommandMap as Command, PointHelper } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { arrows, getArrowPath } from './data/arrows'
|
|
@@ -15,8 +15,10 @@ export const PathArrowModule: IPathArrowModule = {
|
|
|
15
15
|
|
|
16
16
|
list: arrows,
|
|
17
17
|
|
|
18
|
-
addArrows(ui: IUI
|
|
19
|
-
const { startArrow, endArrow, strokeWidth, dashPattern, __pathForRender: data } = ui.__
|
|
18
|
+
addArrows(ui: IUI): void {
|
|
19
|
+
const { startArrow, endArrow, strokeWidth, dashPattern, __pathForRender: data, cornerRadius } = ui.__
|
|
20
|
+
|
|
21
|
+
const clonePathForArrow = !cornerRadius // cornerRadius会创建新的render路径,所以不用再clone
|
|
20
22
|
|
|
21
23
|
let command: number, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== 'none'
|
|
22
24
|
|
|
@@ -34,11 +36,11 @@ export const PathArrowModule: IPathArrowModule = {
|
|
|
34
36
|
i += 3
|
|
35
37
|
break
|
|
36
38
|
case C: // bezierCurveTo(x1, y1, x2, y2, x, y)
|
|
37
|
-
if (count === 1 || i + 7
|
|
39
|
+
if (count === 1 || i + 7 >= len - 3) copyPoints(data, last, now, i + 3) // C 或 C + L结束
|
|
38
40
|
i += 7
|
|
39
41
|
break
|
|
40
42
|
case Q: // quadraticCurveTo(x1, y1, x, y)
|
|
41
|
-
if (count === 1 || i + 5
|
|
43
|
+
if (count === 1 || i + 5 >= len - 3) copyPoints(data, last, now, i + 1) // Q 或 Q + L结束
|
|
42
44
|
i += 5
|
|
43
45
|
break
|
|
44
46
|
case Z: // closepath()
|
|
@@ -68,7 +70,13 @@ export const PathArrowModule: IPathArrowModule = {
|
|
|
68
70
|
i += 4
|
|
69
71
|
break
|
|
70
72
|
case U: // arcTo(x1, y1, x2, y2, radius)
|
|
71
|
-
if (count === 1 || i + 6
|
|
73
|
+
if (count === 1 || i + 6 >= len - 3) { // U 或 U + L结束
|
|
74
|
+
copyPoints(data, last, now, i + 1)
|
|
75
|
+
if (i + 6 !== len) { // 避免与结束点重合
|
|
76
|
+
now.x -= (now.x - last.x) / 10
|
|
77
|
+
now.y -= (now.y - last.y) / 10
|
|
78
|
+
}
|
|
79
|
+
}
|
|
72
80
|
i += 6
|
|
73
81
|
break
|
|
74
82
|
}
|
|
@@ -79,7 +87,7 @@ export const PathArrowModule: IPathArrowModule = {
|
|
|
79
87
|
if (count === 2 && useStartArrow) copy(second, command === L ? now : last)
|
|
80
88
|
|
|
81
89
|
if (i === len) {
|
|
82
|
-
const path = ui.__.__pathForRender =
|
|
90
|
+
const path = ui.__.__pathForRender = clonePathForArrow ? [...data] : data
|
|
83
91
|
const pathForArrow: IPathCommandData = ui.__.__pathForArrow = []
|
|
84
92
|
|
|
85
93
|
if (useStartArrow) {
|
|
@@ -124,10 +132,20 @@ export const PathArrowModule: IPathArrowModule = {
|
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
register(name: string, data: IPathDataArrow): void {
|
|
138
|
+
this.list[name] = data
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
get(name: string): IPathDataArrow {
|
|
142
|
+
return this.list[name]
|
|
127
143
|
}
|
|
144
|
+
|
|
128
145
|
}
|
|
129
146
|
|
|
130
147
|
|
|
148
|
+
|
|
131
149
|
function copyPoints(data: IPathCommandData, from: IPointData, to: IPointData, startIndex: number): void {
|
|
132
150
|
copyFrom(from, data[startIndex], data[startIndex + 1])
|
|
133
151
|
copyFrom(to, data[startIndex + 2], data[startIndex + 3])
|
package/src/data/arrows.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IArrowStyle, IArrowTypeData, IPathDataArrow, IPathDataArrowMap, IUI, IPathCommandData, IPointData } from '@leafer-ui/interface'
|
|
2
2
|
import { DataHelper, PointHelper, isObject } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { PathMatrixHelper } from '../PathMatrixHelper'
|
|
@@ -55,9 +55,21 @@ export const arrows: IPathDataArrowMap = {
|
|
|
55
55
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export function getArrowPath(ui: IUI, arrow:
|
|
58
|
+
export function getArrowPath(ui: IUI, arrow: IArrowStyle, from: IPointData, to: IPointData, size: number, connectOffset: IPointData, hasDashPattern?: boolean): IPathCommandData {
|
|
59
|
+
let pathData: IPathDataArrow, scale: number
|
|
60
|
+
|
|
59
61
|
const { strokeCap, strokeJoin } = ui.__
|
|
60
|
-
|
|
62
|
+
|
|
63
|
+
if (isObject(arrow)) {
|
|
64
|
+
if ((arrow as IArrowTypeData).type) {
|
|
65
|
+
scale = (arrow as IArrowTypeData).scale
|
|
66
|
+
pathData = arrows[(arrow as IArrowTypeData).type]
|
|
67
|
+
} else pathData = arrow as IPathDataArrow
|
|
68
|
+
} else {
|
|
69
|
+
pathData = arrows[arrow]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const { offset, connect, path, dashPath } = pathData
|
|
61
73
|
|
|
62
74
|
let connectX = connect ? connect.x : 0
|
|
63
75
|
let offsetX = offset ? offset.x : 0
|
|
@@ -71,9 +83,12 @@ export function getArrowPath(ui: IUI, arrow: IArrowType, from: IPointData, to: I
|
|
|
71
83
|
else if (strokeJoin === 'bevel' && offset.bevelJoin) offsetX += offset.bevelJoin
|
|
72
84
|
}
|
|
73
85
|
|
|
86
|
+
if (scale) layout(data, 0, 0, scale, scale) // 预留箭头比例缩放功能
|
|
87
|
+
|
|
74
88
|
if (offsetX) layout(data, offsetX, 0)
|
|
75
|
-
layout(data, to.x, to.y, scale, scale, getAngle(from, to))
|
|
76
89
|
|
|
77
|
-
|
|
90
|
+
layout(data, to.x, to.y, size, size, getAngle(from, to)) // scale rotate 先围绕 data 数据应用后,再加 to
|
|
91
|
+
|
|
92
|
+
connectOffset.x = (connectX + offsetX) * size
|
|
78
93
|
return data
|
|
79
94
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as _leafer_ui_interface from '@leafer-ui/interface';
|
|
2
|
-
import { IArrow, IArrowData,
|
|
2
|
+
import { IArrow, IArrowData, IArrowStyle, IArrowInputData, IPathDataArrow, IPathArrowModule, IPathCommandData, IPointData, IValue } from '@leafer-ui/interface';
|
|
3
3
|
import { Line, LineData } from '@leafer-ui/draw';
|
|
4
4
|
|
|
5
5
|
declare class Arrow extends Line implements IArrow {
|
|
6
6
|
get __tag(): string;
|
|
7
7
|
__: IArrowData;
|
|
8
|
-
endArrow?:
|
|
8
|
+
endArrow?: IArrowStyle;
|
|
9
9
|
constructor(data?: IArrowInputData);
|
|
10
|
+
static registerArrow(name: string, data: IPathDataArrow): void;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
declare class ArrowData extends LineData implements IArrowData {
|