@leafer-in/arrow 1.0.0-rc.21 → 1.0.0-rc.23

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 ADDED
@@ -0,0 +1,279 @@
1
+ 'use strict';
2
+
3
+ var draw = require('@leafer-ui/draw');
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 + 6 >= 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;
package/dist/arrow.esm.js CHANGED
@@ -171,7 +171,7 @@ const PathArrowModule = {
171
171
  switch (command) {
172
172
  case M:
173
173
  case L:
174
- if (count < 2 || i + 3 === len) {
174
+ if (count < 2 || i + 6 >= len) {
175
175
  copyFrom(now, data[i + 1], data[i + 2]);
176
176
  if (!count && useStartArrow)
177
177
  copy(first, now);
@@ -1 +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};
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+6>=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 CHANGED
@@ -173,7 +173,7 @@ this.LeaferIN.arrow = (function (exports, draw) {
173
173
  switch (command) {
174
174
  case M:
175
175
  case L:
176
- if (count < 2 || i + 3 === len) {
176
+ if (count < 2 || i + 6 >= len) {
177
177
  copyFrom(now, data[i + 1], data[i + 2]);
178
178
  if (!count && useStartArrow)
179
179
  copy(first, now);
@@ -0,0 +1 @@
1
+ "use strict";var e=require("@leafer-ui/draw");function t(e,t,r,o){var a,n=arguments.length,s=n<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--)(a=e[c])&&(s=(n<3?a(s):n>3?a(t,r,s):a(t,r))||s);return n>3&&s&&Object.defineProperty(t,r,s),s}"function"==typeof SuppressedError&&SuppressedError;class r extends e.LineData{}exports.Arrow=class extends e.Line{get __tag(){return"Arrow"}constructor(e){super(e),this.__.__useArrow=!0}},t([e.dataProcessor(r)],exports.Arrow.prototype,"__",void 0),t([e.strokeType("angle")],exports.Arrow.prototype,"endArrow",void 0),exports.Arrow=t([e.registerUI()],exports.Arrow);const{M:o,L:a,C:n,Q:s,O:c}=e.PathCommandMap,{rotate:i,copyFrom:p,scale:l}=e.PointHelper,f={},u={layout(e,t,r,i,p,l,f){let u,d,x=0,b=e.length;for(;x<b;)switch(u=e[x],u){case o:case a:h(e,x+1,t,r,i,p,l,f),x+=3;break;case n:for(d=1;d<6;d+=2)h(e,x+d,t,r,i,p,l,f);x+=7;break;case s:for(d=1;d<4;d+=2)h(e,x+d,t,r,i,p,l,f);x+=5;break;case c:e[x+1]+=t,e[x+2]+=r,i&&(e[x+3]*=i),l&&(e[x+4]+=l,e[x+5]+=l),x+=7}},rotate(e,t,r){u.layout(e,0,0,1,1,t,r)}};function h(e,t,r,o,a,n,s,c){p(f,e[t],e[t+1]),s&&i(f,s,c),a&&l(f,a,n),e[t]=r+f.x,e[t+1]=o+f.y}const{layout:d,rotate:x}=u,{getAngle:b}=e.PointHelper,k={x:-.5},y={connect:k,offset:{x:-.71,bevelJoin:.36,roundJoin:.22},path:[1,-3,-3,2,0,0,2,-3,3]},w={connect:k,offset:{x:-1.207,bevelJoin:.854,roundJoin:.707},path:[1,-3,-3,2,0,0,2,-1,0]},_={connect:k,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]},g={connect:k,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]},A={offset:k,path:[..._.path]};x(A.path,180,{x:-1.5,y:0});const J={connect:{x:-1.3},path:[1,1.8,-.1,2,1.8,0,26,0,0,1.8,0,359,0]},P={connect:{x:.5},path:[...J.path,1,0,0,26,0,0,1,0,360,0]},v={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]},m={path:[...v.path,2,-1.4,-.49,2,1,-.49,1,-1.4,.49,2,1,.49]},D=e.DataHelper.clone(v),H=e.DataHelper.clone(m);x(D.path,45),x(H.path,45);const M={angle:y,"angle-side":w,arrow:g,triangle:_,"triangle-flip":A,circle:P,"circle-line":J,square:m,"square-line":v,diamond:H,"diamond-line":D,mark:{offset:k,path:[1,0,-2,2,0,2]}};function O(e,t,r,o,a,n){const{strokeCap:s,strokeJoin:c}=e.__,{offset:i,connect:p,path:l}="object"==typeof t?t:M[t];let f=p?p.x:0,u=i?i.x:0;const h=[...l];return"none"!==s&&(f-=.5),i&&("round"===c&&i.roundJoin?u+=i.roundJoin:"bevel"===c&&i.bevelJoin&&(u+=i.bevelJoin)),u&&d(h,u,0),d(h,o.x,o.y,a,a,b(r,o)),n.x=(f+u)*a,h}const{M:j,L:C,C:F,Q:R,Z:L,N:q,D:E,X:Q,G:S,F:U,O:G,P:I,U:N}=e.PathCommandMap,{copy:T,copyFrom:W,getDistancePoint:X}=e.PointHelper,Z={},z={},B={},K={},V={},Y={list:M,addArrows(e,t){const{startArrow:r,endArrow:o,strokeWidth:a,__pathForRender:n}=e.__;let s,c=0,i=n.length,p=0,l=r&&"none"!==r;for(;c<i;){switch(s=n[c],s){case j:case C:(p<2||c+6>=i)&&(W(V,n[c+1],n[c+2]),!p&&l&&T(z,V)),c+=3;break;case F:1!==p&&c+7!==i||$(n,K,V,c+3),c+=7;break;case R:1!==p&&c+5!==i||$(n,K,V,c+1),c+=5;break;case L:return;case q:c+=5;break;case E:c+=9;break;case Q:c+=6;break;case S:c+=9;break;case U:c+=5;break;case G:c+=7;break;case I:c+=4;break;case N:1!==p&&c+6!==i||$(n,K,V,c+1),c+=6}if(p++,1===p&&s!==j)return;if(2===p&&l&&T(B,s===C?V:K),c===i){const i=e.__.__pathForRender=t?[...n]:n;if(l&&(i.push(...O(e,r,B,z,a,Z)),Z.x&&(X(z,B,-Z.x,!0),i[1]=B.x,i[2]=B.y)),o&&"none"!==o&&(i.push(...O(e,o,K,V,a,Z)),Z.x)){let e;switch(X(V,K,-Z.x,!0),s){case C:e=c-3+1;break;case F:e=c-7+5;break;case R:e=c-5+3;break;case N:e=c-6+3}e&&ee(i,K,e)}}else T(K,V)}}};function $(e,t,r,o){W(t,e[o],e[o+1]),W(r,e[o+2],e[o+3])}function ee(e,t,r){e[r]=t.x,e[r+1]=t.y}Object.assign(e.PathArrow,Y),exports.PathArrowModule=Y,exports.PathMatrixHelper=u;
package/dist/arrow.min.js CHANGED
@@ -1 +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);
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+6>=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 CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@leafer-in/arrow",
3
- "version": "1.0.0-rc.21",
3
+ "version": "1.0.0-rc.23",
4
4
  "description": "@leafer-in/arrow",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
+ "type": "module",
7
8
  "main": "dist/arrow.esm.js",
9
+ "exports": {
10
+ "import": "./dist/arrow.esm.js",
11
+ "require": "./dist/arrow.cjs",
12
+ "types": "./types/index.d.ts"
13
+ },
14
+ "types": "types/index.d.ts",
8
15
  "unpkg": "dist/arrow.js",
9
16
  "jsdelivr": "dist/arrow.js",
10
- "types": "types/index.d.ts",
11
17
  "files": [
12
18
  "src",
13
19
  "types",
@@ -28,8 +34,8 @@
28
34
  "leaferjs"
29
35
  ],
30
36
  "dependencies": {
31
- "@leafer-ui/draw": "1.0.0-rc.21",
32
- "@leafer-ui/interface": "1.0.0-rc.21",
33
- "@leafer-in/interface": "1.0.0-rc.21"
37
+ "@leafer-ui/draw": "1.0.0-rc.23",
38
+ "@leafer-ui/interface": "1.0.0-rc.23",
39
+ "@leafer-in/interface": "1.0.0-rc.23"
34
40
  }
35
41
  }
@@ -27,7 +27,7 @@ export const PathArrowModule: IPathArrowModule = {
27
27
  switch (command) {
28
28
  case M: // moveto(x, y)
29
29
  case L: // lineto(x, y)
30
- if (count < 2 || i + 3 === len) {
30
+ if (count < 2 || i + 6 >= len) { // 3 + 3 可能是两个连续L命令结束
31
31
  copyFrom(now, data[i + 1], data[i + 2])
32
32
  if (!count && useStartArrow) copy(first, now)
33
33
  }