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

3 lines
4.3 KiB
JavaScript

function _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,n;function resume(t,n){try{var o=e[t](n),r=o.value,a=r instanceof _AwaitValue;Promise.resolve(a?r.wrapped:r).then((function(e){a?resume("return"===t?"return":"next",e):settle(o.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,o){switch(e){case"return":t.resolve({value:o,done:!0});break;case"throw":t.reject(o);break;default:t.resolve({value:o,done:!1})}(t=t.next)?resume(t.key,t.arg):n=null}this._invoke=function send(e,o){return new Promise((function(r,a){var s={key:e,arg:o,resolve:r,reject:a,next:null};n?n=n.next=s:(t=n=s,resume(e,o))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,n,o,r,a,s){try{var i=e[a](s),c=i.value}catch(e){return void n(e)}i.done?t(c):Promise.resolve(c).then(o,r)}"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)};var e={name:"polygon",init:function init(e){var t=this;return function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise((function(o,r){var a=e.apply(t,n);function _next(e){asyncGeneratorStep(a,o,r,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(a,o,r,_next,_throw,"throw",e)}_next(void 0)}))}}(regeneratorRuntime.mark((function _callee(){var n,o,r,a,s,i,c,l,u,d,p,f,h;return regeneratorRuntime.wrap((function _callee$(y){for(;;)switch(y.prev=y.next){case 0:return p=function _sec(e){return 1/Math.cos(e)},d=function _cot(e){return 1/Math.tan(e)},u=function _setAttr(e,t){n.changeSelectedAttribute(e,t),n.call("changed",s)},l=function _showPanel(e){var t=o("#fc_rules");t.length||(t=o('<style id="fc_rules"></style>').appendTo("head")),t.text(e?" #tool_topath { display: none !important; }":""),o("#polygon_panel").toggle(e)},n=t.canvas,o=e.$,r=e.importLocale,!1,y.next=9,r();case 9:return a=y.sent,f=[{id:"tool_polygon",icon:"polygon.png",type:"mode",position:11,events:{click:function click(){n.setMode("polygon"),l(!0)}}}],h=[{type:"input",panel:"polygon_panel",id:"polySides",size:3,defval:5,events:{change:function change(){u("sides",this.value)}}}],y.abrupt("return",{name:a.name,svgicons:"polygon-icons.svg",buttons:a.buttons.map((function(e,t){return Object.assign(f[t],e)})),context_tools:a.contextTools.map((function(e,t){return Object.assign(h[t],e)})),callback:function callback(){o("#polygon_panel").hide();setTimeout((function(){o("#tool_source_save").clone().hide().attr("id","polygon_save").unbind().appendTo("#tool_source_back").click((function(){})),o("#tool_source_cancel").clone().hide().attr("id","polygon_cancel").unbind().appendTo("#tool_source_back").click((function(){}))}),3e3)},mouseDown:function mouseDown(e){if("polygon"===n.getMode()){var t=n.getColor("fill"),o=n.getColor("stroke"),r=n.getStrokeWidth();return i=!0,c=n.addSVGElementFromJson({element:"polygon",attr:{cx:e.start_x,cy:e.start_y,id:n.getNextId(),shape:"regularPoly",sides:document.getElementById("polySides").value,orient:"x",edge:0,fill:t,strokecolor:o,strokeWidth:r}}),{started:!0}}},mouseMove:function mouseMove(e){if(i&&"polygon"===n.getMode()){var t=o(c).attr(["cx","cy","sides","orient","fill","strokecolor","strokeWidth"]),r=e.mouse_x,a=e.mouse_y,s=t.cx,l=t.cy,u=t.fill,f=t.strokecolor,h=t.strokeWidth,y=t.sides,g=Math.sqrt((r-s)*(r-s)+(a-l)*(a-l))/1.5;c.setAttribute("edge",g);for(var _=g/2*d(Math.PI/y)*p(Math.PI/y),v="",m=0;y>=m;m++){var k=2*Math.PI*m/y;v+=(r=_*Math.cos(k)+s)+","+(a=_*Math.sin(k)+l)+" "}return c.setAttribute("points",v),c.setAttribute("fill",u),c.setAttribute("stroke",f),c.setAttribute("stroke-width",h),{started:!0}}},mouseUp:function mouseUp(e){if("polygon"===n.getMode())return{keep:"0"!==o(c).attr("edge").edge,element:c}},selectedChanged:function selectedChanged(e){for(var t=(s=e.elems).length;t--;){var n=s[t];n&&"regularPoly"===n.getAttribute("shape")&&e.selectedElement&&!e.multiselected?(o("#polySides").val(n.getAttribute("sides")),l(!0)):l(!1)}},elementChanged:function elementChanged(e){}});case 13:case"end":return y.stop()}}),_callee)})))()}};export default e;
//# sourceMappingURL=ext-polygon.js.map