ht-htmlnode.js 5.6 KB

1
  1. !function(U){"use strict";var X="ht",m=U[X],w=function(){return document},h=function(){return w().body},V=function(L,m,l){L.style.setProperty(m,l,null)},j=function(I){return w().createElement(I)},Q=function(){return j("div")},s=function(){var b=j("canvas");return b},f=function(Q,e){V(Q,"-webkit-transform",e),V(Q,"-ms-transform",e),V(Q,"transform",e)},$=function(H,Y){V(H,"-webkit-transform-origin",Y),V(H,"-ms-transform-origin",Y),V(H,"transform-origin",Y)},g=function(S,H){S.appendChild(H)},u=function(e,Z){e.removeChild(Z)},l=U.parseInt,O=m.Default,E=O.getInternal(),F=Math.PI,Z="white-space",q="visibility",B="left",b="top",H="width",r="height",J="position",S="display",i="z-index",v="px",W="0 0",d="absolute",t="visible",K="hidden",T="none",o="block",p="nowrap",z="rgba(0, 0, 0, 0.005)";O.setImage("node_dragger","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAN9JREFUeNrsV9sNhDAMKyzQVdgARmGzrMJNUFZhAh6nfkVcG9PQgHSR8lEksJs6pnGuLCimSRzAa0yyBK9O4gy8GokU+O0kJOAwiQYg0LP1xNYDW3+0CfBYNb7VOuN4LAGpiOaYUhFDas9F2NPHDELNENJqaHgBgSQJ3ufakfQJqckERcOiK+Ae1FGWBNKGh9oX5WPpLpdNYfffijbsxTHh7VKP7388n1g1h7OKUoUuyGpJakQEuhwkZAKcDXVOdWcrOrL/feBVBHI/q8fcjE1nA9PpyHQ+NJ2Qi8A3AQYAOtS27fCoRY0AAAAASUVORK5CYII=");var k=m.graph.GraphView.prototype,_=k._42;k.adjustHtmlNodeIndex=!0,k._42=function(Y,k){if(_.call(this,Y,k),this.adjustHtmlNodeIndex)for(var O=this.getDataModel()._datas._as,o=O.length,y=1,X=0;o>X;X++){var a=O[X];if(a instanceof N){var Q=this.getDataUI(a);V(Q.$2f,i,y+""),V(Q.$3f,i,y+1+""),y+=2}}};var L=m.HtmlNodeUI=function(c,j){var x=this;L.superClass.constructor.call(x,c,j);var l=x.$2f=Q(),N=x.$3f=s();V(l,J,d),V(l,q,K),V(l,Z,p),N.draggable=!1,V(N,J,d),V(N,S,T),$(N,W),l.addEventListener("change",function($){var E=$.target,w=E.bind||E.getAttribute("bind"),s=E.type&&"checkbox"===E.type?E.checked:E.value,T=j.getContext();w&&T&&(T[w]=s,x.$4f=JSON.stringify(T))}),["mousedown","touchstart","keydown","mousewheel","DOMMouseScroll"].forEach(function(P){l.addEventListener(P,this.$9f.bind(this))},x)};O.def(L,E.ui().NodeUI,{_visible:!0,$11f:function(){var N=this,Z=N.$3f,m=N._data,R=m.getDraggerImageWidth(),U=m.getDraggerImageHeight(),r=m.getDraggerImage(),J=E.initContext(Z);J.beginPath(),E.setCanvas(Z,R,U),E.translateAndScale(J,0,0,1),J.clearRect(0,0,R,U),O.drawImage(J,O.getImage(r),0,0,R,U),J.restore()},_80o:function(u){L.superClass._80o.call(this,u);var D=this,A=D._data,$=A._padding,y=2*$,M=D.$2f,U=D.$3f,_=D.gv,p=_.getZoom(),k=_.getTranslateX(),s=_.getTranslateY(),j=_.getView(),N=D._83o,c=A._width,n=A._height,m=N.position,P=N.rotation,h=(c-y)/A.$5f*p,Y=(n-y)/A.$6f*p,X=D._html,I=A._html,W=A.getHtmlType();if("html"===W){var C=A.getContext()||{},E=D.$4f,x=A.$10f,G=JSON.stringify(C);X&&E&&X===I&&E===G||(D.$4f=G,D._html=I,M.innerHTML=x?x(C):I)}else if(null!=W){var O=A.getHtml();"ht"===W&&(O=O.getView()),X&&X===O&&M.contains(X)||(D._html=O,M.innerHTML="",g(M,O))}if(!M.parentNode){var R=_.$1f;if(!R){var w=Q();V(w,J,d),V(w,i,"0"),R=_.$1f=w;var e=_._canvas.nextSibling;e?j.insertBefore(w,e):g(j,w)}g(R,M),g(R,U),A.onContentInitialized&&A.onContentInitialized(M)}if(A._scalable){var Z=A.$5f,a=A.$6f;f(M,"rotate("+180*(P/F)+"deg) scale("+h+","+Y+")"),V(M,H,""),V(M,r,""),V(M,B,(m.x-Z/p/2)*p+k+v),V(M,b,(m.y-a/p/2)*p+s+v)}else{var He=l(M.style.width),Xe=l(M.style.height),id=l((c-y)*p),sl=l((n-y)*p),sq="100%",Pk=M.children[0];V(Pk,H,sq),V(Pk,r,sq),(He!==id||Xe!==sl)&&(V(M,H,id+v),V(M,r,sl+v),"ht"===W&&I.invalidate()),f(M,"rotate("+180*(P/F)+"deg)"),V(M,B,(m.x-id/p/2)*p+k+v),V(M,b,(m.y-sl/p/2)*p+s+v)}var il=D.dragRect;_.isMovable(A)&&_.isSelected(A)&&il?(u.save(),u.fillStyle=z,u.fillRect(il.x,il.y,il.width,il.height),u.restore(),V(U,B,il.x*p+k+v),V(U,b,il.y*p+s+v),f(U,"scale("+p+","+p+")"),V(U,S,o),D.$11f()):V(U,S,T),V(M,q,this._visible?t:K)},dispose:function(){var M=this.gv.$1f;this.$2f.parentNode===M&&M.removeChild(this.$2f),this.$3f.parentNode===M&&M.removeChild(this.$3f)},_84o:function(P){this._visible=P,V(this.$2f,q,P?t:K),V(this.$3f,S,P?o:T)},_3O:function(){var u=this,x=u.gv,J=u._data;L.superClass._3O.call(u);var P=J.getRect();x.isEditable(J)&&(u.dragRect={x:P.x+P.width+J._padding,y:P.y+10,width:J.getDraggerImageWidth(),height:J.getDraggerImageHeight()},u._68o(u.dragRect))},rectIntersects:function(Y){var h=this._79o();return m.Default.intersection(h,Y)?!0:void 0},$9f:function(E){var p=this.gv,R=this._data;p.sm().contains(R)&&E.stopPropagation()}});var N=m.HtmlNode=function(){N.superClass.constructor.call(this)};m.Default.def(N,m.Node,{ms_ac:["html","context","scalable","padding","draggerImage","draggerImageWidth","draggerImageHeight"],_padding:m.Default.isTouchable?12:6,_image:null,_scalable:!0,_draggerImage:"node_dragger",_draggerImageWidth:20,_draggerImageHeight:20,setHtml:function(t){var c=this,R=c._html;c._html=t,"html"===c.getHtmlType()&&"Handlebars"in U&&(c.$10f=Handlebars.compile(t)),c.$13f(),c.fp("html",R,t)},setContext:function(Y){var C=this,j=C._context;C._context=Y,C.fp("context",j,Y),C.$13f()},setScalable:function(G){var z=this,X=z._scalable;z._scalable=G,z.fp("scalable",X,G),z.$13f()},getHtmlType:function(){var B=this._html;return B?"string"==typeof B?"html":B.getView?"ht":"dom":null},$13f:function(){var e=this,L=e._html,s=e.$10f;if(L){var B=Q(),z=!1,E=e.getHtmlType();if(V(B,J,d),V(B,Z,p),V(B,q,K),"html"===E?(B.innerHTML=s?s(e.getContext()||{}):L,z=!0):"ht"===E?(g(B,L.getView()),z=!0):"dom"===E&&(g(B,L),z=!0),z){var y=2*e._padding;g(h(),B),e.$5f=B.scrollWidth,e.$6f=B.scrollHeight,e._width=e.$5f+y,e._height=e.$6f+y,e._originWidth=e._width,e._originHeight=e._height,u(h(),B)}}},getUIClass:function(){return m.HtmlNodeUI}})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:this,Object);