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