@leafer-in/arrow 1.8.0 → 1.9.0
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 +276 -195
- package/dist/arrow.esm.js +271 -193
- package/dist/arrow.esm.min.js +1 -1
- package/dist/arrow.esm.min.js.map +1 -1
- package/dist/arrow.js +231 -203
- 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/data/arrows.ts +2 -2
package/dist/arrow.esm.js
CHANGED
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
import { LineData, decorateLeafAttr, attr, doStrokeType, dataProcessor, registerUI, Line, PathCommandMap, PointHelper, DataHelper, Plugin, UI, PathArrow, Paint } from
|
|
2
|
-
|
|
3
|
-
/******************************************************************************
|
|
4
|
-
Copyright (c) Microsoft Corporation.
|
|
5
|
-
|
|
6
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
-
purpose with or without fee is hereby granted.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
***************************************************************************** */
|
|
17
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function __decorate(decorators, target, key, desc) {
|
|
21
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
-
var e = new Error(message);
|
|
29
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
-
};
|
|
1
|
+
import { LineData, decorateLeafAttr, attr, doStrokeType, dataProcessor, registerUI, Line, PathCommandMap, PointHelper, DataHelper, isObject, Plugin, UI, PathArrow, Paint } from "@leafer-ui/draw";
|
|
31
2
|
|
|
32
|
-
|
|
3
|
+
function __decorate(decorators, target, key, desc) {
|
|
4
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
33
7
|
}
|
|
34
8
|
|
|
9
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
10
|
+
var e = new Error(message);
|
|
11
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class ArrowData extends LineData {}
|
|
15
|
+
|
|
35
16
|
function arrowType(defaultValue) {
|
|
36
|
-
return decorateLeafAttr(defaultValue,
|
|
17
|
+
return decorateLeafAttr(defaultValue, key => attr({
|
|
37
18
|
set(value) {
|
|
38
19
|
if (this.__setAttr(key, value)) {
|
|
39
20
|
const data = this.__;
|
|
40
|
-
data.__useArrow = data.startArrow !==
|
|
21
|
+
data.__useArrow = data.startArrow !== "none" || data.endArrow !== "none";
|
|
41
22
|
doStrokeType(this);
|
|
42
23
|
}
|
|
43
24
|
}
|
|
@@ -45,57 +26,59 @@ function arrowType(defaultValue) {
|
|
|
45
26
|
}
|
|
46
27
|
|
|
47
28
|
let Arrow = class Arrow extends Line {
|
|
48
|
-
get __tag() {
|
|
29
|
+
get __tag() {
|
|
30
|
+
return "Arrow";
|
|
31
|
+
}
|
|
49
32
|
constructor(data) {
|
|
50
33
|
super(data);
|
|
51
34
|
this.__.__useArrow = true;
|
|
52
35
|
}
|
|
53
36
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
__decorate([
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const { rotate: rotate$1, copyFrom: copyFrom$1, scale } = PointHelper;
|
|
37
|
+
|
|
38
|
+
__decorate([ dataProcessor(ArrowData) ], Arrow.prototype, "__", void 0);
|
|
39
|
+
|
|
40
|
+
__decorate([ arrowType("angle") ], Arrow.prototype, "endArrow", void 0);
|
|
41
|
+
|
|
42
|
+
Arrow = __decorate([ registerUI() ], Arrow);
|
|
43
|
+
|
|
44
|
+
const {M: M$1, L: L$1, C: C$1, Q: Q$1, O: O$1} = PathCommandMap;
|
|
45
|
+
|
|
46
|
+
const {rotate: rotate$1, copyFrom: copyFrom$1, scale: scale} = PointHelper;
|
|
47
|
+
|
|
66
48
|
const point = {};
|
|
49
|
+
|
|
67
50
|
const PathMatrixHelper = {
|
|
68
51
|
layout(data, x, y, scaleX, scaleY, rotation, origin) {
|
|
69
52
|
let command, i = 0, j, len = data.length;
|
|
70
53
|
while (i < len) {
|
|
71
54
|
command = data[i];
|
|
72
55
|
switch (command) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
56
|
+
case M$1:
|
|
57
|
+
case L$1:
|
|
58
|
+
setPoint$1(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
|
|
59
|
+
i += 3;
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case C$1:
|
|
63
|
+
for (j = 1; j < 6; j += 2) setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
|
|
64
|
+
i += 7;
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case Q$1:
|
|
68
|
+
for (j = 1; j < 4; j += 2) setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
|
|
69
|
+
i += 5;
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case O$1:
|
|
73
|
+
data[i + 1] += x;
|
|
74
|
+
data[i + 2] += y;
|
|
75
|
+
if (scaleX) data[i + 3] *= scaleX;
|
|
76
|
+
if (rotation) {
|
|
77
|
+
data[i + 4] += rotation;
|
|
78
|
+
data[i + 5] += rotation;
|
|
79
|
+
}
|
|
80
|
+
i += 7;
|
|
81
|
+
break;
|
|
99
82
|
}
|
|
100
83
|
}
|
|
101
84
|
},
|
|
@@ -103,141 +86,229 @@ const PathMatrixHelper = {
|
|
|
103
86
|
PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
|
|
104
87
|
}
|
|
105
88
|
};
|
|
89
|
+
|
|
106
90
|
function setPoint$1(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
|
|
107
91
|
copyFrom$1(point, data[startIndex], data[startIndex + 1]);
|
|
108
|
-
if (rotation)
|
|
109
|
-
|
|
110
|
-
if (scaleX)
|
|
111
|
-
scale(point, scaleX, scaleY);
|
|
92
|
+
if (rotation) rotate$1(point, rotation, origin);
|
|
93
|
+
if (scaleX) scale(point, scaleX, scaleY);
|
|
112
94
|
data[startIndex] = x + point.x;
|
|
113
95
|
data[startIndex + 1] = y + point.y;
|
|
114
96
|
}
|
|
115
97
|
|
|
116
|
-
const { layout, rotate } = PathMatrixHelper;
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
98
|
+
const {layout: layout, rotate: rotate} = PathMatrixHelper;
|
|
99
|
+
|
|
100
|
+
const {getAngle: getAngle} = PointHelper;
|
|
101
|
+
|
|
102
|
+
const half = {
|
|
103
|
+
x: -.5
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const angle = {
|
|
107
|
+
connect: half,
|
|
108
|
+
offset: {
|
|
109
|
+
x: -.71,
|
|
110
|
+
bevelJoin: .36,
|
|
111
|
+
roundJoin: .22
|
|
112
|
+
},
|
|
113
|
+
path: [ 1, -3, -3, 2, 0, 0, 2, -3, 3 ]
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const angleSide = {
|
|
117
|
+
connect: half,
|
|
118
|
+
offset: {
|
|
119
|
+
x: -1.207,
|
|
120
|
+
bevelJoin: .854,
|
|
121
|
+
roundJoin: .707
|
|
122
|
+
},
|
|
123
|
+
path: [ 1, -3, -3, 2, 0, 0, 2, -1, 0 ]
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const triangleLinePath = [ 1, -3, 0, 2, -3, -2, 2, 0, 0, 2, -3, 2, 2, -3, 0 ];
|
|
127
|
+
|
|
128
|
+
const triangle = {
|
|
129
|
+
connect: half,
|
|
130
|
+
offset: {
|
|
131
|
+
x: -.9,
|
|
132
|
+
bevelJoin: .624,
|
|
133
|
+
roundJoin: .4
|
|
134
|
+
},
|
|
135
|
+
path: [ ...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1 ],
|
|
136
|
+
dashPath: [ 1, -2, 0, 2, -.5, 0 ]
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const arrowLinePath = [ 1, -3, 0, 2, -3.5, -1.8, 2, 0, 0, 2, -3.5, 1.8, 2, -3, 0 ];
|
|
140
|
+
|
|
141
|
+
const arrow = {
|
|
142
|
+
connect: half,
|
|
143
|
+
offset: {
|
|
144
|
+
x: -1.1,
|
|
145
|
+
bevelJoin: .872,
|
|
146
|
+
roundJoin: .6
|
|
147
|
+
},
|
|
148
|
+
path: [ ...arrowLinePath, 1, -2.25, .95, 2, -2.25, -.95 ],
|
|
149
|
+
dashPath: [ 1, -3, 0, 2, -.5, 0 ]
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const triangleFlip = {
|
|
153
|
+
offset: half,
|
|
154
|
+
path: [ ...triangle.path ],
|
|
155
|
+
dashPath: [ 1, -2.5, 0, 2, -1, 0 ]
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
rotate(triangleFlip.path, 180, {
|
|
159
|
+
x: -1.5,
|
|
160
|
+
y: 0
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const circleLine = {
|
|
164
|
+
connect: {
|
|
165
|
+
x: -1.3
|
|
166
|
+
},
|
|
167
|
+
path: [ 1, 1.8, -.1, 2, 1.8, 0, 26, 0, 0, 1.8, 0, 359, 0 ]
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const circle = {
|
|
171
|
+
connect: {
|
|
172
|
+
x: .5
|
|
173
|
+
},
|
|
174
|
+
path: [ ...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0 ],
|
|
175
|
+
dashPath: [ 1, -.5, 0, 2, .5, 0 ]
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const squareLine = {
|
|
179
|
+
connect: {
|
|
180
|
+
x: -1.3
|
|
181
|
+
},
|
|
182
|
+
path: [ 1, -1.4, 0, 2, -1.4, -1.4, 2, 1.4, -1.4, 2, 1.4, 1.4, 2, -1.4, 1.4, 2, -1.4, 0 ]
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const square = {
|
|
186
|
+
path: [ ...squareLine.path, 2, -1.4, -.49, 2, 1, -.49, 1, -1.4, .49, 2, 1, .49 ]
|
|
187
|
+
};
|
|
188
|
+
|
|
131
189
|
const diamondLine = DataHelper.clone(squareLine);
|
|
190
|
+
|
|
132
191
|
const diamond = DataHelper.clone(square);
|
|
192
|
+
|
|
133
193
|
rotate(diamondLine.path, 45);
|
|
194
|
+
|
|
134
195
|
rotate(diamond.path, 45);
|
|
135
|
-
|
|
196
|
+
|
|
197
|
+
const mark = {
|
|
198
|
+
offset: half,
|
|
199
|
+
path: [ 1, 0, -2, 2, 0, 2 ]
|
|
200
|
+
};
|
|
201
|
+
|
|
136
202
|
const arrows = {
|
|
137
|
-
angle,
|
|
138
|
-
|
|
139
|
-
arrow,
|
|
140
|
-
triangle,
|
|
141
|
-
|
|
142
|
-
circle,
|
|
143
|
-
|
|
144
|
-
square,
|
|
145
|
-
|
|
146
|
-
diamond,
|
|
147
|
-
|
|
148
|
-
mark
|
|
203
|
+
angle: angle,
|
|
204
|
+
"angle-side": angleSide,
|
|
205
|
+
arrow: arrow,
|
|
206
|
+
triangle: triangle,
|
|
207
|
+
"triangle-flip": triangleFlip,
|
|
208
|
+
circle: circle,
|
|
209
|
+
"circle-line": circleLine,
|
|
210
|
+
square: square,
|
|
211
|
+
"square-line": squareLine,
|
|
212
|
+
diamond: diamond,
|
|
213
|
+
"diamond-line": diamondLine,
|
|
214
|
+
mark: mark
|
|
149
215
|
};
|
|
216
|
+
|
|
150
217
|
function getArrowPath(ui, arrow, from, to, scale, connectOffset, hasDashPattern) {
|
|
151
|
-
const { strokeCap, strokeJoin } = ui.__;
|
|
152
|
-
const { offset, connect, path, dashPath } = (
|
|
218
|
+
const {strokeCap: strokeCap, strokeJoin: strokeJoin} = ui.__;
|
|
219
|
+
const {offset: offset, connect: connect, path: path, dashPath: dashPath} = isObject(arrow) ? arrow : arrows[arrow];
|
|
153
220
|
let connectX = connect ? connect.x : 0;
|
|
154
221
|
let offsetX = offset ? offset.x : 0;
|
|
155
|
-
const data = [...path];
|
|
156
|
-
if (hasDashPattern && dashPath)
|
|
157
|
-
|
|
158
|
-
if (strokeCap !== 'none')
|
|
159
|
-
connectX -= 0.5;
|
|
222
|
+
const data = [ ...path ];
|
|
223
|
+
if (hasDashPattern && dashPath) data.push(...dashPath);
|
|
224
|
+
if (strokeCap !== "none") connectX -= .5;
|
|
160
225
|
if (offset) {
|
|
161
|
-
if (strokeJoin ===
|
|
162
|
-
offsetX += offset.roundJoin;
|
|
163
|
-
else if (strokeJoin === 'bevel' && offset.bevelJoin)
|
|
164
|
-
offsetX += offset.bevelJoin;
|
|
226
|
+
if (strokeJoin === "round" && offset.roundJoin) offsetX += offset.roundJoin; else if (strokeJoin === "bevel" && offset.bevelJoin) offsetX += offset.bevelJoin;
|
|
165
227
|
}
|
|
166
|
-
if (offsetX)
|
|
167
|
-
layout(data, offsetX, 0);
|
|
228
|
+
if (offsetX) layout(data, offsetX, 0);
|
|
168
229
|
layout(data, to.x, to.y, scale, scale, getAngle(from, to));
|
|
169
230
|
connectOffset.x = (connectX + offsetX) * scale;
|
|
170
231
|
return data;
|
|
171
232
|
}
|
|
172
233
|
|
|
173
|
-
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
|
|
174
|
-
|
|
234
|
+
const {M: M, L: L, C: C, Q: Q, Z: Z, N: N, D: D, X: X, G: G, F: F, O: O, P: P, U: U} = PathCommandMap;
|
|
235
|
+
|
|
236
|
+
const {copy: copy, copyFrom: copyFrom, getDistancePoint: getDistancePoint} = PointHelper;
|
|
237
|
+
|
|
175
238
|
const connectPoint = {};
|
|
239
|
+
|
|
176
240
|
const first = {}, second = {};
|
|
241
|
+
|
|
177
242
|
const last = {}, now = {};
|
|
243
|
+
|
|
178
244
|
const PathArrowModule = {
|
|
179
245
|
list: arrows,
|
|
180
246
|
addArrows(ui, changeRenderPath) {
|
|
181
|
-
const { startArrow, endArrow, strokeWidth, dashPattern, __pathForRender: data
|
|
182
|
-
let command, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !==
|
|
247
|
+
const {startArrow: startArrow, endArrow: endArrow, strokeWidth: strokeWidth, dashPattern: dashPattern, __pathForRender: data} = ui.__;
|
|
248
|
+
let command, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== "none";
|
|
183
249
|
while (i < len) {
|
|
184
250
|
command = data[i];
|
|
185
251
|
switch (command) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
252
|
+
case M:
|
|
253
|
+
case L:
|
|
254
|
+
if (count < 2 || i + 6 >= len) {
|
|
255
|
+
copyFrom(now, data[i + 1], data[i + 2]);
|
|
256
|
+
if (!count && useStartArrow) copy(first, now);
|
|
257
|
+
}
|
|
258
|
+
i += 3;
|
|
259
|
+
break;
|
|
260
|
+
|
|
261
|
+
case C:
|
|
262
|
+
if (count === 1 || i + 7 === len) copyPoints(data, last, now, i + 3);
|
|
263
|
+
i += 7;
|
|
264
|
+
break;
|
|
265
|
+
|
|
266
|
+
case Q:
|
|
267
|
+
if (count === 1 || i + 5 === len) copyPoints(data, last, now, i + 1);
|
|
268
|
+
i += 5;
|
|
269
|
+
break;
|
|
270
|
+
|
|
271
|
+
case Z:
|
|
272
|
+
return;
|
|
273
|
+
|
|
274
|
+
case N:
|
|
275
|
+
i += 5;
|
|
276
|
+
break;
|
|
277
|
+
|
|
278
|
+
case D:
|
|
279
|
+
i += 9;
|
|
280
|
+
break;
|
|
281
|
+
|
|
282
|
+
case X:
|
|
283
|
+
i += 6;
|
|
284
|
+
break;
|
|
285
|
+
|
|
286
|
+
case G:
|
|
287
|
+
i += 9;
|
|
288
|
+
break;
|
|
289
|
+
|
|
290
|
+
case F:
|
|
291
|
+
i += 5;
|
|
292
|
+
break;
|
|
293
|
+
|
|
294
|
+
case O:
|
|
295
|
+
i += 7;
|
|
296
|
+
break;
|
|
297
|
+
|
|
298
|
+
case P:
|
|
299
|
+
i += 4;
|
|
300
|
+
break;
|
|
301
|
+
|
|
302
|
+
case U:
|
|
303
|
+
if (count === 1 || i + 6 === len) copyPoints(data, last, now, i + 1);
|
|
304
|
+
i += 6;
|
|
305
|
+
break;
|
|
233
306
|
}
|
|
234
307
|
count++;
|
|
235
|
-
if (count === 1 && command !== M)
|
|
236
|
-
|
|
237
|
-
if (count === 2 && useStartArrow)
|
|
238
|
-
copy(second, command === L ? now : last);
|
|
308
|
+
if (count === 1 && command !== M) return;
|
|
309
|
+
if (count === 2 && useStartArrow) copy(second, command === L ? now : last);
|
|
239
310
|
if (i === len) {
|
|
240
|
-
const path = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
|
|
311
|
+
const path = ui.__.__pathForRender = changeRenderPath ? [ ...data ] : data;
|
|
241
312
|
const pathForArrow = ui.__.__pathForArrow = [];
|
|
242
313
|
if (useStartArrow) {
|
|
243
314
|
const startArrowPath = getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint, !!dashPattern);
|
|
@@ -248,50 +319,57 @@ const PathArrowModule = {
|
|
|
248
319
|
path[2] = second.y;
|
|
249
320
|
}
|
|
250
321
|
}
|
|
251
|
-
if (endArrow && endArrow !==
|
|
322
|
+
if (endArrow && endArrow !== "none") {
|
|
252
323
|
const endArrowPath = getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint, !!dashPattern);
|
|
253
324
|
dashPattern ? pathForArrow.push(...endArrowPath) : path.push(...endArrowPath);
|
|
254
325
|
if (connectPoint.x) {
|
|
255
326
|
getDistancePoint(now, last, -connectPoint.x, true);
|
|
256
327
|
let index;
|
|
257
328
|
switch (command) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
329
|
+
case L:
|
|
330
|
+
index = i - 3 + 1;
|
|
331
|
+
break;
|
|
332
|
+
|
|
333
|
+
case C:
|
|
334
|
+
index = i - 7 + 5;
|
|
335
|
+
break;
|
|
336
|
+
|
|
337
|
+
case Q:
|
|
338
|
+
index = i - 5 + 3;
|
|
339
|
+
break;
|
|
340
|
+
|
|
341
|
+
case U:
|
|
342
|
+
index = i - 6 + 3;
|
|
343
|
+
break;
|
|
270
344
|
}
|
|
271
|
-
if (index)
|
|
272
|
-
setPoint(path, last, index);
|
|
345
|
+
if (index) setPoint(path, last, index);
|
|
273
346
|
}
|
|
274
347
|
}
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
348
|
+
} else {
|
|
277
349
|
copy(last, now);
|
|
278
350
|
}
|
|
279
351
|
}
|
|
280
352
|
}
|
|
281
353
|
};
|
|
354
|
+
|
|
282
355
|
function copyPoints(data, from, to, startIndex) {
|
|
283
356
|
copyFrom(from, data[startIndex], data[startIndex + 1]);
|
|
284
357
|
copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
|
|
285
358
|
}
|
|
359
|
+
|
|
286
360
|
function setPoint(data, point, startIndex) {
|
|
287
361
|
data[startIndex] = point.x;
|
|
288
362
|
data[startIndex + 1] = point.y;
|
|
289
363
|
}
|
|
290
364
|
|
|
291
|
-
Plugin.add(
|
|
292
|
-
|
|
293
|
-
UI.addAttr(
|
|
365
|
+
Plugin.add("arrow");
|
|
366
|
+
|
|
367
|
+
UI.addAttr("startArrow", "none", arrowType);
|
|
368
|
+
|
|
369
|
+
UI.addAttr("endArrow", "none", arrowType);
|
|
370
|
+
|
|
294
371
|
Object.assign(PathArrow, PathArrowModule);
|
|
372
|
+
|
|
295
373
|
Object.assign(Paint, {
|
|
296
374
|
strokeArrow(_stroke, ui, canvas) {
|
|
297
375
|
if (ui.__.dashPattern) {
|
package/dist/arrow.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{LineData as e,decorateLeafAttr as t,attr as r,doStrokeType as o,dataProcessor as n,registerUI as a,Line as s,PathCommandMap as c,PointHelper as i,DataHelper as h,
|
|
1
|
+
import{LineData as e,decorateLeafAttr as t,attr as r,doStrokeType as o,dataProcessor as n,registerUI as a,Line as s,PathCommandMap as c,PointHelper as i,DataHelper as h,isObject as p,Plugin as l,UI as d,PathArrow as f,Paint as u}from"@leafer-ui/draw";function _(e,t,r,o){var n,a=arguments.length,s=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,o);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(s=(a<3?n(s):a>3?n(t,r,s):n(t,r))||s);return a>3&&s&&Object.defineProperty(t,r,s),s}"function"==typeof SuppressedError&&SuppressedError;class b extends e{}function x(e){return t(e,e=>r({set(t){if(this.__setAttr(e,t)){const e=this.__;e.__useArrow="none"!==e.startArrow||"none"!==e.endArrow,o(this)}}}))}let k=class extends s{get __tag(){return"Arrow"}constructor(e){super(e),this.__.__useArrow=!0}};_([n(b)],k.prototype,"__",void 0),_([x("angle")],k.prototype,"endArrow",void 0),k=_([a()],k);const{M:w,L:y,C:g,Q:A,O:P}=c,{rotate:J,copyFrom:v,scale:m}=i,F={},O={layout(e,t,r,o,n,a,s){let c,i,h=0,p=e.length;for(;h<p;)switch(c=e[h],c){case w:case y:j(e,h+1,t,r,o,n,a,s),h+=3;break;case g:for(i=1;i<6;i+=2)j(e,h+i,t,r,o,n,a,s);h+=7;break;case A:for(i=1;i<4;i+=2)j(e,h+i,t,r,o,n,a,s);h+=5;break;case P:e[h+1]+=t,e[h+2]+=r,o&&(e[h+3]*=o),a&&(e[h+4]+=a,e[h+5]+=a),h+=7}},rotate(e,t,r){O.layout(e,0,0,1,1,t,r)}};function j(e,t,r,o,n,a,s,c){v(F,e[t],e[t+1]),s&&J(F,s,c),n&&m(F,n,a),e[t]=r+F.x,e[t+1]=o+F.y}const{layout:R,rotate:D}=O,{getAngle:C}=i,q={x:-.5},E={connect:q,offset:{x:-.71,bevelJoin:.36,roundJoin:.22},path:[1,-3,-3,2,0,0,2,-3,3]},L={connect:q,offset:{x:-1.207,bevelJoin:.854,roundJoin:.707},path:[1,-3,-3,2,0,0,2,-1,0]},M={connect:q,offset:{x:-.9,bevelJoin:.624,roundJoin:.4},path:[1,-3,0,2,-3,-2,2,0,0,2,-3,2,2,-3,0,1,-2.05,1.1,2,-2.05,-1.1],dashPath:[1,-2,0,2,-.5,0]},Q={connect:q,offset:{x:-1.1,bevelJoin:.872,roundJoin:.6},path:[1,-3,0,2,-3.5,-1.8,2,0,0,2,-3.5,1.8,2,-3,0,1,-2.25,.95,2,-2.25,-.95],dashPath:[1,-3,0,2,-.5,0]},S={offset:q,path:[...M.path],dashPath:[1,-2.5,0,2,-1,0]};D(S.path,180,{x:-1.5,y:0});const B={connect:{x:-1.3},path:[1,1.8,-.1,2,1.8,0,26,0,0,1.8,0,359,0]},G={connect:{x:.5},path:[...B.path,1,0,0,26,0,0,1,0,360,0],dashPath:[1,-.5,0,2,.5,0]},N={connect:{x:-1.3},path:[1,-1.4,0,2,-1.4,-1.4,2,1.4,-1.4,2,1.4,1.4,2,-1.4,1.4,2,-1.4,0]},U={path:[...N.path,2,-1.4,-.49,2,1,-.49,1,-1.4,.49,2,1,.49]},W=h.clone(N),X=h.clone(U);D(W.path,45),D(X.path,45);const Z={angle:E,"angle-side":L,arrow:Q,triangle:M,"triangle-flip":S,circle:G,"circle-line":B,square:U,"square-line":N,diamond:X,"diamond-line":W,mark:{offset:q,path:[1,0,-2,2,0,2]}};function z(e,t,r,o,n,a,s){const{strokeCap:c,strokeJoin:i}=e.__,{offset:h,connect:l,path:d,dashPath:f}=p(t)?t:Z[t];let u=l?l.x:0,_=h?h.x:0;const b=[...d];return s&&f&&b.push(...f),"none"!==c&&(u-=.5),h&&("round"===i&&h.roundJoin?_+=h.roundJoin:"bevel"===i&&h.bevelJoin&&(_+=h.bevelJoin)),_&&R(b,_,0),R(b,o.x,o.y,n,n,C(r,o)),a.x=(u+_)*n,b}const{M:H,L:I,C:K,Q:T,Z:V,N:Y,D:$,X:ee,G:te,F:re,O:oe,P:ne,U:ae}=c,{copy:se,copyFrom:ce,getDistancePoint:ie}=i,he={},pe={},le={},de={},fe={},ue={list:Z,addArrows(e,t){const{startArrow:r,endArrow:o,strokeWidth:n,dashPattern:a,__pathForRender:s}=e.__;let c,i=0,h=s.length,p=0,l=r&&"none"!==r;for(;i<h;){switch(c=s[i],c){case H:case I:(p<2||i+6>=h)&&(ce(fe,s[i+1],s[i+2]),!p&&l&&se(pe,fe)),i+=3;break;case K:1!==p&&i+7!==h||_e(s,de,fe,i+3),i+=7;break;case T:1!==p&&i+5!==h||_e(s,de,fe,i+1),i+=5;break;case V:return;case Y:i+=5;break;case $:i+=9;break;case ee:i+=6;break;case te:i+=9;break;case re:i+=5;break;case oe:i+=7;break;case ne:i+=4;break;case ae:1!==p&&i+6!==h||_e(s,de,fe,i+1),i+=6}if(p++,1===p&&c!==H)return;if(2===p&&l&&se(le,c===I?fe:de),i===h){const h=e.__.__pathForRender=t?[...s]:s,p=e.__.__pathForArrow=[];if(l){const t=z(e,r,le,pe,n,he,!!a);a?p.push(...t):h.push(...t),he.x&&(ie(pe,le,-he.x,!0),h[1]=le.x,h[2]=le.y)}if(o&&"none"!==o){const t=z(e,o,de,fe,n,he,!!a);if(a?p.push(...t):h.push(...t),he.x){let e;switch(ie(fe,de,-he.x,!0),c){case I:e=i-3+1;break;case K:e=i-7+5;break;case T:e=i-5+3;break;case ae:e=i-6+3}e&&be(h,de,e)}}}else se(de,fe)}}};function _e(e,t,r,o){ce(t,e[o],e[o+1]),ce(r,e[o+2],e[o+3])}function be(e,t,r){e[r]=t.x,e[r+1]=t.y}l.add("arrow"),d.addAttr("startArrow","none",x),d.addAttr("endArrow","none",x),Object.assign(f,ue),Object.assign(u,{strokeArrow(e,t,r){t.__.dashPattern&&(r.beginPath(),t.__drawPathByData(r,t.__.__pathForArrow),r.dashPattern=null,r.stroke())}});export{k as Arrow,b as ArrowData,ue as PathArrowModule,O as PathMatrixHelper,x as arrowType};
|
|
2
2
|
//# sourceMappingURL=arrow.esm.min.js.map
|