var SDT=function(){if(document.querySelector(".sdt-canvas #sdtDropCanvas")){document.querySelector(".sdt-canvas #sdtDropCanvas").innerHTML=document.querySelector(".sdt-canvas #sdtDropCanvas").innerHTML+'<g id="sdtDropCanvasAll"><g id="sdtDropCanvasRight"></g><g id="sdtDropCanvasLeft"></g></g>';document.querySelector(".sdt-canvas #sdtDropCanvas #sdtDropCanvasAll").setAttribute("style","-moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none;")}var e={SDTTreeElements:[],SDTTreeSet:{SDTTreeLineType:"bessel",SDTTreeEleHeight:0,SDTTreeEleWidth:0,SDTTreeEleMargin:0,SDTTreeLineColor:"#000",SDTTreeCenterX:0,SDTTreeCenterY:0,SDTViewBoxMinX:0,SDTViewBoxMinY:0,SDTViewBoxWidth:0,SDTViewBoxHeight:0}};var t;var r=[];var i={id:"SDTTreeRight",objHeight:0,childEles:[],objRelativelyHeight:0,objcolumn:0};var l={id:"SDTTreeLeft",objHeight:0,childEles:[],objRelativelyHeight:0,objcolumn:0};var n={id:"SDTTree",objHeight:0,childEles:[i,l],objRelativelyHeight:0,objcolumn:0};var o=[];var s={};s.dataDropError;var a=new RegExp(/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/);var d=true;function T(){this.type="";this.dropSwitch=true;this.foresideType=[];this.id="";this.name="";this.foresideObjId="";this.objHeight=1;this.childEles=[];this.objRelativelyHeight=0;this.objcolumn=0;this.leanRight=true}function c(e){this.countType=e;this.countNumber=0}if(document.querySelectorAll(".sdt-drag-element")){var h=document.querySelectorAll(".sdt-drag-element");for(var S=0;S<h.length;S++){if(h[S].dataset.sdtType){h[S].setAttribute("draggable","true");var u={dropSwitch:true,foresideType:["all"],objHeight:1,leanRight:true};u.type=h[S].dataset.sdtType;if(h[S].dataset.sdtElesetDropswitch){if(h[S].dataset.sdtElesetDropswitch==="ture"){u.dropSwitch=true}else{u.dropSwitch=false}}if(h[S].dataset.sdtElesetForesidetype){u.foresideType=[];var f="";var D=h[S].dataset.sdtElesetForesidetype;for(j=0;j<D.length;j++){if(D.charAt(j)!==","){f=f+D.charAt(j)}else{u.foresideType.push(f);f=""}if(j===D.length-1){u.foresideType.push(f);f=""}}}if(h[S].dataset.sdtElesetLeanright){if(h[S].dataset.sdtElesetLeanright==="ture"){u.leanRight=true}else{u.leanRight=false}}if(h[S].getElementsByTagName("text")[0]){u.name=h[S].getElementsByTagName("text")[0].childNodes[0].nodeValue}e.SDTTreeElements.push(u);var v=new c(u.type);o.push(v)}}e.SDTTreeSet.SDTTreeEleWidth=document.querySelector(".sdt-drag-element svg").width.baseVal.value;e.SDTTreeSet.SDTTreeEleHeight=document.querySelector(".sdt-drag-element svg").height.baseVal.value;e.SDTTreeSet.SDTViewBoxWidth=document.querySelector(".sdt-canvas").clientWidth;e.SDTTreeSet.SDTViewBoxHeight=document.querySelector(".sdt-canvas").clientHeight;var g=document.querySelector(".sdt-canvas");if(g.dataset.sdtElesetLinetype){e.SDTTreeSet.SDTTreeLineType=g.dataset.sdtElesetLinetype}if(g.dataset.sdtElesetLinecolor){if(a.test(g.dataset.sdtElesetLinecolor)){e.SDTTreeSet.SDTTreeLineColor=g.dataset.sdtElesetLinecolor}else{console.log("颜色值非法")}}if(g.dataset.sdtElesetTreecenterx){e.SDTTreeSet.SDTTreeCenterX=Number(g.dataset.sdtElesetTreecenterx)}if(g.dataset.sdtElesetTreecentery){e.SDTTreeSet.SDTTreeCenterY=Number(g.dataset.sdtElesetTreecentery)}if(g.dataset.sdtElesetMargin){e.SDTTreeSet.SDTTreeEleMargin=Number(g.dataset.sdtElesetMargin);e.SDTTreeSet.SDTTreeEleHeight=e.SDTTreeSet.SDTTreeEleHeight+e.SDTTreeSet.SDTTreeEleMargin}else{e.SDTTreeSet.SDTTreeEleMargin=e.SDTTreeSet.SDTTreeEleHeight;e.SDTTreeSet.SDTTreeEleHeight=e.SDTTreeSet.SDTTreeEleHeight+e.SDTTreeSet.SDTTreeEleMargin}}document.querySelector(".sdt-drag-element-lis").ondragstart=function(e){var r;if(e.target.dataset.sdtType){r=e.target.dataset.sdtType;t=p(r)}e.dataTransfer.setData("Text",t)};document.getElementById("sdtDropCanvas").ondragover=function(e){e.preventDefault()};document.getElementById("sdtDropCanvas").ondrop=function(e){e.preventDefault();if(t){if(t.dropSwitch===true){o.forEach(function(e){if(e.countType===t.type){t.id=t.type+(e.countNumber+1);if(t.name===""){t.name=t.id}else{t.name=t.name+"-"+(e.countNumber+1)}e.countNumber++}});if(e.target.id==="sdtDropCanvas"){if(t.leanRight){t.foresideObjId="SDTTreeRight"}else{t.foresideObjId="SDTTreeLeft"}}else{t.foresideObjId=e.target.parentNode.id}if(e.target.parentNode.getAttribute("objcolumn")){t.objcolumn=Number(e.target.parentNode.getAttribute("objcolumn"))+1}else{t.objcolumn=1}m(n,t);r.push(t.id);E()}else{s.dataDropError=t.foresideType}}t=null};function p(t){var r;e.SDTTreeElements.forEach(function(e){if(e.type===t){r=new T;r.type=e.type;r.name=e.name;r.dropSwitch=e.dropSwitch;r.foresideType=e.foresideType;r.leanRight=e.leanRight}});return r}function E(){H(n);document.querySelectorAll("#sdtDropCanvasRight svg,#sdtDropCanvasLeft svg,.objLine").forEach(function(e){e.remove()});C(n,e.SDTTreeSet);if(e.SDTTreeSet.SDTTreeLineType==="straight"){w(n,e.SDTTreeSet)}else{L(n,e.SDTTreeSet)}M();if(d){A();B();d=false}}function m(e,t){for(var r=0;r<e.childEles.length;r++){if(e.childEles[r].id===t.id){t.foresideObjId=null}else{m(e.childEles[r],t);if(e.childEles[r].id===t.foresideObjId){e.childEles[r].childEles.push(t)}}}}function b(e,t){for(var r=0;r<e.childEles.length;r++){b(e.childEles[r],t);if(e.childEles[r].id===t){e.childEles.splice(r,1)}}}function H(e){t(e.childEles[0]);t(e.childEles[1]);function t(e){if(e.childEles.length>0){e.objHeight=0}for(var r=0;r<e.childEles.length;r++){t(e.childEles[r]);e.objHeight=e.objHeight+e.childEles[r].objHeight;e.childEles[r].objRelativelyHeight=e.childEles[r].objHeight}}}function C(e,t){var r=t.SDTTreeEleHeight;var i=t.SDTTreeEleWidth;var l=t.SDTTreeEleMargin;var n=t.SDTTreeCenterX;var o=t.SDTTreeCenterY;s(e.childEles[0],true);s(e.childEles[1],false);function s(e,t){for(var a=0;a<e.childEles.length;a++){e.childEles[a].objRelativelyHeight=e.childEles.length>1?a>0?e.childEles[a].objRelativelyHeight*.5+e.childEles[a-1].objRelativelyHeight+e.childEles[a-1].objHeight*.5:e.objRelativelyHeight+e.childEles[a].objRelativelyHeight*.5-e.objHeight*.5:e.objRelativelyHeight;var d=document.querySelector("[data-sdt-type="+e.childEles[a].type+"] svg").cloneNode(true);d.setAttribute("id",e.childEles[a].id);d.setAttribute("class",e.childEles[a].type);d.setAttribute("objcolumn",e.childEles[a].objcolumn);if(t){d.setAttribute("x",(r*3+i)*e.childEles[a].objcolumn-i+n)}else{d.setAttribute("x",-(r*3+i)*e.childEles[a].objcolumn+n)}d.setAttribute("y",r*e.childEles[a].objRelativelyHeight+l/2+o);if(t){document.querySelector("#sdtDropCanvasRight").appendChild(d)}else{document.querySelector("#sdtDropCanvasLeft").appendChild(d)}document.querySelector("#"+e.childEles[a].id+" text").childNodes[0].nodeValue=e.childEles[a].name;s(e.childEles[a],t)}}}function w(e,t){var r=t.SDTTreeEleHeight;var i=t.SDTTreeEleWidth;var l=t.SDTTreeLineColor;var n=t.SDTTreeCenterX;var o=t.SDTTreeCenterY;s(e.childEles[0],true);s(e.childEles[1],false);function s(e,t){for(var a=0;a<e.childEles.length;a++){s(e.childEles[a],t);if(t){var d=(r*3+i)*e.childEles[a].objcolumn-r*3-i+n;var T=" h "}else{var d=-(r*3+i)*e.childEles[a].objcolumn+(r*3+i)+n;var T=" h -"}var c=r*e.childEles[a].objRelativelyHeight-(e.childEles[a].objHeight>1?(e.childEles[a].objHeight-1)*(r/2):0);c=c+o;var h=r+(e.childEles[a].objHeight>1?(e.childEles[a].objHeight-1)*r:0);var S=-(r/2)-(e.childEles[a].objHeight>1?(e.childEles[a].objHeight-1)*(r/2):0);if(e.childEles.length>1){if(a===0){document.getElementById("sdtDropCanvasAll").innerHTML=document.getElementById("sdtDropCanvasAll").innerHTML+"<path class='objLine' d =' M "+d+" "+(c+h+S)+T+r*3+"' stroke = '"+l+"' fill='transparent'/><path class='objLine' d =' M "+d+" "+(c+h+S-r/4)+" v "+(-S+r/4)+"' stroke = '"+l+"' stroke-width='4px' fill='transparent'/>"}else if(a===e.childEles.length-1){document.getElementById("sdtDropCanvasAll").innerHTML=document.getElementById("sdtDropCanvasAll").innerHTML+"<path class='objLine' d =' M "+d+" "+(c+h+S)+T+r*3+"' stroke = '"+l+"' fill='transparent'/><path class='objLine' d =' M "+d+" "+c+" v "+(h+S+r/2/2)+"' stroke = '"+l+"' stroke-width='4px' fill='transparent'/>"}else{document.getElementById("sdtDropCanvasAll").innerHTML=document.getElementById("sdtDropCanvasAll").innerHTML+"<path class='objLine' d =' M "+d+" "+(c+h+S)+T+r*3+"' stroke = '"+l+"' fill='transparent'/><path class='objLine' d =' M "+d+" "+c+" v "+h+"' stroke = '"+l+"' stroke-width='4px' fill='transparent'/>"}}else{c=c+r/4;h=h-r/2;S=S+r/4;document.getElementById("sdtDropCanvasAll").innerHTML=document.getElementById("sdtDropCanvasAll").innerHTML+"<path class='objLine' d =' M "+d+" "+(c+h+S)+T+r*3+"' stroke = '"+l+"' fill='transparent'/><path class='objLine' d =' M "+d+" "+c+" v "+h+"' stroke = '"+l+"' stroke-width='4px' fill='transparent'/>"}}}}function L(e,t){var r=t.SDTTreeEleHeight;var i=t.SDTTreeEleWidth;var l=t.SDTTreeLineColor;var n=t.SDTTreeCenterX;var o=t.SDTTreeCenterY;s(e.childEles[0],true);s(e.childEles[1],false);function s(e,t){for(var a=0;a<e.childEles.length;a++){s(e.childEles[a],t);if(t){var d=(r*3+i)*e.childEles[a].objcolumn-i+n;var T=(r*3+i)*e.objcolumn+i-i+r+n;var c=d-r;var h=T-r}else{var d=-(r*3+i)*e.childEles[a].objcolumn+i+n;var T=d+r*3-r;var c=d+r;var h=T+r}var S=r*e.childEles[a].objRelativelyHeight+r/2+o;var u=r*e.objRelativelyHeight+r/2+o;document.getElementById("sdtDropCanvasAll").innerHTML=document.getElementById("sdtDropCanvasAll").innerHTML+"<path class='objLine' d =' M "+d+" "+S+" C "+c+" "+S+","+T+" "+u+","+h+" "+u+"' stroke = '"+l+"' fill='transparent'/>"}}}function M(){document.querySelectorAll("#sdtDropCanvas svg").forEach(function(e){e.ondragover=function(e){e.preventDefault();if(t){var r=this.getAttribute("class");var i=t.foresideType;if(i.indexOf(r)!==-1||i.indexOf("all")!==-1){e.target.parentNode.setAttribute("opacity",.38);t.dropSwitch=true}else{t.dropSwitch=false}}};e.ondragleave=function(e){e.preventDefault();this.setAttribute("opacity",1);t.dropSwitch=false;var r=t.foresideType;if(r.indexOf("root")!==-1||r.indexOf("all")!==-1){t.dropSwitch=true}}})}function B(){var t=document.querySelector("#sdtDropCanvas");function r(r){e.SDTTreeSet.SDTViewBoxMinX=-(r.clientX-x);e.SDTTreeSet.SDTViewBoxMinY=-(r.clientY-y);t.setAttribute("viewBox",e.SDTTreeSet.SDTViewBoxMinX+","+e.SDTTreeSet.SDTViewBoxMinY+","+e.SDTTreeSet.SDTViewBoxWidth+","+e.SDTTreeSet.SDTViewBoxHeight)}function i(t){x=t.clientX+e.SDTTreeSet.SDTViewBoxMinX;y=t.clientY+e.SDTTreeSet.SDTViewBoxMinY;document.addEventListener("mousemove",r)}document.getElementById("sdtDropCanvas").addEventListener("mousedown",i,false);document.addEventListener("mouseup",function(e){document.removeEventListener("mousemove",r)});document.addEventListener("dragend",function(e){document.removeEventListener("mousemove",r)})}function A(){var t=e.SDTTreeSet.SDTViewBoxHeight;var r=1;document.querySelector("#sdtDropCanvas").addEventListener("mousewheel",function(e){e.preventDefault();if(e.wheelDelta>0){if(r<1.5){r+=.1}}else{if(r>.75){r-=.1}}document.getElementById("sdtDropCanvasAll").setAttribute("transform","translate("+t/2+" "+t/2+") scale("+r+") translate("+-(t/2)+" "+-(t/2)+")")});document.querySelector("#sdtDropCanvas").addEventListener("DOMMouseScroll",function(e){e.preventDefault();if(e.detail<0){if(r<1.5){r+=.1}}else{if(r>.75){r-=.1}}document.getElementById("sdtDropCanvasAll").setAttribute("transform","translate("+t/2+" "+t/2+") scale("+r+") translate("+-(t/2)+" "+-(t/2)+")")})}return{SVGDragComponent:function(t){if(t.SDTTreeSet.lineType){e.SDTTreeSet.SDTTreeLineType=t.SDTTreeSet.lineType}if(t.SDTTreeSet.lineColor){if(a.test(t.SDTTreeSet.lineColor)){e.SDTTreeSet.SDTTreeLineColor=t.SDTTreeSet.lineColor}else{console.log("颜色值非法")}}if(t.SDTTreeSet.treeCenterX!==undefined){e.SDTTreeSet.SDTTreeCenterX=Number(t.SDTTreeSet.treeCenterX)}if(t.SDTTreeSet.treeCenterY!==undefined){e.SDTTreeSet.SDTTreeCenterY=Number(t.SDTTreeSet.treeCenterY)}if(t.SDTTreeSet.treeEleMargin!==undefined){e.SDTTreeSet.SDTTreeEleMargin=Number(t.SDTTreeSet.treeEleMargin);e.SDTTreeSet.SDTTreeEleHeight=document.querySelector(".sdt-drag-element svg").height.baseVal.value;e.SDTTreeSet.SDTTreeEleHeight=e.SDTTreeSet.SDTTreeEleHeight+e.SDTTreeSet.SDTTreeEleMargin}t.SDTTreeElements.forEach(function(t){var r=t;e.SDTTreeElements.forEach(function(e){if(r.type===e.type){if("dropSwitch"in r){if(typeof r.dropSwitch==="string"){if(r.dropSwitch==="ture"){e.dropSwitch=true}else{e.dropSwitch=false}}else if(typeof r.dropSwitch==="boolean"){e.dropSwitch=r.dropSwitch}}if("foresideType"in r){e.foresideType=r.foresideType}if("leanRight"in r){e.leanRight=r.leanRight}if("name"in r){e.name=r.name}}})})},returnTree:function(e){if(e){var t=i(n);function i(e,t){var t=t||{};for(var r in e){if(r==="id"||r==="name"||r==="foresideObjId"||r==="childEles"||!isNaN(r)){if(typeof e[r]==="object"){t[r]=Object.prototype.toString.call(e[r])==="[object Array]"?[]:{};i(e[r],t[r])}else{t[r]=e[r]}}}return t}return t}var l=[n,r,o];return l},backCenter:function(){var t=document.getElementById("sdtDropCanvas");var r=e.SDTTreeSet;var i=r.SDTViewBoxMinX;var l=r.SDTViewBoxMinY;var n=r.SDTViewBoxWidth;var o=r.SDTViewBoxHeight;setTimeout(function(){if(i!=0||l!=0){i=i-i/4;l=l-l/4;if(i<1&&i>0||i>-1&&i<0){i=0}if(l<1&&l>0||l>-1&&l<0){l=0}t.setAttribute("viewBox",i+","+l+","+o+","+n);r.SDTViewBoxMinX=i;r.SDTViewBoxMinY=l;r.SDTViewBoxWidth=n;r.SDTViewBoxHeight=o;setTimeout(arguments.callee,20)}},20)},removeELe:function(e){if(Object.prototype.toString.call(e)==="[object Array]"){e.forEach(function(e){b(n,e)})}else if(e===undefined){b(n,r.pop())}E()},drawInputTree:function(e){n=e[0];r=e[1];o=e[2];E()},dropErrorMsg:s}}();