ht-palette.js 13 KB

1
  1. !function(x,X,H){"use strict";var r="px",e="0",Y="innerHTML",z="className",F=ht.Default,_=ht.Color,f=ht.Node,K="position",Z="top",m="left",S=F.animate,c=F.getInternal(),l="width",e="0",d="none",L="max-height",G="font",Q="background",h="border-box",b="user-select",B="box-sizing",E="overflow",s=F.isTouchable,c=F.getInternal(),u=_.titleIconBackground,O=F.scrollBarInteractiveSize,g=/msie 9/.test(x.navigator?x.navigator.userAgent.toLowerCase():""),W=null,R=function(){return document},o=function(i){return R().createElement(i)},M=function(){return o("div")},C=function(){var m=M(),E=m.style;return E.msTouchAction=d,E.cursor="default",s&&E.setProperty("-webkit-tap-highlight-color","rgba(0, 0, 0, 0)",W),E.position="absolute",E.left=e,E.top=e,m},P=function(){return o("canvas")},U=function(){return document.body},$=function(u,j,T){u.style.setProperty(j,T,W)},N=function(y,r){y.style.removeProperty(r)},a=function(s,N,H){F.def(ht.widget[s],N,H)},D=function(_,y){_.appendChild(y)},j=function(L,H){L.removeChild(H)},p=function(_,M,w,r){_.addEventListener(M,w,!!r)};c.addMethod(F,{paletteExpandIcon:{width:16,height:16,comps:[{type:"triangle",rect:[4,4,10,8],background:u,rotation:3.14}]},paletteCollapseIcon:{width:16,height:16,comps:[{type:"triangle",rect:[4,4,10,8],background:u}]},paletteTitleLabelColor:F.labelSelectColor,paletteTitleLabelFont:F.labelFont,paletteContentLabelFont:F.labelFont,paletteContentLabelColor:"#777",paletteContentBackground:"#fff",paletteTitleHeight:F.widgetTitleHeight,paletteTitleBackground:_.titleBackground,paletteTitleHoverBackground:_.titleBackground,paletteSeparatorWidth:1,paletteSeparatorColor:H,paletteItemHoverBorderColor:_.highlight,paletteItemSelectBackground:_.highlight},!0);var w=".palette-item:hover{border: 1px solid "+F.paletteItemHoverBorderColor+" !important}"+" .palette-header:hover{background: "+F.paletteTitleHoverBackground+" !important}",v=document.createElement("style");s||(v.styleSheet?v.styleSheet.cssText=w:v.appendChild(R().createTextNode(w))),R().getElementsByTagName("head")[0].appendChild(v);var t=function(G){var p=this;p.$22h=G,p.addListeners()};F.def(t,X,{ms_listener:1,getView:function(){return this.$22h.getView()},$26h:function(){var l=this;l.$36h&&U().removeChild(l.$36h),l.$23h=l.$24h=l.$25h=l.$35h=l.$36h=W},handle_touchstart:function(Y){for(var e,d=this,y=d.$22h,b=Y.target,j=y.sm(),c=y.dm(),O="palette-header",m="palette-header-tool",I="palette-item",W=!1,h=!1,u=!1;b&&(b[z]||"").indexOf(O)<0&&(b[z]||"").indexOf(I)<0;)b=b.parentNode;if(b&&b[z].indexOf(m)>=0?W=!0:b&&b[z].indexOf(O)>=0?u=!0:b&&b[z].indexOf(I)>=0&&(h=!0),F.isLeftButton(Y))if(d.$27h(Y))d.$24h=F.getClientPoint(Y),d.$25h=y.ty();else if(W){F.preventDefault(Y),e=b.parentNode.$11h;var $=c.getDataById(e),x=$.s("tools")[b.toolIndex];x.action&&x.action.call(y)}else if(u){F.preventDefault(Y),e=b.$11h;var $=c.getDataById(e);$.isExpanded()?$.setExpanded(!1):$.setExpanded(!0)}else if(h){e=b.$11h;var g=c.getDataById(e);j.ss(g),y.handleDragAndDrop&&(F.preventDefault(Y),g.s("draggable")&&(y.handleDragAndDrop(Y,"prepare"),d.$35h=0)),g.s("draggable")||(F.preventDefault(Y),d.$24h=F.getClientPoint(Y),d.$25h=y.ty())}else F.preventDefault(Y),d.$24h=F.getClientPoint(Y),d.$25h=y.ty();else d.$26h(Y)},handle_mousedown:function(L){this.handle_touchstart(L)},handle_mousewheel:function(w){this.handleScroll(w,w.wheelDelta/40,w.wheelDelta!==w.wheelDeltaX)},handle_DOMMouseScroll:function(X){this.handleScroll(X,-X.detail,1)},handleScroll:function(g,K,A){var Z=this.$22h;F.preventDefault(g),A&&Z._41o()&&Z.ty(Z.ty()+20*K)},handle_mouseup:function(r){this.handle_touchend(r)},handle_touchend:function(P){var s=this;s.$37h(P),s.$26h(P)},handleWindowMouseUp:function(e){this.handleWindowTouchEnd(e)},handleWindowTouchEnd:function(S){var c=this;c.$37h(S),c.$26h(S)},$37h:function(o){var P=this,W=P.$22h;2===P.$35h&&(P.$35h=3,W.handleDragAndDrop(o,"end"))},handleWindowMouseMove:function(d){this.handleWindowTouchMove(d)},handleWindowTouchMove:function(B){var u=this,b=u.$22h,y=u.$23h,n=u.$24h,I=u.$25h,j=F.getClientPoint(B),e=b._29I,m=u.$36h;if(1===u.$35h||2===u.$35h){if(u.$35h=2,b.handleDragAndDrop(B,"between"),s){var t=B.touches[0];B=t?t:B.changedTouches[0]}m.style.left=B.pageX-parseInt(m.width)/2+r,m.style.top=B.pageY-parseInt(m.height)/2+r}else"p"===y?b.ty(I+j.y-n.y):"v"===y&&b.ty(I+(n.y-j.y)/e.height*b._59I)},handle_mousemove:function(f){this.handle_touchmove(f)},handle_touchmove:function(m){if(!F.isDragging()&&F.isLeftButton(m)){var y=this,N=y.$22h,g=y.$27h(m);if(y.$24h){if(!y.$23h){if(F.getDistance(F.getClientPoint(m),y.$24h)<2)return;y.$23h=g?"v":"p",F.startDragging(y)}}else if(g)N._43o();else if(0===y.$35h){if(y.$35h=1,N.handleDragAndDrop(m,"begin"),s){var L=m.touches[0];m=L?L:m.changedTouches[0]}var B=y.$36h=new Image,P=N.$10h[N.sm().ld().getId()].querySelector(".image-box"),E=parseInt(P.style.width),n=parseInt(P.style.height);B.draggable=!1,B.src=P.toDataURL(),B.width=E,B.height=n,B.style.position="absolute",B.style.left=m.pageX-E/2+r,B.style.top=m.pageY-n/2+r,U().appendChild(B),F.startDragging(y)}}},$27h:function(S){var T=this.$22h,b=T.getView(),f=b.getBoundingClientRect(),x=T._29I,k=S.clientX-f.left+b.scrollLeft;return T._41o()&&x.x+x.width-k<O}}),ht.widget.Palette=function(Y){var w=this,g=w._view=c.createView(null,w);w.$9h={},w.$10h={},w.$4h={},w._29I={x:0,y:0,width:0,height:0},w._59I=0,w.dm(Y?Y:new ht.DataModel),g[z]="ht-widget-palette",w.$29h=new t(w),$(g,Q,F.paletteContentBackground),$(g,E,"auto"),$(g,B,h),$(g,"-moz-"+B,h),$(g,"-webkit-"+b,d),$(g,"-moz-"+b,d),$(g,"-ms-"+b,d),$(g,b,d),$(g,"position","absolute"),$(g,"overflow","hidden"),D(g,w._79O=C()),p(g,"dragstart",function(b){b.dataTransfer&&(b.dataTransfer.setData("Text","nodeid:"+b.target.$11h),b.dataTransfer.effectAllowed="all",w.$29h.$26h())})},a("Palette",X,{ms_v:1,ms_fire:1,ms_dm:1,ms_sm:1,ms_vs:1,ms_ac:["itemImageWidth","itemImageHeight","itemImagePadding","itemMargin","layout","autoHideScrollBar","scrollBarSize","scrollBarColor"],$30h:0,_itemImagePadding:4,_itemImageWidth:70,_itemImageHeight:50,_itemMargin:10,_layout:"largeicons",_autoHideScrollBar:F.autoHideScrollBar,_scrollBarSize:F.scrollBarSize,_scrollBarColor:F.scrollBarColor,getViewRect:function(){return this._29I},ty:function(e){return e?(this.setTranslateY(e),void 0):this.getTranslateY()},setTranslateY:function(P){if(this.$32h==W){var L=this,w=L.$33h(P),m=L.$30h;L.$30h=w,L.fp("translateY",m,w)}},getTranslateY:function(){return this.$30h},setLayout:function(M){var x,y,b=this,J=b._layout;b._layout=M,"smallicons"===M?x=y=20:"iconsonly"===M?x=y=50:(x=70,y=50),b.setItemImageWidth(x),b.setItemImageHeight(y),b.setItemImagePadding(4),b.fp("layout",J,M)},getDataAt:function(s){for(var $=s.target;$&&$.$11h==W;)$=$.parentNode;return $&&$.$11h!=W?this.getDataModel().getDataById($.$11h):void 0},$20h:function(){var d=16;return s&&(d*=1.2),d},$19h:function(){return F.paletteTitleHeight},$18h:function(){var D=F.paletteSeparatorWidth,o=F.paletteTitleBackground,Z=F.paletteSeparatorColor||F.brighter(o);return D+r+" solid "+Z},$17h:function(z){$(z,"cursor","pointer"),$(z,"display","inline-block"),$(z,"margin-right",(s?8:4)+r),$(z,"vertical-align",Z)},$1h:function(S){var N=this,w=M(),j=M(),T=o("span");w[z]="palette-header",$(w,K,"relative"),$(w,Q,F.paletteTitleBackground),$(w,"color",F.paletteTitleLabelColor),$(w,Z,e),$(w,B,h),$(w,"-moz-"+B,h),$(w,"padding","0 5px 0 0"),$(w,"border-top",N.$18h()),$(w,l,"100%"),$(w,"cursor","pointer"),$(w,"white-space","nowrap"),$(w,E,"hidden"),$(w,G,F.paletteTitleLabelFont),$(w,"line-height",N.$19h()+r),w.$11h=S.getId();var u=P(),J=N.$19h(),O=N.$20h();N.$17h(u),c.setCanvas(u,O,J),D(w,u);var n=S.s("tools");if(n)for(var m=0;m<n.length;m++){var U=P();N.$17h(U),c.setCanvas(U,O,J),U[z]="palette-header-tool palette-header-tool"+S.getId()+"-"+m,U.style.position="absolute",U.style.right=(O+10)*m+"px",U.toolIndex=m,D(w,U)}return u[z]="palette-toggle-icon-"+S.getId(),j[z]="palette-content",$(j,"max-height",0+r),$(j,G,F.paletteContentLabelFont),$(j,E,"hidden"),j.$11h=S.getId(),N.$9h[S.getId()]=j,T[Y]=S.getName(),$(T,G,F.paletteTitleLabelFont),D(w,u),D(w,T),[w,j]},$2h:function(n){var w=this,I=w._layout,h=g&&n.s("draggable")?o("a"):M(),u=P(),b=M(),j=n.getName()||"",p=n.s("title")||n.getToolTip()||j,B=w._itemMargin;u[z]="image-box";var R=w.getItemImageWidth(),J=w.getItemImageHeight();return c.setCanvas(u,R,J),D(h,u),b[Y]=j,b[z]="label-box","iconsonly"!==I&&D(h,b),h[z]="palette-item",$(h,"vertical-align",Z),$(h,"cursor","pointer"),$(h,"border-radius",5+r),$(h,"border","1px solid transparent"),$(h,"text-align","center"),$(h,"display","inline-block"),$(h,"margin-left",B+r),$(h,"margin-top",B+r),$(h,"color",F.paletteContentLabelColor),"smallicons"===I?($(u,"vertical-align","middle"),$(h,"margin-left",2+r),$(h,"margin-top",2+r),$(h,"padding",2+r),$(h,"text-align",m),$(b,"display","inline-block"),$(b,"min-width",w.$21h+w._itemMargin+r)):"largeicons"===I&&($(b,"max-width",R+r),$(b,"overflow","hidden")),h.$11h=n.getId(),p&&(h.title=p),n.s("draggable")&&!w.handleDragAndDrop&&(g?(h.href="#",$(h,"text-decoration",d)):h.draggable="true"),h},$16h:function(_,x,f,U){var K=c.initContext(_);c.translateAndScale(K,0,0,1),K.clearRect(0,0,f,f);var b=(f-U)/2;F.drawStretchImage(K,F.getImage(x),"fill",0,b,U,U),K.restore()},$15h:function(o){var J=this,K=o.getId(),C=J._view.querySelector(".palette-toggle-icon-"+K),L=o.isExpanded()?F.paletteCollapseIcon:F.paletteExpandIcon;if(C&&L){var S=J.$19h(),$=J.$20h();J.$16h(C,L,S,$)}},_drawToolsIcon:function(s){var J=this,W=s.s("tools");if(W)for(var o=0;o<W.length;o++){var i=J._view.querySelector(".palette-header-tool"+s.getId()+"-"+o),H=W[o].icon,m=J.$19h(),Y=J.$20h();J.$16h(i,H,m,Y)}},$14h:function(G){var k=this,w=G.getId(),d=k.$10h[w].querySelector(".image-box"),m=G.getImage(),p=G.s("image.stretch");if(d&&m){var C=c.initContext(d),x=k.getItemImagePadding();x="smallicons"===k._layout?x/2:x;var W=k.getItemImageWidth()-2*x,L=k.getItemImageHeight()-2*x;c.translateAndScale(C,0,0,1),C.clearRect(0,0,W,L),F.drawStretchImage(C,F.getImage(m),p,x,x,W,L,G,k),C.restore()}},validateImpl:function(){var a,v,P,N=this,y=N.$9h,O=N._layout,s=N.$10h,_=N.$4h,k=N._view,l=N.dm();if(N.$13h&&(delete N.$13h,_={},l.each(function(G){_[G.getId()]=G})),"smallicons"===O)for(var A in _){var z=_[A];if(z instanceof f){var u=z.getName()||"",H=F.getTextSize(F.paletteContentLabelFont,u).width;N.$21h!=W&&N.$21h>H||(N.$21h=H)}}for(var A in _){P=_[A];var t,w;if(l.contains(P)){if(P instanceof ht.Group){var b,x=N.$1h(P),B=s[P.getId()];B&&(b=B.nextSibling,j(k,b),j(k,B)),v=l.getSiblings(P).indexOf(P);var U=k.children[2*v]||N._79O;U&&U.parentNode?(k.insertBefore(x[0],U),k.insertBefore(b||x[1],U)):(k.appendChild(x[0]),k.appendChild(b||x[1])),s[P.getId()]=x[0],a=y[P.getId()]=b||x[1],w=P.$12h;var C=P.s("promptText");w||(P.$12h=o("div"),P.$12h[Y]=C||"",w=P.$12h),0===P.getChildren().size()?a.contains(w)||D(a,w):a.contains(w)&&j(a,w)}else if(t=P.getParent()){var R=N.$2h(P),V=s[P.getId()];a=y[t.getId()],V&&j(V.parentNode,V),v=l.getSiblings(P).indexOf(P);var p=a.children[v];p?a.insertBefore(R,p):D(a,R),s[P.getId()]=R,N.$14h(P)}}else{var n=s[P.getId()],q=n.parentNode;if(P instanceof ht.Group){var X=n.nextSibling;j(k,n),j(k,X),delete y[P.getId()]}else j(q,n),0===q.children.length&&(t=l.getDataById(q.$11h),w=t.$12h,w&&!q.contains(w)&&D(q,w));delete s[P.getId()]}}N.$4h={};var M=function(){var j=N._59I,V=0;N.$32h!=W&&(clearInterval(N.$32h),V=0,delete N.$32h),N.$32h=setInterval(function(){N.$31h(),j===N._59I?(V++,V>=2&&(clearInterval(N.$32h),delete N.$32h)):(V=0,j=N._59I)},30)};for(var d in y)if(a=y[d],P=l.getDataById(y[d].$11h),N.$15h(P),N._drawToolsIcon(P),P.isExpanded()){if(a.style.maxHeight===0+r){var h=a.scrollHeight+N._itemMargin+r;S(a).duration(200).set(L,h).set("padding-bottom",N._itemMargin+r).end(function(){return function(){M()}}(h))}else a.style.maxHeight=a.scrollHeight+r;a.style.paddingBottom=N._itemMargin+r}else a.style.maxHeight!==0+r&&S(a).duration(200).set(L,e).set("padding-bottom",e).end(function(){return function(){M()}}(a));N.$28h(),N.$31h()},$31h:function(){for(var w=this,j=w._view,v=0,A=j.children,M=0;M<A.length;M++){var t=A[M];t.className&&t.className.indexOf("palette-")>=0&&(v+=t.offsetHeight)}w._59I=v,w.$30h=w.$33h(w.ty());var S=w.ty();j.scrollTop=-S,w._29I={x:0,y:-S,width:j.clientWidth,height:j.clientHeight},$(w._79O,Z,-S+r),w._93I()},$33h:function(l){var M=this,n=M._29I.height-M._59I;return n>l&&(l=n),l>0?0:Math.round(l)},redraw:function(){this.$13h||(this.$13h=1,this.iv())},onPropertyChanged:function(d){["autoHideScrollBar","scrollBarSize","scrollBarColor","translateY"].indexOf(d.property)<0&&this.redraw(),"translateY"===d.property&&(this.iv(),this._43o())},findDataByName:function(G){for(var k=this.dm().getDatas(),K=0;K<k.size();K++){var e=k.get(K);if(e.getName()===G)return e}},setDataModel:function(N){var h=this,Y=h._dataModel,W=h._selectionModel;Y!==N&&(Y&&(Y.umm(h.$6h,h),Y.umd(h.$8h,h),Y.umh(h.$7h,h),W||Y.sm().ums(h.$28h,h)),h._dataModel=N,N.mm(h.$6h,h),N.md(h.$8h,h),N.mh(h.$7h,h),W?W._21I(N):N.sm().ms(h.$28h,h),h.sm().setSelectionMode("single"),h.fp("dataModel",Y,N))},$6h:function(X){var V=this,P=V._view,D=X.data,k=V.$4h;"add"===X.kind?k[D.getId()]=D:"remove"===X.kind?k[D.getId()]=D:"clear"===X.kind&&(V.$10h={},V.$9h={},V.$4h={},P[Y]=""),V.iv()},$7h:function(V){var j=this,k=V.data;j.$4h[k.getId()]=k,j.iv()},$8h:function(I){var s=this,H=I.data,W=I.property;"expanded"===W?s.iv():(s.$4h[H.getId()]=H,s.iv())},$28h:function(){var e,x=this,y=x.sm(),X="palette-item",t=y.ld();this.dm().each(function(U){e=x.$10h[U.getId()],e&&e[z].indexOf(X)>=0&&(U===t?$(e,Q,F.paletteItemSelectBackground):N(e,Q))})}})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:this,Object);