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

10 lines
57 KiB
JavaScript
Raw Normal View History

Refactor canvas in multiple pieces to increase maintainability (#446) * #refactor-canvas getJsonFromSvgElement and svgroot code moved to separate file * #refactor-canvas build files changes * #refactor-canvas addSVGElementsFromJson move to json file * #refactor-canvas selected element option function move separate file * #refactor-canvas moveUpDownSelected move to select-elem * ##refactor-canvas build file updated * #refactor-canvas moveSelectedElements move to selected-elem * #refactor-canvas cloneSelectedElements move to slected-elem * #refactor-canvas alignSelectedElements move to selected-elem * #refactor-canvas deleteSelectedElements move to selected-elem * #refactor-canvas copySelectedElements and groupSelectedElements move to selected-elem * #refactor-canvas pushGroupProperty, ungroupSelectedElement move to selected-elem * #refactor-canvas comment changes * #refactor-canvas UndoManager move to separate file * #refactor-canvas event file move to mouseMove, mouseUpEvent and dblClickEvent * #refactor-canvas mouseDown move to event * #refactor-canvas move to undo file * #refactor alignment changes and set function revert return * #refactor-canvas textaction move to separate file * #refactor-canvas paste-element function move to separate file * #refactor-canvas set and get method move to separate file * #refactor-canvas set and get function moved changes * #refactor clear file import and regaring function moved changes changes * #refactor-canvas svg related function move to separate file * #refactor-canvas setBackground methos move to elem-get-set file * #refactor-canvas getBsplinePoint method move to event file * #refactor-canvas export functions move to svg-exec * #refactor-canvas svg related function moved separate file * #refactor-canvas updateCanvas, cycleElement move to selected-elem file * #refactor-canvas removeUnusedDefElems move to svg-exec file * #refactor-canvas blur method move to separate file blur-event.js * #refactor-canvas selection related function move to separate file slection.js * #refactor-canvas convertGradients, mousewheelmove event bind function move to other files * #refactor-canvas extension function move to selection file * #refactor-canvas svg tag long string changes to es6 format * eslint fixes * eslint and test fixes * add netlify logo per their requirements * #refactor-canvas path file separate to path-method.js and path-actions.js * #refactor-canvas lint issue fixed * #refactor-canvas path.js file class and const move to path-method.js * #refactor-canvas eslint issue fixed. 'jsdoc/check-examples': 'off' already so removed eslint-disable jsdoc/check-examples * #refactor-canvas path class moved changes and copy-elem.js file cypress test issue fixed * #refactor-canvas UI - Clipboard paste element cypress issue fixed * #refactor-canvas cypress test cases issue fixed changes * #refactor-canvas cypress test cases issue fixed changes * #refactor-canvas cypress test case issue fixed * npm update and fix a few eslint new errors * fix snapshot and run tests * add star tool to cypress * #refactor-canvas shapelibrary, star, polygon and panning tool issue fixed * build * Update layer.js * revert proper declarations Authored-by OptimistikSAS
2020-11-11 10:38:45 +00:00
System.register([],(function(t){"use strict";return{execute:function(){var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}var check=function(t){return t&&t.Math==Math&&t},r=check("object"==typeof globalThis&&globalThis)||check("object"==typeof window&&window)||check("object"==typeof self&&self)||check("object"==typeof e&&e)||function(){return this}()||Function("return this")(),fails=function(t){try{return!!t()}catch(t){return!0}},n=!fails((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),o={}.propertyIsEnumerable,i=Object.getOwnPropertyDescriptor,a={f:i&&!o.call({1:2},1)?function propertyIsEnumerable(t){var e=i(this,t);return!!e&&e.enumerable}:o},createPropertyDescriptor=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},c={}.toString,classofRaw=function(t){return c.call(t).slice(8,-1)},u="".split,s=fails((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==classofRaw(t)?u.call(t,""):Object(t)}:Object,requireObjectCoercible=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},toIndexedObject=function(t){return s(requireObjectCoercible(t))},isObject=function(t){return"object"==typeof t?null!==t:"function"==typeof t},toPrimitive=function(t,e){if(!isObject(t))return t;var r,n;if(e&&"function"==typeof(r=t.toString)&&!isObject(n=r.call(t)))return n;if("function"==typeof(r=t.valueOf)&&!isObject(n=r.call(t)))return n;if(!e&&"function"==typeof(r=t.toString)&&!isObject(n=r.call(t)))return n;throw TypeError("Can't convert object to primitive value")},f={}.hasOwnProperty,has=function(t,e){return f.call(t,e)},l=r.document,p=isObject(l)&&isObject(l.createElement),documentCreateElement=function(t){return p?l.createElement(t):{}},h=!n&&!fails((function(){return 7!=Object.defineProperty(documentCreateElement("div"),"a",{get:function(){return 7}}).a})),d=Object.getOwnPropertyDescriptor,v={f:n?d:function getOwnPropertyDescriptor(t,e){if(t=toIndexedObject(t),e=toPrimitive(e,!0),h)try{return d(t,e)}catch(t){}if(has(t,e))return createPropertyDescriptor(!a.f.call(t,e),t[e])}},anObject=function(t){if(!isObject(t))throw TypeError(String(t)+" is not an object");return t},y=Object.defineProperty,g={f:n?y:function defineProperty(t,e,r){if(anObject(t),e=toPrimitive(e,!0),anObject(r),h)try{return y(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(t[e]=r.value),t}},m=n?function(t,e,r){return g.f(t,e,createPropertyDescriptor(1,r))}:function(t,e,r){return t[e]=r,t},setGlobal=function(t,e){try{m(r,t,e)}catch(n){r[t]=e}return e},b="__core-js_shared__",S=r[b]||setGlobal(b,{}),w=Function.toString;"function"!=typeof S.inspectSource&&(S.inspectSource=function(t){return w.call(t)});var x,_,E,O=S.inspectSource,j=r.WeakMap,A="function"==typeof j&&/native code/.test(O(j)),I=createCommonjsModule((function(t){(t.exports=function(t,e){return S[t]||(S[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.7.0",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),P=0,k=Math.random(),uid=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++P+k).toString(36)},T=I("keys"),sharedKey=function(t){return T[t]||(T[t]=uid(t))},L={},N=r.WeakMap;if(A){var R=S.state||(S.state=new N),C=R.get,M=R.has,G=R.set;x=function(t,e){return e.facade=t,G.call(R,t,e),e},_=function(t){return C.call(R,t)||{}},E=function(t){return M.call(R,t)}}else{var D=sharedKey("state");L[D]=!0,x=function(t,e){return e.facade=t,m(t,D,e),e},_=function(t){return has(t,D)?t[D]:{}},E=function(t){return has(t,D)}}var B,U,V={set:x,get:_,has:E,enforce:function(t){return E(t)?_(t):x(t,{})},getterFor:function(t){return function(e){var r;if(!isObject(e)||(r=_(e)).type!==t)thr
2020-09-06 06:32:10 +00:00
/**
2020-09-11 23:27:47 +00:00
* @file ext-connector.js
*
2020-09-08 23:35:47 +00:00
* @license MIT
*
* @copyright 2010 Alexis Deveria
*
Refactor canvas in multiple pieces to increase maintainability (#446) * #refactor-canvas getJsonFromSvgElement and svgroot code moved to separate file * #refactor-canvas build files changes * #refactor-canvas addSVGElementsFromJson move to json file * #refactor-canvas selected element option function move separate file * #refactor-canvas moveUpDownSelected move to select-elem * ##refactor-canvas build file updated * #refactor-canvas moveSelectedElements move to selected-elem * #refactor-canvas cloneSelectedElements move to slected-elem * #refactor-canvas alignSelectedElements move to selected-elem * #refactor-canvas deleteSelectedElements move to selected-elem * #refactor-canvas copySelectedElements and groupSelectedElements move to selected-elem * #refactor-canvas pushGroupProperty, ungroupSelectedElement move to selected-elem * #refactor-canvas comment changes * #refactor-canvas UndoManager move to separate file * #refactor-canvas event file move to mouseMove, mouseUpEvent and dblClickEvent * #refactor-canvas mouseDown move to event * #refactor-canvas move to undo file * #refactor alignment changes and set function revert return * #refactor-canvas textaction move to separate file * #refactor-canvas paste-element function move to separate file * #refactor-canvas set and get method move to separate file * #refactor-canvas set and get function moved changes * #refactor clear file import and regaring function moved changes changes * #refactor-canvas svg related function move to separate file * #refactor-canvas setBackground methos move to elem-get-set file * #refactor-canvas getBsplinePoint method move to event file * #refactor-canvas export functions move to svg-exec * #refactor-canvas svg related function moved separate file * #refactor-canvas updateCanvas, cycleElement move to selected-elem file * #refactor-canvas removeUnusedDefElems move to svg-exec file * #refactor-canvas blur method move to separate file blur-event.js * #refactor-canvas selection related function move to separate file slection.js * #refactor-canvas convertGradients, mousewheelmove event bind function move to other files * #refactor-canvas extension function move to selection file * #refactor-canvas svg tag long string changes to es6 format * eslint fixes * eslint and test fixes * add netlify logo per their requirements * #refactor-canvas path file separate to path-method.js and path-actions.js * #refactor-canvas lint issue fixed * #refactor-canvas path.js file class and const move to path-method.js * #refactor-canvas eslint issue fixed. 'jsdoc/check-examples': 'off' already so removed eslint-disable jsdoc/check-examples * #refactor-canvas path class moved changes and copy-elem.js file cypress test issue fixed * #refactor-canvas UI - Clipboard paste element cypress issue fixed * #refactor-canvas cypress test cases issue fixed changes * #refactor-canvas cypress test cases issue fixed changes * #refactor-canvas cypress test case issue fixed * npm update and fix a few eslint new errors * fix snapshot and run tests * add star tool to cypress * #refactor-canvas shapelibrary, star, polygon and panning tool issue fixed * build * Update layer.js * revert proper declarations Authored-by OptimistikSAS
2020-11-11 10:38:45 +00:00
*/var ai=function(){var t=_asyncToGenerator(regeneratorRuntime.mark((function _callee(t){var e;return regeneratorRuntime.wrap((function _callee$(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,__variableDynamicImportRuntime0__("./locale/".concat(encodeURIComponent(t),".js"));case 3:e=r.sent,r.next=12;break;case 6:return r.prev=6,r.t0=r.catch(0),console.error("Missing translation (".concat(t,") - using 'en'")),r.next=11,Promise.resolve().then((function(){return ci}));case 11:e=r.sent;case 12:return r.abrupt("return",e.default);case 13:case"end":return r.stop()}}),_callee,null,[[0,6]])})));return function loadExtensionTranslation(e){return t.apply(this,arguments)}}(),ci=(t("default",{name:"connector",init:function init(t){var e=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var r,n,o,i,a,c,u,s,f,l,p,h,d,v,y,g,m,b,S,w,x,_,E,O,j,A,I,P,k;return regeneratorRuntime.wrap((function _callee2$(T){for(;;)switch(T.prev=T.next){case 0:return I=function _init(){i(g).find("*").each((function(){var t=this.getAttributeNS(y,"connector");if(t){this.setAttribute("class",s.substr(1));var e=t.split(" "),r=n.getStrokedBBox([o(e[0])]),a=n.getStrokedBBox([o(e[1])]);i(this).data("c_start",e[0]).data("c_end",e[1]).data("start_bb",r).data("end_bb",a),n.getEditorNS(!0)}}))},A=function _updateConnectors(t){if(j(t),b.length)for(var e=b.length;e--;){var r=b[e],o=r.connector,i=r.elem,a=r.is_start?"start":"end",c=n.getStrokedBBox([i]);c.x=r.start_x,c.y=r.start_y,f(o,a+"_bb",c),f(o,a+"_off");var u=r.is_start?"end":"start",s=f(o,u+"_bb"),l=s.x+s.width/2,p=s.y+s.height/2,h=w(l,p,c,x(a,o));E(o,r.is_start?0:"end",h.x,h.y,!0);var d=w(h.x,h.y,f(o,u+"_bb"),x(u,o));if(E(o,r.is_start?"end":0,d.x,d.y,!0),navigator.userAgent.includes("AppleWebKit")){for(var v=o.points,y=v.numberOfItems,g=[],m=0;m<y;m++)h=v.getItem(m),g[m]=h.x+","+h.y;o.setAttribute("points",g.join(" "))}}},j=function _findConnectors(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:S,e=i(g).find(s);b=[],e.each((function(){var e;function add(){t.includes(this)&&(e=!0)}var r=[];["start","end"].forEach((function(t,e){var o=f(this,"c_"+t);null==o?(o=document.getElementById(this.attributes["se:connector"].value.split(" ")[e]),f(this,"c_"+t,o.id),f(this,t+"_bb",n.getStrokedBBox([o]))):o=document.getElementById(o),r.push(o)}),this);for(var o=0;o<2;o++){var a=r[o];if(e=!1,i(a).parents().each(add),a&&a.parentNode){if(t.includes(a)||e){var c=n.getStrokedBBox([a]);b.push({elem:a,connector:this,is_start:0===o,start_x:c.x,start_y:c.y})}}else i(this).remove()}}))},O=function _updateLine(t,e){for(var r=b.length;r--;){var n=b[r],o=n.connector,i=n.is_start?"start":"end",a=f(o,i+"_bb");a.x=n.start_x+t,a.y=n.start_y+e,f(o,i+"_bb",a);var c=n.is_start?"end":"start",u=f(o,c+"_bb"),s=u.x+u.width/2,l=u.y+u.height/2,p=w(s,l,a,x(i,o));E(o,n.is_start?0:"end",p.x,p.y,!0);var h=w(p.x,p.y,f(o,c+"_bb"),x(c,o));E(o,n.is_start?"end":0,h.x,h.y,!0)}},E=function _setPoint(t,e,r,n,o){var i=t.points,c=a.createSVGPoint();c.x=r,c.y=n,"end"===e&&(e=i.numberOfItems-1);try{i.replaceItem(c,e)}catch(o){for(var u=t.getAttribute("points").split(" "),s=0;s<u.length;s++)s===e&&(u[s]=r+","+n);t.setAttribute("points",u.join(" "))}if(o){var f=i.getItem(0),l=i.getItem(i.numberOfItems-1);E(t,1,(l.x+f.x)/2,(l.y+f.y)/2)}},_=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)},x=function _getOffset(t,e){var r=e.getAttribute("marker-"+t),n=5*e.getAttribute("stroke-width");return r?n:0},w=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,c=r.y+r.height/2,u=t-a,s=e-c;return{x:a+u*(o=Math.abs(s/u)<r.height/r.width?r.width/2/Math.abs(u):s?r.height/2/Math.abs(s):0),y:c+s*o}},n=(r=e).canvas,o=n.getElem,i=t.$,a=t.svgroot,c=n.addSVGElementFromJson,u=t.selectorManager,s=".se_connector",f=i.data,g=t.svgcontent,m=!1,b=[],S=[],function(){va