@leafer-in/arrow
Version:
3 lines (2 loc) • 4.63 kB
JavaScript
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.arrow=function(e,t){"use strict";function r(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 o extends t.LineData{}function a(e){return t.decorateLeafAttr(e,(e=>t.attr({set(r){if(this.__setAttr(e,r)){const e=this.__;e.__useArrow="none"!==e.startArrow||"none"!==e.endArrow,t.doStrokeType(this)}}})))}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([a("angle")],e.Arrow.prototype,"endArrow",void 0),e.Arrow=r([t.registerUI()],e.Arrow);const{M:n,L:s,C:c,Q:i,O:h}=t.PathCommandMap,{rotate:p,copyFrom:l,scale:d}=t.PointHelper,f={},u={layout(e,t,r,o,a,p,l){let d,f,u=0,w=e.length;for(;u<w;)switch(d=e[u],d){case n:case s:_(e,u+1,t,r,o,a,p,l),u+=3;break;case c:for(f=1;f<6;f+=2)_(e,u+f,t,r,o,a,p,l);u+=7;break;case i:for(f=1;f<4;f+=2)_(e,u+f,t,r,o,a,p,l);u+=5;break;case h:e[u+1]+=t,e[u+2]+=r,o&&(e[u+3]*=o),p&&(e[u+4]+=p,e[u+5]+=p),u+=7}},rotate(e,t,r){u.layout(e,0,0,1,1,t,r)}};function _(e,t,r,o,a,n,s,c){l(f,e[t],e[t+1]),s&&p(f,s,c),a&&d(f,a,n),e[t]=r+f.x,e[t+1]=o+f.y}const{layout:w,rotate:b}=u,{getAngle:A}=t.PointHelper,P={x:-.5},k={connect:P,offset:{x:-.71,bevelJoin:.36,roundJoin:.22},path:[1,-3,-3,2,0,0,2,-3,3]},x={connect:P,offset:{x:-1.207,bevelJoin:.854,roundJoin:.707},path:[1,-3,-3,2,0,0,2,-1,0]},y={connect:P,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]},g={connect:P,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]},J={offset:P,path:[...y.path],dashPath:[1,-2.5,0,2,-1,0]};b(J.path,180,{x:-1.5,y:0});const v={connect:{x:-1.3},path:[1,1.8,-.1,2,1.8,0,26,0,0,1.8,0,359,0]},m={connect:{x:.5},path:[...v.path,1,0,0,26,0,0,1,0,360,0],dashPath:[1,-.5,0,2,.5,0]},L={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]},D={path:[...L.path,2,-1.4,-.49,2,1,-.49,1,-1.4,.49,2,1,.49]},F=t.DataHelper.clone(L),I=t.DataHelper.clone(D);b(F.path,45),b(I.path,45);const O={angle:k,"angle-side":x,arrow:g,triangle:y,"triangle-flip":J,circle:m,"circle-line":v,square:D,"square-line":L,diamond:I,"diamond-line":F,mark:{offset:P,path:[1,0,-2,2,0,2]}};function j(e,t,r,o,a,n,s){const{strokeCap:c,strokeJoin:i}=e.__,{offset:h,connect:p,path:l,dashPath:d}="object"==typeof t?t:O[t];let f=p?p.x:0,u=h?h.x:0;const _=[...l];return s&&d&&_.push(...d),"none"!==c&&(f-=.5),h&&("round"===i&&h.roundJoin?u+=h.roundJoin:"bevel"===i&&h.bevelJoin&&(u+=h.bevelJoin)),u&&w(_,u,0),w(_,o.x,o.y,a,a,A(r,o)),n.x=(f+u)*a,_}const{M:H,L:M,C:C,Q:R,Z:U,N:N,D:S,X:q,G:E,F:Q,O:T,P:B,U:G}=t.PathCommandMap,{copy:W,copyFrom:X,getDistancePoint:Z}=t.PointHelper,z={},K={},V={},Y={},$={},ee={list:O,addArrows(e,t){const{startArrow:r,endArrow:o,strokeWidth:a,dashPattern:n,__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 M:(p<2||i+6>=h)&&(X($,s[i+1],s[i+2]),!p&&l&&W(K,$)),i+=3;break;case C:1!==p&&i+7!==h||te(s,Y,$,i+3),i+=7;break;case R:1!==p&&i+5!==h||te(s,Y,$,i+1),i+=5;break;case U:return;case N:i+=5;break;case S:i+=9;break;case q:i+=6;break;case E:i+=9;break;case Q:i+=5;break;case T:i+=7;break;case B:i+=4;break;case G:1!==p&&i+6!==h||te(s,Y,$,i+1),i+=6}if(p++,1===p&&c!==H)return;if(2===p&&l&&W(V,c===M?$:Y),i===h){const h=e.__.__pathForRender=t?[...s]:s,p=e.__.__pathForArrow=[];if(l){const t=j(e,r,V,K,a,z,!!n);n?p.push(...t):h.push(...t),z.x&&(Z(K,V,-z.x,!0),h[1]=V.x,h[2]=V.y)}if(o&&"none"!==o){const t=j(e,o,Y,$,a,z,!!n);if(n?p.push(...t):h.push(...t),z.x){let e;switch(Z($,Y,-z.x,!0),c){case M:e=i-3+1;break;case C:e=i-7+5;break;case R:e=i-5+3;break;case G:e=i-6+3}e&&re(h,Y,e)}}}else W(Y,$)}}};function te(e,t,r,o){X(t,e[o],e[o+1]),X(r,e[o+2],e[o+3])}function re(e,t,r){e[r]=t.x,e[r+1]=t.y}return t.Plugin.add("arrow"),t.UI.addAttr("startArrow","none",a),t.UI.addAttr("endArrow","none",a),Object.assign(t.PathArrow,ee),Object.assign(t.Paint,{strokeArrow(e,t,r){t.__.dashPattern&&(r.beginPath(),t.__drawPathByData(r,t.__.__pathForArrow),r.dashPattern=null,r.stroke())}}),e.ArrowData=o,e.PathArrowModule=ee,e.PathMatrixHelper=u,e.arrowType=a,e}({},LeaferUI);
//# sourceMappingURL=arrow.min.js.map