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

32 lines
59 KiB
JavaScript
Raw Normal View History

2020-09-11 23:27:47 +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")(),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,l=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 l(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")},s={}.hasOwnProperty,has=function(t,e){return s.call(t,e)},f=r.document,p=isObject(f)&&isObject(f.createElement),documentCreateElement=function(t){return p?f.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__",w=r[b]||setGlobal(b,{}),x=Function.toString;"function"!=typeof w.inspectSource&&(w.inspectSource=function(t){return x.call(t)});var S,_,k,E=w.inspectSource,O=r.WeakMap,A="function"==typeof O&&/native code/.test(E(O)),j=createCommonjsModule((function(t){(t.exports=function(t,e){return w[t]||(w[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),P=0,L=Math.random(),uid=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++P+L).toString(36)},I=j("keys"),sharedKey=function(t){return I[t]||(I[t]=uid(t))},T={},R=r.WeakMap;if(A){var C=new R,N=C.get,M=C.has,G=C.set;S=function(t,e){return G.call(C,t,e),e},_=function(t){return N.call(C,t)||{}},k=function(t){return M.call(C,t)}}else{var D=sharedKey("state");T[D]=!0,S=function(t,e){return m(t,D,e),e},_=function(t){return has(t,D)?t[D]:{}},k=function(t){return has(t,D)}}var B,U={set:S,get:_,has:k,enforce:function(t){return k(t)?_(t):S(t,{})},getterFor:function(t){return function(e){var r;if(!isObject(e)||(r=_(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return r}}},V=cr
2020-09-06 06:32:10 +00:00
/**
2020-09-11 23:27:47 +00:00
* @file ext-markers.js
2020-09-08 23:35:47 +00:00
*
2020-09-11 23:27:47 +00:00
* @license Apache-2.0
2020-09-08 23:35:47 +00:00
*
2020-09-11 23:27:47 +00:00
* @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
*
*/var ti=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(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 ei}));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)}}(),ei=(t("default",{name:"markers",init:function init(t){var e=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee4(){var r,n,o,i,a,c,u,l,s,f,p,h,d,v,y,g,m,b,w,x,S,_,k,E,O,A;return regeneratorRuntime.wrap((function _callee4$(j){for(;;)switch(j.prev=j.next){case 0:return O=function _buildButtonList(){var t=[];return o.each(c,(function(e,r){var n=r+"_marker_list",o=!0;Object.keys(s).forEach((function(e){var i=E(String(e));t.push({id:l+r+"_"+e,svgicon:e,icon:"markers-"+e+".png",title:i,type:"context",events:{click:_},panel:"marker_panel",list:n,isDefault:o}),o=!1}))})),t},E=function _getTitle(t){var e=n.langList.find((function(e){return e.id===t}));return e?e.title:t},k=function _setArrowFromButton3(){return(k=_asyncToGenerator(regeneratorRuntime.mark((function _callee3(t){var e,r,n;return regeneratorRuntime.wrap((function _callee3$(t){for(;;)switch(t.prev=t.next){case 0:if(e=this.id.split("_"),r=e[1],n=e[2],e[3]&&(n+="_"+e[3]),"textmarker"===n){t.next=8;break}w(r,"\\"+n),t.next=10;break;case 8:return t.next=10,x(r);case 10:case"end":return t.stop()}}),_callee3,this)})))).apply(this,arguments)},_=function _setArrowFromButton2(t){return k.apply(this,arguments)},S=function _showTextPrompt3(){return(S=_asyncToGenerator(regeneratorRuntime.mark((function _callee2(t){var e,r;return regeneratorRuntime.wrap((function _callee2$(n){for(;;)switch(n.prev=n.next){case 0:return"\\"===(e=o("#"+t+"_marker").val()).substr(0,1)&&(e=""),n.next=4,o.prompt("Enter text for "+t+" marker",e);case 4:(r=n.sent)&&w(t,r);case 6:case"end":return n.stop()}}),_callee2)})))).apply(this,arguments)},x=function _showTextPrompt2(t){return S.apply(this,arguments)},w=function _triggerTextEntry(t,e){o("#"+t+"_marker").val(e),o("#"+t+"_marker").change()},b=function _updateReferences(t){o.each(c,(function(e,r){var n=u+r+"_"+t.id,a="marker-"+r,c=f(t,a);if(c&&c.attributes.se_type){var l=t.getAttribute(a);if(l){var s=t.id.length,p=l.substr(-s-1,s);if(t.id!==p){var d=o("#"+r+"_marker").attr("value");v(n,d),i.changeSelectedAttribute(a,"url(#"+n+")"),"line"===t.tagName&&"mid"===r&&(t=y(t)),i.call("changed",h)}}}}))},m=function _colorChanged(t){var e=t.getAttribute("stroke");o.each(c,(function(r,n){var o=f(t,"marker-"+n);if(o&&o.attributes.se_type){var i=o.lastElementChild;if(i){var a=i.getAttribute("fill"),c=i.getAttribute("stroke");a&&"none"!==a&&i.setAttribute("fill",e),c&&"none"!==c&&i.setAttribute("stroke",e)}}}))},g=function _setMarker(){var t={start_marker:"start",mid_marker:"mid",end_marker:"end"}[this.id],e="marker-"+t,r=h[0],n=f(r,e);n&&o(n).remove(),r.removeAttribute(e);var a=this.value;if(""===a&&(a="\\nomarker"),"\\nomarker"===a)return p(t,a),void i.call("changed",h);var c=u+t+"_"+r.id;v(c,a),i.changeSelectedAttribute(e,"url(#"+c+")"),"line"===r.tagName&&"mid"===t&&y(r),i.call("changed",h),p(t,a)},y=function _convertline(e){if("line"!==e.tagName)return e;var r=Number(e.getAttribute("x1")),n=Number(e.getAttribute("x2")),u=Number(e.getAttribute("y1")),l=Number(e.getAttribute("y2")),s=e.id,f=a({element:"polyline",attr:{points:r+","+u+(" "+(r+n)/2+","+(u+l)/2+" ")+n+","+l,stroke:e.getAttribute("stroke"),"stroke-width":e.getAttribute("stroke-width"),fill:"none",opacity:e.getAttribute("opacity")||1}});o.each(c,(function(t,r){var n="marker-"+r;e.getAttribute(n)&&f.setAttribute(n,e.getAttribute(n))}));var p=new t.BatchCommand;return p.addSubCommand(new t.RemoveElementCommand(e,e.parentNod