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

11 lines
5.4 KiB
JavaScript

System.register([],(function(e){"use strict";return{execute:function(){function _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,r;function resume(t,r){try{var n=e[t](r),a=n.value,o=a instanceof _AwaitValue;Promise.resolve(o?a.wrapped:a).then((function(e){o?resume("return"===t?"return":"next",e):settle(n.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,n){switch(e){case"return":t.resolve({value:n,done:!0});break;case"throw":t.reject(n);break;default:t.resolve({value:n,done:!1})}(t=t.next)?resume(t.key,t.arg):r=null}this._invoke=function send(e,n){return new Promise((function(a,o){var i={key:e,arg:n,resolve:a,reject:o,next:null};r?r=r.next=i:(t=r=i,resume(e,n))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,r,n,a,o,i){try{var u=e[o](i),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,a)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function _next(e){asyncGeneratorStep(o,n,a,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(o,n,a,_next,_throw,"throw",e)}_next(void 0)}))}}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},_AsyncGenerator.prototype.throw=function(e){return this._invoke("throw",e)},_AsyncGenerator.prototype.return=function(e){return this._invoke("return",e)};
/**
* @file ext-arrows.js
*
* @license MIT
*
* @copyright 2010 Alexis Deveria
*
*/
e("default",{name:"arrows",init:function init(e){var t=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var r,n,a,o,i,u,c,l,s,d,f,m,h,v,_,k,p,w,b;return regeneratorRuntime.wrap((function _callee2$(g){for(;;)switch(g.prev=g.next){case 0:return w=function _colorChanged(t){var r=t.getAttribute("stroke"),a=["start","mid","end"],o=n.findDefs();i.each(a,(function(n,u){var c=h(t,"marker-"+u);if(c){var s=i(c).children().attr("fill"),d=i(c).children().attr("d");if(s!==r){var f=i(o).find("marker"),m=null;if(f.each((function(){var e=i(this).children().attr(["fill","d"]);e.fill===r&&e.d===d&&(m=this)})),!m){var v=c.id.includes("_fw")?"fw":"bk";m=k(v,u,l+v+f.length),i(m).children().attr("fill",r)}i(t).attr("marker-"+u,"url(#"+m.id+")");var _=!0;i(e.svgcontent).find("line, polyline, path, polygon").each((function(){var e=this;if(i.each(a,(function(t,r){if(i(e).attr("marker-"+r)==="url(#"+c.id+")")return _=!1})),!_)return!1})),_&&i(c).remove()}}}))},p=function _setArrow(){_();var e=this.value;if("none"!==e){var t="fw";"mid_bk"===e?(e="mid",t="bk"):"both"===e?(k("bk",e),n.changeSelectedAttribute("marker-start","url(#"+m.bk.id+")"),e="end",t="fw"):"start"===e&&(t="bk"),k(t,e),n.changeSelectedAttribute("marker-"+e,"url(#"+m[t].id+")"),n.call("changed",c)}},k=function _addMarker(e,t,r){r=r||l+e;var o=m[e];"mid"===t&&(o.refx=5);var i=n.getElem(r);if(!i){i=a({element:"marker",attr:{viewBox:"0 0 10 10",id:r,refY:5,markerUnits:"strokeWidth",markerWidth:5,markerHeight:5,orient:"auto",style:"pointer-events:none"}});var u=a({element:"path",attr:{d:o.d,fill:"#000000"}});i.append(u),n.findDefs().append(i)}return i.setAttribute("refX",o.refx),i},_=function _resetMarker(){var e=c[0];e.removeAttribute("marker-start"),e.removeAttribute("marker-mid"),e.removeAttribute("marker-end")},v=function _showPanel(e){if(i("#arrow_panel").toggle(e),e){var t,r=c[0],n=r.getAttribute("marker-end"),a=r.getAttribute("marker-start"),o=r.getAttribute("marker-mid");n&&a?t="both":n?t="end":a?t="start":o&&(t="mid",o.includes("bk")&&(t="mid_bk")),a||o||n||(t="none"),i("#arrow_list").val(t)}},h=function _getLinked(e,t){var r=e.getAttribute(t);if(!r)return null;var a=r.match(/\(#(.*)\)/);return a&&2===a.length?n.getElem(a[1]):null},f=function _unsetArrowNonce(e){s=!1,l=u,m.fw.id=l+"fw",m.bk.id=l+"bk"},d=function _setArrowNonce(e,t){s=!0,l=u+t+"_",m.fw.id=l+"fw",m.bk.id=l+"bk"},g.next=10,e.importLocale();case 10:return r=g.sent,n=t.canvas,a=n.addSVGElementFromJson,o=e.nonce,i=e.$,u="se_arrow_",s=e.randomize_ids,n.bind("setnonce",d),n.bind("unsetnonce",f),m={fw:{d:"m0,0l10,5l-10,5l5,-5l-5,-5z",refx:8,id:(l=s?u+o+"_":u)+"fw"},bk:{d:"m10,0l-10,5l10,5l-5,-5l5,-5z",refx:2,id:l+"bk"}},b=[{type:"select",panel:"arrow_panel",id:"arrow_list",defval:"none",events:{change:p}}],g.abrupt("return",{name:r.name,context_tools:r.contextTools.map((function(e,t){return Object.assign(b[t],e)})),callback:function callback(){i("#arrow_panel").hide(),i("#arrow_list option")[0].id="connector_no_arrow"},addLangData:function addLangData(e){return _asyncToGenerator(regeneratorRuntime.mark((function _callee(){var t,r,n;return regeneratorRuntime.wrap((function _callee$(a){for(;;)switch(a.prev=a.next){case 0:return e.lang,t=e.importLocale,a.next=3,t();case 3:return r=a.sent,n=r.langList,a.abrupt("return",{data:n});case 6:case"end":return a.stop()}}),_callee)})))()},selectedChanged:function selectedChanged(e){for(var t=["line","path","polyline","polygon"],r=(c=e.elems).length;r--;){var n=c[r];n&&t.includes(n.tagName)&&e.selectedElement&&!e.multiselected?v(!0):v(!1)}},elementChanged:function elementChanged(e){var t=e.elems[0];t&&(t.getAttribute("marker-start")||t.getAttribute("marker-mid")||t.getAttribute("marker-end"))&&w(t)}});case 21:case"end":return g.stop()}}),_callee2)})))()}})}}}));