svgedit/dist/editor/system/extensions/ext-connector/ext-connector.js

11 lines
8.3 KiB
JavaScript
Raw Normal View History

2020-09-06 06:32:10 +00:00
System.register([],(function(t,e){"use strict";return{execute:function(){function asyncGeneratorStep(t,e,r,n,o,a,i){try{var s=t[a](i),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,o)}
/**
* @file ext-connector.js
*
* @license MIT
*
* @copyright 2010 Alexis Deveria
*
*/
t("default",{name:"connector",init:function init(t){var r=this;return function _asyncToGenerator(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function _next(t){asyncGeneratorStep(a,n,o,_next,_throw,"next",t)}function _throw(t){asyncGeneratorStep(a,n,o,_next,_throw,"throw",t)}_next(void 0)}))}}(regeneratorRuntime.mark((function _callee(){var n,o,a,i,s,c,u,l,d,g,f,m,h,v,_,b,p,y,x,k,S,A,w,B,E,N,I,M,C,G;return regeneratorRuntime.wrap((function _callee$(j){for(;;)switch(j.prev=j.next){case 0:return I=function _init(){i(b).find("*").each((function(){var t=this.getAttributeNS(_,"connector");if(t){this.setAttribute("class",l.substr(1));var e=t.split(" "),r=o.getStrokedBBox([a(e[0])]),n=o.getStrokedBBox([a(e[1])]);i(this).data("c_start",e[0]).data("c_end",e[1]).data("start_bb",r).data("end_bb",n),o.getEditorNS(!0)}}))},N=function _updateConnectors(t){if(E(t),y.length)for(var e=y.length;e--;){var r=y[e],n=r.connector,a=r.elem,i=r.is_start?"start":"end",s=o.getStrokedBBox([a]);s.x=r.start_x,s.y=r.start_y,d(n,i+"_bb",s),d(n,i+"_off");var c=r.is_start?"end":"start",u=d(n,c+"_bb"),l=u.x+u.width/2,g=u.y+u.height/2,f=k(l,g,s,S(i,n));w(n,r.is_start?0:"end",f.x,f.y,!0);var m=k(f.x,f.y,d(n,c+"_bb"),S(c,n));if(w(n,r.is_start?"end":0,m.x,m.y,!0),navigator.userAgent.includes("AppleWebKit")){for(var h=n.points,v=h.numberOfItems,_=[],b=0;b<v;b++)f=h.getItem(b),_[b]=f.x+","+f.y;n.setAttribute("points",_.join(" "))}}},E=function _findConnectors(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:x,e=i(b).find(l);y=[],e.each((function(){var e;function add(){t.includes(this)&&(e=!0)}var r=[];["start","end"].forEach((function(t,e){var n=d(this,"c_"+t);null==n?(n=document.getElementById(this.attributes["se:connector"].value.split(" ")[e]),d(this,"c_"+t,n.id),d(this,t+"_bb",o.getStrokedBBox([n]))):n=document.getElementById(n),r.push(n)}),this);for(var n=0;n<2;n++){var a=r[n];if(e=!1,i(a).parents().each(add),a&&a.parentNode){if(t.includes(a)||e){var s=o.getStrokedBBox([a]);y.push({elem:a,connector:this,is_start:0===n,start_x:s.x,start_y:s.y})}}else i(this).remove()}}))},B=function _updateLine(t,e){for(var r=y.length;r--;){var n=y[r],o=n.connector,a=n.is_start?"start":"end",i=d(o,a+"_bb");i.x=n.start_x+t,i.y=n.start_y+e,d(o,a+"_bb",i);var s=n.is_start?"end":"start",c=d(o,s+"_bb"),u=c.x+c.width/2,l=c.y+c.height/2,g=k(u,l,i,S(a,o));w(o,n.is_start?0:"end",g.x,g.y,!0);var f=k(g.x,g.y,d(o,s+"_bb"),S(s,o));w(o,n.is_start?"end":0,f.x,f.y,!0)}},w=function _setPoint(t,e,r,n,o){var a=t.points,i=s.createSVGPoint();i.x=r,i.y=n,"end"===e&&(e=a.numberOfItems-1);try{a.replaceItem(i,e)}catch(o){for(var c=t.getAttribute("points").split(" "),u=0;u<c.length;u++)u===e&&(c[u]=r+","+n);t.setAttribute("points",c.join(" "))}if(o){var l=a.getItem(0),d=a.getItem(a.numberOfItems-1);w(t,1,(d.x+l.x)/2,(d.y+l.y)/2)}},A=function _showPanel(t){var e=i("#connector_rules");e.length||(e=i('<style id="connector_rules"></style>').appendTo("head")),e.text(t?"#tool_clone, #tool_topath, #tool_angle, #xy_panel { display: none !important; }":""),i("#connector_panel").toggle(t)},S=function _getOffset(t,e){var r=e.getAttribute("marker-"+t),n=5*e.getAttribute("stroke-width");return r?n:0},k=function _getBBintersect(t,e,r,n){n&&(n-=0,(r=i.extend({},r)).width+=n,r.height+=n,r.x-=n/2,r.y-=n/2);var o,a=r.x+r.width/2,s=r.y+r.height/2,c=t-a,u=e-s;return{x:a+c*(o=Math.abs(u/c)<r.height/r.width?r.width/2/Math.abs(c):u?r.height/2/Math.abs(u):0),y:s+u*o}},o=(n=r).canvas,a=o.getElem,i=t.$,s=t.svgroot,c=o.addSVGElementFromJson,u=t.selectorManager,l=".se_connector",d=i.data,b=t.svgcontent,p=!1,y=[],x=[],function(){var t=o.groupSelectedElements;o.groupSelectedElements=function(){o.removeFromSelection(i(l).toArray());for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return t.apply(this,r)};var e=o.moveSelectedElements;o.moveSelectedElements=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var o=e.apply(this,r);return N(),o},_=o.getEditorNS()}(),M=[{id:"mode_connect",type:"mode",icon:n.curConfig