svgedit/dist/editor/extensions/ext-markers.js

34 lines
10 KiB
JavaScript
Raw Normal View History

2020-09-04 20:34:30 +00:00
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,i=a instanceof _AwaitValue;Promise.resolve(i?a.wrapped:a).then((function(e){i?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,i){var o={key:e,arg:n,resolve:a,reject:i,next:null};r?r=r.next=o:(t=r=o,resume(e,n))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,r,n,a,i,o){try{var s=e[i](o),l=s.value}catch(e){return void r(e)}s.done?t(l):Promise.resolve(l).then(n,a)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function _next(e){asyncGeneratorStep(i,n,a,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(i,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-markers.js
*
* @license Apache-2.0
*
* @copyright 2010 Will Schleter based on ext-arrows.js by Copyright(c) 2010 Alexis Deveria
*
* This extension provides for the addition of markers to the either end
* or the middle of a line, polyline, path, polygon.
*
* Markers may be either a graphic or arbitary text
*
* to simplify the coding and make the implementation as robust as possible,
* markers are not shared - every object has its own set of markers.
* this relationship is maintained by a naming convention between the
* ids of the markers and the ids of the object
*
* The following restrictions exist for simplicty of use and programming
* objects and their markers to have the same color
* marker size is fixed
* text marker font, size, and attributes are fixed
* an application specific attribute - se_type - is added to each marker element
* to store the type of marker
*
* @todo
* remove some of the restrictions above
* add option for keeping text aligned to horizontal
* add support for dimension extension lines
*
*/
2020-09-04 20:34:30 +00:00
var e={name:"markers",init:function init(e){var t=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee3(){var r,n,a,i,o,s,l,u,c,m,d,h,f,p,_,k,v,g,b,y,x,w,A,L,C,S;return regeneratorRuntime.wrap((function _callee3$(G){for(;;)switch(G.prev=G.next){case 0:return C=function _buildButtonList(){var e=[];return a.each(s,(function(t,r){var n=r+"_marker_list",a=!0;Object.keys(c).forEach((function(t){var i=L(String(t));e.push({id:u+r+"_"+t,svgicon:t,icon:"markers-"+t+".png",title:i,type:"context",events:{click:w},panel:"marker_panel",list:n,isDefault:a}),a=!1}))})),e},L=function _getTitle(e){var t=r.langList.find((function(t){return t.id===e}));return t?t.title:e},A=function _setArrowFromButton3(){return(A=_asyncToGenerator(regeneratorRuntime.mark((function _callee2(e){var t,r,n;return regeneratorRuntime.wrap((function _callee2$(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.id.split("_"),r=t[1],n=t[2],t[3]&&(n+="_"+t[3]),"textmarker"===n){e.next=8;break}b(r,"\\"+n),e.next=10;break;case 8:return e.next=10,y(r);case 10:case"end":return e.stop()}}),_callee2,this)})))).apply(this,arguments)},w=function _setArrowFromButton2(e){return A.apply(this,arguments)},x=function _showTextPrompt3(){return(x=_asyncToGenerator(regeneratorRuntime.mark((function _callee(e){var t,r;return regeneratorRuntime.wrap((function _callee$(n){for(;;)switch(n.prev=n.next){case 0:return"\\"===(t=a("#"+e+"_marker").val()).substr(0,1)&&(t=""),n.next=4,a.prompt("Enter text for "+e+" marker",t);case 4:(r=n.sent)&&b(e,r);case 6:case"end":return n.stop()}}),_callee)})))).apply(this,arguments)},y=function _showTextPrompt2(e){return x.apply(this,arguments)},b=function _triggerTextEntry(e,t){a("#"+e+"_marker").val(t),a("#"+e+"_marker").change()},g=function _updateReferences(e){a.each(s,(function(t,r){var n=l+r+"_"+e.id,o="marker-"+r,s=m(e,o);if(s&&s.attributes.se_type){var u=e.getAttribute(o);if(u){var c=e.id.length,d=u.substr(-c-1,c);if(e.id!==d){var f=a("#"+r+"_marker").attr("value");p(n,f),i.changeSelectedAttribute(o,"url(#"+n+")"),"line"===e.tagName&&"mid"===r&&(e=_(e)),i.call("changed",h)}}}}))},v=function _colorChanged(e){var t=e.getAttribute("stroke");a.each(s,(function(r,n){var a=m(e,"marker-"+n);if(a&&a.attributes.se_type){var i=a.lastElementChild;if(i){var o=i.getAttribute("fill"),s=i.getAttribute("stroke");o&&"none"!==o&&i.setAttribute("fill",t),s&&"none"!==s&&i.setAttribute("stroke",t)}}}))},k=function _setMarker(){var e={start_marker:"start",mid_marker:"mid",end_marker:"end"}[this.id],t="marker-"+e,r=h[0],n=m(r,t);n&&a(n).remove(),r.removeAttribute(t);var o=this.value;if(""===o&&(o="\\nomarker"),"\\nomarker"===o)return d(e,o),void i.call("changed",h);var s=l+e+"_"+r.id;p(s,o),i.changeSelectedAttribute(t,"url(#"+s+")"),"line"===r.tagName&&"mid"===e&&_(r),i.call("changed",h),d(e,o)},_=function _convertline(t){if("line"!==t.tagName)return t;var r=Number(t.getAttribute("x1")),n=Number(t.getAttribute("x2")),l=Number(t.getAttribute("y1")),u=Number(t.getAttribute("y2")),c=t.id,m=o({element:"polyline",attr:{points:r+","+l+(" "+(r+n)/2+","+(l+u)/2+" ")+n+","+u,stroke:t.getAttribute("stroke"),"stroke-width":t.getAttribute("stroke-width"),fill:"none",opacity:t.getAttribute("opacity")||1}});a.each(s,(function(e,r){var n="marker-"+r;t.getAttribute(n)&&m.setAttribute(n,t.getAttribute(n))}));var d=new e.BatchCommand;return d.addSubCommand(new e.RemoveElementCommand(t,t.parentNode)),d.addSubCommand(new e.InsertElementCommand(m)),a(t).after(m).remove(),i.clearSelection(),m.id=c,i.addToSelection([m]),e.addCommandToHistory(d),m},p=function _addMarker(e,t){var r=i.getElem(e);if(!r&&""!==t&&"\\nomarker"!==t){var n,a=h[0].getAttribute("stroke"),s=50,l=50,u="0 0 100 100",m=5,d=5;if(n="\\"===t.substr(0,1)?t.substr(1):"textmarker",c[n]){if(r=o({element:"marker",attr:{id:e,markerUnits:"strokeWidth",orient:"auto",style:"pointer-events:none",se_type:n}}),"textmarker"!==n){var f=o(c[n]),p="_o"===n.substr(-2)?"none":a;f.setAttribute("fill",p),f.setAttribute("stroke",a),f.setAttribute("stroke-width",10),r.append(f)}else{var _=o(c[n]);_.textContent=t;var k=_.getBBox()
2020-08-28 22:07:07 +00:00
//# sourceMappingURL=ext-markers.js.map