suyiScreen/public/htWeb/lib/plugin/ht-rulerframe.js

1 line
9.3 KiB
JavaScript

!function(P,r){"use strict";var T="position",Z="absolute",b="relative",o="px",t="left",a="right",n="top",c="bottom",B="display",R="none",Y="block",y=ht.Default,A=y.getInternal(),F=Math.floor,Q=Math.ceil,s=Math.PI,m=null,w=P.parseInt,U=function(m){return m.getContext("2d")},x=function(){return document},f=function(p){return x().createElement(p)},N=function(){return f("canvas")},i=function(N,S,M){N.style.setProperty(S,M,m)},v=function(K,Z,F){y.def(ht.widget[K],Z,F)},V=function(L,j){L.appendChild(j)},W=function(Z,a){Z.removeChild(a)},A=y.getInternal(),E=A.addEventListener,M=A.removeEventListener;ht.widget.RulerFrame=function(s){var p=this,y=p._view=A.createView(null,p),X=p.$1k=N(),C=p.$2k=N(),W=p.$3k=N(),v=p.$4k=N();p._defaultRulerConfig={size:20,borderWidth:1,borderStyle:"solid",borderColor:"#888",defaultMajorTickSpacing:50,minMajorTickSpacing:10,minPhysicalMajorTickSpacing:40,maxPhysicalMajorTickSpacing:100,tickSpacingAdaptable:!0,majorTickTextFont:"12px Arial",majorTickTextColor:"#666",majorTickColor:"#888",minorTickColor:"#ccc",background:"rgba(0,0,0,0)",guideColor:"rgb(0, 173, 239)",guideWidth:2,guideVisible:!1,guideTipVisible:!1,guideTipBorderColor:"#666",guideTipTextColor:"#666",guideTipTextFont:"12px Arial",guideTipBackground:"#fff"},p._topRulerConfig={visible:!0},p._rightRulerConfig={visible:!1},p._bottomRulerConfig={visible:!1},p._leftRulerConfig={visible:!0},V(y,X),V(y,W),V(y,C),V(y,v),i(y,T,b),i(y,"box-sizing","border-box"),i(y,"-moz-box-sizing","border-box"),i(X,T,Z),i(C,T,Z),i(W,T,Z),i(v,T,Z),p.$14k=function(){p.$13k=1,p.iv()},p.$15k=function(O){if(p._topRulerConfig.guideVisible||p._rightRulerConfig.guideVisible||p._bottomRulerConfig.guideVisible||p._leftRulerConfig.guideVisible||p._defaultRulerConfig.guideVisible||(p._topRulerConfig.guideTipVisible||p._rightRulerConfig.guideTipVisible||p._bottomRulerConfig.guideTipVisible||p._leftRulerConfig.guideTipVisible||p._defaultRulerConfig.guideTipVisible)&&p._component){var C=y.getBoundingClientRect();p.$16k={x:O.clientX-C.left,y:O.clientY-C.top},p.$5k()}},p.setComponent(s)},v("RulerFrame",r,{ms_v:1,ms_fire:1,ms_ac:["defaultRulerConfig","topRulerConfig","rightRulerConfig","bottomRulerConfig","leftRulerConfig","component"],setComponent:function(U){var c=this,B=c._component,n=c.getView();if(n){if(c._component=U,c.fp("component",B,U),B){var p=c.getComponentView(B);W(n,p),M(n,"mousemove",c.$15k),c.removeComponentPropertyChangeListener(B,c.$14k)}if(U){var a=c.getComponentView(U);V(n,a),i(a,T,Z),E(n,"mousemove",c.$15k),c.addComponentPropertyChangeListener(U,c.$14k)}}},addComponentPropertyChangeListener:function(Q,x){Q&&Q.mp&&Q.mp(x)},removeComponentPropertyChangeListener:function(J,h){J&&J.ump&&J.ump(h)},getComponentHZoom:function(P){return P&&P.getZoom?P.getZoom():1},getComponentVZoom:function(O){return O&&O.getZoom?O.getZoom():1},getComponentViewRect:function(T){return T&&T.getViewRect?T.getViewRect():void 0},getComponentView:function(B){return B&&B.getView?B.getView():B},invalidateComponent:function(N){N&&N.iv&&N.iv()},validateComponent:function(X){X&&X.validate&&X.validate()},$7k:function(l,S,e,o,b,G,t,D,N,d,Q,I){if(S.visible){var T=this._defaultRulerConfig,$="borderStyle",H="borderColor",K="borderWidth",O="background",n=S[$]||T[$],J=S[H]||T[H],h=S[K]||T[K],x=S.size!=m?S.size:T.size,Z=S[O]||T[O],y=x+h,u=this.$6k(h,n,J,l,e,b,y,t,D,N,d,Q,I);i(l,b,"0px"),G?A.setCanvas(l,o-u,x):A.setCanvas(l,x,o-u),i(l,"background",Z),i(l,B,Y)}else i(l,B,R),i(this.getComponentView(this._component),b,"0px")},$6k:function(G,l,Z,N,u,y,W,F,E,H,p,t,I){var D=0;return i(N,u,G+"px "+l+" "+Z),i(this.getComponentView(this._component),y,W+o),F?(i(N,E,H+o),D+=H):i(N,E,"0px"),p?(i(N,t,I+o),D+=I):i(N,t,"0px"),D},validateImpl:function(){var x=this,V=x._component,W=x.$1k,I=x.$2k,G=x.$3k,S=x.$4k,e=x._view,N=x._defaultRulerConfig,y=x._topRulerConfig,Q=x._rightRulerConfig,P=x._bottomRulerConfig,d=x._leftRulerConfig,u=N.size;if(e&&V){var X=y.size!=m?y.size:u,r=Q.size!=m?Q.size:u,$=P.size!=m?P.size:u,q=d.size!=m?d.size:u;x.$7k(W,y,"border-bottom",e.offsetWidth,n,!0,d.visible,t,q,Q.visible,a,r),x.$7k(I,Q,"border-left",e.offsetHeight,a,!1,y.visible,n,X,P.visible,c,$),x.$7k(G,P,"border-top",e.offsetWidth,c,!0,d.visible,t,q,Q.visible,a,r),x.$7k(S,d,"border-right",e.offsetHeight,t,!1,y.visible,n,X,P.visible,c,$),x.$13k?delete x.$13k:x.invalidateComponent(V),x.validateComponent(V),x.$5k()}},$5k:function(){function b(o,I,q,p,E,V){if(I.visible){var b=U(o),k=I[X]||G,d=I[K]!=m?I[K]:T,B=I[F]||x,j=I[N]||v,D=I.size!=m?I.size:t,lo=I[l]||C,Cj=I[n]||O,ho=I[g]||H,dq=I[e]!=m?I[e]:W,oj=I[A]!=m?I[A]:M,tr=I[i]!=m?I[i]:f,Ad=I[L]!=m?I[L]:a,se=I[Z]!=m?I[Z]:z,Di=I[P]!=m?I[P]:u,ng=I[$]||Ee,tk=I[J]||Lr;d&&(k=Y[V]=Y.$8k(Y[V]||k,I[y]||h,I[w]||R,p?c:s,Cj)),q.call(Y,b,Q,S,r,_,D,p?c:s,k,B,j,E,lo,ho);var mo=Y.$16k;(dq||oj)&&mo&&(p?Y.$9k(b,mo.x,D,ng,tk,dq,oj,tr,Ad,se,Di):Y.$10k(b,mo.y,D,ng,tk,dq,oj,tr,Ad,se,Di,E))}}var Y=this,q=Y.$1k,k=Y.$2k,p=Y.$3k,I=Y.$4k,D=Y._topRulerConfig,j=Y._rightRulerConfig,o=Y._bottomRulerConfig,E=Y._leftRulerConfig,d=Y._defaultRulerConfig,B=Y._component,V=Y.getComponentViewRect(B),c=Y.getComponentHZoom(B),s=Y.getComponentVZoom(B),Q=V.x*c,r=Q+V.width*c,S=V.y*s,_=S+V.height*s,t=Y._defaultRulerConfig.size,X="defaultMajorTickSpacing",y="maxPhysicalMajorTickSpacing",w="minPhysicalMajorTickSpacing",K="tickSpacingAdaptable",F="majorTickTextFont",N="majorTickTextColor",l="majorTickColor",g="minorTickColor",e="guideVisible",A="guideTipVisible",i="guideTipBorderColor",L="guideTipTextColor",Z="guideTipTextFont",P="guideTipBackground",$="guideColor",J="guideWidth",n="minMajorTickSpacing",G=d[X],h=d[y],R=d[w],T=d[K],x=d[F],v=d[N],C=d[l],O=d[n],H=d[g],W=d[e],M=d[A],f=d[i],a=d[L],z=d[Z],u=d[P],Ee=d[$],Lr=d[J];Y._view&&B&&(b(q,D,Y.$11k,!0,!1,"_currentTopMajorTickSpacing"),b(k,j,Y.$12k,!1,!0,"_currentRightMajorTickSpacing"),b(p,o,Y.$11k,!0,!0,"_currentBottomMajorTickSpacing"),b(I,E,Y.$12k,!1,!1,"_currenLeftMajorTickSpacing"))},$8k:function(y,E,a,z,o){return a>y*z?y=F(E/z/o)*o:y*z>E&&(y=Q(a/z/o)*o),y},getHTipText:function(A){var x=this,K=x._component,g=0,H=x._view.getBoundingClientRect();return K.lp?g=w(K.lp({x:A.x+H.left,y:A.y}).x):g-=w(this.getComponentView(K).style.left)||0,g},$9k:function(o,I,y,e,h,J,C,q,$,E,b){var X=this,G=X._component;o.save(),A.translateAndScale(o,0,0,1);var m=I-(w(this.getComponentView(G).style.left)||0),f=0;if(I=X.getHTipText(X.$16k),J&&(o.beginPath(),o.fillStyle=e,o.rect(m,f,h,y),o.fill()),C){o.beginPath(),o.textAlign="center",o.textBaseline="middle",o.font=E;var D=o.measureText(I).width+6;o.fillStyle=b,o.rect(m-D/2,f,D,y),o.fill(),o.strokeStyle=q,o.stroke(),o.beginPath(),o.fillStyle=$,o.fillText(I,m,f+y/2)}o.restore()},getVTipText:function(B){var N=this,x=N._component,I=0,Q=N._view.getBoundingClientRect();return x.lp?I=w(x.lp({x:B.x,y:B.y+Q.top}).y):I-=w(this.getComponentView(x).style.top)||0,I},formatScaleText:function(S){return Math.round(S)},$10k:function(a,W,T,D,S,v,Z,G,$,J,h,Q){var f=this,O=f._component;a.save(),A.translateAndScale(a,0,0,1);var o=T/2,t=W-(w(this.getComponentView(O).style.top)||0);if(W=f.getVTipText(f.$16k),v&&(a.beginPath(),a.fillStyle=D,a.rect(o-T/2,t,T,S),a.fill()),Z){a.translate(o,t),a.rotate((Q?90:-90)*s/180),a.translate(-o,-t),a.beginPath(),a.textAlign="center",a.textBaseline="middle",a.font=J;var e=a.measureText(W).width+6;a.fillStyle=h,a.rect(o-e/2,t-T/2,e,T),a.fill(),a.strokeStyle=G,a.stroke(),a.fillStyle=$,a.fillText(W,o,t)}a.restore()},$11k:function(g,B,u,Z,$,s,q,d,K,S,V,f,c){g.save(),u=0;var b=B,I=Z,v=(b+I)/2;B=0,Z=I-b,A.translateAndScale(g,0,0,1);var o=0,x=0,Q=w(s/2),M=s-Q,l=V?0:Q,E=d*q,h=E/10;B-=E,Z+=E,g.clearRect(B,0,Z-B,s),g.beginPath(),g.fillStyle=c;var y=F(v/h)*h-b;for(o=y;Z>o;o+=h)g.rect(o,u+l,1,M);for(o=y;o>B;o-=h)g.rect(o,u+l,1,M);for(g.fill(),l=V?0:1,g.beginPath(),g.fillStyle=f,y=F(v/E)*E-b,o=y;Z>o;o+=E)g.rect(o,u+l,1,s-1);for(o=y;o>B;o-=E)g.rect(o,u+l,1,s-1);g.fill();var N=w(/\d+px/.exec(K)[0]),_=(N||10)/2;g.textBaseline="middle",l=V?s-_-2:_+2,g.beginPath(),g.fillStyle=S,g.font=K;var H=F(v/E)*E/q;for(o=y,x=H;Z>o;o+=E,x+=d){var D=this.getHScaleText?this.getHScaleText(o):x;g.fillText(this.formatScaleText(D),o+2,u+l)}for(o=y,x=H;o>B;o-=E,x-=d){var D=this.getHScaleText?this.getHScaleText(o):x;g.fillText(this.formatScaleText(D),o+2,u+l)}g.restore()},$12k:function(N,m,n,C,I,J,f,L,r,v,k,$,R){function u(y,H,M,r,j,X){j=E.getVScaleText?E.getVScaleText(M):j,j=E.formatScaleText(j),N.translate(y+H,M),N.rotate(-r),N.translate(-y-H,-M),N.fillText(j,y+H+(X?2:1),M),N.translate(y+H,M),N.rotate(r),N.translate(-y-H,-M)}N.save(),m=0;var g=n,W=I,S=(g+W)/2;n=0,I=W-g,A.translateAndScale(N,0,0,1);var T=0,E=this,h=0,t=w(J/2),O=J-t,d=k?0:t,z=L*f,H=z/10;n-=z,I+=z,N.clearRect(m,0,J,I-n),N.beginPath(),N.fillStyle=R;var j=F(S/H)*H-g;for(T=j;I>T;T+=H)N.rect(m+d,T,O,1);for(T=j;T>n;T-=H)N.rect(m+d,T,O,1);for(N.fill(),d=k?0:1,N.beginPath(),N.fillStyle=$,j=F(S/z)*z-g,T=j;I>T;T+=z)N.rect(m+d,T,J-1,1);for(T=j;T>n;T-=z)N.rect(m+d,T,J-1,1);N.fill();var i=w(/\d+px/.exec(r)[0]),B=(i||10)/2,P=90*s/180;N.textBaseline="middle",d=k?J-B:B+2,P=k?-P:P,N.beginPath(),N.fillStyle=v,N.font=r;var q=F(S/z)*z/f;for(T=j,h=q;I>T;T+=z,h+=L)u(m,d,T,P,h,k);for(T=j,h=q;T>n;T-=z,h-=L)u(m,d,T,P,h,k);N.restore()},onPropertyChanged:function(){this.iv()},dispose:function(){var k=this,i=k._component,j=k._view;i&&k.removeComponentPropertyChangeListener(i,k.$14k),j&&(M(j,"mousemove",k.$15k),W(j.parentNode,j),k._view=null)}})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:(0,eval)("this"),Object);