define("local_treestudyplan/simpleline",["exports","./css-calc"],(function(_exports,_cssCalc){function _defineProperties(target,props){for(var i=0;i0&&(this.refreshTimer=setInterval((function(){_this.positionCheck()}),this.specs.autorefresh)),this.active=!0,this.update()}var Constructor,protoProps,staticProps;return Constructor=SimpleLine,(protoProps=[{key:"setConfig",value:function(config){var _this2=this;this.specs||(this.specs={autorefresh:10,class:"",color:"",anchors:{start:["middle","right"],end:["middle","left"]},gravity:{start:1,end:1},stroke:"4px"}),config&&"object"==_typeof(config)&&specsCopy(this.specs,config),this.svg&&(clearInterval(this.refreshTimer),this.specs.autorefresh>0&&(this.refreshTimer=setInterval((function(){_this2.positionCheck()}),this.specs.autorefresh)),this.update())}},{key:"cssClass",get:function(){return this.specs.class},set:function(cssClass){this.specs.class=cssClass,this.update()}},{key:"positionCheck",value:function(){var startPos={x:this.start.offsetLeft,y:this.start.offsetTop},endPos={x:this.end.offsetLeft,y:this.end.offsetTop},needUpdate=!1;this.startPos&&(needUpdate=needUpdate||this.startPos.x!=startPos.x||this.startPos.y!=startPos.y),this.startPos=startPos,this.endPos&&(needUpdate=needUpdate||this.endPos.x!=endPos.x||this.endPos.y!=endPos.y),this.endPos=endPos,needUpdate&&this.update()}},{key:"getContainer",value:function(){var container=this.start.offsetParent;return container||("fixed"==getComputedStyle(this.start).position?container=document.querySelector("body"):console.error("Start element has no offsetParent. likely ")),container}},{key:"getAnchorPoint",value:function(anchor){var x,dirX,y,dirY,el=this.start;return"start"!=anchor&&(anchor="end",el=this.end),this.specs.anchors[anchor].includes("left")?(x=0,dirX=-1):this.specs.anchors[anchor].includes("right")?(x=el.offsetWidth-1,dirX=1):(x=el.offsetWidth/2,dirX=0),this.specs.anchors[anchor].includes("top")?(y=0,dirY=-1):this.specs.anchors[anchor].includes("bottom")?(y=el.offsetHeight-1,dirY=1):(y=el.offsetHeight/2,dirY=0),{x:x,y:y,dir:{x:dirX,y:dirY}}}},{key:"svgDefs",value:function(){var defs=document.createElementNS("http://www.w3.org/2000/svg","defs"),marker=document.createElementNS("http://www.w3.org/2000/svg","marker");marker.setAttribute("id","simpleline-".concat(this.id,"-arrow")),marker.setAttribute("markerUnits","strokeWidth"),marker.setAttribute("viewBox","-8 -8 16 16"),marker.setAttribute("orient","auto"),marker.setAttribute("markerWidth","4"),marker.setAttribute("markerHeight","4"),defs.appendChild(marker);var polygon=document.createElementNS("http://www.w3.org/2000/svg","polygon");return polygon.setAttribute("fill","currentColor"),polygon.setAttribute("points","-8,-8 8,0 -8,8 -5,0"),marker.append(polygon),defs}},{key:"update",value:function(){if(this.active){var container=this.getContainer();if(container){this.svg&&this.svg instanceof SVGElement?container!==this.svg.offsetParent&&container.appendChild(this.svg):(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.setAttribute("id","simpleline-".concat(this.id)),this.svg.setAttribute("class","simpleline ".concat(this.specs.class)),this.svg.style.position="absolute",this.svg.style.pointerEvents="none",container.appendChild(this.svg),this.svg.appendChild(this.svgDefs()));var startAnchor=this.getAnchorPoint("start"),endAnchor=this.getAnchorPoint("end"),strokeWpx=(0,_cssCalc.calc)(this.specs.stroke);endAnchor.x+=endAnchor.dir.x*strokeWpx*1.5,endAnchor.y+=endAnchor.dir.y*strokeWpx*1.5;var elStartPos=getElementPosition(this.start,container),elEndPos=getElementPosition(this.end,container),w=Math.max(elStartPos.x+startAnchor.x,elEndPos.x+endAnchor.x)-Math.min(elStartPos.x+startAnchor.x,elEndPos.x+endAnchor.x),h=Math.max(elStartPos.y+startAnchor.y,elEndPos.y+endAnchor.y)-Math.min(elStartPos.y+startAnchor.y,elEndPos.y+endAnchor.y),weight=Math.sqrt(h*h+w*w)/2,cStartPos={x:elStartPos.x+startAnchor.x,y:elStartPos.y+startAnchor.y,dirx:elStartPos.x+startAnchor.x+startAnchor.dir.x*this.specs.gravity.start*weight,diry:elStartPos.y+startAnchor.y+startAnchor.dir.y*this.specs.gravity.start*weight},cEndPos={x:elEndPos.x+endAnchor.x,y:elEndPos.y+endAnchor.y,dirx:elEndPos.x+endAnchor.x+endAnchor.dir.x*this.specs.gravity.end*weight,diry:elEndPos.y+endAnchor.y+endAnchor.dir.y*this.specs.gravity.end*weight},margin=isNaN(this.specs.stroke)?25:5*this.specs.stroke,bounds={x:Math.min(cStartPos.x,cEndPos.x,cStartPos.dirx,cEndPos.dirx)-margin,y:Math.min(cStartPos.y,cEndPos.y,cStartPos.diry,cEndPos.diry)-margin,w:Math.max(cStartPos.x,cEndPos.x,cStartPos.dirx,cEndPos.dirx)-Math.min(cStartPos.x,cEndPos.x,cStartPos.dirx,cEndPos.dirx)+2*margin,h:Math.max(cStartPos.y,cEndPos.y,cStartPos.diry,cEndPos.diry)-Math.min(cStartPos.y,cEndPos.y,cStartPos.diry,cEndPos.diry)+2*margin},startPos={x:cStartPos.x-bounds.x,y:cStartPos.y-bounds.y,dirx:cStartPos.dirx-bounds.x,diry:cStartPos.diry-bounds.y},endPos={x:cEndPos.x-bounds.x,y:cEndPos.y-bounds.y,dirx:cEndPos.dirx-bounds.x,diry:cEndPos.diry-bounds.y};this.svg.setAttribute("viewBox","0 0 ".concat(bounds.w,", ").concat(bounds.h)),this.svg.setAttribute("width","".concat(bounds.w,"px")),this.svg.setAttribute("height","".concat(bounds.h,"px")),this.svg.style.color=this.specs.color,this.svg.style.left="".concat(bounds.x,"px"),this.svg.style.top="".concat(bounds.y,"px"),this.svg.style.width="".concat(bounds.w,"px"),this.svg.style.height="".concat(bounds.h,"px"),this.line||(this.line=document.createElementNS("http://www.w3.org/2000/svg","path"),this.line.setAttribute("marker-end","url(#simpleline-".concat(this.id,"-arrow)")),this.svg.appendChild(this.line));var strokeWidth=this.specs.stroke;isNaN(strokeWidth)||0==strokeWidth||(strokeWidth="".concat(strokeWidth,"px")),this.line.style.stroke="currentColor",this.line.style.fill="none",this.line.style.strokeWidth=strokeWidth,this.line.setAttribute("d","M ".concat(startPos.x," ").concat(startPos.y,"\n C ").concat(startPos.dirx," ").concat(startPos.diry,", ").concat(endPos.dirx," ").concat(endPos.diry,", ").concat(endPos.x," ").concat(endPos.y))}}}},{key:"remove",value:function(){this.svg.remove(),this.svg=null,this.line=null,clearInterval(this.refreshTimer),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),this.active=!1}}])&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),SimpleLine}();_exports.SimpleLine=SimpleLine,value=0,(key="idCounter")in(obj=SimpleLine)?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value})); //# sourceMappingURL=simpleline.min.js.map