antosdk-apps/SVGEdit/svgedit/extensions/ext-polystar/ext-polystar.js

12 lines
9.3 KiB
JavaScript
Raw Normal View History

2023-08-17 23:54:41 +02:00
/**
* @file ext-polystar.js
*
*
* @copyright 2010 CloudCanvas, Inc. All rights reserved
* @copyright 2021 Optimistik SAS, Inc. All rights reserved
* @license MIT
*
*/
const t="polystar",loadExtensionTranslation=async function(e){let s;const a=e.configObj.pref("lang");try{s=await function __variableDynamicImportRuntime0__(t){switch(t){case"./locale/en.js":return Promise.resolve().then((function(){return o}));case"./locale/fr.js":return Promise.resolve().then((function(){return l}));case"./locale/tr.js":return Promise.resolve().then((function(){return n}));case"./locale/zh-CN.js":return Promise.resolve().then((function(){return i}));default:return new Promise((function(e,o){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(o.bind(null,new Error("Unknown variable dynamic import: "+t)))}))}}("./locale/".concat(a,".js"))}catch(e){console.warn("Missing translation (".concat(a,") for ").concat(t," - using 'en'")),s=await Promise.resolve().then((function(){return o}))}e.i18next.addResourceBundle(a,t,s.default)};var e={name:t,async init(){const e=this,{svgCanvas:o}=e,{ChangeElementCommand:l}=o.history,addToHistory=t=>{o.undoMgr.addCommandToHistory(t)},{$id:n,$click:i}=o;let s,a,r;await loadExtensionTranslation(e);const showPanel=(t,e)=>{t?n("".concat(e,"_panel")).style.removeProperty("display"):n("".concat(e,"_panel")).style.display="none"},setAttr=(t,e)=>{o.changeSelectedAttribute(t,e),o.call("changed",s)},cot=t=>1/Math.tan(t),sec=t=>1/Math.cos(t);return{name:e.i18next.t("".concat(t,":name")),callback(){const e="".concat(t,":title"),a="".concat(t,":buttons.0.title"),r="".concat(t,":buttons.1.title"),u='\n <se-flyingbutton id="tools_polygon" title="'.concat(e,'">\n <se-button id="tool_star" title="').concat(a,'" src="star.svg">\n </se-button>\n <se-button id="tool_polygon" title="').concat(r,'" src="polygon.svg">\n </se-button>\n </se-flyingbutton>\n ');o.insertChildAtIndex(n("tools_left"),u,10),i(n("tool_star"),(()=>{this.leftPanel.updateLeftPanel("tool_star")&&(o.setMode("star"),showPanel(!0,"star"),showPanel(!1,"polygon"))})),i(n("tool_polygon"),(()=>{this.leftPanel.updateLeftPanel("tool_polygon")&&(o.setMode("polygon"),showPanel(!0,"polygon"),showPanel(!1,"star"))}));const c="".concat(t,":contextTools.0.label"),d="".concat(t,":contextTools.0.title"),g="".concat(t,":contextTools.1.label"),b="".concat(t,":contextTools.1.title"),p="".concat(t,":contextTools.2.label"),h="".concat(t,":contextTools.2.title"),m="".concat(t,":contextTools.3.label"),f="".concat(t,":contextTools.3.title"),y=document.createElement("template");y.innerHTML='\n <div id="star_panel">\n <se-spin-input id="starNumPoints" label="'.concat(c,'" min=1 step=1 value=5 title="').concat(d,'">\n </se-spin-input>\n <se-spin-input id="RadiusMultiplier" label="').concat(g,'" min=1 step=2.5 value=3 title="').concat(b,'">\n </se-spin-input>\n <se-spin-input id="radialShift" min=0 step=1 value=0 label="').concat(p,'" title="').concat(h,'">\n </se-spin-input>\n </div>\n <div id="polygon_panel">\n <se-spin-input size="3" id="polySides" min=1 step=1 value=5 label="').concat(m,'" title="').concat(f,'">\n </se-spin-input>\n </div>\n '),n("tools_top").appendChild(y.content.cloneNode(!0)),showPanel(!1,"star"),showPanel(!1,"polygon"),n("starNumPoints").addEventListener("change",(t=>{setAttr("point",t.target.value);const e=t.target.value;let o=s.length;for(;o--;){const t=s[o];if(t.hasAttribute("r")){const o=t.getAttribute("point"),n=t.getAttribute("points"),i=t.getAttribute("radialshift");let s=0,a=0;if(t.points){const r=t.points,u=r.numberOfItems;for(let t=0;t<u;++t){const e=r.getItem(t);s+=parseFloat(e.x),a+=parseFloat(e.y)}const c=s/u,d=a/u,g=Number(t.getAttribute("r")),b=g/t.getAttribute("starRadiusMultiplier");let p="";for(let t=0;e>=t;t++){let o=2*Math.PI*(t/e);o-=Math.PI/2;let l=g*Math.cos(o)+c,n=g*Math.sin(o)+d;p+=l+","+n+" ",isNaN(b)||(o=2*Math.PI*(t/e)+Math.PI/e,o-=Math.PI/2,o+=i,l=b*Math.cos(o)+c,n=b*Math.sin(o)+d,p+=l+","+n+" ")}t.setAttribute("points",p),addToHistory(new l(t,{point:o,points:n}))}}}})),n("Radius
//# sourceMappingURL=ext-polystar.js.map