@leafer-in/arrow 1.0.0-rc.22 → 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;
@@ -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/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@leafer-in/arrow",
3
- "version": "1.0.0-rc.22",
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.22",
32
- "@leafer-ui/interface": "1.0.0-rc.22",
33
- "@leafer-in/interface": "1.0.0-rc.22"
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
  }