3 lines
3.5 KiB
JavaScript
3 lines
3.5 KiB
JavaScript
|
function asyncGeneratorStep(t,e,n,a,r,o,i){try{var s=t[o](i),l=s.value}catch(t){return void n(t)}s.done?e(l):Promise.resolve(l).then(a,r)}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(a,r){var o=t.apply(e,n);function _next(t){asyncGeneratorStep(o,a,r,_next,_throw,"next",t)}function _throw(t){asyncGeneratorStep(o,a,r,_next,_throw,"throw",t)}_next(void 0)}))}}(regeneratorRuntime.mark((function _callee(){var n,a,r,o,i,s,l,u,c,d,h,p;return regeneratorRuntime.wrap((function _callee$(f){for(;;)switch(f.prev=f.next){case 0:return d=function _setAttr(t,e){a.changeSelectedAttribute(t,e),a.call("changed",o)},c=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)},a=(n=e).canvas,r=t.$,f.next=7,import("./locale/".concat(n.curPrefs.lang,".js"));case 7:return l=f.sent,u=l.default,h=[{id:"tool_star",icon:"star.png",type:"mode",position:12,events:{click:function click(){c(!0),a.setMode("star")}}}],p=[{type:"input",panel:"star_panel",id:"starNumPoints",size:3,defval:5,events:{change:function change(){d("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(){d("radialshift",this.value)}}}],f.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(p[e],t)})),callback:function callback(){r("#star_panel").hide()},mouseDown:function mouseDown(t){var e=a.getColor("fill"),n=a.getColor("stroke"),r=a.getStrokeWidth();if("star"===a.getMode())return i=!0,s=a.addSVGElementFromJson({element:"polygon",attr:{cx:t.start_x,cy:t.start_y,id:a.getNextId(),shape:"star",point:document.getElementById("starNumPoints").value,r:0,radialshift:document.getElementById("radialShift").value,r2:0,orient:"point",fill:e,strokecolor:n,strokeWidth:r}}),{started:!0}},mouseMove:function mouseMove(t){if(i&&"star"===a.getMode()){var e=r(s).attr(["cx","cy","point","orient","fill","strokecolor","strokeWidth","radialshift"]),n=t.mouse_x,o=t.mouse_y,l=e.cx,u=e.cy,c=e.fill,d=e.strokecolor,h=e.strokeWidth,p=e.radialshift,f=e.point,g=e.orient,m=Math.sqrt((n-l)*(n-l)+(o-u)*(o-u))/1.5,v=m/document.getElementById("starRadiusMulitplier").value;s.setAttribute("r",m),s.setAttribute("r2",v);for(var _="",y=0;f>=y;y++){var M=2*Math.PI*(y/f);"point"===g?M-=Math.PI/2:"edge"===g&&(M=M+Math.PI/f-Math.PI/2),_+=(n=m*Math.cos(M)+l)+","+(o=m*Math.sin(M)+u)+" ",isNaN(v)||(M=2*Math.PI*(y/f)+Math.PI/f,"point"===g?M-=Math.PI/2:"edge"===g&&(M=M+Math.PI/f-Math.PI/2),M+=p,_+=(n=v*Math.cos(M)+l)+","+(o=v*Math.sin(M)+u)+" ")}return s.setAttribute("points",_),s.setAttribute("fill",c),s.setAttribute("stroke",d),s.setAttribute("stroke-width",h),s.getAttribute("shape"),{started:!0}}},mouseUp:function mouseUp(){if("star"===a.getMode())return{keep:"0"!==r(s).attr(["r"]).r,element:s}},selectedChanged:function selectedChanged(t){for(var e=(o=t.elems).length;e--;){var n=o[e];n&&"star"===n.getAttribute("shape")&&t.selectedElement&&!t.multiselected?(r("#starNumPoints").val(n.getAttribute("point")),r("#radialShift").val(n.getAttribute("radialshift")),c(!0)):c(!1)}},elementChanged:function elementChanged(t){}});case 12:case"end":return f.stop()}}),_callee)})))()}};export default t;
|
||
|
//# sourceMappingURL=ext-star.js.map
|