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

3 lines
4.5 KiB
JavaScript

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