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

32 lines
58 KiB
JavaScript
Raw Normal View History

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={},C=r.WeakMap;if(A){var R=new C,N=R.get,M=R.has,G=R.set;S=function(t,e){return G.call(R,t,e),e},_=function(t){return N.call(R,t)||{}},k=function(t){return M.call(R,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-08 23:35:47 +00:00
* @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
*
*/t("default",{name:"markers",init:function init(t){var e=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee3(){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,j;return regeneratorRuntime.wrap((function _callee3$(P){for(;;)switch(P.prev=P.next){case 0:return A=function _buildButtonList(){var t=[];return i.each(u,(function(e,r){var n=r+"_marker_list",o=!0;Object.keys(f).forEach((function(e){var i=O(String(e));t.push({id:s+r+"_"+e,svgicon:e,icon:"markers-"+e+".png",title:i,type:"context",events:{click:k},panel:"marker_panel",list:n,isDefault:o}),o=!1}))})),t},O=function _getTitle(t){var e=o.langList.find((function(e){return e.id===t}));return e?e.title:t},E=function _setArrowFromButton3(){return(E=_asyncToGenerator(regeneratorRuntime.mark((function _callee2(t){var e,r,n;return regeneratorRuntime.wrap((function _callee2$(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}x(r,"\\"+n),t.next=10;break;case 8:return t.next=10,S(r);case 10:case"end":return t.stop()}}),_callee2,this)})))).apply(this,arguments)},k=function _setArrowFromButton2(t){return E.apply(this,arguments)},_=function _showTextPrompt3(){return(_=_asyncToGenerator(regeneratorRuntime.mark((function _callee(t){var e,r;return regeneratorRuntime.wrap((function _callee$(n){for(;;)switch(n.prev=n.next){case 0:return"\\"===(e=i("#"+t+"_marker").val()).substr(0,1)&&(e=""),n.next=4,i.prompt("Enter text for "+t+" marker",e);case 4:(r=n.sent)&&x(t,r);case 6:case"end":return n.stop()}}),_callee)})))).apply(this,arguments)},S=function _showTextPrompt2(t){return _.apply(this,arguments)},x=function _triggerTextEntry(t,e){i("#"+t+"_marker").val(e),i("#"+t+"_marker").change()},w=function _updateReferences(t){i.each(u,(function(e,r){var n=l+r+"_"+t.id,o="marker-"+r,c=p(t,o);if(c&&c.attributes.se_type){var u=t.getAttribute(o);if(u){var s=t.id.length,f=u.substr(-s-1,s);if(t.id!==f){var h=i("#"+r+"_marker").attr("value");y(n,h),a.changeSelectedAttribute(o,"url(#"+n+")"),"line"===t.tagName&&"mid"===r&&(t=g(t)),a.call("changed",d)}}}}))},b=function _colorChanged(t){var e=t.getAttribute("stroke");i.each(u,(function(r,n){var o=p(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)}}}))},m=function _setMarker(){var t={start_marker:"start",mid_marker:"mid",end_marker:"end"}[this.id],e="marker-"+t,r=d[0],n=p(r,e);n&&i(n).remove(),r.removeAttribute(e);var o=this.value;if(""===o&&(o="\\nomarker"),"\\nomarker"===o)return h(t,o),void a.call("changed",d);var c=l+t+"_"+r.id;y(c,o),a.changeSelectedAttribute(e,"url(#"+c+")"),"line"===r.tagName&&"mid"===t&&g(r),a.call("changed",d),h(t,o)},g=function _convertline(e){if("line"!==e.tagName)return e;var r=Number(e.getAttribute("x1")),n=Number(e.getAttribute("x2")),o=Number(e.getAttribute("y1")),l=Number(e.getAttribute("y2")),s=e.id,f=c({element:"polyline",attr:{points:r+","+o+(" "+(r+n)/2+","+(o+l)/2+" ")+n+","+l,stroke:e.getAttribute("stroke"),"stroke-width":e.getAttribute("stroke-width"),fill:"none",opacity:e.getAttribute("opacity")||1}});i.each(u,(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.parentNode)),p.addSubCommand(new t.InsertElementCommand(f)),i(e).after(f).remove(),a.clearSelection(),f.id=s,a.addToSelection([f]),t.addCommandToHistory(p),f},y=function _addMarker(t,e){var r=a.getElem(t);if(!r&&""!==e&&"\\nomarker"!==e){var n,o=d[0].getAttribute("stroke"),i=50,u=50,l="0 0 100 100",s=5,p=5;if(n="\\"===e.substr(0,1)?e.substr(1):"textmarker",f[n]){if(r=c({element:"marker",attr:{id:t,markerUnits:"strokeWidth",orient:"auto",style:"pointer-events:none",se_type:n}}),"textmarker"!==n){var h=c(f[n]),v="_o"===n.substr(-2)?"none":o;h.setAttribute("fill",v),h.setAttribute("stroke",o),h.setAttribute("stroke-width",10),r.append(h)}else{var y=c(f[n]);y.textContent=e;var