3 lines
8.7 KiB
JavaScript
3 lines
8.7 KiB
JavaScript
function asyncGeneratorStep(t,e,r,n,a,i,l){try{var o=t[i](l),s=o.value}catch(t){return void r(t)}o.done?e(s):Promise.resolve(s).then(n,a)}function _slicedToArray(t,e){return function _arrayWithHoles(t){if(Array.isArray(t))return t}(t)||function _iterableToArrayLimit(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,a=!1,i=void 0;try{for(var l,o=t[Symbol.iterator]();!(n=(l=o.next()).done)&&(r.push(l.value),!e||r.length!==e);n=!0);}catch(t){a=!0,i=t}finally{try{n||null==o.return||o.return()}finally{if(a)throw i}}return r}(t,e)||function _unsupportedIterableToArray(t,e){if(!t)return;if("string"==typeof t)return _arrayLikeToArray(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _arrayLikeToArray(t,e)}(t,e)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var t={name:"placemark",init:function init(t){var e=this;return function _asyncToGenerator(t){return function(){var e=this,r=arguments;return new Promise((function(n,a){var i=t.apply(e,r);function _next(t){asyncGeneratorStep(i,n,a,_next,_throw,"next",t)}function _throw(t){asyncGeneratorStep(i,n,a,_next,_throw,"throw",t)}_next(void 0)}))}}(regeneratorRuntime.mark((function _callee(){var r,n,a,i,l,o,s,c,u,m,p,f,d,h,k,_,y,v,g,b,x,A,w;return regeneratorRuntime.wrap((function _callee$(L){for(;;)switch(L.prev=L.next){case 0:return x=function _addMarkerButtons(t){return Object.keys(m).forEach((function(e){var r=b(String(e));t.push({id:"placemark_marker_"+e,svgicon:e,icon:"markers-"+e+".png",title:r,type:"context",events:{click:g},panel:"placemark_panel",list:"placemark_marker",isDefault:"leftarrow"===e})})),t},b=function _getTitle(t){var e=u.langList.find((function(e){return e.id===t}));return e?e.title:t},g=function _setArrowFromButton(t){var e=this.id.split("_"),r=e[2];e[3]&&(r+="_"+e[3]),i("#placemark_marker").attr("value",r)},v=function _updateReferences(t){var e="placemark_marker_"+t.id,r="marker-start",a=f(t,r);if(a&&a.attributes.class){var o=t.getAttribute(r);if(o){var s=t.id.length,c=o.substr(-s-1,s);if(t.id!==c){var u=i("#placemark_marker").attr("value")||"leftarrow";k(e,u),n.changeSelectedAttribute(r,"url(#"+e+")"),n.call("changed",l)}}}},y=function _colorChanged(t){var e=t.getAttribute("stroke"),r=f(t,"marker-start");if(r&&r.attributes.class){var n=r.lastElementChild;if(n){var a=n.getAttribute("fill"),i=n.getAttribute("stroke");a&&"none"!==a&&n.setAttribute("fill",e),i&&"none"!==i&&n.setAttribute("stroke",e)}}},_=function _setMarker(t,e){var r="marker-start",a=f(t,r);if(a&&i(a).remove(),t.removeAttribute(r),"nomarker"!==e){var l="placemark_marker_"+t.id;k(l,e),t.setAttribute(r,"url(#"+l+")"),n.call("changed",[t])}else n.call("changed",[t])},k=function _addMarker(t,e){var r=n.getElem(t);if(!r&&""!==e&&"nomarker"!==e){var i=n.getColor("stroke"),l=50,o=e;if(m[o]){o.includes("left")&&(l=0),o.includes("right")&&(l=100),r=a({element:"marker",attr:{id:t,markerUnits:"strokeWidth",orient:"auto",style:"pointer-events:none",class:o}});var s=a(m[o]),c="_o"===o.substr(-2)?"none":i;return s.setAttribute("fill",c),s.setAttribute("stroke",i),s.setAttribute("stroke-width",10),r.append(s),r.setAttribute("viewBox","0 0 100 100"),r.setAttribute("markerWidth",10),r.setAttribute("markerHeight",10),r.setAttribute("refX",l),r.setAttribute("refY",50),n.findDefs().append(r),r}}},h=function _updateFont(t){t=t.split(" ");var e=Number.parseInt(t.pop());t=t.join(" "),l.forEach((function(r){r&&r.getAttribute("class").includes("placemark")&&i(r).children().each((function(r,n){"txt"===_slicedToArray(n.id.split("_"),3)[2]&&i(n).attr({"font-family":t,"font-size":e})}))}))},d=function _updateText(t){var e=t.split(";");l.forEach((function(t){t&&t.getAttribute("class").includes("placemark")&&i(t).children().each((function(t,r){var n=_slicedToArray(r.id.split("_"),4),a=n[2],l=n[3];"txt"===a&&i(r).text(e[l])}))}))},f=function _getLinked(t,e){if(!t)return null;var r=t.getAttribute(e);if(!r)return null;var a=r.match(/\(#(.*)\)/);return a&&2===a.length?n.getElem(a[1]):null},p=function _showPanel(t){i("#placemark_panel").toggle(t)},n=(r=e).canvas,a=n.addSVGElementFromJson,i=t.$,L.next=17,import("./locale/".concat(r.curPrefs.lang,".js"));case 17:return c=L.sent,u=c.default,m={nomarker:{},forwardslash:{element:"path",attr:{d:"M30,100 L70,0"}},reverseslash:{element:"path",attr:{d:"M30,0 L70,100"}},verticalslash:{element:"path",attr:{d:"M50,0 L50,100"}},xmark:{element:"path",attr:{d:"M20,80 L80,20 M80,80 L20,20"}},leftarrow:{element:"path",attr:{d:"M0,50 L100,90 L70,50 L100,10 Z"}},rightarrow:{element:"path",attr:{d:"M100,50 L0,90 L30,50 L0,10 Z"}},box:{element:"path",attr:{d:"M20,20 L20,80 L80,80 L80,20 Z"}},star:{element:"path",attr:{d:"M10,30 L90,30 L20,90 L50,10 L80,90 Z"}},mcircle:{element:"circle",attr:{r:30,cx:50,cy:50}},triangle:{element:"path",attr:{d:"M10,80 L50,20 L80,80 Z"}}},["leftarrow","rightarrow","box","star","mcircle","triangle"].forEach((function(t){m[t+"_o"]=m[t]})),A=[{id:"tool_placemark",icon:"placemark.png",type:"mode",position:12,events:{click:function click(){p(!0),n.setMode("placemark")}}}],w=[{type:"button-select",panel:"placemark_panel",id:"placemark_marker",colnum:3,events:{change:g}},{type:"input",panel:"placemark_panel",id:"placemarkText",size:20,defval:"",events:{change:function change(){d(this.value)}}},{type:"input",panel:"placemark_panel",id:"placemarkFont",size:7,defval:"Arial 10",events:{change:function change(){h(this.value)}}}],L.abrupt("return",{name:u.name,svgicons:"placemark-icons.xml",buttons:x(u.buttons.map((function(t,e){return Object.assign(A[e],t)}))),context_tools:u.contextTools.map((function(t,e){return Object.assign(w[e],t)})),callback:function callback(){i("#placemark_panel").hide()},mouseDown:function mouseDown(t){var e=n.getColor("stroke"),r=n.getStrokeWidth();if("placemark"===n.getMode()){o=!0;var a=n.getNextId(),l=i("#placemarkText").val().split(";"),c=i("#placemarkFont").val().split(" "),u=Number.parseInt(c.pop());c=c.join(" ");var m=t.start_x+10,p=t.start_y+10,f=0,d=[{element:"line",attr:{id:a+"_pline_0",fill:"none",stroke:e,"stroke-width":r,"stroke-linecap":"round",x1:t.start_x,y1:t.start_y,x2:m,y2:p}}];return l.forEach((function(t,n){f=Math.max(f,t.length),d.push({element:"line",attr:{id:a+"_tline_"+n,fill:"none",stroke:e,"stroke-width":r,"stroke-linecap":"round",x1:m,y1:p+(u+6)*n,x2:m+t.length*u*.5+u,y2:p+(u+6)*n}}),d.push({element:"text",attr:{id:a+"_txt_"+n,fill:e,stroke:"none","stroke-width":0,x:m+3,y:p-3+(u+6)*n,"font-family":c,"font-size":u,"text-anchor":"start"},children:[t]})})),l.length>0&&d.push({element:"line",attr:{id:a+"_vline_0",fill:"none",stroke:e,"stroke-width":r,"stroke-linecap":"round",x1:m,y1:p,x2:m,y2:p+(u+6)*(l.length-1)}}),s=n.addSVGElementFromJson({element:"g",attr:{id:a,class:"placemark",fontSize:u,maxlen:f,lines:l.length,x:t.start_x,y:t.start_y,px:t.start_x,py:t.start_y},children:d}),_(s.firstElementChild,i("#placemark_marker").attr("value")||"leftarrow"),{started:!0}}},mouseMove:function mouseMove(t){if(o&&"placemark"===n.getMode()){var e=t.mouse_x/n.getZoom(),r=t.mouse_y/n.getZoom(),a=i(s).attr(["fontSize","maxlen","lines","px","py"]),l=a.fontSize,c=a.maxlen,u=a.lines,m=a.px,p=a.py;return i(s).attr({x:e,y:r}),i(s).children().each((function(t,n){var a=_slicedToArray(n.id.split("_"),4),i=a[2],o=a[3],s=r+(l+6)*o,f=e+c*l*.5+l,d=e+(f-e)/2<m?f:e,h=r+(l+6)*(u-1)/2<p?r+(l+6)*(u-1):r;"pline"===i&&(n.setAttribute("x2",d),n.setAttribute("y2",h)),"tline"===i&&(n.setAttribute("x1",e),n.setAttribute("y1",s),n.setAttribute("x2",f),n.setAttribute("y2",s)),"vline"===i&&(n.setAttribute("x1",d),n.setAttribute("y1",r),n.setAttribute("x2",d),n.setAttribute("y2",r+(l+6)*(u-1))),"txt"===i&&(n.setAttribute("x",e+l/2),n.setAttribute("y",s-3))})),{started:!0}}},mouseUp:function mouseUp(){if("placemark"===n.getMode()){var t=i(s).attr(["x","y","px","py"]),e=t.x,r=t.y,a=t.px,l=t.py;return{keep:e!=a&&r!=l,element:s}}},selectedChanged:function selectedChanged(t){(l=t.elems).forEach((function(t){if(t&&t.getAttribute("class").includes("placemark")){var e=[];i(t).children().each((function(t,r){"txt"===_slicedToArray(r.id.split("_"),3)[2]&&(i("#placemarkFont").val(r.getAttribute("font-family")+" "+r.getAttribute("font-size")),e.push(i(r).text()))})),i("#placemarkText").val(e.join(";")),p(!0)}else p(!1)}))},elementChanged:function elementChanged(t){t.elems.forEach((function(t){t.id.includes("pline_0")&&(y(t),v(t))}))}});case 24:case"end":return L.stop()}}),_callee)})))()}};export default t;
|
|
//# sourceMappingURL=ext-placemark.js.map
|