=0&&this.selected_pts.push(G)}this.selected_pts.sort();
z=this.selected_pts.length;for(n=Array(z);z--;){B=this.segs[this.selected_pts[z]];B.select(true);n[z]=B.ptgrip}ra.canDeleteNodes=true;ra.closed_subpath=this.subpathIsClosed(this.selected_pts[0]);ma("selected",n)};var j=f=null,E=false;return{mouseDown:function(n,z,B,G){var K;if(ua==="path"){mouse_x=B;mouse_y=G;G=mouse_x/A;z=mouse_y/A;B=svgedit.utilities.getElem("path_stretch_line");d=[G,z];if(i.gridSnapping){G=svgedit.utilities.snapToGrid(G);z=svgedit.utilities.snapToGrid(z);mouse_x=svgedit.utilities.snapToGrid(mouse_x);
mouse_y=svgedit.utilities.snapToGrid(mouse_y)}if(!B){B=document.createElementNS(c.SVG,"path");svgedit.utilities.assignAttributes(B,{id:"path_stretch_line",stroke:"#22C","stroke-width":"0.5",fill:"none"});B=svgedit.utilities.getElem("selectorParentGroup").appendChild(B)}B.setAttribute("display","inline");var C=null;if(j){C=j.pathSegList;var O=C.numberOfItems;K=6/A;for(var T=false;O;){O--;var V=C.getItem(O),X=V.x;V=V.y;if(G>=X-K&&G<=X+K&&z>=V-K&&z<=V+K){T=true;break}}K=Ya();svgedit.path.removePath_(K);
K=svgedit.utilities.getElem(K);X=C.numberOfItems;if(T){if(O<=1&&X>=2){G=C.getItem(0).x;z=C.getItem(0).y;n=B.pathSegList.getItem(1);n=n.pathSegType===4?j.createSVGPathSegLinetoAbs(G,z):j.createSVGPathSegCurvetoCubicAbs(G,z,n.x1/A,n.y1/A,G,z);G=j.createSVGPathSegClosePath();C.appendItem(n);C.appendItem(G)}else if(X<3)return C=false;$(B).remove();element=K;j=null;ya=false;if(b){svgedit.path.path.matrix&&svgedit.coords.remapElement(K,{},svgedit.path.path.matrix.inverse());B=K.getAttribute("d");n=$(svgedit.path.path.elem).attr("d");
$(svgedit.path.path.elem).attr("d",n+B);$(K).remove();svgedit.path.path.matrix&&svgedit.path.recalcRotatedPath();svgedit.path.path.init();ra.toEditMode(svgedit.path.path.elem);svgedit.path.path.selectPt();return false}}else{if(!$.contains(a,Ib(n))){console.log("Clicked outside canvas");return false}C=j.pathSegList.numberOfItems;O=j.pathSegList.getItem(C-1);K=O.x;O=O.y;if(n.shiftKey){n=svgedit.math.snapToAngle(K,O,G,z);G=n.x;z=n.y}n=B.pathSegList.getItem(1);n=n.pathSegType===4?j.createSVGPathSegLinetoAbs(Gb(G),
Gb(z)):j.createSVGPathSegCurvetoCubicAbs(Gb(G),Gb(z),n.x1/A,n.y1/A,n.x2/A,n.y2/A);j.pathSegList.appendItem(n);G*=A;z*=A;B.setAttribute("d",["M",G,z,G,z].join(" "));B=C;if(b)B+=svgedit.path.path.segs.length;svgedit.path.addPointGrip(B,G,z)}}else{d_attr="M"+G+","+z+" ";j=L({element:"path",curStyles:true,attr:{d:d_attr,id:Ga(),opacity:t.opacity/2}});B.setAttribute("d",["M",mouse_x,mouse_y,mouse_x,mouse_y].join(" "));B=b?svgedit.path.path.segs.length:0;svgedit.path.addPointGrip(B,mouse_x,mouse_y)}}else if(svgedit.path.path){svgedit.path.path.storeD();
K=n.target.id;if(K.substr(0,14)=="pathpointgrip_"){z=svgedit.path.path.cur_pt=parseInt(K.substr(14));svgedit.path.path.dragging=[B,G];C=svgedit.path.path.segs[z];if(n.shiftKey)C.selected?svgedit.path.path.removePtFromSelection(z):svgedit.path.path.addPtsToSelection(z);else{if(svgedit.path.path.selected_pts.length<=1||!C.selected)svgedit.path.path.clearSelection();svgedit.path.path.addPtsToSelection(z)}}else if(K.indexOf("ctrlpointgrip_")==0){svgedit.path.path.dragging=[B,G];n=K.split("_")[1].split("c");
z=Number(n[0]);svgedit.path.path.selectPt(z,Number(n[1]))}if(!svgedit.path.path.dragging){if(Ca==null)Ca=va.getRubberBandBox();svgedit.utilities.assignAttributes(Ca,{x:B*A,y:G*A,width:0,height:0,display:"inline"},100)}}},mouseMove:function(n,z){E=true;if(ua==="path"){if(j){var B=j.pathSegList,G=B.numberOfItems-1;if(d){var K=svgedit.path.addCtrlGrip("1c1"),C=svgedit.path.addCtrlGrip("0c2");K.setAttribute("cx",n);K.setAttribute("cy",z);K.setAttribute("display","inline");K=d[0];var O=d[1];B.getItem(G);
var T=K+(K-n/A),V=O+(O-z/A);C.setAttribute("cx",T*A);C.setAttribute("cy",V*A);C.setAttribute("display","inline");C=svgedit.path.getCtrlLine(1);svgedit.utilities.assignAttributes(C,{x1:n,y1:z,x2:T*A,y2:V*A,display:"inline"});if(G===0)r=[n,z];else{B=B.getItem(G-1);C=B.x;var X=B.y;if(B.pathSegType===6){C+=C-B.x2;X+=X-B.y2}else if(r){C=r[0]/A;X=r[1]/A}svgedit.path.replacePathSeg(6,G,[K,O,C,X,T,V],j)}}else if(K=svgedit.utilities.getElem("path_stretch_line")){G=B.getItem(G);if(G.pathSegType===6)svgedit.path.replacePathSeg(6,
1,[n,z,(G.x+(G.x-G.x2))*A,(G.y+(G.y-G.y2))*A,n,z],K);else r?svgedit.path.replacePathSeg(6,1,[n,z,r[0],r[1],n,z],K):svgedit.path.replacePathSeg(4,1,[n,z],K)}}}else if(svgedit.path.path.dragging){K=svgedit.path.getPointFromGrip({x:svgedit.path.path.dragging[0],y:svgedit.path.path.dragging[1]},svgedit.path.path);O=svgedit.path.getPointFromGrip({x:n,y:z},svgedit.path.path);G=O.x-K.x;K=O.y-K.y;svgedit.path.path.dragging=[n,z];svgedit.path.path.dragctrl?svgedit.path.path.moveCtrl(G,K):svgedit.path.path.movePts(G,
K)}else{svgedit.path.path.selected_pts=[];svgedit.path.path.eachSeg(function(){if(this.next||this.prev){var ca=Ca.getBBox(),S=svgedit.path.getGripPt(this);ca=svgedit.math.rectsIntersect(ca,{x:S.x,y:S.y,width:0,height:0});this.select(ca);ca&&svgedit.path.path.selected_pts.push(this.index)}})}},mouseUp:function(n,z){if(ua==="path"){d=null;if(!j){z=svgedit.utilities.getElem(Ya());ya=false;r=null}return{keep:true,element:z}}if(svgedit.path.path.dragging){var B=svgedit.path.path.cur_pt;svgedit.path.path.dragging=
false;svgedit.path.path.dragctrl=false;svgedit.path.path.update();E&&svgedit.path.path.endChanges("Move path point(s)");!n.shiftKey&&!E&&svgedit.path.path.selectPt(B)}else if(Ca&&Ca.getAttribute("display")!="none"){Ca.setAttribute("display","none");Ca.getAttribute("width")<=2&&Ca.getAttribute("height")<=2&&ra.toSelectMode(n.target)}else ra.toSelectMode(n.target);E=false},toEditMode:function(n){svgedit.path.path=svgedit.path.getPath_(n);ua="pathedit";za();svgedit.path.path.show(true).update();svgedit.path.path.oldbbox=
svgedit.utilities.getBBox(svgedit.path.path.elem);b=false},toSelectMode:function(n){var z=n==svgedit.path.path.elem;ua="select";svgedit.path.path.show(false);f=false;za();svgedit.path.path.matrix&&svgedit.path.recalcRotatedPath();if(z){ma("selected",[n]);gb([n],true)}},addSubPath:function(n){if(n){ua="path";b=true}else{ra.clear(true);ra.toEditMode(svgedit.path.path.elem)}},select:function(n){if(f===n){ra.toEditMode(n);ua="pathedit"}else f=n},reorient:function(){var n=m[0];if(n)if(svgedit.utilities.getRotationAngle(n)!=
0){var z=new svgedit.history.BatchCommand("Reorient path"),B={d:n.getAttribute("d"),transform:n.getAttribute("transform")};z.addSubCommand(new svgedit.history.ChangeElementCommand(n,B));za();this.resetOrientation(n);Y(z);svgedit.path.getPath_(n).show(false).matrix=null;this.clear();gb([n],true);ma("changed",m)}},clear:function(){f=null;if(j){var n=svgedit.utilities.getElem(Ya());$(svgedit.utilities.getElem("path_stretch_line")).remove();$(n).remove();$(svgedit.utilities.getElem("pathpointgrip_container")).find("*").attr("display",
"none");j=r=null;ya=false}else ua=="pathedit"&&this.toSelectMode();svgedit.path.path&&svgedit.path.path.init().show(false)},resetOrientation:function(n){if(n==null||n.nodeName!="path")return false;var z=svgedit.transformlist.getTransformList(n),B=svgedit.math.transformListToTransform(z).matrix;z.clear();n.removeAttribute("transform");z=n.pathSegList;var G=z.numberOfItems,K;for(K=0;K