@leafer-in/arrow 1.0.0-rc.16

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present, Chao (Leafer) Wan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @leafer-in/arrow
@@ -0,0 +1,276 @@
1
+ import { LineData, dataProcessor, strokeType, registerUI, Line, PathCommandMap, PointHelper, DataHelper, PathArrow } from '@leafer-ui/draw';
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 */
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
+ };
31
+
32
+ class ArrowData extends LineData {
33
+ }
34
+
35
+ let Arrow = class Arrow extends Line {
36
+ get __tag() { return 'Arrow'; }
37
+ constructor(data) {
38
+ super(data);
39
+ this.__.__useArrow = true;
40
+ }
41
+ };
42
+ __decorate([
43
+ dataProcessor(ArrowData)
44
+ ], Arrow.prototype, "__", void 0);
45
+ __decorate([
46
+ strokeType('angle')
47
+ ], Arrow.prototype, "endArrow", void 0);
48
+ Arrow = __decorate([
49
+ registerUI()
50
+ ], Arrow);
51
+
52
+ const { M: M$1, L: L$1, C: C$1, Q: Q$1, O: O$1 } = PathCommandMap;
53
+ const { rotate: rotate$1, copyFrom: copyFrom$1, scale } = PointHelper;
54
+ const point = {};
55
+ const PathMatrixHelper = {
56
+ layout(data, x, y, scaleX, scaleY, rotation, origin) {
57
+ let command, i = 0, j, len = data.length;
58
+ while (i < len) {
59
+ command = data[i];
60
+ switch (command) {
61
+ case M$1:
62
+ case L$1:
63
+ setPoint$1(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
64
+ i += 3;
65
+ break;
66
+ case C$1:
67
+ for (j = 1; j < 6; j += 2)
68
+ setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
69
+ i += 7;
70
+ break;
71
+ case Q$1:
72
+ for (j = 1; j < 4; j += 2)
73
+ setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
74
+ i += 5;
75
+ break;
76
+ case O$1:
77
+ data[i + 1] += x;
78
+ data[i + 2] += y;
79
+ if (scaleX)
80
+ data[i + 3] *= scaleX;
81
+ if (rotation) {
82
+ data[i + 4] += rotation;
83
+ data[i + 5] += rotation;
84
+ }
85
+ i += 7;
86
+ break;
87
+ }
88
+ }
89
+ },
90
+ rotate(data, rotation, center) {
91
+ PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
92
+ }
93
+ };
94
+ function setPoint$1(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
95
+ copyFrom$1(point, data[startIndex], data[startIndex + 1]);
96
+ if (rotation)
97
+ rotate$1(point, rotation, origin);
98
+ if (scaleX)
99
+ scale(point, scaleX, scaleY);
100
+ data[startIndex] = x + point.x;
101
+ data[startIndex + 1] = y + point.y;
102
+ }
103
+
104
+ const { layout, rotate } = PathMatrixHelper;
105
+ const { getAngle } = PointHelper;
106
+ const half = { x: -0.5 };
107
+ const angle = { connect: half, offset: { x: -0.71, bevelJoin: 0.36, roundJoin: 0.22 }, path: [1, -3, -3, 2, 0, 0, 2, -3, 3] };
108
+ const angleSide = { connect: half, offset: { x: -1.207, bevelJoin: 0.854, roundJoin: 0.707 }, path: [1, -3, -3, 2, 0, 0, 2, -1, 0] };
109
+ const triangleLinePath = [1, -3, 0, 2, -3, -2, 2, 0, 0, 2, -3, 2, 2, -3, 0];
110
+ const triangle = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1] };
111
+ const arrowLinePath = [1, -3, 0, 2, -3.5, -1.8, 2, 0, 0, 2, -3.5, 1.8, 2, -3, 0];
112
+ const arrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95] };
113
+ const triangleFlip = { offset: half, path: [...triangle.path], };
114
+ rotate(triangleFlip.path, 180, { x: -1.5, y: 0 });
115
+ const circleLine = { connect: { x: -1.3 }, path: [1, 1.8, -0.1, 2, 1.8, 0, 26, 0, 0, 1.8, 0, 359, 0], };
116
+ const circle = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0] };
117
+ const squareLine = { 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] };
118
+ const square = { path: [...squareLine.path, 2, -1.4, -0.49, 2, 1, -0.49, 1, -1.4, 0.49, 2, 1, 0.49] };
119
+ const diamondLine = DataHelper.clone(squareLine);
120
+ const diamond = DataHelper.clone(square);
121
+ rotate(diamondLine.path, 45);
122
+ rotate(diamond.path, 45);
123
+ const mark = { offset: half, path: [1, 0, -2, 2, 0, 2] };
124
+ const arrows = {
125
+ angle,
126
+ 'angle-side': angleSide,
127
+ arrow,
128
+ triangle,
129
+ 'triangle-flip': triangleFlip,
130
+ circle,
131
+ 'circle-line': circleLine,
132
+ square,
133
+ 'square-line': squareLine,
134
+ diamond,
135
+ 'diamond-line': diamondLine,
136
+ mark,
137
+ };
138
+ function getArrowPath(ui, arrow, from, to, scale, connectOffset) {
139
+ const { strokeCap, strokeJoin } = ui.__;
140
+ const { offset, connect, path } = (typeof arrow === 'object' ? arrow : arrows[arrow]);
141
+ let connectX = connect ? connect.x : 0;
142
+ let offsetX = offset ? offset.x : 0;
143
+ const data = [...path];
144
+ if (strokeCap !== 'none')
145
+ connectX -= 0.5;
146
+ if (offset) {
147
+ if (strokeJoin === 'round' && offset.roundJoin)
148
+ offsetX += offset.roundJoin;
149
+ else if (strokeJoin === 'bevel' && offset.bevelJoin)
150
+ offsetX += offset.bevelJoin;
151
+ }
152
+ if (offsetX)
153
+ layout(data, offsetX, 0);
154
+ layout(data, to.x, to.y, scale, scale, getAngle(from, to));
155
+ connectOffset.x = (connectX + offsetX) * scale;
156
+ return data;
157
+ }
158
+
159
+ const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
160
+ const { copy, copyFrom, getDistancePoint, } = PointHelper;
161
+ const connectPoint = {};
162
+ const first = {}, second = {};
163
+ const last = {}, now = {};
164
+ const PathArrowModule = {
165
+ list: arrows,
166
+ addArrows(ui, changeRenderPath) {
167
+ const { startArrow, endArrow, strokeWidth, __pathForRender: data } = ui.__;
168
+ let command, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== 'none';
169
+ while (i < len) {
170
+ command = data[i];
171
+ switch (command) {
172
+ case M:
173
+ case L:
174
+ if (count < 2 || i + 3 === len) {
175
+ copyFrom(now, data[i + 1], data[i + 2]);
176
+ if (!count && useStartArrow)
177
+ copy(first, now);
178
+ }
179
+ i += 3;
180
+ break;
181
+ case C:
182
+ if (count === 1 || i + 7 === len)
183
+ copyPoints(data, last, now, i + 3);
184
+ i += 7;
185
+ break;
186
+ case Q:
187
+ if (count === 1 || i + 5 === len)
188
+ copyPoints(data, last, now, i + 1);
189
+ i += 5;
190
+ break;
191
+ case Z:
192
+ return;
193
+ case N:
194
+ i += 5;
195
+ break;
196
+ case D:
197
+ i += 9;
198
+ break;
199
+ case X:
200
+ i += 6;
201
+ break;
202
+ case G:
203
+ i += 9;
204
+ break;
205
+ case F:
206
+ i += 5;
207
+ break;
208
+ case O:
209
+ i += 7;
210
+ break;
211
+ case P:
212
+ i += 4;
213
+ break;
214
+ case U:
215
+ if (count === 1 || i + 6 === len)
216
+ copyPoints(data, last, now, i + 1);
217
+ i += 6;
218
+ break;
219
+ }
220
+ count++;
221
+ if (count === 1 && command !== M)
222
+ return;
223
+ if (count === 2 && useStartArrow)
224
+ copy(second, command === L ? now : last);
225
+ if (i === len) {
226
+ const p = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
227
+ if (useStartArrow) {
228
+ p.push(...getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint));
229
+ if (connectPoint.x) {
230
+ getDistancePoint(first, second, -connectPoint.x, true);
231
+ p[1] = second.x;
232
+ p[2] = second.y;
233
+ }
234
+ }
235
+ if (endArrow && endArrow !== 'none') {
236
+ p.push(...getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint));
237
+ if (connectPoint.x) {
238
+ getDistancePoint(now, last, -connectPoint.x, true);
239
+ let index;
240
+ switch (command) {
241
+ case L:
242
+ index = i - 3 + 1;
243
+ break;
244
+ case C:
245
+ index = i - 7 + 5;
246
+ break;
247
+ case Q:
248
+ index = i - 5 + 3;
249
+ break;
250
+ case U:
251
+ index = i - 6 + 3;
252
+ break;
253
+ }
254
+ if (index)
255
+ setPoint(p, last, index);
256
+ }
257
+ }
258
+ }
259
+ else {
260
+ copy(last, now);
261
+ }
262
+ }
263
+ }
264
+ };
265
+ function copyPoints(data, from, to, startIndex) {
266
+ copyFrom(from, data[startIndex], data[startIndex + 1]);
267
+ copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
268
+ }
269
+ function setPoint(data, point, startIndex) {
270
+ data[startIndex] = point.x;
271
+ data[startIndex + 1] = point.y;
272
+ }
273
+
274
+ Object.assign(PathArrow, PathArrowModule);
275
+
276
+ export { Arrow, PathArrowModule, PathMatrixHelper };
@@ -0,0 +1 @@
1
+ import{LineData as e,dataProcessor as t,strokeType as o,registerUI as n,Line as r,PathCommandMap as a,PointHelper as c,DataHelper as s,PathArrow as i}from"@leafer-ui/draw";function l(e,t,o,n){var r,a=arguments.length,c=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,o,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(c=(a<3?r(c):a>3?r(t,o,c):r(t,o))||c);return a>3&&c&&Object.defineProperty(t,o,c),c}"function"==typeof SuppressedError&&SuppressedError;let p=class extends r{get __tag(){return"Arrow"}constructor(e){super(e),this.__.__useArrow=!0}};l([t(class extends e{})],p.prototype,"__",void 0),l([o("angle")],p.prototype,"endArrow",void 0),p=l([n()],p);const{M:f,L:u,C:h,Q:d,O:b}=a,{rotate:x,copyFrom:k,scale:y}=c,_={},g={layout(e,t,o,n,r,a,c){let s,i,l=0,p=e.length;for(;l<p;)switch(s=e[l],s){case f:case u:J(e,l+1,t,o,n,r,a,c),l+=3;break;case h:for(i=1;i<6;i+=2)J(e,l+i,t,o,n,r,a,c);l+=7;break;case d:for(i=1;i<4;i+=2)J(e,l+i,t,o,n,r,a,c);l+=5;break;case b:e[l+1]+=t,e[l+2]+=o,n&&(e[l+3]*=n),a&&(e[l+4]+=a,e[l+5]+=a),l+=7}},rotate(e,t,o){g.layout(e,0,0,1,1,t,o)}};function J(e,t,o,n,r,a,c,s){k(_,e[t],e[t+1]),c&&x(_,c,s),r&&y(_,r,a),e[t]=o+_.x,e[t+1]=n+_.y}const{layout:w,rotate:v}=g,{getAngle:m}=c,A={x:-.5},O={connect:A,offset:{x:-.71,bevelJoin:.36,roundJoin:.22},path:[1,-3,-3,2,0,0,2,-3,3]},j={connect:A,offset:{x:-1.207,bevelJoin:.854,roundJoin:.707},path:[1,-3,-3,2,0,0,2,-1,0]},F={connect:A,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]},R={connect:A,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]},P={offset:A,path:[...F.path]};v(P.path,180,{x:-1.5,y:0});const C={connect:{x:-1.3},path:[1,1.8,-.1,2,1.8,0,26,0,0,1.8,0,359,0]},D={connect:{x:.5},path:[...C.path,1,0,0,26,0,0,1,0,360,0]},q={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]},E={path:[...q.path,2,-1.4,-.49,2,1,-.49,1,-1.4,.49,2,1,.49]},L=s.clone(q),M=s.clone(E);v(L.path,45),v(M.path,45);const Q={angle:O,"angle-side":j,arrow:R,triangle:F,"triangle-flip":P,circle:D,"circle-line":C,square:E,"square-line":q,diamond:M,"diamond-line":L,mark:{offset:A,path:[1,0,-2,2,0,2]}};function S(e,t,o,n,r,a){const{strokeCap:c,strokeJoin:s}=e.__,{offset:i,connect:l,path:p}="object"==typeof t?t:Q[t];let f=l?l.x:0,u=i?i.x:0;const h=[...p];return"none"!==c&&(f-=.5),i&&("round"===s&&i.roundJoin?u+=i.roundJoin:"bevel"===s&&i.bevelJoin&&(u+=i.bevelJoin)),u&&w(h,u,0),w(h,n.x,n.y,r,r,m(o,n)),a.x=(f+u)*r,h}const{M:G,L:N,C:U,Q:W,Z:X,N:Z,D:z,X:B,G:H,F:I,O:K,P:T,U:V}=a,{copy:Y,copyFrom:$,getDistancePoint:ee}=c,te={},oe={},ne={},re={},ae={},ce={list:Q,addArrows(e,t){const{startArrow:o,endArrow:n,strokeWidth:r,__pathForRender:a}=e.__;let c,s=0,i=a.length,l=0,p=o&&"none"!==o;for(;s<i;){switch(c=a[s],c){case G:case N:(l<2||s+3===i)&&($(ae,a[s+1],a[s+2]),!l&&p&&Y(oe,ae)),s+=3;break;case U:1!==l&&s+7!==i||se(a,re,ae,s+3),s+=7;break;case W:1!==l&&s+5!==i||se(a,re,ae,s+1),s+=5;break;case X:return;case Z:s+=5;break;case z:s+=9;break;case B:s+=6;break;case H:s+=9;break;case I:s+=5;break;case K:s+=7;break;case T:s+=4;break;case V:1!==l&&s+6!==i||se(a,re,ae,s+1),s+=6}if(l++,1===l&&c!==G)return;if(2===l&&p&&Y(ne,c===N?ae:re),s===i){const i=e.__.__pathForRender=t?[...a]:a;if(p&&(i.push(...S(e,o,ne,oe,r,te)),te.x&&(ee(oe,ne,-te.x,!0),i[1]=ne.x,i[2]=ne.y)),n&&"none"!==n&&(i.push(...S(e,n,re,ae,r,te)),te.x)){let e;switch(ee(ae,re,-te.x,!0),c){case N:e=s-3+1;break;case U:e=s-7+5;break;case W:e=s-5+3;break;case V:e=s-6+3}e&&ie(i,re,e)}}else Y(re,ae)}}};function se(e,t,o,n){$(t,e[n],e[n+1]),$(o,e[n+2],e[n+3])}function ie(e,t,o){e[o]=t.x,e[o+1]=t.y}Object.assign(i,ce);export{p as Arrow,ce as PathArrowModule,g as PathMatrixHelper};
package/dist/arrow.js ADDED
@@ -0,0 +1,283 @@
1
+ this.LeaferIN = this.LeaferIN || {};
2
+ this.LeaferIN.arrow = (function (exports, draw) {
3
+ 'use strict';
4
+
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol */
20
+
21
+
22
+ function __decorate(decorators, target, key, desc) {
23
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
+ 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;
26
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
27
+ }
28
+
29
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
+ var e = new Error(message);
31
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
+ };
33
+
34
+ class ArrowData extends draw.LineData {
35
+ }
36
+
37
+ exports.Arrow = class Arrow extends draw.Line {
38
+ get __tag() { return 'Arrow'; }
39
+ constructor(data) {
40
+ super(data);
41
+ this.__.__useArrow = true;
42
+ }
43
+ };
44
+ __decorate([
45
+ draw.dataProcessor(ArrowData)
46
+ ], exports.Arrow.prototype, "__", void 0);
47
+ __decorate([
48
+ draw.strokeType('angle')
49
+ ], exports.Arrow.prototype, "endArrow", void 0);
50
+ exports.Arrow = __decorate([
51
+ draw.registerUI()
52
+ ], exports.Arrow);
53
+
54
+ const { M: M$1, L: L$1, C: C$1, Q: Q$1, O: O$1 } = draw.PathCommandMap;
55
+ const { rotate: rotate$1, copyFrom: copyFrom$1, scale } = draw.PointHelper;
56
+ const point = {};
57
+ const PathMatrixHelper = {
58
+ layout(data, x, y, scaleX, scaleY, rotation, origin) {
59
+ let command, i = 0, j, len = data.length;
60
+ while (i < len) {
61
+ command = data[i];
62
+ switch (command) {
63
+ case M$1:
64
+ case L$1:
65
+ setPoint$1(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
66
+ i += 3;
67
+ break;
68
+ case C$1:
69
+ for (j = 1; j < 6; j += 2)
70
+ setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
71
+ i += 7;
72
+ break;
73
+ case Q$1:
74
+ for (j = 1; j < 4; j += 2)
75
+ setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
76
+ i += 5;
77
+ break;
78
+ case O$1:
79
+ data[i + 1] += x;
80
+ data[i + 2] += y;
81
+ if (scaleX)
82
+ data[i + 3] *= scaleX;
83
+ if (rotation) {
84
+ data[i + 4] += rotation;
85
+ data[i + 5] += rotation;
86
+ }
87
+ i += 7;
88
+ break;
89
+ }
90
+ }
91
+ },
92
+ rotate(data, rotation, center) {
93
+ PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
94
+ }
95
+ };
96
+ function setPoint$1(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
97
+ copyFrom$1(point, data[startIndex], data[startIndex + 1]);
98
+ if (rotation)
99
+ rotate$1(point, rotation, origin);
100
+ if (scaleX)
101
+ scale(point, scaleX, scaleY);
102
+ data[startIndex] = x + point.x;
103
+ data[startIndex + 1] = y + point.y;
104
+ }
105
+
106
+ const { layout, rotate } = PathMatrixHelper;
107
+ const { getAngle } = draw.PointHelper;
108
+ const half = { x: -0.5 };
109
+ const angle = { connect: half, offset: { x: -0.71, bevelJoin: 0.36, roundJoin: 0.22 }, path: [1, -3, -3, 2, 0, 0, 2, -3, 3] };
110
+ const angleSide = { connect: half, offset: { x: -1.207, bevelJoin: 0.854, roundJoin: 0.707 }, path: [1, -3, -3, 2, 0, 0, 2, -1, 0] };
111
+ const triangleLinePath = [1, -3, 0, 2, -3, -2, 2, 0, 0, 2, -3, 2, 2, -3, 0];
112
+ const triangle = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1] };
113
+ const arrowLinePath = [1, -3, 0, 2, -3.5, -1.8, 2, 0, 0, 2, -3.5, 1.8, 2, -3, 0];
114
+ const arrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95] };
115
+ const triangleFlip = { offset: half, path: [...triangle.path], };
116
+ rotate(triangleFlip.path, 180, { x: -1.5, y: 0 });
117
+ const circleLine = { connect: { x: -1.3 }, path: [1, 1.8, -0.1, 2, 1.8, 0, 26, 0, 0, 1.8, 0, 359, 0], };
118
+ const circle = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0] };
119
+ const squareLine = { 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] };
120
+ const square = { path: [...squareLine.path, 2, -1.4, -0.49, 2, 1, -0.49, 1, -1.4, 0.49, 2, 1, 0.49] };
121
+ const diamondLine = draw.DataHelper.clone(squareLine);
122
+ const diamond = draw.DataHelper.clone(square);
123
+ rotate(diamondLine.path, 45);
124
+ rotate(diamond.path, 45);
125
+ const mark = { offset: half, path: [1, 0, -2, 2, 0, 2] };
126
+ const arrows = {
127
+ angle,
128
+ 'angle-side': angleSide,
129
+ arrow,
130
+ triangle,
131
+ 'triangle-flip': triangleFlip,
132
+ circle,
133
+ 'circle-line': circleLine,
134
+ square,
135
+ 'square-line': squareLine,
136
+ diamond,
137
+ 'diamond-line': diamondLine,
138
+ mark,
139
+ };
140
+ function getArrowPath(ui, arrow, from, to, scale, connectOffset) {
141
+ const { strokeCap, strokeJoin } = ui.__;
142
+ const { offset, connect, path } = (typeof arrow === 'object' ? arrow : arrows[arrow]);
143
+ let connectX = connect ? connect.x : 0;
144
+ let offsetX = offset ? offset.x : 0;
145
+ const data = [...path];
146
+ if (strokeCap !== 'none')
147
+ connectX -= 0.5;
148
+ if (offset) {
149
+ if (strokeJoin === 'round' && offset.roundJoin)
150
+ offsetX += offset.roundJoin;
151
+ else if (strokeJoin === 'bevel' && offset.bevelJoin)
152
+ offsetX += offset.bevelJoin;
153
+ }
154
+ if (offsetX)
155
+ layout(data, offsetX, 0);
156
+ layout(data, to.x, to.y, scale, scale, getAngle(from, to));
157
+ connectOffset.x = (connectX + offsetX) * scale;
158
+ return data;
159
+ }
160
+
161
+ const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = draw.PathCommandMap;
162
+ const { copy, copyFrom, getDistancePoint, } = draw.PointHelper;
163
+ const connectPoint = {};
164
+ const first = {}, second = {};
165
+ const last = {}, now = {};
166
+ const PathArrowModule = {
167
+ list: arrows,
168
+ addArrows(ui, changeRenderPath) {
169
+ const { startArrow, endArrow, strokeWidth, __pathForRender: data } = ui.__;
170
+ let command, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== 'none';
171
+ while (i < len) {
172
+ command = data[i];
173
+ switch (command) {
174
+ case M:
175
+ case L:
176
+ if (count < 2 || i + 3 === len) {
177
+ copyFrom(now, data[i + 1], data[i + 2]);
178
+ if (!count && useStartArrow)
179
+ copy(first, now);
180
+ }
181
+ i += 3;
182
+ break;
183
+ case C:
184
+ if (count === 1 || i + 7 === len)
185
+ copyPoints(data, last, now, i + 3);
186
+ i += 7;
187
+ break;
188
+ case Q:
189
+ if (count === 1 || i + 5 === len)
190
+ copyPoints(data, last, now, i + 1);
191
+ i += 5;
192
+ break;
193
+ case Z:
194
+ return;
195
+ case N:
196
+ i += 5;
197
+ break;
198
+ case D:
199
+ i += 9;
200
+ break;
201
+ case X:
202
+ i += 6;
203
+ break;
204
+ case G:
205
+ i += 9;
206
+ break;
207
+ case F:
208
+ i += 5;
209
+ break;
210
+ case O:
211
+ i += 7;
212
+ break;
213
+ case P:
214
+ i += 4;
215
+ break;
216
+ case U:
217
+ if (count === 1 || i + 6 === len)
218
+ copyPoints(data, last, now, i + 1);
219
+ i += 6;
220
+ break;
221
+ }
222
+ count++;
223
+ if (count === 1 && command !== M)
224
+ return;
225
+ if (count === 2 && useStartArrow)
226
+ copy(second, command === L ? now : last);
227
+ if (i === len) {
228
+ const p = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
229
+ if (useStartArrow) {
230
+ p.push(...getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint));
231
+ if (connectPoint.x) {
232
+ getDistancePoint(first, second, -connectPoint.x, true);
233
+ p[1] = second.x;
234
+ p[2] = second.y;
235
+ }
236
+ }
237
+ if (endArrow && endArrow !== 'none') {
238
+ p.push(...getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint));
239
+ if (connectPoint.x) {
240
+ getDistancePoint(now, last, -connectPoint.x, true);
241
+ let index;
242
+ switch (command) {
243
+ case L:
244
+ index = i - 3 + 1;
245
+ break;
246
+ case C:
247
+ index = i - 7 + 5;
248
+ break;
249
+ case Q:
250
+ index = i - 5 + 3;
251
+ break;
252
+ case U:
253
+ index = i - 6 + 3;
254
+ break;
255
+ }
256
+ if (index)
257
+ setPoint(p, last, index);
258
+ }
259
+ }
260
+ }
261
+ else {
262
+ copy(last, now);
263
+ }
264
+ }
265
+ }
266
+ };
267
+ function copyPoints(data, from, to, startIndex) {
268
+ copyFrom(from, data[startIndex], data[startIndex + 1]);
269
+ copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
270
+ }
271
+ function setPoint(data, point, startIndex) {
272
+ data[startIndex] = point.x;
273
+ data[startIndex + 1] = point.y;
274
+ }
275
+
276
+ Object.assign(draw.PathArrow, PathArrowModule);
277
+
278
+ exports.PathArrowModule = PathArrowModule;
279
+ exports.PathMatrixHelper = PathMatrixHelper;
280
+
281
+ return exports;
282
+
283
+ })({}, LeaferUI);
@@ -0,0 +1 @@
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.arrow=function(e,t){"use strict";function r(e,t,r,o){var a,n=arguments.length,c=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,r,o);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(c=(n<3?a(c):n>3?a(t,r,c):a(t,r))||c);return n>3&&c&&Object.defineProperty(t,r,c),c}"function"==typeof SuppressedError&&SuppressedError;class o extends t.LineData{}e.Arrow=class extends t.Line{get __tag(){return"Arrow"}constructor(e){super(e),this.__.__useArrow=!0}},r([t.dataProcessor(o)],e.Arrow.prototype,"__",void 0),r([t.strokeType("angle")],e.Arrow.prototype,"endArrow",void 0),e.Arrow=r([t.registerUI()],e.Arrow);const{M:a,L:n,C:c,Q:s,O:i}=t.PathCommandMap,{rotate:p,copyFrom:l,scale:f}=t.PointHelper,h={},u={layout(e,t,r,o,p,l,f){let h,u,b=0,x=e.length;for(;b<x;)switch(h=e[b],h){case a:case n:d(e,b+1,t,r,o,p,l,f),b+=3;break;case c:for(u=1;u<6;u+=2)d(e,b+u,t,r,o,p,l,f);b+=7;break;case s:for(u=1;u<4;u+=2)d(e,b+u,t,r,o,p,l,f);b+=5;break;case i:e[b+1]+=t,e[b+2]+=r,o&&(e[b+3]*=o),l&&(e[b+4]+=l,e[b+5]+=l),b+=7}},rotate(e,t,r){u.layout(e,0,0,1,1,t,r)}};function d(e,t,r,o,a,n,c,s){l(h,e[t],e[t+1]),c&&p(h,c,s),a&&f(h,a,n),e[t]=r+h.x,e[t+1]=o+h.y}const{layout:b,rotate:x}=u,{getAngle:k}=t.PointHelper,y={x:-.5},w={connect:y,offset:{x:-.71,bevelJoin:.36,roundJoin:.22},path:[1,-3,-3,2,0,0,2,-3,3]},_={connect:y,offset:{x:-1.207,bevelJoin:.854,roundJoin:.707},path:[1,-3,-3,2,0,0,2,-1,0]},g={connect:y,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]},A={connect:y,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]},J={offset:y,path:[...g.path]};x(J.path,180,{x:-1.5,y:0});const P={connect:{x:-1.3},path:[1,1.8,-.1,2,1.8,0,26,0,0,1.8,0,359,0]},v={connect:{x:.5},path:[...P.path,1,0,0,26,0,0,1,0,360,0]},m={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]},L={path:[...m.path,2,-1.4,-.49,2,1,-.49,1,-1.4,.49,2,1,.49]},D=t.DataHelper.clone(m),H=t.DataHelper.clone(L);x(D.path,45),x(H.path,45);const M={angle:w,"angle-side":_,arrow:A,triangle:g,"triangle-flip":J,circle:v,"circle-line":P,square:L,"square-line":m,diamond:H,"diamond-line":D,mark:{offset:y,path:[1,0,-2,2,0,2]}};function O(e,t,r,o,a,n){const{strokeCap:c,strokeJoin:s}=e.__,{offset:i,connect:p,path:l}="object"==typeof t?t:M[t];let f=p?p.x:0,h=i?i.x:0;const u=[...l];return"none"!==c&&(f-=.5),i&&("round"===s&&i.roundJoin?h+=i.roundJoin:"bevel"===s&&i.bevelJoin&&(h+=i.bevelJoin)),h&&b(u,h,0),b(u,o.x,o.y,a,a,k(r,o)),n.x=(f+h)*a,u}const{M:j,L:C,C:F,Q:I,Z:R,N:N,D:U,X:q,G:E,F:Q,O:S,P:G,U:T}=t.PathCommandMap,{copy:W,copyFrom:X,getDistancePoint:Z}=t.PointHelper,z={},B={},K={},V={},Y={},$={list:M,addArrows(e,t){const{startArrow:r,endArrow:o,strokeWidth:a,__pathForRender:n}=e.__;let c,s=0,i=n.length,p=0,l=r&&"none"!==r;for(;s<i;){switch(c=n[s],c){case j:case C:(p<2||s+3===i)&&(X(Y,n[s+1],n[s+2]),!p&&l&&W(B,Y)),s+=3;break;case F:1!==p&&s+7!==i||ee(n,V,Y,s+3),s+=7;break;case I:1!==p&&s+5!==i||ee(n,V,Y,s+1),s+=5;break;case R:return;case N:s+=5;break;case U:s+=9;break;case q:s+=6;break;case E:s+=9;break;case Q:s+=5;break;case S:s+=7;break;case G:s+=4;break;case T:1!==p&&s+6!==i||ee(n,V,Y,s+1),s+=6}if(p++,1===p&&c!==j)return;if(2===p&&l&&W(K,c===C?Y:V),s===i){const i=e.__.__pathForRender=t?[...n]:n;if(l&&(i.push(...O(e,r,K,B,a,z)),z.x&&(Z(B,K,-z.x,!0),i[1]=K.x,i[2]=K.y)),o&&"none"!==o&&(i.push(...O(e,o,V,Y,a,z)),z.x)){let e;switch(Z(Y,V,-z.x,!0),c){case C:e=s-3+1;break;case F:e=s-7+5;break;case I:e=s-5+3;break;case T:e=s-6+3}e&&te(i,V,e)}}else W(V,Y)}}};function ee(e,t,r,o){X(t,e[o],e[o+1]),X(r,e[o+2],e[o+3])}function te(e,t,r){e[r]=t.x,e[r+1]=t.y}return Object.assign(t.PathArrow,$),e.PathArrowModule=$,e.PathMatrixHelper=u,e}({},LeaferUI);
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@leafer-in/arrow",
3
+ "version": "1.0.0-rc.16",
4
+ "description": "@leafer-in/arrow",
5
+ "author": "Chao (Leafer) Wan",
6
+ "license": "MIT",
7
+ "main": "dist/arrow.esm.js",
8
+ "unpkg": "dist/arrow.js",
9
+ "jsdelivr": "dist/arrow.js",
10
+ "types": "types/index.d.ts",
11
+ "files": [
12
+ "src",
13
+ "types",
14
+ "dist"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/leaferjs/in.git"
19
+ },
20
+ "homepage": "https://github.com/leaferjs/in/tree/main/packages/arrow",
21
+ "bugs": "https://github.com/leaferjs/in/issues",
22
+ "keywords": [
23
+ "leafer arrow",
24
+ "leafer-arrow",
25
+ "leafer-in",
26
+ "arrow",
27
+ "leafer-ui",
28
+ "leaferjs"
29
+ ],
30
+ "dependencies": {
31
+ "@leafer-ui/draw": "1.0.0-rc.16"
32
+ },
33
+ "devDependencies": {
34
+ "@leafer-ui/interface": "1.0.0-rc.16",
35
+ "@leafer-in/interface": "1.0.0-rc.16"
36
+ }
37
+ }
package/src/Arrow.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { IArrow, IArrowData, IArrowInputData, IArrowType } from '@leafer-ui/interface'
2
+ import { Line, registerUI, strokeType, dataProcessor } from '@leafer-ui/draw'
3
+
4
+ import { ArrowData } from './data/ArrowData'
5
+
6
+
7
+ @registerUI()
8
+ export class Arrow extends Line implements IArrow {
9
+
10
+ public get __tag() { return 'Arrow' }
11
+
12
+ @dataProcessor(ArrowData)
13
+ declare public __: IArrowData
14
+
15
+ @strokeType('angle')
16
+ declare public endArrow: IArrowType
17
+
18
+ constructor(data?: IArrowInputData) {
19
+ super(data)
20
+ this.__.__useArrow = true
21
+ }
22
+
23
+ }
@@ -0,0 +1,136 @@
1
+ import { IPathArrowModule, IUI, IPathCommandData, IPointData } from '@leafer-ui/interface'
2
+ import { PathCommandMap as Command, PointHelper } from '@leafer-ui/draw'
3
+
4
+ import { arrows, getArrowPath } from './data/arrows'
5
+
6
+
7
+ const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = Command
8
+ const { copy, copyFrom, getDistancePoint, } = PointHelper
9
+
10
+ const connectPoint = {} as IPointData
11
+ const first = {} as IPointData, second = {} as IPointData
12
+ const last = {} as IPointData, now = {} as IPointData
13
+
14
+ export const PathArrowModule: IPathArrowModule = {
15
+
16
+ list: arrows,
17
+
18
+ addArrows(ui: IUI, changeRenderPath?: boolean): void {
19
+ const { startArrow, endArrow, strokeWidth, __pathForRender: data } = ui.__
20
+
21
+ let command: number, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== 'none'
22
+
23
+ while (i < len) {
24
+
25
+ command = data[i]
26
+
27
+ switch (command) {
28
+ case M: // moveto(x, y)
29
+ case L: // lineto(x, y)
30
+ if (count < 2 || i + 3 === len) {
31
+ copyFrom(now, data[i + 1], data[i + 2])
32
+ if (!count && useStartArrow) copy(first, now)
33
+ }
34
+ i += 3
35
+ break
36
+ case C: // bezierCurveTo(x1, y1, x2, y2, x, y)
37
+ if (count === 1 || i + 7 === len) copyPoints(data, last, now, i + 3)
38
+ i += 7
39
+ break
40
+ case Q: // quadraticCurveTo(x1, y1, x, y)
41
+ if (count === 1 || i + 5 === len) copyPoints(data, last, now, i + 1)
42
+ i += 5
43
+ break
44
+ case Z: // closepath()
45
+ return // no arrow
46
+
47
+ // canvas command
48
+
49
+ case N: // rect(x, y, width, height)
50
+ i += 5
51
+ break
52
+ case D: // roundRect(x, y, width, height, radius1, radius2, radius3, radius4)
53
+ i += 9
54
+ break
55
+ case X: // simple roundRect(x, y, width, height, radius)
56
+ i += 6
57
+ break
58
+ case G: // ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
59
+ i += 9
60
+ break
61
+ case F: // simple ellipse(x, y, radiusX, radiusY)
62
+ i += 5
63
+ break
64
+ case O: // arc(x, y, radius, startAngle, endAngle, anticlockwise)
65
+ i += 7
66
+ break
67
+ case P: // simple arc(x, y, radius)
68
+ i += 4
69
+ break
70
+ case U: // arcTo(x1, y1, x2, y2, radius)
71
+ if (count === 1 || i + 6 === len) copyPoints(data, last, now, i + 1)
72
+ i += 6
73
+ break
74
+ }
75
+
76
+ count++
77
+
78
+ if (count === 1 && command !== M) return // no arrow
79
+ if (count === 2 && useStartArrow) copy(second, command === L ? now : last)
80
+
81
+ if (i === len) {
82
+ const p = ui.__.__pathForRender = changeRenderPath ? [...data] : data
83
+
84
+ if (useStartArrow) {
85
+ p.push(...getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint))
86
+
87
+ if (connectPoint.x) {
88
+ getDistancePoint(first, second, -connectPoint.x, true)
89
+ p[1] = second.x
90
+ p[2] = second.y
91
+ }
92
+ }
93
+
94
+ if (endArrow && endArrow !== 'none') {
95
+ p.push(...getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint))
96
+
97
+ if (connectPoint.x) {
98
+ getDistancePoint(now, last, -connectPoint.x, true)
99
+ let index: number
100
+ switch (command) {
101
+ case L: //lineto(x, y)
102
+ index = i - 3 + 1
103
+ break
104
+ case C: //bezierCurveTo(x1, y1, x2, y2, x, y)
105
+ index = i - 7 + 5
106
+ break
107
+ case Q: //quadraticCurveTo(x1, y1, x, y)
108
+ index = i - 5 + 3
109
+ break
110
+ case U: // arcTo(x1, y1, x2, y2, radius)
111
+ index = i - 6 + 3
112
+ break
113
+ }
114
+ if (index) setPoint(p, last, index)
115
+ }
116
+ }
117
+
118
+ } else {
119
+ copy(last, now)
120
+ }
121
+ }
122
+
123
+
124
+ }
125
+ }
126
+
127
+
128
+ function copyPoints(data: IPathCommandData, from: IPointData, to: IPointData, startIndex: number): void {
129
+ copyFrom(from, data[startIndex], data[startIndex + 1])
130
+ copyFrom(to, data[startIndex + 2], data[startIndex + 3])
131
+ }
132
+
133
+ function setPoint(data: IPathCommandData, point: IPointData, startIndex: number): void {
134
+ data[startIndex] = point.x
135
+ data[startIndex + 1] = point.y
136
+ }
@@ -0,0 +1,57 @@
1
+ import { IPathCommandData, IPointData } from '@leafer-ui/interface'
2
+ import { PathCommandMap as Command, PointHelper } from '@leafer-ui/draw'
3
+
4
+
5
+ const { M, L, C, Q, O } = Command
6
+ const { rotate, copyFrom, scale } = PointHelper
7
+ const point: IPointData = {} as IPointData
8
+
9
+ export const PathMatrixHelper = {
10
+
11
+ layout(data: IPathCommandData, x: number, y: number, scaleX?: number, scaleY?: number, rotation?: number, origin?: IPointData): void {
12
+ let command: number, i = 0, j: number, len = data.length
13
+
14
+ while (i < len) {
15
+ command = data[i]
16
+ switch (command) {
17
+ case M: // moveto(x, y)
18
+ case L: // lineto(x, y)
19
+ setPoint(data, i + 1, x, y, scaleX, scaleY, rotation, origin)
20
+ i += 3
21
+ break
22
+ case C: // bezierCurveTo(x1, y1, x2, y2, x, y)
23
+ for (j = 1; j < 6; j += 2) setPoint(data, i + j, x, y, scaleX, scaleY, rotation, origin)
24
+ i += 7
25
+ break
26
+ case Q: // quadraticCurveTo(x1, y1, x, y)
27
+ for (j = 1; j < 4; j += 2) setPoint(data, i + j, x, y, scaleX, scaleY, rotation, origin)
28
+ i += 5
29
+ break
30
+ case O: // arc(x, y, radius, startAngle, endAngle, anticlockwise)
31
+ data[i + 1] += x
32
+ data[i + 2] += y
33
+ if (scaleX) data[i + 3] *= scaleX
34
+ if (rotation) {
35
+ data[i + 4] += rotation
36
+ data[i + 5] += rotation
37
+ }
38
+ i += 7
39
+ break
40
+ }
41
+ }
42
+ },
43
+
44
+ rotate(data: IPathCommandData, rotation?: number, center?: IPointData): void {
45
+ PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center)
46
+ }
47
+
48
+ }
49
+
50
+
51
+ function setPoint(data: IPathCommandData, startIndex: number, x: number, y: number, scaleX?: number, scaleY?: number, rotation?: number, origin?: IPointData): void {
52
+ copyFrom(point, data[startIndex], data[startIndex + 1])
53
+ if (rotation) rotate(point, rotation, origin)
54
+ if (scaleX) scale(point, scaleX, scaleY)
55
+ data[startIndex] = x + point.x
56
+ data[startIndex + 1] = y + point.y
57
+ }
@@ -0,0 +1,7 @@
1
+ import { IArrowData } from "@leafer-ui/interface"
2
+ import { LineData } from '@leafer-ui/draw'
3
+
4
+
5
+ export class ArrowData extends LineData implements IArrowData {
6
+
7
+ }
@@ -0,0 +1,78 @@
1
+ import { IArrowType, IPathDataArrow, IPathDataArrowMap, IUI, IPathCommandData, IPointData } from '@leafer-ui/interface'
2
+ import { DataHelper, PointHelper } from '@leafer-ui/draw'
3
+
4
+ import { PathMatrixHelper } from '../PathMatrixHelper'
5
+
6
+
7
+ const { layout, rotate } = PathMatrixHelper
8
+ const { getAngle } = PointHelper
9
+ const half = { x: -0.5 }
10
+
11
+
12
+ const angle: IPathDataArrow = { connect: half, offset: { x: -0.71, bevelJoin: 0.36, roundJoin: 0.22 }, path: [1, -3, -3, 2, 0, 0, 2, -3, 3] } // moveTo(-3, -3).lineTo(0, 0).lineTo(-3, 3)
13
+ const angleSide: IPathDataArrow = { connect: half, offset: { x: -1.207, bevelJoin: 0.854, roundJoin: 0.707 }, path: [1, -3, -3, 2, 0, 0, 2, -1, 0] } // moveTo(-3, -3).lineTo(0, 0).lineTo(-1, 0)
14
+
15
+ const triangleLinePath = [1, -3, 0, 2, -3, -2, 2, 0, 0, 2, -3, 2, 2, -3, 0] // moveTo(-3, 0).lineTo(-3, -2).lineTo(0, 0).lineTo(-3, 2).lineTo(-3, 0)
16
+ const triangle: IPathDataArrow = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1] } // fill: moveTo(-2.05, 1.1).lineTo(-2.05, -1.1)
17
+
18
+ const arrowLinePath = [1, -3, 0, 2, -3.5, -1.8, 2, 0, 0, 2, -3.5, 1.8, 2, -3, 0] // moveTo(-3, 0).lineTo(-3.5, -1.8).lineTo(0, 0).lineTo(-3.5, 1.8).lineTo(-3, 0)
19
+ const arrow: IPathDataArrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95] } // fill: moveTo(-2.25, 0.95).lineTo(-2.25, -0.95)
20
+
21
+ const triangleFlip: IPathDataArrow = { offset: half, path: [...triangle.path], } // triangle rotate 180
22
+ rotate(triangleFlip.path, 180, { x: -1.5, y: 0 })
23
+
24
+ const circleLine: IPathDataArrow = { connect: { x: -1.3 }, path: [1, 1.8, -0.1, 2, 1.8, 0, 26, 0, 0, 1.8, 0, 359, 0], } //drawArc(0, 0, 2, 0, 360)
25
+ const circle: IPathDataArrow = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0] } // fill: moveTo(0,0).arc(0, 0, 1, 0, 360)
26
+
27
+ const squareLine: IPathDataArrow = { 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] } // moveTo(-1.4, 0).lineTo(-1.4, -1.4).lineTo(1.4, -1.4).lineTo(1.4, 1.4).lineTo(-1.4, 1.4).lineTo(-1.4, 0)
28
+ const square: IPathDataArrow = { path: [...squareLine.path, 2, -1.4, -0.49, 2, 1, -0.49, 1, -1.4, 0.49, 2, 1, 0.49] } // fill: moveTo(-1.4, -0.49).lineTo(1, -0.49).moveTo(-1.4, 0.49).lineTo(1, 0.49)
29
+
30
+ const diamondLine = DataHelper.clone(squareLine) as IPathDataArrow // square-line rotate 45
31
+ const diamond: IPathDataArrow = DataHelper.clone(square) as IPathDataArrow // square rotate 45
32
+ rotate(diamondLine.path, 45)
33
+ rotate(diamond.path, 45)
34
+
35
+ const mark: IPathDataArrow = { offset: half, path: [1, 0, -2, 2, 0, 2] } // moveTo(0, -2).lineTo(0, 2)
36
+
37
+ export const arrows: IPathDataArrowMap = {
38
+ angle,
39
+ 'angle-side': angleSide,
40
+
41
+ arrow,
42
+ triangle,
43
+ 'triangle-flip': triangleFlip,
44
+
45
+ circle,
46
+ 'circle-line': circleLine,
47
+
48
+ square,
49
+ 'square-line': squareLine,
50
+
51
+ diamond,
52
+ 'diamond-line': diamondLine,
53
+
54
+ mark,
55
+
56
+ }
57
+
58
+ export function getArrowPath(ui: IUI, arrow: IArrowType, from: IPointData, to: IPointData, scale: number, connectOffset: IPointData): IPathCommandData {
59
+ const { strokeCap, strokeJoin } = ui.__
60
+ const { offset, connect, path } = (typeof arrow === 'object' ? arrow : arrows[arrow])
61
+
62
+ let connectX = connect ? connect.x : 0
63
+ let offsetX = offset ? offset.x : 0
64
+
65
+ const data = [...path]
66
+
67
+ if (strokeCap !== 'none') connectX -= 0.5
68
+ if (offset) {
69
+ if (strokeJoin === 'round' && offset.roundJoin) offsetX += offset.roundJoin
70
+ else if (strokeJoin === 'bevel' && offset.bevelJoin) offsetX += offset.bevelJoin
71
+ }
72
+
73
+ if (offsetX) layout(data, offsetX, 0)
74
+ layout(data, to.x, to.y, scale, scale, getAngle(from, to))
75
+
76
+ connectOffset.x = (connectX + offsetX) * scale
77
+ return data
78
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export { Arrow } from './Arrow'
2
+ export { PathArrowModule } from './PathArrowModule'
3
+ export { PathMatrixHelper } from './PathMatrixHelper'
4
+
5
+ import { PathArrow } from '@leafer-ui/draw'
6
+ import { PathArrowModule } from './PathArrowModule'
7
+
8
+
9
+ Object.assign(PathArrow, PathArrowModule)
@@ -0,0 +1,18 @@
1
+ import { IArrow, IArrowData, IArrowType, IArrowInputData, IPathArrowModule, IPathCommandData, IPointData } from '@leafer-ui/interface';
2
+ import { Line } from '@leafer-ui/draw';
3
+
4
+ declare class Arrow extends Line implements IArrow {
5
+ get __tag(): string;
6
+ __: IArrowData;
7
+ endArrow: IArrowType;
8
+ constructor(data?: IArrowInputData);
9
+ }
10
+
11
+ declare const PathArrowModule: IPathArrowModule;
12
+
13
+ declare const PathMatrixHelper: {
14
+ layout(data: IPathCommandData, x: number, y: number, scaleX?: number, scaleY?: number, rotation?: number, origin?: IPointData): void;
15
+ rotate(data: IPathCommandData, rotation?: number, center?: IPointData): void;
16
+ };
17
+
18
+ export { Arrow, PathArrowModule, PathMatrixHelper };