UNPKG

@leafer-in/arrow

Version:
3 lines (2 loc) 5.96 kB
import{LineData as t,decorateLeafAttr as e,attr as r,doBoundsType as a,doStrokeType as o,dataProcessor as n,registerUI as s,Line as c,PathArrow as i,PathCommandMap as l,PointHelper as h,DataHelper as d,isObject as f,Plugin as p,UI as _,Paint as u}from"@leafer-ui/draw";function x(t,e,r,a){var o,n=arguments.length,s=n<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,a);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(s=(n<3?o(s):n>3?o(e,r,s):o(e,r))||s);return n>3&&s&&Object.defineProperty(e,r,s),s}"function"==typeof SuppressedError&&SuppressedError;class b extends t{}function y(t){return e(t,t=>r({set(e){if(this.__setAttr(t,e)){const t=this.__,e="none"!==t.startArrow||"none"!==t.endArrow;t.__useArrow!==e&&a(this),t.__useArrow=e,o(this)}}}))}let w=class extends c{get __tag(){return"Arrow"}constructor(t){super(t),this.__.__useArrow=!0}static registerArrow(t,e){i.register(t,e)}};x([n(b)],w.prototype,"__",void 0),x([y("angle")],w.prototype,"endArrow",void 0),w=x([s()],w);const{M:k,L:g,C:A,Q:P,O:J}=l,{rotate:v,copyFrom:m,scale:O}=h,R={},S={layout(t,e,r,a,o,n,s){let c,i,l=0,h=t.length;for(;l<h;)switch(c=t[l],c){case k:case g:F(t,l+1,e,r,a,o,n,s),l+=3;break;case A:for(i=1;i<6;i+=2)F(t,l+i,e,r,a,o,n,s);l+=7;break;case P:for(i=1;i<4;i+=2)F(t,l+i,e,r,a,o,n,s);l+=5;break;case J:t[l+1]+=e,t[l+2]+=r,a&&(t[l+3]*=a),n&&(t[l+4]+=n,t[l+5]+=n),l+=7}},rotate(t,e,r){S.layout(t,0,0,1,1,e,r)}};function F(t,e,r,a,o,n,s,c){m(R,t[e],t[e+1]),s&&v(R,s,c),o&&O(R,o,n),t[e]=r+R.x,t[e+1]=a+R.y}const{layout:j,rotate:C}=S,{getAngle:D}=h,L={x:0},W={x:-.5},q={connect:L,offset:{x:-.71,bevelJoin:.36,roundJoin:.22},path:[1,-3,-3,2,0,0,2,-3,3]},B={connect:W,offset:{x:-1.207,bevelJoin:.854,roundJoin:.707},path:[1,-3,-3,2,0,0,2,-1,0]},E=[1,-3,0,2,-3,-2,2,0,0,2,-3,2,2,-3,0],M={connect:L,offset:{x:-.9,bevelJoin:.624,roundJoin:.4},path:[...E]},Q=d.clone(M);Q.path=[...E,1,-2.05,1.1,2,-2.05,-1.1],Q.dashPath=[1,-2,0,2,-.5,0];const G={connect:L,offset:W,path:[...M.path]},N={connect:L,offset:W,path:[...Q.path],dashPath:[1,-2.5,0,2,-1,0]};C(G.path,180,{x:-1.5,y:0}),C(N.path,180,{x:-1.5,y:0});const U=[1,-3,0,2,-3.5,-1.8,2,0,0,2,-3.5,1.8,2,-3,0],X={connect:L,offset:{x:-1.1,bevelJoin:.872,roundJoin:.6},path:[...U]},Z=d.clone(X);Z.path=[...U,1,-2.25,.95,2,-2.25,-.95],Z.dashPath=[1,-3,0,2,-.5,0];const z={connect:{x:-1.8},path:[1,1.8,-.1,2,1.8,0,26,0,0,1.8,0,359,0]},H={connect:{x:.5},path:[...z.path]},I=d.clone(H);I.path=[...z.path,1,0,0,26,0,0,1,0,360,0],I.dashPath=[1,-.5,0,2,.5,0];const K={connect:{x:-1.4},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]},T={path:[...K.path]},V={path:[...K.path,2,-1.4,-.49,2,1,-.49,1,-1.4,.49,2,1,.49]},Y=d.clone(K);Y.connect.x=-1.9;const $=d.clone(T),tt=d.clone(V);C(Y.path,45),C($.path,45),C(tt.path,45);const et={angle:q,"angle-side":B,arrow:Z,triangle:Q,"triangle-flip":N,circle:I,"circle-line":z,square:V,"square-line":K,diamond:tt,"diamond-line":Y,mark:{offset:W,path:[1,0,-2,2,0,2]}},rt={triangle:M,"triangle-flip":G,arrow:X,circle:H,square:T,diamond:$};function at(t,e,r,a,o,n,s){let c,i,l=1,h=0;const{strokeCap:d,strokeJoin:p}=t.__;if(f(e))if(e.type){if(l=e.scale||1,h=e.rotation||0,c=et[e.type],l>1){const t=rt[e.type];t&&(c=t,i=!0)}}else c=e;else c=et[e];i||(i=c.fill);const{offset:_,connect:u,path:x,dashPath:b}=c;let y=u?u.x*l:0,w=_?_.x:0;const k=[...x];s&&b&&k.push(...b),"none"!==d&&(y-=.5),_&&("round"===p&&_.roundJoin?w+=_.roundJoin:"bevel"===p&&_.bevelJoin&&(w+=_.bevelJoin)),1!==l&&j(k,0,0,l,l),w&&j(k,w,0),j(k,a.x,a.y,o,o,D(r,a)+h),n.x=(y+w)*o;const g={data:k};return i&&(g.fill=i),g}const{M:ot,L:nt,C:st,Q:ct,Z:it,N:lt,D:ht,X:dt,G:ft,F:pt,O:_t,P:ut,U:xt}=l,{copy:bt,copyFrom:yt,getDistancePoint:wt,isSame:kt}=h,{stintSet:gt}=d,At={},Pt={},Jt={},vt={},mt={},Ot={},Rt={list:et,fillList:rt,addArrows(t,e){const r=t.__,{startArrow:a,endArrow:o,__strokeWidth:n,dashPattern:s,__pathForRender:c,cornerRadius:i}=r,l=!i;let h,d,f,p;e||(r.__strokeWidthCache=n);let _,u=0,x=c.length,b=0,y=a&&"none"!==a;for(;u<x;){switch(_=c[u],_){case ot:case nt:(b<2||u+6>=x)&&(bt(vt,Ot),yt(Ot,c[u+1],c[u+2]),!b&&y&&bt(Pt,Ot)),u+=3;break;case st:(1===b||u+7>=x-3)&&(St(c,mt,Ot,u+3),vt.x=c[u+1],vt.y=c[u+2]),u+=7;break;case ct:(1===b||u+5>=x-3)&&(St(c,mt,Ot,u+1),bt(vt,mt)),u+=5;break;case it:return;case lt:u+=5;break;case ht:u+=9;break;case dt:u+=6;break;case ft:u+=9;break;case pt:u+=5;break;case _t:u+=7;break;case ut:u+=4;break;case xt:(1===b||u+6>=x-3)&&(St(c,mt,Ot,u+1),bt(vt,mt),u+6!==x&&(Ot.x-=(Ot.x-mt.x)/10,Ot.y-=(Ot.y-mt.y)/10)),u+=6}if(b++,1===b&&_!==ot)return;if(2===b&&y&&bt(Jt,_===nt?Ot:kt(vt,Pt)?mt:vt),u===x){const e=r.__pathForRender=l?[...c]:c;if(y&&(h=at(t,a,Jt,Pt,n,At,!!s),d=h.fill||s,d||e.push(...h.data),At.x&&(wt(Pt,Jt,-At.x,!0),e[1]=Jt.x,e[2]=Jt.y)),o&&"none"!==o&&(kt(mt,Ot)&&bt(mt,vt),f=at(t,o,mt,Ot,n,At,!!s),p=f.fill||s,p||e.push(...f.data),At.x)){let t;switch(wt(Ot,mt,-At.x,!0),_){case nt:t=u-3+1;break;case st:t=u-7+5;break;case ct:t=u-5+3;break;case xt:t=u-6+3}t&&Ft(e,mt,t)}}else bt(mt,Ot);gt(r,"__startArrowPath",d&&h),gt(r,"__endArrowPath",p&&f)}},updateArrow(t){const e=t.__;e.strokeScaleFixed&&e.__strokeWidthCache!==e.__strokeWidth&&t.__updateRenderPath(!0)},register(t,e,r){this.list[t]=e,r&&(this.fillList[t]=e)},get(t){return this.list[t]}};function St(t,e,r,a){yt(e,t[a],t[a+1]),yt(r,t[a+2],t[a+3])}function Ft(t,e,r){t[r]=e.x,t[r+1]=e.y}p.add("arrow"),_.addAttr("startArrow","none",y),_.addAttr("endArrow","none",y),Object.assign(i,Rt),Object.assign(u,{strokeArrow(t,e,r,a){const{__startArrowPath:o,__endArrowPath:n,dashPattern:s}=e.__;s&&(r.dashPattern=null),o&&(r.beginPath(),e.__drawPathByData(r,o.data),r.stroke(),o.fill&&(r.fillStyle=t,r.fill())),n&&(r.beginPath(),e.__drawPathByData(r,n.data),r.stroke(),n.fill&&(r.fillStyle=t,r.fill()))}});export{w as Arrow,b as ArrowData,Rt as PathArrowModule,S as PathMatrixHelper,y as arrowType}; //# sourceMappingURL=arrow.esm.min.js.map